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 = [])
{
Yii::$app = $this;
$this->setInstance($this);
static::setInstance($this);
$this->state = self::STATE_BEGIN;

7
framework/captcha/Captcha.php

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

10
framework/db/ActiveRecord.php

@ -114,7 +114,7 @@ class ActiveRecord extends BaseActiveRecord
*/
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)) {
$this->{$column->name} = $column->defaultValue;
}
@ -454,11 +454,11 @@ class ActiveRecord extends BaseActiveRecord
return false;
}
$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;
}
foreach ($primaryKeys as $name => $value) {
$id = $this->getTableSchema()->columns[$name]->phpTypecast($value);
$id = static::getTableSchema()->columns[$name]->phpTypecast($value);
$this->setAttribute($name, $id);
$values[$name] = $id;
}
@ -607,7 +607,7 @@ class ActiveRecord extends BaseActiveRecord
if ($lock !== null) {
$condition[$lock] = $this->$lock;
}
$result = $this->deleteAll($condition);
$result = static::deleteAll($condition);
if ($lock !== null && !$result) {
throw new StaleObjectException('The object being deleted is outdated.');
}
@ -630,7 +630,7 @@ class ActiveRecord extends BaseActiveRecord
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;
}
$rows = $this->updateAll($values, $this->getOldPrimaryKey(true));
$rows = static::updateAll($values, $this->getOldPrimaryKey(true));
foreach ($values as $name => $value) {
$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
// 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) {
throw new StaleObjectException('The object being updated is outdated.');
@ -760,7 +760,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
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) {
if (!isset($this->_attributes[$name])) {
$this->_attributes[$name] = $value;
@ -805,7 +805,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
if ($lock !== null) {
$condition[$lock] = $this->$lock;
}
$result = $this->deleteAll($condition);
$result = static::deleteAll($condition);
if ($lock !== null && !$result) {
throw new StaleObjectException('The object being deleted is outdated.');
}
@ -957,7 +957,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
public function refresh()
{
/* @var $record BaseActiveRecord */
$record = $this->findOne($this->getPrimaryKey(true));
$record = static::findOne($this->getPrimaryKey(true));
if ($record === null) {
return false;
}
@ -1212,7 +1212,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
}
} else {
$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 ($this->getIsNewRecord() && $model->getIsNewRecord()) {
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 {
$p1 = $model->isPrimaryKey(array_keys($relation->link));
$p2 = $this->isPrimaryKey(array_values($relation->link));
$p2 = static::isPrimaryKey(array_values($relation->link));
if ($p2) {
foreach ($relation->link as $a => $b) {
$model->$a = null;

2
framework/log/Target.php

@ -99,7 +99,7 @@ abstract class Target extends Component
*/
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);
if ($count > 0 && ($final || $this->exportInterval > 0 && $count >= $this->exportInterval)) {
if (($context = $this->getContextMessage()) !== '') {

Loading…
Cancel
Save