_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q241700
QueryBuilder.getColumnType
validation
public function getColumnType($type) { if ($type instanceof ColumnSchemaBuilder) { $type = $type->__toString(); } if (isset($this->typeMap[$type])) { return $this->typeMap[$type]; } elseif (preg_match('/^(\w+)\((.+?)\)(.*)$/', $type, $matches)) { ...
php
{ "resource": "" }
q241701
QueryBuilder.quoteTableNames
validation
private function quoteTableNames($tables, &$params) { foreach ($tables as $i => $table) { if ($table instanceof Query) { list($sql, $params) = $this->build($table, $params); $tables[$i] = "($sql) " . $this->db->quoteTableName($i); } elseif (is_string($...
php
{ "resource": "" }
q241702
QueryBuilder.buildColumns
validation
public function buildColumns($columns) { if (!is_array($columns)) { if (strpos($columns, '(') !== false) { return $columns; } $rawColumns = $columns; $columns = preg_split('/\s*,\s*/', $columns, -1, PREG_SPLIT_NO_EMPTY); if ($colum...
php
{ "resource": "" }
q241703
QueryBuilder.buildCondition
validation
public function buildCondition($condition, &$params) { if (is_array($condition)) { if (empty($condition)) { return ''; } $condition = $this->createConditionFromArray($condition); } if ($condition instanceof ExpressionInterface) { ...
php
{ "resource": "" }
q241704
QueryBuilder.buildAndCondition
validation
public function buildAndCondition($operator, $operands, &$params) { array_unshift($operands, $operator); return $this->buildCondition($operands, $params); }
php
{ "resource": "" }
q241705
QueryBuilder.buildNotCondition
validation
public function buildNotCondition($operator, $operands, &$params) { array_unshift($operands, $operator); return $this->buildCondition($operands, $params); }
php
{ "resource": "" }
q241706
QueryBuilder.buildBetweenCondition
validation
public function buildBetweenCondition($operator, $operands, &$params) { array_unshift($operands, $operator); return $this->buildCondition($operands, $params); }
php
{ "resource": "" }
q241707
QueryBuilder.buildInCondition
validation
public function buildInCondition($operator, $operands, &$params) { array_unshift($operands, $operator); return $this->buildCondition($operands, $params); }
php
{ "resource": "" }
q241708
QueryBuilder.buildExistsCondition
validation
public function buildExistsCondition($operator, $operands, &$params) { array_unshift($operands, $operator); return $this->buildCondition($operands, $params); }
php
{ "resource": "" }
q241709
QueryBuilder.buildSimpleCondition
validation
public function buildSimpleCondition($operator, $operands, &$params) { array_unshift($operands, $operator); return $this->buildCondition($operands, $params); }
php
{ "resource": "" }
q241710
ViewAction.run
validation
public function run($id) { $model = $this->findModel($id); if ($this->checkAccess) { call_user_func($this->checkAccess, $this->id, $model); } return $model; }
php
{ "resource": "" }
q241711
Migration.up
validation
public function up() { $transaction = $this->db->beginTransaction(); try { if ($this->safeUp() === false) { $transaction->rollBack(); return false; } $transaction->commit(); } catch (\Exception $e) { $this->print...
php
{ "resource": "" }
q241712
Migration.down
validation
public function down() { $transaction = $this->db->beginTransaction(); try { if ($this->safeDown() === false) { $transaction->rollBack(); return false; } $transaction->commit(); } catch (\Exception $e) { $this->p...
php
{ "resource": "" }
q241713
Migration.insert
validation
public function insert($table, $columns) { $time = $this->beginCommand("insert into $table"); $this->db->createCommand()->insert($table, $columns)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241714
Migration.batchInsert
validation
public function batchInsert($table, $columns, $rows) { $time = $this->beginCommand("insert into $table"); $this->db->createCommand()->batchInsert($table, $columns, $rows)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241715
Migration.update
validation
public function update($table, $columns, $condition = '', $params = []) { $time = $this->beginCommand("update $table"); $this->db->createCommand()->update($table, $columns, $condition, $params)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241716
Migration.delete
validation
public function delete($table, $condition = '', $params = []) { $time = $this->beginCommand("delete from $table"); $this->db->createCommand()->delete($table, $condition, $params)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241717
Migration.createTable
validation
public function createTable($table, $columns, $options = null) { $time = $this->beginCommand("create table $table"); $this->db->createCommand()->createTable($table, $columns, $options)->execute(); foreach ($columns as $column => $type) { if ($type instanceof ColumnSchemaBuilder &...
php
{ "resource": "" }
q241718
Migration.renameTable
validation
public function renameTable($table, $newName) { $time = $this->beginCommand("rename table $table to $newName"); $this->db->createCommand()->renameTable($table, $newName)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241719
Migration.dropColumn
validation
public function dropColumn($table, $column) { $time = $this->beginCommand("drop column $column from table $table"); $this->db->createCommand()->dropColumn($table, $column)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241720
Migration.renameColumn
validation
public function renameColumn($table, $name, $newName) { $time = $this->beginCommand("rename column $name in table $table to $newName"); $this->db->createCommand()->renameColumn($table, $name, $newName)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241721
Migration.alterColumn
validation
public function alterColumn($table, $column, $type) { $time = $this->beginCommand("alter column $column in table $table to $type"); $this->db->createCommand()->alterColumn($table, $column, $type)->execute(); if ($type instanceof ColumnSchemaBuilder && $type->comment !== null) { $...
php
{ "resource": "" }
q241722
Migration.addPrimaryKey
validation
public function addPrimaryKey($name, $table, $columns) { $time = $this->beginCommand("add primary key $name on $table (" . (is_array($columns) ? implode(',', $columns) : $columns) . ')'); $this->db->createCommand()->addPrimaryKey($name, $table, $columns)->execute(); $this->endCommand($time);...
php
{ "resource": "" }
q241723
Migration.addForeignKey
validation
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null) { $time = $this->beginCommand("add foreign key $name: $table (" . implode(',', (array) $columns) . ") references $refTable (" . implode(',', (array) $refColumns) . ')'); $this->db->createCo...
php
{ "resource": "" }
q241724
Migration.createIndex
validation
public function createIndex($name, $table, $columns, $unique = false) { $time = $this->beginCommand('create' . ($unique ? ' unique' : '') . " index $name on $table (" . implode(',', (array) $columns) . ')'); $this->db->createCommand()->createIndex($name, $table, $columns, $unique)->execute(); ...
php
{ "resource": "" }
q241725
Migration.dropIndex
validation
public function dropIndex($name, $table) { $time = $this->beginCommand("drop index $name on $table"); $this->db->createCommand()->dropIndex($name, $table)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241726
Migration.addCommentOnColumn
validation
public function addCommentOnColumn($table, $column, $comment) { $time = $this->beginCommand("add comment on column $column"); $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241727
Migration.addCommentOnTable
validation
public function addCommentOnTable($table, $comment) { $time = $this->beginCommand("add comment on table $table"); $this->db->createCommand()->addCommentOnTable($table, $comment)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241728
Migration.dropCommentFromTable
validation
public function dropCommentFromTable($table) { $time = $this->beginCommand("drop comment from table $table"); $this->db->createCommand()->dropCommentFromTable($table)->execute(); $this->endCommand($time); }
php
{ "resource": "" }
q241729
UploadedFile.getInstances
validation
public static function getInstances($model, $attribute) { $name = Html::getInputName($model, $attribute); return static::getInstancesByName($name); }
php
{ "resource": "" }
q241730
Schema.findTableConstraints
validation
protected function findTableConstraints($table, $type) { $keyColumnUsageTableName = 'INFORMATION_SCHEMA.KEY_COLUMN_USAGE'; $tableConstraintsTableName = 'INFORMATION_SCHEMA.TABLE_CONSTRAINTS'; if ($table->catalogName !== null) { $keyColumnUsageTableName = $table->catalogName . '.'...
php
{ "resource": "" }
q241731
Schema.findPrimaryKeys
validation
protected function findPrimaryKeys($table) { $result = []; foreach ($this->findTableConstraints($table, 'PRIMARY KEY') as $row) { $result[] = $row['field_name']; } $table->primaryKey = $result; }
php
{ "resource": "" }
q241732
ActiveRelationTrait.via
validation
public function via($relationName, callable $callable = null) { $relation = $this->primaryModel->getRelation($relationName); $callableUsed = $callable !== null; $this->via = [$relationName, $relation, $callableUsed]; if ($callable !== null) { call_user_func($callable, $re...
php
{ "resource": "" }
q241733
ActiveRelationTrait.findFor
validation
public function findFor($name, $model) { if (method_exists($model, 'get' . $name)) { $method = new \ReflectionMethod($model, 'get' . $name); $realName = lcfirst(substr($method->getName(), 3)); if ($realName !== $name) { throw new InvalidArgumentException('...
php
{ "resource": "" }
q241734
ActiveRelationTrait.indexBuckets
validation
private function indexBuckets($buckets, $indexBy) { $result = []; foreach ($buckets as $key => $models) { $result[$key] = []; foreach ($models as $model) { $index = is_string($indexBy) ? $model[$indexBy] : call_user_func($indexBy, $model); $res...
php
{ "resource": "" }
q241735
Logger.flush
validation
public function flush($final = false) { $messages = $this->messages; // https://github.com/yiisoft/yii2/issues/5619 // new messages could be logged while the existing ones are being handled by targets $this->messages = []; if ($this->dispatcher instanceof Dispatcher) { ...
php
{ "resource": "" }
q241736
Logger.getProfiling
validation
public function getProfiling($categories = [], $excludeCategories = []) { $timings = $this->calculateTimings($this->messages); if (empty($categories) && empty($excludeCategories)) { return $timings; } foreach ($timings as $i => $timing) { $matched = empty($ca...
php
{ "resource": "" }
q241737
Logger.getDbProfiling
validation
public function getDbProfiling() { $timings = $this->getProfiling(['yii\db\Command::query', 'yii\db\Command::execute']); $count = count($timings); $time = 0; foreach ($timings as $timing) { $time += $timing['duration']; } return [$count, $time]; }
php
{ "resource": "" }
q241738
Logger.calculateTimings
validation
public function calculateTimings($messages) { $timings = []; $stack = []; foreach ($messages as $i => $log) { list($token, $level, $category, $timestamp, $traces) = $log; $memory = isset($log[5]) ? $log[5] : 0; $log[6] = $i; $hash = md5(json_e...
php
{ "resource": "" }
q241739
Theme.applyTo
validation
public function applyTo($path) { $pathMap = $this->pathMap; if (empty($pathMap)) { if (($basePath = $this->getBasePath()) === null) { throw new InvalidConfigException('The "basePath" property must be set.'); } $pathMap = [Yii::$app->getBasePath() =...
php
{ "resource": "" }
q241740
GettextMoFile.writeInteger
validation
protected function writeInteger($fileHandle, $integer) { return $this->writeBytes($fileHandle, pack($this->useBigEndian ? 'N' : 'V', (int) $integer)); }
php
{ "resource": "" }
q241741
GettextMoFile.readString
validation
protected function readString($fileHandle, $length, $offset = null) { if ($offset !== null) { fseek($fileHandle, $offset); } return $this->readBytes($fileHandle, $length); }
php
{ "resource": "" }
q241742
CheckboxColumn.getHeaderCheckBoxName
validation
protected function getHeaderCheckBoxName() { $name = $this->name; if (substr_compare($name, '[]', -2, 2) === 0) { $name = substr($name, 0, -2); } if (substr_compare($name, ']', -1, 1) === 0) { $name = substr($name, 0, -1) . '_all]'; } else { ...
php
{ "resource": "" }
q241743
CheckboxColumn.registerClientScript
validation
public function registerClientScript() { $id = $this->grid->options['id']; $options = Json::encode([ 'name' => $this->name, 'class' => $this->cssClass, 'multiple' => $this->multiple, 'checkAll' => $this->grid->showHeader ? $this->getHeaderCheckBoxName(...
php
{ "resource": "" }
q241744
QueryBuilder.batchInsert
validation
public function batchInsert($table, $columns, $rows, &$params = []) { if (empty($rows)) { return ''; } // SQLite supports batch insert natively since 3.7.11 // http://www.sqlite.org/releaselog/3_7_11.html $this->db->open(); // ensure pdo is not null if (v...
php
{ "resource": "" }
q241745
ErrorAction.renderHtmlResponse
validation
protected function renderHtmlResponse() { return $this->controller->render($this->view ?: $this->id, $this->getViewRenderParams()); }
php
{ "resource": "" }
q241746
I18N.init
validation
public function init() { parent::init(); if (!isset($this->translations['yii']) && !isset($this->translations['yii*'])) { $this->translations['yii'] = [ 'class' => 'yii\i18n\PhpMessageSource', 'sourceLanguage' => 'en-US', 'basePath' => '@yi...
php
{ "resource": "" }
q241747
I18N.getMessageFormatter
validation
public function getMessageFormatter() { if ($this->_messageFormatter === null) { $this->_messageFormatter = new MessageFormatter(); } elseif (is_array($this->_messageFormatter) || is_string($this->_messageFormatter)) { $this->_messageFormatter = Yii::createObject($this->_mess...
php
{ "resource": "" }
q241748
I18N.getMessageSource
validation
public function getMessageSource($category) { if (isset($this->translations[$category])) { $source = $this->translations[$category]; if ($source instanceof MessageSource) { return $source; } return $this->translations[$category] = Yii::createO...
php
{ "resource": "" }
q241749
MultiFieldSession.composeFields
validation
protected function composeFields($id = null, $data = null) { $fields = $this->writeCallback ? call_user_func($this->writeCallback, $this) : []; if ($id !== null) { $fields['id'] = $id; } if ($data !== null) { $fields['data'] = $data; } return $...
php
{ "resource": "" }
q241750
HelpController.actionIndex
validation
public function actionIndex($command = null) { if ($command !== null) { $result = Yii::$app->createController($command); if ($result === false) { $name = $this->ansiFormat($command, Console::FG_YELLOW); throw new Exception("No help for unknown command ...
php
{ "resource": "" }
q241751
HelpController.actionList
validation
public function actionList() { foreach ($this->getCommandDescriptions() as $command => $description) { $result = Yii::$app->createController($command); if ($result === false || !($result[0] instanceof Controller)) { continue; } /** @var $contro...
php
{ "resource": "" }
q241752
HelpController.formatOptionHelp
validation
protected function formatOptionHelp($name, $required, $type, $defaultValue, $comment) { $comment = trim($comment); $type = trim($type); if (strncmp($type, 'bool', 4) === 0) { $type = 'boolean, 0 or 1'; } if ($defaultValue !== null && !is_array($defaultValue)) { ...
php
{ "resource": "" }
q241753
ApcCache.addValues
validation
protected function addValues($data, $duration) { $result = $this->useApcu ? apcu_add($data, null, $duration) : apc_add($data, null, $duration); return is_array($result) ? array_keys($result) : []; }
php
{ "resource": "" }
q241754
BaseMigrateController.actionUp
validation
public function actionUp($limit = 0) { $migrations = $this->getNewMigrations(); if (empty($migrations)) { $this->stdout("No new migrations found. Your system is up-to-date.\n", Console::FG_GREEN); return ExitCode::OK; } $total = count($migrations); $...
php
{ "resource": "" }
q241755
BaseMigrateController.actionDown
validation
public function actionDown($limit = 1) { if ($limit === 'all') { $limit = null; } else { $limit = (int) $limit; if ($limit < 1) { throw new Exception('The step argument must be greater than 0.'); } } $migrations = $this...
php
{ "resource": "" }
q241756
BaseMigrateController.actionTo
validation
public function actionTo($version) { if (($namespaceVersion = $this->extractNamespaceMigrationVersion($version)) !== false) { $this->migrateToVersion($namespaceVersion); } elseif (($migrationName = $this->extractMigrationVersion($version)) !== false) { $this->migrateToVersion...
php
{ "resource": "" }
q241757
BaseMigrateController.actionMark
validation
public function actionMark($version) { $originalVersion = $version; if (($namespaceVersion = $this->extractNamespaceMigrationVersion($version)) !== false) { $version = $namespaceVersion; } elseif (($migrationName = $this->extractMigrationVersion($version)) !== false) { ...
php
{ "resource": "" }
q241758
BaseMigrateController.actionFresh
validation
public function actionFresh() { if (YII_ENV_PROD) { $this->stdout("YII_ENV is set to 'prod'.\nRefreshing migrations is not possible on production systems.\n"); return ExitCode::OK; } if ($this->confirm( "Are you sure you want to reset the database and sta...
php
{ "resource": "" }
q241759
BaseMigrateController.generateClassName
validation
private function generateClassName($name) { $namespace = null; $name = trim($name, '\\'); if (strpos($name, '\\') !== false) { $namespace = substr($name, 0, strrpos($name, '\\')); $name = substr($name, strrpos($name, '\\') + 1); } else { if ($this-...
php
{ "resource": "" }
q241760
BaseMigrateController.findMigrationPath
validation
private function findMigrationPath($namespace) { if (empty($namespace)) { return is_array($this->migrationPath) ? reset($this->migrationPath) : $this->migrationPath; } if (!in_array($namespace, $this->migrationNamespaces, true)) { throw new Exception("Namespace '{$na...
php
{ "resource": "" }
q241761
BaseMigrateController.migrateUp
validation
protected function migrateUp($class) { if ($class === self::BASE_MIGRATION) { return true; } $this->stdout("*** applying $class\n", Console::FG_YELLOW); $start = microtime(true); $migration = $this->createMigration($class); if ($migration->up() !== false)...
php
{ "resource": "" }
q241762
BaseMigrateController.migrateDown
validation
protected function migrateDown($class) { if ($class === self::BASE_MIGRATION) { return true; } $this->stdout("*** reverting $class\n", Console::FG_YELLOW); $start = microtime(true); $migration = $this->createMigration($class); if ($migration->down() !== f...
php
{ "resource": "" }
q241763
BaseMigrateController.createMigration
validation
protected function createMigration($class) { $this->includeMigrationFile($class); /** @var MigrationInterface $migration */ $migration = Yii::createObject($class); if ($migration instanceof BaseObject && $migration->canSetProperty('compact')) { $migration->compact = $thi...
php
{ "resource": "" }
q241764
BaseMigrateController.includeMigrationFile
validation
protected function includeMigrationFile($class) { $class = trim($class, '\\'); if (strpos($class, '\\') === false) { if (is_array($this->migrationPath)) { foreach ($this->migrationPath as $path) { $file = $path . DIRECTORY_SEPARATOR . $class . '.php'; ...
php
{ "resource": "" }
q241765
BaseMigrateController.migrateToTime
validation
protected function migrateToTime($time) { $count = 0; $migrations = array_values($this->getMigrationHistory(null)); while ($count < count($migrations) && $migrations[$count] > $time) { ++$count; } if ($count === 0) { $this->stdout("Nothing needs to be ...
php
{ "resource": "" }
q241766
BaseMigrateController.migrateToVersion
validation
protected function migrateToVersion($version) { $originalVersion = $version; // try migrate up $migrations = $this->getNewMigrations(); foreach ($migrations as $i => $migration) { if (strpos($migration, $version) === 0) { $this->actionUp($i + 1); ...
php
{ "resource": "" }
q241767
AssetBundle.init
validation
public function init() { if ($this->sourcePath !== null) { $this->sourcePath = rtrim(Yii::getAlias($this->sourcePath), '/\\'); } if ($this->basePath !== null) { $this->basePath = rtrim(Yii::getAlias($this->basePath), '/\\'); } if ($this->baseUrl !== nu...
php
{ "resource": "" }
q241768
AssetBundle.registerAssetFiles
validation
public function registerAssetFiles($view) { $manager = $view->getAssetManager(); foreach ($this->js as $js) { if (is_array($js)) { $file = array_shift($js); $options = ArrayHelper::merge($this->jsOptions, $js); $view->registerJsFile($manage...
php
{ "resource": "" }
q241769
ReleaseController.actionInfo
validation
public function actionInfo() { $items = [ 'framework', 'app-basic', 'app-advanced', ]; $extensionPath = "{$this->basePath}/extensions"; foreach (scandir($extensionPath) as $extension) { if (ctype_alpha($extension) && is_dir($extensionPa...
php
{ "resource": "" }
q241770
ReleaseController.actionPackage
validation
public function actionPackage(array $what) { $this->validateWhat($what, ['app']); $versions = $this->getCurrentVersions($what); $this->stdout("You are about to generate packages for the following things:\n\n"); foreach ($what as $ext) { if (strncmp('app-', $ext, 4) === 0...
php
{ "resource": "" }
q241771
ReleaseController.actionSortChangelog
validation
public function actionSortChangelog(array $what) { if (\count($what) > 1) { $this->stdout("Currently only one simultaneous release is supported.\n"); return 1; } $this->validateWhat($what, ['framework', 'ext'], false); $version = $this->version ?: array_value...
php
{ "resource": "" }
q241772
ReleaseController.splitChangelog
validation
protected function splitChangelog($file, $version) { $lines = explode("\n", file_get_contents($file)); // split the file into relevant parts $start = []; $changelog = []; $end = []; $state = 'start'; foreach ($lines as $l => $line) { // starting ...
php
{ "resource": "" }
q241773
ReleaseController.resortChangelog
validation
protected function resortChangelog($changelog) { // cleanup whitespace foreach ($changelog as $i => $line) { $changelog[$i] = rtrim($line); } $changelog = array_filter($changelog); $i = 0; ArrayHelper::multisort($changelog, function ($line) use (&$i) { ...
php
{ "resource": "" }
q241774
PhpDocController.actionFix
validation
public function actionFix($root = null) { $files = $this->findFiles($root, false); $nFilesTotal = 0; $nFilesUpdated = 0; foreach ($files as $file) { $contents = file_get_contents($file); $hash = $this->hash($contents); // fix line endings ...
php
{ "resource": "" }
q241775
PhpDocController.fixFileDoc
validation
protected function fixFileDoc(&$lines) { // find namespace $namespace = false; $namespaceLine = ''; $contentAfterNamespace = false; foreach ($lines as $i => $line) { $line = trim($line); if (!empty($line)) { if (strncmp($line, 'namespac...
php
{ "resource": "" }
q241776
PhpDocController.fixDocBlockIndentation
validation
protected function fixDocBlockIndentation(&$lines) { $docBlock = false; $codeBlock = false; $listIndent = ''; $tag = false; $indent = ''; foreach ($lines as $i => $line) { if (preg_match('~^(\s*)/\*\*$~', $line, $matches)) { $docBlock = tru...
php
{ "resource": "" }
q241777
PhpDocController.cleanDocComment
validation
protected function cleanDocComment($doc) { $lines = explode("\n", $doc); $n = \count($lines); for ($i = 0; $i < $n; $i++) { $lines[$i] = rtrim($lines[$i]); if (trim($lines[$i]) == '*' && trim($lines[$i + 1]) == '*') { unset($lines[$i]); } ...
php
{ "resource": "" }
q241778
PhpDocController.updateDocComment
validation
protected function updateDocComment($doc, $properties) { $lines = explode("\n", $doc); $propertyPart = false; $propertyPosition = false; foreach ($lines as $i => $line) { $line = trim($line); if (strncmp($line, '* @property ', 12) === 0) { $pro...
php
{ "resource": "" }
q241779
Serializer.serializeDataProvider
validation
protected function serializeDataProvider($dataProvider) { if ($this->preserveKeys) { $models = $dataProvider->getModels(); } else { $models = array_values($dataProvider->getModels()); } $models = $this->serializeModels($models); if (($pagination = $da...
php
{ "resource": "" }
q241780
Serializer.serializePagination
validation
protected function serializePagination($pagination) { return [ $this->linksEnvelope => Link::serialize($pagination->getLinks(true)), $this->metaEnvelope => [ 'totalCount' => $pagination->totalCount, 'pageCount' => $pagination->getPageCount(), ...
php
{ "resource": "" }
q241781
Serializer.addPaginationHeaders
validation
protected function addPaginationHeaders($pagination) { $links = []; foreach ($pagination->getLinks(true) as $rel => $url) { $links[] = "<$url>; rel=$rel"; } $this->response->getHeaders() ->set($this->totalCountHeader, $pagination->totalCount) ->se...
php
{ "resource": "" }
q241782
Serializer.serializeModelErrors
validation
protected function serializeModelErrors($model) { $this->response->setStatusCode(422, 'Data Validation Failed.'); $result = []; foreach ($model->getFirstErrors() as $name => $message) { $result[] = [ 'field' => $name, 'message' => $message, ...
php
{ "resource": "" }
q241783
Serializer.serializeModels
validation
protected function serializeModels(array $models) { list($fields, $expand) = $this->getRequestedFields(); foreach ($models as $i => $model) { if ($model instanceof Arrayable) { $models[$i] = $model->toArray($fields, $expand); } elseif (is_array($model)) { ...
php
{ "resource": "" }
q241784
FileTarget.init
validation
public function init() { parent::init(); if ($this->logFile === null) { $this->logFile = Yii::$app->getRuntimePath() . '/logs/app.log'; } else { $this->logFile = Yii::getAlias($this->logFile); } if ($this->maxLogFiles < 1) { $this->maxLogFi...
php
{ "resource": "" }
q241785
FileTarget.export
validation
public function export() { $logPath = dirname($this->logFile); FileHelper::createDirectory($logPath, $this->dirMode, true); $text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n"; if (($fp = @fopen($this->logFile, 'a')) === false) { throw new ...
php
{ "resource": "" }
q241786
FileTarget.rotateFiles
validation
protected function rotateFiles() { $file = $this->logFile; for ($i = $this->maxLogFiles; $i >= 0; --$i) { // $i == 0 is the original log file $rotateFile = $file . ($i === 0 ? '' : '.' . $i); if (is_file($rotateFile)) { // suppress errors because i...
php
{ "resource": "" }
q241787
Schema.getCreateTableSql
validation
protected function getCreateTableSql($table) { $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->quoteTableName($table->fullName))->queryOne(); if (isset($row['Create Table'])) { $sql = $row['Create Table']; } else { $row = array_values($row); ...
php
{ "resource": "" }
q241788
MemCache.addServers
validation
protected function addServers($cache, $servers) { if (empty($servers)) { $servers = [new MemCacheServer([ 'host' => '127.0.0.1', 'port' => 11211, ])]; } else { foreach ($servers as $server) { if ($server->host === nu...
php
{ "resource": "" }
q241789
MemCache.addMemcachedServers
validation
protected function addMemcachedServers($cache, $servers) { $existingServers = []; if ($this->persistentId !== null) { foreach ($cache->getServerList() as $s) { $existingServers[$s['host'] . ':' . $s['port']] = true; } } foreach ($servers as $se...
php
{ "resource": "" }
q241790
BaseVarDumper.dumpAsString
validation
public static function dumpAsString($var, $depth = 10, $highlight = false) { self::$_output = ''; self::$_objects = []; self::$_depth = $depth; self::dumpInternal($var, 0); if ($highlight) { $result = highlight_string("<?php\n" . self::$_output, true); ...
php
{ "resource": "" }
q241791
CacheController.actionIndex
validation
public function actionIndex() { $caches = $this->findCaches(); if (!empty($caches)) { $this->notifyCachesCanBeFlushed($caches); } else { $this->notifyNoCachesFound(); } }
php
{ "resource": "" }
q241792
CacheController.actionFlush
validation
public function actionFlush() { $cachesInput = func_get_args(); if (empty($cachesInput)) { throw new Exception('You should specify cache components names'); } $caches = $this->findCaches($cachesInput); $cachesInfo = []; $foundCaches = array_keys($caches...
php
{ "resource": "" }
q241793
CacheController.actionFlushAll
validation
public function actionFlushAll() { $caches = $this->findCaches(); $cachesInfo = []; if (empty($caches)) { $this->notifyNoCachesFound(); return ExitCode::OK; } foreach ($caches as $name => $class) { $cachesInfo[] = [ 'name'...
php
{ "resource": "" }
q241794
CacheController.actionFlushSchema
validation
public function actionFlushSchema($db = 'db') { $connection = Yii::$app->get($db, false); if ($connection === null) { $this->stdout("Unknown component \"$db\".\n", Console::FG_RED); return ExitCode::UNSPECIFIED_ERROR; } if (!$connection instanceof \yii\db\Con...
php
{ "resource": "" }
q241795
CacheController.notifyCachesCanBeFlushed
validation
private function notifyCachesCanBeFlushed($caches) { $this->stdout("The following caches were found in the system:\n\n", Console::FG_YELLOW); foreach ($caches as $name => $class) { if ($this->canBeFlushed($class)) { $this->stdout("\t* $name ($class)\n", Console::FG_GREEN...
php
{ "resource": "" }
q241796
CacheController.notifyNotFoundCaches
validation
private function notifyNotFoundCaches($cachesNames) { $this->stdout("The following cache components were NOT found:\n\n", Console::FG_RED); foreach ($cachesNames as $name) { $this->stdout("\t* $name \n", Console::FG_GREEN); } $this->stdout("\n"); }
php
{ "resource": "" }
q241797
ServiceLocator.setComponents
validation
public function setComponents($components) { foreach ($components as $id => $component) { $this->set($id, $component); } }
php
{ "resource": "" }
q241798
ActiveDataFilter.buildConjunctionCondition
validation
protected function buildConjunctionCondition($operator, $condition) { if (isset($this->queryOperatorMap[$operator])) { $operator = $this->queryOperatorMap[$operator]; } $result = [$operator]; foreach ($condition as $part) { $result[] = $this->buildCondition($...
php
{ "resource": "" }
q241799
ActiveDataFilter.buildBlockCondition
validation
protected function buildBlockCondition($operator, $condition) { if (isset($this->queryOperatorMap[$operator])) { $operator = $this->queryOperatorMap[$operator]; } return [ $operator, $this->buildCondition($condition), ]; }
php
{ "resource": "" }