コード例 #1
0
 /**
  * Instantiates an object
  *
  * @param string $class
  * @param array  $arguments
  *
  * @return object
  */
 private function instantiateClass($class, $arguments = array())
 {
     // Checks if the class exists.
     if (!class_exists($class)) {
         throw LogicException::classNotFoundException($class);
     }
     // Get class reflection.
     $reflection = new \ReflectionClass($class);
     // Checks if the class is instantiable.
     if (!$reflection->isInstantiable()) {
         throw LogicException::classNotInstantiableException($class);
     }
     // Checks if the constructor exists and takes the right number of parameters.
     if ($reflection->hasMethod('__construct')) {
         $method = $reflection->getMethod('__construct');
         if ($method->getNumberOfRequiredParameters() > count($arguments)) {
             throw LogicException::invalidNumberOfParametersException($class, '__construct()', $method->getNumberOfRequiredParameters());
         }
     }
     // Instantiate class and return the object.
     return $reflection->newInstanceArgs($arguments);
 }
コード例 #2
0
 /**
  * Executes a command (must be overridden)
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function executeCommand(InputInterface $input, OutputInterface $output)
 {
     throw LogicException::mustOverrideMethodException(__METHOD__, get_class($this));
 }