本文整理汇总了PHP中Silex\Application::getEnvironment方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getEnvironment方法的具体用法?PHP Application::getEnvironment怎么用?PHP Application::getEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::getEnvironment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_config_info
/**
* Provide information about phraseanet configuration
*
* @param \Silex\Application $app the silex application
*
* @return array
*/
private function get_config_info(Application $app)
{
$ret = [];
$ret['phraseanet']['version'] = ['name' => $app['phraseanet.version']::getName(), 'number' => $app['phraseanet.version']::getNumber()];
$ret['phraseanet']['environment'] = $app->getEnvironment();
$ret['phraseanet']['debug'] = $app['debug'];
$ret['phraseanet']['maintenance'] = $app['conf']->get(['main', 'maintenance']);
$ret['phraseanet']['errorsLog'] = $app['debug'];
$ret['phraseanet']['serverName'] = $app['conf']->get('servername');
return $ret;
}
示例2: register
public function register(Application $app)
{
$app['EM.sql-logger.file'] = $app->share(function (Application $app) {
return $app['log.path'] . '/doctrine-log.log';
});
$app['EM.sql-logger.max-files'] = 5;
$app['EM.sql-logger'] = $app->share(function (Application $app) {
$logger = new $app['monolog.logger.class']('doctrine-logger');
$logger->pushHandler(new RotatingFileHandler($app['EM.sql-logger.file'], $app['EM.sql-logger.max-files']));
return new MonologSQLLogger($logger, 'yaml');
});
$app['EM.driver'] = $app->share(function (Application $app) {
AnnotationRegistry::registerFile($app['root.path'] . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
$annotationReader = new AnnotationReader();
$fileCacheReader = new FileCacheReader($annotationReader, $app['cache.path'] . '/doctrine', $app['debug']);
$driverChain = new MappingDriverChain();
DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $fileCacheReader);
$annotationDriver = new AnnotationDriver($annotationReader, [$app['root.path'] . '/lib/Alchemy/Phrasea/Model/Entities']);
$driverChain->addDriver($annotationDriver, 'Alchemy\\Phrasea\\Model\\Entities');
return $driverChain;
});
$app['EM.config'] = $app->share(function (Application $app) {
$config = new ORMConfiguration();
if ($app->getEnvironment() === PhraseaApplication::ENV_DEV) {
$config->setSQLLogger($app['EM.sql-logger']);
}
$config->setMetadataCacheImpl($app['phraseanet.cache-service']->factory('ORMmetadata', $app['EM.opcode-cache-type'], $app['EM.opcode-cache-options']));
$config->setQueryCacheImpl($app['phraseanet.cache-service']->factory('ORMquery', $app['EM.opcode-cache-type'], $app['EM.opcode-cache-options']));
$config->setResultCacheImpl($app['phraseanet.cache-service']->factory('ORMresult', $app['EM.cache-type'], $app['EM.cache-options']));
$config->setAutoGenerateProxyClasses($app['debug']);
$config->setMetadataDriverImpl($app['EM.driver']);
$config->setProxyDir($app['root.path'] . '/resources/proxies');
$config->setProxyNamespace('Alchemy\\Phrasea\\Model\\Proxies');
$config->setAutoGenerateProxyClasses($app['debug']);
$config->addEntityNamespace('Phraseanet', 'Alchemy\\Phrasea\\Model\\Entities');
return $config;
});
$app['EM.opcode-cache-type'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'opcodecache', 'type']);
}
return 'ArrayCache';
});
$app['EM.opcode-cache-options'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'opcodecache', 'options']);
}
return [];
});
$app['EM.cache-type'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'cache', 'type']);
}
return 'ArrayCache';
});
$app['EM.cache-options'] = $app->share(function (Application $app) {
if ($app['configuration.store']->isSetup()) {
return $app['conf']->get(['main', 'cache', 'options']);
}
return [];
});
$app['EM.events-manager'] = $app->share(function (Application $app) {
$evm = new EventManager();
$evm->addEventSubscriber(new TimestampableListener());
return $evm;
});
$app['EM.dbal-conf'] = $app->share(function (Application $app) {
if ('test' === $app->getEnvironment()) {
return $app['conf']->get(['main', 'database-test']);
}
return $app['conf']->get(['main', 'database']);
});
$app['dbal.provider'] = $app->share(function (Application $app) {
return new ConnectionProvider($app['EM.config'], $app['EM.events-manager'], isset($app['task-manager.logger']) ? $app['task-manager.logger'] : $app['monolog']);
});
$app['EM'] = $app->share(function (Application $app) {
try {
$em = EntityManager::create($app['EM.dbal-conf'], $app['EM.config'], $app['EM.events-manager']);
} catch (\Exception $e) {
throw new RuntimeException("Unable to create database connection", $e->getCode(), $e);
}
$platform = $em->getConnection()->getDatabasePlatform();
$types = ['blob' => 'Alchemy\\Phrasea\\Model\\Types\\Blob', 'enum' => 'Alchemy\\Phrasea\\Model\\Types\\Blob', 'longblob' => 'Alchemy\\Phrasea\\Model\\Types\\LongBlob', 'varbinary' => 'Alchemy\\Phrasea\\Model\\Types\\VarBinary', 'binary' => 'Alchemy\\Phrasea\\Model\\Types\\Binary', 'binary_string' => 'Alchemy\\Phrasea\\Model\\Types\\BinaryString'];
foreach ($types as $type => $class) {
if (!Type::hasType($type)) {
Type::addType($type, $class);
}
$platform->registerDoctrineTypeMapping($type, $type);
}
return $em;
});
$app['EM.native-query'] = $app->share(function ($app) {
return new NativeQueryProvider($app['EM']);
});
}
示例3: register
//.........这里部分代码省略.........
$key = $app['hash.dsn']($app['db.dsn']($info));
$evm = new EventManager();
$app['dbal.evm.register.listeners']($evm);
$app['dbs.event_manager'][$key] = $evm;
$app['dbs.config'][$key] = new Configuration();
$app['dbs'][$key] = $app['dbs']->share(function () use($app, $info, $key) {
return DriverManager::getConnection($info, $app['dbs.config'][$key], $app['dbs.event_manager'][$key]);
});
$options = $app['orm.options']($key);
$config = $app['orm.config.new']($key, $options);
$app['orm.annotation.register']($key);
$app['orm.ems'][$key] = $app['orm.ems']->share(function ($ems) use($app, $key, $options, $config) {
$connection = $app['dbs'][$key];
$app['connection.pool.manager']->add($connection);
$types = $options['types'];
$app['dbal.type.register']($connection, $types);
return EntityManager::create($connection, $config, $app['dbs.event_manager'][$options['connection']]);
});
return $key;
});
// Listeners should be attached with their events as info.
$app['dbal.evm.listeners'] = $app->share(function () {
return new \SplObjectStorage();
});
$app['dbal.evm.register.listeners'] = $app->protect(function (EventManager $evm) use($app) {
$evm->addEventSubscriber(new TimestampableListener());
/** @var \SplObjectStorage $listeners */
$listeners = $app['dbal.evm.listeners'];
foreach ($listeners as $listener) {
$evm->addEventListener($listeners[$listener], $listener);
}
});
$app['dbal.config.register.loggers'] = $app->protect(function (Configuration $config) use($app) {
if ($app->getEnvironment() === PhraseaApplication::ENV_DEV) {
$config->setSQLLogger($app['orm.query.logger']);
}
});
$app['orm.annotation.register'] = $app->protect(function ($key) use($app) {
$driver = new AnnotationDriver($app['orm.annotation.reader'], array($app['root.path'] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity/MappedSuperclass', $app['root.path'] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity/MappedSuperclass', $app['root.path'] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity/MappedSuperclass'));
$app['orm.add_mapping_driver']($driver, 'Gedmo', $key);
});
$app['dbal.type.register'] = $app->protect(function (Connection $connection, $types) {
$platform = $connection->getDatabasePlatform();
foreach (array_keys((array) $types) as $type) {
$platform->registerDoctrineTypeMapping($type, $type);
}
});
$app['orm.config.new'] = $app->protect(function ($key, $options) use($app) {
$config = new ORMConfig();
$app['orm.cache.configurer']($key, $config, $options);
$config->setProxyDir($app['orm.proxies_dir']);
$config->setProxyNamespace($app['orm.proxies_namespace']);
$config->setAutoGenerateProxyClasses($app['orm.auto_generate_proxies']);
$config->setCustomStringFunctions($app['orm.custom.functions.string']);
$config->setCustomNumericFunctions($app['orm.custom.functions.numeric']);
$config->setCustomDatetimeFunctions($app['orm.custom.functions.datetime']);
$config->setCustomHydrationModes($app['orm.custom.hydration_modes']);
$config->setClassMetadataFactoryName($app['orm.class_metadata_factory_name']);
$config->setDefaultRepositoryClassName($app['orm.default_repository_class']);
$config->setEntityListenerResolver($app['orm.entity_listener_resolver']);
$config->setRepositoryFactory($app['orm.repository_factory']);
$config->setNamingStrategy($app['orm.strategy.naming']);
$config->setQuoteStrategy($app['orm.strategy.quote']);
$chain = $app['orm.mapping_driver_chain.locator']($key);
foreach ((array) $options['mappings'] as $entity) {
if (!is_array($entity)) {