本文整理匯總了PHP中Symfony\Component\DependencyInjection\DefinitionDecorator::setFactory方法的典型用法代碼示例。如果您正苦於以下問題:PHP DefinitionDecorator::setFactory方法的具體用法?PHP DefinitionDecorator::setFactory怎麽用?PHP DefinitionDecorator::setFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\DefinitionDecorator
的用法示例。
在下文中一共展示了DefinitionDecorator::setFactory方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: process
/**
* @param ContainerBuilder $container
*
* @throws \InvalidArgumentException
*/
public function process(ContainerBuilder $container)
{
$config = $container->getExtensionConfig('elastica')[0];
$jsonLdFrameLoader = $container->get('nemrod.elastica.jsonld.frame.loader.filesystem');
$confManager = $container->getDefinition('nemrod.elastica.config_manager');
$filiationBuilder = $container->get('nemrod.filiation.builder');
$jsonLdFrameLoader->setFiliationBuilder($filiationBuilder);
foreach ($config['indexes'] as $name => $index) {
$indexName = isset($index['index_name']) ? $index['index_name'] : $name;
foreach ($index['types'] as $typeName => $settings) {
$jsonLdFrameLoader->setEsIndex($name);
$frame = $jsonLdFrameLoader->load($settings['frame'], null, true, true, true);
$type = !empty($frame['@type']) ? $frame['@type'] : $settings['type'];
if (empty($type)) {
throw \Exception("You must provide a RDF Type.");
}
//type
$typeId = 'nemrod.elastica.type.' . $name . '.' . $typeName;
$indexId = 'nemrod.elastica.index.' . $name;
$typeDef = new DefinitionDecorator('nemrod.elastica.type.abstract');
$typeDef->replaceArgument(0, $type);
$typeDef->setFactory(array(new Reference($indexId), 'getType'));
$typeDef->addTag('nemrod.elastica.type', array('index' => $name, 'name' => $typeName, 'type' => $type));
$container->setDefinition($typeId, $typeDef);
//registering config to configManager
$confManager->addMethodCall('setTypeConfigurationArray', array($name, $typeName, $type, $frame));
}
}
}
示例2: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config/'));
$loader->load('services.xml');
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), $configs);
$collection = 'in_memory';
switch (true) {
case 'redis' === $config['persistence']:
$loader->load('redis.xml');
$collection = 'predis';
$container->setParameter('qandidate.toggle.redis.namespace', $config['redis_namespace']);
$container->setAlias('qandidate.toggle.redis.client', $config['redis_client']);
break;
case 'factory' === $config['persistence']:
$collection = 'factory';
$definition = new DefinitionDecorator('qandidate.toggle.collection.in_memory');
$definition->setFactory(array(new Reference($config['collection_factory']['service_id']), $config['collection_factory']['method']));
$container->setDefinition('qandidate.toggle.collection.factory', $definition);
break;
}
$container->setAlias('qandidate.toggle.collection', 'qandidate.toggle.collection.' . $collection);
$contextFactoryService = 'qandidate.toggle.user_context_factory';
if (null !== $config['context_factory']) {
$contextFactoryService = $config['context_factory'];
}
$container->setAlias('qandidate.toggle.context_factory', $contextFactoryService);
}
示例3: loadTypes
/**
* Loads the configured types.
*
* @param array $types
* @param ContainerBuilder $container
* @param array $indexConfig
* @param array $indexableCallbacks
*/
private function loadTypes(array $types, ContainerBuilder $container, array $indexConfig, array &$indexableCallbacks)
{
foreach ($types as $name => $type) {
$indexName = $indexConfig['name'];
$typeId = sprintf('%s.%s', $indexConfig['reference'], $name);
$typeDef = new DefinitionDecorator('fos_elastica.type_prototype');
$typeDef->setFactory(array($indexConfig['reference'], 'getType'));
$typeDef->replaceArgument(0, $name);
$container->setDefinition($typeId, $typeDef);
$typeConfig = array('name' => $name, 'mapping' => array(), 'config' => array());
foreach (array('dynamic_templates', 'properties', '_all', '_boost', '_id', '_parent', '_routing', '_source', '_timestamp', '_ttl') as $field) {
if (isset($type[$field])) {
$typeConfig['mapping'][$field] = $type[$field];
}
}
foreach (array('persistence', 'serializer', 'analyzer', 'search_analyzer', 'dynamic', 'date_detection', 'dynamic_date_formats', 'numeric_detection') as $field) {
$typeConfig['config'][$field] = array_key_exists($field, $type) ? $type[$field] : null;
}
$this->indexConfigs[$indexName]['types'][$name] = $typeConfig;
if (isset($type['persistence'])) {
$this->loadTypePersistenceIntegration($type['persistence'], $container, new Reference($typeId), $indexName, $name);
$typeConfig['persistence'] = $type['persistence'];
}
if (isset($type['_parent'])) {
// _parent mapping cannot contain `property` and `identifier`, so removing them after building `persistence`
unset($indexConfig['types'][$name]['mapping']['_parent']['property'], $indexConfig['types'][$name]['mapping']['_parent']['identifier']);
}
if (isset($type['indexable_callback'])) {
$indexableCallbacks[sprintf('%s/%s', $indexName, $name)] = $type['indexable_callback'];
}
if ($container->hasDefinition('fos_elastica.serializer_callback_prototype')) {
$typeSerializerId = sprintf('%s.serializer.callback', $typeId);
$typeSerializerDef = new DefinitionDecorator('fos_elastica.serializer_callback_prototype');
if (isset($type['serializer']['groups'])) {
$typeSerializerDef->addMethodCall('setGroups', array($type['serializer']['groups']));
}
if (isset($type['serializer']['serialize_null'])) {
$typeSerializerDef->addMethodCall('setSerializeNull', array($type['serializer']['serialize_null']));
}
if (isset($type['serializer']['version'])) {
$typeSerializerDef->addMethodCall('setVersion', array($type['serializer']['version']));
}
$typeDef->addMethodCall('setSerializer', array(array(new Reference($typeSerializerId), 'serialize')));
$container->setDefinition($typeSerializerId, $typeSerializerDef);
}
}
}
示例4: loadIndexes
/**
* Loads the configured indexes.
*
* @param array $indexes An array of indexes configurations
* @param ContainerBuilder $container A ContainerBuilder instance
* @throws \InvalidArgumentException
* @return array
*/
private function loadIndexes(array $indexes, ContainerBuilder $container)
{
$confManager = $container->getDefinition('nemrod.elastica.config_manager');
$indexRegistry = $container->getDefinition('nemrod.elastica.index_registry');
foreach ($indexes as $name => $index) {
$indexId = sprintf('nemrod.elastica.index.%s', $name);
$indexName = isset($index['index_name']) ? $index['index_name'] : $name;
$indexDef = new DefinitionDecorator('nemrod.elastica.index.abstract');
$indexDef->replaceArgument(0, $indexName);
$indexDef->addTag('nemrod.elastica.index', array('name' => $name));
if (isset($index['client'])) {
$clientId = 'nemrod.elastica.client.' . $index['client'];
$indexDef->setFactory(array(new Reference($clientId), 'getIndex'));
}
$container->setDefinition($indexId, $indexDef);
$reference = new Reference($indexId);
$this->indexConfigs[$name] = array('elasticsearch_name' => $indexName, 'reference' => $reference, 'name' => $name, 'settings' => $index['settings']);
$confManager->addMethodCall('setIndexConfigurationArray', array($name, $this->indexConfigs[$name]));
$indexRegistry->addMethodCall('registerIndex', array($name, $reference));
}
}