Browse Source

Merge remote branch 'upstream/master'

tags/2.0.0-alpha
gevik 11 years ago
parent
commit
004a069c5d
  1. 27
      framework/yii/YiiBase.php
  2. 2
      framework/yii/base/ErrorHandler.php
  3. 1
      framework/yii/base/Formatter.php
  4. 63
      framework/yii/base/HttpException.php
  5. 1
      framework/yii/base/InvalidCallException.php
  6. 1
      framework/yii/base/InvalidConfigException.php
  7. 1
      framework/yii/base/InvalidParamException.php
  8. 1
      framework/yii/base/InvalidRouteException.php
  9. 22
      framework/yii/base/Jsonable.php
  10. 13
      framework/yii/base/Model.php
  11. 1334
      framework/yii/base/Module.php
  12. 1
      framework/yii/base/NotSupportedException.php
  13. 19
      framework/yii/base/Object.php
  14. 2
      framework/yii/base/Theme.php
  15. 1
      framework/yii/base/UnknownClassException.php
  16. 1
      framework/yii/base/UnknownMethodException.php
  17. 1
      framework/yii/base/UnknownPropertyException.php
  18. 3
      framework/yii/bootstrap/Button.php
  19. 2
      framework/yii/bootstrap/ButtonDropdown.php
  20. 1
      framework/yii/bootstrap/ButtonGroup.php
  21. 2
      framework/yii/bootstrap/Collapse.php
  22. 1
      framework/yii/bootstrap/Dropdown.php
  23. 2
      framework/yii/bootstrap/Nav.php
  24. 1
      framework/yii/bootstrap/Progress.php
  25. 1
      framework/yii/bootstrap/Widget.php
  26. 2
      framework/yii/caching/DbCache.php
  27. 1
      framework/yii/caching/XCache.php
  28. 1
      framework/yii/console/Exception.php
  29. 6
      framework/yii/console/controllers/AssetController.php
  30. 3
      framework/yii/console/controllers/MessageController.php
  31. 1270
      framework/yii/console/controllers/MigrateController.php
  32. 7
      framework/yii/db/Connection.php
  33. 103
      framework/yii/db/pgsql/PDO.php
  34. 132
      framework/yii/db/pgsql/Schema.php
  35. 2
      framework/yii/debug/Module.php
  36. 2
      framework/yii/debug/controllers/DefaultController.php
  37. 1
      framework/yii/helpers/Json.php
  38. 5
      framework/yii/helpers/base/Console.php
  39. 1
      framework/yii/helpers/base/Html.php
  40. 6
      framework/yii/helpers/base/Inflector.php
  41. 20
      framework/yii/helpers/base/Json.php
  42. 158
      framework/yii/i18n/DbMessageSource.php
  43. 9
      framework/yii/i18n/I18N.php
  44. 1
      framework/yii/i18n/MessageSource.php
  45. 2
      framework/yii/jui/Accordion.php
  46. 1
      framework/yii/jui/Menu.php
  47. 1
      framework/yii/jui/Widget.php
  48. 3
      framework/yii/rbac/DbManager.php
  49. 2
      framework/yii/rbac/PhpManager.php
  50. 2
      framework/yii/requirements/requirements.php
  51. 1
      framework/yii/validators/CaptchaValidator.php
  52. 1
      framework/yii/validators/DateValidator.php
  53. 1
      framework/yii/validators/DefaultValueValidator.php
  54. 1
      framework/yii/validators/ExistValidator.php
  55. 1
      framework/yii/validators/FilterValidator.php
  56. 2
      framework/yii/validators/RangeValidator.php
  57. 2
      framework/yii/validators/RegularExpressionValidator.php
  58. 1
      framework/yii/validators/StringValidator.php
  59. 2
      framework/yii/validators/UrlValidator.php
  60. 2
      framework/yii/validators/Validator.php
  61. 1
      framework/yii/web/HeaderCollection.php
  62. 206
      framework/yii/web/PageCache.php
  63. 1
      framework/yii/web/Request.php
  64. 243
      framework/yii/web/Response.php
  65. 2
      framework/yii/web/UploadedFile.php
  66. 2
      framework/yii/web/User.php
  67. 348
      framework/yii/widgets/FragmentCache.php
  68. 1
      framework/yii/widgets/ListPager.php
  69. 3
      tests/unit/data/config.php
  70. 1
      tests/unit/framework/web/ResponseTest.php

27
framework/yii/YiiBase.php

@ -606,11 +606,36 @@ class YiiBase
public static function t($category, $message, $params = array(), $language = null)
{
if (self::$app !== null) {
return self::$app->getI18N()->translate($category, $message, $params, $language);
return self::$app->getI18N()->translate($category, $message, $params, $language ?: self::$app->language);
} else {
return is_array($params) ? strtr($message, $params) : $message;
}
}
/**
* Configures an object with the initial property values.
* @param object $object the object to be configured
* @param array $properties the property initial values given in terms of name-value pairs.
*/
public static function configure($object, $properties)
{
foreach ($properties as $name => $value) {
$object->$name = $value;
}
}
/**
* Returns the public member variables of an object.
* This method is provided such that we can get the public member variables of an object.
* It is different from "get_object_vars()" because the latter will return private
* and protected variables if it is called within the object itself.
* @param object $object the object to be handled
* @return array the public member variables of the object
*/
public static function getObjectVars($object)
{
return get_object_vars($object);
}
}
YiiBase::$aliases = array(

2
framework/yii/base/ErrorHandler.php

@ -255,7 +255,7 @@ class ErrorHandler extends Component
if (isset($_SERVER['SERVER_SOFTWARE'])) {
foreach ($serverUrls as $url => $keywords) {
foreach ($keywords as $keyword) {
if (stripos($_SERVER['SERVER_SOFTWARE'], $keyword) !== false ) {
if (stripos($_SERVER['SERVER_SOFTWARE'], $keyword) !== false) {
return '<a href="' . $url . '" target="_blank">' . $this->htmlEncode($_SERVER['SERVER_SOFTWARE']) . '</a>';
}
}

1
framework/yii/base/Formatter.php

@ -12,7 +12,6 @@ use DateTime;
use yii\helpers\HtmlPurifier;
use yii\helpers\Html;
/**
* Formatter provides a set of commonly used data formatting methods.
*

63
framework/yii/base/HttpException.php

@ -7,6 +7,7 @@
namespace yii\base;
/**
* HttpException represents an exception caused by an improper request of the end-user.
*
@ -42,66 +43,8 @@ class HttpException extends UserException
*/
public function getName()
{
static $httpCodes = array(
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
118 => 'Connection timed out',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status',
210 => 'Content Different',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
310 => 'Too many Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Time-out',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested range unsatisfiable',
417 => 'Expectation failed',
418 => 'I’m a teapot',
422 => 'Unprocessable entity',
423 => 'Locked',
424 => 'Method failure',
425 => 'Unordered Collection',
426 => 'Upgrade Required',
449 => 'Retry With',
450 => 'Blocked by Windows Parental Controls',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway ou Proxy Error',
503 => 'Service Unavailable',
504 => 'Gateway Time-out',
505 => 'HTTP Version not supported',
507 => 'Insufficient storage',
509 => 'Bandwidth Limit Exceeded',
);
if (isset($httpCodes[$this->statusCode])) {
return $httpCodes[$this->statusCode];
if (isset(\yii\web\Response::$statusTexts[$this->statusCode])) {
return \yii\web\Response::$statusTexts[$this->statusCode];
} else {
return 'Error';
}

1
framework/yii/base/InvalidCallException.php

@ -23,4 +23,3 @@ class InvalidCallException extends Exception
return \Yii::t('yii', 'Invalid Call');
}
}

1
framework/yii/base/InvalidConfigException.php

@ -23,4 +23,3 @@ class InvalidConfigException extends Exception
return \Yii::t('yii', 'Invalid Configuration');
}
}

1
framework/yii/base/InvalidParamException.php

@ -23,4 +23,3 @@ class InvalidParamException extends Exception
return \Yii::t('yii', 'Invalid Parameter');
}
}

