/**
  * Validates, if argument has its annotation and converts it to defined type.
  *
  * @param  mixed $argument
  * @param  int $i
  * @return mixed
  * @throws InvalidEventArgumentDefinitionException
  * @throws InvalidEventArgumentTypeException
  * @throws InvalidEventArgumentValueException
  */
 private function validateArgument($argument, $i)
 {
     $annotations = $this->annotations;
     if (!isset($annotations['param'][$i])) {
         throw new InvalidEventArgumentDefinitionException('Not all parameters have their own @param annotation at method ' . $this->method->getName() . '.');
     }
     $annotation = $annotations['param'][$i];
     return $this->convertToType($argument, $annotation);
 }
 /**
  * Creates method list
  * (may take a time..)
  *
  * @return array
  */
 public function createMethodList()
 {
     /** @var $robotLoader RobotLoader */
     $robotLoader = $this->context->getService('robotLoader');
     foreach ($robotLoader->getIndexedClasses() as $class => $file) {
         if (Strings::match($file, "~\\Nette~")) {
             continue;
         }
         $creflection = new Nette\Reflection\ClassType($class);
         foreach ($creflection->getMethods() as $method) {
             $mreflection = new Method($class, $method->getName());
             if ($mreflection->hasAnnotation('cron')) {
                 $m = new stdClass();
                 $m->name = $mreflection->getName();
                 $m->class = $mreflection->getDeclaringClass()->getName();
                 $m->annotations = $mreflection->getAnnotations();
                 $this->methods[] = $m;
             }
         }
     }
     return $this->methods;
 }
 /**
  * @param $name
  * @return Nette\ComponentModel\IComponent
  * @throws Nette\UnexpectedValueException
  */
 protected function createComponent($name)
 {
     $sl = $this->getComponentFactoriesLocator();
     $ucName = ucfirst($name);
     $method = 'createComponent' . $ucName;
     if ($ucName !== $name && method_exists($this, $method)) {
         $methodReflection = new Method($this, $method);
         if ($methodReflection->getName() !== $method) {
             return;
         }
         $parameters = $methodReflection->getParameters();
         $args = [];
         if (($first = reset($parameters)) && !$first->className) {
             $args[] = $name;
         }
         $args = Nette\DI\Helpers::autowireArguments($methodReflection, $args, $sl);
         $component = call_user_func_array([$this, $method], $args);
         if (!$component instanceof Nette\ComponentModel\IComponent && !isset($this->components[$name])) {
             throw new Nette\UnexpectedValueException("Method {$methodReflection} did not return or create the desired component.");
         }
         return $component;
     }
 }
Exemple #4
0
 /**
  * Parse cronner values from annotations.
  *
  * @param \Nette\Reflection\Method $method
  * @return array
  */
 public static function parseParameters(Method $method)
 {
     $taskName = NULL;
     if ($method->hasAnnotation(Parameters::TASK)) {
         $className = $method->getDeclaringClass()->getName();
         $methodName = $method->getName();
         $taskName = $className . ' - ' . $methodName;
     }
     $parameters = array(static::TASK => Parser::parseName($method->getAnnotation(Parameters::TASK)) ?: $taskName, static::PERIOD => $method->hasAnnotation(Parameters::PERIOD) ? Parser::parsePeriod($method->getAnnotation(Parameters::PERIOD)) : NULL, static::DAYS => $method->hasAnnotation(Parameters::DAYS) ? Parser::parseDays($method->getAnnotation(Parameters::DAYS)) : NULL, static::TIME => $method->hasAnnotation(Parameters::TIME) ? Parser::parseTimes($method->getAnnotation(Parameters::TIME)) : NULL);
     return $parameters;
 }
Exemple #5
0
 /**
  * @return string
  */
 public function getName()
 {
     return $this->method->getName();
 }
Exemple #6
0
 /**
  * Get name for a job
  * 
  * @param \Nette\Reflection\Method $method
  * @return string
  */
 protected function getJobName(\Nette\Reflection\Method $method)
 {
     if ($method->hasAnnotation("test")) {
         return (string) $method->getAnnotation("test");
     } else {
         return $this->getSuitName() . "::" . $method->getName();
     }
 }