예제 #1
0
 /**
  * add method
  *
  * @param \Codex\Addons\Scanner\ClassFileInfo      $file
  * @param                                          $annotation
  * @param string|null                              $method
  */
 public function add(ClassFileInfo $file, Hook $annotation, $method = null)
 {
     $class = $file->getClassName();
     if ($method instanceof Closure) {
         $id = $class . '@' . str_random();
         $listener = $method;
     } else {
         $id = $method === null ? $class : "{$class}@{$method}";
         $listener = $id;
     }
     $this->set($id, array_merge(compact('file', 'annotation', 'class', 'listener'), (array) $annotation));
     if ($annotation->replace) {
         $this->set("{$annotation->replace}.replaced", $id);
     }
     $hooks = $this;
     $this->app->make('events')->listen('codex:' . $annotation->name, function () use($hooks, $id) {
         if ($this->has("{$id}.replaced")) {
             return;
         }
         $listener = $this->get("{$id}.listener");
         if ($listener instanceof Closure) {
             return call_user_func_array($listener, func_get_args());
         }
         $method = 'handle';
         if (str_contains($listener, '@')) {
             list($class, $method) = explode('@', $listener);
         } else {
             $class = $listener;
         }
         $instance = $this->app->build($class);
         return call_user_func_array([$instance, $method], func_get_args());
     });
 }
예제 #2
0
 public function add(ClassFileInfo $file, Processor $annotation)
 {
     $class = $file->getClassName();
     $instance = null;
     //$this->app->make($class);
     $data = array_merge(compact('file', 'annotation', 'class', 'instance'), (array) $annotation);
     $processor = $this->app->build(ProcessorPresenter::class);
     $processor->hydrate($data);
     $this->set($annotation->name, $processor);
 }
예제 #3
0
 /**
  * Search file for matching addon annotations and automaticly resolve and add them into their collections
  *
  * @param \Codex\Addons\Scanner\ClassFileInfo $file
  */
 public function resolveAndRegister(ClassFileInfo $file)
 {
     $class = $file->getClassName();
     if (array_key_exists($class, $this->registered)) {
         return;
     }
     $this->registered[$class] = $file;
     foreach ($file->getClassAnnotations() as $annotation) {
         if ($annotation instanceof Annotations\Processor) {
             $this->processors->add($file, $annotation);
         } elseif ($annotation instanceof Annotations\Hook) {
             $this->hooks->add($file, $annotation);
         } elseif ($annotation instanceof Annotations\Plugin) {
             $this->plugins->add($file, $annotation);
         }
     }
     foreach ($file->getMethodAnnotations(true) as $method => $annotations) {
         foreach ($annotations as $annotation) {
             if ($annotation instanceof Annotations\Hook) {
                 $this->hooks->add($file, $annotation, $method);
             }
         }
     }
     foreach ($file->getPropertyAnnotations(true) as $property => $annotations) {
         foreach ($annotations as $annotation) {
         }
     }
 }