Esempio n. 1
0
 /**
  * Build service cache block
  *
  * @return string Service cache block
  */
 public function buildServiceCacheBlock()
 {
     $cacheContent = '';
     $this->serviceDefinitionChain->each(function (ServiceDefinition $serviceDefinition) use(&$cacheContent) {
         $serviceName = $serviceDefinition->getName();
         $serverClass = $serviceDefinition->getClass();
         $cacheArgumentsStack = array();
         $serviceDefinition->getArgumentChain()->each(function (Argument $argument) use(&$cacheDefinition, &$cacheArgumentsStack) {
             $argumentValue = $argument->getValue();
             if ($argument instanceof ServiceArgument) {
                 $method = $this->getCachedServiceMethodName($argumentValue);
                 $cacheArgumentsStack[] = "\$this->{$method}()";
             } elseif ($argument instanceof ParameterArgument) {
                 $cacheArgumentsStack[] = "\$this->parameters[\"{$argumentValue}\"]";
             } else {
                 $cacheArgumentsStack[] = var_export($argumentValue, true);
             }
         });
         $serviceCacheableMethod = self::getCachedServiceMethodName($serviceName);
         $cacheArguments = '';
         if ($cacheArgumentsStack) {
             $cacheArguments = "\n            " . implode(',
         ', $cacheArgumentsStack) . "\n        ";
         }
         $cacheContent .= "/**\n     * Return instance of service {$serviceName}\n     *\n     * @return {$serverClass} Service instance\n     */\n    public function {$serviceCacheableMethod}()\n    {\n        return new {$serverClass}({$cacheArguments});\n    }\n\n    ";
     });
     return $cacheContent;
 }
Esempio n. 2
0
 /**
  * Check services arguments references
  *
  * This call has only sense if the service stack is built before. The why
  * of this methods is because now we have the correct acknowledgement about
  * all the services and parameters we will work with.
  *
  * We will now check that all service arguments have correct references.
  *
  * @throws DoppoServiceArgumentNotExistsException service argument not found
  */
 protected function checkServiceArgumentsReferences()
 {
     $this->services->each(function (ServiceDefinition $serviceDefinition) {
         $serviceDefinition->getArgumentChain()->each(function (Argument $argument) use($serviceDefinition) {
             $argumentValue = $argument->getValue();
             if ($argument instanceof ServiceArgument) {
                 if (!$this->services->has($argumentValue)) {
                     throw new DoppoServiceArgumentNotExistsException(sprintf('Service "%s" not found in "@%s" arguments list', $argumentValue, $serviceDefinition->getName()));
                 }
             }
             if ($argument instanceof ParameterArgument) {
                 if (!$this->parameters->has($argumentValue)) {
                     throw new DoppoServiceArgumentNotExistsException(sprintf('Parameter "%s" not found in "@%s" arguments list', $argumentValue, $serviceDefinition->getName()));
                 }
             }
         });
     });
 }