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

[php-di v7] Optimize compiled factory definitions #15

Open
wants to merge 5 commits into
base: mod7
Choose a base branch
from

Conversation

partikus
Copy link
Collaborator

@partikus partikus commented Jan 13, 2023

Version compatible with PHP ^8.0 as a successor of #6

Details (copied from #6)

  • 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);

1. Detected deprecations in use:
- Rule "braces" is deprecated. Use "single_space_around_construct", "control_structure_braces", "control_structure_continuation_position", "declare_parentheses", "no_multiple_statements_per_line", "curly_braces_position", "statement_indentation" and "no_extra_blank_lines" instead.

2. Detected deprecations in use:
- Rule "curly_braces_position" is deprecated. Use "braces_position" instead.
@partikus partikus force-pushed the feature/php-di-7-compiler-optimize-factories branch 2 times, most recently from d5c242f to 6a0fd6b Compare January 10, 2024 12:52
mnapoli and others added 4 commits January 10, 2024 19:05
…ions

feat: php-cs-fixer - removing deprecations
- compile final function with injected dependencies
- only for closure factories for now (as the first step)
@partikus partikus force-pushed the feature/php-di-7-compiler-optimize-factories branch from 6a0fd6b to b6b60f3 Compare January 11, 2024 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants