本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::setFactory方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::setFactory方法的具体用法?PHP Definition::setFactory怎么用?PHP Definition::setFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Definition
的用法示例。
在下文中一共展示了Definition::setFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$analysis = $container->getParameter('es.analysis');
$connections = $container->getParameter('es.connections');
$managers = $container->getParameter('es.managers');
$collector = $container->get('es.metadata_collector');
foreach ($managers as $managerName => $manager) {
if (!isset($connections[$manager['connection']])) {
throw new InvalidConfigurationException('There is no ES connection with the name: ' . $manager['connection']);
}
$managerName = strtolower($managerName);
$connection = $connections[$manager['connection']];
$managerDefinition = new Definition($container->getParameter('es.manager.class'), [$managerName, $connection, $analysis, $manager]);
$managerDefinition->setFactory([new Reference('es.manager_factory'), 'createManager']);
$container->setDefinition(sprintf('es.manager.%s', $managerName), $managerDefinition);
// Make es.manager.default as es.manager service.
if ($managerName === 'default') {
$container->setAlias('es.manager', 'es.manager.default');
}
$mappings = $collector->getMappings($manager['mappings']);
// Building repository services.
foreach ($mappings as $repositoryType => $repositoryDetails) {
$repositoryDefinition = new Definition($container->getParameter('es.repository.class'), [$repositoryDetails['bundle'] . ':' . $repositoryDetails['class']]);
$repositoryDefinition->setFactory([new Reference(sprintf('es.manager.%s', $managerName)), 'getRepository']);
$repositoryId = sprintf('es.manager.%s.%s', $managerName, $repositoryType);
if (strtolower(substr($repositoryType, -8)) === 'document') {
$container->setAlias(sprintf('es.manager.%s.%s', $managerName, substr($repositoryType, 0, strlen($repositoryType) - 8)), $repositoryId);
}
$container->setDefinition($repositoryId, $repositoryDefinition);
}
}
}
示例2: createDefinition
/**
* {@inheritdoc}
*/
public function createDefinition(ContainerBuilder $container, array $config)
{
$definition = new Definition('Jose\\Object\\StorableJWK');
$definition->setFactory([new Reference('jose.factory.jwk'), 'createStorableKey']);
$definition->setArguments([$config['storage_path'], $this->getKeyConfig($config)]);
return $definition;
}
示例3: createDefinition
/**
* {@inheritdoc}
*/
public function createDefinition(ContainerBuilder $container, array $config)
{
$definition = new Definition('Jose\\Object\\JWK');
$definition->setFactory([new Reference('jose.factory.jwk'), 'createFromKeyFile']);
$definition->setArguments([$config['path'], $config['password'], $config['additional_values']]);
return $definition;
}
示例4: createDefinition
/**
* {@inheritdoc}
*/
public function createDefinition(ContainerBuilder $container, array $config)
{
$definition = new Definition('Jose\\Object\\X5UJWKSet');
$definition->setFactory([new Reference('jose.factory.jwk'), 'createFromX5U']);
$definition->setArguments([$config['url'], $config['is_secured'], $config['cache'], $config['cache_ttl'], $config['is_https']]);
return $definition;
}
示例5: buildRevalidationDefinition
private function buildRevalidationDefinition(array $cacheConfiguration)
{
$factory = new Definition(RevalidationFactory::class);
$revalidation = new Definition(RevalidationInterface::class, [$cacheConfiguration['validation']]);
$revalidation->setFactory([$factory, 'create']);
return $revalidation;
}
示例6: convertFactoryDefinition
private function convertFactoryDefinition(ContainerBuilder $container, $definition)
{
$symfonyDefinition = new Definition('Class');
$symfonyDefinition->setFactory([$this->convertArguments($container, $definition->getFactory()), $definition->getMethodName()]);
$symfonyDefinition->setArguments($this->convertArguments($container, $definition->getArguments()));
return $symfonyDefinition;
}
示例7: registerRepository
protected function registerRepository($name, $repositoryClass, $entityClass, ContainerBuilder $container)
{
$definition = new Definition($repositoryClass);
$definition->setFactory([new Reference('doctrine.orm.entity_manager'), 'getRepository']);
$definition->addArgument($entityClass);
$container->setDefinition($name . '.repository', $definition);
}
示例8: createServiceDefinition
private function createServiceDefinition($name)
{
$clientClass = "Aws\\{$name}\\{$name}Client";
$serviceDefinition = new Definition(class_exists($clientClass) ? $clientClass : AwsClient::class);
$serviceDefinition->setFactory([new Reference('aws_sdk'), 'create' . $name]);
return $serviceDefinition;
}
示例9: newGuzzleClient
/**
* Creates a new Guzzle client definition
*
* @param string $name Client name
* @param array $config Client configuration
* @param ContainerBuilder $container Service container
*
* @throws \LogicException
*/
private function newGuzzleClient($name, array $config, ContainerBuilder $container)
{
$client = new Definition('Guzzle\\Service\\Description\\ServiceDescription');
$client->setFactory(['Guzzle\\Service\\Description\\ServiceDescription', 'factory']);
if (!isset($config['description']['name'])) {
$config['description']['name'] = $name;
}
$client->addArgument($config['description']);
// Add the service to the container
$serviceName = sprintf('lsw_guzzle.%s', $name);
$container->setDefinition($serviceName, $client);
$client = new Definition('Guzzle\\Service\\Client');
$client->setFactory(['Guzzle\\Service\\Client', 'factory']);
$client->addArgument($config['config']);
$client->addMethodCall('setDescription', array(new Reference($serviceName)));
$client->addMethodCall('addSubscriber', array(new Reference('lsw_guzzle.log_plugin')));
if (isset($config['config']['json_objects']) && $config['config']['json_objects']) {
$client->addMethodCall('addSubscriber', array(new Reference('lsw_guzzle.json_objects_plugin')));
}
if ($container->hasDefinition('lsw_guzzle.command_history_plugin')) {
$client->addMethodCall('addSubscriber', array(new Reference('lsw_guzzle.command_history_plugin')));
}
// Add the service to the container
$serviceName = sprintf('guzzle.%s', $name);
$container->setDefinition($serviceName, $client);
}
示例10: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$immutableProperties = array_merge($config['content_immutable_properties'], array('linkedToSite', 'deleted'));
$container->setParameter('open_orchestra_model.content.immutable_properties', $immutableProperties);
foreach ($config['fixtures_interface'] as $command => $content) {
$container->setParameter('open_orchestra_model.fixtures_interface.' . $command, $content);
}
$container->setParameter('open_orchestra_model.fixtures.command', array_keys($config['fixtures_interface']));
foreach ($config['document'] as $class => $content) {
if (is_array($content)) {
$container->setParameter('open_orchestra_model.document.' . $class . '.class', $content['class']);
if (array_key_exists('repository', $content)) {
$definition = new Definition($content['repository'], array($content['class']));
$definition->setFactory(array(new Reference('doctrine.odm.mongodb.document_manager'), 'getRepository'));
$definition->addMethodCall('setAggregationQueryBuilder', array(new Reference('doctrine_mongodb.odm.default_aggregation_query')));
if (method_exists($content['repository'], 'setFilterTypeManager')) {
$definition->addMethodCall('setFilterTypeManager', array(new Reference('open_orchestra_pagination.filter_type.manager')));
}
$container->setDefinition('open_orchestra_model.repository.' . $class, $definition);
}
}
}
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('listener.yml');
$loader->load('validator.yml');
$loader->load('manager.yml');
$loader->load('saver.yml');
$loader->load('form.yml');
$loader->load('transformer.yml');
$loader->load('helper.yml');
}
示例11: load
/**
* @param array $configs
* @param ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
{
$this->container = $container;
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$connectionsConfig = $config['connections'];
$exchangesConfig = $config['exchanges'];
$container->setParameter('hector.config.connections', $connectionsConfig);
$container->setParameter('hector.config.exchanges', $exchangesConfig);
$contextRegistry = $container->getDefinition('hector.context.registry');
foreach ($exchangesConfig as $exchangeName => $exchangeConfiguration) {
$exchangeContextServiceName = 'hector.exchange.context.' . $exchangeName;
$exchangeContext = new Definition(ExchangeContext::class, [$exchangeConfiguration]);
$exchangeContext->setFactory('Evaneos\\Hector\\Exchange\\Context::createFromConfig');
$container->setDefinition($exchangeContextServiceName, $exchangeContext);
$contextRegistry->addMethodCall('addExchangeContext', [$exchangeName, new Reference($exchangeContextServiceName)]);
if (!isset($exchangeConfiguration['queues'])) {
continue;
}
foreach ($exchangeConfiguration['queues'] as $queueName => $queueConfiguration) {
$queueContextServiceName = 'hector.queue.context.' . $queueName;
$queueContext = new Definition(QueueContext::class, [$queueConfiguration]);
$queueContext->setFactory('Evaneos\\Hector\\Queue\\Context::createFromConfig');
$container->setDefinition($queueContextServiceName, $queueContext);
$contextRegistry->addMethodCall('addQueueContext', [$queueName, new Reference($queueContextServiceName)]);
}
}
// Register Connections
foreach ($config['connections'] as $name => $connectionConfig) {
$this->registerConnection($name, $connectionConfig);
}
}
示例12: createServiceDefinitions
/**
* @inheritDoc
*/
public function createServiceDefinitions(array $data, ContainerBuilder $container, $prefix)
{
if (!isset($data['host'])) {
throw new UrlResolveException("No region hostname found in url");
}
if (!isset($data['user'])) {
throw new UrlResolveException("No key (username) found in url");
}
if (!isset($data['pass'])) {
throw new UrlResolveException("No secret (password) found in url");
}
if (!isset($data['clean_path'])) {
throw new UrlResolveException("No bucket name (path) found in url");
}
$region = $data['host'];
$key = $data['user'];
$secret = $data['pass'];
$bucket = $data['clean_path'];
$adapterPrefix = null;
if (isset($data['prefix'])) {
$adapterPrefix = $data['prefix'];
}
$version = 'latest';
if (isset($data['version'])) {
$version = $data['version'];
}
$client = new Definition('Aws\\S3\\S3Client');
$client->setFactory(['Aws\\S3\\S3Client', 'factory']);
$client->setArguments([['credentials' => ['key' => $key, 'secret' => $secret], 'region' => $region, 'version' => $version]]);
$container->setDefinition("{$prefix}.client", $client);
$container->setDefinition("{$prefix}.adapter", new Definition('League\\Flysystem\\AwsS3v3\\AwsS3Adapter', [new Reference("{$prefix}.client"), $bucket, $adapterPrefix]));
return "{$prefix}.adapter";
}
示例13: load
/**
* {@inheritDoc}
*/
public function load(ContainerBuilder $container)
{
$omnipayFactory = new Definition(GatewayFactory::class);
$omnipayFactory->setFactory([Omnipay::class, 'getFactory']);
$container->setDefinition('payum.omnipay_factory', $omnipayFactory);
parent::load($container);
}
示例14: create
public function create(string $class) : Definition
{
$definition = new Definition(EntityManager::class);
$definition->setFactory([new Reference('doctrine.orm.entity_manager'), 'getRepository']);
$definition->addArgument($class);
return $definition;
}
示例15: createMenuService
/**
* @param string $service
* @param string $alias
*
* @return Definition
*/
private function createMenuService($service, $alias)
{
$definition = new Definition(ItemInterface::class);
$definition->setFactory([new Reference($service), 'create']);
$definition->addTag('knp_menu.menu', ['alias' => $alias]);
return $definition;
}