コード例 #1
0
 public function render()
 {
     $editor = new OpenInEditor();
     $structure = (object) array('structure' => array());
     $isAll = true;
     foreach (Finder::findFiles('*Test.php')->from($this->dir) as $file) {
         $relative = substr($file, strlen($this->dir) + 1);
         $cursor =& $structure;
         foreach (explode(DIRECTORY_SEPARATOR, $relative) as $d) {
             $r = isset($cursor->relative) ? $cursor->relative . DIRECTORY_SEPARATOR : NULL;
             $cursor =& $cursor->structure[$d];
             $path = $this->dir . DIRECTORY_SEPARATOR . $r . $d;
             $open = $path === $this->open;
             if ($open) {
                 $isAll = false;
             }
             $cursor = (object) array('relative' => $r . $d, 'name' => $d, 'open' => $open, 'structure' => isset($cursor->structure) ? $cursor->structure : array(), 'editor' => $editor->link($path, 1), 'mode' => is_file($path) ? 'file' : 'folder');
             if (!$cursor->structure and $cursor->mode === 'file') {
                 foreach ($this->loadMethod($path) as $l => $m) {
                     $cursor->structure[$m] = (object) array('relative' => $cursor->relative . '::' . $m, 'name' => $m, 'open' => $cursor->open and $this->method === $m, 'structure' => array(), 'editor' => $editor->link($path, $l), 'mode' => 'method');
                 }
             }
         }
         $cursor->name = $file->getBasename();
     }
     $this->template->isAll = ($isAll and $this->open !== false);
     $this->template->basePath = TemplateFactory::getBasePath();
     $this->template->structure = $structure->structure;
     $this->template->setFile(__DIR__ . '/StructureRenderer.latte');
     $this->template->render();
 }
コード例 #2
0
 /**
  * @see OpenInEditor
  * @param string
  * @param Exception
  * @return string|NULL
  */
 private function getEditorLink($path, Exception $e, $method)
 {
     if ($e->getFile() === $path) {
         return $this->editor->link($path, $e->getLine());
     }
     $last = $first = NULL;
     foreach ($e->getTrace() as $trace) {
         if ($first === NULL and isset($trace['file']) and $trace['file'] === $path) {
             $first = $this->editor->link($path, $trace['line']);
         }
         if ($trace['function'] === $method and isset($last['file']) and $last['file'] === $path) {
             return $this->editor->link($path, $last['line']);
         }
         $last = $trace;
     }
     if ($first !== NULL) {
         return $first;
     }
     if (is_file($path)) {
         $tmp = preg_grep('#function\\s+' . preg_quote($method) . '\\s*\\(#si', explode("\n", file_get_contents($path)));
         if ($tmp) {
             return $this->editor->link($path, key($tmp) + 1);
         }
     }
     return $this->editor->link($path, 1);
 }