コード例 #1
0
 private function spoofPageCode()
 {
     // Spoof all the objects we need to make a page object
     $theme = Theme::load('test');
     $page = Page::load($theme, 'index.htm');
     $layout = Layout::load($theme, 'content.htm');
     $controller = new Controller($theme);
     $parser = new CodeParser($page);
     $pageObj = $parser->source($page, $layout, $controller);
     return $pageObj;
 }
コード例 #2
0
ファイル: Controller.php プロジェクト: Tripplefix/pfadiorion
 /**
  * Renders a requested partial.
  * The framework uses this method internally.
  * @param string $partial The view to load.
  * @param array $parameters Parameter variables to pass to the view.
  * @param bool $throwException Throw an exception if the partial is not found.
  * @return mixed Partial contents or false if not throwing an exception.
  */
 public function renderPartial($name, $parameters = [], $throwException = true)
 {
     $vars = $this->vars;
     /*
      * Alias @ symbol for ::
      */
     if (substr($name, 0, 1) == '@') {
         $name = '::' . substr($name, 1);
     }
     /*
      * Process Component partial
      */
     if (strpos($name, '::') !== false) {
         list($componentAlias, $partialName) = explode('::', $name);
         /*
          * Component alias not supplied
          */
         if (!strlen($componentAlias)) {
             if ($this->componentContext !== null) {
                 $componentObj = $this->componentContext;
             } elseif (($componentObj = $this->findComponentByPartial($partialName)) === null) {
                 if ($throwException) {
                     throw new CmsException(Lang::get('cms::lang.partial.not_found_name', ['name' => $partialName]));
                 } else {
                     return false;
                 }
             }
             /*
              * Component alias is supplied
              */
         } else {
             if (($componentObj = $this->findComponentByName($componentAlias)) === null) {
                 if ($throwException) {
                     throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $componentAlias]));
                 } else {
                     return false;
                 }
             }
         }
         $partial = null;
         $this->componentContext = $componentObj;
         /*
          * Check if the theme has an override
          */
         if (strpos($partialName, '/') === false) {
             $overrideName = $componentObj->alias . '/' . $partialName;
             $partial = Partial::loadCached($this->theme, $overrideName);
         }
         /*
          * Check the component partial
          */
         if ($partial === null) {
             $partial = ComponentPartial::loadCached($componentObj, $partialName);
         }
         if ($partial === null) {
             if ($throwException) {
                 throw new CmsException(Lang::get('cms::lang.partial.not_found_name', ['name' => $name]));
             } else {
                 return false;
             }
         }
         /*
          * Set context for self access
          */
         $this->vars['__SELF__'] = $componentObj;
     } else {
         /*
          * Process theme partial
          */
         if (($partial = Partial::loadCached($this->theme, $name)) === null) {
             if ($throwException) {
                 throw new CmsException(Lang::get('cms::lang.partial.not_found_name', ['name' => $name]));
             } else {
                 return false;
             }
         }
     }
     /*
      * Run functions for CMS partials only (Cms\Classes\Partial)
      */
     if ($partial instanceof Partial) {
         $this->partialStack->stackPartial();
         $manager = ComponentManager::instance();
         foreach ($partial->settings['components'] as $component => $properties) {
             // Do not inject the viewBag component to the environment.
             // Not sure if they're needed there by the requirements,
             // but there were problems with array-typed properties used by Static Pages
             // snippets and setComponentPropertiesFromParams(). --ab
             if ($component == 'viewBag') {
                 continue;
             }
             list($name, $alias) = strpos($component, ' ') ? explode(' ', $component) : [$component, $component];
             if (!($componentObj = $manager->makeComponent($name, $this->pageObj, $properties))) {
                 throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $name]));
             }
             $componentObj->alias = $alias;
             $parameters[$alias] = $partial->components[$alias] = $componentObj;
             $this->partialStack->addComponent($alias, $componentObj);
             $this->setComponentPropertiesFromParams($componentObj, $parameters);
             $componentObj->init();
         }
         CmsException::mask($this->page, 300);
         $parser = new CodeParser($partial);
         $partialObj = $parser->source($this->page, $this->layout, $this);
         CmsException::unmask();
         CmsException::mask($partial, 300);
         $partialObj->onStart();
         $partial->runComponents();
         $partialObj->onEnd();
         CmsException::unmask();
     }
     /*
      * Render the partial
      */
     CmsException::mask($partial, 400);
     $this->loader->setObject($partial);
     $template = $this->twig->loadTemplate($partial->getFullPath());
     $result = $template->render(array_merge($this->vars, $parameters));
     CmsException::unmask();
     if ($partial instanceof Partial) {
         $this->partialStack->unstackPartial();
     }
     $this->vars = $vars;
     return $result;
 }
コード例 #3
0
 public function testNamespaces()
 {
     $theme = Theme::load('test');
     $page = Page::load($theme, 'code-namespaces.htm');
     $this->assertNotEmpty($page);
     $parser = new CodeParser($page);
     $info = $parser->parse();
     $this->assertInternalType('array', $info);
     $this->assertArrayHasKey('filePath', $info);
     $this->assertArrayHasKey('className', $info);
     $this->assertArrayHasKey('source', $info);
     $this->assertFileExists($info['filePath']);
     $controller = new Controller($theme);
     $obj = $parser->source($page, null, $controller);
     $this->assertInstanceOf('\\Cms\\Classes\\PageCode', $obj);
     $referenceFilePath = base_path() . '/tests/fixtures/cms/reference/namespaces.php';
     $this->assertFileExists($referenceFilePath);
     $referenceContents = $this->getContents($referenceFilePath);
     $referenceContents = str_replace('{className}', $info['className'], $referenceContents);
     $this->assertEquals($referenceContents, $this->getContents($info['filePath']));
 }
