Skip to content

Instantly share code, notes, and snippets.

@rodrigodiez
Created October 22, 2013 15:33
Show Gist options
  • Save rodrigodiez/7102847 to your computer and use it in GitHub Desktop.
Save rodrigodiez/7102847 to your computer and use it in GitHub Desktop.
FooNamespace\FooClass:
FooNamespace\BarClass:
setting1: value
setting2: value
<?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');
}
}
}
@everzet
Copy link

everzet commented Oct 22, 2013

What if you want to use FooNamespace\MegaBarClass instead. That extends functionality of FooNamespace\BarClass ? You need to update config???

@rodrigodiez
Copy link
Author

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

@everzet
Copy link

everzet commented Oct 22, 2013

<?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

@rodrigodiez
Copy link
Author

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