Beispiel #1
0
 public function setup()
 {
     $router = new \Lucid\Component\Router\Router();
     $config = new \Lucid\Component\Container\Container();
     $config->set('root', realpath(__DIR__ . '/app/'));
     $factory = new \Lucid\Component\Factory\Factory(null, $config);
     $this->queue = new Queue(null, $router, $factory);
 }
Beispiel #2
0
 public function buildParameters($object, string $method, $parameters = [])
 {
     $objectClass = get_class($object);
     # we need to use the Request object's methods for casting parameters
     if (is_array($parameters) === true) {
         $paramObject = new \Lucid\Component\Container\Container();
         $paramObject->setSource($parameters);
     } else {
         $paramObject = $parameters;
     }
     if (method_exists($objectClass, $method) === false) {
         throw new \Exception($objectClass . ' does not contain a method named ' . $method . '. Valid methods are: ' . implode(', ', get_class_methods($objectClass)));
     }
     $r = new \ReflectionMethod($objectClass, $method);
     $methodParameters = $r->getParameters();
     # construct an array of parameters in the right order using the passed parameters
     $boundParameters = [];
     foreach ($methodParameters as $methodParameter) {
         $type = strval($methodParameter->getType());
         if ($parameters->is_set($methodParameter->name)) {
             if (is_null($type) === true || $type == '' || method_exists($paramObject, $type) === false) {
                 $boundParameters[] = $paramObject->get($methodParameter->name);
             } else {
                 $boundParameters[] = $paramObject->{$type}($methodParameter->name);
             }
         } else {
             if ($methodParameter->isDefaultValueAvailable() === true) {
                 $boundParameters[] = $methodParameter->getDefaultValue();
             } else {
                 throw new \Exception('Could not find a value to set for parameter ' . $methodParameter->name . ' of function ' . $objectClass . '->' . $method . ', and no default value was set.');
             }
         }
     }
     return $boundParameters;
 }
Beispiel #3
0
 public function setup()
 {
     $config = new \Lucid\Component\Container\Container();
     $config->set('root', realpath(__DIR__ . '/app/'));
     $this->factory = new Factory(null, $config);
 }