-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Ahead of time factory creation command #180
Ahead of time factory creation command #180
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
c7f87d6
to
bd6a362
Compare
I like that proposed feature pretty much 👍 But I prefer to keep generated files in a dedicated directory ( $generatedFactoriesConfig = [
ServiceManagerConfigProvider::CONFIGURATION_KEY_FACTORY_TARGET_PATH => __DIR__ . '/../../data/generated/',
'factory-override-path' => __DIR__ . '/../data/generated/generated-factories.php'
];
$aggregator = new ConfigAggregator([
ServiceManagerConfigProvider::class,
new PhpFileProvider(realpath(__DIR__) . '/autoload/{,*.}{global,local}.php'),
// Add config for generated factories
new ArrayProvider($generatedFactoriesConfig),
// Add generated factories
new PhpFileProvider($generatedFactoriesConfig['factory-override-path']),
]);
return $aggregator->getMergedConfig(); One feature I'd like to propose is adding php bin/console.php servicemanager:generate-aot-factories data/generated/generated-factories.php How about WDYT? |
@bcremer thats exactly how it is proposed here. You have to configure You have to add it as your If we are talking about the path which has to be added by So imho, its up to the projects to specify a path and - in case the path is not automatically picked-up by configuration merge - make the changes to their |
I withdraw my idea of having a configuration key to configure the path for the override factory mapping ( For most users the the proposed default is the better choice as there is already the default I still support the proposed Pull Request from @boesing and would like to see it going forward. |
There are projects out there which do want to have "autowiring". Since the service manager is not build with that kind of autowiring compatibility, some developers started to use `ReflectionBasedAbstractFactory` so that they can prevent themselves from writing factories. Since this project does already provide a CLI command to generate factories, having another CLI command which scans the project configuration for services registered via `ReflectionBasedAbstractFactory` should work. With this change, both `ReflectionBasedAbstractFactory` and `FactoryCreator`-Command do use the same constructor parameter resolving logic. Due to this, we can safely assume that all services registered with a `ReflectionBasedAbstractFactory` can also be generated during CI. Signed-off-by: Maximilian Bösing <[email protected]>
bd6a362
to
aa86639
Compare
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
22bf5dc
to
91a7a82
Compare
Signed-off-by: Maximilian Bösing <[email protected]>
…ct Factory` category Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
… to that page Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
…ries CLI command Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
…onstructorParameterResolver` The `ReflectionBasedAbstractFactory` should only test itself rather than integration testing the constructor parameter resolver. Tests which verified the appropriate functionality from `ConstructorParameterResolver` were moved to a dedicated test class. Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
In case there are autoloadable factories with the same class-name as the generated factory, the factory generation should be aborted to avoid autolaoding conflicts. Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
Signed-off-by: Maximilian Bösing <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation is good, I will take over all further changes, because it would go beyond the scope here.
Signed-off-by: Maximilian Bösing <[email protected]>
50e72c7
to
89976b0
Compare
Description
Fixes #171
So just to quickly sum this up:
We do have project configuration, so this is not some fictional use-case.
This configuration contains
service_manager
configuration where some services (usually only depending on interfaces) are registered viaReflectionBasedAbstractFactory
:Even tho, the
ReflectionBasedAbstractFactory
is an abstract factory, it also extendsFactoryInterface
and thus can be used as shown above.__construct
argument valuesI've played a little bit in our project and I ended up writing some code (which I now used to contribute here) which allows us to use
ReflectionBasedAbstractFactory
in development while providing a CLI command to generate a opcachable factory while putting it on the filesystem during release artifact generation.Usage would be as follows:
One needs also to register a directory in the application config:
config/autoload/global.php
Since the path registered in that configuration key MUST also be added to
composer.json
autoload
section usingclassmap
, having this as a required configuration key to use the CLI command seemed to be a good solution.So after configuring the application as mentioned above, the CLI command could be executed like:
This will then scan the projects configuration for all container configurations (so everything which looks like a container configuration actually: has to be an array, containing key
factories
being an array, containing values with eitherclass-string<ReflectionBasedAbstractFactory>
or instance ofReflectionBasedAbstractFactory
.So in the end, we should have a bunch of generated factories located in the
path/to/factory/output
directory (there is a sub-directory per "container") PLUS theaot-factories.local.php
file located inconfig/autoload
.In the end, running
composer dump-autoload
should "register" all the factories located inpath/to/factory/output
and the nextvendor/bin/laminas servicemanager:generate-aot-factories
run should tell us, that there are no (more) services registered viaReflectionBasedAbstractFactory
(as theaot-factories.local.php
should've overriden the initial application config).🎉