예제 #1
0
 public function testTemplateParser()
 {
     $app = $this->getApp();
     $loader = $app['twig.loader'];
     $app['twig']->render('error.twig', ['context' => ['class' => 'BoltResponse', 'message' => 'Clippy is bent out of shape', 'code' => '1555', 'trace' => []]]);
     $templates = Library::parseTwigTemplates($loader);
     $this->assertEquals(1, count($templates));
 }
예제 #2
0
 public function testTemplateParser()
 {
     $app = $this->getApp();
     $loader = $app['twig.loader'];
     $template = $app['twig']->render('error.twig');
     $templates = Library::parseTwigTemplates($loader);
     $this->assertEquals(1, count($templates));
     // Test deprecated function for now
     $this->assertEquals($templates, Library::hackislyParseRegexTemplates($loader));
 }
예제 #3
0
 /**
  * Collect information from Twig.
  *
  * @param Request    $request   The Request Object
  * @param Response   $response  The Response Object
  * @param \Exception $exception The Exception
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $filters = array();
     $tests = array();
     $extensions = array();
     $functions = array();
     foreach ($this->getTwig()->getExtensions() as $extensionName => $extension) {
         /** @var $extension \Twig_ExtensionInterface */
         $extensions[] = array('name' => $extensionName, 'class' => get_class($extension));
         foreach ($extension->getFilters() as $filterName => $filter) {
             if ($filter instanceof \Twig_FilterInterface) {
                 $call = $filter->compile();
                 if (is_array($call) && is_callable($call)) {
                     $call = 'Method ' . $call[1] . ' of an object ' . get_class($call[0]);
                 }
             } elseif ($filter instanceof \Twig_SimpleFilter) {
                 $call = $filter->getName();
             } else {
                 continue;
             }
             $filters[] = array('name' => $filterName, 'extension' => $extensionName, 'call' => $call);
         }
         foreach ($extension->getTests() as $testName => $test) {
             if ($test instanceof \Twig_TestInterface) {
                 $call = $test->compile();
             } elseif ($test instanceof \Twig_SimpleTest) {
                 $call = $test->getName();
             } else {
                 continue;
             }
             $tests[] = array('name' => $testName, 'extension' => $extensionName, 'call' => $call);
         }
         foreach ($extension->getFunctions() as $functionName => $function) {
             if ($function instanceof \Twig_FunctionInterface) {
                 $call = $function->compile();
             } elseif ($function instanceof \Twig_SimpleFunction) {
                 $call = $function->getName();
             } else {
                 continue;
             }
             $functions[] = array('name' => $functionName, 'extension' => $extensionName, 'call' => $call);
         }
     }
     $this->data = array('extensions' => $extensions, 'tests' => $tests, 'filters' => $filters, 'functions' => $functions, 'templates' => Lib::parseTwigTemplates($this->app['twig.loader']), 'templatechosen' => $this->getTrackedValue('templatechosen'), 'templateerror' => $this->getTrackedValue('templateerror'));
 }
예제 #4
0
 /**
  * Set up the profilers for the toolbar.
  */
 public function initProfiler()
 {
     // On 'after' attach the debug-bar, if debug is enabled.
     if (!($this['debug'] && ($this['session']->has('user') || $this['config']->get('general/debug_show_loggedoff')))) {
         error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED);
         return;
     }
     // Set the error_reporting to the level specified in config.yml
     error_reporting($this['config']->get('general/debug_error_level'));
     // Register Whoops, to handle errors for logged in users only.
     if ($this['config']->get('general/debug_enable_whoops')) {
         $this->register(new WhoopsServiceProvider());
         // Add a special handler to deal with AJAX requests
         if ($this['config']->getWhichEnd() == 'async') {
             $this['whoops']->pushHandler(new JsonResponseHandler());
         }
     }
     // Register the Silex/Symfony web debug toolbar.
     $this->register(new Silex\Provider\WebProfilerServiceProvider(), array('profiler.cache_dir' => $this['resources']->getPath('cache') . '/profiler', 'profiler.mount_prefix' => '/_profiler'));
     // Register the toolbar item for our Database query log.
     $this->register(new Provider\DatabaseProfilerServiceProvider());
     // Register the toolbar item for our bolt nipple.
     $this->register(new Provider\BoltProfilerServiceProvider());
     // Register the toolbar item for the Twig toolbar item.
     $this->register(new Provider\TwigProfilerServiceProvider());
     $this['twig.loader.filesystem'] = $this->share($this->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $filesystem, Application $app) {
         $filesystem->addPath($app['resources']->getPath('root') . '/vendor/symfony/web-profiler-bundle/Symfony/Bundle/WebProfilerBundle/Resources/views', 'WebProfiler');
         $filesystem->addPath($app['resources']->getPath('app') . '/view', 'BoltProfiler');
         return $filesystem;
     }));
     // PHP 5.3 does not allow 'use ($this)' in closures.
     $app = $this;
     $this->after(function () use($app) {
         foreach (Lib::parseTwigTemplates($app['twig.loader.filesystem']) as $template) {
             $app['twig.logger']->collectTemplateData($template);
         }
     });
 }