Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diviner/controller/DivinerAtomController.php
| Show All 29 Lines | $book = id(new DivinerBookQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withNames(array($this->bookName)) | ->withNames(array($this->bookName)) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$book) { | if (!$book) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| // TODO: This query won't load ghosts, because they'll fail `needAtoms()`. | |||||
| // Instead, we might want to load ghosts and render a message like | |||||
| // "this thing existed in an older version, but no longer does", especially | |||||
| // if we add content like comments. | |||||
| $symbol = id(new DivinerAtomQuery()) | $symbol = id(new DivinerAtomQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withBookPHIDs(array($book->getPHID())) | ->withBookPHIDs(array($book->getPHID())) | ||||
| ->withTypes(array($this->atomType)) | ->withTypes(array($this->atomType)) | ||||
| ->withNames(array($this->atomName)) | ->withNames(array($this->atomName)) | ||||
| ->withContexts(array($this->atomContext)) | ->withContexts(array($this->atomContext)) | ||||
| ->withIndexes(array($this->atomIndex)) | ->withIndexes(array($this->atomIndex)) | ||||
| ->withGhosts(false) | |||||
| ->withIsDocumentable(true) | ->withIsDocumentable(true) | ||||
| ->needAtoms(true) | ->needAtoms(true) | ||||
| ->needExtends(true) | ->needExtends(true) | ||||
| ->needChildren(true) | ->needChildren(true) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$symbol) { | if (!$symbol) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $atom = $symbol->getAtom(); | $atom = $symbol->getAtom(); | ||||
| $crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
| $crumbs->setBorder(true); | $crumbs->setBorder(true); | ||||
| $crumbs->addTextCrumb( | $crumbs->addTextCrumb( | ||||
| $book->getShortTitle(), | $book->getShortTitle(), | ||||
| '/book/'.$book->getName().'/'); | '/book/'.$book->getName().'/'); | ||||
| $atom_short_title = $atom->getDocblockMetaValue( | $atom_short_title = $atom | ||||
| 'short', | ? $atom->getDocblockMetaValue('short', $symbol->getTitle()) | ||||
| $symbol->getTitle()); | : $symbol->getTitle(); | ||||
| $crumbs->addTextCrumb($atom_short_title); | $crumbs->addTextCrumb($atom_short_title); | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader($this->renderFullSignature($symbol)) | ->setHeader($this->renderFullSignature($symbol)) | ||||
| ->addTag( | ->addTag( | ||||
| id(new PHUITagView()) | id(new PHUITagView()) | ||||
| ->setType(PHUITagView::TYPE_STATE) | ->setType(PHUITagView::TYPE_STATE) | ||||
| ->setBackgroundColor(PHUITagView::COLOR_BLUE) | ->setBackgroundColor(PHUITagView::COLOR_BLUE) | ||||
| ->setName(DivinerAtom::getAtomTypeNameString($atom->getType()))); | ->setName(DivinerAtom::getAtomTypeNameString( | ||||
| $atom ? $atom->getType() : $symbol->getType()))); | |||||
| $properties = id(new PHUIPropertyListView()); | $properties = id(new PHUIPropertyListView()); | ||||
| $group = $atom->getProperty('group'); | $group = $atom ? $atom->getProperty('group') : $symbol->getGroupName(); | ||||
| if ($group) { | if ($group) { | ||||
| $group_name = $book->getGroupName($group); | $group_name = $book->getGroupName($group); | ||||
| } else { | } else { | ||||
| $group_name = null; | $group_name = null; | ||||
| } | } | ||||
| $document = id(new PHUIDocumentView()) | |||||
| ->setBook($book->getTitle(), $group_name) | |||||
| ->setHeader($header) | |||||
| ->addClass('diviner-view') | |||||
| ->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS) | |||||
| ->appendChild($properties); | |||||
| if ($atom) { | |||||
| $this->buildDefined($properties, $symbol); | $this->buildDefined($properties, $symbol); | ||||
| $this->buildExtendsAndImplements($properties, $symbol); | $this->buildExtendsAndImplements($properties, $symbol); | ||||
| $warnings = $atom->getWarnings(); | $warnings = $atom->getWarnings(); | ||||
| if ($warnings) { | if ($warnings) { | ||||
| $warnings = id(new PHUIInfoView()) | $warnings = id(new PHUIInfoView()) | ||||
| ->setErrors($warnings) | ->setErrors($warnings) | ||||
| ->setTitle(pht('Documentation Warnings')) | ->setTitle(pht('Documentation Warnings')) | ||||
| ->setSeverity(PHUIInfoView::SEVERITY_WARNING); | ->setSeverity(PHUIInfoView::SEVERITY_WARNING); | ||||
| } | } | ||||
| $document->appendChild($warnings); | |||||
| } | |||||
| $methods = $this->composeMethods($symbol); | $methods = $this->composeMethods($symbol); | ||||
| $field = 'default'; | $field = 'default'; | ||||
| $engine = id(new PhabricatorMarkupEngine()) | $engine = id(new PhabricatorMarkupEngine()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->addObject($symbol, $field); | ->addObject($symbol, $field); | ||||
| foreach ($methods as $method) { | foreach ($methods as $method) { | ||||
| foreach ($method['atoms'] as $matom) { | foreach ($method['atoms'] as $matom) { | ||||
| $engine->addObject($matom, $field); | $engine->addObject($matom, $field); | ||||
| } | } | ||||
| } | } | ||||
| $engine->process(); | $engine->process(); | ||||
| if ($atom) { | |||||
| $content = $this->renderDocumentationText($symbol, $engine); | $content = $this->renderDocumentationText($symbol, $engine); | ||||
| $document->appendChild($content); | |||||
| } | |||||
| $toc = $engine->getEngineMetadata( | $toc = $engine->getEngineMetadata( | ||||
| $symbol, | $symbol, | ||||
| $field, | $field, | ||||
| PhutilRemarkupHeaderBlockRule::KEY_HEADER_TOC, | PhutilRemarkupHeaderBlockRule::KEY_HEADER_TOC, | ||||
| array()); | array()); | ||||
| $document = id(new PHUIDocumentView()) | if (!$atom) { | ||||
| ->setBook($book->getTitle(), $group_name) | $document->appendChild( | ||||
| ->setHeader($header) | id(new PHUIInfoView()) | ||||
| ->addClass('diviner-view') | ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ||||
| ->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS) | ->appendChild( | ||||
| ->appendChild($properties) | pht( | ||||
| ->appendChild($warnings) | 'This atom no longer exists.'))); | ||||
| ->appendChild($content); | } | ||||
| if ($atom) { | |||||
| $document->appendChild($this->buildParametersAndReturn(array($symbol))); | $document->appendChild($this->buildParametersAndReturn(array($symbol))); | ||||
| } | |||||
| if ($methods) { | if ($methods) { | ||||
| $tasks = $this->composeTasks($symbol); | $tasks = $this->composeTasks($symbol); | ||||
| if ($tasks) { | if ($tasks) { | ||||
| $methods_by_task = igroup($methods, 'task'); | $methods_by_task = igroup($methods, 'task'); | ||||
| // Add phantom tasks for methods which have a "@task" name that isn't | // Add phantom tasks for methods which have a "@task" name that isn't | ||||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | if ($methods) { | ||||
| $inner_box->appendChild($box_content); | $inner_box->appendChild($box_content); | ||||
| $section->addContent($inner_box); | $section->addContent($inner_box); | ||||
| } | } | ||||
| $document->appendChild($section); | $document->appendChild($section); | ||||
| } | } | ||||
| $section = id(new DivinerSectionView()) | $section = id(new DivinerSectionView()) | ||||
| ->setHeader(pht('Methods')); | ->setHeader(pht('Methods')); | ||||
| foreach ($methods as $spec) { | foreach ($methods as $spec) { | ||||
| $matom = last($spec['atoms']); | $matom = last($spec['atoms']); | ||||
| $method_header = id(new PHUIHeaderView()) | $method_header = id(new PHUIHeaderView()) | ||||
| ->setNoBackground(true); | ->setNoBackground(true); | ||||
| $inherited = $spec['inherited']; | $inherited = $spec['inherited']; | ||||
| if ($inherited) { | if ($inherited) { | ||||
| ▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | switch ($symbol->getType()) { | ||||
| break; | break; | ||||
| default: | default: | ||||
| return $symbol->getTitle(); | return $symbol->getTitle(); | ||||
| } | } | ||||
| $atom = $symbol->getAtom(); | $atom = $symbol->getAtom(); | ||||
| $out = array(); | $out = array(); | ||||
| if ($atom) { | |||||
| if ($atom->getProperty('final')) { | if ($atom->getProperty('final')) { | ||||
| $out[] = 'final'; | $out[] = 'final'; | ||||
| } | } | ||||
| if ($atom->getProperty('abstract')) { | if ($atom->getProperty('abstract')) { | ||||
| $out[] = 'abstract'; | $out[] = 'abstract'; | ||||
| } | } | ||||
| if ($atom->getProperty('access')) { | if ($atom->getProperty('access')) { | ||||
| $out[] = $atom->getProperty('access'); | $out[] = $atom->getProperty('access'); | ||||
| } | } | ||||
| if ($atom->getProperty('static')) { | if ($atom->getProperty('static')) { | ||||
| $out[] = 'static'; | $out[] = 'static'; | ||||
| } | } | ||||
| } | |||||
| switch ($symbol->getType()) { | switch ($symbol->getType()) { | ||||
| case DivinerAtom::TYPE_CLASS: | case DivinerAtom::TYPE_CLASS: | ||||
| case DivinerAtom::TYPE_INTERFACE: | case DivinerAtom::TYPE_INTERFACE: | ||||
| $out[] = $symbol->getType(); | $out[] = $symbol->getType(); | ||||
| break; | break; | ||||
| case DivinerAtom::TYPE_FUNCTION: | case DivinerAtom::TYPE_FUNCTION: | ||||
| switch ($atom->getLanguage()) { | switch ($atom->getLanguage()) { | ||||
| Show All 26 Lines | $out[] = phutil_tag( | ||||
| 'class' => 'diviner-atom-signature-name', | 'class' => 'diviner-atom-signature-name', | ||||
| 'href' => $anchor ? '#'.$anchor : null, | 'href' => $anchor ? '#'.$anchor : null, | ||||
| 'name' => $is_link ? null : $anchor, | 'name' => $is_link ? null : $anchor, | ||||
| ), | ), | ||||
| $symbol->getName()); | $symbol->getName()); | ||||
| $out = phutil_implode_html(' ', $out); | $out = phutil_implode_html(' ', $out); | ||||
| if ($atom) { | |||||
| $parameters = $atom->getProperty('parameters'); | $parameters = $atom->getProperty('parameters'); | ||||
| if ($parameters !== null) { | if ($parameters !== null) { | ||||
| $pout = array(); | $pout = array(); | ||||
| foreach ($parameters as $parameter) { | foreach ($parameters as $parameter) { | ||||
| $pout[] = idx($parameter, 'name', '...'); | $pout[] = idx($parameter, 'name', '...'); | ||||
| } | } | ||||
| $out = array($out, '('.implode(', ', $pout).')'); | $out = array($out, '('.implode(', ', $pout).')'); | ||||
| } | } | ||||
| } | |||||
| return phutil_tag( | return phutil_tag( | ||||
| 'span', | 'span', | ||||
| array( | array( | ||||
| 'class' => 'diviner-atom-signature', | 'class' => 'diviner-atom-signature', | ||||
| ), | ), | ||||
| $out); | $out); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines | |||||