Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace yii\db; use Yii; use yii\base\InvalidArgumentException; use yii\base\Inva..

Decoded Output download

<?php
 namespace yii\db; use Yii; use yiiase\InvalidArgumentException; use yiiase\InvalidConfigException; use yii\helpers\ArrayHelper; use yii\helpers\Inflector; use yii\helpers\StringHelper; class ActiveRecord extends BaseActiveRecord { const OP_INSERT = 1; const OP_UPDATE = 2; const OP_DELETE = 4; const OP_ALL = 7; public function loadDefaultValues($skipIfSet = true) { $columns = static::getTableSchema()->columns; foreach ($this->attributes() as $name) { if (isset($columns[$name])) { $defaultValue = $columns[$name]->defaultValue; if ($defaultValue !== null && (!$skipIfSet || $this->getAttribute($name) === null)) { $this->setAttribute($name, $defaultValue); } } } return $this; } public static function getDb() { return Yii::$app->getDb(); } public static function findBySql($sql, $params = array()) { $query = static::find(); $query->sql = $sql; return $query->params($params); } protected static function findByCondition($condition) { $query = static::find(); if (!ArrayHelper::isAssociative($condition) && !$condition instanceof ExpressionInterface) { $primaryKey = static::primaryKey(); if (isset($primaryKey[0])) { $pk = $primaryKey[0]; if (!empty($query->join) || !empty($query->joinWith)) { $pk = static::tableName() . "." . $pk; } $condition = array($pk => is_array($condition) ? array_values($condition) : $condition); } else { throw new InvalidConfigException(""" . get_called_class() . "" must have a primary key."); } } elseif (is_array($condition)) { $aliases = static::filterValidAliases($query); $condition = static::filterCondition($condition, $aliases); } return $query->andWhere($condition); } protected static function filterValidAliases(Query $query) { $tables = $query->getTablesUsedInFrom(); $aliases = array_diff(array_keys($tables), $tables); return array_map(function ($alias) { return preg_replace("/{{(\w+)}}/", "$1", $alias); }, array_values($aliases)); } protected static function filterCondition(array $condition, array $aliases = array()) { $result = array(); $db = static::getDb(); $columnNames = static::filterValidColumnNames($db, $aliases); foreach ($condition as $key => $value) { if (is_string($key) && !in_array($db->quoteSql($key), $columnNames, true)) { throw new InvalidArgumentException("Key "" . $key . "" is not a column name and can not be used as a filter"); } $result[$key] = is_array($value) ? array_values($value) : $value; } return $result; } protected static function filterValidColumnNames($db, array $aliases) { $columnNames = array(); $tableName = static::tableName(); $quotedTableName = $db->quoteTableName($tableName); foreach (static::getTableSchema()->getColumnNames() as $columnName) { $columnNames[] = $columnName; $columnNames[] = $db->quoteColumnName($columnName); $columnNames[] = "{$tableName}.{$columnName}"; $columnNames[] = $db->quoteSql("{$quotedTableName}.[[{$columnName}]]"); foreach ($aliases as $tableAlias) { $columnNames[] = "{$tableAlias}.{$columnName}"; $quotedTableAlias = $db->quoteTableName($tableAlias); $columnNames[] = $db->quoteSql("{$quotedTableAlias}.[[{$columnName}]]"); } } return $columnNames; } public function refresh() { $query = static::find(); $tableName = key($query->getTablesUsedInFrom()); $pk = array(); foreach ($this->getPrimaryKey(true) as $key => $value) { $pk[$tableName . "." . $key] = $value; } $query->where($pk); $record = $query->noCache()->one(); return $this->refreshInternal($record); } public static function updateAll($attributes, $condition = '', $params = array()) { $command = static::getDb()->createCommand(); $command->update(static::tableName(), $attributes, $condition, $params); return $command->execute(); } public static function updateAllCounters($counters, $condition = '', $params = array()) { $n = 0; foreach ($counters as $name => $value) { $counters[$name] = new Expression("[[{$name}]]+:bp{$n}", array(":bp{$n}" => $value)); $n++; } $command = static::getDb()->createCommand(); $command->update(static::tableName(), $counters, $condition, $params); return $command->execute(); } public static function deleteAll($condition = null, $params = array()) { $command = static::getDb()->createCommand(); $command->delete(static::tableName(), $condition, $params); return $command->execute(); } public static function find() { return Yii::createObject(ActiveQuery::className(), array(get_called_class())); } public static function tableName() { return "{{%" . Inflector::camel2id(StringHelper::basename(get_called_class()), "_") . "}}"; } public static function getTableSchema() { $tableSchema = static::getDb()->getSchema()->getTableSchema(static::tableName()); if ($tableSchema === null) { throw new InvalidConfigException("The table does not exist: " . static::tableName()); } return $tableSchema; } public static function primaryKey() { return static::getTableSchema()->primaryKey; } public function attributes() { return static::getTableSchema()->getColumnNames(); } public function transactions() { return array(); } public static function populateRecord($record, $row) { $columns = static::getTableSchema()->columns; foreach ($row as $name => $value) { if (isset($columns[$name])) { $row[$name] = $columns[$name]->phpTypecast($value); } } parent::populateRecord($record, $row); } public function insert($runValidation = true, $attributes = null) { if ($runValidation && !$this->validate($attributes)) { Yii::info("Model not inserted due to validation error.", __METHOD__); return false; } if (!$this->isTransactional(self::OP_INSERT)) { return $this->insertInternal($attributes); } $transaction = static::getDb()->beginTransaction(); try { $result = $this->insertInternal($attributes); if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } catch (\Throwable $e) { $transaction->rollBack(); throw $e; } } protected function insertInternal($attributes = null) { if (!$this->beforeSave(true)) { return false; } $values = $this->getDirtyAttributes($attributes); if (($primaryKeys = static::getDb()->schema->insert(static::tableName(), $values)) === false) { return false; } foreach ($primaryKeys as $name => $value) { $id = static::getTableSchema()->columns[$name]->phpTypecast($value); $this->setAttribute($name, $id); $values[$name] = $id; } $changedAttributes = array_fill_keys(array_keys($values), null); $this->setOldAttributes($values); $this->afterSave(true, $changedAttributes); return true; } public function update($runValidation = true, $attributeNames = null) { if ($runValidation && !$this->validate($attributeNames)) { Yii::info("Model not updated due to validation error.", __METHOD__); return false; } if (!$this->isTransactional(self::OP_UPDATE)) { return $this->updateInternal($attributeNames); } $transaction = static::getDb()->beginTransaction(); try { $result = $this->updateInternal($attributeNames); if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } catch (\Throwable $e) { $transaction->rollBack(); throw $e; } } public function delete() { if (!$this->isTransactional(self::OP_DELETE)) { return $this->deleteInternal(); } $transaction = static::getDb()->beginTransaction(); try { $result = $this->deleteInternal(); if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } catch (\Throwable $e) { $transaction->rollBack(); throw $e; } } protected function deleteInternal() { if (!$this->beforeDelete()) { return false; } $condition = $this->getOldPrimaryKey(true); $lock = $this->optimisticLock(); if ($lock !== null) { $condition[$lock] = $this->{$lock}; } $result = static::deleteAll($condition); if ($lock !== null && !$result) { throw new StaleObjectException("The object being deleted is outdated."); } $this->setOldAttributes(null); $this->afterDelete(); return $result; } public function equals($record) { if ($this->isNewRecord || $record->isNewRecord) { return false; } return static::tableName() === $record->tableName() && $this->getPrimaryKey() === $record->getPrimaryKey(); } public function isTransactional($operation) { $scenario = $this->getScenario(); $transactions = $this->transactions(); return isset($transactions[$scenario]) && $transactions[$scenario] & $operation; } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace yii\db; use Yii; use yii\base\InvalidArgumentException; use yii\base\InvalidConfigException; use yii\helpers\ArrayHelper; use yii\helpers\Inflector; use yii\helpers\StringHelper; class ActiveRecord extends BaseActiveRecord { const OP_INSERT = 1; const OP_UPDATE = 2; const OP_DELETE = 4; const OP_ALL = 7; public function loadDefaultValues($skipIfSet = true) { $columns = static::getTableSchema()->columns; foreach ($this->attributes() as $name) { if (isset($columns[$name])) { $defaultValue = $columns[$name]->defaultValue; if ($defaultValue !== null && (!$skipIfSet || $this->getAttribute($name) === null)) { $this->setAttribute($name, $defaultValue); } } } return $this; } public static function getDb() { return Yii::$app->getDb(); } public static function findBySql($sql, $params = array()) { $query = static::find(); $query->sql = $sql; return $query->params($params); } protected static function findByCondition($condition) { $query = static::find(); if (!ArrayHelper::isAssociative($condition) && !$condition instanceof ExpressionInterface) { $primaryKey = static::primaryKey(); if (isset($primaryKey[0])) { $pk = $primaryKey[0]; if (!empty($query->join) || !empty($query->joinWith)) { $pk = static::tableName() . "\x2e" . $pk; } $condition = array($pk => is_array($condition) ? array_values($condition) : $condition); } else { throw new InvalidConfigException("\42" . get_called_class() . "\42\x20\x6d\x75\163\x74\x20\x68\141\x76\145\40\x61\40\x70\162\151\155\141\x72\171\x20\153\145\x79\x2e"); } } elseif (is_array($condition)) { $aliases = static::filterValidAliases($query); $condition = static::filterCondition($condition, $aliases); } return $query->andWhere($condition); } protected static function filterValidAliases(Query $query) { $tables = $query->getTablesUsedInFrom(); $aliases = array_diff(array_keys($tables), $tables); return array_map(function ($alias) { return preg_replace("\x2f\x7b\x7b\x28\134\167\x2b\x29\x7d\175\x2f", "\x24\61", $alias); }, array_values($aliases)); } protected static function filterCondition(array $condition, array $aliases = array()) { $result = array(); $db = static::getDb(); $columnNames = static::filterValidColumnNames($db, $aliases); foreach ($condition as $key => $value) { if (is_string($key) && !in_array($db->quoteSql($key), $columnNames, true)) { throw new InvalidArgumentException("\113\x65\171\40\x22" . $key . "\42\40\x69\x73\40\156\x6f\164\40\x61\x20\143\157\x6c\x75\x6d\156\x20\156\141\x6d\x65\x20\141\156\x64\40\x63\141\x6e\40\156\x6f\164\40\x62\x65\x20\x75\x73\145\x64\x20\x61\163\x20\x61\40\x66\x69\154\x74\x65\162"); } $result[$key] = is_array($value) ? array_values($value) : $value; } return $result; } protected static function filterValidColumnNames($db, array $aliases) { $columnNames = array(); $tableName = static::tableName(); $quotedTableName = $db->quoteTableName($tableName); foreach (static::getTableSchema()->getColumnNames() as $columnName) { $columnNames[] = $columnName; $columnNames[] = $db->quoteColumnName($columnName); $columnNames[] = "{$tableName}\x2e{$columnName}"; $columnNames[] = $db->quoteSql("{$quotedTableName}\56\133\133{$columnName}\x5d\135"); foreach ($aliases as $tableAlias) { $columnNames[] = "{$tableAlias}\x2e{$columnName}"; $quotedTableAlias = $db->quoteTableName($tableAlias); $columnNames[] = $db->quoteSql("{$quotedTableAlias}\x2e\x5b\133{$columnName}\x5d\135"); } } return $columnNames; } public function refresh() { $query = static::find(); $tableName = key($query->getTablesUsedInFrom()); $pk = array(); foreach ($this->getPrimaryKey(true) as $key => $value) { $pk[$tableName . "\56" . $key] = $value; } $query->where($pk); $record = $query->noCache()->one(); return $this->refreshInternal($record); } public static function updateAll($attributes, $condition = '', $params = array()) { $command = static::getDb()->createCommand(); $command->update(static::tableName(), $attributes, $condition, $params); return $command->execute(); } public static function updateAllCounters($counters, $condition = '', $params = array()) { $n = 0; foreach ($counters as $name => $value) { $counters[$name] = new Expression("\x5b\133{$name}\x5d\135\53\72\142\160{$n}", array("\72\x62\160{$n}" => $value)); $n++; } $command = static::getDb()->createCommand(); $command->update(static::tableName(), $counters, $condition, $params); return $command->execute(); } public static function deleteAll($condition = null, $params = array()) { $command = static::getDb()->createCommand(); $command->delete(static::tableName(), $condition, $params); return $command->execute(); } public static function find() { return Yii::createObject(ActiveQuery::className(), array(get_called_class())); } public static function tableName() { return "\x7b\x7b\x25" . Inflector::camel2id(StringHelper::basename(get_called_class()), "\x5f") . "\x7d\175"; } public static function getTableSchema() { $tableSchema = static::getDb()->getSchema()->getTableSchema(static::tableName()); if ($tableSchema === null) { throw new InvalidConfigException("\x54\150\x65\x20\164\141\x62\154\x65\x20\x64\x6f\145\x73\x20\x6e\157\164\x20\x65\170\151\x73\164\72\x20" . static::tableName()); } return $tableSchema; } public static function primaryKey() { return static::getTableSchema()->primaryKey; } public function attributes() { return static::getTableSchema()->getColumnNames(); } public function transactions() { return array(); } public static function populateRecord($record, $row) { $columns = static::getTableSchema()->columns; foreach ($row as $name => $value) { if (isset($columns[$name])) { $row[$name] = $columns[$name]->phpTypecast($value); } } parent::populateRecord($record, $row); } public function insert($runValidation = true, $attributes = null) { if ($runValidation && !$this->validate($attributes)) { Yii::info("\115\x6f\x64\x65\154\40\x6e\x6f\164\x20\151\x6e\163\145\x72\x74\145\144\40\144\165\x65\x20\x74\157\x20\166\x61\154\x69\144\141\164\151\157\x6e\40\x65\x72\162\157\162\x2e", __METHOD__); return false; } if (!$this->isTransactional(self::OP_INSERT)) { return $this->insertInternal($attributes); } $transaction = static::getDb()->beginTransaction(); try { $result = $this->insertInternal($attributes); if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } catch (\Throwable $e) { $transaction->rollBack(); throw $e; } } protected function insertInternal($attributes = null) { if (!$this->beforeSave(true)) { return false; } $values = $this->getDirtyAttributes($attributes); if (($primaryKeys = static::getDb()->schema->insert(static::tableName(), $values)) === false) { return false; } foreach ($primaryKeys as $name => $value) { $id = static::getTableSchema()->columns[$name]->phpTypecast($value); $this->setAttribute($name, $id); $values[$name] = $id; } $changedAttributes = array_fill_keys(array_keys($values), null); $this->setOldAttributes($values); $this->afterSave(true, $changedAttributes); return true; } public function update($runValidation = true, $attributeNames = null) { if ($runValidation && !$this->validate($attributeNames)) { Yii::info("\x4d\157\x64\x65\x6c\x20\156\x6f\x74\40\165\x70\x64\141\x74\145\144\x20\x64\165\145\x20\x74\x6f\40\x76\141\154\151\144\x61\x74\151\x6f\156\40\145\162\162\157\x72\56", __METHOD__); return false; } if (!$this->isTransactional(self::OP_UPDATE)) { return $this->updateInternal($attributeNames); } $transaction = static::getDb()->beginTransaction(); try { $result = $this->updateInternal($attributeNames); if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } catch (\Throwable $e) { $transaction->rollBack(); throw $e; } } public function delete() { if (!$this->isTransactional(self::OP_DELETE)) { return $this->deleteInternal(); } $transaction = static::getDb()->beginTransaction(); try { $result = $this->deleteInternal(); if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; } catch (\Throwable $e) { $transaction->rollBack(); throw $e; } } protected function deleteInternal() { if (!$this->beforeDelete()) { return false; } $condition = $this->getOldPrimaryKey(true); $lock = $this->optimisticLock(); if ($lock !== null) { $condition[$lock] = $this->{$lock}; } $result = static::deleteAll($condition); if ($lock !== null && !$result) { throw new StaleObjectException("\124\150\x65\40\157\142\x6a\x65\x63\x74\x20\142\x65\151\156\x67\x20\144\x65\x6c\145\x74\145\x64\40\x69\x73\x20\157\165\164\x64\x61\x74\x65\x64\56"); } $this->setOldAttributes(null); $this->afterDelete(); return $result; } public function equals($record) { if ($this->isNewRecord || $record->isNewRecord) { return false; } return static::tableName() === $record->tableName() && $this->getPrimaryKey() === $record->getPrimaryKey(); } public function isTransactional($operation) { $scenario = $this->getScenario(); $transactions = $this->transactions(); return isset($transactions[$scenario]) && $transactions[$scenario] & $operation; } }

Function Calls

None

Variables

None

Stats

MD5 3bd6a8e0a9a986c870a9b2f64bc3fe30
Eval Count 0
Decode Time 112 ms