Browse Source

Yii references fixes, method names

tags/2.0.0-beta
Alexander Makarov 13 years ago
parent
commit
0b4d9eb05a
  1. 53
      framework/base/Application.php

53
framework/base/Application.php

@ -8,6 +8,8 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yii\base;
/** /**
* Application is the base class for all application classes. * Application is the base class for all application classes.
* *
@ -114,7 +116,7 @@ abstract class Application extends Module
*/ */
public function __construct($config = null) public function __construct($config = null)
{ {
Yii::setApplication($this); \Yii::$app = $this;
// set basePath at early as possible to avoid trouble // set basePath at early as possible to avoid trouble
if (is_string($config)) if (is_string($config))
@ -126,9 +128,9 @@ abstract class Application extends Module
} }
else else
$this->setBasePath('protected'); $this->setBasePath('protected');
Yii::setPathOfAlias('application', $this->getBasePath()); \Yii::setAlias('application', $this->getBasePath());
Yii::setPathOfAlias('webroot', dirname($_SERVER['SCRIPT_FILENAME'])); \Yii::setAlias('webroot', dirname($_SERVER['SCRIPT_FILENAME']));
Yii::setPathOfAlias('ext', $this->getBasePath() . DIRECTORY_SEPARATOR . 'extensions'); \Yii::setAlias('ext', $this->getBasePath() . DIRECTORY_SEPARATOR . 'extensions');
$this->preinit(); $this->preinit();
@ -151,10 +153,10 @@ abstract class Application extends Module
*/ */
public function run() public function run()
{ {
if ($this->hasEventHandler('onBeginRequest')) if ($this->hasEventHandlers('onBeginRequest'))
$this->onBeginRequest(new CEvent($this)); $this->onBeginRequest(new CEvent($this));
$this->processRequest(); $this->processRequest();
if ($this->hasEventHandler('onEndRequest')) if ($this->hasEventHandlers('onEndRequest'))
$this->onEndRequest(new CEvent($this)); $this->onEndRequest(new CEvent($this));
} }
@ -168,7 +170,7 @@ abstract class Application extends Module
*/ */
public function end($status = 0, $exit = true) public function end($status = 0, $exit = true)
{ {
if ($this->hasEventHandler('onEndRequest')) if ($this->hasEventHandlers('onEndRequest'))
$this->onEndRequest(new CEvent($this)); $this->onEndRequest(new CEvent($this));
if ($exit) if ($exit)
exit($status); exit($status);
@ -235,7 +237,7 @@ abstract class Application extends Module
public function setBasePath($path) public function setBasePath($path)
{ {
if (($this->_basePath = realpath($path)) === false || !is_dir($this->_basePath)) if (($this->_basePath = realpath($path)) === false || !is_dir($this->_basePath))
throw new CException(Yii::t('yii', 'Application base path "{path}" is not a valid directory.', throw new \yii\base\Exception(\Yii::t('yii', 'Application base path "{path}" is not a valid directory.',
array('{path}' => $path))); array('{path}' => $path)));
} }
@ -262,7 +264,7 @@ abstract class Application extends Module
public function setRuntimePath($path) public function setRuntimePath($path)
{ {
if (($runtimePath = realpath($path)) === false || !is_dir($runtimePath) || !is_writable($runtimePath)) if (($runtimePath = realpath($path)) === false || !is_dir($runtimePath) || !is_writable($runtimePath))
throw new CException(Yii::t('yii', 'Application runtime path "{path}" is not valid. Please make sure it is a directory writable by the Web server process.', throw new \yii\base\Exception(\Yii::t('yii', 'Application runtime path "{path}" is not valid. Please make sure it is a directory writable by the Web server process.',
array('{path}' => $path))); array('{path}' => $path)));
$this->_runtimePath = $runtimePath; $this->_runtimePath = $runtimePath;
} }
@ -273,7 +275,7 @@ abstract class Application extends Module
*/ */
public function getExtensionPath() public function getExtensionPath()
{ {
return Yii::getPathOfAlias('ext'); return \Yii::getPathOfAlias('ext');
} }
/** /**
@ -283,9 +285,9 @@ abstract class Application extends Module
public function setExtensionPath($path) public function setExtensionPath($path)
{ {
if (($extensionPath = realpath($path)) === false || !is_dir($extensionPath)) if (($extensionPath = realpath($path)) === false || !is_dir($extensionPath))
throw new CException(Yii::t('yii', 'Extension path "{path}" does not exist.', throw new \yii\base\Exception(\Yii::t('yii', 'Extension path "{path}" does not exist.',
array('{path}' => $path))); array('{path}' => $path)));
Yii::setPathOfAlias('ext', $extensionPath); \Yii::setAlias('ext', $extensionPath);
} }
/** /**
@ -386,7 +388,7 @@ abstract class Application extends Module
*/ */
public function getLocaleDataPath() public function getLocaleDataPath()
{ {
return CLocale::$dataPath === null ? Yii::getPathOfAlias('system.i18n.data') : CLocale::$dataPath; return CLocale::$dataPath === null ? \Yii::getPathOfAlias('system.i18n.data') : CLocale::$dataPath;
} }
/** /**
@ -641,7 +643,7 @@ abstract class Application extends Module
/** /**
* Loads the global state data from persistent storage. * Loads the global state data from persistent storage.
* @see getStatePersister * @see getStatePersister
* @throws CException if the state persister is not available * @throws \yii\base\Exception if the state persister is not available
*/ */
public function loadGlobalState() public function loadGlobalState()
{ {
@ -688,27 +690,33 @@ abstract class Application extends Module
restore_exception_handler(); restore_exception_handler();
$category = 'exception.' . get_class($exception); $category = 'exception.' . get_class($exception);
if ($exception instanceof CHttpException) if ($exception instanceof \yii\web\HttpException)
$category .= '.' . $exception->statusCode; $category .= '.' . $exception->statusCode;
// php <5.2 doesn't support string conversion auto-magically // php <5.2 doesn't support string conversion auto-magically
$message = $exception->__toString(); $message = $exception->__toString();
if (isset($_SERVER['REQUEST_URI'])) if (isset($_SERVER['REQUEST_URI']))
$message .= ' REQUEST_URI=' . $_SERVER['REQUEST_URI']; $message .= ' REQUEST_URI=' . $_SERVER['REQUEST_URI'];
Yii::log($message, CLogger::LEVEL_ERROR, $category); \Yii::error($message, $category);
try try
{ {
$event = new CExceptionEvent($this, $exception); // TODO: do we need separate exception class as it was in 1.1?
//$event = new CExceptionEvent($this, $exception);
$event = new Event($this, array('exception' => $exception));
$this->onException($event); $this->onException($event);
if (!$event->handled) if (!$event->handled)
{ {
// try an error handler // try an error handler
if (($handler = $this->getErrorHandler()) !== null) if (($handler = $this->getErrorHandler()) !== null)
{
$handler->handle($event); $handler->handle($event);
}
else else
{
$this->displayException($exception); $this->displayException($exception);
} }
} }
}
catch(Exception $e) catch(Exception $e)
{ {
$this->displayException($e); $this->displayException($e);
@ -777,11 +785,11 @@ abstract class Application extends Module
} }
if (isset($_SERVER['REQUEST_URI'])) if (isset($_SERVER['REQUEST_URI']))
$log .= 'REQUEST_URI=' . $_SERVER['REQUEST_URI']; $log .= 'REQUEST_URI=' . $_SERVER['REQUEST_URI'];
Yii::log($log, CLogger::LEVEL_ERROR, 'php'); \Yii::error($log, 'php');
try try
{ {
Yii::import('CErrorEvent', true); \Yii::import('CErrorEvent', true);
$event = new CErrorEvent($this, $code, $message, $file, $line); $event = new CErrorEvent($this, $code, $message, $file, $line);
$this->onError($event); $this->onError($event);
if (!$event->handled) if (!$event->handled)
@ -940,9 +948,10 @@ abstract class Application extends Module
'messages' => array( 'messages' => array(
'class' => 'CPhpMessageSource', 'class' => 'CPhpMessageSource',
), ),
'errorHandler' => array( // TODO: uncomment when error handler is properly implemented
'class' => 'CErrorHandler', // 'errorHandler' => array(
), // 'class' => 'CErrorHandler',
// ),
'securityManager' => array( 'securityManager' => array(
'class' => 'CSecurityManager', 'class' => 'CSecurityManager',
), ),

Loading…
Cancel
Save