Commit b7a7800f by Qiang Xue

Fixed constructors.

parent fd3c29aa
......@@ -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);
}
/**
......
......@@ -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);
}
}
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
}
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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';
}
/**
......
<?php
/**
* Response and CCookieCollection class file.
* Response class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
......@@ -10,11 +10,42 @@
namespace yii\base;
/**
* Response encapsulates the $_SERVER variable and resolves its inconsistency among different Web servers.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @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();
}
}
}
......@@ -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);
}
/**
......
......@@ -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())
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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',
),
));
}
}
......@@ -13,7 +13,7 @@ namespace yii\console;
* @author Qiang Xue <qiang.xue@gmail.com>
* @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,
......
......@@ -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);
}
/**
......
......@@ -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)
......
......@@ -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()
......
......@@ -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
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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);
}
/**
......
......@@ -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',
),
));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment