/** * Generates an array containing class to path references and then invokes * the Source specific method. * * @param \DOMDocument $structure Structure source * use as basis for the transformation. * @param \phpDocumentor\Transformer\Transformation $transformation Transformation * that supplies the meta-data for this writer. * * @return void */ public function transform(\DOMDocument $structure, \phpDocumentor\Transformer\Transformation $transformation) { // NOTE: the -V flag sends output using STDERR and STDOUT exec('dot -V 2>&1', $output, $error); if ($error != 0) { $this->log('Unable to find the `dot` command of the GraphViz package. ' . 'Is GraphViz correctly installed and present in your path?', \phpDocumentor\Plugin\Core\Log::ERR); return; } $this->node_font = $transformation->getParameter('font', 'Courier'); // add to classes $xpath = new \DOMXPath($structure); $qry = $xpath->query('//class[full_name]/..'); $class_paths = array(); /** @var \DOMElement $element */ foreach ($qry as $element) { $path = $element->getAttribute('generated-path'); foreach ($element->getElementsByTagName('class') as $class) { $class_paths[$class->getElementsByTagName('full_name')->item(0)->nodeValue] = $path; } } // add to interfaces $qry = $xpath->query('//interface[full_name]/..'); /** @var \DOMElement $element */ foreach ($qry as $element) { $path = $element->getAttribute('generated-path'); foreach ($element->getElementsByTagName('interface') as $class) { $class_paths[$class->getElementsByTagName('full_name')->item(0)->nodeValue] = $path; } } $this->class_paths = $class_paths; $type_method = 'process' . ucfirst($transformation->getSource()); $this->{$type_method}($structure, $transformation); }
/** * Calls the wkhtmltopdf executable to generate a PDF. * * @param \DOMDocument $structure Structure source * use as basis for the transformation. * @param \phpDocumentor\Transformer\Transformation $transformation Transformation * that supplies the meta-data for this writer. * * @return void */ public function transform(\DOMDocument $structure, \phpDocumentor\Transformer\Transformation $transformation) { $artifact = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact(); $transformation->setArtifact($artifact); $source = substr($transformation->getSource(), 0, 1) != DIRECTORY_SEPARATOR ? $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getSource() : $transformation->getSource(); $transformation->setSource($source); $options = ''; if ($transformation->getParameter('toc', 'false') == 'true') { $options = ' toc '; } // TODO: add parameter to provide a cover HTML // TODO: add a parameter to provide a header HTML // TODO: add a parameter to provide a footer HTML // first try if there is a wkhtmltopdf in the global path, this helps // windows users exec('wkhtmltopdf ' . $options . ' ' . $transformation->getSource() . ' ' . $transformation->getArtifact() . ' 2>&1', $output, $error); $output = implode(PHP_EOL, $output); // this notice is linux specific; if it is found no global wkhtmltopdf // was installed; try the one which is included with phpDocumentor if (strpos($output, 'wkhtmltopdf: not found') !== false) { // TODO: replace the below with a decent way to find the executable exec(dirname(__FILE__) . '/../../../src/wkhtmltopdf/wkhtmltopdf-i386 ' . $options . ' ' . $transformation->getSource() . ' ' . $transformation->getArtifact() . ' 2>&1', $output, $error); $output = implode(PHP_EOL, $output) . PHP_EOL; } // log message and output $this->log('Generating PDF file ' . $transformation->getArtifact() . ' from ' . $transformation->getSource()); $this->log($output, $error == 0 ? \phpDocumentor\Plugin\Core\Log::INFO : \phpDocumentor\Plugin\Core\Log::CRIT); // CRASH! if ($error != 0) { throw new \phpDocumentor\Plugin\Core\Exception('Conversion to PDF failed, see output for details'); } }
/** * Returns the path belonging to the template. * * @param Transformation $transformation * * @return string */ protected function getTemplatePath($transformation) { $parts = preg_split('[\\\\|/]', $transformation->getSource()); return $parts[0] . DIRECTORY_SEPARATOR . $parts[1]; }
/** * Invokes the query method contained in this class. * * @param ProjectDescriptor $project Document containing the structure. * @param Transformation $transformation Transformation to execute. * * @return void */ public function transform(ProjectDescriptor $project, Transformation $transformation) { $type_method = 'process' . ucfirst($transformation->getSource()); $this->{$type_method}($project, $transformation); }