Source of file View.php
Size: 3,591 Bytes - Last Modified: 2021-12-23T10:11:42+00:00
/var/www/docs.ssmods.com/process/src/code/cronkeep/src/library/App/View.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 | <?php /** * Copyright 2014 Bogdan Ghervan * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace library\App; use \Zend\View\Renderer\RendererInterface; use \Zend\View\Resolver\ResolverInterface; /** * Implementation of a layout system similar to what other frameworks have. * Extends \Zend\View\Renderer\RendererInterface for interoperability with Zend_View. * * @author Bogdan Ghervan <bogdan.ghervan@gmail.com> * @copyright 2014 Bogdan Ghervan * @link http://github.com/cronkeep/cronkeep * @license http://opensource.org/licenses/Apache-2.0 Apache License 2.0 */ class View extends \Slim\View implements RendererInterface { /** * Local view helper cache. * * @var array */ protected $_helperCache = array(); /** * View helper manager. * * @var \Zend\View\HelperPluginManager */ protected $_helperManager = array(); /** * Class constructor. * Initializes helper manager. * * @return void */ public function __construct() { parent::__construct(); // Initialize helper manager $this->_helperManager = new \Zend\View\HelperPluginManager(); $this->_helperManager->setRenderer($this); // Inject form-related invokable helpers $helperConfig = new \Zend\Form\View\HelperConfig(); $helperConfig->configureServiceManager($this->_helperManager); } /** * Returns the template engine object. * * @return Layout */ public function getEngine() { return $this; } /** * Renders template and injects it to the layout file. * * @param string $template * @param array $data * @return string */ public function render($template, $data = null) { return parent::render($template, $data); } /** * Set the resolver used to map a template name to a resource the renderer may consume. * * @param ResolverInterface $resolver * @return Layout */ public function setResolver(ResolverInterface $resolver) { return $this; } /** * Renders template fragment in its own veriable scope. * * @param string $template * @param array $data * @return string */ public function partial($template, $data = array()) { $view = new View(); $view->setTemplatesDirectory($this->getTemplatesDirectory()); return $view->render($template, $data); } /** * Provides access to view helpers. * * @param string $method * @param array $args * @return mixed */ public function __call($method, $args) { if (!isset($this->_helperCache[$method])) { $helper = $this->_helperManager->get($method); $helper->setView($this); $this->_helperCache[$method] = $helper; } return call_user_func_array($this->_helperCache[$method], $args); } } |