本文整理匯總了PHP中Symfony\Component\DependencyInjection\DefinitionDecorator::setLazy方法的典型用法代碼示例。如果您正苦於以下問題:PHP DefinitionDecorator::setLazy方法的具體用法?PHP DefinitionDecorator::setLazy怎麽用?PHP DefinitionDecorator::setLazy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\DefinitionDecorator
的用法示例。
在下文中一共展示了DefinitionDecorator::setLazy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: convert
/**
* Converts class hierarchy metadata to definition instances.
*
* @param ClassHierarchyMetadata $metadata
* @return array an array of Definition instances
*/
public function convert(ClassHierarchyMetadata $metadata)
{
static $count = 0;
$definitions = array();
$previous = null;
foreach ($metadata->classMetadata as $classMetadata) {
if (null === $previous && null === $classMetadata->parent) {
$definition = new Definition();
} else {
$definition = new DefinitionDecorator($classMetadata->parent ?: $previous->id);
}
$definition->setClass($classMetadata->name);
if (null !== $classMetadata->scope) {
$definition->setScope($classMetadata->scope);
}
if (null !== $classMetadata->public) {
$definition->setPublic($classMetadata->public);
}
if (null !== $classMetadata->abstract) {
$definition->setAbstract($classMetadata->abstract);
}
if (null !== $classMetadata->lazy) {
$definition->setLazy($classMetadata->lazy);
}
if (null !== $classMetadata->arguments) {
$definition->setArguments($classMetadata->arguments);
}
$definition->setMethodCalls($classMetadata->methodCalls);
$definition->setTags($classMetadata->tags);
$definition->setProperties($classMetadata->properties);
if (null !== $classMetadata->decorates) {
if (!method_exists($definition, 'setDecoratedService')) {
throw new InvalidAnnotationException(sprintf("decorations require symfony >=2.8 on class %s", $classMetadata->name));
}
$definition->setDecoratedService($classMetadata->decorates, $classMetadata->decoration_inner_name);
}
if (null !== $classMetadata->deprecated && method_exists($definition, 'setDeprecated')) {
$definition->setDeprecated(true, $classMetadata->deprecated);
}
if (null === $classMetadata->id) {
$classMetadata->id = '_jms_di_extra.unnamed.service_' . $count++;
}
if (0 !== count($classMetadata->initMethods)) {
foreach ($classMetadata->initMethods as $initMethod) {
$definition->addMethodCall($initMethod);
}
} elseif (null !== $classMetadata->initMethod) {
@trigger_error('ClassMetadata::$initMethod is deprecated since version 1.7 and will be removed in 2.0. Use ClassMetadata::$initMethods instead.', E_USER_DEPRECATED);
$definition->addMethodCall($classMetadata->initMethod);
}
$definitions[$classMetadata->id] = $definition;
$previous = $classMetadata;
}
return $definitions;
}
示例2: load
/** {@inheritdoc} */
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('error-handler-services.xml');
$container->setParameter('error_handler.stage', $config['stage']);
$container->setParameter('error_handler.root_dir', $config['root_dir']);
$shutdownSeverity = strtoupper($config['shutdown_severity']);
$container->setParameter('error_handler.shutdown_severity', $shutdownSeverity);
$baseErrorHandler = $container->getDefinition('base_error_handler');
$baseErrorHandler->replaceArgument(0, Severity::$SEVERITIES[$shutdownSeverity]);
$errorHandler = $container->getDefinition('error_handler');
foreach ($config['categories'] as $categoryName => $categoryConfiguration) {
if (empty($categoryConfiguration['handlers'])) {
continue;
}
foreach ($categoryConfiguration['handlers'] as $handlerName => $handlerConfiguration) {
$handlerClass = $container->getParameter(sprintf('error_handler.handler_%s.class', $handlerName));
$handlerId = sprintf('error_handler.handler.%s.%s', $categoryName, $handlerName);
$handlerDefinition = new DefinitionDecorator('error_handler.abstract.handler');
$handlerDefinition->setClass($handlerClass);
$handlerDefinition->setPublic(false);
$handlerDefinition->setLazy(true);
switch ($handlerName) {
case 'bugsnag':
$handlerDefinition->addArgument($handlerConfiguration['apiKey']);
if (isset($handlerConfiguration['endpoint'])) {
$handlerDefinition->addMethodCall('setEndpoint', array($handlerConfiguration['endpoint']));
}
if (isset($handlerConfiguration['useSSL'])) {
$handlerDefinition->addMethodCall('setUseSSL', array($handlerConfiguration['useSSL']));
}
break;
case 'raven':
$handlerDefinition->addArgument($handlerConfiguration['endpoint']);
break;
}
$container->setDefinition($handlerId, $handlerDefinition);
$errorHandler->addMethodCall('addHandler', array(new Reference($handlerId), array($categoryName)));
}
}
}