From 6379051972225236d13fc771f1b11b0ef229042e Mon Sep 17 00:00:00 2001 From: wodka Date: Tue, 16 Feb 2016 16:15:28 +0100 Subject: [PATCH] finish rebase --- Metadata/ClassMetadata.php | 9 ----- Metadata/MetadataConverter.php | 35 ++++++++----------- Tests/Metadata/ClassMetadataTest.php | 11 ++++-- .../Metadata/Driver/AnnotationDriverTest.php | 16 +++++++-- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/Metadata/ClassMetadata.php b/Metadata/ClassMetadata.php index 85627ad..e45c957 100644 --- a/Metadata/ClassMetadata.php +++ b/Metadata/ClassMetadata.php @@ -93,9 +93,6 @@ class ClassMetadata extends BaseClassMetadata * @var string[] */ public $environments = array(); - public $decorates; - public $decoration_inner_name; - public $deprecated; /** * service definitions @@ -188,9 +185,6 @@ public function serialize() $this->initMethod, parent::serialize(), $this->environments, - $this->decorates, - $this->decoration_inner_name, - $this->deprecated, $this->services, )); } @@ -217,9 +211,6 @@ public function unserialize($str) $this->initMethod, $parentStr, $this->environments, - $this->decorates, - $this->decoration_inner_name, - $this->deprecated, $this->services, ) = $data; diff --git a/Metadata/MetadataConverter.php b/Metadata/MetadataConverter.php index 18c3dac..8760bab 100644 --- a/Metadata/MetadataConverter.php +++ b/Metadata/MetadataConverter.php @@ -20,7 +20,6 @@ use JMS\DiExtraBundle\Exception\InvalidParentException; use JMS\DiExtraBundle\Exception\InvalidAnnotationException; -use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Definition; use Metadata\ClassHierarchyMetadata; @@ -44,12 +43,6 @@ public function convert(ClassHierarchyMetadata $metadata, $environment = null) /** @var ClassMetadata $classMetadata */ foreach ($metadata->classMetadata as $classMetadata) { foreach ($classMetadata->getServices() as $service) { - if (@$service['id'] == 'third.multi') { - //echo $environment; - - //print_r($service); - } - if (isset($environment) && isset($service['environments']) && sizeof($service['environments']) > 0 @@ -95,22 +88,22 @@ public function convert(ClassHierarchyMetadata $metadata, $environment = null) $definition->setTags($classMetadata->tags); $definition->setProperties($classMetadata->properties); - if (null !== $classMetadata->decorates) { - if (!method_exists($definition, 'setDecoratedService')) { - throw new InvalidAnnotationException( - sprintf( - "decorations require symfony >=2.8 on class %s", - $classMetadata->name - ) - ); - } + if (isset($service['decorates'])) { + if (!method_exists($definition, 'setDecoratedService')) { + throw new InvalidAnnotationException( + sprintf( + "decorations require symfony >=2.8 on class %s", + $classMetadata->name + ) + ); + } - $definition->setDecoratedService($classMetadata->decorates, $classMetadata->decoration_inner_name); - } + $definition->setDecoratedService($service['decorates'], $service['decoration_inner_name']); + } - if (null !== $classMetadata->deprecated && method_exists($definition, 'setDeprecated')) { - $definition->setDeprecated(true, $classMetadata->deprecated); - } + if (isset($service['deprecated']) && method_exists($definition, 'setDeprecated')) { + $definition->setDeprecated(true, $service['deprecated']); + } if (0 !== count($classMetadata->initMethods)) { foreach ($classMetadata->initMethods as $initMethod) { diff --git a/Tests/Metadata/ClassMetadataTest.php b/Tests/Metadata/ClassMetadataTest.php index 5ce158a..febcc41 100644 --- a/Tests/Metadata/ClassMetadataTest.php +++ b/Tests/Metadata/ClassMetadataTest.php @@ -29,9 +29,14 @@ public function testSerializeUnserialize() $classMetadata->abstract = true; $classMetadata->public = false; $classMetadata->id = 'foo'; - $classMetadata->deprecated = true; - $classMetadata->decorates = 'test.service'; - $classMetadata->decoration_inner_name = 'old.test.service'; + $classMetadata->addService(array( + 'id' => 'foo', + 'abstract' => true, + 'public' => false, + 'deprecated' => true, + 'decorates' => 'test.service', + 'decoration_inner_name' => 'old.test.service', + )); $this->assertEquals($classMetadata, unserialize(serialize($classMetadata))); } diff --git a/Tests/Metadata/Driver/AnnotationDriverTest.php b/Tests/Metadata/Driver/AnnotationDriverTest.php index fa367ba..ebdcf59 100644 --- a/Tests/Metadata/Driver/AnnotationDriverTest.php +++ b/Tests/Metadata/Driver/AnnotationDriverTest.php @@ -41,10 +41,20 @@ public function testCustomAnnotationOnClass() public function testServiceAnnotations() { $metadata = $this->getDriver()->loadMetadataForClass(new \ReflectionClass('JMS\DiExtraBundle\Tests\Metadata\Driver\Fixture\Service')); + + $services = $metadata->getServices(); + $service = array_filter(@$services['test.service'], function ($value) { return $value !== null; }); + $this->assertEquals('test.service', $metadata->id); - $this->assertEquals('test.service', $metadata->decorates); - $this->assertEquals('original.test.service', $metadata->decoration_inner_name); - $this->assertEquals('use new.test.service instead', $metadata->deprecated); + $this->assertArrayHasKey('test.service', $metadata->getServices()); + $this->assertEquals(array( + 'id' => 'test.service', + 'public' => false, + 'decorates' => 'test.service', + 'decoration_inner_name' => 'original.test.service', + 'deprecated' => 'use new.test.service instead', + 'environments' => array() + ), $service); $this->assertEquals(false, $metadata->public); }