本文整理匯總了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());
}
示例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);