Open Green-Cat opened 9 years ago
Waiting full support of keyword "use" to delete pseudo-classes phalcon/zephir#888
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?
@kristoftorfs : Instead of using anonym function, you can use classic class.
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.
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