Skip to content
This repository has been archived by the owner on Jun 2, 2021. It is now read-only.

Support for closures #5

Open
Green-Cat opened this issue Apr 1, 2015 · 4 comments
Open

Support for closures #5

Green-Cat opened this issue Apr 1, 2015 · 4 comments

Comments

@Green-Cat
Copy link

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
Copy link
Owner

fezfez commented May 15, 2015

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

@kristoftorfs
Copy link

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
Copy link
Owner

fezfez commented Feb 2, 2016

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

@kristoftorfs
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants