Lazily instantiates tagged services which are associated with a name and stores configurations which are relevant to these services. $reg->getService($config['renderer']); $reg->render($something, $config);
Esempio n. 1
0
 private function registerStorage(Container $container)
 {
     $container->register('storage.driver_registry', function (Container $container) {
         $registry = new Registry('storage', $container, $container->getParameter('storage'));
         foreach ($container->getServiceIdsForTag('storage_driver') as $serviceId => $attributes) {
             $registry->registerService($attributes['name'], $serviceId);
         }
         return $registry;
     });
     $container->register('storage.archiver_registry', function (Container $container) {
         $registry = new Registry('archiver', $container, $container->getParameter('archiver'));
         foreach ($container->getServiceIdsForTag('storage_archiver') as $serviceId => $attributes) {
             $registry->registerService($attributes['name'], $serviceId);
         }
         return $registry;
     });
     $container->register('storage.driver.xml', function (Container $container) {
         return new XmlDriver($container->getParameter('xml_storage_path'), $container->get('serializer.encoder.xml'), $container->get('serializer.decoder.xml'));
     }, ['storage_driver' => ['name' => 'xml']]);
     $container->register('storage.uuid_resolver', function (Container $container) {
         return new UuidResolver($container->get('storage.driver_registry'));
     });
     $container->register('storage.archiver.xml', function (Container $container) {
         return new Storage\Archiver\XmlArchiver($container->get('storage.driver_registry'), $container->get('serializer.encoder.xml'), $container->get('serializer.decoder.xml'), $container->getParameter('archive_path'));
     }, ['storage_archiver' => ['name' => 'xml']]);
 }
 public function __construct($serviceType, Container $container, JsonDecoder $jsonDecoder)
 {
     parent::__construct($serviceType, $container);
     $this->jsonDecoder = $jsonDecoder;
 }
Esempio n. 3
0
 /**
  * It should throw an exception if no argument given to get() and no default is defined.
  *
  * @expectedException RuntimeException
  * @expectedExceptionMessage You must configure a default test service, registered test services: "foo"
  */
 public function testDefaultGetNoDefault()
 {
     $registry = new Registry('test', $this->container->reveal());
     $registry->setService('foo', 'bar');
     $this->assertEquals($registry->getService(), 'bar');
 }