Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize compiled factory definitions #664

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@falkenhawk
Copy link

commented May 31, 2019

  • compile final function with injected dependencies
  • only for closure factories for now (as the first step)
  1. Simple example:
    before:
return $this->resolveFactory(static function () {
    return 'bar';
}, 'factory');

now:

return (static function () {
    return 'bar';
})();
  1. More complex example:
    before:
return $this->resolveFactory(static function (\DI\Factory\RequestedEntry $entry, \DI\Container $c, $dbName = null) {
    $parts = explode('.', $entry->getName());
    $type = $parts[1];
    if ($dbName === null && isset($parts[2])) {
        $dbName = $parts[2] !== '0' ? $parts[2] : false;
    }
    $factory = $c->get(\CMS\Database\ConnectionFactory::class);
    return $factory->create($type, $dbName);
}, 'db.mysql', [
            'dbName' => NULL,
        ]);

now:

return (static function (\DI\Factory\RequestedEntry $entry, \DI\Container $c, $dbName = null) {
    $parts = explode('.', $entry->getName());
    $type = $parts[1];
    if ($dbName === null && isset($parts[2])) {
        $dbName = $parts[2] !== '0' ? $parts[2] : false;
    }
    $factory = $c->get(\CMS\Database\ConnectionFactory::class);
    return $factory->create($type, $dbName);
})(new DI\Compiler\RequestedEntryHolder('db.mysql'), $this->get5cc4bd5c6dc8e808068072(), NULL);

[from ovos#6]

Optimize compiled factory definitions
- compile final function with injected dependencies
- only for closure factories for now (as the first step)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.