コード例 #4
0
ファイル: Controller.php プロジェクト: 360weboy/october
 /**
  * Initializes the custom layout and page objects.
  * @return void
  */
 protected function initCustomObjects()
 {
     $this->layoutObj = null;
     if (!$this->layout->isFallBack()) {
         CmsException::mask($this->layout, 300);
         $parser = new CodeParser($this->layout);
         $this->layoutObj = $parser->source($this->page, $this->layout, $this);
         CmsException::unmask();
     }
     CmsException::mask($this->page, 300);
     $parser = new CodeParser($this->page);
     $this->pageObj = $parser->source($this->page, $this->layout, $this);
     CmsException::unmask();
 }
コード例 #5
0
ファイル: Controller.php プロジェクト: nnmer/october
 /**
  * Renders a requested partial.
  * The framework uses this method internally.
  * @param string $partial The view to load.
  * @param array $params Parameter variables to pass to the view.
  * @param bool $throwException Throw an exception if the partial is not found.
  * @return mixed Partial contents or false if not throwing an exception.
  */
 public function renderPartial($name, $parameters = [], $throwException = true)
 {
     $vars = $this->vars;
     /*
      * Alias @ symbol for ::
      */
     if (substr($name, 0, 1) == '@') {
         $name = '::' . substr($name, 1);
     }
     /*
      * Process Component partial
      */
     if (strpos($name, '::') !== false) {
         list($componentAlias, $partialName) = explode('::', $name);
         /*
          * Component alias not supplied
          */
         if (!strlen($componentAlias)) {
             if ($this->componentContext !== null) {
                 $componentObj = $this->componentContext;
             } elseif (($componentObj = $this->findComponentByPartial($partialName)) === null) {
                 if ($throwException) {
                     throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name' => $name]));
                 } else {
                     return false;
                 }
             }
             /*
              * Component alias is supplied
              */
         } else {
             if (($componentObj = $this->findComponentByName($componentAlias)) === null) {
                 if ($throwException) {
                     throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $componentAlias]));
                 } else {
                     return false;
                 }
             }
         }
         $partial = null;
         $this->componentContext = $componentObj;
         /*
          * Check if the theme has an override
          */
         if (strpos($partialName, '/') === false) {
             $overrideName = $componentObj->alias . '/' . $partialName;
             $partial = Partial::loadCached($this->theme, $overrideName);
         }
         /*
          * Check the component partial
          */
         if ($partial === null) {
             $partial = ComponentPartial::loadCached($componentObj, $partialName);
         }
         if ($partial === null) {
             if ($throwException) {
                 throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name' => $name]));
             } else {
                 return false;
             }
         }
         /*
          * Set context for self access
          */
         $this->vars['__SELF__'] = $componentObj;
     } else {
         /*
          * Process theme partial
          */
         if (($partial = Partial::loadCached($this->theme, $name)) === null) {
             if ($throwException) {
                 throw new CmsException(Lang::get('cms::lang.partial.not_found', ['name' => $name]));
             } else {
                 return false;
             }
         }
     }
     /*
      * Run functions for CMS partials only (Cms\Classes\Partial)
      */
     if ($partial instanceof Partial) {
         $manager = ComponentManager::instance();
         foreach ($partial->settings['components'] as $component => $properties) {
             list($name, $alias) = strpos($component, ' ') ? explode(' ', $component) : [$component, $component];
             if (!($componentObj = $manager->makeComponent($name, $this->pageObj, $properties))) {
                 throw new CmsException(Lang::get('cms::lang.component.not_found', ['name' => $name]));
             }
             $componentObj->alias = $alias;
             $parameters[$alias] = $partial->components[$alias] = $componentObj;
             array_push($this->partialComponentStack, ['name' => $alias, 'obj' => $componentObj]);
             $this->setComponentPropertiesFromParameters($componentObj, $parameters);
             $componentObj->init();
             $componentObj->onInit();
             // Deprecated: Remove ithis line if year >= 2015
         }
         CmsException::mask($this->page, 300);
         $parser = new CodeParser($partial);
         $partialObj = $parser->source($this->page, $this->layout, $this);
         CmsException::unmask();
         CmsException::mask($partial, 300);
         $partialObj->onStart();
         $partial->runComponents();
         $partialObj->onEnd();
         CmsException::unmask();
     }
     /*
      * Render the parital
      */
     CmsException::mask($partial, 400);
     $this->loader->setObject($partial);
     $template = $this->twig->loadTemplate($partial->getFullPath());
     $result = $template->render(array_merge($this->vars, $parameters));
     CmsException::unmask();
     if ($partial instanceof Partial) {
         if ($this->partialComponentStack) {
             array_pop($this->partialComponentStack);
         }
     }
     $this->vars = $vars;
     $this->componentContext = null;
     return $result;
 }