1
framework/yii/base/InvalidRouteException.php

@ -23,4 +23,3 @@ class InvalidRouteException extends UserException
return \Yii::t('yii', 'Invalid Route');
}
}

22
framework/yii/base/Jsonable.php

@ -0,0 +1,22 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\base;
/**
* Jsonable should be implemented by classes that need to be represented in JSON format.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
interface Jsonable
{
/**
* @return string the JSON representation of this object
*/
public function toJson();
}

13
framework/yii/base/Model.php

@ -10,6 +10,7 @@ namespace yii\base;
use ArrayObject;
use ArrayIterator;
use yii\helpers\Inflector;
use yii\helpers\Json;
use yii\validators\RequiredValidator;
use yii\validators\Validator;
@ -41,7 +42,7 @@ use yii\validators\Validator;
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Model extends Component implements \IteratorAggregate, \ArrayAccess
class Model extends Component implements \IteratorAggregate, \ArrayAccess, Jsonable
{
/**
* @event ModelEvent an event raised at the beginning of [[validate()]]. You may set
@ -638,6 +639,16 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
}
/**
* Returns the JSON representation of this object.
* The default implementation will return [[attributes]].
* @return string the JSON representation of this object.
*/
public function toJson()
{
return Json::encode($this->getAttributes());
}
/**
* Returns an iterator for traversing the attributes in the model.
* This method is required by the interface IteratorAggregate.
* @return ArrayIterator an iterator for traversing the items in the list.

1334
framework/yii/base/Module.php

File diff suppressed because it is too large Load Diff

1
framework/yii/base/NotSupportedException.php

@ -23,4 +23,3 @@ class NotSupportedException extends Exception
return \Yii::t('yii', 'Not Supported');
}
}

19
framework/yii/base/Object.php

@ -7,12 +7,15 @@
namespace yii\base;
use Yii;
use yii\helpers\Json;
/**
* @include @yii/base/Object.md
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Object
class Object implements Jsonable
{
/**
* @return string the fully qualified name of this class.
@ -38,8 +41,8 @@ class Object
*/
public function __construct($config = array())
{
foreach ($config as $name => $value) {
$this->$name = $value;
if (!empty($config)) {
Yii::configure($this, $config);
}
$this->init();
}
@ -216,4 +219,14 @@ class Object
{
return method_exists($this, 'set' . $name) || $checkVar && property_exists($this, $name);
}
/**
* Returns the JSON representation of this object.
* The default implementation will return all public member variables.
* @return string the JSON representation of this object.
*/
public function toJson()
{
return Json::encode(Yii::getObjectVars($this));
}
}

2
framework/yii/base/Theme.php

@ -73,7 +73,7 @@ class Theme extends Component
*/
public function init()
{
parent::init();
parent::init();
if (empty($this->pathMap)) {
if ($this->basePath !== null) {
$this->basePath = Yii::getAlias($this->basePath);

1
framework/yii/base/UnknownClassException.php

@ -23,4 +23,3 @@ class UnknownClassException extends Exception
return \Yii::t('yii', 'Unknown Class');
}
}

1
framework/yii/base/UnknownMethodException.php

@ -23,4 +23,3 @@ class UnknownMethodException extends Exception
return \Yii::t('yii', 'Unknown Method');
}
}

1
framework/yii/base/UnknownPropertyException.php

@ -23,4 +23,3 @@ class UnknownPropertyException extends Exception
return \Yii::t('yii', 'Unknown Property');
}
}

3
framework/yii/bootstrap/Button.php

