/**
  * This method generates the checkstyle.xml report
  *
  * @param \DOMDocument                              $structure      XML source.
  * @param \phpDocumentor\Transformer\Transformation $transformation Transformation.
  *
  * @throws \Exception
  *
  * @return void
  */
 public function transform(\DOMDocument $structure, \phpDocumentor\Transformer\Transformation $transformation)
 {
     $artifact = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact();
     $list = $structure->getElementsByTagName('parse_markers');
     $document = new \DOMDocument();
     $document->formatOutput = true;
     $report = $document->createElement('checkstyle');
     $report->setAttribute('version', '1.3.0');
     $document->appendChild($report);
     foreach ($list as $node) {
         $file = $document->createElement('file');
         $file->setAttribute('name', $node->parentNode->getAttribute('path'));
         $report->appendChild($file);
         foreach ($node->childNodes as $error) {
             if ((string) $error->nodeName != '#text') {
                 $item = $document->createElement('error');
                 $item->setAttribute('line', $error->getAttribute('line'));
                 $item->setAttribute('severity', $error->nodeName);
                 $item->setAttribute('message', $error->textContent);
                 $item->setAttribute('source', 'phpDocumentor.phpDocumentor.phpDocumentor');
                 $file->appendChild($item);
             }
         }
     }
     $this->saveCheckstyleReport($artifact, $document);
 }
 /**
  * Copies files or folders to the Artifact location.
  *
  * @param Transformation $transformation Transformation to use as data source.
  *
  * @throws Exception
  *
  * @return void
  */
 public function executeQueryCopy(Transformation $transformation)
 {
     $path = $transformation->getSourceAsPath();
     if (!is_readable($path)) {
         throw new Exception('Unable to read the source file: ' . $path);
     }
     if (!is_writable($transformation->getTransformer()->getTarget())) {
         throw new Exception('Unable to write to: ' . dirname($transformation->getArtifact()));
     }
     $this->copyRecursive($path, $transformation->getArtifact());
 }
 /**
  * Copies files or folders to the Artifact location.
  *
  * @param Transformation $transformation Transformation to use as data source.
  *
  * @throws Exception
  *
  * @return void
  */
 public function executeQueryCopy(Transformation $transformation)
 {
     $path = $transformation->getSourceAsPath();
     if (!is_readable($path)) {
         throw new Exception('Unable to read the source file: ' . $path);
     }
     if (!is_writable($transformation->getTransformer()->getTarget())) {
         throw new Exception('Unable to write to: ' . dirname($transformation->getArtifact()));
     }
     $filesystem = new Filesystem();
     if (is_file($path)) {
         $filesystem->copy($path, $transformation->getArtifact());
     } else {
         $filesystem->mirror($path, $transformation->getArtifact());
     }
 }
Exemple #4
0
 /**
  * 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];
 }
Exemple #5
0
 /**
  * @param \phpDocumentor\Transformer\Transformation $transformation
  * @return string
  */
 protected function getDestinationPath(Transformation $transformation)
 {
     $filename = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact();
     return $filename;
 }
