Skip to content

Commit

Permalink
finish rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
wodka committed Feb 16, 2016
1 parent 4546faa commit 6379051
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 36 deletions.
9 changes: 0 additions & 9 deletions Metadata/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ class ClassMetadata extends BaseClassMetadata
* @var string[]
*/
public $environments = array();
public $decorates;
public $decoration_inner_name;
public $deprecated;

/**
* service definitions
Expand Down Expand Up @@ -188,9 +185,6 @@ public function serialize()
$this->initMethod,
parent::serialize(),
$this->environments,
$this->decorates,
$this->decoration_inner_name,
$this->deprecated,
$this->services,
));
}
Expand All @@ -217,9 +211,6 @@ public function unserialize($str)
$this->initMethod,
$parentStr,
$this->environments,
$this->decorates,
$this->decoration_inner_name,
$this->deprecated,
$this->services,
) = $data;

Expand Down
35 changes: 14 additions & 21 deletions Metadata/MetadataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions Tests/Metadata/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
16 changes: 13 additions & 3 deletions Tests/Metadata/Driver/AnnotationDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 6379051

Please sign in to comment.