@ -6,9 +6,8 @@
*/
namespace yii\bootstrap;
use yii\base\InvalidConfigException;
use yii\helpers\Html;
use yii\helpers\Html;
/**
* Button renders a bootstrap button.

2
framework/yii/bootstrap/ButtonDropdown.php

@ -6,8 +6,8 @@
*/
namespace yii\bootstrap;
use yii\helpers\Html;
use yii\helpers\Html;
/**
* ButtonDropdown renders a group or split button dropdown bootstrap component.

1
framework/yii/bootstrap/ButtonGroup.php

@ -10,7 +10,6 @@ namespace yii\bootstrap;
use yii\helpers\base\ArrayHelper;
use yii\helpers\Html;
/**
* ButtonGroup renders a button group bootstrap component.
*

2
framework/yii/bootstrap/Collapse.php

@ -130,4 +130,4 @@ class Collapse extends Widget
return implode("\n", $group);
}
}
}

1
framework/yii/bootstrap/Dropdown.php

@ -11,7 +11,6 @@ use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* Dropdown renders a Bootstrap dropdown menu component.
*

2
framework/yii/bootstrap/Nav.php

@ -118,7 +118,7 @@ class Nav extends Widget
$url = Html::url(ArrayHelper::getValue($item, 'url', '#'));
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', array());
if(ArrayHelper::getValue($item, 'active')) {
if (ArrayHelper::getValue($item, 'active')) {
$this->addCssClass($options, 'active');
}

1
framework/yii/bootstrap/Progress.php

@ -11,7 +11,6 @@ use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
/**
* Progress renders a bootstrap progress bar component.
*

1
framework/yii/bootstrap/Widget.php

@ -11,7 +11,6 @@ use Yii;
use yii\base\View;
use yii\helpers\Json;
/**
* \yii\bootstrap\Widget is the base class for all bootstrap widgets.
*

2
framework/yii/caching/DbCache.php

@ -170,7 +170,7 @@ class DbCache extends Cache
} else {
return $this->addValue($key, $value, $expire);
}
}
}
/**
* Stores a value identified by a key into cache if the cache does not contain this key.

1
framework/yii/caching/XCache.php

@ -86,4 +86,3 @@ class XCache extends Cache
return true;
}
}

1
framework/yii/console/Exception.php

@ -25,4 +25,3 @@ class Exception extends UserException
return \Yii::t('yii', 'Error');
}
}

6
framework/yii/console/controllers/AssetController.php

@ -164,7 +164,6 @@ class AssetController extends Controller
protected function loadConfiguration($configFile)
{
echo "Loading configuration from '{$configFile}'...\n";
foreach (require($configFile) as $name => $value) {
if (property_exists($this, $name) || $this->canSetProperty($name)) {
$this->$name = $value;
@ -221,7 +220,8 @@ class AssetController extends Controller
* @param array $result already loaded bundles list.
* @throws \yii\console\Exception on failure.
*/
protected function loadBundleDependency($name, $bundle, &$result) {
protected function loadBundleDependency($name, $bundle, &$result)
{
if (!empty($bundle->depends)) {
$assetManager = $this->getAssetManager();
foreach ($bundle->depends as $dependencyName) {
@ -573,7 +573,7 @@ EOD;
$inputFileRelativePathParts = explode('/', $inputFileRelativePath);
$outputFileRelativePathParts = explode('/', $outputFileRelativePath);
$callback = function($matches) use ($inputFileRelativePathParts, $outputFileRelativePathParts) {
$callback = function ($matches) use ($inputFileRelativePathParts, $outputFileRelativePathParts) {
$fullMatch = $matches[0];
$inputUrl = $matches[1];

3
framework/yii/console/controllers/MessageController.php

@ -179,8 +179,7 @@ class MessageController extends Controller
}
ksort($translated);
foreach ($translated as $message => $translation) {
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld)
{
if (!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld) {
if (substr($translation, 0, 2) === '@@' && substr($translation, -2) === '@@') {
$todo[$message]=$translation;
} else {

1270
framework/yii/console/controllers/MigrateController.php

File diff suppressed because it is too large Load Diff

7
framework/yii/db/Connection.php

@ -305,8 +305,7 @@ class Connection extends Component
$this->pdo = $this->createPdoInstance();
$this->initConnection();
Yii::endProfile($token, __METHOD__);
}
catch (\PDOException $e) {
} catch (\PDOException $e) {
Yii::endProfile($token, __METHOD__);
Yii::error("Failed to open DB connection ({$this->dsn}): " . $e->getMessage(), __METHOD__);
$message = YII_DEBUG ? 'Failed to open DB connection: ' . $e->getMessage() : 'Failed to open DB connection.';
@ -343,8 +342,6 @@ class Connection extends Component
$driver = strtolower(substr($this->dsn, 0, $pos));
if ($driver === 'mssql' || $driver === 'dblib' || $driver === 'sqlsrv') {
$pdoClass = 'yii\db\mssql\PDO';
} else if ($driver === 'pgsql') {
$pdoClass = 'yii\db\pgsql\PDO';
}
}
return new $pdoClass($this->dsn, $this->username, $this->password, $this->attributes);
@ -510,7 +507,7 @@ class Connection extends Component
{
$db = $this;
return preg_replace_callback('/(\\{\\{([%\w\-\. ]+)\\}\\}|\\[\\[([\w\-\. ]+)\\]\\])/',
function($matches) use($db) {
function ($matches) use ($db) {
if (isset($matches[3])) {
return $db->quoteColumnName($matches[3]);
} else {

103
framework/yii/db/pgsql/PDO.php

@ -1,103 +0,0 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\pgsql;
/**
* This is an extension of the default PDO class for PostgreSQL drivers.
* It provides additional low level functionality for setting database
* configuration parameters.
*
* @author Gevik babakhani <gevikb@gmail.com>
* @since 2.0
*/
class PDO extends \PDO
{
const OPT_SEARCH_PATH = 'search_path';
const OPT_DEFAULT_SCHEMA = 'default_schema';
const DEFAULT_SCHEMA = 'public';
private $_currentDatabase;
/**
* Returns value of the last inserted ID.
* @param string|null $sequence the sequence name. Defaults to null.
* @return integer last inserted ID value.
*/
public function lastInsertId($sequence = null) {
if ($sequence !== null) {
$sequence = $this->quote($sequence);
return $this->query("SELECT currval({$sequence})")->fetchColumn();
} else {
return null;
}
}
/**
* Here we override the default PDO constructor in order to
* find and set the default schema search path.
*/
public function __construct($dsn, $username, $passwd, $options) {
$searchPath = null;
if (is_array($options)) {
if (isset($options[self::OPT_SEARCH_PATH])) {
$matches = null;
if (preg_match("/(\s?)+(\w)+((\s+)?,(\s+)?\w+)*/", $options[self::OPT_SEARCH_PATH], $matches) === 1) {
$searchPath = $matches[0];
}
}
if (isset($options[self::OPT_DEFAULT_SCHEMA])) {
$schema = trim($options[self::OPT_DEFAULT_SCHEMA]);
if (!empty($schema)) {
Schema::$DEFAULT_SCHEMA = $schema;
}
}
if (is_null(Schema::$DEFAULT_SCHEMA) || empty(Schema::$DEFAULT_SCHEMA)) {
Schema::$DEFAULT_SCHEMA = self::DEFAULT_SCHEMA;
}
}
parent::__construct($dsn, $username, $passwd, $options);
if (!is_null($searchPath)) {
$this->setSchemaSearchPath($searchPath);
}
}
/**
* Returns the name of the current (connected) database
* @return string
*/
public function getCurrentDatabase() {
if (is_null($this->_currentDatabase)) {
return $this->query('select current_database()')->fetchColumn();
}
}
/**
* Sets the schema search path of the current users session.
* The syntax of the path is a comma separated string with
* your custom search path at the beginning and the "public"
* schema at the end.
*
* This method automatically adds the "public" schema at the
* end of the search path if it is not provied.
* @param string custom schema search path. defaults to public
*/
public function setSchemaSearchPath($searchPath = 'public') {
$schemas = explode(',', str_replace(' ', '', $searchPath));
if (end($schemas) !== 'public') {
$schemas[] = 'public';
}
foreach ($schemas as $k => $item) {
$schemas[$k] = '"' . str_replace(array('"', "'", ';'), '', $item) . '"';
}
$path = implode(', ', $schemas);
$this->exec('SET search_path TO ' . $path);
}
}

132
framework/yii/db/pgsql/Schema.php

@ -12,7 +12,7 @@ use yii\db\TableSchema;
use yii\db\ColumnSchema;
/**
* Schema is the class for retrieving metadata from a PostgreSQL database
* Schema is the class for retrieving metadata from a PostgreSQL database
* (version 9.x and above).
*
* @author Gevik Babakhani <gevikb@gmail.com>
@ -22,62 +22,62 @@ class Schema extends \yii\db\Schema
{
/**
* The default schema used for the current session. This value is
* automatically set to "public" by the PDO driver.
* @var string
* The default schema used for the current session.
* @var string
*/
public static $DEFAULT_SCHEMA;
public $defaultSchema = 'public';
/**
* @var array mapping from physical column types (keys) to abstract
* @var array mapping from physical column types (keys) to abstract
* column types (values)
*/
public $typeMap = array(
'abstime' => self::TYPE_TIMESTAMP,
'bit' => self::TYPE_STRING,
'boolean' => self::TYPE_BOOLEAN,
'box' => self::TYPE_STRING,
'character' => self::TYPE_STRING,
'bytea' => self::TYPE_BINARY,
'char' => self::TYPE_STRING,
'cidr' => self::TYPE_STRING,
'circle' => self::TYPE_STRING,
'date' => self::TYPE_DATE,
'real' => self::TYPE_FLOAT,
'double precision' => self::TYPE_DECIMAL,
'inet' => self::TYPE_STRING,
'smallint' => self::TYPE_SMALLINT,
'integer' => self::TYPE_INTEGER,
'bigint' => self::TYPE_BIGINT,
'interval' => self::TYPE_STRING,
'json' => self::TYPE_STRING,
'line' => self::TYPE_STRING,
'macaddr' => self::TYPE_STRING,
'money' => self::TYPE_MONEY,
'name' => self::TYPE_STRING,
'numeric' => self::TYPE_STRING,
'numrange' => self::TYPE_DECIMAL,
'oid' => self::TYPE_BIGINT, // should not be used. it's pg internal!
'path' => self::TYPE_STRING,
'point' => self::TYPE_STRING,
'polygon' => self::TYPE_STRING,
'text' => self::TYPE_TEXT,
'time without time zone' => self::TYPE_TIME,
'timestamp without time zone' => self::TYPE_TIMESTAMP,
'timestamp with time zone' => self::TYPE_TIMESTAMP,
'time with time zone' => self::TYPE_TIMESTAMP,
'unknown' => self::TYPE_STRING,
'uuid' => self::TYPE_STRING,
'bit varying' => self::TYPE_STRING,
'character varying' => self::TYPE_STRING,
'xml' => self::TYPE_STRING
'abstime' => self::TYPE_TIMESTAMP,
'bit' => self::TYPE_STRING,
'boolean' => self::TYPE_BOOLEAN,
'box' => self::TYPE_STRING,
'character' => self::TYPE_STRING,
'bytea' => self::TYPE_BINARY,
'char' => self::TYPE_STRING,
'cidr' => self::TYPE_STRING,
'circle' => self::TYPE_STRING,
'date' => self::TYPE_DATE,
'real' => self::TYPE_FLOAT,
'double precision' => self::TYPE_DECIMAL,
'inet' => self::TYPE_STRING,
'smallint' => self::TYPE_SMALLINT,
'integer' => self::TYPE_INTEGER,
'bigint' => self::TYPE_BIGINT,
'interval' => self::TYPE_STRING,
'json' => self::TYPE_STRING,
'line' => self::TYPE_STRING,
'macaddr' => self::TYPE_STRING,
'money' => self::TYPE_MONEY,
'name' => self::TYPE_STRING,
'numeric' => self::TYPE_STRING,
'numrange' => self::TYPE_DECIMAL,
'oid' => self::TYPE_BIGINT, // should not be used. it's pg internal!
'path' => self::TYPE_STRING,
'point' => self::TYPE_STRING,
'polygon' => self::TYPE_STRING,
'text' => self::TYPE_TEXT,
'time without time zone' => self::TYPE_TIME,
'timestamp without time zone' => self::TYPE_TIMESTAMP,
'timestamp with time zone' => self::TYPE_TIMESTAMP,
'time with time zone' => self::TYPE_TIMESTAMP,
'unknown' => self::TYPE_STRING,
'uuid' => self::TYPE_STRING,
'bit varying' => self::TYPE_STRING,
'character varying' => self::TYPE_STRING,
'xml' => self::TYPE_STRING
);
/**
* Creates a query builder for the MySQL database.
* @return QueryBuilder query builder instance
*/
public function createQueryBuilder() {
public function createQueryBuilder()
{
return new QueryBuilder($this->db);
}
@ -86,7 +86,8 @@ class Schema extends \yii\db\Schema
* @param TableSchema $table the table metadata object
* @param string $name the table name
*/
protected function resolveTableNames($table, $name) {
protected function resolveTableNames($table, $name)
{
$parts = explode('.', str_replace('"', '', $name));
if (isset($parts[1])) {
$table->schemaName = $parts[0];
@ -95,7 +96,7 @@ class Schema extends \yii\db\Schema
$table->name = $parts[0];
}
if ($table->schemaName === null) {
$table->schemaName = self::$DEFAULT_SCHEMA;
$table->schemaName = $this->defaultSchema;
}
}
@ -105,7 +106,8 @@ class Schema extends \yii\db\Schema
* @param string $name table name
* @return string the properly quoted table name
*/
public function quoteSimpleTableName($name) {
public function quoteSimpleTableName($name)
{
return strpos($name, '"') !== false ? $name : '"' . $name . '"';
}
@ -114,12 +116,15 @@ class Schema extends \yii\db\Schema
* @param string $name table name
* @return TableSchema|null driver dependent table metadata. Null if the table does not exist.
*/
public function loadTableSchema($name) {
public function loadTableSchema($name)
{
$table = new TableSchema();
$this->resolveTableNames($table, $name);
if ($this->findColumns($table)) {
$this->findConstraints($table);
return $table;
} else {
return null;
}
}
@ -127,11 +132,11 @@ class Schema extends \yii\db\Schema
* Collects the foreign key column details for the given table.
* @param TableSchema $table the table metadata
*/
protected function findConstraints($table) {
protected function findConstraints($table)
{
$tableName = $this->quoteValue($table->name);
$tableSchema = $this->quoteValue($table->schemaName);
$database = $this->quoteValue($this->db->pdo->getCurrentDatabase());
//We need to extract the constraints de hard way since:
//http://www.postgresql.org/message-id/26677.1086673982@sss.pgh.pa.us
@ -158,14 +163,9 @@ where
ct.contype='f'
and c.relname={$tableName}
and ns.nspname={$tableSchema}
and current_database() = {$database}
SQL;
try {
$constraints = $this->db->createCommand($sql)->queryAll();
} catch (\Exception $e) {
return false;
}
$constraints = $this->db->createCommand($sql)->queryAll();
foreach ($constraints as $constraint) {
$columns = explode(',', $constraint['columns']);
$fcolumns = explode(',', $constraint['foreign_columns']);
@ -175,7 +175,6 @@ SQL;
}
$table->foreignKeys[] = $citem;
}
return true;
}
/**
@ -183,8 +182,8 @@ SQL;
* @param TableSchema $table the table metadata
* @return boolean whether the table exists in the database
*/
protected function findColumns($table) {
$dbname = $this->db->quoteValue($this->db->pdo->getCurrentDatabase());
protected function findColumns($table)
{
$tableName = $this->db->quoteValue($table->name);
$schemaName = $this->db->quoteValue($table->schemaName);
$sql = <<<SQL
@ -239,16 +238,15 @@ WHERE
a.attnum > 0
and c.relname = {$tableName}
and d.nspname = {$schemaName}
and current_database() = {$dbname}
ORDER BY
a.attnum;
SQL;
try {
$columns = $this->db->createCommand($sql)->queryAll();
} catch (\Exception $e) {
$columns = $this->db->createCommand($sql)->queryAll();
if (empty($columns)) {
return false;
}
foreach ($columns as $column) {
$column = $this->loadColumnSchema($column);
$table->columns[$column->name] = $column;
@ -267,7 +265,8 @@ SQL;
* @param array $info column information
* @return ColumnSchema the column schema object
*/
protected function loadColumnSchema($info) {
protected function loadColumnSchema($info)
{
$column = new ColumnSchema();
$column->allowNull = $info['is_nullable'];
$column->autoIncrement = $info['is_autoinc'];
@ -290,5 +289,4 @@ SQL;
$column->phpType = $this->getColumnPhpType($column);
return $column;
}
}
}

2
framework/yii/debug/Module.php

@ -14,4 +14,4 @@ namespace yii\debug;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'yii\debug\controllers';
}
}

2
framework/yii/debug/controllers/DefaultController.php

@ -31,4 +31,4 @@ class DefaultController extends Controller
echo "Unable to find debug data tagged with '$tag'.";
}
}
}
}

1
framework/yii/helpers/Json.php

@ -14,5 +14,4 @@ namespace yii\helpers;
*/
class Json extends base\Json
{
}

5
framework/yii/helpers/base/Console.php

@ -286,7 +286,7 @@ class Console
* You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xtermFgColor]] and [[xtermBgColor]].
* @return string
*/
public static function ansiFormat($string, $format=array())
public static function ansiFormat($string, $format = array())
{
$code = implode(';', $format);
return "\033[0m" . ($code !== '' ? "\033[" . $code . "m" : '') . $string . "\033[0m";
@ -589,11 +589,10 @@ class Console
if (static::isRunningOnWindows()) {
$output = array();
exec('mode con', $output);
if(isset($output) && strpos($output[1], 'CON')!==false) {
if (isset($output) && strpos($output[1], 'CON') !== false) {
return $size = array((int)preg_replace('~[^0-9]~', '', $output[3]), (int)preg_replace('~[^0-9]~', '', $output[4]));
}
} else {
// try stty if available
$stty = array();
if (exec('stty -a 2>&1', $stty) && preg_match('/rows\s+(\d+);\s*columns\s+(\d+);/mi', implode(' ', $stty), $matches)) {

1
framework/yii/helpers/base/Html.php

@ -1479,5 +1479,4 @@ class Html
$name = strtolower(static::getInputName($model, $attribute));
return str_replace(array('[]', '][', '[', ']', ' '), array('', '-', '-', '', '-'), $name);
}
}

6
framework/yii/helpers/base/Inflector.php

@ -50,7 +50,7 @@ class Inflector
'/(ax|cris|test)is$/i' => '\1es',
'/s$/' => 's',
'/^$/' => '',
'/$/' => 's',
'/$/' => 's',
);
/**
* @var array the rules for converting a word into its singular form.
@ -94,7 +94,7 @@ class Inflector
'/(n)ews$/i' => '\1\2ews',
'/eaus$/' => 'eau',
'/^(.*us)$/' => '\\1',
'/s$/i' => '',
'/s$/i' => '',
);
/**
* @var array the special rules for converting a word between its plural form and singular form.
@ -468,7 +468,7 @@ class Inflector
if (in_array(($number % 100), range(11, 13))) {
return $number . 'th';
}
switch (($number % 10)) {
switch ($number % 10) {
case 1: return $number . 'st';
case 2: return $number . 'nd';
case 3: return $number . 'rd';

20
framework/yii/helpers/base/Json.php

@ -8,6 +8,7 @@
namespace yii\helpers\base;
use yii\base\InvalidParamException;
use yii\base\Jsonable;
use yii\web\JsExpression;
/**
@ -90,16 +91,19 @@ class Json
$token = '!{[' . count($expressions) . ']}!';
$expressions['"' . $token . '"'] = $data->expression;
return $token;
}
$result = array();
foreach ($data as $key => $value) {
if (is_array($value) || is_object($value)) {
$result[$key] = static::processData($value, $expressions);
} else {
$result[$key] = $value;
} elseif ($data instanceof Jsonable) {
return $data->toJson();
} else {
$result = array();
foreach ($data as $key => $value) {
if (is_array($value) || is_object($value)) {
$result[$key] = static::processData($value, $expressions);
} else {
$result[$key] = $value;
}
}
return $result;
}
return $result;
} else {
return $data;
}

158
framework/yii/i18n/DbMessageSource.php

@ -0,0 +1,158 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\i18n;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\caching\Cache;
use yii\db\Connection;
use yii\db\Query;
/**
* DbMessageSource extends [[MessageSource]] and represents a message source that stores translated
* messages in database.
*
* The database must contain the following two tables:
*
* ~~~
* CREATE TABLE tbl_source_message (
* id INTEGER PRIMARY KEY,
* category VARCHAR(32),
* message TEXT
* );
*
* CREATE TABLE tbl_message (
* id INTEGER,
* language VARCHAR(16),
* translation TEXT,
* PRIMARY KEY (id, language),
* CONSTRAINT fk_message_source_message FOREIGN KEY (id)
* REFERENCES tbl_source_message (id) ON DELETE CASCADE ON UPDATE RESTRICT
* );
* ~~~
*
* The `tbl_source_message` table stores the messages to be translated, and the `tbl_message` table stores
* the translated messages. The name of these two tables can be customized by setting [[sourceMessageTable]]
* and [[messageTable]], respectively.
*
* @author resurtm <resurtm@gmail.com>
* @since 2.0
*/
class DbMessageSource extends MessageSource
{
/**
* Prefix which would be used when generating cache key.
*/
const CACHE_KEY_PREFIX = 'DbMessageSource';
/**
* @var Connection|string the DB connection object or the application component ID of the DB connection.
* After the DbMessageSource object is created, if you want to change this property, you should only assign
* it with a DB connection object.
*/
public $db = 'db';
/**
* @var Cache|string the cache object or the application component ID of the cache object.
* The messages data will be cached using this cache object. Note, this property has meaning only
* in case [[cachingDuration]] set to non-zero value.
* After the DbMessageSource object is created, if you want to change this property, you should only assign
* it with a cache object.
*/
public $cache = 'cache';
/**
* @var string the name of the source message table.
*/
public $sourceMessageTable = 'tbl_source_message';
/**
* @var string the name of the translated message table.
*/
public $messageTable = 'tbl_message';
/**
* @var integer the time in seconds that the messages can remain valid in cache.
* Use 0 to indicate that the cached data will never expire.
* @see enableCaching
*/
public $cachingDuration = 0;
/**
* @var boolean whether to enable caching translated messages
*/
public $enableCaching = false;
/**
* Initializes the DbMessageSource component.
* This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
* Configured [[cache]] component would also be initialized.
* @throws InvalidConfigException if [[db]] is invalid or [[cache]] is invalid.
*/
public function init()
{
parent::init();
if (is_string($this->db)) {
$this->db = Yii::$app->getComponent($this->db);
}
if (!$this->db instanceof Connection) {
throw new InvalidConfigException("DbMessageSource::db must be either a DB connection instance or the application component ID of a DB connection.");
}
if ($this->enableCaching) {
if (is_string($this->cache)) {
$this->cache = Yii::$app->getComponent($this->cache);
}
if (!$this->cache instanceof Cache) {
throw new InvalidConfigException("DbMessageSource::cache must be either a cache object or the application component ID of the cache object.");
}
}
}
/**
* Loads the message translation for the specified language and category.
* Child classes should override this method to return the message translations of
* the specified language and category.
* @param string $category the message category
* @param string $language the target language
* @return array the loaded messages. The keys are original messages, and the values
* are translated messages.
*/
protected function loadMessages($category, $language)
{
if ($this->enableCaching) {
$key = array(
__CLASS__,
$category,
$language,
);
$messages = $this->cache->get($key);
if ($messages === false) {
$messages = $this->loadMessagesFromDb($category, $language);
$this->cache->set($key, $messages, $this->cachingDuration);
}
return $messages;
} else {
return $this->loadMessagesFromDb($category, $language);
}
}
/**
* Loads the messages from database.
* You may override this method to customize the message storage in the database.
* @param string $category the message category.
* @param string $language the target language.
* @return array the messages loaded from database.
*/
protected function loadMessagesFromDb($category, $language)
{
$query = new Query();
$messages = $query->select(array('t1.message message', 't2.translation translation'))
->from(array($this->sourceMessageTable . ' t1', $this->messageTable . ' t2'))
->where('t1.id = t2.id AND t1.category = :category AND t2.language = :language')
->params(array(':category' => $category, ':language' => $language))
->createCommand($this->db)
->queryAll();
return ArrayHelper::map($messages, 'message', 'translation');
}
}

9
framework/yii/i18n/I18N.php

@ -78,16 +78,11 @@ class I18N extends Component
* @param string $category the message category.
* @param string $message the message to be translated.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
* @param string $language the language code (e.g. `en_US`, `en`). If this is null, the current
* [[\yii\base\Application::language|application language]] will be used.
* @param string $language the language code (e.g. `en_US`, `en`).
* @return string the translated message.
*/
public function translate($category, $message, $params = array(), $language = null)
public function translate($category, $message, $params, $language)
{
if ($language === null) {
$language = Yii::$app->language;
}
$message = $this->getMessageSource($category)->translate($category, $message, $language);
if (!is_array($params)) {

1
framework/yii/i18n/MessageSource.php

@ -118,4 +118,3 @@ class MessageSource extends Component
}
}
}

2
framework/yii/jui/Accordion.php

@ -125,7 +125,7 @@ class Accordion extends Widget
$items[] = Html::tag($headerTag, $item['header'], $headerOptions);
$options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', array()));
$tag = ArrayHelper::remove($options, 'tag', 'div');
$items[] = Html::tag($tag, $item['content'], $options);;
$items[] = Html::tag($tag, $item['content'], $options);
}
return implode("\n", $items);

1
framework/yii/jui/Menu.php

@ -10,7 +10,6 @@ namespace yii\jui;
use Yii;
use yii\helpers\Json;
/**
* Menu renders a menu jQuery UI widget.
*

1
framework/yii/jui/Widget.php

@ -10,7 +10,6 @@ namespace yii\jui;
use Yii;
use yii\helpers\Json;
/**
* \yii\jui\Widget is the base class for all jQuery UI widgets.
*

3
framework/yii/rbac/DbManager.php

@ -493,8 +493,9 @@ class DbManager extends Manager
'bizRule' => $row['biz_rule'],
'data' => $data,
));
} else
} else {
return null;
}
}
/**

2
framework/yii/rbac/PhpManager.php

@ -468,7 +468,7 @@ class PhpManager extends Manager
'bizRule' => $assignment['bizRule'],
'data' => $assignment['data'],
));
}
}
}
}
}

2
framework/yii/requirements/requirements.php

@ -45,4 +45,4 @@ return array(
'by' => '<a href="http://www.php.net/manual/en/book.intl.php">Internationalization</a> support',
'memo' => 'PHP Intl extension 1.0.2 or higher is required when you want to use <abbr title="Internationalized domain names">IDN</abbr>-feature of EmailValidator or UrlValidator or the <code>yii\i18n\Formatter</code> class.'
),
);
);

1
framework/yii/validators/CaptchaValidator.php

@ -117,4 +117,3 @@ class CaptchaValidator extends Validator
return 'yii.validation.captcha(value, messages, ' . json_encode($options) . ');';
}
}

1
framework/yii/validators/DateValidator.php

@ -73,4 +73,3 @@ class DateValidator extends Validator
return DateTime::createFromFormat($this->format, $value) !== false;
}
}

1
framework/yii/validators/DefaultValueValidator.php

@ -40,4 +40,3 @@ class DefaultValueValidator extends Validator
}
}
}

1
framework/yii/validators/ExistValidator.php

@ -99,4 +99,3 @@ class ExistValidator extends Validator
return $query->exists();
}
}

1
framework/yii/validators/FilterValidator.php

@ -6,6 +6,7 @@
*/
namespace yii\validators;
use yii\base\InvalidConfigException;
/**

2
framework/yii/validators/RangeValidator.php

@ -35,7 +35,7 @@ class RangeValidator extends Validator
* @var boolean whether to invert the validation logic. Defaults to false. If set to true,
* the attribute value should NOT be among the list of values defined via [[range]].
**/
public $not = false;
public $not = false;
/**
* Initializes the validator.

2
framework/yii/validators/RegularExpressionValidator.php

@ -32,7 +32,7 @@ class RegularExpressionValidator extends Validator
* the regular expression defined via [[pattern]] should NOT match the attribute value.
* @throws InvalidConfigException if the "pattern" is not a valid regular expression
**/
public $not = false;
public $not = false;
/**
* Initializes the validator.

1
framework/yii/validators/StringValidator.php

@ -174,4 +174,3 @@ class StringValidator extends Validator
return 'yii.validation.string(value, messages, ' . json_encode($options) . ');';
}
}

2
framework/yii/validators/UrlValidator.php

@ -99,7 +99,7 @@ class UrlValidator extends Validator
}
if ($this->enableIDN) {
$value = preg_replace_callback('/:\/\/([^\/]+)/', function($matches) {
$value = preg_replace_callback('/:\/\/([^\/]+)/', function ($matches) {
return '://' . idn_to_ascii($matches[1]);
}, $value);
}

2
framework/yii/validators/Validator.php

@ -179,7 +179,7 @@ abstract class Validator extends Component
}
foreach ($attributes as $attribute) {
$skip = $this->skipOnError && $object->hasErrors($attribute)
|| $this->skipOnEmpty && $this->isEmpty($object->$attribute);
|| $this->skipOnEmpty && $this->isEmpty($object->$attribute);
if (!$skip) {
$this->validateAttribute($object, $attribute);
}

1
framework/yii/web/HeaderCollection.php

@ -11,7 +11,6 @@ use Yii;
use yii\base\Object;
use ArrayIterator;
/**
* HeaderCollection is used by [[Response]] to maintain the currently registered HTTP headers.
*

206
framework/yii/web/PageCache.php

@ -1,104 +1,104 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\web;
use Yii;
use yii\base\ActionFilter;
use yii\base\Action;
use yii\base\View;
use yii\caching\Dependency;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class PageCache extends ActionFilter
{
/**
* @var boolean whether the content being cached should be differentiated according to the route.
* A route consists of the requested controller ID and action ID. Defaults to true.
*/
public $varyByRoute = true;
/**
* @var string the application component ID of the [[\yii\caching\Cache|cache]] object.
*/
public $cache = 'cache';
/**
* @var integer number of seconds that the data can remain valid in cache.
* Use 0 to indicate that the cached data will never expire.
*/
public $duration = 60;
/**
* @var array|Dependency the dependency that the cached content depends on.
* This can be either a [[Dependency]] object or a configuration array for creating the dependency object.
* For example,
*
* ~~~
* array(
* 'class' => 'yii\caching\DbDependency',
* 'sql' => 'SELECT MAX(lastModified) FROM Post',
* )
* ~~~
*
* would make the output cache depends on the last modified time of all posts.
* If any post has its modification time changed, the cached content would be invalidated.
*/
public $dependency;
/**
* @var array list of factors that would cause the variation of the content being cached.
* Each factor is a string representing a variation (e.g. the language, a GET parameter).
* The following variation setting will cause the content to be cached in different versions
* according to the current application language:
*
* ~~~
* array(
* Yii::$app->language,
* )
*/
public $variations;
/**
* @var boolean whether to enable the fragment cache. You may use this property to turn on and off
* the fragment cache according to specific setting (e.g. enable fragment cache only for GET requests).
*/
public $enabled = true;
public function init()
{
parent::init();
if ($this->view === null) {
$this->view = Yii::$app->getView();
}
}
/**
* This method is invoked right before an action is to be executed (after all possible filters.)
* You may override this method to do last-minute preparation for the action.
* @param Action $action the action to be executed.
* @return boolean whether the action should continue to be executed.
*/
public function beforeAction($action)
{
$properties = array();
foreach (array('cache', 'duration', 'dependency', 'variations', 'enabled') as $name) {
$properties[$name] = $this->$name;
}
$id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
return $this->view->beginCache($id, $properties);
}
/**
* This method is invoked right after an action is executed.
* You may override this method to do some postprocessing for the action.
* @param Action $action the action just executed.
*/
public function afterAction($action)
{
$this->view->endCache();
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\web;
use Yii;
use yii\base\ActionFilter;
use yii\base\Action;
use yii\base\View;
use yii\caching\Dependency;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class PageCache extends ActionFilter
{
/**
* @var boolean whether the content being cached should be differentiated according to the route.
* A route consists of the requested controller ID and action ID. Defaults to true.
*/
public $varyByRoute = true;
/**
* @var string the application component ID of the [[\yii\caching\Cache|cache]] object.
*/
public $cache = 'cache';
/**
* @var integer number of seconds that the data can remain valid in cache.
* Use 0 to indicate that the cached data will never expire.
*/
public $duration = 60;
/**
* @var array|Dependency the dependency that the cached content depends on.
* This can be either a [[Dependency]] object or a configuration array for creating the dependency object.
* For example,
*
* ~~~
* array(
* 'class' => 'yii\caching\DbDependency',
* 'sql' => 'SELECT MAX(lastModified) FROM Post',
* )
* ~~~
*
* would make the output cache depends on the last modified time of all posts.
* If any post has its modification time changed, the cached content would be invalidated.
*/
public $dependency;
/**
* @var array list of factors that would cause the variation of the content being cached.
* Each factor is a string representing a variation (e.g. the language, a GET parameter).
* The following variation setting will cause the content to be cached in different versions
* according to the current application language:
*
* ~~~
* array(
* Yii::$app->language,
* )
*/
public $variations;
/**
* @var boolean whether to enable the fragment cache. You may use this property to turn on and off
* the fragment cache according to specific setting (e.g. enable fragment cache only for GET requests).
*/
public $enabled = true;
public function init()
{
parent::init();
if ($this->view === null) {
$this->view = Yii::$app->getView();
}
}
/**
* This method is invoked right before an action is to be executed (after all possible filters.)
* You may override this method to do last-minute preparation for the action.
* @param Action $action the action to be executed.
* @return boolean whether the action should continue to be executed.
*/
public function beforeAction($action)
{
$properties = array();
foreach (array('cache', 'duration', 'dependency', 'variations', 'enabled') as $name) {
$properties[$name] = $this->$name;
}
$id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
return $this->view->beginCache($id, $properties);
}
/**
* This method is invoked right after an action is executed.
* You may override this method to do some postprocessing for the action.
* @param Action $action the action just executed.
*/
public function afterAction($action)
{
$this->view->endCache();
}
}

1
framework/yii/web/Request.php

@ -792,4 +792,3 @@ class Request extends \yii\base\Request
}
}
}

243
framework/yii/web/Response.php

@ -9,8 +9,10 @@ namespace yii\web;
use Yii;
use yii\base\HttpException;
use yii\base\InvalidParamException;
use yii\helpers\FileHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\StringHelper;
/**
@ -27,9 +29,122 @@ class Response extends \yii\base\Response
* @see redirect
*/
public $ajaxRedirectCode = 278;
/**
* @var string
*/
public $content;
/**
* @var string
*/
public $statusText;
/**
* @var string the charset to use. If not set, [[\yii\base\Application::charset]] will be used.
*/
public $charset;
/**
* @var string the version of the HTTP protocol to use
*/
public $version = '1.0';
/**
* @var array list of HTTP status codes and the corresponding texts
*/
public static $statusTexts = array(
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
118 => 'Connection timed out',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status',
208 => 'Already Reported',
210 => 'Content Different',
226 => 'IM Used',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
306 => 'Reserved',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect',
310 => 'Too many Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Time-out',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested range unsatisfiable',
417 => 'Expectation failed',
418 => 'I’m a teapot',
422 => 'Unprocessable entity',
423 => 'Locked',
424 => 'Method failure',
425 => 'Unordered Collection',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
449 => 'Retry With',
450 => 'Blocked by Windows Parental Controls',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway ou Proxy Error',
503 => 'Service Unavailable',
504 => 'Gateway Time-out',
505 => 'HTTP Version not supported',
507 => 'Insufficient storage',
508 => 'Loop Detected',
509 => 'Bandwidth Limit Exceeded',
510 => 'Not Extended',
511 => 'Network Authentication Required',
);
private $_statusCode = 200;
/**
* @var HeaderCollection
*/
private $_headers;
public function init()
{
if ($this->charset === null) {
$this->charset = Yii::$app->charset;
}
}
public function getStatusCode()
{
return $this->_statusCode;
}
public function setStatusCode($value)
{
$this->_statusCode = (int)$value;
if ($this->isInvalid()) {
throw new InvalidParamException("The HTTP status code is invalid: $value");
}
$this->statusText = isset(self::$statusTexts[$this->_statusCode]) ? self::$statusTexts[$this->_statusCode] : '';
}
/**
* Returns the header collection.
* The header collection contains the currently registered HTTP headers.
@ -43,6 +158,52 @@ class Response extends \yii\base\Response
return $this->_headers;
}
public function renderJson($data)
{
$this->getHeaders()->set('content-type', 'application/json');
$this->content = Json::encode($data);
}
public function renderJsonp($data, $callbackName)
{
$this->getHeaders()->set('content-type', 'text/javascript');
$data = Json::encode($data);
$this->content = "$callbackName($data);";
}
/**
* Sends the response to the client.
* @return boolean true if the response was sent
*/
public function send()
{
$this->sendHeaders();
$this->sendContent();
}
/**
* Sends the response headers to the client
*/
protected function sendHeaders()
{
header("HTTP/{$this->version} " . $this->getStatusCode() . " {$this->statusText}");
foreach ($this->_headers as $name => $values) {
foreach ($values as $value) {
header("$name: $value");
}
}
$this->_headers->removeAll();
}
/**
* Sends the response content to the client
*/
protected function sendContent()
{
echo $this->content;
$this->content = null;
}
/**
* Sends a file to user.
* @param string $fileName file name
@ -201,7 +362,7 @@ class Response extends \yii\base\Response
}
if (!isset($options['mimeType'])) {
if (($options['mimeType'] = CFileHelper::getMimeTypeByExtension($filePath)) === null) {
if (($options['mimeType'] = FileHelper::getMimeTypeByExtension($filePath)) === null) {
$options['mimeType'] = 'text/plain';
}
}
@ -303,4 +464,84 @@ class Response extends \yii\base\Response
{
return Yii::$app->getRequest()->getCookies();
}
/**
* @return boolean whether this response has a valid [[statusCode]].
*/
public function isInvalid()
{
return $this->getStatusCode() < 100 || $this->getStatusCode() >= 600;
}
/**
* @return boolean whether this response is informational
*/
public function isInformational()
{
return $this->getStatusCode() >= 100 && $this->getStatusCode() < 200;
}
/**
* @return boolean whether this response is successfully
*/
public function isSuccessful()
{
return $this->getStatusCode() >= 200 && $this->getStatusCode() < 300;
}
/**
* @return boolean whether this response is a redirection
*/
public function isRedirection()
{
return $this->getStatusCode() >= 300 && $this->getStatusCode() < 400;
}
/**
* @return boolean whether this response indicates a client error
*/
public function isClientError()
{
return $this->getStatusCode() >= 400 && $this->getStatusCode() < 500;
}
/**
* @return boolean whether this response indicates a server error
*/
public function isServerError()
{
return $this->getStatusCode() >= 500 && $this->getStatusCode() < 600;
}
/**
* @return boolean whether this response is OK
*/
public function isOk()
{
return 200 === $this->getStatusCode();
}
/**
* @return boolean whether this response indicates the current request is forbidden
*/
public function isForbidden()
{
return 403 === $this->getStatusCode();
}
/**
* @return boolean whether this response indicates the currently requested resource is not found
*/
public function isNotFound()
{
return 404 === $this->getStatusCode();
}
/**
* @return boolean whether this response is empty
*/
public function isEmpty()
{
return in_array($this->getStatusCode(), array(201, 204, 304));
}
}

2
framework/yii/web/UploadedFile.php

@ -7,7 +7,7 @@
namespace yii\web;
use yii\widgets\Html;
use yii\helpers\Html;
/**
* @author Qiang Xue <qiang.xue@gmail.com>

2
framework/yii/web/User.php

@ -221,7 +221,7 @@ class User extends Component
if ($destroySession) {
Yii::$app->getSession()->destroy();
}
$this->afterLogout($identity);
$this->afterLogout($identity);
}
}

348
framework/yii/widgets/FragmentCache.php

@ -1,174 +1,174 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
use Yii;
use yii\base\Widget;
use yii\caching\Cache;
use yii\caching\Dependency;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class FragmentCache extends Widget
{
/**
* @var Cache|string the cache object or the application component ID of the cache object.
* After the FragmentCache object is created, if you want to change this property,
* you should only assign it with a cache object.
*/
public $cache = 'cache';
/**
* @var integer number of seconds that the data can remain valid in cache.
* Use 0 to indicate that the cached data will never expire.
*/
public $duration = 60;
/**
* @var array|Dependency the dependency that the cached content depends on.
* This can be either a [[Dependency]] object or a configuration array for creating the dependency object.
* For example,
*
* ~~~
* array(
* 'class' => 'yii\caching\DbDependency',
* 'sql' => 'SELECT MAX(lastModified) FROM Post',
* )
* ~~~
*
* would make the output cache depends on the last modified time of all posts.
* If any post has its modification time changed, the cached content would be invalidated.
*/
public $dependency;
/**
* @var array list of factors that would cause the variation of the content being cached.
* Each factor is a string representing a variation (e.g. the language, a GET parameter).
* The following variation setting will cause the content to be cached in different versions
* according to the current application language:
*
* ~~~
* array(
* Yii::$app->language,
* )
*/
public $variations;
/**
* @var boolean whether to enable the fragment cache. You may use this property to turn on and off
* the fragment cache according to specific setting (e.g. enable fragment cache only for GET requests).
*/
public $enabled = true;
/**
* @var array a list of placeholders for embedding dynamic contents. This property
* is used internally to implement the content caching feature. Do not modify it.
*/
public $dynamicPlaceholders;
/**
* Initializes the FragmentCache object.
*/
public function init()
{
parent::init();
if (!$this->enabled) {
$this->cache = null;
} elseif (is_string($this->cache)) {
$this->cache = Yii::$app->getComponent($this->cache);
}
if ($this->getCachedContent() === false) {
$this->view->cacheStack[] = $this;
ob_start();
ob_implicit_flush(false);
}
}
/**
* Marks the end of content to be cached.
* Content displayed before this method call and after {@link init()}
* will be captured and saved in cache.
* This method does nothing if valid content is already found in cache.
*/
public function run()
{
if (($content = $this->getCachedContent()) !== false) {
echo $content;
} elseif ($this->cache instanceof Cache) {
$content = ob_get_clean();
array_pop($this->view->cacheStack);
if (is_array($this->dependency)) {
$this->dependency = Yii::createObject($this->dependency);
}
$data = array($content, $this->dynamicPlaceholders);
$this->cache->set($this->calculateKey(), $data, $this->duration, $this->dependency);
if (empty($this->view->cacheStack) && !empty($this->dynamicPlaceholders)) {
$content = $this->updateDynamicContent($content, $this->dynamicPlaceholders);
}
echo $content;
}
}
/**
* @var string|boolean the cached content. False if the content is not cached.
*/
private $_content;
/**
* Returns the cached content if available.
* @return string|boolean the cached content. False is returned if valid content is not found in the cache.
*/
public function getCachedContent()
{
if ($this->_content === null) {
$this->_content = false;
if ($this->cache instanceof Cache) {
$key = $this->calculateKey();
$data = $this->cache->get($key);
if (is_array($data) && count($data) === 2) {
list ($content, $placeholders) = $data;
if (is_array($placeholders) && count($placeholders) > 0) {
if (empty($this->view->cacheStack)) {
// outermost cache: replace placeholder with dynamic content
$content = $this->updateDynamicContent($content, $placeholders);
}
foreach ($placeholders as $name => $statements) {
$this->view->addDynamicPlaceholder($name, $statements);
}
}
$this->_content = $content;
}
}
}
return $this->_content;
}
protected function updateDynamicContent($content, $placeholders)
{
foreach ($placeholders as $name => $statements) {
$placeholders[$name] = $this->view->evaluateDynamicContent($statements);
}
return strtr($content, $placeholders);
}
/**
* Generates a unique key used for storing the content in cache.
* The key generated depends on both [[id]] and [[variations]].
* @return mixed a valid cache key
*/
protected function calculateKey()
{
$factors = array(__CLASS__, $this->getId());
if (is_array($this->variations)) {
foreach ($this->variations as $factor) {
$factors[] = $factor;
}
}
return $factors;
}
}
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
use Yii;
use yii\base\Widget;
use yii\caching\Cache;
use yii\caching\Dependency;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class FragmentCache extends Widget
{
/**
* @var Cache|string the cache object or the application component ID of the cache object.
* After the FragmentCache object is created, if you want to change this property,
* you should only assign it with a cache object.
*/
public $cache = 'cache';
/**
* @var integer number of seconds that the data can remain valid in cache.
* Use 0 to indicate that the cached data will never expire.
*/
public $duration = 60;
/**
* @var array|Dependency the dependency that the cached content depends on.
* This can be either a [[Dependency]] object or a configuration array for creating the dependency object.
* For example,
*
* ~~~
* array(
* 'class' => 'yii\caching\DbDependency',
* 'sql' => 'SELECT MAX(lastModified) FROM Post',
* )
* ~~~
*
* would make the output cache depends on the last modified time of all posts.
* If any post has its modification time changed, the cached content would be invalidated.
*/
public $dependency;
/**
* @var array list of factors that would cause the variation of the content being cached.
* Each factor is a string representing a variation (e.g. the language, a GET parameter).
* The following variation setting will cause the content to be cached in different versions
* according to the current application language:
*
* ~~~
* array(
* Yii::$app->language,
* )
*/
public $variations;
/**
* @var boolean whether to enable the fragment cache. You may use this property to turn on and off
* the fragment cache according to specific setting (e.g. enable fragment cache only for GET requests).
*/
public $enabled = true;
/**
* @var array a list of placeholders for embedding dynamic contents. This property
* is used internally to implement the content caching feature. Do not modify it.
*/
public $dynamicPlaceholders;
/**
* Initializes the FragmentCache object.
*/
public function init()
{
parent::init();
if (!$this->enabled) {
$this->cache = null;
} elseif (is_string($this->cache)) {
$this->cache = Yii::$app->getComponent($this->cache);
}
if ($this->getCachedContent() === false) {
$this->view->cacheStack[] = $this;
ob_start();
ob_implicit_flush(false);
}
}
/**
* Marks the end of content to be cached.
* Content displayed before this method call and after {@link init()}
* will be captured and saved in cache.
* This method does nothing if valid content is already found in cache.
*/
public function run()
{
if (($content = $this->getCachedContent()) !== false) {
echo $content;
} elseif ($this->cache instanceof Cache) {
$content = ob_get_clean();
array_pop($this->view->cacheStack);
if (is_array($this->dependency)) {
$this->dependency = Yii::createObject($this->dependency);
}
$data = array($content, $this->dynamicPlaceholders);
$this->cache->set($this->calculateKey(), $data, $this->duration, $this->dependency);
if (empty($this->view->cacheStack) && !empty($this->dynamicPlaceholders)) {
$content = $this->updateDynamicContent($content, $this->dynamicPlaceholders);
}
echo $content;
}
}
/**
* @var string|boolean the cached content. False if the content is not cached.
*/
private $_content;
/**
* Returns the cached content if available.
* @return string|boolean the cached content. False is returned if valid content is not found in the cache.
*/
public function getCachedContent()
{
if ($this->_content === null) {
$this->_content = false;
if ($this->cache instanceof Cache) {
$key = $this->calculateKey();
$data = $this->cache->get($key);
if (is_array($data) && count($data) === 2) {
list ($content, $placeholders) = $data;
if (is_array($placeholders) && count($placeholders) > 0) {
if (empty($this->view->cacheStack)) {
// outermost cache: replace placeholder with dynamic content
$content = $this->updateDynamicContent($content, $placeholders);
}
foreach ($placeholders as $name => $statements) {
$this->view->addDynamicPlaceholder($name, $statements);
}
}
$this->_content = $content;
}
}
}
return $this->_content;
}
protected function updateDynamicContent($content, $placeholders)
{
foreach ($placeholders as $name => $statements) {
$placeholders[$name] = $this->view->evaluateDynamicContent($statements);
}
return strtr($content, $placeholders);
}
/**
* Generates a unique key used for storing the content in cache.
* The key generated depends on both [[id]] and [[variations]].
* @return mixed a valid cache key
*/
protected function calculateKey()
{
$factors = array(__CLASS__, $this->getId());
if (is_array($this->variations)) {
foreach ($this->variations as $factor) {
$factors[] = $factor;
}
}
return $factors;
}
}

1
framework/yii/widgets/ListPager.php

@ -91,5 +91,4 @@ class ListPager extends Widget
'{page}' => $page + 1,
));
}
}

3
tests/unit/data/config.php

@ -22,9 +22,6 @@ return array(
'dsn' => 'pgsql:host=localhost;dbname=yiitest;port=5432;',
'username' => 'postgres',
'password' => 'postgres',
'attributes' => array(
'search_path' => 'master,hello'
),
'fixture' => __DIR__ . '/postgres.sql',
)
)

1
tests/unit/framework/web/ResponseTest.php

@ -32,6 +32,7 @@ class ResponseTest extends \yiiunit\TestCase
protected function setUp()
{
parent::setUp();
$this->mockApplication();
$this->reset();
}

Loading…
Cancel
Save