Conversation
|
Sadly, factories aren't compatible with Symfony 2.3 ... Do you plan remove BC for that version? |
|
|
||
| $factory = $definition->getFactory(); | ||
|
|
||
| if( !is_array( $factory ) ) { |
There was a problem hiding this comment.
You could check if the Definition::getFactoryClass() method exists to implement a pre Symfony 2.7 compatible solution.
- Check for <2.6 symfony/dependency-injection version - Test old yml syntax format
|
|
||
| private function getFactoryData( Definition $definition ) | ||
| { | ||
| if( self::isLegacySymfonyDI() ) { |
There was a problem hiding this comment.
This is a dirty, but working solution ... I checked with DI 2.3, 3.0 and 3.3 and they working ... a better approach may be an abstract class with "getFactoryData" as abstract method, but this commit resolves <= 2.6 versions and variated factory syntax in yml.
A test case not cover is a service with "setFactoryClass" definition ... This is pending.
|
|
||
| static public function isLegacySymfonyDI() | ||
| { | ||
| return method_exists( new Definition(), 'getFactoryService' ); |
There was a problem hiding this comment.
no need to create an instance here, just using the class name works too
|
|
||
| public function toString() | ||
| { | ||
| if( null === $this->expectedFactoryClass ) |
There was a problem hiding this comment.
Please remove all spaces between sprintf() & strings inside:
if (null === $this->expectedFactoryClass) {
return sprintf('"%s" has factory', $this->serviceId);
}
|
|
||
| $factory = $this->getFactoryData($definition); | ||
|
|
||
| if( !is_array( $factory ) ) { |
|
|
||
| $factory = $this->getFactoryData( $definition ); | ||
|
|
||
| list( $factoryDefinition, $factoryMethod ) = $factory; |
There was a problem hiding this comment.
Please remove all spaces in function calls. Same for those in if/else etc.
| return null; | ||
|
|
||
| return array( $factoryClass ? $factoryClass : $factoryService, $factoryMethod ); | ||
| } else { |
There was a problem hiding this comment.
No point for else as you do return in if.
|
Could you also rebase on master? |
- Check for <2.6 symfony/dependency-injection version - Test old yml syntax format
|
@Nyholm I'm sorry ... I'm doing some bad. How to I must rebase my PR? |
| $container->setAlias('manual_alias', 'service_id'); | ||
|
|
||
| // add an factory service | ||
| $container->register('manual_factory_service', new Definition()); |
There was a problem hiding this comment.
@Nyholm I'm sorry again! The bug is here ... must be $container->register('manual_factory_service', 'stdClass');
I will fix and I will push again later.
|
Hi @stloyd In December 2017 I reviewed the Symfony CS unmatches. I forgot something ? |
| * @param $expectedFactoryClass | ||
| * @param $expectedFactoryMethod | ||
| */ | ||
| protected function assertContainerBuilderHasCreatedByFactoryService($serviceId, $expectedFactoryClass = null, $expectedFactoryMethod) |
There was a problem hiding this comment.
now that the library requires PHP 7 we can use scalar type hints here
| private $expectedFactoryClass; | ||
| private $expectedFactoryMethod; | ||
|
|
||
| public function __construct($serviceId, $expectedFactoryClass = null, $expectedFactoryMethod = null) |
Hi, I hope this pull request was useful for you. I apologize for my basic English