Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/markup/PhabricatorMarkupEngine.php
| Show All 35 Lines | |||||
| * | * | ||||
| * @task markup Markup Pipeline | * @task markup Markup Pipeline | ||||
| * @task engine Engine Construction | * @task engine Engine Construction | ||||
| */ | */ | ||||
| final class PhabricatorMarkupEngine { | final class PhabricatorMarkupEngine { | ||||
| private $objects = array(); | private $objects = array(); | ||||
| private $viewer; | private $viewer; | ||||
| private $contextObject; | |||||
| private $version = 14; | private $version = 14; | ||||
| /* -( Markup Pipeline )---------------------------------------------------- */ | /* -( Markup Pipeline )---------------------------------------------------- */ | ||||
| /** | /** | ||||
| * Convenience method for pushing a single object through the markup | * Convenience method for pushing a single object through the markup | ||||
| * pipeline. | * pipeline. | ||||
| * | * | ||||
| * @param PhabricatorMarkupInterface The object to render. | * @param PhabricatorMarkupInterface The object to render. | ||||
| * @param string The field to render. | * @param string The field to render. | ||||
| * @param PhabricatorUser User viewing the markup. | * @param PhabricatorUser User viewing the markup. | ||||
| * @param object A context object for policy checks | |||||
| * @return string Marked up output. | * @return string Marked up output. | ||||
| * @task markup | * @task markup | ||||
| */ | */ | ||||
| public static function renderOneObject( | public static function renderOneObject( | ||||
| PhabricatorMarkupInterface $object, | PhabricatorMarkupInterface $object, | ||||
| $field, | $field, | ||||
| PhabricatorUser $viewer) { | PhabricatorUser $viewer, | ||||
| $context_object = null) { | |||||
| return id(new PhabricatorMarkupEngine()) | return id(new PhabricatorMarkupEngine()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->setContextObject($context_object) | |||||
| ->addObject($object, $field) | ->addObject($object, $field) | ||||
| ->process() | ->process() | ||||
| ->getOutput($object, $field); | ->getOutput($object, $field); | ||||
| } | } | ||||
| /** | /** | ||||
| * Queue an object for markup generation when @{method:process} is | * Queue an object for markup generation when @{method:process} is | ||||
| Show All 37 Lines | public function process() { | ||||
| $objects = array_select_keys($this->objects, $keys); | $objects = array_select_keys($this->objects, $keys); | ||||
| // Build all the markup engines. We need an engine for each field whether | // Build all the markup engines. We need an engine for each field whether | ||||
| // we have a cache or not, since we still need to postprocess the cache. | // we have a cache or not, since we still need to postprocess the cache. | ||||
| $engines = array(); | $engines = array(); | ||||
| foreach ($objects as $key => $info) { | foreach ($objects as $key => $info) { | ||||
| $engines[$key] = $info['object']->newMarkupEngine($info['field']); | $engines[$key] = $info['object']->newMarkupEngine($info['field']); | ||||
| $engines[$key]->setConfig('viewer', $this->viewer); | $engines[$key]->setConfig('viewer', $this->viewer); | ||||
| $engines[$key]->setConfig('contextObject', $this->contextObject); | |||||
| } | } | ||||
| // Load or build the preprocessor caches. | // Load or build the preprocessor caches. | ||||
| $blocks = $this->loadPreprocessorCaches($engines, $objects); | $blocks = $this->loadPreprocessorCaches($engines, $objects); | ||||
| $blocks = mpull($blocks, 'getCacheData'); | $blocks = mpull($blocks, 'getCacheData'); | ||||
| $this->engineCaches = $blocks; | $this->engineCaches = $blocks; | ||||
| ▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | /* -( Markup Pipeline )---------------------------------------------------- */ | ||||
| * @return this | * @return this | ||||
| * @task markup | * @task markup | ||||
| */ | */ | ||||
| public function setViewer(PhabricatorUser $viewer) { | public function setViewer(PhabricatorUser $viewer) { | ||||
| $this->viewer = $viewer; | $this->viewer = $viewer; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | |||||
| * Set the context object. Used to implement object permissions. | |||||
| * | |||||
| * @param The object in which context this remarkup is used. | |||||
| * @return this | |||||
| * @task markup | |||||
| */ | |||||
| public function setContextObject($object) { | |||||
| $this->contextObject = $object; | |||||
| return $this; | |||||
| } | |||||
| /* -( Engine Construction )------------------------------------------------ */ | /* -( Engine Construction )------------------------------------------------ */ | ||||
| /** | /** | ||||
| * @task engine | * @task engine | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 306 Lines • Show Last 20 Lines | |||||