当前位置: 首页>>代码示例>>PHP>>正文


PHP Twig_Environment::initRuntime方法代码示例

本文整理汇总了PHP中Twig_Environment::initRuntime方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Environment::initRuntime方法的具体用法?PHP Twig_Environment::initRuntime怎么用?PHP Twig_Environment::initRuntime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Twig_Environment的用法示例。


在下文中一共展示了Twig_Environment::initRuntime方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     parent::setUp();
     $loader = new \Twig_Loader_Filesystem([__DIR__ . '/../../Resources/theme']);
     $cacheDir = sys_get_temp_dir() . '/twig-perf';
     if (!file_exists($cacheDir)) {
         @mkdir($cacheDir);
     }
     $this->twig = new \Twig_Environment($loader, ['debug' => true, 'strict_variables' => true, 'cache' => $cacheDir]);
     $this->extension = new DatagridExtension('datagrid.html.twig');
     $this->twig->addExtension($this->extension);
     $this->twig->initRuntime();
     // load template to ensure a compile, we are only interested in the rendering speed
     $this->twig->loadTemplate('datagrid.html.twig');
 }
开发者ID:sstok,项目名称:rollerworks-datagrid-twig,代码行数:15,代码来源:DatagridExtensionPerformanceTest.php

示例2: setUp

 protected function setUp()
 {
     parent::setUp();
     $loader = new \Twig_Loader_Filesystem([__DIR__ . '/../../Resources/theme', __DIR__ . '/../Resources/views']);
     $cacheDir = sys_get_temp_dir() . '/twig' . microtime(false);
     if (!file_exists($cacheDir)) {
         @mkdir($cacheDir);
     }
     $twig = new \Twig_Environment($loader, ['debug' => true, 'cache' => $cacheDir]);
     $twig->addGlobal('global_var', 'global_value');
     $this->twig = $twig;
     $this->extension = new DatagridExtension('datagrid.html.twig');
     $this->twig->addExtension($this->extension);
     $this->twig->initRuntime();
 }
开发者ID:sstok,项目名称:rollerworks-datagrid-twig,代码行数:15,代码来源:DatagridExtensionTest.php

示例3: testDataSourceRenderBlockFromParent

 public function testDataSourceRenderBlockFromParent()
 {
     $this->twig->addExtension($this->extension);
     $this->twig->initRuntime();
     $parent = $this->getMock('\\Twig_Template', array('hasBlock', 'render', 'display', 'getEnvironment', 'displayBlock', 'getParent', 'getTemplateName', 'doDisplay'), array($this->twig));
     $template = $this->getMock('\\Twig_Template', array('hasBlock', 'render', 'display', 'getEnvironment', 'displayBlock', 'getParent', 'getTemplateName', 'doDisplay'), array($this->twig));
     $template->expects($this->at(0))->method('hasBlock')->with('datasource_datasource_filter')->will($this->returnValue(false));
     $template->expects($this->at(1))->method('getParent')->with(array())->will($this->returnValue(false));
     $template->expects($this->at(2))->method('hasBlock')->with('datasource_filter')->will($this->returnValue(false));
     $template->expects($this->at(3))->method('getParent')->with(array())->will($this->returnValue($parent));
     $parent->expects($this->at(0))->method('hasBlock')->with('datasource_filter')->will($this->returnValue(true));
     $datasourceView = $this->getDataSourceView('datasource');
     $this->extension->setTheme($datasourceView, $template);
     $parent->expects($this->at(1))->method('displayBlock')->with('datasource_filter', array('datasource' => $datasourceView, 'vars' => array(), 'global_var' => 'global_value'))->will($this->returnValue(true));
     $this->extension->datasourceFilter($datasourceView);
 }
开发者ID:norzechowicz,项目名称:datasource-bundle,代码行数:16,代码来源:DataSourceExtensionTest.php

