本文整理汇总了PHP中Propel\Runtime\Propel::setServiceContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP Propel::setServiceContainer方法的具体用法?PHP Propel::setServiceContainer怎么用?PHP Propel::setServiceContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Runtime\Propel
的用法示例。
在下文中一共展示了Propel::setServiceContainer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerRuntimeConfiguration
/**
* Register propel runtime configuration.
*
* @return void
*/
protected function registerRuntimeConfiguration()
{
$propel_conf = $this->app->config['propel.propel'];
if (!isset($propel_conf['runtime']['connections'])) {
throw new \InvalidArgumentException('Unable to guess Propel runtime config file. Please, initialize the "propel.runtime" parameter.');
}
/** @var $serviceContainer \Propel\Runtime\ServiceContainer\StandardServiceContainer */
$serviceContainer = Propel::getServiceContainer();
$serviceContainer->closeConnections();
$serviceContainer->checkVersion('2.0.0-dev');
$runtime_conf = $propel_conf['runtime'];
// set connections
foreach ($runtime_conf['connections'] as $connection_name) {
$config = $propel_conf['database']['connections'][$connection_name];
$serviceContainer->setAdapterClass($connection_name, $config['adapter']);
$manager = new ConnectionManagerSingle();
$manager->setConfiguration($config + [$propel_conf['paths']]);
$manager->setName($connection_name);
$serviceContainer->setConnectionManager($connection_name, $manager);
}
$serviceContainer->setDefaultDatasource($runtime_conf['defaultConnection']);
// set loggers
$has_default_logger = false;
if (isset($runtime_conf['log'])) {
$has_default_logger = array_key_exists('defaultLogger', $runtime_conf['log']);
foreach ($runtime_conf['log'] as $logger_name => $logger_conf) {
$serviceContainer->setLoggerConfiguration($logger_name, $logger_conf);
}
}
if (!$has_default_logger) {
$serviceContainer->setLogger('defaultLogger', \Log::getMonolog());
}
Propel::setServiceContainer($serviceContainer);
}
示例2: testSetServiceContainerOverridesTheExistingServiceContainer
public function testSetServiceContainerOverridesTheExistingServiceContainer()
{
$oldSC = Propel::getServiceContainer();
$newSC = new StandardServiceContainer();
Propel::setServiceContainer($newSC);
$this->assertSame($newSC, Propel::getServiceContainer());
Propel::setServiceContainer($oldSC);
}
示例3: setupPropel
/**
* Set propel to be used later
*
* @return void
*/
public static function setupPropel()
{
$serviceContainer = new StandardServiceContainer();
Propel::setServiceContainer($serviceContainer);
$config = Helper::getConfig();
$dbConfig = $config['database'];
$manager = self::setPropelManager($dbConfig);
self::setPropelServiceContainer($serviceContainer, $dbConfig, $manager);
}
示例4: boot
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->publishes([__DIR__ . '/../config/propel.php' => config_path('propel.php')]);
if (!$this->app->config['propel.propel.runtime.connections']) {
throw new \InvalidArgumentException('Unable to guess Propel runtime config file. Please, initialize the "propel.runtime" parameter.');
}
// load pregenerated config
if (file_exists(app_path() . '/propel/config.php')) {
Propel::init(app_path() . '/propel/config.php');
return;
}
// runtime configuration
/** @var \Propel\Runtime\ServiceContainer\StandardServiceContainer */
$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();
$serviceContainer->closeConnections();
$serviceContainer->checkVersion('2.0.0-dev');
$propel_conf = $this->app->config['propel.propel'];
$runtime_conf = $propel_conf['runtime'];
// set connections
foreach ($runtime_conf['connections'] as $connection_name) {
$config = $propel_conf['database']['connections'][$connection_name];
if (!isset($config['classname'])) {
if ($this->app->config['app.debug']) {
$config['classname'] = '\\Propel\\Runtime\\Connection\\DebugPDO';
} else {
$config['classname'] = '\\Propel\\Runtime\\Connection\\ConnectionWrapper';
}
}
$serviceContainer->setAdapterClass($connection_name, $config['adapter']);
$manager = new \Propel\Runtime\Connection\ConnectionManagerSingle();
$manager->setConfiguration($config + [$propel_conf['paths']]);
$manager->setName($connection_name);
$serviceContainer->setConnectionManager($connection_name, $manager);
}
$serviceContainer->setDefaultDatasource($runtime_conf['defaultConnection']);
// set loggers
$has_default_logger = false;
if (isset($runtime_conf['log'])) {
foreach ($runtime_conf['log'] as $logger_name => $logger_conf) {
$serviceContainer->setLoggerConfiguration($logger_name, $logger_conf);
$has_default_logger |= $logger_name === 'defaultLogger';
}
}
if (!$has_default_logger) {
$serviceContainer->setLogger('defaultLogger', \Log::getMonolog());
}
Propel::setServiceContainer($serviceContainer);
$command = false;
if (\App::runningInConsole()) {
$input = new ArgvInput();
$command = $input->getFirstArgument();
}
// skip auth driver adding if running as CLI to avoid auth model not found
if ('propel:model:build' !== $command && 'propel' === \Config::get('auth.driver')) {
$query_name = \Config::get('auth.user_query', false);
if ($query_name) {
$query = new $query_name();
if (!$query instanceof Criteria) {
throw new InvalidConfigurationException("Configuration directive «auth.user_query» must contain valid classpath of user Query. Excpected type: instanceof Propel\\Runtime\\ActiveQuery\\Criteria");
}
} else {
$user_class = \Config::get('auth.model');
$query = new $user_class();
if (!method_exists($query, 'buildCriteria')) {
throw new InvalidConfigurationException("Configuration directive «auth.model» must contain valid classpath of model, which has method «buildCriteria()»");
}
$query = $query->buildPkeyCriteria();
$query->clear();
}
\Auth::extend('propel', function (\Illuminate\Foundation\Application $app) use($query) {
return new PropelUserProvider($query, $app->make('hash'));
});
}
}