本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::setFactoryService方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::setFactoryService方法的具体用法?PHP Definition::setFactoryService怎么用?PHP Definition::setFactoryService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Definition
的用法示例。
在下文中一共展示了Definition::setFactoryService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: loadDbalConnection
/**
* Loads a configured DBAL connection.
*
* @param string $name The name of the connection
* @param array $connection A dbal connection configuration.
* @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function loadDbalConnection($name, array $connection, ContainerBuilder $container)
{
$containerDef = new Definition('%doctrine.dbal.configuration_class%');
$containerDef->setPublic(false);
if (isset($connection['logging']) && $connection['logging']) {
$containerDef->addMethodCall('setSQLLogger', array(new Reference('doctrine.dbal.logger')));
unset($connection['logging']);
}
$container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), $containerDef);
$driverDef = new Definition('Doctrine\\DBAL\\Connection');
$driverDef->setFactoryService('doctrine.dbal.connection_factory');
$driverDef->setFactoryMethod('createConnection');
$container->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), $driverDef);
// event manager
$eventManagerId = sprintf('doctrine.dbal.%s_connection.event_manager', $name);
$eventManagerDef = new Definition('%doctrine.dbal.event_manager_class%');
$eventManagerDef->setPublic(false);
$container->setDefinition($eventManagerId, $eventManagerDef);
if (isset($connection['charset'])) {
if (isset($connection['driver']) && stripos($connection['driver'], 'mysql') !== false || isset($connection['driverClass']) && stripos($connection['driverClass'], 'mysql') !== false) {
$mysqlSessionInit = new Definition('%doctrine.dbal.events.mysql_session_init.class%');
$mysqlSessionInit->setArguments(array($connection['charset']));
$mysqlSessionInit->setPublic(false);
$mysqlSessionInit->addTag(sprintf('doctrine.dbal.%s_event_subscriber', $name));
$container->setDefinition(sprintf('doctrine.dbal.%s_connection.events.mysqlsessioninit', $name), $mysqlSessionInit);
unset($connection['charset']);
}
}
if (isset($connection['platform_service'])) {
$connection['platform'] = new Reference($connection['platform_service']);
unset($connection['platform_service']);
}
$driverDef->setArguments(array($connection, new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)), new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name))));
}
示例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: 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);
}
示例6: prepareRepositoriesServices
protected function prepareRepositoriesServices($classes, ContainerBuilder $container, $appName)
{
foreach (array_keys($classes) as $model) {
$repositoryClassKey = $this->getParameterName($appName, 'repository', $model);
$repositoryClass = $container->getParameter($repositoryClassKey);
$repositoryDefinition = new Definition($repositoryClass);
$repositoryDefinition->setFactoryService('doctrine.orm.entity_manager')->setFactoryMethod('getRepository')->setArguments([$container->getParameter($this->getParameterName($appName, 'model', $model))]);
$container->setDefinition($appName . '.repository.' . $model, $repositoryDefinition);
}
}
示例7: testProcessDetectsReferencesFromInlinedFactoryDefinitions
public function testProcessDetectsReferencesFromInlinedFactoryDefinitions()
{
$container = new ContainerBuilder();
$container->register('a');
$factory = new Definition();
$factory->setFactoryService('a');
$container->register('b')->addArgument($factory);
$graph = $this->process($container);
$this->assertTrue($graph->hasNode('a'));
$this->assertCount(1, $refs = $graph->getNode('a')->getInEdges());
}
示例8: 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;
}
示例9: 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());
}
示例10: 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;
}
示例11: getRepositoryDefinition
/**
* {@inheritdoc}
*/
protected function getRepositoryDefinition(array $classes)
{
$repositoryClass = 'Sylius\\Bundle\\ResourceBundle\\Doctrine\\ODM\\MongoDB\\DocumentRepository';
if (isset($classes['repository'])) {
$repositoryClass = $classes['repository'];
}
$unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
$unitOfWorkDefinition->setFactoryService($this->getManagerServiceKey())->setFactoryMethod('getUnitOfWork')->setPublic(false);
$definition = new Definition($repositoryClass);
$definition->setArguments(array(new Reference($this->getContainerKey('manager')), $unitOfWorkDefinition, $this->getClassMetadataDefinition($classes['model'])));
return $definition;
}
示例12: 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));
}
}
示例13: 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');
}
示例14: 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];
}
示例15: getRepositoryDefinition
/**
* {@inheritdoc}
*/
protected function getRepositoryDefinition(array $classes)
{
$reflection = new \ReflectionClass($classes['model']);
$translatableInterface = 'Sylius\\Component\\Translation\\Model\\TranslatableInterface';
$translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface);
$repositoryClass = $translatable ? 'Sylius\\Bundle\\TranslationBundle\\Doctrine\\ODM\\MongoDB\\TranslatableResourceRepository' : new Parameter('sylius.mongodb_odm.repository.class');
if (isset($classes['repository'])) {
$repositoryClass = $classes['repository'];
}
$unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
$unitOfWorkDefinition->setFactoryService($this->getManagerServiceKey())->setFactoryMethod('getUnitOfWork')->setPublic(false);
$definition = new Definition($repositoryClass);
$definition->setArguments(array(new Reference($this->getContainerKey('manager')), $unitOfWorkDefinition, $this->getClassMetadataDefinition($classes['model'])));
return $definition;
}