示例4: testDataGridColumnActionCellActionRenderBlock

 public function testDataGridColumnActionCellActionRenderBlock()
 {
     $this->twig->addExtension($this->extension);
     $this->twig->initRuntime();
     $template = $this->getMock('\\Twig_Template', array('hasBlock', 'render', 'display', 'getEnvironment', 'displayBlock', 'getParent', 'getTemplateName', 'doDisplay'), array($this->twig));
     $template->expects($this->at(0))->method('hasBlock')->with('datagrid_grid_column_type_action_cell_action_edit')->will($this->returnValue(false));
     $template->expects($this->at(1))->method('getParent')->with(array())->will($this->returnValue(false));
     $template->expects($this->at(2))->method('hasBlock')->with('datagrid_column_type_action_cell_action_edit')->will($this->returnValue(false));
     $template->expects($this->at(3))->method('getParent')->with(array())->will($this->returnValue(false));
     $template->expects($this->at(4))->method('hasBlock')->with('datagrid_grid_column_type_action_cell_action')->will($this->returnValue(false));
     $template->expects($this->at(5))->method('getParent')->with(array())->will($this->returnValue(false));
     $template->expects($this->at(6))->method('hasBlock')->with('datagrid_column_type_action_cell_action')->will($this->returnValue(true));
     $this->extension->setBaseTheme($template);
     $datagridView = $this->getDataGridView('grid');
     $cellView = $this->getColumnCellView($datagridView, 'action', 'actions', array());
     $cellView->expects($this->any())->method('getAttribute')->with('translation_domain')->will($this->returnValue(null));
     $template->expects($this->at(7))->method('displayBlock')->with('datagrid_column_type_action_cell_action', array('content' => 'content', 'attr' => array(), 'translation_domain' => null, 'field_mapping_values' => array(), 'global_var' => 'global_value'))->will($this->returnValue(true));
     $this->extension->datagridColumnActionCellActionWidget($cellView, 'edit', 'content');
 }
开发者ID:norzechowicz,项目名称:datagrid-bundle,代码行数:19,代码来源:DataGridExtensionTest.php

示例5: testGlobals

 public function testGlobals()
 {
     // globals can be added after calling getGlobals
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->addGlobal('foo', 'foo');
     $twig->getGlobals();
     $twig->addGlobal('foo', 'bar');
     $globals = $twig->getGlobals();
     $this->assertEquals('bar', $globals['foo']);
     // globals can be modified after runtime init
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->addGlobal('foo', 'foo');
     $twig->getGlobals();
     $twig->initRuntime();
     $twig->addGlobal('foo', 'bar');
     $globals = $twig->getGlobals();
     $this->assertEquals('bar', $globals['foo']);
     // globals can be modified after extensions init
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->addGlobal('foo', 'foo');
     $twig->getGlobals();
     $twig->getFunctions();
     $twig->addGlobal('foo', 'bar');
     $globals = $twig->getGlobals();
     $this->assertEquals('bar', $globals['foo']);
     // globals can be modified after extensions and runtime init
     $twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{foo}}')));
     $twig->addGlobal('foo', 'foo');
     $twig->getGlobals();
     $twig->getFunctions();
     $twig->initRuntime();
     $twig->addGlobal('foo', 'bar');
     $globals = $twig->getGlobals();
     $this->assertEquals('bar', $globals['foo']);
     $twig = new Twig_Environment($loader);
     $twig->getGlobals();
     $twig->addGlobal('foo', 'bar');
     $template = $twig->loadTemplate('index');
     $this->assertEquals('bar', $template->render(array()));
     // globals cannot be added after runtime init
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->addGlobal('foo', 'foo');
     $twig->getGlobals();
     $twig->initRuntime();
     try {
         $twig->addGlobal('bar', 'bar');
         $this->fail();
     } catch (LogicException $e) {
         $this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
     }
     // globals cannot be added after extensions init
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->addGlobal('foo', 'foo');
     $twig->getGlobals();
     $twig->getFunctions();
     try {
         $twig->addGlobal('bar', 'bar');
         $this->fail();
     } catch (LogicException $e) {
         $this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
     }
     // globals cannot be added after extensions and runtime init
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->addGlobal('foo', 'foo');
     $twig->getGlobals();
     $twig->getFunctions();
     $twig->initRuntime();
     try {
         $twig->addGlobal('bar', 'bar');
         $this->fail();
     } catch (LogicException $e) {
         $this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
     }
     // test adding globals after initRuntime without call to getGlobals
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->initRuntime();
     try {
         $twig->addGlobal('bar', 'bar');
         $this->fail();
     } catch (LogicException $e) {
         $this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
     }
 }
