Exemplo n.º 1
0
Arquivo: Pdf.php Projeto: hjr3/Docblox
 /**
  * Calls the wkhtmltopdf executable to generate a PDF.
  *
  * @param DOMDocument            $structure
  * @param DocBlox_Transformer_Transformation $transformation
  *
  * @return void
  */
 public function transform(DOMDocument $structure, DocBlox_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 docblox
     if (strpos($output, 'wkhtmltopdf: not found') !== false) {
         exec($this->getConfig()->paths->application . '/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 ? DocBlox_Core_Log::INFO : DocBlox_Core_Log::CRIT);
     // CRASH!
     if ($error != 0) {
         throw new Exception('Conversion to PDF failed, see output for details');
     }
 }
Exemplo n.º 2
0
 /**
  * Copies files or folders to the Artifact location.
  *
  * @throws Exception
  *
  * @return void
  */
 public function executeQueryCopy(DocBlox_Transformer_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()));
     }
     $transformation->getTransformer()->copyRecursive($path, $transformation->getArtifact());
 }
Exemplo n.º 3
0
 /**
  * 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 DocBlox_Transformer_Transformation $transformation Transformation.
  *
  * @throws Exception
  *
  * @return void
  */
 public function transform(DOMDocument $structure, DocBlox_Transformer_Transformation $transformation)
 {
     if (!class_exists('XSLTProcessor')) {
         throw new Exception('The XSL writer was unable to find your XSLTProcessor; ' . 'please check if you have installed the PHP XSL extension');
     }
     $artifact = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact();
     $xsl = new DOMDocument();
     $xsl->load($transformation->getSourceAsPath());
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     $proc->setParameter('', 'title', $structure->documentElement->getAttribute('title'));
     $proc->setParameter('', 'root', str_repeat('../', substr_count($transformation->getArtifact(), '/')));
     $proc->setParameter('', 'search_template', $transformation->getParameter('search', 'none'));
     $proc->setParameter('', 'version', DocBlox_Core_Abstract::VERSION);
     // check parameters for variables and add them when found
     $this->setProcessorParameters($transformation, $proc);
     // if a query is given, then apply a transformation to the artifact
     // location by replacing ($<var>} with the sluggified node-value of the
     // search result
     if ($transformation->getQuery() !== '') {
         $xpath = new DOMXPath($transformation->getTransformer()->getSource());
         $qry = $xpath->query($transformation->getQuery());
         foreach ($qry as $element) {
             $proc->setParameter('', $element->nodeName, $element->nodeValue);
             $filename = str_replace('{$' . $element->nodeName . '}', $transformation->getTransformer()->generateFilename($element->nodeValue), $artifact);
             $this->log('Processing the file: ' . $element->nodeValue . ' as ' . $filename);
             $proc->transformToURI($structure, 'file://' . $filename);
         }
     } else {
         if (substr($transformation->getArtifact(), 0, 1) == '$') {
             // not a file, it must become a variable!
             if (!isset($this->getConfig()->transformations->{'xsl.variables'})) {
                 $this->getConfig()->transformations->{'xsl-variables'} = new Zend_Config(array(), true);
             }
             $variable_name = substr($transformation->getArtifact(), 1);
             $this->getConfig()->transformations->{'xsl-variables'}->{$variable_name} = $proc->transformToXml($structure);
         } else {
             $proc->transformToURI($structure, 'file://' . $artifact);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Generates a SVG Class Diagram at the given artifact location.
  *
  * @param DOMDocument                        $structure
  * @param DocBlox_Transformer_Transformation $transformation
  *
  * @todo this method should be refactored into smaller components.
  *
  * @return void
  */
 public function processClass(DOMDocument $structure, DocBlox_Transformer_Transformation $transformation)
 {
     $filename = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact();
     // generate graphviz
     $xpath = new DOMXPath($structure);
     $qry = $xpath->query("/project/file/class|/project/file/interface");
     $extend_classes = array();
     $classes = array();
     /** @var DOMElement $element */
     foreach ($qry as $element) {
         $extends = $element->getElementsByTagName('extends')->item(0)->nodeValue;
         if (!$extends) {
             $extends = 'stdClass';
         }
         if (!isset($extend_classes[$extends])) {
             $extend_classes[$extends] = array();
         }
         $extend_classes[$extends][] = $element->getElementsByTagName('full_name')->item(0)->nodeValue;
         $classes[] = $element->getElementsByTagName('full_name')->item(0)->nodeValue;
     }
     // find root nodes, (any class not found as extend)
     foreach ($extend_classes as $extend => $class_list) {
         if (!in_array($extend, $classes)) {
             // if the extend is not in the list of classes (i.e. stdClass) then we have a root node
             $root_nodes[] = $extend;
         }
     }
     if (empty($root_nodes)) {
         $this->log('No classes have been found, and therefore no class diagram is required', Zend_Log::INFO);
         return;
     }
     // traverse root nodes upwards
     $tree['stdClass'] = $this->buildTreenode($extend_classes);
     foreach ($root_nodes as $node) {
         if ($node === 'stdClass') {
             continue;
         }
         if (!isset($tree['stdClass']['?'])) {
             $tree['stdClass']['?'] = array();
         }
         $tree['stdClass']['?'][$node] = $this->buildTreenode($extend_classes, $node);
     }
     $graph = new Image_GraphViz(true, array('rankdir' => 'RL', 'splines' => true, 'concentrate' => 'true', 'ratio' => '0.9'), 'Classes');
     $this->buildGraphNode($graph, $tree);
     // disable E_STRICT reporting on the end to prevent PEAR from throwing Strict warnings.
     $reporting = error_reporting();
     error_reporting(error_reporting() & ~E_STRICT);
     // render graph using Image_GraphViz
     $dot_file = $graph->saveParsedGraph();
     $graph->renderDotFile($dot_file, $filename);
     error_reporting($reporting);
     // add panning and zooming extension
     $svg = simplexml_load_file($filename);
     $script = $svg->addChild('script');
     $script->addAttribute('xlink:href', 'js/SVGPan.js', 'http://www.w3.org/1999/xlink');
     // for the SVGPan file to work no viewBox may be defined and the id of the first <g> node must be renamed to 'viewport'
     unset($svg['viewBox']);
     $svg->g['id'] = 'viewport';
     // save a full version
     // $svg->asXML(substr($filename, 0, -4) . '_full.svg');
     // replace width and height with 100% on non-full version
     // $svg['width']  = '100%';
     // $svg['height'] = '100%';
     $svg->asXML($filename);
 }
Exemplo n.º 5
0
 /**
  * Creates a class inheritance diagram.
  *
  * @param DOMDocument                        $structure
  * @param DocBlox_Transformer_Transformation $transformation
  *
  * @return void
  */
 public function processClass(DOMDocument $structure, DocBlox_Transformer_Transformation $transformation)
 {
     $filename = $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact();
     $graph = DocBlox_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(str_replace(array('\\', '$'), '_', $from_name));
         $to = $graph->findNode(str_replace(array('\\', '$'), '_', $to_name));
         if ($from === null) {
             $from = DocBlox_GraphViz_Node::create(str_replace(array('\\', '$'), '_', $from_name));
             $from->setFontColor('gray');
             $from->setLabel(addslashes($from_name));
             $graph->setNode($from);
         }
         if ($to === null) {
             $to = DocBlox_GraphViz_Node::create(str_replace(array('\\', '$'), '_', $to_name));
             $to->setFontColor('gray');
             $to->setLabel(addslashes($to_name));
             $graph->setNode($to);
         }
         $edge = DocBlox_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(str_replace(array('\\', '$'), '_', $from_name));
             $to = $graph->findNode(str_replace(array('\\', '$'), '_', $to_name));
             if ($from === null) {
                 $from = DocBlox_GraphViz_Node::create(str_replace(array('\\', '$'), '_', $from_name));
                 $from->setFontColor('gray');
                 $from->setLabel(addslashes($from_name));
                 $graph->setNode($from);
             }
             if ($to === null) {
                 $to = DocBlox_GraphViz_Node::create(str_replace(array('\\', '$'), '_', $to_name));
                 $to->setFontColor('gray');
                 $to->setLabel(addslashes($to_name));
                 $graph->setNode($to);
             }
             $edge = DocBlox_GraphViz_Edge::create($from, $to);
             $edge->setStyle('dotted');
             $edge->setArrowHead('empty');
             $graph->link($edge);
         }
     }
     $graph->export('svg', $filename);
     $svg = simplexml_load_file($filename);
     $script = $svg->addChild('script');
     $script->addAttribute('xlink:href', 'js/SVGPan.js', 'http://www.w3.org/1999/xlink');
     // for the SVGPan file to work no viewBox may be defined and the id of the first <g> node must be renamed to 'viewport'
     unset($svg['viewBox']);
     $svg->g['id'] = 'viewport';
     $svg->asXML($filename);
 }
Exemplo n.º 6
0
 /**
  * Creates the search index at the artifact location.
  *
  * @param DOMDocument            $structure
  * @param DocBlox_Transformer_Transformation $transformation
  *
  * @return void
  */
 public function transform(DOMDocument $structure, DocBlox_Transformer_Transformation $transformation)
 {
     $this->createXmlIndex($structure, $transformation->getTransformer()->getTarget() . DIRECTORY_SEPARATOR . $transformation->getArtifact());
 }