mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
code style, fixes #3140
This commit is contained in:
@ -13,10 +13,10 @@ namespace yii\base;
|
||||
* Note that ArrayAccessTrait requires the class using it contain a property named `data` which should be an array.
|
||||
* The data will be exposed by ArrayAccessTrait to support accessing the class object like an array.
|
||||
*
|
||||
* @property array $data
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @since 2.0
|
||||
*
|
||||
* @property array $data
|
||||
*/
|
||||
trait ArrayAccessTrait
|
||||
{
|
||||
|
||||
@ -350,6 +350,7 @@ class Formatter extends Component
|
||||
if (is_string($value)) {
|
||||
return is_numeric($value) || $value === '' ? (int) $value : strtotime($value);
|
||||
} elseif ($value instanceof DateTime || $value instanceof \DateTimeInterface) {
|
||||
/** @var $value \DateTimeInterface */
|
||||
return $value->getTimestamp();
|
||||
} else {
|
||||
return (int) $value;
|
||||
|
||||
@ -118,6 +118,7 @@ class FixtureController extends Controller
|
||||
* whitespace between names.
|
||||
* @param array|string $fixtures
|
||||
* @param array|string $except
|
||||
* @throws \yii\console\Exception in case no fixtures are found.
|
||||
*/
|
||||
public function actionUnload(array $fixtures, array $except = [])
|
||||
{
|
||||
|
||||
@ -257,7 +257,6 @@ trait ActiveRelationTrait
|
||||
* @param ActiveRecordInterface[] $models models
|
||||
* @param string $primaryName the primary relation name
|
||||
* @param string $name the relation name
|
||||
* @return null
|
||||
*/
|
||||
private function populateInverseRelation(&$primaryModels, $models, $primaryName, $name)
|
||||
{
|
||||
@ -368,6 +367,10 @@ trait ActiveRelationTrait
|
||||
return $buckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attributes the attributes to prefix
|
||||
* @return array
|
||||
*/
|
||||
private function prefixKeyColumns($attributes)
|
||||
{
|
||||
if ($this instanceof ActiveQuery && (!empty($this->join) || !empty($this->joinWith))) {
|
||||
@ -385,7 +388,7 @@ trait ActiveRelationTrait
|
||||
}
|
||||
if (isset($alias)) {
|
||||
foreach ($attributes as $i => $attribute) {
|
||||
$attributes[$i] = "$alias.$attribute";
|
||||
$attributes[$i] = "$alias.$attribute";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -911,7 +911,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
||||
*/
|
||||
public function refresh()
|
||||
{
|
||||
/** @var ActiveQuery $record */
|
||||
/** @var BaseActiveRecord $record */
|
||||
$record = $this->findOne($this->getPrimaryKey(true));
|
||||
if ($record === null) {
|
||||
return false;
|
||||
|
||||
@ -107,6 +107,7 @@ class Query extends Component implements QueryInterface
|
||||
*/
|
||||
public $params = [];
|
||||
|
||||
|
||||
/**
|
||||
* Creates a DB command that can be used to execute this query.
|
||||
* @param Connection $db the database connection used to generate the SQL statement.
|
||||
@ -201,7 +202,6 @@ class Query extends Component implements QueryInterface
|
||||
public function all($db = null)
|
||||
{
|
||||
$rows = $this->createCommand($db)->queryAll();
|
||||
|
||||
return $this->prepareResult($rows);
|
||||
}
|
||||
|
||||
@ -226,7 +226,6 @@ class Query extends Component implements QueryInterface
|
||||
}
|
||||
$result[$key] = $row;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -343,7 +342,6 @@ class Query extends Component implements QueryInterface
|
||||
$this->select = [new Expression('1')];
|
||||
$command = $this->createCommand($db);
|
||||
$this->select = $select;
|
||||
|
||||
return $command->queryScalar() !== false;
|
||||
}
|
||||
|
||||
@ -404,7 +402,6 @@ class Query extends Component implements QueryInterface
|
||||
}
|
||||
$this->select = $columns;
|
||||
$this->selectOption = $option;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -424,7 +421,6 @@ class Query extends Component implements QueryInterface
|
||||
} else {
|
||||
$this->select = array_merge($this->select, $columns);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -436,7 +432,6 @@ class Query extends Component implements QueryInterface
|
||||
public function distinct($value = true)
|
||||
{
|
||||
$this->distinct = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -462,7 +457,6 @@ class Query extends Component implements QueryInterface
|
||||
$tables = preg_split('/\s*,\s*/', trim($tables), -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
$this->from = $tables;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -570,7 +564,6 @@ class Query extends Component implements QueryInterface
|
||||
$this->where = ['and', $this->where, $condition];
|
||||
}
|
||||
$this->addParams($params);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -618,7 +611,6 @@ class Query extends Component implements QueryInterface
|
||||
public function join($type, $table, $on = '', $params = [])
|
||||
{
|
||||
$this->join[] = [$type, $table, $on];
|
||||
|
||||
return $this->addParams($params);
|
||||
}
|
||||
|
||||
@ -643,7 +635,6 @@ class Query extends Component implements QueryInterface
|
||||
public function innerJoin($table, $on = '', $params = [])
|
||||
{
|
||||
$this->join[] = ['INNER JOIN', $table, $on];
|
||||
|
||||
return $this->addParams($params);
|
||||
}
|
||||
|
||||
@ -668,7 +659,6 @@ class Query extends Component implements QueryInterface
|
||||
public function leftJoin($table, $on = '', $params = [])
|
||||
{
|
||||
$this->join[] = ['LEFT JOIN', $table, $on];
|
||||
|
||||
return $this->addParams($params);
|
||||
}
|
||||
|
||||
@ -693,7 +683,6 @@ class Query extends Component implements QueryInterface
|
||||
public function rightJoin($table, $on = '', $params = [])
|
||||
{
|
||||
$this->join[] = ['RIGHT JOIN', $table, $on];
|
||||
|
||||
return $this->addParams($params);
|
||||
}
|
||||
|
||||
@ -712,7 +701,6 @@ class Query extends Component implements QueryInterface
|
||||
$columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
$this->groupBy = $columns;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -735,7 +723,6 @@ class Query extends Component implements QueryInterface
|
||||
} else {
|
||||
$this->groupBy = array_merge($this->groupBy, $columns);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -752,7 +739,6 @@ class Query extends Component implements QueryInterface
|
||||
{
|
||||
$this->having = $condition;
|
||||
$this->addParams($params);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -774,7 +760,6 @@ class Query extends Component implements QueryInterface
|
||||
$this->having = ['and', $this->having, $condition];
|
||||
}
|
||||
$this->addParams($params);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -796,7 +781,6 @@ class Query extends Component implements QueryInterface
|
||||
$this->having = ['or', $this->having, $condition];
|
||||
}
|
||||
$this->addParams($params);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -809,7 +793,6 @@ class Query extends Component implements QueryInterface
|
||||
public function union($sql, $all = false)
|
||||
{
|
||||
$this->union[] = [ 'query' => $sql, 'all' => $all ];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -823,7 +806,6 @@ class Query extends Component implements QueryInterface
|
||||
public function params($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -849,7 +831,6 @@ class Query extends Component implements QueryInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ use yii\base\InvalidParamException;
|
||||
*/
|
||||
class QueryBuilder extends \yii\db\QueryBuilder
|
||||
{
|
||||
private $sql;
|
||||
private $_sql;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -37,16 +37,16 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
$this->buildHaving($query->having, $params),
|
||||
$this->buildOrderBy($query->orderBy),
|
||||
];
|
||||
$this->sql = implode($this->separator, array_filter($clauses));
|
||||
$this->_sql = implode($this->separator, array_filter($clauses));
|
||||
|
||||
$this->sql = $this->buildLimit($query->limit, $query->offset);
|
||||
$this->_sql = $this->buildLimit($query->limit, $query->offset);
|
||||
|
||||
$union = $this->buildUnion($query->union, $params);
|
||||
if ($union !== '') {
|
||||
$this->sql = "{$this->sql}{$this->separator}$union";
|
||||
$this->_sql = "{$this->_sql}{$this->separator}$union";
|
||||
}
|
||||
|
||||
return [$this->sql, $params];
|
||||
return [$this->_sql, $params];
|
||||
}
|
||||
|
||||
public function buildLimit($limit, $offset)
|
||||
@ -64,14 +64,14 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
$filter = implode(' and ', $filters);
|
||||
|
||||
return <<<EOD
|
||||
WITH USER_SQL AS ({$this->sql}),
|
||||
WITH USER_SQL AS ({$this->_sql}),
|
||||
PAGINATION AS (SELECT USER_SQL.*, rownum as rowNumId FROM USER_SQL)
|
||||
SELECT *
|
||||
FROM PAGINATION
|
||||
WHERE $filter
|
||||
EOD;
|
||||
} else {
|
||||
return $this->sql;
|
||||
return $this->_sql;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -671,15 +671,16 @@ class Request extends \yii\base\Request
|
||||
// try to encode in UTF8 if not so
|
||||
// http://w3.org/International/questions/qa-forms-utf-8.html
|
||||
if (!preg_match('%^(?:
|
||||
[\x09\x0A\x0D\x20-\x7E] # ASCII
|
||||
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
|
||||
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
|
||||
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
|
||||
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
|
||||
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
|
||||
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
|
||||
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
|
||||
)*$%xs', $pathInfo)) {
|
||||
[\x09\x0A\x0D\x20-\x7E] # ASCII
|
||||
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
|
||||
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
|
||||
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
|
||||
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
|
||||
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
|
||||
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
|
||||
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
|
||||
)*$%xs', $pathInfo)
|
||||
) {
|
||||
$pathInfo = utf8_encode($pathInfo);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user