开发者ID:JohnnyEstilles,项目名称:Twig,代码行数:83,代码来源:EnvironmentTest.php

示例6: testGlobals

 public function testGlobals()
 {
     // globals can be added after calling getGlobals
     $twig = new Twig_Environment(new Twig_Loader_String());
     $twig->addGlobal('foo', 'foo');
     $globals = $twig->getGlobals();
     $twig->addGlobal('foo', 'bar');
     $globals = $twig->getGlobals();
     $this->assertEquals('bar', $globals['foo']);
     // globals can be modified after runtime init
     $twig = new Twig_Environment(new Twig_Loader_String());
     $twig->addGlobal('foo', 'foo');
     $globals = $twig->getGlobals();
     $twig->initRuntime();
     $twig->addGlobal('foo', 'bar');
     $globals = $twig->getGlobals();
     $this->assertEquals('bar', $globals['foo']);
     // globals can be modified after extensions init
     $twig = new Twig_Environment(new Twig_Loader_String());
     $twig->addGlobal('foo', 'foo');
     $globals = $twig->getGlobals();
     $twig->getFunctions();
     $twig->addGlobal('foo', 'bar');
     $globals = $twig->getGlobals();
     $this->assertEquals('bar', $globals['foo']);
     // globals can be modified after extensions and runtime init
     $twig = new Twig_Environment(new Twig_Loader_String());
     $twig->addGlobal('foo', 'foo');
     $globals = $twig->getGlobals();
     $twig->getFunctions();
     $twig->initRuntime();
     $twig->addGlobal('foo', 'bar');
     $globals = $twig->getGlobals();
     $this->assertEquals('bar', $globals['foo']);
     // globals cannot be added after runtime init
     $twig = new Twig_Environment(new Twig_Loader_String());
     $twig->addGlobal('foo', 'foo');
     $globals = $twig->getGlobals();
     $twig->initRuntime();
     try {
         $twig->addGlobal('bar', 'bar');
         $this->fail();
     } catch (LogicException $e) {
         $this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
     }
     // globals cannot be added after extensions init
     $twig = new Twig_Environment(new Twig_Loader_String());
     $twig->addGlobal('foo', 'foo');
     $globals = $twig->getGlobals();
     $twig->getFunctions();
     try {
         $twig->addGlobal('bar', 'bar');
         $this->fail();
     } catch (LogicException $e) {
         $this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
     }
     // globals cannot be added after extensions and runtime init
     $twig = new Twig_Environment(new Twig_Loader_String());
     $twig->addGlobal('foo', 'foo');
     $globals = $twig->getGlobals();
     $twig->getFunctions();
     $twig->initRuntime();
     try {
         $twig->addGlobal('bar', 'bar');
         $this->fail();
     } catch (LogicException $e) {
         $this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
     }
     // test adding globals after initRuntime without call to getGlobals
     $twig = new Twig_Environment(new Twig_Loader_String());
     $twig->initRuntime();
     try {
         $twig->addGlobal('bar', 'bar');
         $this->fail();
     } catch (LogicException $e) {
         $this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
     }
 }
开发者ID:rikh42,项目名称:band-framework,代码行数:78,代码来源:EnvironmentTest.php

示例7: testInitRuntimeWithAnExtensionUsingInitRuntimeDeprecation

 /**
  * @requires PHP 5.3
  */
 public function testInitRuntimeWithAnExtensionUsingInitRuntimeDeprecation()
 {
     $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
     $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime());
     $this->deprecations = array();
     set_error_handler(array($this, 'handleError'));
     $twig->initRuntime();
     $this->assertCount(1, $this->deprecations);
     $this->assertContains('Defining the initRuntime() method in the "Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime" extension is deprecated since version 1.23.', $this->deprecations[0]);
     restore_error_handler();
 }
开发者ID:bigbitecreative,项目名称:wordpress-git-content,代码行数:14,代码来源:EnvironmentTest.php

示例8: testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation

 public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation()
 {
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime());
     $twig->initRuntime();
 }
开发者ID:shota-suzuki,项目名称:Twig,代码行数:6,代码来源:EnvironmentTest.php


注:本文中的Twig_Environment::initRuntime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。