[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/infrastructure/markup/interpreter/ -> PhabricatorRemarkupGraphvizBlockInterpreter.php (source)

   1  <?php
   2  
   3  final class PhabricatorRemarkupGraphvizBlockInterpreter
   4    extends PhutilRemarkupBlockInterpreter {
   5  
   6    public function getInterpreterName() {
   7      return 'dot';
   8    }
   9  
  10    public function markupContent($content, array $argv) {
  11      if (!Filesystem::binaryExists('dot')) {
  12        return $this->markupError(
  13          pht('Unable to locate the `dot` binary. Install Graphviz.'));
  14      }
  15  
  16      $width = $this->parseDimension(idx($argv, 'width'));
  17  
  18      $future = id(new ExecFuture('dot -T%s', 'png'))
  19        ->setTimeout(15)
  20        ->write(trim($content));
  21  
  22      list($err, $stdout, $stderr) = $future->resolve();
  23  
  24      if ($err) {
  25        return $this->markupError(
  26          pht(
  27            'Execution of `dot` failed (#%d), check your syntax: %s',
  28            $err,
  29            $stderr));
  30      }
  31  
  32      $file = PhabricatorFile::buildFromFileDataOrHash(
  33        $stdout,
  34        array(
  35          'name' => 'graphviz.png',
  36        ));
  37  
  38      if ($this->getEngine()->isTextMode()) {
  39        return '<'.$file->getBestURI().'>';
  40      }
  41  
  42      return phutil_tag(
  43        'img',
  44        array(
  45          'src' => $file->getBestURI(),
  46          'width' => nonempty($width, null),
  47        ));
  48    }
  49  
  50    // TODO: This is duplicated from PhabricatorEmbedFileRemarkupRule since they
  51    // do not share a base class.
  52    private function parseDimension($string) {
  53      $string = trim($string);
  54  
  55      if (preg_match('/^(?:\d*\\.)?\d+%?$/', $string)) {
  56        return $string;
  57      }
  58  
  59      return null;
  60    }
  61  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1