本文整理匯總了PHP中Symfony\Component\DependencyInjection\ContainerInterface::setDefinition方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContainerInterface::setDefinition方法的具體用法?PHP ContainerInterface::setDefinition怎麽用?PHP ContainerInterface::setDefinition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::setDefinition方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: bootstrapContainer
/**
* Bootstrap the container.
*
* @return self
*/
private function bootstrapContainer()
{
$this->container = new ContainerBuilder();
$yaml = new Definition('Modrepo\\Configuration\\Yaml', [$this->configPath]);
$this->container->setDefinition('config', $yaml);
foreach ($this->getInitialServices() as $service => $class) {
$this->container->register($service, $class);
}
return $this;
}
示例2: setupAuthentication
public function setupAuthentication(ContainerInterface $container, $name, $options)
{
$container->setParameter("vss_oauth_extension.providers.{$name}.client_id", $options['client_id']);
$definition = new DefinitionDecorator("vss_oauth.security.auth.{$options['type']}");
$container->setDefinition("vss_oauth.security.auth.email.{$name}", $definition);
$definition->replaceArgument(0, $options);
}
示例3: loadClient
/**
* Load a client configuration as a service in the container. A client can use multiple servers
*
* @param ContainerInterface $container The container
* @param string $alias Alias of the client
* @param array $config Base config of the client
* @param array $servers List of available servers as describe in the config file
* @param boolean $baseEvents Register base events
*
* @throws InvalidConfigurationException
* @return string the service name
*/
protected function loadClient($container, $alias, array $config, array $servers, $baseEvents)
{
$usedServers = [];
$events = $config['events'];
$matchedServers = [];
if ($config['servers'][0] == 'all') {
// Use all servers
$matchedServers = array_keys($servers);
} else {
// Use only declared servers
foreach ($config['servers'] as $serverAlias) {
// Named server
if (array_key_exists($serverAlias, $servers)) {
$matchedServers[] = $serverAlias;
continue;
}
// Search matchning server config name
$found = false;
foreach (array_keys($servers) as $key) {
if (fnmatch($serverAlias, $key)) {
$matchedServers[] = $key;
$found = true;
}
}
// No server found
if (!$found) {
throw new InvalidConfigurationException(sprintf('M6WebStatsd client %s used server %s which is not defined in the servers section', $alias, $serverAlias));
}
}
}
// Matched server congurations
foreach ($matchedServers as $serverAlias) {
$usedServers[] = ['address' => $servers[$serverAlias]['address'], 'port' => $servers[$serverAlias]['port']];
}
// Add the statsd client configured
$serviceId = $alias == 'default' ? 'm6_statsd' : 'm6_statsd.' . $alias;
$definition = new Definition('M6Web\\Bundle\\StatsdBundle\\Client\\Client');
$definition->setScope(ContainerInterface::SCOPE_CONTAINER);
$definition->addArgument($usedServers);
if (isset($config['to_send_limit'])) {
$definition->addMethodCall('setToSendLimit', array($config['to_send_limit']));
}
foreach ($events as $eventName => $eventConfig) {
$definition->addTag('kernel.event_listener', ['event' => $eventName, 'method' => 'handleEvent']);
$definition->addMethodCall('addEventToListen', [$eventName, $eventConfig]);
}
$container->setDefinition($serviceId, $definition);
// Add the statsd client listener
$serviceListenerId = $serviceId . '.listener';
$definition = new Definition('M6Web\\Bundle\\StatsdBundle\\Statsd\\Listener');
$definition->addArgument(new Reference($serviceId));
$definition->addArgument(new Reference('event_dispatcher'));
$definition->addTag('kernel.event_listener', ['event' => 'kernel.terminate', 'method' => 'onKernelTerminate', 'priority' => -100]);
if ($baseEvents) {
$definition->addTag('kernel.event_listener', ['event' => 'kernel.terminate', 'method' => 'onKernelTerminateEvents', 'priority' => 0]);
$definition->addTag('kernel.event_listener', ['event' => 'kernel.exception', 'method' => 'onKernelException', 'priority' => 0]);
}
$container->setDefinition($serviceListenerId, $definition);
return $serviceId;
}
示例4: loadClient
/**
* Load a dbclient configuration as a service in the container. A client can use multiple servers
* @param ContainerInterface $container The container
* @param string $alias Alias of the client
* @param array $config Base config of the client
* @param array $servers List of available servers as describe in the config file
* @param string $type db or multi
*
* @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
* @return void
*/
protected function loadClient($container, $alias, array $config, array $servers, $type = 'cache')
{
$configuration = array('timeout' => $config['timeout'], 'server_config' => array());
if (array_key_exists('readwritetimeout', $config)) {
$configuration['read_write_timeout'] = $config['readwritetimeout'];
}
if (array_key_exists('reconnect', $config)) {
$configuration['reconnect'] = $config['reconnect'];
}
if ('cache' === $type) {
// check namespace
if (!isset($config['namespace'])) {
throw new InvalidConfigurationException("namespace Parameter for M6Redis cache server is required");
}
$configuration['namespace'] = $config['namespace'];
$configuration['compress'] = $config['compress'];
}
$configuration['server_config'] = $this->getServers($servers, $config['servers'], $alias);
if (count($configuration['server_config']) === 0) {
throw new InvalidConfigurationException(sprintf("no server found for M6Redis client %s", $alias));
}
switch ($type) {
case 'cache':
$redisCacheId = sprintf('m6_redis.cache.%s', $alias);
$container->register($redisCacheId, 'M6Web\\Component\\Redis\\Cache')->addArgument($configuration);
$serviceId = $alias == 'default' ? 'm6_redis' : 'm6_redis.' . $alias;
$definition = new Definition($config['class']);
$definition->addArgument(new Reference($redisCacheId));
break;
case 'db':
$serviceId = $alias == 'default' ? 'm6_dbredis' : 'm6_dbredis.' . $alias;
$definition = new Definition('M6Web\\Component\\Redis\\DB');
$definition->addArgument($configuration);
break;
case 'multi':
$serviceId = $alias == 'default' ? 'm6_multiredis' : 'm6_multiredis.' . $alias;
$definition = new Definition('M6Web\\Component\\Redis\\Multi');
$definition->addArgument($configuration);
break;
default:
throw new InvalidConfigurationException("Invalid client type");
}
$definition->setScope(ContainerInterface::SCOPE_CONTAINER);
$definition->addMethodCall('setEventDispatcher', array(new Reference('event_dispatcher'), 'M6Web\\Bundle\\RedisBundle\\EventDispatcher\\RedisEvent'));
$container->setDefinition($serviceId, $definition);
}