本文整理汇总了PHP中CBLib\Application\Application::createApplication方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::createApplication方法的具体用法?PHP Application::createApplication怎么用?PHP Application::createApplication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBLib\Application\Application
的用法示例。
在下文中一共展示了Application::createApplication方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createApplication
/**
* Create CBLib Application if not already created, and returns it for chaining
*
* @param string $type [optional] 'Web' or 'Cli'
* @param array|object|InputInterface|null $input (array_merge(get, post) or argv if cli)
* @param Config|callable|null $config The Config to use (or a closure returning it)
* @return Application
*/
public static function createApplication($type = 'Web', $input = null, $config = null)
{
if (!static::$application) {
// Define $app Containers 'Application' and 'Cms':
$application = Application::createApplication($type);
static::$application = $application;
// Define $app Container 'Config':
$application->set('Config', function () use($config, $application) {
return Config::setMainConfig($config, $application);
}, true, true);
// Define $app Container 'DatabaseDriverInterface':
$application->set('CBLib\\Database\\DatabaseDriverInterface', function (ApplicationContainerInterface $di) {
return Database::createDatabaseDriver($di->getCms());
}, true)->alias('CBLib\\Database\\DatabaseDriverInterface', 'Database');
// Define $app Container 'Input':
$application->set('CBLib\\Input\\InputInterface', function (ApplicationContainerInterface $di) use($type, $input) {
// return static::getMainInput( static::$app, $type, $input );
return $di->getCms()->getInput($di, $type, $input);
}, true)->alias('CBLib\\Input\\InputInterface', 'Input');
// Define $app Container 'Output':
/** @noinspection PhpUnusedParameterInspection */
$application->set('CBLib\\Output\\OutputInterface', function (ApplicationContainerInterface $di, array $parameters) {
return Output::createNew('html', $parameters);
//TODO json+xml
}, true)->alias('CBLib\\Output\\OutputInterface', 'Output');
// 'Router' and CBLib\Controller\RouterInterface service providers are defined in specific Cms constructor.
// Define $app Container 'Session':
$application->set('CBLib\\Session\\SessionInterface', '\\CBLib\\Session\\Session')->alias('CBLib\\Session\\SessionInterface', 'Session');
// Define $app Container 'SessionState':
$application->set('CBLib\\Session\\SessionStateInterface', '\\CBLib\\Session\\SessionState')->alias('CBLib\\Session\\SessionStateInterface', 'SessionState');
// Define $app Container 'User':
$application->set('CBLib\\Entity\\User\\User', function (ApplicationContainerInterface $di, array $parameters) {
if (count($parameters) === 0) {
throw new \UnexpectedValueException('Application::MyUser() called without a parameter');
}
return User::getInstanceForContainerOnly($parameters[0], $di->getCms(), $di->getConfig());
})->alias('CBLib\\Entity\\User\\User', 'User');
$application->set('MyUser', function (ApplicationContainerInterface $di, array $parameters) {
if (count($parameters) !== 0) {
throw new \UnexpectedValueException('Application::User() called with a parameter');
}
return User::getInstanceForContainerOnly(null, $di->getCms(), $di->getConfig());
});
// Define Language and translations, as well as the translations logger interface:
$application->set('Language', 'CBLib\\Language\\CBTxt', true);
$application->set('CBLib\\Language\\TranslationsLoggerInterface', function (ApplicationContainerInterface $di) {
// Creates the logger:
$translationsLogger = new TranslationsLogger();
// Registers after-render event to add the translations log at the end of the html body:
$di->getCms()->registerOnAfterRenderBodyFilter(function ($body) use($translationsLogger) {
return $translationsLogger->appendToBodyUsedStrings($body);
});
return $translationsLogger;
}, true);
}
return static::$application;
}