Exemple #6
0
 /**
  * Creates the search index at the artifact location.
  *
  * @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)
 {
     $this->createXmlIndex($structure, $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact());
 }
Exemple #7
0
 /**
  * Sets the parameters of the XSLT processor.
  *
  * @param \phpDocumentor\Transformer\Transformation $transformation Transformation.
  * @param \XSLTProcessor                      $proc           XSLTProcessor.
  *
  * @return void
  */
 public function setProcessorParameters(\phpDocumentor\Transformer\Transformation $transformation, \XSLTProcessor $proc)
 {
     foreach ($this->xsl_variables as $key => $variable) {
         // XSL does not allow both single and double quotes in a string
         if (strpos($variable, '"') !== false && strpos($variable, "'") !== false) {
             $this->log('XSLT does not allow both double and single quotes in ' . 'a variable; transforming single quotes to a character ' . 'encoded version in variable: ' . $key, \phpDocumentor\Plugin\Core\Log::WARN);
             $variable = str_replace("'", "'", $variable);
         }
         $proc->setParameter('', $key, $variable);
     }
     // add / overwrite the parameters with those defined in the
     // transformation entry
     $parameters = $transformation->getParameters();
     if (isset($parameters['variables'])) {
         /** @var \DOMElement $variable */
         foreach ($parameters['variables'] as $key => $value) {
             $proc->setParameter('', $key, $value);
         }
     }
 }
    /**
     * This method writes every source code entry in the structure file to a highlighted file.
     *
     * @param ProjectDescriptor $project        Document containing the structure.
     * @param Transformation    $transformation Transformation to execute.
     *
     * @return void
     */
    public function transform(ProjectDescriptor $project, Transformation $transformation)
    {
        $artifact = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . ($transformation->getArtifact() ? $transformation->getArtifact() : 'source');
        /** @var FileDescriptor $file */
        foreach ($project->getFiles() as $file) {
            $filename = $file->getPath();
            $source = $file->getSource();
            $root = str_repeat('../', count(explode(DIRECTORY_SEPARATOR, $filename)));
            $path = $artifact . DIRECTORY_SEPARATOR . $filename;
            if (!file_exists(dirname($path))) {
                mkdir(dirname($path), 0755, true);
            }
            $source = htmlentities($source);
            file_put_contents($path . '.html', <<<HTML
<html>
    <head>
        <script
            type="text/javascript"
            src="{$root}js/jquery-1.4.2.min.js">
        </script>
        <script
            type="text/javascript"
            src="{$root}syntax_highlighter/scripts/shCore.js">
        </script>
        <script
            type="text/javascript"
            src="{$root}syntax_highlighter/scripts/shBrushJScript.js">
        </script>
        <script
            type="text/javascript"
            src="{$root}syntax_highlighter/scripts/shBrushPhp.js">
        </script>
        <script
            type="text/javascript"
            src="{$root}syntax_highlighter/scripts/shBrushXml.js">
        </script>
        <link
            href="{$root}syntax_highlighter/styles/shCore.css" rel="stylesheet"
            type="text/css"
        />
        <link
            href="{$root}syntax_highlighter/styles/shCoreEclipse.css"
            rel="stylesheet" type="text/css"
        />
        <link
            href="{$root}syntax_highlighter/styles/shThemeWordpress.css"
            rel="stylesheet" type="text/css"
        />
    </head>
    <body>
        <pre class="brush: php">{$source}</pre>
        <script type="text/javascript">
             SyntaxHighlighter.all()
             jQuery('.gutter div').each(function(key, data){
                jQuery(data).prepend('<a name="L'+jQuery(data).text()+'"/>');
             });
        </script>
    </body>
</html>
HTML
);
        }
    }
Exemple #9
0
 /**
  * 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');
     }
 }
Exemple #10
0
 /**
  * Returns the path to the location where the artifact should be written, or null to automatically detect the
  * location using the router.
  *
  * @param Transformation $transformation
  *
  * @return string|null
  */
 private function getArtifactPath(Transformation $transformation)
 {
     return $transformation->getArtifact() ? $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact() : null;
 }
    /**
     * This method writes every source code entry in the structure file
     * to a highlighted file.
     *
     * @param \DOMDocument                        $structure      XML source.
     * @param \phpDocumentor\Transformer\Transformation $transformation Transformation.
     *
     * @throws \Exception
     *
     * @return void
     */
    public function transform(\DOMDocument $structure, \phpDocumentor\Transformer\Transformation $transformation)
    {
        $artifact = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . ($transformation->getArtifact() ? $transformation->getArtifact() : 'source');
        $xpath = new \DOMXPath($structure);
        $list = $xpath->query("/project/file[source]");
        for ($i = 0; $i < $list->length; $i++) {
            /** @var \DOMElement $element */
            $element = $list->item($i);
            $filename = $element->getAttribute('path');
            $source = gzuncompress(base64_decode($element->getElementsByTagName('source')->item(0)->nodeValue));
            $root = str_repeat('../', count(explode(DIRECTORY_SEPARATOR, $filename)));
            $path = $artifact . DIRECTORY_SEPARATOR . $filename;
            if (!file_exists(dirname($path))) {
                mkdir(dirname($path), 0755, true);
            }
            $source = htmlentities($source);
            file_put_contents($path . '.html', <<<HTML
<html>
    <head>
        <script
            type="text/javascript"
            src="{$root}js/jquery-1.4.2.min.js">
        </script>
        <script
            type="text/javascript"
            src="{$root}syntax_highlighter/scripts/shCore.js">
        </script>
        <script
            type="text/javascript"
            src="{$root}syntax_highlighter/scripts/shBrushJScript.js">
        </script>
        <script
            type="text/javascript"
            src="{$root}syntax_highlighter/scripts/shBrushPhp.js">
        </script>
        <script
            type="text/javascript"
            src="{$root}syntax_highlighter/scripts/shBrushXml.js">
        </script>
        <link
            href="{$root}syntax_highlighter/styles/shCore.css" rel="stylesheet"
            type="text/css"
        />
        <link
            href="{$root}syntax_highlighter/styles/shCoreEclipse.css"
            rel="stylesheet" type="text/css"
        />
        <link
            href="{$root}syntax_highlighter/styles/shThemeWordpress.css"
            rel="stylesheet" type="text/css"
        />
    </head>
    <body>
        <pre class="brush: php">{$source}</pre>
        <script type="text/javascript">
             SyntaxHighlighter.all()
             jQuery('.gutter div').each(function(key, data){
                jQuery(data).prepend('<a name="L'+jQuery(data).text()+'"/>');
             });
        </script>
    </body>
</html>
HTML
);
        }
    }
