예제 #1
0
 public function run($name, Document $document)
 {
     /** @var Processor $annotation */
     $this->currentDocument = $document;
     $project = $document->getProject();
     $processor = $this->get($name);
     if ($processor->plugin && false === $this->addons->plugins->canRunPlugin($processor->plugin)) {
         throw CodexException::because("Cannot run processor [{$name}] belonging to plugin [{$processor->plugin}] because the plugin can not run. Ensure the plugin is installed and enabled");
     }
     // hook point before can prevent the processor from running
     if (false === $this->hookPoint('addons:processor:before', [$name])) {
         return $processor;
     }
     $instance = $this->getInstance($name);
     $annotation = $processor['annotation'];
     if ($annotation->config !== false) {
         // get default config
         if (!property_exists($instance, $annotation->config)) {
             throw CodexException::because('Config not found for ' . $processor['class']);
         }
         $config = $instance->{$annotation->config};
         $config = array_replace_recursive($config, $project->config('processors.' . $name, []), $document->attr('processors.' . $name, []));
         $instance->{$annotation->config} = new Collection($config);
     }
     if (property_exists($instance, 'codex')) {
         $instance->codex = $document->getCodex();
     }
     if (property_exists($instance, 'project')) {
         $instance->project = $document->getProject();
     }
     if (property_exists($instance, 'document')) {
         $instance->document = $document;
     }
     // hook point after can prevent the processor from running
     if (false === $this->hookPoint('addons:processor:after', [$name, $annotation, $instance])) {
         return $processor;
     }
     $this->app->call([$instance, $annotation->method], compact('document'));
     return $processor;
 }