本文整理匯總了PHP中Nette\DI\Compiler::compile方法的典型用法代碼示例。如果您正苦於以下問題:PHP Compiler::compile方法的具體用法?PHP Compiler::compile怎麽用?PHP Compiler::compile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\DI\Compiler
的用法示例。
在下文中一共展示了Compiler::compile方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: fixCompile
/**
* @param \Nette\DI\Compiler $compiler
* @return string
*/
protected function fixCompile(\Nette\DI\Compiler $compiler)
{
$code = $this->compiler->compile();
if (!is_array($code)) {
return $code;
}
return implode("\n\n\n", $code);
}
示例2: compile
protected function compile()
{
$result = $this->compiler->compile();
if (is_array($result)) {
return implode("\n\n\n", $result);
}
return $result;
}
示例3: testGettingImageStorage
public function testGettingImageStorage()
{
eval($this->compiler->compile());
/** @var \Nette\DI\Container $container */
$container = new Container();
$this->assertNotNull($class = $container->getByType(\WebChemistry\Images\IImageStorage::class));
$this->assertInstanceOf(\WebChemistry\Images\IImageStorage::class, $class);
$this->assertInstanceOf(\WebChemistry\Images\AbstractStorage::class, $class);
}
示例4: testEvents
public function testEvents()
{
$this->compiler->setClassName('Container_Events');
eval($this->compiler->compile());
/** @var \Nette\DI\Container $container */
$container = new Container_Events();
/** @var _MockStorage $class */
$this->assertNotNull($class = $container->getByType(\WebChemistry\Images\IImageStorage::class));
$this->assertInstanceOf(\WebChemistry\Images\IImageStorage::class, $class);
$this->assertInstanceOf(_MockStorage::class, $class);
$events = $class->getEvents()['onCreate'];
$this->assertTrue(is_callable($events[0]));
$events[0]();
$this->assertTrue(_Events::$called);
_Events::$called = FALSE;
$this->assertTrue(is_callable($events[1]));
$events[1]();
$this->assertTrue(_Events::$called);
}
示例5: generate
/**
* @return array of (code, file[])
*/
protected function generate($class, $generator)
{
$compiler = new Compiler();
$compiler->getContainerBuilder()->setClassName($class);
$code = call_user_func_array($generator, [&$compiler]);
$code = $code ?: implode("\n\n\n", $compiler->compile());
$files = $compiler->getDependencies();
$files = call_user_func($this->filter, $files);
$files = array_combine($files, $files);
return array("<?php\n{$code}", serialize(@array_map('filemtime', $files)));
}
示例6: generate
/**
* @return array of (code, file[])
*/
protected function generate($class, $generator)
{
$compiler = new Compiler();
$compiler->getContainerBuilder()->setClassName($class);
$code = call_user_func_array($generator, array(&$compiler));
$code = $code ?: implode("\n\n\n", $compiler->compile());
$files = $compiler->getDependencies();
$files = $files ? array_combine($files, $files) : array();
// workaround for PHP 5.3 array_combine
return array("<?php\n{$code}", serialize(@array_map('filemtime', $files)));
}
示例7: generateContainer
/**
* @param Compiler $compiler
* @return string
*/
public function generateContainer(Compiler $compiler)
{
// Load configs
$loader = new Loader();
$compiler->addConfig(['parameters' => $this->parameters]);
foreach ($this->configs as $config) {
$compiler->addConfig($loader->load($config));
}
$compiler->addDependencies($loader->getDependencies());
// Exclude classes
$builder = $compiler->getContainerBuilder();
$builder->addExcludedClasses($this->excludedClasses);
// Fire events
foreach ($this->onCompile as $cb) {
call_user_func_array($cb, [$compiler]);
}
// Compile container
$classes = $compiler->compile();
$classes[0]->setExtends(PiDiContainer::class);
return implode("\n", []) . "\n\n" . implode("\n\n\n", $classes);
}
示例8: testCompile
public function testCompile()
{
$this->compiler->compile();
}
示例9: generate
/**
* @return array of (code, file[])
*/
protected function generate($class, $generator)
{
$compiler = new Compiler();
$compiler->setClassName($class);
$code = call_user_func_array($generator, [&$compiler]) ?: $compiler->compile();
return ["<?php\n{$code}", serialize($compiler->exportDependencies())];
}