本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::setFactoryMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::setFactoryMethod方法的具体用法?PHP Definition::setFactoryMethod怎么用?PHP Definition::setFactoryMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Definition
的用法示例。
在下文中一共展示了Definition::setFactoryMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('html_purifier.xml');
/* Prepend the default configuration. This cannot be defined within the
* Configuration class, since the root node's children are array
* prototypes.
*
* This cache path may be suppressed by either unsetting the "default"
* configuration (relying on canBeUnset() on the prototype node) or
* setting the "Cache.SerializerPath" option to null.
*/
array_unshift($configs, array('default' => array('Cache.SerializerPath' => '%kernel.cache_dir%/htmlpurifier')));
$configs = $this->processConfiguration(new Configuration(), $configs);
$configs = array_map(array($this, 'resolveServices'), $configs);
$paths = array();
foreach ($configs as $name => $config) {
$configDefinition = new Definition('%exercise_html_purifier.config.class%');
$configDefinition->setFactoryClass('%exercise_html_purifier.config.class%');
if ('default' === $name) {
$configDefinition->setFactoryMethod('create')->addArgument($config);
} else {
$configDefinition->setFactoryMethod('inherit')->addArgument(new Reference('exercise_html_purifier.config.default'))->addMethodCall('loadArray', array($config));
}
$configId = 'exercise_html_purifier.config.' . $name;
$container->setDefinition($configId, $configDefinition);
$container->setDefinition('exercise_html_purifier.' . $name, new Definition('%exercise_html_purifier.class%', array(new Reference($configId))));
if (isset($config['Cache.SerializerPath'])) {
$paths[] = $config['Cache.SerializerPath'];
}
}
$container->setParameter('exercise_html_purifier.cache_warmer.serializer.paths', array_unique($paths));
}
示例2: reflectDefinition
protected function reflectDefinition($reflClass)
{
$definition = new Definition($reflClass->getName());
if ($annot = $this->reader->getClassAnnotation($reflClass, 'LoSo\\Symfony\\Component\\DependencyInjection\\Loader\\Annotation\\Service')) {
$id = $this->extractServiceName($reflClass, $annot);
if (isset($annot->shared)) {
$definition->setShared($annot->shared);
}
if (isset($annot->factoryMethod)) {
$definition->setFactoryMethod($annot->factoryMethod);
}
if (isset($annot->factoryService)) {
$definition->setFactoryService($annot->factoryService);
}
foreach ($annot->tags as $tag) {
$name = $tag['name'];
unset($tag['name']);
$definition->addTag($name, $tag);
}
$this->reflectProperties($reflClass, $definition);
$this->reflectMethods($reflClass, $definition);
$this->reflectConstructor($reflClass, $definition);
$this->container->setDefinition($id, $definition);
}
}
示例3: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$def = $container->getDefinition('socloz.nsq');
if ($config['lookupd_hosts']) {
$container->setDefinition('socloz.nsq.lookup', new Definition('nsqphp\\Lookup\\Nsqlookupd', array($config['lookupd_hosts'])));
}
$def->addMethodCall('setDelayedMessagesTopic', array($config['delayed_messages_topic']));
$def->addMethodCall('setStubMode', array($config['stub']));
foreach ($config['topics'] as $name => $conf) {
$def->addMethodCall('setTopic', array($name, $conf));
if ($conf['consumers']) {
foreach ($conf['consumers'] as $channel => $service) {
$def->addMethodCall('setTopicConsumer', array($name, $channel, new Reference($service)));
}
}
$tsd = new Definition('Socloz\\NsqBundle\\Topic\\Topic', array($name));
$tsd->setFactoryService('socloz.nsq');
$tsd->setFactoryMethod('getTopic');
$container->setDefinition('socloz.nsq.topic.' . $name, $tsd);
}
}
示例4: getEntityMetadataDefinition
public function getEntityMetadataDefinition($entity, $entityManager)
{
$definition = new Definition('Doctrine\\ORM\\Mapping\\ClassMetadata');
$definition->setFactoryService($this->resolveEntityManagerId($entityManager));
$definition->setFactoryMethod('getClassMetadata');
$definition->setArguments(array($entity));
return $definition;
}
示例5: loadDoctrine
private function loadDoctrine(ContainerBuilder $container, $config)
{
$this->loadConfiguration($container, $config);
$definition = new Definition('Doctrine\\DBAL\\Connection', array(array('driver' => 'pdo_sqlite', 'memory' => true), new Reference('doctrine.configuration')));
$definition->setFactoryClass('Doctrine\\DBAL\\DriverManager');
$definition->setFactoryMethod('getConnection');
$container->setDefinition('doctrine.connection', $definition);
}
示例6: buildUseCaseProxyFactoryDefinition
private function buildUseCaseProxyFactoryDefinition($taggedServiceName, $tagParameters)
{
$definition = $this->container->findDefinition($taggedServiceName);
$factoryDefinition = new Definition();
$factoryDefinition->setFactoryService('openclassrooms.use_case.use_case_proxy_factory');
$factoryDefinition->setFactoryMethod('create');
$factoryDefinition->setArguments(array($definition, $tagParameters[0]));
$this->container->setDefinition($taggedServiceName, $factoryDefinition);
}
示例7: loadDoctrine
private function loadDoctrine(ContainerBuilder $container, $config)
{
$this->loadConfiguration($container, $config);
$this->loadEventManager($container, $config);
$definition = new Definition('Doctrine\\ORM\\EntityManager', array(array('driver' => 'pdo_sqlite', 'memory' => true), new Reference('doctrine.configuration'), new Reference('doctrine.event_manager')));
$definition->setFactoryClass('Doctrine\\ORM\\EntityManager');
$definition->setFactoryMethod('create');
$container->setDefinition('doctrine', $definition);
}
示例8: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
$driver = $container->getDefinition('prezent_doctrine_translatable.driver_chain');
foreach ($container->getParameter('doctrine.entity_managers') as $name => $manager) {
$adapter = new Definition('Metadata\\Driver\\DriverInterface', array(new Reference(sprintf('doctrine.orm.%s_metadata_driver', $name))));
$adapter->setFactoryClass('Prezent\\Doctrine\\Translatable\\Mapping\\Driver\\DoctrineAdapter');
$adapter->setFactoryMethod('fromMetadataDriver');
$driver->addMethodCall('addDriver', array($adapter));
}
}
示例9: resolveString
public function resolveString($value, array $resolved = array())
{
if (preg_match('/\\&([^\\&\\s]+)\\&$/', $value, $match)) {
$definition = new Definition();
$definition->setFactoryService('service_container');
$definition->setFactoryMethod('getVariable');
$definition->setArguments(array($match[1]));
return $definition;
}
return $value;
}
示例10: testResolveFactoryService
/**
* @group legacy
*/
public function testResolveFactoryService()
{
$container = new ContainerBuilder();
$container->register('factory', 'Factory');
$container->setAlias('factory_alias', new Alias('factory'));
$foo = new Definition();
$foo->setFactoryService('factory_alias');
$foo->setFactoryMethod('createFoo');
$container->setDefinition('foo', $foo);
$this->process($container);
$this->assertSame('factory', $foo->getFactoryService());
}
示例11: createGateway
/**
* @param ContainerBuilder $container
* @param $gatewayName
* @param array $config
*
* @return Definition
*/
protected function createGateway(ContainerBuilder $container, $gatewayName, array $config)
{
$gatewayFactoryClass = $this->getPayumGatewayFactoryClass();
if (false == class_exists($gatewayFactoryClass)) {
throw new RuntimeException(sprintf('Cannot find gateway factory class. Have you installed %s or payum/payum package?', $this->getComposerPackage()));
}
$config['payum.gateway_name'] = $gatewayName;
$gateway = new Definition('Payum\\Core\\Gateway', array($config));
$gateway->setFactoryService(sprintf('payum.%s.factory', $this->getName()));
$gateway->setFactoryMethod('create');
return $gateway;
}
示例12: create
/**
* {@inheritDoc}
*/
public function create(ContainerBuilder $container, $resolverName, array $config)
{
$awsS3ClientDefinition = new Definition('Aws\S3\S3Client');
$awsS3ClientDefinition->setFactoryClass('Aws\S3\S3Client');
$awsS3ClientDefinition->setFactoryMethod('factory');
$awsS3ClientDefinition->addArgument($config['client_config']);
$awsS3ClientId = 'liip_imagine.cache.resolver.'.$resolverName.'.client';
$container->setDefinition($awsS3ClientId, $awsS3ClientDefinition);
$resolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.aws_s3');
$resolverDefinition->replaceArgument(0, new Reference($awsS3ClientId));
$resolverDefinition->replaceArgument(1, $config['bucket']);
$resolverDefinition->replaceArgument(2, $config['acl']);
$resolverDefinition->replaceArgument(3, array_replace($config['url_options'], $config['get_options']));
$resolverDefinition->replaceArgument(4, $config['put_options']);
$resolverId = 'liip_imagine.cache.resolver.'.$resolverName;
$container->setDefinition($resolverId, $resolverDefinition);
if (isset($config['cache_prefix'])) {
$resolverDefinition->addMethodCall('setCachePrefix', array($config['cache_prefix']));
}
if ($config['proxies']) {
$proxiedResolverId = 'liip_imagine.cache.resolver.'.$resolverName.'.proxied';
$container->setDefinition($proxiedResolverId, $resolverDefinition);
$proxyResolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.proxy');
$proxyResolverDefinition->replaceArgument(0, new Reference($proxiedResolverId));
$proxyResolverDefinition->replaceArgument(1, $config['proxies']);
$container->setDefinition($resolverId, $proxyResolverDefinition);
}
if ($config['cache']) {
$cachedResolverId = 'liip_imagine.cache.resolver.'.$resolverName.'.cached';
$container->setDefinition($cachedResolverId, $container->getDefinition($resolverId));
$cacheResolverDefinition = new DefinitionDecorator('liip_imagine.cache.resolver.prototype.cache');
$cacheResolverDefinition->replaceArgument(0, new Reference($config['cache']));
$cacheResolverDefinition->replaceArgument(1, new Reference($cachedResolverId));
$container->setDefinition($resolverId, $cacheResolverDefinition);
}
$container->getDefinition($resolverId)->addTag('liip_imagine.cache.resolver', array(
'resolver' => $resolverName,
));
return $resolverId;
}
示例13: createFactoryDefinition
/**
* Creates a complex setting factory.
*
* The factory has a variable number of arguments.
* Dynamic settings are added as tupples: first the argument without the leading and trailing $, so that it is not
* transformed by the config resolver pass, then the argument as a string, so that it does get transformed.
*
* @param string $argumentValue The original argument ($var$/$another_var$)
* @param array $dynamicSettings Array of dynamic settings in $argumentValue
*
* @return Definition
*/
private function createFactoryDefinition($argumentValue, $dynamicSettings)
{
$definition = new Definition('stdClass', array($argumentValue));
$definition->setFactoryClass('eZ\\Bundle\\EzPublishCoreBundle\\DependencyInjection\\Configuration\\ComplexSettings\\ComplexSettingValueFactory');
$definition->setFactoryMethod('getArgumentValue');
foreach ($dynamicSettings as $dynamicSetting) {
// Trim the '$' so that the dynamic setting doesn't get transformed
$definition->addArgument(trim($dynamicSetting, '$'));
// This one will be transformed
$definition->addArgument($dynamicSetting);
}
return $definition;
}
示例14: loadClientConnection
protected function loadClientConnection($name, array $connection, ContainerBuilder $container)
{
$container->setDefinition(sprintf('doctrine_couchdb.client.%s_connection', $name), new DefinitionDecorator('doctrine_couchdb.client.connection'))->setArguments(array($connection));
if (isset($connection['logging']) && $connection['logging'] === true) {
$def = new Definition('Doctrine\\CouchDB\\HTTP\\Client');
$def->setFactoryService(sprintf('doctrine_couchdb.client.%s_connection', $name));
$def->setFactoryMethod('getHttpClient');
$def->setPublic(false);
$container->setDefinition(sprintf('doctrine_couchdb.httpclient.%s_client', $name), $def);
$def = $container->getDefinition('doctrine_couchdb.datacollector');
$def->addMethodCall('addLoggingClient', array(new Reference(sprintf('doctrine_couchdb.httpclient.%s_client', $name)), $name));
}
}
示例15: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('kalamu_menu_service.menus', $config);
foreach ($config as $name => $infos) {
$definition = new Definition('Knp\\Menu\\MenuItem', array($name));
$definition->setFactoryService('kalamu_menu_service.menu_builder');
$definition->setFactoryMethod('createMenu');
$definition->addTag('knp_menu.menu', array('alias' => $name));
$container->setDefinition('kalamu_menu_service.menu.' . $name, $definition);
}
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}