fezfez / php-to-zephir

Convert PHP to Zephir
MIT License
191 stars 40 forks source link

Support for closures #5

Open Green-Cat opened 9 years ago

Green-Cat commented 9 years ago

Zephir implemented support for closures. So now they can be used like in php instead of using separate pseudo-classes. http://blog.zephir-lang.com

fezfez commented 9 years ago

Waiting full support of keyword "use" to delete pseudo-classes phalcon/zephir#888

kristoftorfs commented 8 years ago

Is it possible to implement this without the functionality of the use keyword? Or is there any other way to use callbacks right now that don't require use?

fezfez commented 8 years ago

@kristoftorfs : Instead of using anonym function, you can use classic class.

kristoftorfs commented 8 years ago

Would you be so kind to give me an example? I'm trying to port a PHP (Phalcon) app to a Zephir extension, and I am having trouble injecting my services.

Boot.php:

$di = new FactoryDefault();
$di->setShared('db', new DatabaseService());

DatabaseService.php

class DatabaseService implements ServiceClosure {
    public function __invoke() {
        return new Mysql([
            'host' => 'localhost',
            'username' => 'root',
            'password' => 'secret',
            'dbname' => 'testdb'
        ]);
    }
}

When I try to get the service in the controller $this->getDI()->get('db') I get an instance of DatabaseService instead of the actual connection.