當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。