PhpBench\Registry\Registry::registerService PHP Method

registerService() public method

Register a service ID with against the given name.
public registerService ( string $name, string $serviceId )
$name string
$serviceId string
    public function registerService($name, $serviceId)
    {
        if (isset($this->serviceMap[$name])) {
            throw new \InvalidArgumentException(sprintf('%s service "%s" is already registered', $this->serviceType, $name));
        }
        $this->serviceMap[$name] = $serviceId;
        $this->services[$name] = null;
    }

Usage Example

Example #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']]);
 }