-
Notifications
You must be signed in to change notification settings - Fork 130
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
Add missing service properties #145
base: master
Are you sure you want to change the base?
Changes from all commits
9f7a797
37d9e4d
bd6c60b
9611da0
7f3abeb
f162d22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,21 @@ public function convert(ClassHierarchyMetadata $metadata) | |
if (null !== $classMetadata->deprecated && method_exists($definition, 'setDeprecated')) { | ||
$definition->setDeprecated(true, $classMetadata->deprecated); | ||
} | ||
if (null !== $classMetadata->lazy) { | ||
if (!method_exists($definition, 'setLazy')) { | ||
throw new \RuntimeException(sprintf('the "lazy" attribute is not available on your Symfony version.')); | ||
} | ||
$definition->setLazy($classMetadata->lazy); | ||
} | ||
if (null !== $classMetadata->factoryClass) { | ||
$definition->setFactoryClass($classMetadata->factoryClass); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is deprecated, you should use |
||
} | ||
if (null !== $classMetadata->factoryMethod) { | ||
$definition->setFactoryMethod($classMetadata->factoryMethod); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing |
||
} | ||
if (null !== $classMetadata->factoryService) { | ||
$definition->setFactoryService($classMetadata->factoryService); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
|
||
if (null === $classMetadata->id) { | ||
$classMetadata->id = '_jms_di_extra.unnamed.service_'.$count++; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Factory; | ||
|
||
use JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Model\TestClass; | ||
use JMS\DiExtraBundle\Annotation\Service; | ||
|
||
/** | ||
* JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Factory\TestClassFactory | ||
* | ||
* @Service("jms_di_extra.factory.test_factory") | ||
* | ||
* @author Ivan Molchanov <[email protected]> | ||
*/ | ||
class TestClassFactory | ||
{ | ||
/** | ||
* @param string $message | ||
* @return TestClass | ||
*/ | ||
public function create($message = '') | ||
{ | ||
$class = new TestClass(); | ||
$class->setTestMessage($message); | ||
|
||
return $class; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Model; | ||
|
||
use JMS\DiExtraBundle\Annotation\Service; | ||
|
||
/** | ||
* JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Model\TestClass | ||
* | ||
* @Service("jms_di_extra.model.test", | ||
* factoryClass = "JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Factory\TestClassFactory", | ||
* factoryMethod="create", factoryMethodArguments={ | ||
* "message" = "created by factory" | ||
* } ) | ||
* | ||
* @author Ivan Molchanov <[email protected]> | ||
*/ | ||
class TestClass | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $testMessage; | ||
|
||
/** | ||
* @param string $testMessage | ||
* @return TestClass | ||
*/ | ||
public function setTestMessage($testMessage) | ||
{ | ||
$this->testMessage = $testMessage; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTestMessage() | ||
{ | ||
return $this->testMessage; | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Model; | ||
|
||
use JMS\DiExtraBundle\Annotation\Service; | ||
|
||
/** | ||
* JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Model\TestService | ||
* | ||
* @Service("jms_di_extra.model.test_service", | ||
* factoryService = "jms_di_extra.factory.test_factory", | ||
* factoryMethod="create", factoryMethodArguments={ | ||
* "message" = "created by factory" | ||
* } ) | ||
* | ||
* @author Ivan Molchanov <[email protected]> | ||
*/ | ||
class TestService | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $testMessage; | ||
|
||
/** | ||
* @param string $testMessage | ||
* @return TestClass | ||
*/ | ||
public function setTestMessage($testMessage) | ||
{ | ||
$this->testMessage = $testMessage; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getTestMessage() | ||
{ | ||
return $this->testMessage; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace JMS\DiExtraBundle\Tests\Functional; | ||
|
||
/** | ||
* JMS\DiExtraBundle\Tests\Functional\Bundle\FactoryPropertiesTest | ||
* | ||
* @author Ivan Molchanov <[email protected]> | ||
*/ | ||
class FactoryPropertiesTest extends BaseTestCase | ||
{ | ||
/** | ||
* @runInSeparateProcess | ||
*/ | ||
public function testFactoryClassProperty() | ||
{ | ||
$this->createClient(); | ||
$container = self::$kernel->getContainer(); | ||
$testClass = $container->get('jms_di_extra.model.test'); | ||
$this->assertEquals($testClass->getTestMessage(), 'created by factory'); | ||
} | ||
|
||
/** | ||
* @runInSeparateProcess | ||
*/ | ||
public function testFactoryServiceProperty() | ||
{ | ||
$this->createClient(); | ||
$container = self::$kernel->getContainer(); | ||
$testClass = $container->get('jms_di_extra.model.test_service'); | ||
$this->assertEquals($testClass->getTestMessage(), 'created by factory'); | ||
} | ||
} | ||
|
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.
You should add them at the end of the array to avoid BC breaks