/**
  * Build the PHPTAL engine.
  *
  * @param array $options An array of parameters used to set up the PHPTAL configuration.
  *                       Available configuration values include:
  *                       - phptal
  *                       - cache-dir
  *                       - template-dir
  */
 public function __construct(array $options = array())
 {
     if (array_key_exists('phptal', $options)) {
         $this->phptal = $options['phptal'];
         return;
     }
     $this->phptal = new \PHPTAL();
     if (array_key_exists('cache-dir', $options)) {
         $this->phptal->setPhpCodeDestination($options['cache-dir']);
     }
     if (array_key_exists('template-dir', $options)) {
         $this->phptal->setTemplateRepository($options['template-dir']);
     }
 }
 /**
  * @param ContainerInterface $container
  * @return PhptalEngine
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     if (!is_array($config) && !$config instanceof ArrayObject) {
         throw new Exception\InvalidConfigException(sprintf('"config" service must be an array or ArrayObject for the %s to be able to consume it; received %s', __CLASS__, is_object($config) ? get_class($config) : gettype($config)));
     }
     // Set debug mode
     $debug = array_key_exists('debug', $config) ? (bool) $config['debug'] : false;
     $config = $this->mergeConfig($config);
     // Create the engine instance:
     $engine = new PhptalEngine();
     // Change the compiled code destination if set in the config
     if (isset($config['cache_dir'])) {
         $engine->setPhpCodeDestination($config['cache_dir']);
     }
     // Configure the encoding
     if (isset($config['encoding'])) {
         $engine->setEncoding($config['encoding']);
     }
     // Configure the output mode
     $outputMode = isset($config['output_mode']) ? $config['output_mode'] : PHPTAL::HTML5;
     $engine->setOutputMode($outputMode);
     // Set template repositories
     if (isset($config['paths'])) {
         $engine->setTemplateRepository($config['paths']);
     }
     // Configure cache lifetime
     if (isset($config['cache_lifetime'])) {
         $engine->setCacheLifetime($config['cache_lifetime']);
     }
     // If purging of the tal template cache is enabled
     // find all template cache files and delete them
     $cachePurgeMode = isset($config['cache_purge_mode']) ? (bool) $config['cache_purge_mode'] : false;
     if ($cachePurgeMode) {
         $cacheFolder = $engine->getPhpCodeDestination();
         if (is_dir($cacheFolder)) {
             foreach (new DirectoryIterator($cacheFolder) as $cacheItem) {
                 if (strncmp($cacheItem->getFilename(), 'tpl_', 4) != 0 || $cacheItem->isdir()) {
                     continue;
                 }
                 @unlink($cacheItem->getPathname());
             }
         }
     }
     // Configure the whitespace compression mode
     $compressWhitespace = isset($config['compress_whitespace']) ? (bool) $config['compress_whitespace'] : false;
     if ($compressWhitespace) {
         $engine->addPreFilter(new PHPTAL_PreFilter_Compress());
     }
     // Strip html comments and compress un-needed whitespace
     $stripComments = isset($config['strip_comments']) ? (bool) $config['strip_comments'] : false;
     if ($stripComments) {
         $engine->addPreFilter(new PHPTAL_PreFilter_StripComments());
     }
     if ($debug) {
         $engine->setForceReparse(true);
     }
     $this->injectHelpers($engine, $container);
     return $engine;
 }
示例#3
0
 /**
  * Prep the PHPTAL object
  *
  * @param
  *            $app
  */
 public function __construct($app)
 {
     $this->app = $app;
     $this->config = $app['config'];
     $this->phptal = new \PHPTAL();
     // Override the defaults with information from config file
     $preFilters = $this->config->get('phptal.preFilters', []);
     $postFilters = $this->config->get('phptal.postFilters', []);
     $encoding = $this->config->get('phptal.translationEncoding', 'UTF-8');
     $outputMode = $this->config->get('phptal.outputMode', \PHPTAL::HTML5);
     $phpCodeDestination = $this->config->get('phptal.phpCodeDestination', $app['path.storage'] . '/framework/views');
     $forceReparse = $this->config->get('phptal.forceParse', true);
     $templateRepositories = $this->config->get('phptal.templateRepositories', $app['path.base'] . '/resources/views' . (TEMPLATE_ID ? '/' . TEMPLATE_ID : ''));
     $translationClass = $this->config->get('phptal.translationClass');
     $translationDomain = $this->config->get('phptal.translationDomain', 'messages');
     $translationLanguage = [$this->app->getLocale()];
     // Setting up translation settings
     $this->translationSettings['encoding'] = $encoding;
     if (!empty($translationClass)) {
         $this->setTranslator($translationLanguage, $translationDomain, $translationClass);
     }
     // Setting up all the filters
     if (!empty($preFilters)) {
         foreach ($preFilters as $filter) {
             $this->phptal->addPreFilter($filter);
         }
     }
     if (!empty($postFilters)) {
         $filterChain = new PHPTALFilterChain();
         foreach ($postFilters as $filter) {
             $filterChain->add($filter);
         }
         $this->phptal->setPostFilter($filterChain);
     }
     $this->phptal->setForceReparse($forceReparse);
     $this->phptal->setOutputMode($outputMode);
     $this->phptal->setTemplateRepository($templateRepositories);
     $this->phptal->setPhpCodeDestination($phpCodeDestination);
 }
