本文整理匯總了PHP中Symfony\Components\DependencyInjection\BuilderConfiguration::hasDefinition方法的典型用法代碼示例。如果您正苦於以下問題:PHP BuilderConfiguration::hasDefinition方法的具體用法?PHP BuilderConfiguration::hasDefinition怎麽用?PHP BuilderConfiguration::hasDefinition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Components\DependencyInjection\BuilderConfiguration
的用法示例。
在下文中一共展示了BuilderConfiguration::hasDefinition方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: dbalLoad
/**
* Loads the DBAL configuration.
*
* Usage example:
*
* <doctrine:dbal dbname="sfweb" user="root" />
*
* @param array $config A configuration array
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
public function dbalLoad($config, BuilderConfiguration $configuration)
{
if (!$configuration->hasDefinition('doctrine.dbal.logger')) {
$loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
$configuration->merge($loader->load($this->resources['dbal']));
}
$defaultConnection = array('driver' => 'PDOMySql', 'user' => 'root', 'password' => null, 'host' => 'localhost', 'port' => null, 'event_manager_class' => 'Doctrine\\Common\\EventManager', 'configuration_class' => 'Doctrine\\DBAL\\Configuration', 'wrapper_class' => null, 'options' => array());
$defaultConnectionName = isset($config['default_connection']) ? $config['default_connection'] : $configuration->getParameter('doctrine.dbal.default_connection');
$configuration->setAlias('database_connection', null !== $this->alias ? $this->alias : sprintf('doctrine.dbal.%s_connection', $defaultConnectionName));
$configuration->setParameter('doctrine.dbal.default_connection', $defaultConnectionName);
$connections = array();
if (isset($config['connections'])) {
foreach ($config['connections'] as $name => $connection) {
$connections[isset($connection['id']) ? $connection['id'] : $name] = $connection;
}
} else {
$connections = array($defaultConnectionName => $config);
}
foreach ($connections as $name => $connection) {
// previously registered?
if ($configuration->hasDefinition(sprintf('doctrine.dbal.%s_connection', $name))) {
$driverDef = $configuration->getDefinition(sprintf('doctrine.dbal.%s_connection', $name));
$arguments = $driverDef->getArguments();
$driverOptions = $arguments[0];
} else {
$connection = array_merge($defaultConnection, $connection);
$configurationClass = isset($connection['configuration_class']) ? $connection['configuration_class'] : 'Doctrine\\DBAL\\Configuration';
$configurationDef = new Definition($configurationClass);
$configurationDef->addMethodCall('setSqlLogger', array(new Reference('doctrine.dbal.logger')));
$configuration->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration', $name), $configurationDef);
$eventManagerDef = new Definition($connection['event_manager_class']);
$configuration->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager', $name), $eventManagerDef);
$driverOptions = array();
$driverDef = new Definition('Doctrine\\DBAL\\DriverManager');
$driverDef->setFactoryMethod('getConnection');
$configuration->setDefinition(sprintf('doctrine.dbal.%s_connection', $name), $driverDef);
}
if (isset($connection['driver'])) {
$driverOptions['driverClass'] = sprintf('Doctrine\\DBAL\\Driver\\%s\\Driver', $connection['driver']);
}
if (isset($connection['wrapper_class'])) {
$driverOptions['wrapperClass'] = $connection['wrapper_class'];
}
if (isset($connection['options'])) {
$driverOptions['driverOptions'] = $connection['options'];
}
foreach (array('dbname', 'host', 'user', 'password', 'path', 'port', 'unix_socket') as $key) {
if (isset($connection[$key])) {
$driverOptions[$key] = $connection[$key];
}
}
$driverDef->setArguments(array($driverOptions, new Reference(sprintf('doctrine.dbal.%s_connection.configuration', $name)), new Reference(sprintf('doctrine.dbal.%s_connection.event_manager', $name))));
}
return $configuration;
}
示例2: mongodbLoad
public function mongodbLoad($config, BuilderConfiguration $configuration)
{
$loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
$configuration->merge($loader->load($this->resources['mongodb']));
if (!$configuration->hasDefinition('doctrine.odm.mongodb.document_manager')) {
$configuration->setParameter('doctrine.odm.mongodb.mapping_dirs', $this->findBundleSubpaths('Resources/config/doctrine/metadata', $configuration));
$configuration->setParameter('doctrine.odm.mongodb.document_dirs', $this->findBundleSubpaths('Document', $configuration));
$configuration->setDefinition('doctrine.odm.mongodb.metadata', $this->buildMetadataDefinition($configuration));
}
foreach (array('host', 'port', 'database') as $key) {
if (isset($config[$key])) {
$configuration->setParameter('doctrine.odm.mongodb.default_' . $key, $config[$key]);
}
}
foreach (array('proxy_dir', 'auto_generate_proxy_classes') as $key) {
if (isset($config[$key])) {
$configuration->setParameter('doctrine.odm.mongodb.' . $key, $config[$key]);
}
}
foreach (array('cache', 'metadata') as $key) {
if (isset($config[$key])) {
$configuration->setAlias('doctrine.odm.mongodb.' . $key, 'doctrine.odm.mongodb.' . $key . '.' . $config[$key]);
}
}
}
示例3: sessionLoad
/**
* Loads the session configuration.
*
* @param array $config A configuration array
* @param BuilderConfiguration $configuration A BuilderConfiguration instance
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
public function sessionLoad($config, BuilderConfiguration $configuration)
{
if (!$configuration->hasDefinition('session')) {
$loader = new XmlFileLoader(array(__DIR__ . '/../Resources/config', __DIR__ . '/Resources/config'));
$configuration->merge($loader->load('session.xml'));
}
if (isset($config['default_locale'])) {
$configuration->setParameter('session.default_locale', $config['default_locale']);
}
if (isset($config['class'])) {
$configuration->setParameter('session.class', $config['class']);
}
foreach (array('name', 'auto_start', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'cache_limiter', 'pdo.db_table') as $name) {
if (isset($config['session'][$name])) {
$configuration->setParameter('session.options.' . $name, $config['session'][$name]);
}
}
if (isset($config['session']['class'])) {
$class = $config['session']['class'];
if (in_array($class, array('Native', 'Pdo'))) {
$class = 'Symfony\\Framework\\FrameworkBundle\\SessionStorage\\' . $class . 'SessionStorage';
}
$configuration->setParameter('session.session', 'session.session.' . strtolower($class));
}
return $configuration;
}
示例4: configLoad
public function configLoad($config, BuilderConfiguration $configuration)
{
if (!$configuration->hasDefinition('twig')) {
$loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
$configuration->merge($loader->load('twig.xml'));
}
$configuration->setParameter('twig.options', array_replace($configuration->getParameter('twig.options'), $config));
}
示例5: mailerLoad
/**
* Loads the Swift Mailer configuration.
*
* Usage example:
*
* <swift:mailer transport="gmail" delivery_strategy="spool">
* <swift:username>fabien</swift:username>
* <swift:password>xxxxx</swift:password>
* <swift:spool path="/path/to/spool/" />
* </swift:mailer>
*
* @param array $config A configuration array
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
public function mailerLoad($config, BuilderConfiguration $configuration)
{
if (!$configuration->hasDefinition('swiftmailer.mailer')) {
$loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
$configuration->merge($loader->load($this->resources['mailer']));
$configuration->setAlias('mailer', 'swiftmailer.mailer');
}
$r = new \ReflectionClass('Swift_Message');
$configuration->setParameter('swiftmailer.base_dir', dirname(dirname(dirname($r->getFilename()))));
$transport = $configuration->getParameter('swiftmailer.transport.name');
if (array_key_exists('transport', $config)) {
if (null === $config['transport']) {
$transport = 'null';
} elseif ('gmail' === $config['transport']) {
$config['encryption'] = 'ssl';
$config['auth_mode'] = 'login';
$config['host'] = 'smtp.gmail.com';
$transport = 'smtp';
} else {
$transport = $config['transport'];
}
$configuration->setParameter('swiftmailer.transport.name', $transport);
}
$configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.' . $transport);
if (isset($config['encryption']) && 'ssl' === $config['encryption'] && !isset($config['port'])) {
$config['port'] = 465;
}
foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) {
if (isset($config[$key])) {
$configuration->setParameter('swiftmailer.transport.' . $transport . '.' . $key, $config[$key]);
}
}
// spool?
if (isset($config['spool'])) {
$type = isset($config['type']) ? $config['type'] : 'file';
$configuration->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.' . $transport);
$configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
$configuration->setAlias('swiftmailer.spool', 'swiftmailer.spool.' . $type);
foreach (array('path') as $key) {
if (isset($config['spool'][$key])) {
$configuration->setParameter('swiftmailer.spool.' . $type . '.' . $key, $config['spool'][$key]);
}
}
}
if (isset($config['delivery_address'])) {
$configuration->setParameter('swiftmailer.single_address', $config['delivery_address']);
$configuration->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.redirecting')));
}
if (isset($config['disable_delivery']) && $config['disable_delivery']) {
$configuration->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.blackhole')));
}
return $configuration;
}
示例6: loggerLoad
/**
* Loads the logger configuration.
*
* Usage example:
*
* <zend:logger priority="info" path="/path/to/some.log" />
*
* @param array $config A configuration array
* @param BuilderConfiguration $configuration A BuilderConfiguration instance
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
public function loggerLoad($config, BuilderConfiguration $configuration)
{
if (!$configuration->hasDefinition('zend.logger')) {
$loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
$configuration->merge($loader->load($this->resources['logger']));
$configuration->setAlias('logger', 'zend.logger');
}
if (isset($config['priority'])) {
$configuration->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\\Zend\\Log\\Logger::' . strtoupper($config['priority'])));
}
if (isset($config['path'])) {
$configuration->setParameter('zend.logger.path', $config['path']);
}
}
示例7: dbalLoad
/**
* Loads the DBAL configuration.
*
* @param array $config A configuration array
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
public function dbalLoad($config, BuilderConfiguration $configuration)
{
if (!$configuration->hasDefinition('propel')) {
$loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
$configuration->merge($loader->load($this->resources['propel']));
}
$defaultConnection = array('driver' => 'mysql', 'user' => 'root', 'password' => null, 'dsn' => null, 'classname' => 'DebugPDO', 'options' => array(), 'attributes' => array(), 'settings' => array('charset' => array('value' => 'UTF8')));
$defaultConnectionName = isset($config['default_connection']) ? $config['default_connection'] : $configuration->getParameter('propel.dbal.default_connection');
$configuration->setParameter('propel.dbal.default_connection', $defaultConnectionName);
$connections = array();
if (isset($config['connections'])) {
foreach ($config['connections'] as $name => $connection) {
$connections[isset($connection['id']) ? $connection['id'] : $name] = $connection;
}
} else {
$connections = array($defaultConnectionName => $config);
}
$arguments = $configuration->getDefinition('propel.configuration')->getArguments();
if (count($arguments)) {
$c = $arguments[0];
} else {
$c = array('log' => array('level' => 7), 'datasources' => array());
}
foreach ($connections as $name => $connection) {
if (isset($c['datasources'][$name])) {
} else {
$connection = array_replace($defaultConnection, $connection);
$c['datasources'][$name] = array('connection' => array());
}
if (isset($connection['driver'])) {
$c['datasources'][$name]['adapter'] = $connection['driver'];
}
foreach (array('dsn', 'user', 'password', 'classname', 'options', 'attributes', 'settings') as $att) {
if (isset($connection[$att])) {
$c['datasources'][$name]['connection'][$att] = $connection[$att];
}
}
}
$configuration->getDefinition('propel.configuration')->setArguments(array($c));
return $configuration;
}
示例8: serverLoad
/**
* @param array $config
* @param Symfony\Components\DependencyInjection\BuilderConfiguration $configuration
* @return Symfony\Components\DependencyInjection\BuilderConfiguration
*
* @throws \InvalidArgumentException If Server class does not implement ServerInterface
*/
public function serverLoad(array $config, BuilderConfiguration $configuration)
{
if (!$configuration->hasDefinition('server')) {
$loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
$configuration->merge($loader->load($this->resources['server']));
}
// Options
$options = array('pid_file', 'user', 'group', 'umask', 'hostname', 'admin', 'hostname_lookups', 'max_clients', 'max_requests_per_child', 'address', 'port', 'timeout', 'keepalive_timeout', 'compression', 'compression_level');
// General
foreach ($options as $name) {
if (!array_key_exists($name, $config)) {
continue;
}
$configuration->setParameter(sprintf('server.%s', $name), $config[$name]);
}
// Classes
if (isset($config['class'])) {
$this->checkServiceClassInterface('Server', $config['class'], 'Bundle\\ServerBundle\\ServerInterface');
$configuration->setParameter('server.class', $config['class']);
}
if (isset($config['request'])) {
$this->checkServiceClassInterface('Request', $config['request'], 'Bundle\\ServerBundle\\RequestInterface');
$configuration->setParameter('server.request.class', $config['request']);
}
if (isset($config['response'])) {
$this->checkServiceClassInterface('Response', $config['response'], 'Bundle\\ServerBundle\\ResponseInterface');
$configuration->setParameter('server.response.class', $config['response']);
}
// Handlers
if (isset($config['handlers'])) {
if (!is_array($config['handlers'])) {
throw new \InvalidArgumentException(sprintf('Handler configuration must be of type array, "%s" given', gettype($config['handlers'])));
}
foreach ($config['handlers'] as $handler) {
// @TODO: configure handlers
// $this->checkServiceClassInterface('Handler', $handler['class'], 'Bundle\\ServerBundle\\Handler\\HandlerInterface');
}
}
// Handler configuration
if (isset($config['environment'])) {
$configuration->setParameter('server.kernel_environment', $config['environment']);
// fixes class redeclaration error on custom kernel environment
if ($config['environment'] != $this->container->getParameter('kernel.environment')) {
$configuration->setParameter('kernel.include_core_classes', false);
}
}
if (array_key_exists('debug', $config)) {
$configuration->setParameter('server.kernel_debug', $config['debug']);
// fixes class redeclaration error on custom kernel debug mode
if ($config['debug'] != $this->container->getParameter('kernel.debug')) {
$configuration->setParameter('kernel.include_core_classes', false);
}
}
// Filters
if (isset($config['filters'])) {
if (!is_array($config['filters'])) {
throw new \InvalidArgumentException(sprintf('Filter configuration must be of type array, "%s" given', gettype($config['filters'])));
}
foreach ($config['filters'] as $filter) {
// @TODO: configure filters
// $this->checkServiceClassInterface('Filter', $filter['class'], 'Bundle\\ServerBundle\\Filter\\FilterInterface');
}
}
// Filter configuration
return $configuration;
}
示例9: array
$configuration->setAlias('barbar', 'foofoo');
$t->is($configuration->getAliases(), array('bar' => 'foo', 'barbar' => 'foofoo'), '->getAliases() returns an array of all defined aliases');
$configuration->addAliases(array('foo' => 'bar'));
$t->is($configuration->getAliases(), array('bar' => 'foo', 'barbar' => 'foofoo', 'foo' => 'bar'), '->addAliases() adds some aliases');
// ->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()
$t->diag('->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()');
$configuration = new BuilderConfiguration();
$definitions = array(
'foo' => new Definition('FooClass'),
'bar' => new Definition('BarClass'),
);
$configuration->setDefinitions($definitions);
$t->is($configuration->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
$t->ok($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$t->ok(!$configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$t->is($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$t->ok($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$t->is($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
try
{
$configuration->getDefinition('baz');
$t->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
catch (InvalidArgumentException $e)
示例10: testDefinitions
public function testDefinitions()
{
$configuration = new BuilderConfiguration();
$definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'));
$configuration->setDefinitions($definitions);
$this->assertEquals($definitions, $configuration->getDefinitions(), '->setDefinitions() sets the service definitions');
$this->assertTrue($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$this->assertFalse($configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$this->assertEquals($foo, $configuration->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
$this->assertTrue($configuration->setDefinition('foobar', new Definition('FooBarClass')) === $configuration, '->setDefinition() implements a fuild interface');
$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$this->assertEquals(array_merge($definitions, $defs), $configuration->getDefinitions(), '->addDefinitions() adds the service definitions');
try {
$configuration->getDefinition('baz');
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\\InvalidArgumentException', $e, '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
$this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
}
示例11: templatingLoad
/**
* Loads the templating configuration.
*
* @param array $config A configuration array
*
* @return BuilderConfiguration A BuilderConfiguration instance
*/
public function templatingLoad($config, BuilderConfiguration $configuration)
{
if (!$configuration->hasDefinition('templating')) {
$loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
$configuration->merge($loader->load($this->resources['templating']));
}
if (array_key_exists('escaping', $config)) {
$configuration->setParameter('templating.output_escaper', $config['escaping']);
}
if (array_key_exists('assets_version', $config)) {
$configuration->setParameter('templating.assets.version', $config['assets_version']);
}
// path for the filesystem loader
if (isset($config['path'])) {
$configuration->setParameter('templating.loader.filesystem.path', $config['path']);
}
// loaders
if (isset($config['loader'])) {
$loaders = array();
$ids = is_array($config['loader']) ? $config['loader'] : array($config['loader']);
foreach ($ids as $id) {
$loaders[] = new Reference($id);
}
if (1 === count($loaders)) {
$configuration->setAlias('templating.loader', (string) $loaders[0]);
} else {
$configuration->getDefinition('templating.loader.chain')->addArgument($loaders);
$configuration->setAlias('templating.loader', 'templating.loader.chain');
}
}
// cache?
if (isset($config['cache'])) {
// wrap the loader with some cache
$configuration->setDefinition('templating.loader.wrapped', $configuration->findDefinition('templating.loader'));
$configuration->setDefinition('templating.loader', $configuration->getDefinition('templating.loader.cache'));
$configuration->setParameter('templating.loader.cache.path', $config['cache']);
}
return $configuration;
}
示例12: testDefinitions
public function testDefinitions()
{
$configuration = new BuilderConfiguration();
$definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'));
$configuration->setDefinitions($definitions);
$this->assertEquals($configuration->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
$this->assertTrue($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$this->assertTrue(!$configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$this->assertEquals($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$this->assertTrue($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$this->assertEquals($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
try {
$configuration->getDefinition('baz');
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
} catch (\InvalidArgumentException $e) {
}
}