Exemplo n.º 1
0
 /**
  * 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');
 }
Exemplo n.º 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));
 }
Exemplo n.º 3
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);
 }