Exemple #12
0
 /**
  * Creates a class inheritance diagram.
  *
  * @param \DOMDocument                        $structure      Structure
  *     document used to gather data from.
  * @param \phpDocumentor\Transformer\Transformation $transformation Transformation
  *     element containing the meta-data.
  *
  * @return void
  */
 public function processClass(\DOMDocument $structure, \phpDocumentor\Transformer\Transformation $transformation)
 {
     $filename = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact();
     $graph = \phpDocumentor\GraphViz\Graph::create()->setRankSep('1.0')->setCenter('true')->setRank('source')->setRankDir('RL')->setSplines('true')->setConcentrate('true');
     $xpath = new \DOMXPath($structure);
     $qry = $xpath->query("/project/namespace");
     /** @var \DOMElement $element */
     foreach ($qry as $element) {
         $this->buildNamespaceTree($graph, $element, $xpath, '');
     }
     // link all extended relations
     $qry = $xpath->query('/project/file/interface[extends]|/project/file/class[extends]');
     /** @var \DOMElement $element */
     foreach ($qry as $element) {
         $from_name = $element->getElementsByTagName('full_name')->item(0)->nodeValue;
         $to_name = $element->getElementsByTagName('extends')->item(0)->nodeValue;
         if (!$to_name) {
             continue;
         }
         $from = $graph->findNode($from_name);
         $to = $graph->findNode($to_name);
         if ($from === null) {
             $from = \phpDocumentor\GraphViz\Node::create($from_name);
             $from->setFontColor('gray');
             $from->setLabel($from_name);
             $graph->setNode($from);
         }
         if ($to === null) {
             $to = \phpDocumentor\GraphViz\Node::create($to_name);
             $to->setFontColor('gray');
             $to->setLabel($to_name);
             $graph->setNode($to);
         }
         $edge = \phpDocumentor\GraphViz\Edge::create($from, $to);
         $edge->setArrowHead('empty');
         $graph->link($edge);
     }
     // link all implemented relations
     $qry = $xpath->query('/project/file/interface[imports]|/project/file/class[implements]');
     /** @var \DOMElement $element */
     foreach ($qry as $element) {
         $from_name = $element->getElementsByTagName('full_name')->item(0)->nodeValue;
         foreach ($element->getElementsByTagName('implements') as $implements) {
             $to_name = $implements->nodeValue;
             if (!$to_name) {
                 continue;
             }
             $from = $graph->findNode($from_name);
             $to = $graph->findNode($to_name);
             if ($from === null) {
                 $from = \phpDocumentor\GraphViz\Node::create($from_name);
                 $from->setFontColor('gray');
                 $from->setLabel(addslashes($from_name));
                 $graph->setNode($from);
             }
             if ($to === null) {
                 $to = \phpDocumentor\GraphViz\Node::create($to_name);
                 $to->setFontColor('gray');
                 $to->setLabel(addslashes($to_name));
                 $graph->setNode($to);
             }
             $edge = \phpDocumentor\GraphViz\Edge::create($from, $to);
             $edge->setStyle('dotted');
             $edge->setArrowHead('empty');
             $graph->link($edge);
         }
     }
     $graph->export('svg', $filename);
 }
 /**
  * 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);
 }