PHP Method Yii::setApplication Code Examples

This page contains top rated real world PHP examples of method Yii::setApplication extracted from open source projects. You can rate examples to help us improve the quality of examples
Example #1
Show file File: CApplication.php Project: RandomCivil/tiny-yii
0
 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();
 }
Example #2
Show file File: SettingsController.php Project: lhfcainiao/basic
0
 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');
 }
Example #3
Show file File: ShellCommand.php Project: upmunspel/abiturient
0
    /**
     * 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();
    }
Example #4
Show file File: yiilite.php Project: smokeelow/faicore
0
 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();
 }
Example #5
Show file File: TestApplication.php Project: dutchakdev/yii-batch
0
 public function __construct($config = null)
 {
     Yii::setApplication(null);
     clearstatcache();
     parent::__construct($config);
 }
Example #6
Show file File: TbTestCase.php Project: branJakJak/goawtodayaldiskon
0
 protected function destroyApplication()
 {
     Yii::setApplication(null);
 }
Example #7
Show file File: TestCase.php Project: igorsantos07/yii-br-pack
0
 /**
  * Clean up after test.
  * The application created with [[mockApplication]] will be destroyed.
  */
 protected function tearDown()
 {
     parent::tearDown();
     Yii::setApplication(null);
 }
Example #8
Show file File: LiteCommand.php Project: super-d2/codeigniter_demo
0
 protected function runRequest($entryScript, $params = array())
 {
     restore_error_handler();
     restore_exception_handler();
     Yii::setApplication(null);
     Yii::setPathOfAlias('application', null);
     $_GET = $params;
     require $entryScript;
 }
Example #9
Show file File: Yii1.php Project: solutionDrive/Codeception
0
 /**
  *
  * @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;
 }
Example #10
Show file File: sh.php Project: kenrestivo/ossasep
0
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();