/** * Invokes the query method contained in this class. * * @param ProjectDescriptor $project Document containing the structure. * @param Transformation $transformation Transformation to execute. * * @throws \InvalidArgumentException if the query is not supported. * * @return void */ public function transform(ProjectDescriptor $project, Transformation $transformation) { $artifact = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact(); $transformation->setArtifact($artifact); $method = 'executeQuery' . ucfirst($transformation->getQuery()); if (!method_exists($this, $method)) { throw new \InvalidArgumentException('The query ' . $method . ' is not supported by the FileIo writer, supported operation is "copy"'); } $this->{$method}($transformation); }
/** * This method combines the structure.xml and the given target template * and creates a static html page at the artifact location. * * @param \DOMDocument $structure * XML source. * @param \phpDocumentor\Transformer\Transformation $transformation * Transformation. * * @return void */ public function transform(\DOMDocument $structure, Transformation $transformation) { $structure = simplexml_import_dom($structure); if ($transformation->getQuery()) { $structure = $structure->xpath($transformation->getQuery()); } if (!is_array($structure)) { $structure = array($structure); } $template_path = $this->getTemplatePath($transformation); foreach ($structure as $node) { $destination = $this->getDestinationPath($node, $transformation); $this->log('Processing the file: ' . $node->nodeValue . ' as ' . $destination); $environment = $this->initializeEnvironment($node, $transformation, $destination); file_put_contents($destination, $environment->render(substr($transformation->getSource(), strlen($template_path)))); } }
/** * 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); }