Browse Source

Use static:: instead of $this for static method calls

batch-query-test
Alexander Makarov 9 years ago
parent
commit
1f7134634b
  1. 2
      framework/base/Application.php
  2. 7
      framework/captcha/Captcha.php
  3. 10
      framework/db/ActiveRecord.php
  4. 14
      framework/db/BaseActiveRecord.php
  5. 2
      framework/log/Target.php

2
framework/base/Application.php

@ -195,7 +195,7 @@ abstract class Application extends Module
public function __construct($config = []) public function __construct($config = [])
{ {
Yii::$app = $this; Yii::$app = $this;
$this->setInstance($this); static::setInstance($this);
$this->state = self::STATE_BEGIN; $this->state = self::STATE_BEGIN;

7
framework/captcha/Captcha.php

@ -91,7 +91,7 @@ class Captcha extends InputWidget
{ {
parent::init(); parent::init();
$this->checkRequirements(); static::checkRequirements();
if (!isset($this->imageOptions['id'])) { if (!isset($this->imageOptions['id'])) {
$this->imageOptions['id'] = $this->options['id'] . '-image'; $this->imageOptions['id'] = $this->options['id'] . '-image';
@ -165,9 +165,8 @@ class Captcha extends InputWidget
public static function checkRequirements() public static function checkRequirements()
{ {
if (extension_loaded('imagick')) { if (extension_loaded('imagick')) {
$imagick = new \Imagick(); $imagickFormats = \Imagick::queryFormats('PNG');
$imagickFormats = $imagick->queryFormats('PNG'); if (in_array('PNG', $imagickFormats, true)) {
if (in_array('PNG', $imagickFormats)) {
return 'imagick'; return 'imagick';
} }
} }

10
framework/db/ActiveRecord.php

@ -114,7 +114,7 @@ class ActiveRecord extends BaseActiveRecord
*/ */
public function loadDefaultValues($skipIfSet = true) public function loadDefaultValues($skipIfSet = true)
{ {
foreach ($this->getTableSchema()->columns as $column) { foreach (static::getTableSchema()->columns as $column) {
if ($column->defaultValue !== null && (!$skipIfSet || $this->{$column->name} === null)) { if ($column->defaultValue !== null && (!$skipIfSet || $this->{$column->name} === null)) {
$this->{$column->name} = $column->defaultValue; $this->{$column->name} = $column->defaultValue;
} }
@ -454,11 +454,11 @@ class ActiveRecord extends BaseActiveRecord
return false; return false;
} }
$values = $this->getDirtyAttributes($attributes); $values = $this->getDirtyAttributes($attributes);
if (($primaryKeys = static::getDb()->schema->insert($this->tableName(), $values)) === false) { if (($primaryKeys = static::getDb()->schema->insert(static::tableName(), $values)) === false) {
return false; return false;
} }
foreach ($primaryKeys as $name => $value) { foreach ($primaryKeys as $name => $value) {
$id = $this->getTableSchema()->columns[$name]->phpTypecast($value); $id = static::getTableSchema()->columns[$name]->phpTypecast($value);
$this->setAttribute($name, $id); $this->setAttribute($name, $id);
$values[$name] = $id; $values[$name] = $id;
} }
@ -607,7 +607,7 @@ class ActiveRecord extends BaseActiveRecord
if ($lock !== null) { if ($lock !== null) {
$condition[$lock] = $this->$lock; $condition[$lock] = $this->$lock;
} }
$result = $this->deleteAll($condition); $result = static::deleteAll($condition);
if ($lock !== null && !$result) { if ($lock !== null && !$result) {
throw new StaleObjectException('The object being deleted is outdated.'); throw new StaleObjectException('The object being deleted is outdated.');
} }
@ -630,7 +630,7 @@ class ActiveRecord extends BaseActiveRecord
return false; return false;
} }
return $this->tableName() === $record->tableName() && $this->getPrimaryKey() === $record->getPrimaryKey(); return static::tableName() === $record->tableName() && $this->getPrimaryKey() === $record->getPrimaryKey();
} }
/** /**

14
framework/db/BaseActiveRecord.php

@ -688,7 +688,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
return 0; return 0;
} }
$rows = $this->updateAll($values, $this->getOldPrimaryKey(true)); $rows = static::updateAll($values, $this->getOldPrimaryKey(true));
foreach ($values as $name => $value) { foreach ($values as $name => $value) {
$this->_oldAttributes[$name] = $this->_attributes[$name]; $this->_oldAttributes[$name] = $this->_attributes[$name];
@ -721,7 +721,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
} }
// We do not check the return value of updateAll() because it's possible // We do not check the return value of updateAll() because it's possible
// that the UPDATE statement doesn't change anything and thus returns 0. // that the UPDATE statement doesn't change anything and thus returns 0.
$rows = $this->updateAll($values, $condition); $rows = static::updateAll($values, $condition);
if ($lock !== null && !$rows) { if ($lock !== null && !$rows) {
throw new StaleObjectException('The object being updated is outdated.'); throw new StaleObjectException('The object being updated is outdated.');
@ -760,7 +760,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/ */
public function updateCounters($counters) public function updateCounters($counters)
{ {
if ($this->updateAllCounters($counters, $this->getOldPrimaryKey(true)) > 0) { if (static::updateAllCounters($counters, $this->getOldPrimaryKey(true)) > 0) {
foreach ($counters as $name => $value) { foreach ($counters as $name => $value) {
if (!isset($this->_attributes[$name])) { if (!isset($this->_attributes[$name])) {
$this->_attributes[$name] = $value; $this->_attributes[$name] = $value;
@ -805,7 +805,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
if ($lock !== null) { if ($lock !== null) {
$condition[$lock] = $this->$lock; $condition[$lock] = $this->$lock;
} }
$result = $this->deleteAll($condition); $result = static::deleteAll($condition);
if ($lock !== null && !$result) { if ($lock !== null && !$result) {
throw new StaleObjectException('The object being deleted is outdated.'); throw new StaleObjectException('The object being deleted is outdated.');
} }
@ -957,7 +957,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
public function refresh() public function refresh()
{ {
/* @var $record BaseActiveRecord */ /* @var $record BaseActiveRecord */
$record = $this->findOne($this->getPrimaryKey(true)); $record = static::findOne($this->getPrimaryKey(true));
if ($record === null) { if ($record === null) {
return false; return false;
} }
@ -1212,7 +1212,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
} }
} else { } else {
$p1 = $model->isPrimaryKey(array_keys($relation->link)); $p1 = $model->isPrimaryKey(array_keys($relation->link));
$p2 = $this->isPrimaryKey(array_values($relation->link)); $p2 = static::isPrimaryKey(array_values($relation->link));
if ($p1 && $p2) { if ($p1 && $p2) {
if ($this->getIsNewRecord() && $model->getIsNewRecord()) { if ($this->getIsNewRecord() && $model->getIsNewRecord()) {
throw new InvalidCallException('Unable to link models: at most one model can be newly created.'); throw new InvalidCallException('Unable to link models: at most one model can be newly created.');
@ -1302,7 +1302,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
} }
} else { } else {
$p1 = $model->isPrimaryKey(array_keys($relation->link)); $p1 = $model->isPrimaryKey(array_keys($relation->link));
$p2 = $this->isPrimaryKey(array_values($relation->link)); $p2 = static::isPrimaryKey(array_values($relation->link));
if ($p2) { if ($p2) {
foreach ($relation->link as $a => $b) { foreach ($relation->link as $a => $b) {
$model->$a = null; $model->$a = null;

2
framework/log/Target.php

@ -99,7 +99,7 @@ abstract class Target extends Component
*/ */
public function collect($messages, $final) public function collect($messages, $final)
{ {
$this->messages = array_merge($this->messages, $this->filterMessages($messages, $this->getLevels(), $this->categories, $this->except)); $this->messages = array_merge($this->messages, static::filterMessages($messages, $this->getLevels(), $this->categories, $this->except));
$count = count($this->messages); $count = count($this->messages);
if ($count > 0 && ($final || $this->exportInterval > 0 && $count >= $this->exportInterval)) { if ($count > 0 && ($final || $this->exportInterval > 0 && $count >= $this->exportInterval)) {
if (($context = $this->getContextMessage()) !== '') { if (($context = $this->getContextMessage()) !== '') {

Loading…
Cancel
Save