setParser() public method

Sets the Parser instance.
public setParser ( Twig_ParserInterface $parser )
$parser Twig_ParserInterface
Example #1
0
 /**
  * Create twig environment with the options specified in the curry cms configuration.
  *
  * @param Twig_LoaderInterface $loader
  * @return Twig_Environment
  */
 private static function createTwigEnvironment(Twig_LoaderInterface $loader)
 {
     $options = Curry_Core::$config->curry->template->options->toArray();
     $twig = new Twig_Environment($loader, $options);
     $twig->setParser(new Curry_Twig_Parser($twig));
     $twig->addTokenParser(new Curry_Twig_TokenParser_Placeholder());
     $twig->addTokenParser(new Curry_Twig_TokenParser_Ia());
     $twig->addFunction('url', new Twig_Function_Function('url'));
     $twig->addFunction('L', new Twig_Function_Function('L'));
     $twig->addFunction('round', new Twig_Function_Function('round'));
     $twig->addFilter('ldate', new Twig_Filter_Function('Curry_Twig_Template::ldate'));
     $twig->addFilter('dump', new Twig_Filter_Function('var_dump'));
     return $twig;
 }
Example #2
0
 public function boot()
 {
     // Create services
     $this->singleton('logger', array($this, 'getLogger'));
     $this->singleton('cache', array($this, 'getCache'));
     $this->singleton('index', array($this, 'getIndex'));
     $this->singleton('autoloader', array($this, 'getAutoloader'));
     // some more
     $app = $this;
     $this->singleton('dispatcher', function () use($app) {
         return new EventDispatcher();
     });
     $this->singleton('resolver', function () use($app) {
         return new ControllerResolver($app->logger);
     });
     $this->singleton('kernel', function () use($app) {
         return new HttpKernel($app->dispatcher, $app->resolver, $app->requestStack);
     });
     $this->singleton('requestStack', function () use($app) {
         return new RequestStack();
     });
     $this->singleton('backend', function () use($app) {
         return new Backend($app);
     });
     $this->singleton('whoopsHandler', function () use($app) {
         if (PHP_SAPI === 'cli') {
             return new PlainTextHandler();
         } else {
             if ($this['developmentMode']) {
                 return new PrettyPageHandler();
             } else {
                 return new CallbackHandler(array($app, 'showException'));
             }
         }
     });
     $this->singleton('whoops', function () use($app) {
         $whoops = new \Whoops\Run();
         $whoops->pushHandler($app->whoopsHandler);
         // Send error mail
         if ($app['errorNotification']) {
             $whoops->pushHandler(array($app, 'sendErrorNotification'));
         }
         // Add error to log
         $whoops->pushHandler(function (\Exception $e) use($app) {
             $app->logger->error($e->getMessage(), array('exception' => $e));
             return Handler::DONE;
         });
         return $whoops;
     });
     $this->singleton('twig', function () use($app) {
         $loader = new \Twig_Loader_Filesystem($app['template.root']);
         $options = $app['template.options'];
         $twig = new \Twig_Environment($loader, $options);
         $twig->setParser(new \Curry_Twig_Parser($twig));
         $twig->addTokenParser(new \Curry_Twig_TokenParser_Placeholder());
         $twig->addTokenParser(new \Curry_Twig_TokenParser_Ia());
         $twig->addFunction('url', new \Twig_Function_Function('url'));
         $twig->addFunction('L', new \Twig_Function_Function('L'));
         $twig->addFunction('round', new \Twig_Function_Function('round'));
         $twig->addFilter('ldate', new \Twig_Filter_Function('\\Curry\\App::ldate'));
         $twig->addFilter('dump', new \Twig_Filter_Function('var_dump'));
         return $twig;
     });
     $this->whoops->register();
     if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
         $this->logger->warning('Magic quotes gpc is enabled, please disable!');
     }
     // TODO: remove this!
     $this->globals = (object) array('ProjectName' => $this['name'], 'BaseUrl' => $this['baseUrl'], 'DevelopmentMode' => $this['developmentMode']);
     // Try to set utf-8 locale
     $arguments = (array) $this['locale'];
     array_unshift($arguments, LC_ALL);
     $locale = call_user_func_array('setlocale', $arguments);
     $this->logger->debug($locale ? 'Set default locale to ' . $locale : 'Unable to set default locale');
     // Set default umask
     if ($this['umask'] !== false) {
         umask($this['umask']);
     }
     self::initErrorHandling();
     self::initPropel();
     URL::setDefaultBaseUrl($this['baseUrl']);
     URL::setDefaultSecret($this['secret']);
     if ($this['autoPublish']) {
         $this->autoPublish();
     }
     if ($this['sharedController']) {
         $this->logger->notice('Using php routing for curry shared folder');
         $this->dispatcher->addSubscriber(new StaticContent('/shared/', $app['basePath'] . '/shared'));
     }
     if ($app['backend.basePath']) {
         $this->dispatcher->addSubscriber($app->backend);
     }
     if (class_exists('Page')) {
         $this->dispatcher->addSubscriber(new Frontend($this));
     }
     $this->dispatcher->addSubscriber(new FileNotFound($this));
     $this->dispatcher->addSubscriber(new Generator\ModuleProfiler($app->logger));
     $this->dispatcher->addSubscriber(new Generator\ModuleCacher($app->cache));
     $this->dispatcher->addSubscriber(new Generator\ModuleHtmlHead());
     $this->dispatcher->addSubscriber(new Generator\LiveEdit($this));
 }