Ejemplo n.º 1
0
 /**
  * @param $path
  * @param $namespace
  *
  * @return CommandContainer
  */
 public function locate($path, $namespace)
 {
     $container = new CommandContainer();
     foreach ($this->findClasses($path, $namespace) as $class) {
         $container->register($class);
     }
     return $container;
 }
Ejemplo n.º 2
0
 /**
  * @param array $commandData
  */
 public function create(array $commandData)
 {
     $commandClass = $this->commandContainer->find(key($commandData));
     $reflClass = new ReflectionClass($commandClass);
     $command = $reflClass->newInstanceWithoutConstructor();
     foreach (reset($commandData) as $key => $value) {
         try {
             $reflectionProperty = $reflClass->getProperty($key);
             $reflectionProperty->setAccessible(true);
             $reflectionProperty->setValue($command, $value);
         } catch (\ReflectionException $e) {
             continue;
         }
     }
     $errors = $this->validateCommand($command);
     if (count($errors) > 0) {
         $exception = new ValidationException('Invalid command given');
         $exception->setErrors($errors);
         throw $exception;
     }
     return $command;
 }