From b7a7800fecb6dd8948b25cb43449c9015f980178 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 30 Aug 2012 21:17:42 -0400 Subject: [PATCH] Fixed constructors. --- framework/base/Action.php | 4 +++- framework/base/ActionEvent.php | 4 +++- framework/base/Application.php | 4 +++- framework/base/Controller.php | 4 +++- framework/base/Dictionary.php | 4 +++- framework/base/Event.php | 4 +++- framework/base/Model.php | 4 +++- framework/base/Module.php | 4 +++- framework/base/Request.php | 2 +- framework/base/Response.php | 37 +++++++++++++++++++++++++++--- framework/base/Vector.php | 4 +++- framework/base/View.php | 4 +++- framework/base/Widget.php | 4 +++- framework/caching/ChainedDependency.php | 4 +++- framework/caching/DbDependency.php | 4 +++- framework/caching/ExpressionDependency.php | 4 +++- framework/caching/FileDependency.php | 4 +++- framework/console/Application.php | 17 ++++++++++++++ framework/console/Request.php | 2 +- framework/db/ar/ActiveFinder.php | 3 ++- framework/db/ar/ActiveQuery.php | 4 +++- framework/db/ar/ActiveQueryBuilder.php | 3 ++- framework/db/ar/JoinElement.php | 2 +- framework/db/dao/Command.php | 4 +++- framework/db/dao/DataReader.php | 4 +++- framework/db/dao/Driver.php | 4 +++- framework/db/dao/Expression.php | 4 +++- framework/db/dao/QueryBuilder.php | 4 +++- framework/db/dao/Transaction.php | 4 +++- framework/web/Application.php | 20 ++++++++++++++++ 30 files changed, 144 insertions(+), 30 deletions(-) diff --git a/framework/base/Action.php b/framework/base/Action.php index 8830033..4aa7507 100644 --- a/framework/base/Action.php +++ b/framework/base/Action.php @@ -39,11 +39,13 @@ class Action extends Component /** * @param string $id the ID of this action * @param Controller $controller the controller that owns this action + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($id, $controller) + public function __construct($id, $controller, $config = array()) { $this->id = $id; $this->controller = $controller; + parent::__construct($config); } /** diff --git a/framework/base/ActionEvent.php b/framework/base/ActionEvent.php index 34c440e..d751967 100644 --- a/framework/base/ActionEvent.php +++ b/framework/base/ActionEvent.php @@ -32,9 +32,11 @@ class ActionEvent extends Event /** * Constructor. * @param Action $action the action associated with this action event. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct(Action $action) + public function __construct(Action $action, $config = array()) { $this->action = $action; + parent::__construct($config); } } diff --git a/framework/base/Application.php b/framework/base/Application.php index 4a5c089..badf2ce 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -121,14 +121,16 @@ class Application extends Module * @param string $id the ID of this application. The ID should uniquely identify the application from others. * @param string $basePath the base path of this application. This should point to * the directory containing all application logic, template and data. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($id, $basePath) + public function __construct($id, $basePath, $config = array()) { \Yii::$application = $this; $this->id = $id; $this->setBasePath($basePath); $this->registerDefaultAliases(); $this->registerCoreComponents(); + parent::__construct($config); } /** diff --git a/framework/base/Controller.php b/framework/base/Controller.php index f8da2e0..385f38d 100644 --- a/framework/base/Controller.php +++ b/framework/base/Controller.php @@ -78,11 +78,13 @@ class Controller extends Component /** * @param string $id ID of this controller * @param Module $module the module that this controller belongs to. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($id, $module) + public function __construct($id, $module, $config = array()) { $this->id = $id; $this->module = $module; + parent::__construct($config); } /** diff --git a/framework/base/Dictionary.php b/framework/base/Dictionary.php index 4c73463..b8a2173 100644 --- a/framework/base/Dictionary.php +++ b/framework/base/Dictionary.php @@ -48,13 +48,15 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co * Initializes the dictionary with an array or an iterable object. * @param mixed $data the initial data to be populated into the dictionary. * This can be an array or an iterable object. + * @param array $config name-value pairs that will be used to initialize the object properties * @throws Exception if data is not well formed (neither an array nor an iterable object) */ - public function __construct($data = array()) + public function __construct($data = array(), $config = array()) { if ($data !== array()) { $this->copyFrom($data); } + parent::__construct($config); } /** diff --git a/framework/base/Event.php b/framework/base/Event.php index 44b3254..be84d1a 100644 --- a/framework/base/Event.php +++ b/framework/base/Event.php @@ -49,10 +49,12 @@ class Event extends \yii\base\Object * * @param mixed $sender sender of the event * @param mixed $data extra data associated with the event + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($sender = null, $data = null) + public function __construct($sender = null, $data = null, $config = array()) { $this->sender = $sender; $this->data = $data; + parent::__construct($config); } } diff --git a/framework/base/Model.php b/framework/base/Model.php index eee5715..b2da4e2 100644 --- a/framework/base/Model.php +++ b/framework/base/Model.php @@ -54,10 +54,12 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess /** * Constructor. * @param string|null $scenario name of the [[scenario]] that this model is used in. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($scenario = null) + public function __construct($scenario = null, $config = array()) { $this->_scenario = $scenario; + parent::__construct($config); } /** diff --git a/framework/base/Module.php b/framework/base/Module.php index 50a12fd..07005fb 100644 --- a/framework/base/Module.php +++ b/framework/base/Module.php @@ -108,11 +108,13 @@ abstract class Module extends Component * Constructor. * @param string $id the ID of this module * @param Module $parent the parent module (if any) + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($id, $parent = null) + public function __construct($id, $parent = null, $config = array()) { $this->id = $id; $this->module = $parent; + parent::__construct($config); } /** diff --git a/framework/base/Request.php b/framework/base/Request.php index dacc468..9a7fac5 100644 --- a/framework/base/Request.php +++ b/framework/base/Request.php @@ -24,7 +24,7 @@ class Request extends ApplicationComponent */ public function getIsConsoleRequest() { - return isset($this->_isConsoleRequest) ? $this->_isConsoleRequest : PHP_SAPI === 'cli'; + return $this->_isConsoleRequest !== null ? $this->_isConsoleRequest : PHP_SAPI === 'cli'; } /** diff --git a/framework/base/Response.php b/framework/base/Response.php index c15d108..2dcbdc2 100644 --- a/framework/base/Response.php +++ b/framework/base/Response.php @@ -1,6 +1,6 @@ * @since 2.0 */ class Response extends ApplicationComponent { + public function beginOutput() + { + ob_start(); + ob_implicit_flush(false); + } + + public function endOutput() + { + return ob_get_clean(); + } + + public function getOutput() + { + return ob_get_contents(); + } + + public function cleanOutput() + { + ob_clean(); + } + + public function removeOutput($all = true) + { + if ($all) { + for ($level = ob_get_level(); $level > 0; --$level) { + if (!@ob_end_clean()) { + ob_clean(); + } + } + } else { + ob_end_clean(); + } + } } diff --git a/framework/base/Vector.php b/framework/base/Vector.php index f6c7aca..6bd178e 100644 --- a/framework/base/Vector.php +++ b/framework/base/Vector.php @@ -55,13 +55,15 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta * Initializes the vector with an array or an iterable object. * @param mixed $data the initial data to be populated into the vector. * This can be an array or an iterable object. + * @param array $config name-value pairs that will be used to initialize the object properties * @throws Exception if data is not well formed (neither an array nor an iterable object) */ - public function __construct($data = array()) + public function __construct($data = array(), $config = array()) { if ($data !== array()) { $this->copyFrom($data); } + parent::__construct($config); } /** diff --git a/framework/base/View.php b/framework/base/View.php index f2a06e2..32aab50 100644 --- a/framework/base/View.php +++ b/framework/base/View.php @@ -63,10 +63,12 @@ class View extends Component /** * Constructor. * @param Controller|Widget|Object $context the context under which this view is being rendered (e.g. controller, widget) + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($context = null) + public function __construct($context = null, $config = array()) { $this->context = $context; + parent::__construct($config); } public function render($view, $params = array()) diff --git a/framework/base/Widget.php b/framework/base/Widget.php index 23efd37..45e9335 100644 --- a/framework/base/Widget.php +++ b/framework/base/Widget.php @@ -33,10 +33,12 @@ class Widget extends Component /** * Constructor. * @param Widget|Controller $owner owner/creator of this widget. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($owner) + public function __construct($owner, $config = array()) { $this->owner = $owner; + parent::__construct($config); } /** diff --git a/framework/caching/ChainedDependency.php b/framework/caching/ChainedDependency.php index 664fc10..bdc8a8a 100644 --- a/framework/caching/ChainedDependency.php +++ b/framework/caching/ChainedDependency.php @@ -42,10 +42,12 @@ class ChainedDependency extends Dependency * @param array $dependencies list of dependencies that this dependency is composed of. * Each array element should be a dependency object or a configuration array * that can be used to create a dependency object via [[\Yii::createObject()]]. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($dependencies = array()) + public function __construct($dependencies = array(), $config = array()) { $this->dependencies = $dependencies; + parent::__construct($config); } /** diff --git a/framework/caching/DbDependency.php b/framework/caching/DbDependency.php index b0b44be..319483e 100644 --- a/framework/caching/DbDependency.php +++ b/framework/caching/DbDependency.php @@ -41,10 +41,12 @@ class DbDependency extends Dependency /** * Constructor. * @param Query $query the SQL query whose result is used to determine if the dependency has been changed. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($query = null) + public function __construct($query = null, $config = array()) { $this->query = $query; + parent::__construct($config); } /** diff --git a/framework/caching/ExpressionDependency.php b/framework/caching/ExpressionDependency.php index a553cdc..40bbf7e 100644 --- a/framework/caching/ExpressionDependency.php +++ b/framework/caching/ExpressionDependency.php @@ -29,10 +29,12 @@ class ExpressionDependency extends Dependency /** * Constructor. * @param string $expression the PHP expression whose result is used to determine the dependency. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($expression = 'true') + public function __construct($expression = 'true', $config = array()) { $this->expression = $expression; + parent::__construct($config); } /** diff --git a/framework/caching/FileDependency.php b/framework/caching/FileDependency.php index cd02b12..aed986b 100644 --- a/framework/caching/FileDependency.php +++ b/framework/caching/FileDependency.php @@ -29,10 +29,12 @@ class FileDependency extends Dependency /** * Constructor. * @param string $fileName name of the file whose change is to be checked. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($fileName = null) + public function __construct($fileName = null, $config = array()) { $this->fileName = $fileName; + parent::__construct($config); } /** diff --git a/framework/console/Application.php b/framework/console/Application.php index 1098ab1..1e1796f 100644 --- a/framework/console/Application.php +++ b/framework/console/Application.php @@ -135,4 +135,21 @@ class Application extends \yii\base\Application 'app' => 'yii\console\controllers\AppController', ); } + + /** + * Registers the core application components. + * @see setComponents + */ + public function registerCoreComponents() + { + parent::registerCoreComponents(); + $this->setComponents(array( + 'request' => array( + 'class' => 'yii\console\Request', + ), + 'response' => array( + 'class' => 'yii\console\Response', + ), + )); + } } diff --git a/framework/console/Request.php b/framework/console/Request.php index 6133414..195a840 100644 --- a/framework/console/Request.php +++ b/framework/console/Request.php @@ -13,7 +13,7 @@ namespace yii\console; * @author Qiang Xue * @since 2.0 */ -class Request extends \yii\base\ApplicationComponent +class Request extends \yii\base\Request { /** * @var string the controller route specified by this request. If this is an empty string, diff --git a/framework/db/ar/ActiveFinder.php b/framework/db/ar/ActiveFinder.php index 5613639..e1be9bb 100644 --- a/framework/db/ar/ActiveFinder.php +++ b/framework/db/ar/ActiveFinder.php @@ -30,9 +30,10 @@ class ActiveFinder extends \yii\base\Object */ public $connection; - public function __construct($connection) + public function __construct($connection, $config = array()) { $this->connection = $connection; + parent::__construct($config); } /** diff --git a/framework/db/ar/ActiveQuery.php b/framework/db/ar/ActiveQuery.php index 4a812a2..ce7291b 100644 --- a/framework/db/ar/ActiveQuery.php +++ b/framework/db/ar/ActiveQuery.php @@ -38,10 +38,12 @@ class ActiveQuery extends BaseActiveQuery implements \IteratorAggregate, \ArrayA /** * @param string $modelClass the name of the ActiveRecord class. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($modelClass) + public function __construct($modelClass, $config = array()) { $this->modelClass = $modelClass; + parent::__construct($config); } public function __call($name, $params) diff --git a/framework/db/ar/ActiveQueryBuilder.php b/framework/db/ar/ActiveQueryBuilder.php index e17157f..620c336 100644 --- a/framework/db/ar/ActiveQueryBuilder.php +++ b/framework/db/ar/ActiveQueryBuilder.php @@ -26,9 +26,10 @@ class ActiveQueryBuilder extends \yii\base\Object */ public $query; - public function __construct($query) + public function __construct($query, $config = array()) { $this->query = $query; + parent::__construct($config); } public function build() diff --git a/framework/db/ar/JoinElement.php b/framework/db/ar/JoinElement.php index 65f80c1..9758b69 100644 --- a/framework/db/ar/JoinElement.php +++ b/framework/db/ar/JoinElement.php @@ -15,7 +15,7 @@ use yii\db\dao\Query; use yii\db\Exception; -class JoinElement extends \yii\base\Object +class JoinElement { /** * @var integer ID of this join element diff --git a/framework/db/dao/Command.php b/framework/db/dao/Command.php index e025ca0..bde3225 100644 --- a/framework/db/dao/Command.php +++ b/framework/db/dao/Command.php @@ -66,12 +66,14 @@ class Command extends \yii\base\Component * @param Connection $connection the database connection * @param string $sql the SQL statement to be executed * @param array $params the parameters to be bound to the SQL statement + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($connection, $sql = null, $params = array()) + public function __construct($connection, $sql = null, $params = array(), $config = array()) { $this->connection = $connection; $this->_sql = $sql; $this->bindValues($params); + parent::__construct($config); } /** diff --git a/framework/db/dao/DataReader.php b/framework/db/dao/DataReader.php index b791a47..91b2ce6 100644 --- a/framework/db/dao/DataReader.php +++ b/framework/db/dao/DataReader.php @@ -52,11 +52,13 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable /** * Constructor. * @param Command $command the command generating the query result + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct(Command $command) + public function __construct(Command $command, $config = array()) { $this->_statement = $command->pdoStatement; $this->_statement->setFetchMode(\PDO::FETCH_ASSOC); + parent::__construct($config); } /** diff --git a/framework/db/dao/Driver.php b/framework/db/dao/Driver.php index 9ca86e2..46a0d62 100644 --- a/framework/db/dao/Driver.php +++ b/framework/db/dao/Driver.php @@ -71,10 +71,12 @@ abstract class Driver extends \yii\base\Object /** * Constructor. * @param Connection $connection database connection. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($connection) + public function __construct($connection, $config = array()) { $this->connection = $connection; + parent::__construct($config); } /** diff --git a/framework/db/dao/Expression.php b/framework/db/dao/Expression.php index 7d0a960..5975997 100644 --- a/framework/db/dao/Expression.php +++ b/framework/db/dao/Expression.php @@ -42,11 +42,13 @@ class Expression extends \yii\base\Object * Constructor. * @param string $expression the DB expression * @param array $params parameters + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($expression, $params = array()) + public function __construct($expression, $params = array(), $config = array()) { $this->expression = $expression; $this->params = $params; + parent::__construct($config); } /** diff --git a/framework/db/dao/QueryBuilder.php b/framework/db/dao/QueryBuilder.php index 2a69467..a2b685f 100644 --- a/framework/db/dao/QueryBuilder.php +++ b/framework/db/dao/QueryBuilder.php @@ -49,10 +49,12 @@ class QueryBuilder extends \yii\base\Object /** * Constructor. * @param Connection $connection the database connection. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct($connection) + public function __construct($connection, $config = array()) { $this->connection = $connection; + parent::__construct($config); } /** diff --git a/framework/db/dao/Transaction.php b/framework/db/dao/Transaction.php index 70ba26d..0556ecb 100644 --- a/framework/db/dao/Transaction.php +++ b/framework/db/dao/Transaction.php @@ -49,12 +49,14 @@ class Transaction extends \yii\base\Object /** * Constructor. * @param Connection $connection the connection associated with this transaction + * @param array $config name-value pairs that will be used to initialize the object properties * @see Connection::beginTransaction */ - public function __construct($connection) + public function __construct($connection, $config = array()) { $this->active = true; $this->connection = $connection; + parent::__construct($config); } /** diff --git a/framework/web/Application.php b/framework/web/Application.php index 10bd6ce..912af40 100644 --- a/framework/web/Application.php +++ b/framework/web/Application.php @@ -31,4 +31,24 @@ class Application extends \yii\base\Application { return array(); } + + /** + * Registers the core application components. + * @see setComponents + */ + public function registerCoreComponents() + { + parent::registerCoreComponents(); + $this->setComponents(array( + 'urlManager' => array( + 'class' => 'yii\web\UrlManager', + ), + 'request' => array( + 'class' => 'yii\web\Request', + ), + 'response' => array( + 'class' => 'yii\web\Response', + ), + )); + } }