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


PHP ContainerBuilder::compile方法代码示例

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


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

示例1: testSetOnSynchronizedService

 /**
  * Tests set with a synchronized service.
  */
 public function testSetOnSynchronizedService()
 {
     $container = new ContainerBuilder();
     $container->register('baz', 'BazClass')->setSynchronized(TRUE);
     $container->register('bar', 'BarClass')->addMethodCall('setBaz', array(new Reference('baz')));
     // Ensure that we can set services on a compiled container.
     $container->compile();
     $container->set('baz', $baz = new \BazClass());
     $this->assertSame($baz, $container->get('bar')->getBaz());
     $container->set('baz', $baz = new \BazClass());
     $this->assertSame($baz, $container->get('bar')->getBaz());
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:15,代码来源:ContainerBuilderTest.php

示例2: runApp

namespace Acquia\D8\Workshop;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\VarDumper\VarDumper;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
require __DIR__ . '../../../vendor/autoload.php';
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
$loader->load('services.yml');
$container->get('stopwatch')->start('Build container');
$container->compile();
$dump = new PhpDumper($container);
file_put_contents(__DIR__ . '/cached_container.php', $dump->dump());
$build = $container->get('stopwatch')->stop('Build container');
dump($build->getDuration() . "ms");
//runApp($container);
function runApp(ContainerBuilder $container)
{
    $container->get('stopwatch')->start('Acquia D8 Workshop');
    // Calculate.
    // Calculate something.
    $factorial = 1;
    for ($x = 100; $x >= 1; $x--) {
        $factorial = $factorial * $x;
    }
    dump($factorial);
开发者ID:janaksingh,项目名称:drupal8_example_modules,代码行数:31,代码来源:workshop_ex4.php


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