_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q241600
|
YiiRequirementChecker.checkUploadMaxFileSize
|
validation
|
function checkUploadMaxFileSize($min = null, $max = null)
{
$postMaxSize = ini_get('post_max_size');
$uploadMaxFileSize = ini_get('upload_max_filesize');
if ($min !== null) {
$minCheckResult = $this->compareByteSize($postMaxSize, $min, '>=') && $this->compareByteSize($uploadMaxFileSize, $min, '>=');
} else {
$minCheckResult = true;
}
if ($max !== null) {
$maxCheckResult = $this->compareByteSize($postMaxSize, $max, '<=') && $this->compareByteSize($uploadMaxFileSize, $max, '<=');
} else {
$maxCheckResult = true;
}
return ($minCheckResult && $maxCheckResult);
}
|
php
|
{
"resource": ""
}
|
q241601
|
YiiRequirementChecker.normalizeRequirement
|
validation
|
function normalizeRequirement($requirement, $requirementKey = 0)
{
if (!is_array($requirement)) {
$this->usageError('Requirement must be an array!');
}
if (!array_key_exists('condition', $requirement)) {
$this->usageError("Requirement '{$requirementKey}' has no condition!");
} else {
$evalPrefix = 'eval:';
if (is_string($requirement['condition']) && strpos($requirement['condition'], $evalPrefix) === 0) {
$expression = substr($requirement['condition'], strlen($evalPrefix));
$requirement['condition'] = $this->evaluateExpression($expression);
}
}
if (!array_key_exists('name', $requirement)) {
$requirement['name'] = is_numeric($requirementKey) ? 'Requirement #' . $requirementKey : $requirementKey;
}
if (!array_key_exists('mandatory', $requirement)) {
if (array_key_exists('required', $requirement)) {
$requirement['mandatory'] = $requirement['required'];
} else {
$requirement['mandatory'] = false;
}
}
if (!array_key_exists('by', $requirement)) {
$requirement['by'] = 'Unknown';
}
if (!array_key_exists('memo', $requirement)) {
$requirement['memo'] = '';
}
return $requirement;
}
|
php
|
{
"resource": ""
}
|
q241602
|
GridView.renderErrors
|
validation
|
public function renderErrors()
{
if ($this->filterModel instanceof Model && $this->filterModel->hasErrors()) {
return Html::errorSummary($this->filterModel, $this->filterErrorSummaryOptions);
}
return '';
}
|
php
|
{
"resource": ""
}
|
q241603
|
GridView.getClientOptions
|
validation
|
protected function getClientOptions()
{
$filterUrl = isset($this->filterUrl) ? $this->filterUrl : Yii::$app->request->url;
$id = $this->filterRowOptions['id'];
$filterSelector = "#$id input, #$id select";
if (isset($this->filterSelector)) {
$filterSelector .= ', ' . $this->filterSelector;
}
return [
'filterUrl' => Url::to($filterUrl),
'filterSelector' => $filterSelector,
];
}
|
php
|
{
"resource": ""
}
|
q241604
|
GridView.renderItems
|
validation
|
public function renderItems()
{
$caption = $this->renderCaption();
$columnGroup = $this->renderColumnGroup();
$tableHeader = $this->showHeader ? $this->renderTableHeader() : false;
$tableBody = $this->renderTableBody();
$tableFooter = false;
$tableFooterAfterBody = false;
if ($this->showFooter) {
if ($this->placeFooterAfterBody) {
$tableFooterAfterBody = $this->renderTableFooter();
} else {
$tableFooter = $this->renderTableFooter();
}
}
$content = array_filter([
$caption,
$columnGroup,
$tableHeader,
$tableFooter,
$tableBody,
$tableFooterAfterBody,
]);
return Html::tag('table', implode("\n", $content), $this->tableOptions);
}
|
php
|
{
"resource": ""
}
|
q241605
|
GridView.renderCaption
|
validation
|
public function renderCaption()
{
if (!empty($this->caption)) {
return Html::tag('caption', $this->caption, $this->captionOptions);
}
return false;
}
|
php
|
{
"resource": ""
}
|
q241606
|
GridView.renderColumnGroup
|
validation
|
public function renderColumnGroup()
{
foreach ($this->columns as $column) {
/* @var $column Column */
if (!empty($column->options)) {
$cols = [];
foreach ($this->columns as $col) {
$cols[] = Html::tag('col', '', $col->options);
}
return Html::tag('colgroup', implode("\n", $cols));
}
}
return false;
}
|
php
|
{
"resource": ""
}
|
q241607
|
GridView.renderTableFooter
|
validation
|
public function renderTableFooter()
{
$cells = [];
foreach ($this->columns as $column) {
/* @var $column Column */
$cells[] = $column->renderFooterCell();
}
$content = Html::tag('tr', implode('', $cells), $this->footerRowOptions);
if ($this->filterPosition === self::FILTER_POS_FOOTER) {
$content .= $this->renderFilters();
}
return "<tfoot>\n" . $content . "\n</tfoot>";
}
|
php
|
{
"resource": ""
}
|
q241608
|
GridView.renderFilters
|
validation
|
public function renderFilters()
{
if ($this->filterModel !== null) {
$cells = [];
foreach ($this->columns as $column) {
/* @var $column Column */
$cells[] = $column->renderFilterCell();
}
return Html::tag('tr', implode('', $cells), $this->filterRowOptions);
}
return '';
}
|
php
|
{
"resource": ""
}
|
q241609
|
GridView.renderTableBody
|
validation
|
public function renderTableBody()
{
$models = array_values($this->dataProvider->getModels());
$keys = $this->dataProvider->getKeys();
$rows = [];
foreach ($models as $index => $model) {
$key = $keys[$index];
if ($this->beforeRow !== null) {
$row = call_user_func($this->beforeRow, $model, $key, $index, $this);
if (!empty($row)) {
$rows[] = $row;
}
}
$rows[] = $this->renderTableRow($model, $key, $index);
if ($this->afterRow !== null) {
$row = call_user_func($this->afterRow, $model, $key, $index, $this);
if (!empty($row)) {
$rows[] = $row;
}
}
}
if (empty($rows) && $this->emptyText !== false) {
$colspan = count($this->columns);
return "<tbody>\n<tr><td colspan=\"$colspan\">" . $this->renderEmpty() . "</td></tr>\n</tbody>";
}
return "<tbody>\n" . implode("\n", $rows) . "\n</tbody>";
}
|
php
|
{
"resource": ""
}
|
q241610
|
ViewFinderTrait.getViewNames
|
validation
|
public function getViewNames($schema = '', $refresh = false)
{
if (!isset($this->_viewNames[$schema]) || $refresh) {
$this->_viewNames[$schema] = $this->findViewNames($schema);
}
return $this->_viewNames[$schema];
}
|
php
|
{
"resource": ""
}
|
q241611
|
QueryTrait.isEmpty
|
validation
|
protected function isEmpty($value)
{
return $value === '' || $value === [] || $value === null || is_string($value) && trim($value) === '';
}
|
php
|
{
"resource": ""
}
|
q241612
|
Controller.isColorEnabled
|
validation
|
public function isColorEnabled($stream = \STDOUT)
{
return $this->color === null ? Console::streamSupportsAnsiColors($stream) : $this->color;
}
|
php
|
{
"resource": ""
}
|
q241613
|
Controller.stderr
|
validation
|
public function stderr($string)
{
if ($this->isColorEnabled(\STDERR)) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args);
}
return fwrite(\STDERR, $string);
}
|
php
|
{
"resource": ""
}
|
q241614
|
Controller.getOptionValues
|
validation
|
public function getOptionValues($actionID)
{
// $actionId might be used in subclasses to provide properties specific to action id
$properties = [];
foreach ($this->options($this->action->id) as $property) {
$properties[$property] = $this->$property;
}
return $properties;
}
|
php
|
{
"resource": ""
}
|
q241615
|
Controller.getPassedOptionValues
|
validation
|
public function getPassedOptionValues()
{
$properties = [];
foreach ($this->_passedOptions as $property) {
$properties[$property] = $this->$property;
}
return $properties;
}
|
php
|
{
"resource": ""
}
|
q241616
|
Controller.getActionArgsHelp
|
validation
|
public function getActionArgsHelp($action)
{
$method = $this->getActionMethodReflection($action);
$tags = $this->parseDocCommentTags($method);
$params = isset($tags['param']) ? (array) $tags['param'] : [];
$args = [];
/** @var \ReflectionParameter $reflection */
foreach ($method->getParameters() as $i => $reflection) {
if ($reflection->getClass() !== null) {
continue;
}
$name = $reflection->getName();
$tag = isset($params[$i]) ? $params[$i] : '';
if (preg_match('/^(\S+)\s+(\$\w+\s+)?(.*)/s', $tag, $matches)) {
$type = $matches[1];
$comment = $matches[3];
} else {
$type = null;
$comment = $tag;
}
if ($reflection->isDefaultValueAvailable()) {
$args[$name] = [
'required' => false,
'type' => $type,
'default' => $reflection->getDefaultValue(),
'comment' => $comment,
];
} else {
$args[$name] = [
'required' => true,
'type' => $type,
'default' => null,
'comment' => $comment,
];
}
}
return $args;
}
|
php
|
{
"resource": ""
}
|
q241617
|
Controller.parseDocCommentDetail
|
validation
|
protected function parseDocCommentDetail($reflection)
{
$comment = strtr(trim(preg_replace('/^\s*\**( |\t)?/m', '', trim($reflection->getDocComment(), '/'))), "\r", '');
if (preg_match('/^\s*@\w+/m', $comment, $matches, PREG_OFFSET_CAPTURE)) {
$comment = trim(substr($comment, 0, $matches[0][1]));
}
if ($comment !== '') {
return rtrim(Console::renderColoredString(Console::markdownToAnsi($comment)));
}
return '';
}
|
php
|
{
"resource": ""
}
|
q241618
|
MultipartFormDataParser.getByteSize
|
validation
|
private function getByteSize($verboseSize)
{
if (empty($verboseSize)) {
return 0;
}
if (is_numeric($verboseSize)) {
return (int) $verboseSize;
}
$sizeUnit = trim($verboseSize, '0123456789');
$size = trim(str_replace($sizeUnit, '', $verboseSize));
if (!is_numeric($size)) {
return 0;
}
switch (strtolower($sizeUnit)) {
case 'kb':
case 'k':
return $size * 1024;
case 'mb':
case 'm':
return $size * 1024 * 1024;
case 'gb':
case 'g':
return $size * 1024 * 1024 * 1024;
default:
return 0;
}
}
|
php
|
{
"resource": ""
}
|
q241619
|
ErrorHandler.renderException
|
validation
|
protected function renderException($exception)
{
if (Yii::$app->has('response')) {
$response = Yii::$app->getResponse();
// reset parameters of response to avoid interference with partially created response data
// in case the error occurred while sending the response.
$response->isSent = false;
$response->stream = null;
$response->data = null;
$response->content = null;
} else {
$response = new Response();
}
$response->setStatusCodeByException($exception);
$useErrorView = $response->format === Response::FORMAT_HTML && (!YII_DEBUG || $exception instanceof UserException);
if ($useErrorView && $this->errorAction !== null) {
$result = Yii::$app->runAction($this->errorAction);
if ($result instanceof Response) {
$response = $result;
} else {
$response->data = $result;
}
} elseif ($response->format === Response::FORMAT_HTML) {
if ($this->shouldRenderSimpleHtml()) {
// AJAX request
$response->data = '<pre>' . $this->htmlEncode(static::convertExceptionToString($exception)) . '</pre>';
} else {
// if there is an error during error rendering it's useful to
// display PHP error in debug mode instead of a blank screen
if (YII_DEBUG) {
ini_set('display_errors', 1);
}
$file = $useErrorView ? $this->errorView : $this->exceptionView;
$response->data = $this->renderFile($file, [
'exception' => $exception,
]);
}
} elseif ($response->format === Response::FORMAT_RAW) {
$response->data = static::convertExceptionToString($exception);
} else {
$response->data = $this->convertExceptionToArray($exception);
}
$response->send();
}
|
php
|
{
"resource": ""
}
|
q241620
|
ErrorHandler.renderCallStackItem
|
validation
|
public function renderCallStackItem($file, $line, $class, $method, $args, $index)
{
$lines = [];
$begin = $end = 0;
if ($file !== null && $line !== null) {
$line--; // adjust line number from one-based to zero-based
$lines = @file($file);
if ($line < 0 || $lines === false || ($lineCount = count($lines)) < $line) {
return '';
}
$half = (int) (($index === 1 ? $this->maxSourceLines : $this->maxTraceSourceLines) / 2);
$begin = $line - $half > 0 ? $line - $half : 0;
$end = $line + $half < $lineCount ? $line + $half : $lineCount - 1;
}
return $this->renderFile($this->callStackItemView, [
'file' => $file,
'line' => $line,
'class' => $class,
'method' => $method,
'index' => $index,
'lines' => $lines,
'begin' => $begin,
'end' => $end,
'args' => $args,
]);
}
|
php
|
{
"resource": ""
}
|
q241621
|
ErrorHandler.renderCallStack
|
validation
|
public function renderCallStack($exception)
{
$out = '<ul>';
$out .= $this->renderCallStackItem($exception->getFile(), $exception->getLine(), null, null, [], 1);
for ($i = 0, $trace = $exception->getTrace(), $length = count($trace); $i < $length; ++$i) {
$file = !empty($trace[$i]['file']) ? $trace[$i]['file'] : null;
$line = !empty($trace[$i]['line']) ? $trace[$i]['line'] : null;
$class = !empty($trace[$i]['class']) ? $trace[$i]['class'] : null;
$function = null;
if (!empty($trace[$i]['function']) && $trace[$i]['function'] !== 'unknown') {
$function = $trace[$i]['function'];
}
$args = !empty($trace[$i]['args']) ? $trace[$i]['args'] : [];
$out .= $this->renderCallStackItem($file, $line, $class, $function, $args, $i + 2);
}
$out .= '</ul>';
return $out;
}
|
php
|
{
"resource": ""
}
|
q241622
|
ErrorHandler.createServerInformationLink
|
validation
|
public function createServerInformationLink()
{
$serverUrls = [
'http://httpd.apache.org/' => ['apache'],
'http://nginx.org/' => ['nginx'],
'http://lighttpd.net/' => ['lighttpd'],
'http://gwan.com/' => ['g-wan', 'gwan'],
'http://iis.net/' => ['iis', 'services'],
'https://secure.php.net/manual/en/features.commandline.webserver.php' => ['development'],
];
if (isset($_SERVER['SERVER_SOFTWARE'])) {
foreach ($serverUrls as $url => $keywords) {
foreach ($keywords as $keyword) {
if (stripos($_SERVER['SERVER_SOFTWARE'], $keyword) !== false) {
return '<a href="' . $url . '" target="_blank">' . $this->htmlEncode($_SERVER['SERVER_SOFTWARE']) . '</a>';
}
}
}
}
return '';
}
|
php
|
{
"resource": ""
}
|
q241623
|
ErrorHandler.argumentsToString
|
validation
|
public function argumentsToString($args)
{
$count = 0;
$isAssoc = $args !== array_values($args);
foreach ($args as $key => $value) {
$count++;
if ($count >= 5) {
if ($count > 5) {
unset($args[$key]);
} else {
$args[$key] = '...';
}
continue;
}
if (is_object($value)) {
$args[$key] = '<span class="title">' . $this->htmlEncode(get_class($value)) . '</span>';
} elseif (is_bool($value)) {
$args[$key] = '<span class="keyword">' . ($value ? 'true' : 'false') . '</span>';
} elseif (is_string($value)) {
$fullValue = $this->htmlEncode($value);
if (mb_strlen($value, 'UTF-8') > 32) {
$displayValue = $this->htmlEncode(mb_substr($value, 0, 32, 'UTF-8')) . '...';
$args[$key] = "<span class=\"string\" title=\"$fullValue\">'$displayValue'</span>";
} else {
$args[$key] = "<span class=\"string\">'$fullValue'</span>";
}
} elseif (is_array($value)) {
$args[$key] = '[' . $this->argumentsToString($value) . ']';
} elseif ($value === null) {
$args[$key] = '<span class="keyword">null</span>';
} elseif (is_resource($value)) {
$args[$key] = '<span class="keyword">resource</span>';
} else {
$args[$key] = '<span class="number">' . $value . '</span>';
}
if (is_string($key)) {
$args[$key] = '<span class="string">\'' . $this->htmlEncode($key) . "'</span> => $args[$key]";
} elseif ($isAssoc) {
$args[$key] = "<span class=\"number\">$key</span> => $args[$key]";
}
}
return implode(', ', $args);
}
|
php
|
{
"resource": ""
}
|
q241624
|
ErrorHandler.getExceptionName
|
validation
|
public function getExceptionName($exception)
{
if ($exception instanceof \yii\base\Exception || $exception instanceof \yii\base\InvalidCallException || $exception instanceof \yii\base\InvalidParamException || $exception instanceof \yii\base\UnknownMethodException) {
return $exception->getName();
}
return null;
}
|
php
|
{
"resource": ""
}
|
q241625
|
ImageValidator.validateImage
|
validation
|
protected function validateImage($image)
{
if (false === ($imageInfo = getimagesize($image->tempName))) {
return [$this->notImage, ['file' => $image->name]];
}
list($width, $height) = $imageInfo;
if ($width == 0 || $height == 0) {
return [$this->notImage, ['file' => $image->name]];
}
if ($this->minWidth !== null && $width < $this->minWidth) {
return [$this->underWidth, ['file' => $image->name, 'limit' => $this->minWidth]];
}
if ($this->minHeight !== null && $height < $this->minHeight) {
return [$this->underHeight, ['file' => $image->name, 'limit' => $this->minHeight]];
}
if ($this->maxWidth !== null && $width > $this->maxWidth) {
return [$this->overWidth, ['file' => $image->name, 'limit' => $this->maxWidth]];
}
if ($this->maxHeight !== null && $height > $this->maxHeight) {
return [$this->overHeight, ['file' => $image->name, 'limit' => $this->maxHeight]];
}
return null;
}
|
php
|
{
"resource": ""
}
|
q241626
|
Sort.getOrders
|
validation
|
public function getOrders($recalculate = false)
{
$attributeOrders = $this->getAttributeOrders($recalculate);
$orders = [];
foreach ($attributeOrders as $attribute => $direction) {
$definition = $this->attributes[$attribute];
$columns = $definition[$direction === SORT_ASC ? 'asc' : 'desc'];
if (is_array($columns) || $columns instanceof \Traversable) {
foreach ($columns as $name => $dir) {
$orders[$name] = $dir;
}
} else {
$orders[] = $columns;
}
}
return $orders;
}
|
php
|
{
"resource": ""
}
|
q241627
|
Sort.getAttributeOrders
|
validation
|
public function getAttributeOrders($recalculate = false)
{
if ($this->_attributeOrders === null || $recalculate) {
$this->_attributeOrders = [];
if (($params = $this->params) === null) {
$request = Yii::$app->getRequest();
$params = $request instanceof Request ? $request->getQueryParams() : [];
}
if (isset($params[$this->sortParam])) {
foreach ($this->parseSortParam($params[$this->sortParam]) as $attribute) {
$descending = false;
if (strncmp($attribute, '-', 1) === 0) {
$descending = true;
$attribute = substr($attribute, 1);
}
if (isset($this->attributes[$attribute])) {
$this->_attributeOrders[$attribute] = $descending ? SORT_DESC : SORT_ASC;
if (!$this->enableMultiSort) {
return $this->_attributeOrders;
}
}
}
}
if (empty($this->_attributeOrders) && is_array($this->defaultOrder)) {
$this->_attributeOrders = $this->defaultOrder;
}
}
return $this->_attributeOrders;
}
|
php
|
{
"resource": ""
}
|
q241628
|
Sort.setAttributeOrders
|
validation
|
public function setAttributeOrders($attributeOrders, $validate = true)
{
if ($attributeOrders === null || !$validate) {
$this->_attributeOrders = $attributeOrders;
} else {
$this->_attributeOrders = [];
foreach ($attributeOrders as $attribute => $order) {
if (isset($this->attributes[$attribute])) {
$this->_attributeOrders[$attribute] = $order;
if (!$this->enableMultiSort) {
break;
}
}
}
}
}
|
php
|
{
"resource": ""
}
|
q241629
|
Sort.getAttributeOrder
|
validation
|
public function getAttributeOrder($attribute)
{
$orders = $this->getAttributeOrders();
return isset($orders[$attribute]) ? $orders[$attribute] : null;
}
|
php
|
{
"resource": ""
}
|
q241630
|
Sort.link
|
validation
|
public function link($attribute, $options = [])
{
if (($direction = $this->getAttributeOrder($attribute)) !== null) {
$class = $direction === SORT_DESC ? 'desc' : 'asc';
if (isset($options['class'])) {
$options['class'] .= ' ' . $class;
} else {
$options['class'] = $class;
}
}
$url = $this->createUrl($attribute);
$options['data-sort'] = $this->createSortParam($attribute);
if (isset($options['label'])) {
$label = $options['label'];
unset($options['label']);
} else {
if (isset($this->attributes[$attribute]['label'])) {
$label = $this->attributes[$attribute]['label'];
} else {
$label = Inflector::camel2words($attribute);
}
}
return Html::a($label, $url, $options);
}
|
php
|
{
"resource": ""
}
|
q241631
|
ActiveRecord.loadDefaultValues
|
validation
|
public function loadDefaultValues($skipIfSet = true)
{
foreach (static::getTableSchema()->columns as $column) {
if ($column->defaultValue !== null && (!$skipIfSet || $this->{$column->name} === null)) {
$this->{$column->name} = $column->defaultValue;
}
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q241632
|
ActiveRecord.filterValidAliases
|
validation
|
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));
}
|
php
|
{
"resource": ""
}
|
q241633
|
ActiveRecord.filterCondition
|
validation
|
protected static function filterCondition(array $condition, array $aliases = [])
{
$result = [];
$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;
}
|
php
|
{
"resource": ""
}
|
q241634
|
ActiveRecord.filterValidColumnNames
|
validation
|
protected static function filterValidColumnNames($db, array $aliases)
{
$columnNames = [];
$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;
}
|
php
|
{
"resource": ""
}
|
q241635
|
ActiveRecord.updateAll
|
validation
|
public static function updateAll($attributes, $condition = '', $params = [])
{
$command = static::getDb()->createCommand();
$command->update(static::tableName(), $attributes, $condition, $params);
return $command->execute();
}
|
php
|
{
"resource": ""
}
|
q241636
|
ActiveRecord.updateAllCounters
|
validation
|
public static function updateAllCounters($counters, $condition = '', $params = [])
{
$n = 0;
foreach ($counters as $name => $value) {
$counters[$name] = new Expression("[[$name]]+:bp{$n}", [":bp{$n}" => $value]);
$n++;
}
$command = static::getDb()->createCommand();
$command->update(static::tableName(), $counters, $condition, $params);
return $command->execute();
}
|
php
|
{
"resource": ""
}
|
q241637
|
ActiveRecord.deleteAll
|
validation
|
public static function deleteAll($condition = null, $params = [])
{
$command = static::getDb()->createCommand();
$command->delete(static::tableName(), $condition, $params);
return $command->execute();
}
|
php
|
{
"resource": ""
}
|
q241638
|
ActiveRecord.getTableSchema
|
validation
|
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;
}
|
php
|
{
"resource": ""
}
|
q241639
|
ActiveRecord.delete
|
validation
|
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;
}
}
|
php
|
{
"resource": ""
}
|
q241640
|
ActiveRecord.deleteInternal
|
validation
|
protected function deleteInternal()
{
if (!$this->beforeDelete()) {
return false;
}
// we do not check the return value of deleteAll() because it's possible
// the record is already deleted in the database and thus the method will return 0
$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;
}
|
php
|
{
"resource": ""
}
|
q241641
|
BaseMarkdown.process
|
validation
|
public static function process($markdown, $flavor = null)
{
$parser = static::getParser($flavor);
return $parser->parse($markdown);
}
|
php
|
{
"resource": ""
}
|
q241642
|
BaseMarkdown.processParagraph
|
validation
|
public static function processParagraph($markdown, $flavor = null)
{
$parser = static::getParser($flavor);
return $parser->parseParagraph($markdown);
}
|
php
|
{
"resource": ""
}
|
q241643
|
BaseHtmlPurifier.process
|
validation
|
public static function process($content, $config = null)
{
$configInstance = \HTMLPurifier_Config::create($config instanceof \Closure ? null : $config);
$configInstance->autoFinalize = false;
$purifier = \HTMLPurifier::instance($configInstance);
$purifier->config->set('Cache.SerializerPath', \Yii::$app->getRuntimePath());
$purifier->config->set('Cache.SerializerPermissions', 0775);
static::configure($configInstance);
if ($config instanceof \Closure) {
call_user_func($config, $configInstance);
}
return $purifier->purify($content);
}
|
php
|
{
"resource": ""
}
|
q241644
|
Cors.overrideDefaultSettings
|
validation
|
public function overrideDefaultSettings($action)
{
if (isset($this->actions[$action->id])) {
$actionParams = $this->actions[$action->id];
$actionParamsKeys = array_keys($actionParams);
foreach ($this->cors as $headerField => $headerValue) {
if (in_array($headerField, $actionParamsKeys)) {
$this->cors[$headerField] = $actionParams[$headerField];
}
}
}
}
|
php
|
{
"resource": ""
}
|
q241645
|
Cors.prepareHeaders
|
validation
|
public function prepareHeaders($requestHeaders)
{
$responseHeaders = [];
// handle Origin
if (isset($requestHeaders['Origin'], $this->cors['Origin'])) {
if (in_array($requestHeaders['Origin'], $this->cors['Origin'], true)) {
$responseHeaders['Access-Control-Allow-Origin'] = $requestHeaders['Origin'];
}
if (in_array('*', $this->cors['Origin'], true)) {
// Per CORS standard (https://fetch.spec.whatwg.org), wildcard origins shouldn't be used together with credentials
if (isset($this->cors['Access-Control-Allow-Credentials']) && $this->cors['Access-Control-Allow-Credentials']) {
if (YII_DEBUG) {
throw new InvalidConfigException("Allowing credentials for wildcard origins is insecure. Please specify more restrictive origins or set 'credentials' to false in your CORS configuration.");
} else {
Yii::error("Allowing credentials for wildcard origins is insecure. Please specify more restrictive origins or set 'credentials' to false in your CORS configuration.", __METHOD__);
}
} else {
$responseHeaders['Access-Control-Allow-Origin'] = '*';
}
}
}
$this->prepareAllowHeaders('Headers', $requestHeaders, $responseHeaders);
if (isset($requestHeaders['Access-Control-Request-Method'])) {
$responseHeaders['Access-Control-Allow-Methods'] = implode(', ', $this->cors['Access-Control-Request-Method']);
}
if (isset($this->cors['Access-Control-Allow-Credentials'])) {
$responseHeaders['Access-Control-Allow-Credentials'] = $this->cors['Access-Control-Allow-Credentials'] ? 'true' : 'false';
}
if (isset($this->cors['Access-Control-Max-Age']) && $this->request->getIsOptions()) {
$responseHeaders['Access-Control-Max-Age'] = $this->cors['Access-Control-Max-Age'];
}
if (isset($this->cors['Access-Control-Expose-Headers'])) {
$responseHeaders['Access-Control-Expose-Headers'] = implode(', ', $this->cors['Access-Control-Expose-Headers']);
}
if (isset($this->cors['Access-Control-Allow-Headers'])) {
$responseHeaders['Access-Control-Allow-Headers'] = implode(', ', $this->cors['Access-Control-Allow-Headers']);
}
return $responseHeaders;
}
|
php
|
{
"resource": ""
}
|
q241646
|
Cors.addCorsHeaders
|
validation
|
public function addCorsHeaders($response, $headers)
{
if (empty($headers) === false) {
$responseHeaders = $response->getHeaders();
foreach ($headers as $field => $value) {
$responseHeaders->set($field, $value);
}
}
}
|
php
|
{
"resource": ""
}
|
q241647
|
Request.getIsFlash
|
validation
|
public function getIsFlash()
{
$userAgent = $this->headers->get('User-Agent', '');
return stripos($userAgent, 'Shockwave') !== false
|| stripos($userAgent, 'Flash') !== false;
}
|
php
|
{
"resource": ""
}
|
q241648
|
Request.getBodyParams
|
validation
|
public function getBodyParams()
{
if ($this->_bodyParams === null) {
if (isset($_POST[$this->methodParam])) {
$this->_bodyParams = $_POST;
unset($this->_bodyParams[$this->methodParam]);
return $this->_bodyParams;
}
$rawContentType = $this->getContentType();
if (($pos = strpos($rawContentType, ';')) !== false) {
// e.g. text/html; charset=UTF-8
$contentType = substr($rawContentType, 0, $pos);
} else {
$contentType = $rawContentType;
}
if (isset($this->parsers[$contentType])) {
$parser = Yii::createObject($this->parsers[$contentType]);
if (!($parser instanceof RequestParserInterface)) {
throw new InvalidConfigException("The '$contentType' request parser is invalid. It must implement the yii\\web\\RequestParserInterface.");
}
$this->_bodyParams = $parser->parse($this->getRawBody(), $rawContentType);
} elseif (isset($this->parsers['*'])) {
$parser = Yii::createObject($this->parsers['*']);
if (!($parser instanceof RequestParserInterface)) {
throw new InvalidConfigException('The fallback request parser is invalid. It must implement the yii\\web\\RequestParserInterface.');
}
$this->_bodyParams = $parser->parse($this->getRawBody(), $rawContentType);
} elseif ($this->getMethod() === 'POST') {
// PHP has already parsed the body so we have all params in $_POST
$this->_bodyParams = $_POST;
} else {
$this->_bodyParams = [];
mb_parse_str($this->getRawBody(), $this->_bodyParams);
}
}
return $this->_bodyParams;
}
|
php
|
{
"resource": ""
}
|
q241649
|
Request.get
|
validation
|
public function get($name = null, $defaultValue = null)
{
if ($name === null) {
return $this->getQueryParams();
}
return $this->getQueryParam($name, $defaultValue);
}
|
php
|
{
"resource": ""
}
|
q241650
|
Request.getHostInfo
|
validation
|
public function getHostInfo()
{
if ($this->_hostInfo === null) {
$secure = $this->getIsSecureConnection();
$http = $secure ? 'https' : 'http';
if ($this->headers->has('X-Forwarded-Host')) {
$this->_hostInfo = $http . '://' . trim(explode(',', $this->headers->get('X-Forwarded-Host'))[0]);
} elseif ($this->headers->has('Host')) {
$this->_hostInfo = $http . '://' . $this->headers->get('Host');
} elseif (isset($_SERVER['SERVER_NAME'])) {
$this->_hostInfo = $http . '://' . $_SERVER['SERVER_NAME'];
$port = $secure ? $this->getSecurePort() : $this->getPort();
if (($port !== 80 && !$secure) || ($port !== 443 && $secure)) {
$this->_hostInfo .= ':' . $port;
}
}
}
return $this->_hostInfo;
}
|
php
|
{
"resource": ""
}
|
q241651
|
Request.setHostInfo
|
validation
|
public function setHostInfo($value)
{
$this->_hostName = null;
$this->_hostInfo = $value === null ? null : rtrim($value, '/');
}
|
php
|
{
"resource": ""
}
|
q241652
|
Request.utf8Encode
|
validation
|
private function utf8Encode($s)
{
$s .= $s;
$len = \strlen($s);
for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
switch (true) {
case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
default: $s[$j] = "\xC3"; $s[++$j] = \chr(\ord($s[$i]) - 64); break;
}
}
return substr($s, 0, $j);
}
|
php
|
{
"resource": ""
}
|
q241653
|
Request.getPort
|
validation
|
public function getPort()
{
if ($this->_port === null) {
$serverPort = $this->getServerPort();
$this->_port = !$this->getIsSecureConnection() && $serverPort !== null ? $serverPort : 80;
}
return $this->_port;
}
|
php
|
{
"resource": ""
}
|
q241654
|
Request.setPort
|
validation
|
public function setPort($value)
{
if ($value != $this->_port) {
$this->_port = (int) $value;
$this->_hostInfo = null;
}
}
|
php
|
{
"resource": ""
}
|
q241655
|
Request.setSecurePort
|
validation
|
public function setSecurePort($value)
{
if ($value != $this->_securePort) {
$this->_securePort = (int) $value;
$this->_hostInfo = null;
}
}
|
php
|
{
"resource": ""
}
|
q241656
|
Request.getAcceptableContentTypes
|
validation
|
public function getAcceptableContentTypes()
{
if ($this->_contentTypes === null) {
if ($this->headers->get('Accept') !== null) {
$this->_contentTypes = $this->parseAcceptHeader($this->headers->get('Accept'));
} else {
$this->_contentTypes = [];
}
}
return $this->_contentTypes;
}
|
php
|
{
"resource": ""
}
|
q241657
|
Request.getAcceptableLanguages
|
validation
|
public function getAcceptableLanguages()
{
if ($this->_languages === null) {
if ($this->headers->has('Accept-Language')) {
$this->_languages = array_keys($this->parseAcceptHeader($this->headers->get('Accept-Language')));
} else {
$this->_languages = [];
}
}
return $this->_languages;
}
|
php
|
{
"resource": ""
}
|
q241658
|
Request.getETags
|
validation
|
public function getETags()
{
if ($this->headers->has('If-None-Match')) {
return preg_split('/[\s,]+/', str_replace('-gzip', '', $this->headers->get('If-None-Match')), -1, PREG_SPLIT_NO_EMPTY);
}
return [];
}
|
php
|
{
"resource": ""
}
|
q241659
|
Request.getCookies
|
validation
|
public function getCookies()
{
if ($this->_cookies === null) {
$this->_cookies = new CookieCollection($this->loadCookies(), [
'readOnly' => true,
]);
}
return $this->_cookies;
}
|
php
|
{
"resource": ""
}
|
q241660
|
Request.validateCsrfTokenInternal
|
validation
|
private function validateCsrfTokenInternal($clientSuppliedToken, $trueToken)
{
if (!is_string($clientSuppliedToken)) {
return false;
}
$security = Yii::$app->security;
return $security->compareString($security->unmaskToken($clientSuppliedToken), $security->unmaskToken($trueToken));
}
|
php
|
{
"resource": ""
}
|
q241661
|
Block.run
|
validation
|
public function run()
{
$block = ob_get_clean();
if ($this->renderInPlace) {
echo $block;
}
$this->view->blocks[$this->getId()] = $block;
}
|
php
|
{
"resource": ""
}
|
q241662
|
OracleMutex.init
|
validation
|
public function init()
{
parent::init();
if (strncmp($this->db->driverName, 'oci', 3) !== 0 && strncmp($this->db->driverName, 'odbc', 4) !== 0) {
throw new InvalidConfigException('In order to use OracleMutex connection must be configured to use Oracle database.');
}
}
|
php
|
{
"resource": ""
}
|
q241663
|
ActiveField.begin
|
validation
|
public function begin()
{
if ($this->form->enableClientScript) {
$clientOptions = $this->getClientOptions();
if (!empty($clientOptions)) {
$this->form->attributes[] = $clientOptions;
}
}
$inputID = $this->getInputId();
$attribute = Html::getAttributeName($this->attribute);
$options = $this->options;
$class = isset($options['class']) ? (array) $options['class'] : [];
$class[] = "field-$inputID";
if ($this->model->isAttributeRequired($attribute)) {
$class[] = $this->form->requiredCssClass;
}
$options['class'] = implode(' ', $class);
if ($this->form->validationStateOn === ActiveForm::VALIDATION_STATE_ON_CONTAINER) {
$this->addErrorClassIfNeeded($options);
}
$tag = ArrayHelper::remove($options, 'tag', 'div');
return Html::beginTag($tag, $options);
}
|
php
|
{
"resource": ""
}
|
q241664
|
ActiveField.hiddenInput
|
validation
|
public function hiddenInput($options = [])
{
$options = array_merge($this->inputOptions, $options);
$this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activeHiddenInput($this->model, $this->attribute, $options);
return $this;
}
|
php
|
{
"resource": ""
}
|
q241665
|
ActiveField.adjustLabelFor
|
validation
|
protected function adjustLabelFor($options)
{
if (!isset($options['id'])) {
return;
}
$this->_inputId = $options['id'];
if (!isset($this->labelOptions['for'])) {
$this->labelOptions['for'] = $options['id'];
}
}
|
php
|
{
"resource": ""
}
|
q241666
|
ActiveField.addErrorClassIfNeeded
|
validation
|
protected function addErrorClassIfNeeded(&$options)
{
// Get proper attribute name when attribute name is tabular.
$attributeName = Html::getAttributeName($this->attribute);
if ($this->model->hasErrors($attributeName)) {
Html::addCssClass($options, $this->form->errorCssClass);
}
}
|
php
|
{
"resource": ""
}
|
q241667
|
Module.getInstance
|
validation
|
public static function getInstance()
{
$class = get_called_class();
return isset(Yii::$app->loadedModules[$class]) ? Yii::$app->loadedModules[$class] : null;
}
|
php
|
{
"resource": ""
}
|
q241668
|
Module.setInstance
|
validation
|
public static function setInstance($instance)
{
if ($instance === null) {
unset(Yii::$app->loadedModules[get_called_class()]);
} else {
Yii::$app->loadedModules[get_class($instance)] = $instance;
}
}
|
php
|
{
"resource": ""
}
|
q241669
|
Module.init
|
validation
|
public function init()
{
if ($this->controllerNamespace === null) {
$class = get_class($this);
if (($pos = strrpos($class, '\\')) !== false) {
$this->controllerNamespace = substr($class, 0, $pos) . '\\controllers';
}
}
}
|
php
|
{
"resource": ""
}
|
q241670
|
Module.getUniqueId
|
validation
|
public function getUniqueId()
{
return $this->module ? ltrim($this->module->getUniqueId() . '/' . $this->id, '/') : $this->id;
}
|
php
|
{
"resource": ""
}
|
q241671
|
Module.getBasePath
|
validation
|
public function getBasePath()
{
if ($this->_basePath === null) {
$class = new \ReflectionClass($this);
$this->_basePath = dirname($class->getFileName());
}
return $this->_basePath;
}
|
php
|
{
"resource": ""
}
|
q241672
|
Module.getModule
|
validation
|
public function getModule($id, $load = true)
{
if (($pos = strpos($id, '/')) !== false) {
// sub-module
$module = $this->getModule(substr($id, 0, $pos));
return $module === null ? null : $module->getModule(substr($id, $pos + 1), $load);
}
if (isset($this->_modules[$id])) {
if ($this->_modules[$id] instanceof self) {
return $this->_modules[$id];
} elseif ($load) {
Yii::debug("Loading module: $id", __METHOD__);
/* @var $module Module */
$module = Yii::createObject($this->_modules[$id], [$id, $this]);
$module->setInstance($module);
return $this->_modules[$id] = $module;
}
}
return null;
}
|
php
|
{
"resource": ""
}
|
q241673
|
Module.getModules
|
validation
|
public function getModules($loadedOnly = false)
{
if ($loadedOnly) {
$modules = [];
foreach ($this->_modules as $module) {
if ($module instanceof self) {
$modules[] = $module;
}
}
return $modules;
}
return $this->_modules;
}
|
php
|
{
"resource": ""
}
|
q241674
|
Module.setModules
|
validation
|
public function setModules($modules)
{
foreach ($modules as $id => $module) {
$this->_modules[$id] = $module;
}
}
|
php
|
{
"resource": ""
}
|
q241675
|
Module.isIncorrectClassNameOrPrefix
|
validation
|
private function isIncorrectClassNameOrPrefix($className, $prefix)
{
if (!preg_match('%^[a-z][a-z0-9\\-_]*$%', $className)) {
return true;
}
if ($prefix !== '' && !preg_match('%^[a-z0-9_/]+$%i', $prefix)) {
return true;
}
return false;
}
|
php
|
{
"resource": ""
}
|
q241676
|
Module.beforeAction
|
validation
|
public function beforeAction($action)
{
$event = new ActionEvent($action);
$this->trigger(self::EVENT_BEFORE_ACTION, $event);
return $event->isValid;
}
|
php
|
{
"resource": ""
}
|
q241677
|
Module.afterAction
|
validation
|
public function afterAction($action, $result)
{
$event = new ActionEvent($action);
$event->result = $result;
$this->trigger(self::EVENT_AFTER_ACTION, $event);
return $event->result;
}
|
php
|
{
"resource": ""
}
|
q241678
|
CompareValidator.compareValues
|
validation
|
protected function compareValues($operator, $type, $value, $compareValue)
{
if ($type === self::TYPE_NUMBER) {
$value = (float) $value;
$compareValue = (float) $compareValue;
} else {
$value = (string) $value;
$compareValue = (string) $compareValue;
}
switch ($operator) {
case '==':
return $value == $compareValue;
case '===':
return $value === $compareValue;
case '!=':
return $value != $compareValue;
case '!==':
return $value !== $compareValue;
case '>':
return $value > $compareValue;
case '>=':
return $value >= $compareValue;
case '<':
return $value < $compareValue;
case '<=':
return $value <= $compareValue;
default:
return false;
}
}
|
php
|
{
"resource": ""
}
|
q241679
|
Component.__isset
|
validation
|
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
}
// behavior property
$this->ensureBehaviors();
foreach ($this->_behaviors as $behavior) {
if ($behavior->canGetProperty($name)) {
return $behavior->$name !== null;
}
}
return false;
}
|
php
|
{
"resource": ""
}
|
q241680
|
Component.hasProperty
|
validation
|
public function hasProperty($name, $checkVars = true, $checkBehaviors = true)
{
return $this->canGetProperty($name, $checkVars, $checkBehaviors) || $this->canSetProperty($name, false, $checkBehaviors);
}
|
php
|
{
"resource": ""
}
|
q241681
|
Component.canGetProperty
|
validation
|
public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)
{
if (method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name)) {
return true;
} elseif ($checkBehaviors) {
$this->ensureBehaviors();
foreach ($this->_behaviors as $behavior) {
if ($behavior->canGetProperty($name, $checkVars)) {
return true;
}
}
}
return false;
}
|
php
|
{
"resource": ""
}
|
q241682
|
Component.hasMethod
|
validation
|
public function hasMethod($name, $checkBehaviors = true)
{
if (method_exists($this, $name)) {
return true;
} elseif ($checkBehaviors) {
$this->ensureBehaviors();
foreach ($this->_behaviors as $behavior) {
if ($behavior->hasMethod($name)) {
return true;
}
}
}
return false;
}
|
php
|
{
"resource": ""
}
|
q241683
|
Component.hasEventHandlers
|
validation
|
public function hasEventHandlers($name)
{
$this->ensureBehaviors();
foreach ($this->_eventWildcards as $wildcard => $handlers) {
if (!empty($handlers) && StringHelper::matchWildcard($wildcard, $name)) {
return true;
}
}
return !empty($this->_events[$name]) || Event::hasHandlers($this, $name);
}
|
php
|
{
"resource": ""
}
|
q241684
|
Component.off
|
validation
|
public function off($name, $handler = null)
{
$this->ensureBehaviors();
if (empty($this->_events[$name]) && empty($this->_eventWildcards[$name])) {
return false;
}
if ($handler === null) {
unset($this->_events[$name], $this->_eventWildcards[$name]);
return true;
}
$removed = false;
// plain event names
if (isset($this->_events[$name])) {
foreach ($this->_events[$name] as $i => $event) {
if ($event[0] === $handler) {
unset($this->_events[$name][$i]);
$removed = true;
}
}
if ($removed) {
$this->_events[$name] = array_values($this->_events[$name]);
return $removed;
}
}
// wildcard event names
if (isset($this->_eventWildcards[$name])) {
foreach ($this->_eventWildcards[$name] as $i => $event) {
if ($event[0] === $handler) {
unset($this->_eventWildcards[$name][$i]);
$removed = true;
}
}
if ($removed) {
$this->_eventWildcards[$name] = array_values($this->_eventWildcards[$name]);
// remove empty wildcards to save future redundant regex checks:
if (empty($this->_eventWildcards[$name])) {
unset($this->_eventWildcards[$name]);
}
}
}
return $removed;
}
|
php
|
{
"resource": ""
}
|
q241685
|
Component.trigger
|
validation
|
public function trigger($name, Event $event = null)
{
$this->ensureBehaviors();
$eventHandlers = [];
foreach ($this->_eventWildcards as $wildcard => $handlers) {
if (StringHelper::matchWildcard($wildcard, $name)) {
$eventHandlers = array_merge($eventHandlers, $handlers);
}
}
if (!empty($this->_events[$name])) {
$eventHandlers = array_merge($eventHandlers, $this->_events[$name]);
}
if (!empty($eventHandlers)) {
if ($event === null) {
$event = new Event();
}
if ($event->sender === null) {
$event->sender = $this;
}
$event->handled = false;
$event->name = $name;
foreach ($eventHandlers as $handler) {
$event->data = $handler[1];
call_user_func($handler[0], $event);
// stop further handling if the event is handled
if ($event->handled) {
return;
}
}
}
// invoke class-level attached handlers
Event::trigger($this, $name, $event);
}
|
php
|
{
"resource": ""
}
|
q241686
|
Component.getBehavior
|
validation
|
public function getBehavior($name)
{
$this->ensureBehaviors();
return isset($this->_behaviors[$name]) ? $this->_behaviors[$name] : null;
}
|
php
|
{
"resource": ""
}
|
q241687
|
Component.detachBehaviors
|
validation
|
public function detachBehaviors()
{
$this->ensureBehaviors();
foreach ($this->_behaviors as $name => $behavior) {
$this->detachBehavior($name);
}
}
|
php
|
{
"resource": ""
}
|
q241688
|
Component.attachBehaviorInternal
|
validation
|
private function attachBehaviorInternal($name, $behavior)
{
if (!($behavior instanceof Behavior)) {
$behavior = Yii::createObject($behavior);
}
if (is_int($name)) {
$behavior->attach($this);
$this->_behaviors[] = $behavior;
} else {
if (isset($this->_behaviors[$name])) {
$this->_behaviors[$name]->detach();
}
$behavior->attach($this);
$this->_behaviors[$name] = $behavior;
}
return $behavior;
}
|
php
|
{
"resource": ""
}
|
q241689
|
LinkPager.renderPageButtons
|
validation
|
protected function renderPageButtons()
{
$pageCount = $this->pagination->getPageCount();
if ($pageCount < 2 && $this->hideOnSinglePage) {
return '';
}
$buttons = [];
$currentPage = $this->pagination->getPage();
// first page
$firstPageLabel = $this->firstPageLabel === true ? '1' : $this->firstPageLabel;
if ($firstPageLabel !== false) {
$buttons[] = $this->renderPageButton($firstPageLabel, 0, $this->firstPageCssClass, $currentPage <= 0, false);
}
// prev page
if ($this->prevPageLabel !== false) {
if (($page = $currentPage - 1) < 0) {
$page = 0;
}
$buttons[] = $this->renderPageButton($this->prevPageLabel, $page, $this->prevPageCssClass, $currentPage <= 0, false);
}
// internal pages
list($beginPage, $endPage) = $this->getPageRange();
for ($i = $beginPage; $i <= $endPage; ++$i) {
$buttons[] = $this->renderPageButton($i + 1, $i, null, $this->disableCurrentPageButton && $i == $currentPage, $i == $currentPage);
}
// next page
if ($this->nextPageLabel !== false) {
if (($page = $currentPage + 1) >= $pageCount - 1) {
$page = $pageCount - 1;
}
$buttons[] = $this->renderPageButton($this->nextPageLabel, $page, $this->nextPageCssClass, $currentPage >= $pageCount - 1, false);
}
// last page
$lastPageLabel = $this->lastPageLabel === true ? $pageCount : $this->lastPageLabel;
if ($lastPageLabel !== false) {
$buttons[] = $this->renderPageButton($lastPageLabel, $pageCount - 1, $this->lastPageCssClass, $currentPage >= $pageCount - 1, false);
}
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'ul');
return Html::tag($tag, implode("\n", $buttons), $options);
}
|
php
|
{
"resource": ""
}
|
q241690
|
FileCache.init
|
validation
|
public function init()
{
parent::init();
$this->cachePath = Yii::getAlias($this->cachePath);
if (!is_dir($this->cachePath)) {
FileHelper::createDirectory($this->cachePath, $this->dirMode, true);
}
}
|
php
|
{
"resource": ""
}
|
q241691
|
BaseJson.encode
|
validation
|
public static function encode($value, $options = 320)
{
$expressions = [];
$value = static::processData($value, $expressions, uniqid('', true));
set_error_handler(function () {
static::handleJsonError(JSON_ERROR_SYNTAX);
}, E_WARNING);
$json = json_encode($value, $options);
restore_error_handler();
static::handleJsonError(json_last_error());
return $expressions === [] ? $json : strtr($json, $expressions);
}
|
php
|
{
"resource": ""
}
|
q241692
|
QueryBuilder.prepareInsertSelectSubQuery
|
validation
|
protected function prepareInsertSelectSubQuery($columns, $schema, $params = [])
{
if (!is_array($columns->select) || empty($columns->select) || in_array('*', $columns->select)) {
throw new InvalidArgumentException('Expected select query object with enumerated (named) parameters');
}
list($values, $params) = $this->build($columns, $params);
$names = [];
$values = ' ' . $values;
foreach ($columns->select as $title => $field) {
if (is_string($title)) {
$names[] = $schema->quoteColumnName($title);
} elseif (preg_match('/^(.*?)(?i:\s+as\s+|\s+)([\w\-_\.]+)$/', $field, $matches)) {
$names[] = $schema->quoteColumnName($matches[2]);
} else {
$names[] = $schema->quoteColumnName($field);
}
}
return [$names, $values, $params];
}
|
php
|
{
"resource": ""
}
|
q241693
|
QueryBuilder.update
|
validation
|
public function update($table, $columns, $condition, &$params)
{
list($lines, $params) = $this->prepareUpdateSets($table, $columns, $params);
$sql = 'UPDATE ' . $this->db->quoteTableName($table) . ' SET ' . implode(', ', $lines);
$where = $this->buildWhere($condition, $params);
return $where === '' ? $sql : $sql . ' ' . $where;
}
|
php
|
{
"resource": ""
}
|
q241694
|
QueryBuilder.delete
|
validation
|
public function delete($table, $condition, &$params)
{
$sql = 'DELETE FROM ' . $this->db->quoteTableName($table);
$where = $this->buildWhere($condition, $params);
return $where === '' ? $sql : $sql . ' ' . $where;
}
|
php
|
{
"resource": ""
}
|
q241695
|
QueryBuilder.dropPrimaryKey
|
validation
|
public function dropPrimaryKey($name, $table)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
}
|
php
|
{
"resource": ""
}
|
q241696
|
QueryBuilder.dropColumn
|
validation
|
public function dropColumn($table, $column)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP COLUMN ' . $this->db->quoteColumnName($column);
}
|
php
|
{
"resource": ""
}
|
q241697
|
QueryBuilder.dropForeignKey
|
validation
|
public function dropForeignKey($name, $table)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
}
|
php
|
{
"resource": ""
}
|
q241698
|
QueryBuilder.dropUnique
|
validation
|
public function dropUnique($name, $table)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
}
|
php
|
{
"resource": ""
}
|
q241699
|
QueryBuilder.dropCheck
|
validation
|
public function dropCheck($name, $table)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
}
|
php
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.