Example #1
0
 /**
  * Applies all behaviours prior to transformation.
  *
  * @param PreTransformationEvent $data Event object containing the parameters.
  *
  * @phpdoc-event transformer.transform.pre
  *
  * @throws Exception if the event does not originate from the Transformer
  *
  * @return void
  */
 public function applyBehaviours($data)
 {
     if (!$data->getSubject() instanceof \phpDocumentor\Transformer\Transformer) {
         throw new Exception('Unable to apply behaviours, the invoking object is not a ' . '\\phpDocumentor\\Transformer\\Transformer');
     }
     $behaviours = new \phpDocumentor\Transformer\Behaviour\Collection($data->getSubject(), array(new Transformer\Behaviour\GeneratePaths(), new Transformer\Behaviour\Inherit(), new Transformer\Behaviour\Tag\IgnoreTag(), new Transformer\Behaviour\Tag\ReturnTag(), new Transformer\Behaviour\Tag\ParamTag(), new Transformer\Behaviour\Tag\VarTag(), new Transformer\Behaviour\Tag\PropertyTag(), new Transformer\Behaviour\Tag\MethodTag(), new Transformer\Behaviour\Tag\UsesTag(), new Transformer\Behaviour\Tag\CoversTag(), new Transformer\Behaviour\Tag\AuthorTag(), new Transformer\Behaviour\Tag\LicenseTag(), new Transformer\Behaviour\Tag\InternalTag(), new Transformer\Behaviour\AddLinkInformation()));
     $data->setSource($behaviours->process($data->getSource()));
 }
Example #2
0
 /**
  * Executes each transformation.
  *
  * @return void
  */
 public function execute()
 {
     $source = $this->getSource();
     if (!$source) {
         throw new Exception('Unable to process transformations; the source was not set ' . 'correctly');
     }
     // invoke pre-transform actions (i.e. enhance source file with additional
     // meta-data)
     \phpDocumentor\Event\Dispatcher::getInstance()->dispatch('transformer.transform.pre', \phpDocumentor\Transformer\Event\PreTransformEvent::createInstance($this)->setSource($source));
     foreach ($this->getTransformations() as $transformation) {
         \phpDocumentor\Event\Dispatcher::getInstance()->dispatch('transformer.transformation.pre', \phpDocumentor\Transformer\Event\PreTransformationEvent::createInstance($this)->setSource($source));
         $this->log('Applying transformation' . ($transformation->getQuery() ? ' query "' . $transformation->getQuery() . '"' : '') . ' using writer ' . get_class($transformation->getWriter()) . ' on ' . $transformation->getArtifact());
         $transformation->execute($source);
         \phpDocumentor\Event\Dispatcher::getInstance()->dispatch('transformer.transformation.post', \phpDocumentor\Transformer\Event\PostTransformationEvent::createInstance($this)->setSource($source));
     }
     \phpDocumentor\Event\Dispatcher::getInstance()->dispatch('transformer.transform.post', \phpDocumentor\Transformer\Event\PostTransformEvent::createInstance($this)->setSource($source));
 }
 /**
  * Transforms the given project into a series of artifacts as provided by the templates.
  *
  * @param ProjectDescriptor $project
  *
  * @return void
  */
 public function execute(ProjectDescriptor $project)
 {
     Dispatcher::getInstance()->dispatch('transformer.transform.pre', PreTransformEvent::createInstance($this));
     if ($this->getBehaviours() instanceof Behaviour\Collection) {
         $this->log(sprintf('Applying %d behaviours', count($this->getBehaviours())));
         $this->getBehaviours()->process($project);
     }
     $transformations = $this->getTemplates()->getTransformations();
     $this->log(sprintf('Applying %d transformations', count($transformations)));
     foreach ($transformations as $transformation) {
         $this->log('  Writer ' . $transformation->getWriter() . ($transformation->getQuery() ? ' using query "' . $transformation->getQuery() . '"' : '') . ' on ' . $transformation->getArtifact());
         $transformation->setTransformer($this);
         /** @var Writer\WriterAbstract $writer  */
         $writer = $this->writers[$transformation->getWriter()];
         Dispatcher::getInstance()->dispatch('transformer.transformation.pre', PreTransformationEvent::createInstance($this));
         $writer->transform($project, $transformation);
         Dispatcher::getInstance()->dispatch('transformer.transformation.post', PostTransformationEvent::createInstance($this));
     }
     Dispatcher::getInstance()->dispatch('transformer.transform.post', PostTransformEvent::createInstance($this));
     $this->log('Finished transformation process');
 }
Example #4
0
 /**
  * Applies the given transformation to the provided project.
  *
  * This method will attempt to find an appropriate writer for the given transformation and invoke that with the
  * transformation and project so that an artifact can be generated that matches the intended transformation.
  *
  * In addition this method will emit the following events:
  *
  * - transformer.transformation.pre, before the project has been transformed with this transformation.
  * - transformer.transformation.post, after the project has been transformed with this transformation
  *
  * @param Transformation $transformation
  * @param ProjectDescriptor $project
  *
  * @uses Dispatcher to emit the events surrounding a transformation.
  *
  * @return void
  */
 private function applyTransformationToProject(Transformation $transformation, ProjectDescriptor $project)
 {
     $this->log(sprintf('  Writer %s %s on %s', $transformation->getWriter(), $transformation->getQuery() ? ' using query "' . $transformation->getQuery() . '"' : '', $transformation->getArtifact()));
     $preTransformationEvent = PreTransformationEvent::createInstance($this)->setTransformation($transformation);
     Dispatcher::getInstance()->dispatch(self::EVENT_PRE_TRANSFORMATION, $preTransformationEvent);
     $writer = $this->writers[$transformation->getWriter()];
     $writer->transform($project, $transformation);
     $postTransformationEvent = PostTransformationEvent::createInstance($this);
     Dispatcher::getInstance()->dispatch(self::EVENT_POST_TRANSFORMATION, $postTransformationEvent);
 }