本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::getCompiler方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::getCompiler方法的具体用法?PHP ContainerBuilder::getCompiler怎么用?PHP ContainerBuilder::getCompiler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::getCompiler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: then_compiler_passes_are_added
private function then_compiler_passes_are_added()
{
$passes = $this->container->getCompiler()->getPassConfig()->getBeforeOptimizationPasses();
$classes = array_map(function ($pass) {
return get_class($pass);
}, $passes);
$expectedPassClasses = array('Devhelp\\PiwikBundle\\DependencyInjection\\Compiler\\AddPiwikClientDefinition', 'Devhelp\\PiwikBundle\\DependencyInjection\\Compiler\\InsertParamsServices');
$this->assertEquals($expectedPassClasses, $classes);
}
示例2: process
public function process(ContainerBuilder $container)
{
$compiler = $container->getCompiler();
$formatter = $compiler->getLoggingFormatter();
$tags = array_unique(array_merge($container->findTags(), $this->whitelist));
foreach ($container->findUnusedTags() as $tag) {
// skip whitelisted tags
if (in_array($tag, $this->whitelist)) {
continue;
}
// check for typos
$candidates = array();
foreach ($tags as $definedTag) {
if ($definedTag === $tag) {
continue;
}
if (false !== strpos($definedTag, $tag) || levenshtein($tag, $definedTag) <= strlen($tag) / 3) {
$candidates[] = $definedTag;
}
}
$services = array_keys($container->findTaggedServiceIds($tag));
$message = sprintf('Tag "%s" was defined on service(s) "%s", but was never used.', $tag, implode('", "', $services));
if (!empty($candidates)) {
$message .= sprintf(' Did you mean "%s"?', implode('", "', $candidates));
}
$compiler->addLogMessage($formatter->format($this, $message));
}
}
示例3: process
/**
* Process the ContainerBuilder to replace ChildDefinition instances with their real Definition instances.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$this->compiler = $container->getCompiler();
$this->formatter = $this->compiler->getLoggingFormatter();
$container->setDefinitions($this->resolveArguments($container, $container->getDefinitions(), true));
}
示例4: process
/**
* Processes the ContainerBuilder for inline service definitions.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$this->compiler = $container->getCompiler();
$this->formatter = $this->compiler->getLoggingFormatter();
$this->graph = $this->compiler->getServiceReferenceGraph();
$container->setDefinitions($this->inlineArguments($container, $container->getDefinitions(), true));
}
示例5: getMethodsToAutowire
/**
* Gets the list of methods to autowire.
*
* @param string $id
* @param \ReflectionClass $reflectionClass
* @param string[] $autowiredMethods
*
* @return \ReflectionMethod[]
*/
private function getMethodsToAutowire($id, \ReflectionClass $reflectionClass, array $autowiredMethods)
{
$found = array();
$regexList = array();
foreach ($autowiredMethods as $pattern) {
$regexList[] = '/^'.str_replace('\*', '.*', preg_quote($pattern, '/')).'$/i';
}
foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
if ($reflectionMethod->isStatic()) {
continue;
}
foreach ($regexList as $k => $regex) {
if (preg_match($regex, $reflectionMethod->name)) {
$found[] = $autowiredMethods[$k];
yield $reflectionMethod;
continue 2;
}
}
}
if ($notFound = array_diff($autowiredMethods, $found)) {
$compiler = $this->container->getCompiler();
$compiler->addLogMessage($compiler->getLoggingFormatter()->formatUnusedAutowiringPatterns($this, $id, $notFound));
}
}
示例6: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if (!$this->integrationExtension->isTransactionalAutoGenerateProxy()) {
// Transactional system or auto generate proxy is disabled
return;
}
$transactionalId = $this->integrationExtension->getTransactionalService();
// Validate transactional service
$transactionalDefinition = $container->getDefinition($transactionalId);
$class = $transactionalDefinition->getClass();
try {
$class = $container->getParameterBag()->resolveValue($class);
$refClass = new \ReflectionClass($class);
$requiredInterface = 'FivePercent\\Component\\Transactional\\TransactionalInterface';
if (!$refClass->implementsInterface($requiredInterface)) {
throw new \RuntimeException(sprintf('The transactional service with class "%s" should implement %s.', $class, $requiredInterface));
}
} catch (\Exception $e) {
throw new \RuntimeException(sprintf('The transactional service with id "%s" is invalid.', $transactionalId), 0, $e);
}
// Get all services
$serviceIds = $container->getServiceIds();
$directory = $container->getParameter('kernel.cache_dir') . '/transactional';
foreach ($serviceIds as $serviceId) {
if ($container->hasAlias($serviceId)) {
// Not check in alias.
continue;
}
$serviceDefinition = $container->getDefinition($serviceId);
if ($serviceDefinition->isAbstract()) {
// Not check in abstract service.
continue;
}
$class = $serviceDefinition->getClass();
$class = $container->getParameterBag()->resolveValue($class);
if (!$class) {
continue;
}
try {
$proxyCodeGenerator = new ProxyFileGenerator($directory, $class);
} catch (\ReflectionException $e) {
$container->getCompiler()->addLogMessage(sprintf('%s Error with create proxy code generator for class "%s". Maybe class not found?', get_class($this), $class));
continue;
}
if ($proxyCodeGenerator->needGenerate()) {
// Generate proxy file
$filePath = $proxyCodeGenerator->generate();
$serviceDefinition->setClass($proxyCodeGenerator->getProxyClassName());
// Add "__setTransactional" method call for set transactional layer
$methodCalls = $serviceDefinition->getMethodCalls();
array_unshift($methodCalls, ['___setTransactional', [new Reference($transactionalId)]]);
$serviceDefinition->setMethodCalls($methodCalls);
// Add resource for control cache
$container->addResource(new FileResource($filePath));
$realClassReflection = new \ReflectionClass($class);
$container->addResource(new FileResource($realClassReflection->getFileName()));
}
}
}
示例7: process
/**
* Processes the ContainerBuilder for inline service definitions.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$this->graph = $container->getCompiler()->getServiceReferenceGraph();
foreach ($container->getDefinitions() as $definition) {
$definition->setArguments($this->inlineArguments($container, $definition->getArguments()));
$definition->setMethodCalls($this->inlineArguments($container, $definition->getMethodCalls()));
}
}
示例8: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (FALSE === $container->hasDefinition('webprofiler.services')) {
return;
}
$definition = $container->getDefinition('webprofiler.services');
$graph = $container->getCompiler()->getServiceReferenceGraph();
$definition->addMethodCall('setServices', [$this->extractData($container, $graph)]);
}
示例9: process
/**
* Checks the ContainerBuilder object for circular references.
*
* @param ContainerBuilder $container The ContainerBuilder instances
*/
public function process(ContainerBuilder $container)
{
$graph = $container->getCompiler()->getServiceReferenceGraph();
foreach ($graph->getNodes() as $id => $node) {
$this->currentId = $id;
$this->currentPath = array($id);
$this->checkOutEdges($node->getOutEdges());
}
}
示例10: build
public function build(ContainerBuilder $container)
{
$config = $container->getCompiler()->getPassConfig();
$passes = $config->getBeforeOptimizationPasses();
array_unshift($passes, new AnnotationConfigurationPass($this->kernel));
$config->setBeforeOptimizationPasses($passes);
$container->addCompilerPass(new IntegrationPass());
$container->addCompilerPass(new ResourceOptimizationPass(), PassConfig::TYPE_AFTER_REMOVING);
}
示例11: registerLegacyPass
private function registerLegacyPass(ContainerBuilder $container)
{
$passConfig = $container->getCompiler()->getPassConfig();
$passConfig->setAfterRemovingPasses(array());
$passConfig->setBeforeOptimizationPasses(array());
$passConfig->setBeforeRemovingPasses(array());
$passConfig->setOptimizationPasses(array());
$passConfig->setRemovingPasses(array());
$container->addCompilerPass(new LegacyPass());
}
示例12: process
/**
* Process the repeatable passes that run more than once.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$compiler = $container->getCompiler();
$this->repeat = false;
foreach ($this->passes as $pass) {
$pass->process($container);
}
if ($this->repeat) {
$this->process($container);
}
}
示例13: process
/**
* Removes abstract definitions from the ContainerBuilder
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$compiler = $container->getCompiler();
$formatter = $compiler->getLoggingFormatter();
foreach ($container->getDefinitions() as $id => $definition) {
if ($definition->isAbstract()) {
$container->removeDefinition($id);
$compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'abstract'));
}
}
}
示例14: process
/**
* Processes the ContainerBuilder for inline service definitions.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$this->compiler = $container->getCompiler();
$this->formatter = $this->compiler->getLoggingFormatter();
$this->graph = $this->compiler->getServiceReferenceGraph();
foreach ($container->getDefinitions() as $id => $definition) {
$this->currentId = $id;
$definition->setArguments($this->inlineArguments($container, $definition->getArguments()));
$definition->setMethodCalls($this->inlineArguments($container, $definition->getMethodCalls()));
$definition->setProperties($this->inlineArguments($container, $definition->getProperties()));
}
}
示例15: process
public function process(ContainerBuilder $container)
{
$compiler = $container->getCompiler();
$this->repeat = false;
foreach ($this->passes as $pass) {
$time = microtime(true);
$pass->process($container);
$compiler->addLogMessage(sprintf('%s finished in %.3fs', get_class($pass), microtime(true) - $time));
}
if ($this->repeat) {
$this->process($container);
}
}