示例#4
0
            $user = $dataObject;
        } else {
            $user = new World_User($userId);
        }
    } else {
        $user = new World_User($userId);
    }
    // Prüfung ob Daten geladen
    if ($user->isLoaded() === false) {
        $user = null;
    } else {
        // Module registrieren
        $user->registerModule('pokemonTeam', 'World_PokemonTeam');
        $user->registerModule('storeBox', 'World_StoreBoxContainer');
        $user->registerModule('map', 'World_Map');
        $user->registerModule('fight', 'World_Fight');
        $user->registerModule('inventory', 'World_Inventory');
        $user->registerModule('messages', 'World_Messages');
        $user->registerModule('settings', 'World_Settings');
    }
}
World_Base::$USER = $user;
// Templateinstanz erzeugen
$template = new PHPTAL();
$template->setTemplateRepository(array(TEMPLATE_PATH, ADMIN_TEMPLATE_PATH, SITE_TEMPLATE_PATH));
$template->setTemplate('index.html');
$template->viewMacro = 'world';
// Standard, ansonsten auch 'admin' für Adminoberflächen
$template->WORLD = WORLD_DIRECTORY;
$template->SESSION = World_Base::$SESSION;
$javascriptContent = array();
示例#5
0
文件: View.php 项目: jo-m/ecamp3
 /**
  * Either append or overwrite the paths used to find a template.
  *
  * Pass a string to append, pass an array of strings to overwrite.
  *
  * @param string|array $path The path / paths to use.
  *
  * @return void
  */
 public function addTemplateRepositoryPath($path)
 {
     $this->_engine->setTemplateRepository($path);
 }
示例#6
0
文件: View.php 项目: namesco/ztal
 /**
  * Returns PHPTAL output - either from a render or from the cache.
  *
  * @param string|array $template The name of the template to render or
  *                               an array with the ('src') src for a template
  *                               and a ('name') name to help identify the
  *                               template in error messages.
  *
  * @return string
  */
 public function render($template)
 {
     // Check we are fully configured and initialised.
     if ($this->_engine == null) {
         throw new \Zend_View_Exception('PHPTAL is not defined', $this);
     }
     // If a cache has been setup and content is available, return it
     if ($this->_zendPageCacheContent != false) {
         return $this->_zendPageCacheContent;
     }
     // Setup the script locations based on the view's script paths
     $this->_engine->setTemplateRepository($this->getScriptPaths());
     // Do this at this point rather than in the constructor because we don't
     // know what the template repositories are going to be at that point.
     $this->_engine->addSourceResolver(new PharResolver($this->getScriptPaths()));
     // Assign all the variables set here through to the PHPTAL engine.
     foreach ($this->getVars() as $key => $value) {
         $this->_engine->set($key, $value);
     }
     if (!is_array($template)) {
         $this->_engine->setTemplate($this->_convertTemplateName($template));
     } else {
         $this->_engine->setSource($template['src'], $template['name']);
     }
     // Setup a collection of standard variable available in the view
     $this->_engine->set('doctype', $this->doctype());
     $this->_engine->set('headTitle', $this->headTitle());
     $this->_engine->set('headScript', $this->headScript());
     $this->_engine->set('headLink', $this->headLink());
     $this->_engine->set('headMeta', $this->headMeta());
     $this->_engine->set('headStyle', $this->headStyle());
     $this->productionMode = 'production' == APPLICATION_ENV;
     // If perging of the tal template cache is enabled
     // find all template cache files and delete them
     if ($this->_purgeCacheBeforeRender) {
         $cacheFolder = $this->_engine->getPhpCodeDestination();
         if (is_dir($cacheFolder)) {
             foreach (new \DirectoryIterator($cacheFolder) as $cacheItem) {
                 if (strncmp($cacheItem->getFilename(), 'tpl_', 4) != 0 || $cacheItem->isdir()) {
                     continue;
                 }
                 @unlink($cacheItem->getPathname());
             }
         }
     }
     // if a layout is being used and nothing has already overloaded the viewContent,
     // register the content as viewContent, otherwise set it to empty
     if (!isset($this->viewContent)) {
         if ($this->getHelperPath('layout') != false && $this->layout()->isEnabled()) {
             $this->_engine->set('viewContent', $this->layout()->content);
         } else {
             $this->viewContent = '';
         }
     }
     if (!$this->_preFiltersRegistered) {
         // Strip html comments and compress un-needed whitespace
         $this->_engine->addPreFilter(new \PHPTAL_PreFilter_StripComments());
         if ($this->_compressWhitespace == true) {
             $this->_engine->addPreFilter(new \PHPTAL_PreFilter_Compress());
         }
         $this->_preFiltersRegistered = true;
     }
     try {
         $result = $this->_engine->execute();
     } catch (\PHPTAL_TemplateException $e) {
         // If the exception is a root PHPTAL_TemplateException
         // rather than a subclass of this exception and xdebug is enabled,
         // it will have already been picked up by xdebug, if enabled, and
         // should be shown like any other php error.
         // Any subclass of PHPTAL_TemplateException can be handled by
         // the phptal internal exception handler as it gives a useful
         // error output
         if (get_class($e) == 'PHPTAL_TemplateException' && function_exists('xdebug_is_enabled') && xdebug_is_enabled()) {
             exit;
         }
         throw $e;
     }
     // If the page needed to be rendered but was configured to
     // cache then cache the result of the render.
     if ($this->_zendPageCache instanceof \Zend_Cache_Core) {
         $this->_zendPageCache->save($result, $this->_zendPageCacheKey, array(), $this->_zendPageCacheDuration);
     }
     return $result;
 }