本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::setLazy方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::setLazy方法的具体用法?PHP Definition::setLazy怎么用?PHP Definition::setLazy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Definition
的用法示例。
在下文中一共展示了Definition::setLazy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetProxyFactoryCode
public function testGetProxyFactoryCode()
{
$definition = new Definition(__CLASS__);
$definition->setLazy(true);
$code = $this->dumper->getProxyFactoryCode($definition, 'foo');
$this->assertStringMatchesFormat('%wif ($lazyLoad) {%wreturn $this->services[\'foo\'] = new ' . 'SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest_%s(%wfunction ' . '(&$wrappedInstance, \\ProxyManager\\Proxy\\LazyLoadingInterface $proxy) {' . '%w$wrappedInstance = $this->getFooService(false);%w$proxy->setProxyInitializer(null);' . '%wreturn true;%w}%w);%w}%w', $code);
}
示例2: testProcess
public function testProcess()
{
$container = new ContainerBuilder();
$simpleFactory = new Definition();
$simpleProcessor = new Definition('Test\\SimpleProcessor');
$simpleProcessor->addTag('processor');
$abstractProcessor = new Definition();
$abstractProcessor->setAbstract(true);
$abstractProcessor->addTag('processor');
$lazyProcessor = new Definition('Test\\LazyProcessor');
$lazyProcessor->setLazy(true);
$lazyProcessor->addTag('processor');
$withArgumentsProcessor = new Definition('Test\\WithArgumentsProcessor', ['test']);
$withArgumentsProcessor->addTag('processor');
$container->addDefinitions(['simple_factory' => $simpleFactory, 'simple_processor' => $simpleProcessor, 'abstract_processor' => $abstractProcessor, 'lazy_processor' => $lazyProcessor, 'with_arguments_processor' => $withArgumentsProcessor]);
$compilerPass = new CleanUpProcessorsCompilerPass('simple_factory', 'processor');
$compilerPass->process($container);
$this->assertFalse($container->hasDefinition('simple_processor'));
$this->assertTrue($container->hasDefinition('abstract_processor'));
$this->assertTrue($container->hasDefinition('lazy_processor'));
$this->assertTrue($container->hasDefinition('with_arguments_processor'));
$methodCalls = $simpleFactory->getMethodCalls();
$this->assertCount(1, $methodCalls);
$this->assertEquals(['addProcessor', ['simple_processor', 'Test\\SimpleProcessor']], $methodCalls[0]);
}
示例3: addConnection
/**
* @param Definition $definition
* @param string $id
* @param array $tags
*/
protected function addConnection(Definition $definition, $id, $tags)
{
$definition->addMethodCall('setRequestFactory', [new Reference('ms.rpc.request_factory')]);
$definition->addMethodCall('setResponseFactory', [new Reference('ms.rpc.response_factory')]);
$definition->addMethodCall('setSerializer', [new Reference('serializer')]);
$definition->setLazy(true);
}
示例4: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$reflection = new \ReflectionClass($metadata->getClass('model'));
$translatableInterface = TranslatableInterface::class;
$translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface);
$repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName());
$repositoryClass = $translatable ? TranslatableResourceRepository::class : EntityRepository::class;
if ($container->hasParameter($repositoryClassParameterName)) {
$repositoryClass = $container->getParameter($repositoryClassParameterName);
}
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$repositoryReflection = new \ReflectionClass($repositoryClass);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)]);
$definition->setLazy(!$repositoryReflection->isFinal());
if ($metadata->hasParameter('translation')) {
$translatableRepositoryInterface = TranslatableResourceRepositoryInterface::class;
$translationConfig = $metadata->getParameter('translation');
if (interface_exists($translatableRepositoryInterface) && $repositoryReflection->implementsInterface($translatableRepositoryInterface)) {
if (isset($translationConfig['fields'])) {
$definition->addMethodCall('setTranslatableFields', [$translationConfig['fields']]);
}
}
}
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例5: addProvider
protected function addProvider(ContainerBuilder $container, $providerClass, $modelName)
{
$providerReflection = new \ReflectionClass($providerClass);
$definition = new Definition($providerClass);
$definition->setArguments([new Reference(sprintf('%s.repository.%s', $this->applicationName, $modelName)), new Reference(sprintf('%s.factory.%s', $this->applicationName, $modelName))]);
$definition->setLazy(!$providerReflection->isFinal());
$container->setDefinition(sprintf('%s.provider.%s', $this->applicationName, $modelName), $definition);
}
示例6: setMappings
/**
* @param ContainerBuilder $container
* @param $config
*/
private function setMappings(ContainerBuilder $container, $config)
{
$definition = new Definition();
$definition->setClass('NilPortugues\\Api\\Mapping\\Mapper');
$args = $this->resolveMappings($container, $config['mappings']);
$definition->setArguments($args);
$definition->setLazy(true);
$container->setDefinition('nil_portugues.api.mapping.mapper', $definition);
}
示例7: registerService
/**
* @param ContainerBuilder $container
* @param array $metadata
*/
private function registerService(ContainerBuilder $container, array $metadata)
{
$class = 'SupportYard\\FrameworkBundle\\Interceptor\\InputInterceptor';
$interceptorId = $metadata['interceptorId'];
$alias = $metadata['alias'];
$inputId = $metadata['inputId'];
$definition = new Definition($class, [new Reference('validator'), new Reference($inputId)]);
$definition->setLazy(true)->addTag('support_yard_framework.interceptor', ['alias' => $alias]);
$container->setDefinition($interceptorId, $definition);
}
示例8: createSncRedisBusCommandBus
private function createSncRedisBusCommandBus($commandBusServiceName, $config, ContainerBuilder $container)
{
$client = new Reference(sprintf('snc_redis.%s_client', $config['client']));
$serializer = new Reference($config['serializer']);
$keyGenerator = new Reference($config['key_generator']);
$service = new Definition('%rezzza_command_bus.snc_redis_bus.class%', [$client, $keyGenerator, $serializer]);
$service->setLazy(true);
// because snc redis will initiate connection, and we may not want it.
$container->setDefinition($commandBusServiceName, $service);
$defaultConsumerProvider = new Definition('%rezzza_command_bus.snc_redis_provider.class%', [$client, $keyGenerator, $serializer, $config['read_block_timeout']]);
foreach ($config['consumers'] as $consumerName => $consumerConfig) {
$this->createConsumerDefinition($consumerName, $defaultConsumerProvider, $consumerConfig, $commandBusServiceName, $container);
}
}
示例9: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$modelClass = $metadata->getClass('model');
$repositoryClass = in_array(TranslatableInterface::class, class_implements($modelClass)) ? TranslatableRepository::class : new Parameter('sylius.mongodb.odm.repository.class');
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$repositoryReflection = new \ReflectionClass($repositoryClass);
$unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
$unitOfWorkDefinition->setFactory([new Reference($this->getManagerServiceId($metadata)), 'getUnitOfWork'])->setPublic(false);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $unitOfWorkDefinition, $this->getClassMetadataDefinition($metadata)]);
$definition->setLazy(!$repositoryReflection->isFinal());
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例10: getServiceFactory
/**
* return from local cache or make a new one and put it in cache and then return it.
* @param ContainerBuilder $container
* @param string $contextName
* @returns Reference The service definition reference
*/
private function getServiceFactory(ContainerBuilder $container, $contextName)
{
if (!array_key_exists($contextName, $this->serviceDefinistions)) {
$def = new Definition();
$def->setClass('TechData\\ContextDiBundle\\Models\\Context');
$def->setLazy(TRUE);
$def->setFactoryService('tech_data_context_di.context_handler');
$def->setFactoryMethod('getContext');
$def->setArguments(array($contextName));
$id = 'tech_data_context_di.contexts.' . $contextName;
$container->setDefinition($id, $def);
$this->serviceDefinistions[$contextName] = new Reference($id);
}
return $this->serviceDefinistions[$contextName];
}
示例11: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName());
$repositoryClass = EntityRepository::class;
if ($container->hasParameter($repositoryClassParameterName)) {
$repositoryClass = $container->getParameter($repositoryClassParameterName);
}
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$repositoryReflection = new \ReflectionClass($repositoryClass);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)]);
$definition->setLazy(!$repositoryReflection->isFinal());
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例12: createOperation
/**
* Adds an operation.
*
* @param ContainerBuilder $container
* @param string $serviceId
* @param string $method
* @param bool $collection
*
* @return Reference
*/
private function createOperation(ContainerBuilder $container, $serviceId, $method, $collection)
{
if ($collection) {
$factoryMethodName = 'createCollectionOperation';
$operationId = '.collection_operation.';
} else {
$factoryMethodName = 'createItemOperation';
$operationId = '.item_operation.';
}
$operation = new Definition('Dunglas\\ApiBundle\\Api\\Operation\\Operation', [new Reference($serviceId), $method]);
$operation->setFactory([new Reference('api.operation_factory'), $factoryMethodName]);
$operation->setLazy(true);
$operationId = $serviceId . $operationId . $method;
$container->setDefinition($operationId, $operation);
return new Reference($operationId);
}
示例13: setMappings
/**
* @param ContainerBuilder $container
* @param $config
*/
private function setMappings(ContainerBuilder $container, $config)
{
if (true === \file_exists($config['mappings'])) {
$finder = new Finder();
$finder->files()->in($config['mappings']);
$loadedMappings = [];
foreach ($finder as $file) {
/* @var \Symfony\Component\Finder\SplFileInfo $file */
$mapping = \file_get_contents($file->getPathname());
$mapping = Yaml::parse($mapping);
$loadedMappings[] = $mapping['mapping'];
}
$definition = new Definition();
$definition->setClass('NilPortugues\\Api\\Mapping\\Mapper');
$args = array($loadedMappings);
$definition->setArguments($args);
$definition->setLazy(true);
$container->setDefinition('nil_portugues.api.mapping.mapper', $definition);
}
}
示例14: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$repositoryClass = new Parameter('sylius.phpcr_odm.repository.class');
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$repositoryReflection = new \ReflectionClass($repositoryClass);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)]);
$definition->setLazy(!$repositoryReflection->isFinal());
if ($metadata->hasParameter('translation')) {
$translationConfig = $metadata->getParameter('translation');
if (in_array(TranslatableRepositoryInterface::class, class_implements($repositoryClass))) {
if (isset($translationConfig['fields'])) {
$definition->addMethodCall('setTranslatableFields', [$translationConfig['fields']]);
}
}
}
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例15: getAllParameters
private function getAllParameters()
{
$service = new Definition();
$service->setClass('stdClass');
$service->setAbstract(true);
$service->setFactoryClass('stdClass');
$service->setFactoryMethod('get');
$service->setFactoryService('service.fact');
$service->setFile('/file.php');
$service->setLazy(true);
$service->addMethodCall('methodCall1');
$service->addMethodCall('methodCall2', array('arg1', 'arg2'));
$service->addMethodCall('methodCall3', array(new Reference('arg.one')));
$service->setProperty('prop1', 'val1');
$service->setProperty('prop2', new Reference('prop.one'));
$service->setPublic(false);
$service->setScope('request');
$service->setSynchronized(true);
$service->setSynthetic(true);
return new ServiceElement('service.two', $service);
}