Created
October 22, 2013 15:33
-
-
Save rodrigodiez/7102847 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FooNamespace\FooClass: | |
FooNamespace\BarClass: | |
setting1: value | |
setting2: value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FooService | |
{ | |
protected $container; | |
public function __construct(Symfony\Component\DependencyInjection\Container $container) | |
{ | |
$this->container = $container; | |
} | |
public function createFooObject(\stdClass $obj1) | |
{ | |
$config = $this->container->getParameter('foo_service.config'); | |
if(!is_array($config) || !array_key_exists(get_class($obj1), $config)){ | |
throw new \Exception('Config for class ' . get_class($obj1) . ' not found'); | |
} | |
} | |
} |
In that case yes, because the classes are in fact entities and I persist them. All is about entities. I'm trying to be able to configure my bundle to manage the relation between 2 entities
<?php
interface ConfigurableEntity
{
public function getEntityName();
}
class ConfigurableBarEntity implements ConfigurableEntity
{
public function getEntityName()
{
return 'bar';
}
}
class FooService
{
public function createFooObject(ConfigurableEntity $entity)
{
$config = $this->container->getParameter('foo_service.config');
if(!is_array($config) || !array_key_exists($entity->getConfigKey(), $config)){
throw new \Exception('Config for entity ' . $entity->getEntityName() . ' not found');
}
}
}
foo:
bar:
setting1: value
setting2: value
You rocks! Thanks for show me the way :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What if you want to use
FooNamespace\MegaBarClass
instead. That extends functionality ofFooNamespace\BarClass
? You need to update config???