コード例 #1
0
 /**
  * @param ServiceDescriptor $sd
  * @throws NonExistentClassException
  */
 public function check(ServiceDescriptor $sd)
 {
     if ($sd->isAlias()) {
         return;
     }
     $class = $sd->getDefinition()->getClass();
     if ($this->isParameter($class)) {
         $class = $sd->getContainer()->getParameter(trim($class, '%'));
     }
     $factoryClass = $sd->getDefinition()->getFactoryClass();
     if ($this->isParameter($factoryClass)) {
         $factoryClass = $sd->getContainer()->getParameter(trim($factoryClass, '%'));
     }
     if (is_null($class) && is_null($factoryClass)) {
         return;
     }
     if (interface_exists($class) && is_null($factoryClass)) {
         return;
     }
     if (interface_exists($class) && class_exists($factoryClass)) {
         return;
     }
     if (!class_exists($class)) {
         throw new NonExistentClassException(sprintf('the class %s for the service %s does not exists', $class, $sd->getServiceName()));
     }
 }
コード例 #2
0
 /**
  * @param ServiceDescriptor $sd
  * @throws TooFewConstructorCountArguments
  * @throws TooManyConstructorCountArguments
  * @return void
  */
 public function check(ServiceDescriptor $sd)
 {
     if ($sd->isAlias()) {
         return;
     }
     $definition = $sd->getDefinition();
     $class = $definition->getClass();
     if ($this->isParameter($class)) {
         $class = $sd->getContainer()->getParameter($this->parameterName($class));
     }
     $reflection = new \ReflectionClass($class);
     if (($factoryClass = $definition->getFactoryClass()) !== null) {
         if ($this->isParameter($factoryClass)) {
             $factoryClass = $sd->getContainer()->getParameter($this->parameterName($factoryClass));
         }
         $this->checkFactoryClass($sd, $factoryClass);
         return;
     }
     if (($factoryService = $definition->getFactoryService()) !== null) {
         $factoryService = $sd->getContainer()->get($factoryService);
         $this->checkFactoryService($sd, $factoryService);
         return;
     }
     $constructor = $reflection->getConstructor();
     if (is_null($constructor) && 0 === count($definition->getArguments())) {
         return;
     }
     $this->compare($sd, $definition->getArguments(), $constructor->getParameters());
 }