本文整理汇总了PHP中Yii::setApplication方法的典型用法代码示例。如果您正苦于以下问题:PHP Yii::setApplication方法的具体用法?PHP Yii::setApplication怎么用?PHP Yii::setApplication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yii
的用法示例。
在下文中一共展示了Yii::setApplication方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($config = null)
{
if (is_string($config)) {
$config = (require $config);
}
Yii::setApplication($this);
//保存整个app实例
if (isset($config['basePath'])) {
$this->setBasePath($config['basePath']);
unset($config['basePath']);
} else {
$this->setBasePath('protected');
}
//设置别名,后面就可以用application表示basePath了
Yii::setPathOfAlias('application', $this->getBasePath());
//钩子,模块 预 初始化时执行,子类实现。不过这时,配置还没有写入框架
$this->preinit();
$this->registerCoreComponents();
//父类实现
$this->configure($config);
//加载静态应用组件
$this->preloadComponents();
//这才开始初始化模块
$this->init();
}
示例2: actionClearFrontend
public function actionClearFrontend()
{
$local = (require './protected/config/main-local.php');
$base = (require './protected/config/main.php');
$config = CMap::mergeArray($base, $local);
Yii::setApplication(null);
Yii::createWebApplication($config)->cache->flush();
$this->redirect('index');
}
示例3: run
/**
* Execute the action.
* @param array $args command line parameters specific for this command
*/
public function run($args)
{
if (!isset($args[0])) {
$args[0] = 'index.php';
}
$entryScript = isset($args[0]) ? $args[0] : 'index.php';
if (($entryScript = realpath($args[0])) === false || !is_file($entryScript)) {
$this->usageError("{$args[0]} does not exist or is not an entry script file.");
}
// fake the web server setting
$cwd = getcwd();
chdir(dirname($entryScript));
$_SERVER['SCRIPT_NAME'] = '/' . basename($entryScript);
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_FILENAME'] = $entryScript;
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['SERVER_PORT'] = 80;
// reset context to run the web application
restore_error_handler();
restore_exception_handler();
Yii::setApplication(null);
Yii::setPathOfAlias('application', null);
ob_start();
$config = (require $entryScript);
ob_end_clean();
// oops, the entry script turns out to be a config file
if (is_array($config)) {
chdir($cwd);
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_FILENAME'] = $cwd . DIRECTORY_SEPARATOR . 'index.php';
Yii::createWebApplication($config);
}
restore_error_handler();
restore_exception_handler();
$yiiVersion = Yii::getVersion();
echo <<<EOD
Yii Interactive Tool v1.1 (based on Yii v{$yiiVersion})
Please type 'help' for help. Type 'exit' to quit.
EOD;
$this->runShell();
}
示例4: __construct
public function __construct($config = null)
{
Yii::setApplication($this);
// set basePath at early as possible to avoid trouble
if (is_string($config)) {
$config = (require $config);
}
if (isset($config['basePath'])) {
$this->setBasePath($config['basePath']);
unset($config['basePath']);
} else {
$this->setBasePath('protected');
}
Yii::setPathOfAlias('application', $this->getBasePath());
Yii::setPathOfAlias('webroot', dirname($_SERVER['SCRIPT_FILENAME']));
Yii::setPathOfAlias('ext', $this->getBasePath() . DIRECTORY_SEPARATOR . 'extensions');
$this->preinit();
$this->initSystemHandlers();
$this->registerCoreComponents();
$this->configure($config);
$this->attachBehaviors($this->behaviors);
$this->preloadComponents();
$this->init();
}
示例5: __construct
public function __construct($config = null)
{
Yii::setApplication(null);
clearstatcache();
parent::__construct($config);
}
示例6: destroyApplication
protected function destroyApplication()
{
Yii::setApplication(null);
}
示例7: tearDown
/**
* Clean up after test.
* The application created with [[mockApplication]] will be destroyed.
*/
protected function tearDown()
{
parent::tearDown();
Yii::setApplication(null);
}
示例8: runRequest
protected function runRequest($entryScript, $params = array())
{
restore_error_handler();
restore_exception_handler();
Yii::setApplication(null);
Yii::setPathOfAlias('application', null);
$_GET = $params;
require $entryScript;
}
示例9: doRequest
/**
*
* @param \Symfony\Component\BrowserKit\Request $request
*
* @return \Symfony\Component\BrowserKit\Response
*/
public function doRequest($request)
{
$this->headers = array();
$_COOKIE = array_merge($_COOKIE, $request->getCookies());
$_SERVER = array_merge($_SERVER, $request->getServer());
$_FILES = $this->remapFiles($request->getFiles());
$_REQUEST = $this->remapRequestParameters($request->getParameters());
$_POST = $_GET = array();
if (strtoupper($request->getMethod()) == 'GET') {
$_GET = $_REQUEST;
} else {
$_POST = $_REQUEST;
}
// Parse url parts
$uriPath = trim(parse_url($request->getUri(), PHP_URL_PATH), '/');
$uriQuery = ltrim(parse_url($request->getUri(), PHP_URL_QUERY), '?');
$scriptName = trim(parse_url($this->url, PHP_URL_PATH), '/');
if (!empty($uriQuery)) {
$uriPath .= "?{$uriQuery}";
parse_str($uriQuery, $params);
foreach ($params as $k => $v) {
$_GET[$k] = $v;
}
}
// Add script name to request if none
if (strpos($uriPath, $scriptName) === false) {
$uriPath = "/{$scriptName}/{$uriPath}";
}
// Add forward slash if not exists
if (strpos($uriPath, '/') !== 0) {
$uriPath = "/{$uriPath}";
}
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
$_SERVER['REQUEST_URI'] = $uriPath;
/**
* Hack to be sure that CHttpRequest will resolve route correctly
*/
$_SERVER['SCRIPT_NAME'] = "/{$scriptName}";
$_SERVER['SCRIPT_FILENAME'] = $this->appPath;
ob_start();
\Yii::setApplication(null);
\Yii::createApplication($this->appSettings['class'], $this->appSettings['config']);
$app = \Yii::app();
// disabling logging. Logs slow down test execution
if ($app->hasComponent('log')) {
foreach ($app->getComponent('log')->routes as $route) {
$route->enabled = false;
}
}
if ($app->hasComponent('session')) {
// disable regenerate id in session
$app->setComponent('session', Stub::make('CHttpSession', ['regenerateID' => false]));
}
$app->onEndRequest->add([$this, 'setHeaders']);
$app->run();
if ($app->hasComponent('db')) {
// close connection
$app->getDb()->setActive(false);
// cleanup metadata cache
$property = new \ReflectionProperty('CActiveRecord', '_md');
$property->setAccessible(true);
$property->setValue([]);
}
$content = ob_get_clean();
$headers = $this->getHeaders();
$statusCode = 200;
foreach ($headers as $header => $val) {
if ($header == 'Location') {
$statusCode = 302;
}
}
$response = new Response($content, $statusCode, $this->getHeaders());
return $response;
}
示例10: getcwd
if (!is_file($entryScript)) {
$this->usageError("{$args[0]} does not exist or is not an entry script file.");
}
// fake the web server setting
$cwd = getcwd();
chdir(dirname($entryScript));
$_SERVER['SCRIPT_NAME'] = '/' . basename($entryScript);
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_FILENAME'] = $entryScript;
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['SERVER_NAME'] = 'localhost';
$_SERVER['SERVER_PORT'] = 80;
// reset context to run the web application
restore_error_handler();
restore_exception_handler();
Yii::setApplication(null);
Yii::setPathOfAlias('application', null);
ob_start();
$config = (require $entryScript);
ob_end_clean();
// oops, the entry script turns out to be a config file
if (is_array($config)) {
chdir($cwd);
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
$_SERVER['SCRIPT_FILENAME'] = $cwd . DIRECTORY_SEPARATOR . 'index.php';
Yii::createWebApplication($config);
}
restore_error_handler();
restore_exception_handler();
$yiiVersion = Yii::getVersion();