public function create(Definition $serviceConf, \Pimple $container) { $serviceName = $serviceConf->getName(); $factoryFunction = null; if (!$serviceConf->isSynthetic()) { // we dont know how to create a synthetic service, its set later // the class name can be a parameter reference $serviceConf->setClass($this->normalize($serviceConf->getClass(), $container)); $that = $this; $aspectFactory = $this->aspectFactory; $shared = $this->shared; // the instantiator closure function $factoryFunction = function ($c) use($that, $serviceConf, $aspectFactory, &$shared) { $serviceName = $serviceConf->getName(); if (!empty($shared[$serviceName])) { return $shared[$serviceName]; } $instance = $that->createInstance($serviceConf, $c); // add aspects if (null !== $aspectFactory && $serviceConf->hasAspects()) { $instance = $that->addAspects($serviceConf->getAspects(), $instance, $c); } // add some method calls if ($serviceConf->hasCalls()) { $instance = $that->addMethodCalls($serviceConf->getCalls(), $instance, $c); } // let another object modify this instance if ($serviceConf->hasConfigurators()) { $instance = $that->addConfigurators($serviceConf->getConfigurators(), $instance, $c); } // if the service is a shared instance we save it for later use, this is default if (true === $serviceConf->isShared()) { $shared[$serviceName] = $instance; } return $instance; }; if ($serviceConf->hasTags()) { $tags = $serviceConf->getTags(); /** @var TagHandlerInterface $handler */ foreach ($this->tagHandlers as $handler) { $handler->process($serviceConf, $tags, $container); } } // create a lazy proxy if (null !== $this->proxyFactory && $serviceConf->isLazy()) { $factoryFunction = $this->proxyFactory->createProxy($serviceConf->getClass(), $factoryFunction); } } $container[$serviceName] = $factoryFunction; return $container; }
public function process(Definition $serviceConf, array $tags, \Pimple $container) { foreach ($tags as $tag) { if (strtolower($tag['name']) === 'konfigurator.event_listener') { $container[$this->dispatcher] = $container->extend($this->dispatcher, function ($dispatcher, $c) use($serviceConf, $tag) { $dispatcher->addListener($tag['event'], function () use($serviceConf, $tag, $c) { $service = $serviceConf->getName(); $method = $tag['method']; if (isset($c[$service])) { return call_user_func_array(array($c[$service], $method), func_get_args()); } return false; }); return $dispatcher; }); } } }