_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q254600 | BaseBuilder.compileSelect | test | protected function compileSelect($select_override = false): string
{
// Write the "select" portion of the query
if ($select_override !== false)
{
$sql = $select_override;
}
else
{
$sql = ( ! $this->QBDistinct) ? 'SELECT ' : 'SELECT DISTINCT ';
if (empty($this->QBSelect))
{
$sql .= '*';
}
else
{
// Cycle through the "select" portion of the query and prep each column name.
// The reason we protect identifiers here rather than in the select() function
// is because until the user calls the from() function we don't know if there are aliases
foreach ($this->QBSelect as $key => $val)
{
$no_escape = $this->QBNoEscape[$key] ?? null;
$this->QBSelect[$key] = $this->db->protectIdentifiers($val, false, $no_escape);
}
$sql .= implode(', ', $this->QBSelect);
}
}
// Write the "FROM" portion of the query
if (! empty($this->QBFrom))
{
$sql .= "\nFROM " . $this->_fromTables();
}
// Write the "JOIN" portion of the query
if (! empty($this->QBJoin))
{
$sql .= "\n" . implode("\n", $this->QBJoin);
}
$sql .= $this->compileWhereHaving('QBWhere')
. $this->compileGroupBy()
. $this->compileWhereHaving('QBHaving')
. $this->compileOrderBy(); // ORDER BY
// LIMIT
if ($this->QBLimit)
{
return $this->_limit($sql . "\n");
}
return $sql;
} | php | {
"resource": ""
} |
q254601 | BaseBuilder.compileWhereHaving | test | protected function compileWhereHaving(string $qb_key): string
{
if (! empty($this->$qb_key))
{
for ($i = 0, $c = count($this->$qb_key); $i < $c; $i ++)
{
// Is this condition already compiled?
if (is_string($this->{$qb_key}[$i]))
{
continue;
}
elseif ($this->{$qb_key}[$i]['escape'] === false)
{
$this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition'];
continue;
}
// Split multiple conditions
$conditions = preg_split(
'/((?:^|\s+)AND\s+|(?:^|\s+)OR\s+)/i', $this->{$qb_key}[$i]['condition'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
for ($ci = 0, $cc = count($conditions); $ci < $cc; $ci ++)
{
if (($op = $this->getOperator($conditions[$ci])) === false
|| ! preg_match('/^(\(?)(.*)(' . preg_quote($op, '/') . ')\s*(.*(?<!\)))?(\)?)$/i', $conditions[$ci], $matches)
)
{
continue;
}
// $matches = array(
// 0 => '(test <= foo)', /* the whole thing */
// 1 => '(', /* optional */
// 2 => 'test', /* the field name */
// 3 => ' <= ', /* $op */
// 4 => 'foo', /* optional, if $op is e.g. 'IS NULL' */
// 5 => ')' /* optional */
// );
if (! empty($matches[4]))
{
$matches[4] = ' ' . $matches[4];
}
$conditions[$ci] = $matches[1] . $this->db->protectIdentifiers(trim($matches[2]))
. ' ' . trim($matches[3]) . $matches[4] . $matches[5];
}
$this->{$qb_key}[$i] = implode('', $conditions);
}
return ($qb_key === 'QBHaving' ? "\nHAVING " : "\nWHERE ")
. implode("\n", $this->$qb_key);
}
return '';
} | php | {
"resource": ""
} |
q254602 | BaseBuilder.compileGroupBy | test | protected function compileGroupBy(): string
{
if (! empty($this->QBGroupBy))
{
for ($i = 0, $c = count($this->QBGroupBy); $i < $c; $i ++)
{
// Is it already compiled?
if (is_string($this->QBGroupBy[$i]))
{
continue;
}
$this->QBGroupBy[$i] = ($this->QBGroupBy[$i]['escape'] === false ||
$this->isLiteral($this->QBGroupBy[$i]['field'])) ? $this->QBGroupBy[$i]['field'] : $this->db->protectIdentifiers($this->QBGroupBy[$i]['field']);
}
return "\nGROUP BY " . implode(', ', $this->QBGroupBy);
}
return '';
} | php | {
"resource": ""
} |
q254603 | BaseBuilder.compileOrderBy | test | protected function compileOrderBy(): string
{
if (is_array($this->QBOrderBy) && ! empty($this->QBOrderBy))
{
for ($i = 0, $c = count($this->QBOrderBy); $i < $c; $i ++)
{
if ($this->QBOrderBy[$i]['escape'] !== false && ! $this->isLiteral($this->QBOrderBy[$i]['field']))
{
$this->QBOrderBy[$i]['field'] = $this->db->protectIdentifiers($this->QBOrderBy[$i]['field']);
}
$this->QBOrderBy[$i] = $this->QBOrderBy[$i]['field'] . $this->QBOrderBy[$i]['direction'];
}
return $this->QBOrderBy = "\nORDER BY " . implode(', ', $this->QBOrderBy);
}
elseif (is_string($this->QBOrderBy))
{
return $this->QBOrderBy;
}
return '';
} | php | {
"resource": ""
} |
q254604 | BaseBuilder.getOperator | test | protected function getOperator(string $str, bool $list = false)
{
static $_operators;
if (empty($_operators))
{
$_les = ($this->db->likeEscapeStr !== '') ? '\s+' . preg_quote(trim(sprintf($this->db->likeEscapeStr, $this->db->likeEscapeChar)), '/') : '';
$_operators = [
'\s*(?:<|>|!)?=\s*', // =, <=, >=, !=
'\s*<>?\s*', // <, <>
'\s*>\s*', // >
'\s+IS NULL', // IS NULL
'\s+IS NOT NULL', // IS NOT NULL
'\s+EXISTS\s*\(.*\)', // EXISTS(sql)
'\s+NOT EXISTS\s*\(.*\)', // NOT EXISTS(sql)
'\s+BETWEEN\s+', // BETWEEN value AND value
'\s+IN\s*\(.*\)', // IN(list)
'\s+NOT IN\s*\(.*\)', // NOT IN (list)
'\s+LIKE\s+\S.*(' . $_les . ')?', // LIKE 'expr'[ ESCAPE '%s']
'\s+NOT LIKE\s+\S.*(' . $_les . ')?', // NOT LIKE 'expr'[ ESCAPE '%s']
];
}
return preg_match_all('/' . implode('|', $_operators) . '/i', $str, $match) ? ($list ? $match[0] : $match[0][count($match[0]) - 1]) : false;
} | php | {
"resource": ""
} |
q254605 | Toolbar.renderTimeline | test | protected function renderTimeline(array $collectors, $startTime, int $segmentCount, int $segmentDuration, array &$styles): string
{
$displayTime = $segmentCount * $segmentDuration;
$rows = $this->collectTimelineData($collectors);
$output = '';
$styleCount = 0;
foreach ($rows as $row)
{
$output .= '<tr>';
$output .= "<td>{$row['name']}</td>";
$output .= "<td>{$row['component']}</td>";
$output .= "<td class='debug-bar-alignRight'>" . number_format($row['duration'] * 1000, 2) . ' ms</td>';
$output .= "<td class='debug-bar-noverflow' colspan='{$segmentCount}'>";
$offset = ((($row['start'] - $startTime) * 1000) / $displayTime) * 100;
$length = (($row['duration'] * 1000) / $displayTime) * 100;
$styles['debug-bar-timeline-' . $styleCount] = "left: {$offset}%; width: {$length}%;";
$output .= "<span class='timer debug-bar-timeline-{$styleCount}' title='" . number_format($length, 2) . "%'></span>";
$output .= '</td>';
$output .= '</tr>';
$styleCount++;
}
return $output;
} | php | {
"resource": ""
} |
q254606 | Toolbar.collectTimelineData | test | protected function collectTimelineData($collectors): array
{
$data = [];
// Collect it
foreach ($collectors as $collector)
{
if (! $collector['hasTimelineData'])
{
continue;
}
$data = array_merge($data, $collector['timelineData']);
}
// Sort it
return $data;
} | php | {
"resource": ""
} |
q254607 | Toolbar.collectVarData | test | protected function collectVarData(): array
{
$data = [];
foreach ($this->collectors as $collector)
{
if (! $collector->hasVarData())
{
continue;
}
$data = array_merge($data, $collector->getVarData());
}
return $data;
} | php | {
"resource": ""
} |
q254608 | Toolbar.roundTo | test | protected function roundTo(float $number, int $increments = 5): float
{
$increments = 1 / $increments;
return (ceil($number * $increments) / $increments);
} | php | {
"resource": ""
} |
q254609 | Image.copy | test | public function copy(string $targetPath, string $targetName = null, int $perms = 0644): bool
{
$targetPath = rtrim($targetPath, '/ ') . '/';
$targetName = is_null($targetName) ? $this->getFilename() : $targetName;
if (empty($targetName))
{
throw ImageException::forInvalidFile($targetName);
}
if (! is_dir($targetPath))
{
mkdir($targetName, 0755, true);
}
if (! copy($this->getPathname(), "{$targetPath}{$targetName}"))
{
throw ImageException::forCopyError($targetPath);
}
chmod("{$targetPath}/{$targetName}", $perms);
return true;
} | php | {
"resource": ""
} |
q254610 | Image.getProperties | test | public function getProperties(bool $return = false)
{
$path = $this->getPathname();
$vals = getimagesize($path);
$types = [
1 => 'gif',
2 => 'jpeg',
3 => 'png',
];
$mime = 'image/' . ($types[$vals[2]] ?? 'jpg');
if ($return === true)
{
return [
'width' => $vals[0],
'height' => $vals[1],
'image_type' => $vals[2],
'size_str' => $vals[3],
'mime_type' => $mime,
];
}
$this->origWidth = $vals[0];
$this->origHeight = $vals[1];
$this->imageType = $vals[2];
$this->sizeStr = $vals[3];
$this->mime = $mime;
return true;
} | php | {
"resource": ""
} |
q254611 | DatabaseHandler.releaseLock | test | protected function releaseLock(): bool
{
if (! $this->lock)
{
return true;
}
if ($this->platform === 'mysql')
{
if ($this->db->query("SELECT RELEASE_LOCK('{$this->lock}') AS ci_session_lock")->getRow()->ci_session_lock)
{
$this->lock = false;
return true;
}
return $this->fail();
}
elseif ($this->platform === 'postgre')
{
if ($this->db->simpleQuery("SELECT pg_advisory_unlock({$this->lock})"))
{
$this->lock = false;
return true;
}
return $this->fail();
}
// Unsupported DB? Let the parent handle the simple version.
return parent::releaseLock();
} | php | {
"resource": ""
} |
q254612 | Honeypot.attachHoneypot | test | public function attachHoneypot(ResponseInterface $response)
{
$prep_field = $this->prepareTemplate($this->config->template);
$body = $response->getBody();
$body = str_ireplace('</form>', $prep_field, $body);
$response->setBody($body);
} | php | {
"resource": ""
} |
q254613 | Honeypot.prepareTemplate | test | protected function prepareTemplate(string $template): string
{
$template = str_ireplace('{label}', $this->config->label, $template);
$template = str_ireplace('{name}', $this->config->name, $template);
if ($this->config->hidden)
{
$template = '<div style="display:none">' . $template . '</div>';
}
return $template;
} | php | {
"resource": ""
} |
q254614 | Result.fetchObject | test | protected function fetchObject(string $className = 'stdClass')
{
// No native support for fetching rows as objects
if (($row = $this->fetchAssoc()) === false)
{
return false;
}
elseif ($className === 'stdClass')
{
return (object) $row;
}
$classObj = new $className();
$classSet = \Closure::bind(function ($key, $value) {
$this->$key = $value;
}, $classObj, $className
);
foreach (array_keys($row) as $key)
{
$classSet($key, $row[$key]);
}
return $classObj;
} | php | {
"resource": ""
} |
q254615 | Table.makeColumns | test | public function makeColumns($array = [], $columnLimit = 0)
{
if (! is_array($array) || count($array) === 0 || ! is_int($columnLimit))
{
return false;
}
// Turn off the auto-heading feature since it's doubtful we
// will want headings from a one-dimensional array
$this->autoHeading = false;
if ($columnLimit === 0)
{
return $array;
}
$new = [];
do
{
$temp = array_splice($array, 0, $columnLimit);
if (count($temp) < $columnLimit)
{
for ($i = count($temp); $i < $columnLimit; $i ++)
{
$temp[] = ' ';
}
}
$new[] = $temp;
}
while (count($array) > 0);
return $new;
} | php | {
"resource": ""
} |
q254616 | Table.clear | test | public function clear()
{
$this->rows = [];
$this->heading = [];
$this->footing = [];
$this->autoHeading = true;
$this->caption = null;
return $this;
} | php | {
"resource": ""
} |
q254617 | Table._setFromDBResult | test | protected function _setFromDBResult($object)
{
// First generate the headings from the table column names
if ($this->autoHeading === true && empty($this->heading))
{
$this->heading = $this->_prepArgs($object->getFieldNames());
}
foreach ($object->getResultArray() as $row)
{
$this->rows[] = $this->_prepArgs($row);
}
} | php | {
"resource": ""
} |
q254618 | Table._setFromArray | test | protected function _setFromArray($data)
{
if ($this->autoHeading === true && empty($this->heading))
{
$this->heading = $this->_prepArgs(array_shift($data));
}
foreach ($data as &$row)
{
$this->rows[] = $this->_prepArgs($row);
}
} | php | {
"resource": ""
} |
q254619 | UploadedFile.setPath | test | protected function setPath(string $path): string
{
if (! is_dir($path))
{
mkdir($path, 0777, true);
//create the index.html file
if (! is_file($path . 'index.html'))
{
$file = fopen($path . 'index.html', 'x+');
fclose($file);
}
}
return $path;
} | php | {
"resource": ""
} |
q254620 | UploadedFile.getErrorString | test | public function getErrorString(): string
{
$errors = [
UPLOAD_ERR_OK => lang('HTTP.uploadErrOk'),
UPLOAD_ERR_INI_SIZE => lang('HTTP.uploadErrIniSize'),
UPLOAD_ERR_FORM_SIZE => lang('HTTP.uploadErrFormSize'),
UPLOAD_ERR_PARTIAL => lang('HTTP.uploadErrPartial'),
UPLOAD_ERR_NO_FILE => lang('HTTP.uploadErrNoFile'),
UPLOAD_ERR_CANT_WRITE => lang('HTTP.uploadErrCantWrite'),
UPLOAD_ERR_NO_TMP_DIR => lang('HTTP.uploadErrNoTmpDir'),
UPLOAD_ERR_EXTENSION => lang('HTTP.uploadErrExtension'),
];
$error = is_null($this->error) ? UPLOAD_ERR_OK : $this->error;
return sprintf($errors[$error] ?? lang('HTTP.uploadErrUnknown'), $this->getName());
} | php | {
"resource": ""
} |
q254621 | UploadedFile.store | test | public function store(string $folderName = null, string $fileName = null): string
{
$folderName = $folderName ?? date('Ymd');
$fileName = $fileName ?? $this->getRandomName();
// Move the uploaded file to a new location.
return ($this->move(WRITEPATH . 'uploads/' . $folderName, $fileName)) ?
$folderName . DIRECTORY_SEPARATOR . $this->name : null;
} | php | {
"resource": ""
} |
q254622 | FileRules.max_size | test | public function max_size(string $blank = null, string $params, array $data): bool
{
// Grab the file name off the top of the $params
// after we split it.
$params = explode(',', $params);
$name = array_shift($params);
$file = $this->request->getFile($name);
if (is_null($file))
{
return false;
}
return $params[0] >= $file->getSize() / 1024;
} | php | {
"resource": ""
} |
q254623 | FileRules.is_image | test | public function is_image(string $blank = null, string $params, array $data): bool
{
// Grab the file name off the top of the $params
// after we split it.
$params = explode(',', $params);
$name = array_shift($params);
$file = $this->request->getFile($name);
if (is_null($file))
{
return false;
}
// We know that our mimes list always has the first mime
// start with `image` even when then are multiple accepted types.
$type = \Config\Mimes::guessTypeFromExtension($file->getExtension());
return mb_strpos($type, 'image') === 0;
} | php | {
"resource": ""
} |
q254624 | FileRules.mime_in | test | public function mime_in(string $blank = null, string $params, array $data): bool
{
// Grab the file name off the top of the $params
// after we split it.
$params = explode(',', $params);
$name = array_shift($params);
$file = $this->request->getFile($name);
if (is_null($file))
{
return false;
}
return in_array($file->getMimeType(), $params);
} | php | {
"resource": ""
} |
q254625 | FileRules.max_dims | test | public function max_dims(string $blank = null, string $params, array $data): bool
{
// Grab the file name off the top of the $params
// after we split it.
$params = explode(',', $params);
$name = array_shift($params);
$file = $this->request->getFile($name);
if (is_null($file))
{
return false;
}
// Get Parameter sizes
$allowedWidth = $params[0] ?? 0;
$allowedHeight = $params[1] ?? 0;
// Get uploaded image size
$info = getimagesize($file->getTempName());
$fileWidth = $info[0];
$fileHeight = $info[1];
return $fileWidth <= $allowedWidth && $fileHeight <= $allowedHeight;
} | php | {
"resource": ""
} |
q254626 | Request.fetchGlobal | test | public function fetchGlobal($method, $index = null, $filter = null, $flags = null)
{
$method = strtolower($method);
if (! isset($this->globals[$method]))
{
$this->populateGlobals($method);
}
// Null filters cause null values to return.
if (is_null($filter))
{
$filter = FILTER_DEFAULT;
}
// Return all values when $index is null
if (is_null($index))
{
$values = [];
foreach ($this->globals[$method] as $key => $value)
{
$values[$key] = is_array($value)
? $this->fetchGlobal($method, $key, $filter, $flags)
: filter_var($value, $filter, $flags);
}
return $values;
}
// allow fetching multiple keys at once
if (is_array($index))
{
$output = [];
foreach ($index as $key)
{
$output[$key] = $this->fetchGlobal($method, $key, $filter, $flags);
}
return $output;
}
// Does the index contain array notation?
if (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1)
{
$value = $this->globals[$method];
for ($i = 0; $i < $count; $i++)
{
$key = trim($matches[0][$i], '[]');
if ($key === '') // Empty notation will return the value as array
{
break;
}
if (isset($value[$key]))
{
$value = $value[$key];
}
else
{
return null;
}
}
}
if (! isset($value))
{
$value = $this->globals[$method][$index] ?? null;
}
// Cannot filter these types of data automatically...
if (is_array($value) || is_object($value) || is_null($value))
{
return $value;
}
return filter_var($value, $filter, $flags);
} | php | {
"resource": ""
} |
q254627 | Request.populateGlobals | test | protected function populateGlobals(string $method)
{
if (! isset($this->globals[$method]))
{
$this->globals[$method] = [];
}
// Don't populate ENV as it might contain
// sensitive data that we don't want to get logged.
switch($method)
{
case 'get':
$this->globals['get'] = $_GET;
break;
case 'post':
$this->globals['post'] = $_POST;
break;
case 'request':
$this->globals['request'] = $_REQUEST;
break;
case 'cookie':
$this->globals['cookie'] = $_COOKIE;
break;
case 'server':
$this->globals['server'] = $_SERVER;
break;
}
} | php | {
"resource": ""
} |
q254628 | MigrateVersion.run | test | public function run(array $params = [])
{
$runner = Services::migrations();
// Get the version number
$version = array_shift($params);
if (is_null($version))
{
$version = CLI::prompt(lang('Migrations.version'));
}
if (is_null($version))
{
CLI::error(lang('Migrations.invalidVersion'));
exit();
}
CLI::write(sprintf(lang('Migrations.toVersionPH'), $version), 'yellow');
$namespace = $params['-n'] ?? CLI::getOption('n');
$group = $params['-g'] ?? CLI::getOption('g');
try
{
$runner->version($version, $namespace, $group);
CLI::write('Done');
}
catch (\Exception $e)
{
$this->showError($e);
}
} | php | {
"resource": ""
} |
q254629 | Table.fromTable | test | public function fromTable(string $table)
{
$this->prefixedTableName = $table;
// Remove the prefix, if any, since it's
// already been added by the time we get here...
$prefix = $this->db->DBPrefix;
if (! empty($prefix))
{
if (strpos($table, $prefix) === 0)
{
$table = substr($table, strlen($prefix));
}
}
if (! $this->db->tableExists($this->prefixedTableName))
{
throw DataException::forTableNotFound($this->prefixedTableName);
}
$this->tableName = $table;
$this->fields = $this->formatFields($this->db->getFieldData($table));
$this->keys = array_merge($this->keys, $this->formatKeys($this->db->getIndexData($table)));
$this->foreignKeys = $this->db->getForeignKeyData($table);
return $this;
} | php | {
"resource": ""
} |
q254630 | Table.run | test | public function run(): bool
{
$this->db->query('PRAGMA foreign_keys = OFF');
$this->db->transStart();
$this->forge->renameTable($this->tableName, "temp_{$this->tableName}");
$this->forge->reset();
$this->createTable();
$this->copyData();
$this->forge->dropTable("temp_{$this->tableName}");
$success = $this->db->transComplete();
$this->db->query('PRAGMA foreign_keys = ON');
return $success;
} | php | {
"resource": ""
} |
q254631 | Table.modifyColumn | test | public function modifyColumn(array $field)
{
$field = $field[0];
$oldName = $field['name'];
unset($field['name']);
$this->fields[$oldName] = $field;
return $this;
} | php | {
"resource": ""
} |
q254632 | Table.createTable | test | protected function createTable()
{
$this->dropIndexes();
$this->db->resetDataCache();
// Handle any modified columns.
$fields = [];
foreach ($this->fields as $name => $field)
{
if (isset($field['new_name']))
{
$fields[$field['new_name']] = $field;
continue;
}
$fields[$name] = $field;
}
$this->forge->addField($fields);
// Unique/Index keys
if (is_array($this->keys))
{
foreach ($this->keys as $key)
{
switch ($key['type'])
{
case 'primary':
$this->forge->addPrimaryKey($key['fields']);
break;
case 'unique':
$this->forge->addUniqueKey($key['fields']);
break;
case 'index':
$this->forge->addKey($key['fields']);
break;
}
}
}
// Foreign Keys
return $this->forge->createTable($this->tableName);
} | php | {
"resource": ""
} |
q254633 | Table.copyData | test | protected function copyData()
{
$exFields = [];
$newFields = [];
foreach ($this->fields as $name => $details)
{
// Are we modifying the column?
if (isset($details['new_name']))
{
$newFields[] = $details['new_name'];
}
else
{
$newFields[] = $name;
}
$exFields[] = $name;
}
$exFields = implode(', ', $exFields);
$newFields = implode(', ', $newFields);
$this->db->query("INSERT INTO {$this->prefixedTableName}({$newFields}) SELECT {$exFields} FROM {$this->db->DBPrefix}temp_{$this->tableName}");
} | php | {
"resource": ""
} |
q254634 | Table.formatFields | test | protected function formatFields($fields)
{
if (! is_array($fields))
{
return $fields;
}
$return = [];
foreach ($fields as $field)
{
$return[$field->name] = [
'type' => $field->type,
'default' => $field->default,
'nullable' => $field->nullable,
];
if ($field->primary_key)
{
$this->keys[$field->name] = [
'fields' => [$field->name],
'type' => 'primary',
];
}
}
return $return;
} | php | {
"resource": ""
} |
q254635 | Table.formatKeys | test | protected function formatKeys($keys)
{
if (! is_array($keys))
{
return $keys;
}
$return = [];
foreach ($keys as $name => $key)
{
$return[$name] = [
'fields' => $key->fields,
'type' => 'index',
];
}
return $return;
} | php | {
"resource": ""
} |
q254636 | Table.dropIndexes | test | protected function dropIndexes()
{
if (! is_array($this->keys) || ! count($this->keys))
{
return;
}
foreach ($this->keys as $name => $key)
{
if ($key['type'] === 'primary' || $key['type'] === 'unique')
{
continue;
}
$this->db->query("DROP INDEX IF EXISTS '{$name}'");
}
} | php | {
"resource": ""
} |
q254637 | Security.CSRFSetCookie | test | public function CSRFSetCookie(RequestInterface $request)
{
$expire = time() + $this->CSRFExpire;
$secure_cookie = (bool) $this->cookieSecure;
if ($secure_cookie && ! $request->isSecure())
{
return false;
}
setcookie(
$this->CSRFCookieName, $this->CSRFHash, $expire, $this->cookiePath, $this->cookieDomain, $secure_cookie, true // Enforce HTTP only cookie for security
);
log_message('info', 'CSRF cookie sent');
return $this;
} | php | {
"resource": ""
} |
q254638 | Security.CSRFSetHash | test | protected function CSRFSetHash(): string
{
if ($this->CSRFHash === null)
{
// If the cookie exists we will use its value.
// We don't necessarily want to regenerate it with
// each page load since a page could contain embedded
// sub-pages causing this feature to fail
if (isset($_COOKIE[$this->CSRFCookieName]) && is_string($_COOKIE[$this->CSRFCookieName]) && preg_match('#^[0-9a-f]{32}$#iS', $_COOKIE[$this->CSRFCookieName]) === 1
)
{
return $this->CSRFHash = $_COOKIE[$this->CSRFCookieName];
}
$rand = random_bytes(16);
$this->CSRFHash = bin2hex($rand);
}
return $this->CSRFHash;
} | php | {
"resource": ""
} |
q254639 | Time.now | test | public static function now($timezone = null, string $locale = null)
{
return new Time(null, $timezone, $locale);
} | php | {
"resource": ""
} |
q254640 | Time.parse | test | public static function parse(string $datetime, $timezone = null, string $locale = null)
{
return new Time($datetime, $timezone, $locale);
} | php | {
"resource": ""
} |
q254641 | Time.today | test | public static function today($timezone = null, string $locale = null)
{
return new Time(date('Y-m-d 00:00:00'), $timezone, $locale);
} | php | {
"resource": ""
} |
q254642 | Time.yesterday | test | public static function yesterday($timezone = null, string $locale = null)
{
return new Time(date('Y-m-d 00:00:00', strtotime('-1 day')), $timezone, $locale);
} | php | {
"resource": ""
} |
q254643 | Time.tomorrow | test | public static function tomorrow($timezone = null, string $locale = null)
{
return new Time(date('Y-m-d 00:00:00', strtotime('+1 day')), $timezone, $locale);
} | php | {
"resource": ""
} |
q254644 | Time.createFromDate | test | public static function createFromDate(int $year = null, int $month = null, int $day = null, $timezone = null, string $locale = null)
{
return static::create($year, $month, $day, null, null, null, $timezone, $locale);
} | php | {
"resource": ""
} |
q254645 | Time.createFromTime | test | public static function createFromTime(int $hour = null, int $minutes = null, int $seconds = null, $timezone = null, string $locale = null)
{
return static::create(null, null, null, $hour, $minutes, $seconds, $timezone, $locale);
} | php | {
"resource": ""
} |
q254646 | Time.create | test | public static function create(int $year = null, int $month = null, int $day = null, int $hour = null, int $minutes = null, int $seconds = null, $timezone = null, string $locale = null)
{
$year = is_null($year) ? date('Y') : $year;
$month = is_null($month) ? date('m') : $month;
$day = is_null($day) ? date('d') : $day;
$hour = empty($hour) ? 0 : $hour;
$minutes = empty($minutes) ? 0 : $minutes;
$seconds = empty($seconds) ? 0 : $seconds;
return new Time(date('Y-m-d H:i:s', strtotime("{$year}-{$month}-{$day} {$hour}:{$minutes}:{$seconds}")), $timezone, $locale);
} | php | {
"resource": ""
} |
q254647 | Time.createFromFormat | test | public static function createFromFormat($format, $datetime, $timeZone = null)
{
$date = parent::createFromFormat($format, $datetime);
return new Time($date->format('Y-m-d H:i:s'), $timeZone);
} | php | {
"resource": ""
} |
q254648 | Time.createFromTimestamp | test | public static function createFromTimestamp(int $timestamp, $timeZone = null, string $locale = null)
{
return new Time(date('Y-m-d H:i:s', $timestamp), $timeZone, $locale);
} | php | {
"resource": ""
} |
q254649 | Time.instance | test | public static function instance(DateTime $dateTime, string $locale = null)
{
$date = $dateTime->format('Y-m-d H:i:s');
$timezone = $dateTime->getTimezone();
return new Time($date, $timezone, $locale);
} | php | {
"resource": ""
} |
q254650 | Time.toDateTime | test | public function toDateTime()
{
$dateTime = new DateTime(null, $this->getTimezone());
$dateTime->setTimestamp(parent::getTimestamp());
return $dateTime;
} | php | {
"resource": ""
} |
q254651 | Time.getAge | test | public function getAge()
{
$now = Time::now()->getTimestamp();
$time = $this->getTimestamp();
// future dates have no age
return max(0, date('Y', $now) - date('Y', $time));
} | php | {
"resource": ""
} |
q254652 | Time.getDst | test | public function getDst(): bool
{
// grab the transactions that would affect today
$start = strtotime('-1 year', $this->getTimestamp());
$end = strtotime('+2 year', $start);
$transitions = $this->timezone->getTransitions($start, $end);
$daylightSaving = false;
foreach ($transitions as $transition)
{
if ($transition['time'] > $this->format('U'))
{
$daylightSaving = (bool) $transition['isdst'] ?? $daylightSaving;
}
}
return $daylightSaving;
} | php | {
"resource": ""
} |
q254653 | Time.setMonth | test | public function setMonth($value)
{
if (is_numeric($value) && $value < 1 || $value > 12)
{
throw I18nException::forInvalidMonth($value);
}
if (is_string($value) && ! is_numeric($value))
{
$value = date('m', strtotime("{$value} 1 2017"));
}
return $this->setValue('month', $value);
} | php | {
"resource": ""
} |
q254654 | Time.setDay | test | public function setDay($value)
{
if ($value < 1 || $value > 31)
{
throw I18nException::forInvalidDay($value);
}
$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay)
{
throw I18nException::forInvalidOverDay($lastDay, $value);
}
return $this->setValue('day', $value);
} | php | {
"resource": ""
} |
q254655 | Time.setMinute | test | public function setMinute($value)
{
if ($value < 0 || $value > 59)
{
throw I18nException::forInvalidMinutes($value);
}
return $this->setValue('minute', $value);
} | php | {
"resource": ""
} |
q254656 | Time.setSecond | test | public function setSecond($value)
{
if ($value < 0 || $value > 59)
{
throw I18nException::forInvalidSeconds($value);
}
return $this->setValue('second', $value);
} | php | {
"resource": ""
} |
q254657 | Time.setValue | test | protected function setValue(string $name, $value)
{
list($year, $month, $day, $hour, $minute, $second) = explode('-', $this->format('Y-n-j-G-i-s'));
$$name = $value;
return Time::create($year, $month, $day, $hour, $minute, $second, $this->getTimezoneName(), $this->locale);
} | php | {
"resource": ""
} |
q254658 | Time.setTimestamp | test | public function setTimestamp($timestamp)
{
$time = date('Y-m-d H:i:s', $timestamp);
return Time::parse($time, $this->timezone, $this->locale);
} | php | {
"resource": ""
} |
q254659 | Time.equals | test | public function equals($testTime, string $timezone = null): bool
{
$testTime = $this->getUTCObject($testTime, $timezone);
$ourTime = $this->toDateTime()
->setTimezone(new DateTimeZone('UTC'))
->format('Y-m-d H:i:s');
return $testTime->format('Y-m-d H:i:s') === $ourTime;
} | php | {
"resource": ""
} |
q254660 | Time.sameAs | test | public function sameAs($testTime, string $timezone = null): bool
{
if ($testTime instanceof DateTime)
{
$testTime = $testTime->format('Y-m-d H:i:s');
}
else if (is_string($testTime))
{
$timezone = $timezone ?: $this->timezone;
$timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
$testTime = new DateTime($testTime, $timezone);
$testTime = $testTime->format('Y-m-d H:i:s');
}
$ourTime = $this->toDateTimeString();
return $testTime === $ourTime;
} | php | {
"resource": ""
} |
q254661 | Time.getUTCObject | test | public function getUTCObject($time, string $timezone = null)
{
if ($time instanceof Time)
{
$time = $time->toDateTime()
->setTimezone(new DateTimeZone('UTC'));
}
else if ($time instanceof DateTime)
{
$time = $time->setTimezone(new DateTimeZone('UTC'));
}
else if (is_string($time))
{
$timezone = $timezone ?: $this->timezone;
$timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
$time = new DateTime($time, $timezone);
$time = $time->setTimezone(new DateTimeZone('UTC'));
}
return $time;
} | php | {
"resource": ""
} |
q254662 | Escaper.jsMatcher | test | protected function jsMatcher($matches)
{
$chr = $matches[0];
if (strlen($chr) == 1) {
return sprintf('\\x%02X', ord($chr));
}
$chr = $this->convertEncoding($chr, 'UTF-16BE', 'UTF-8');
$hex = strtoupper(bin2hex($chr));
if (strlen($hex) <= 4) {
return sprintf('\\u%04s', $hex);
}
$highSurrogate = substr($hex, 0, 4);
$lowSurrogate = substr($hex, 4, 4);
return sprintf('\\u%04s\\u%04s', $highSurrogate, $lowSurrogate);
} | php | {
"resource": ""
} |
q254663 | Escaper.cssMatcher | test | protected function cssMatcher($matches)
{
$chr = $matches[0];
if (strlen($chr) == 1) {
$ord = ord($chr);
} else {
$chr = $this->convertEncoding($chr, 'UTF-32BE', 'UTF-8');
$ord = hexdec(bin2hex($chr));
}
return sprintf('\\%X ', $ord);
} | php | {
"resource": ""
} |
q254664 | Escaper.toUtf8 | test | protected function toUtf8($string)
{
if ($this->getEncoding() === 'utf-8') {
$result = $string;
} else {
$result = $this->convertEncoding($string, 'UTF-8', $this->getEncoding());
}
if (! $this->isUtf8($result)) {
throw new Exception\RuntimeException(
sprintf('String to be escaped was not valid UTF-8 or could not be converted: %s', $result)
);
}
return $result;
} | php | {
"resource": ""
} |
q254665 | Escaper.fromUtf8 | test | protected function fromUtf8($string)
{
if ($this->getEncoding() === 'utf-8') {
return $string;
}
return $this->convertEncoding($string, $this->getEncoding(), 'UTF-8');
} | php | {
"resource": ""
} |
q254666 | FileCollection.getFile | test | public function getFile(string $name)
{
$this->populateFiles();
if ($this->hasFile($name))
{
if (strpos($name, '.') !== false)
{
$name = explode('.', $name);
$uploadedFile = $this->getValueDotNotationSyntax($name, $this->files);
return ($uploadedFile instanceof UploadedFile) ?
$uploadedFile : null;
}
if (array_key_exists($name, $this->files))
{
$uploadedFile = $this->files[$name];
return ($uploadedFile instanceof UploadedFile) ?
$uploadedFile : null;
}
}
return null;
} | php | {
"resource": ""
} |
q254667 | FileCollection.createFileObject | test | protected function createFileObject(array $array)
{
if (! isset($array['name']))
{
$output = [];
foreach ($array as $key => $values)
{
if (! is_array($values))
{
continue;
}
$output[$key] = $this->createFileObject($values);
}
return $output;
}
return new UploadedFile(
$array['tmp_name'] ?? null, $array['name'] ?? null, $array['type'] ?? null, $array['size'] ?? null, $array['error'] ?? null
);
} | php | {
"resource": ""
} |
q254668 | FileCollection.getValueDotNotationSyntax | test | protected function getValueDotNotationSyntax(array $index, array $value)
{
if (is_array($index) && ! empty($index))
{
$current_index = array_shift($index);
}
if (is_array($index) && $index && is_array($value[$current_index]) && $value[$current_index])
{
return $this->getValueDotNotationSyntax($index, $value[$current_index]);
}
return (isset($value[$current_index])) ? $value[$current_index] : null;
} | php | {
"resource": ""
} |
q254669 | DownloadResponse.setBinary | test | public function setBinary(string $binary)
{
if ($this->file !== null)
{
throw DownloadException::forCannotSetBinary();
}
$this->binary = $binary;
} | php | {
"resource": ""
} |
q254670 | DownloadResponse.setFilePath | test | public function setFilePath(string $filepath)
{
if ($this->binary !== null)
{
throw DownloadException::forCannotSetFilePath($filepath);
}
$this->file = new File($filepath, true);
} | php | {
"resource": ""
} |
q254671 | DownloadResponse.getContentLength | test | public function getContentLength() : int
{
if (is_string($this->binary))
{
return strlen($this->binary);
}
elseif ($this->file instanceof File)
{
return $this->file->getSize();
}
return 0;
} | php | {
"resource": ""
} |
q254672 | DownloadResponse.setContentTypeByMimeType | test | private function setContentTypeByMimeType()
{
$mime = null;
$charset = '';
if ($this->setMime === true)
{
if (($last_dot_position = strrpos($this->filename, '.')) !== false)
{
$mime = Mimes::guessTypeFromExtension(substr($this->filename, $last_dot_position + 1));
$charset = $this->charset;
}
}
if (! is_string($mime))
{
// Set the default MIME type to send
$mime = 'application/octet-stream';
$charset = '';
}
$this->setContentType($mime, $charset);
} | php | {
"resource": ""
} |
q254673 | DownloadResponse.getDownloadFileName | test | private function getDownloadFileName(): string
{
$filename = $this->filename;
$x = explode('.', $this->filename);
$extension = end($x);
/* It was reported that browsers on Android 2.1 (and possibly older as well)
* need to have the filename extension upper-cased in order to be able to
* download it.
*
* Reference: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/
*/
// @todo: depend super global
if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT'])
&& preg_match('/Android\s(1|2\.[01])/', $_SERVER['HTTP_USER_AGENT']))
{
$x[count($x) - 1] = strtoupper($extension);
$filename = implode('.', $x);
}
return $filename;
} | php | {
"resource": ""
} |
q254674 | DownloadResponse.getContentDisposition | test | private function getContentDisposition() : string
{
$download_filename = $this->getDownloadFileName();
$utf8_filename = $download_filename;
if (strtoupper($this->charset) !== 'UTF-8')
{
$utf8_filename = mb_convert_encoding($download_filename, 'UTF-8', $this->charset);
}
$result = sprintf('attachment; filename="%s"', $download_filename);
if (isset($utf8_filename))
{
$result .= '; filename*=UTF-8\'\'' . rawurlencode($utf8_filename);
}
return $result;
} | php | {
"resource": ""
} |
q254675 | DownloadResponse.buildHeaders | test | public function buildHeaders()
{
if (! $this->hasHeader('Content-Type'))
{
$this->setContentTypeByMimeType();
}
$this->setHeader('Content-Disposition', $this->getContentDisposition());
$this->setHeader('Expires-Disposition', '0');
$this->setHeader('Content-Transfer-Encoding', 'binary');
$this->setHeader('Content-Length', (string)$this->getContentLength());
$this->noCache();
} | php | {
"resource": ""
} |
q254676 | DownloadResponse.sendBody | test | public function sendBody()
{
if ($this->binary !== null)
{
return $this->sendBodyByBinary();
}
elseif ($this->file !== null)
{
return $this->sendBodyByFilePath();
}
throw DownloadException::forNotFoundDownloadSource();
} | php | {
"resource": ""
} |
q254677 | DownloadResponse.sendBodyByFilePath | test | private function sendBodyByFilePath()
{
$spl_file_object = $this->file->openFile('rb');
// Flush 1MB chunks of data
while (! $spl_file_object->eof() && ($data = $spl_file_object->fread(1048576)) !== false)
{
echo $data;
}
return $this;
} | php | {
"resource": ""
} |
q254678 | CommandRunner._remap | test | public function _remap($method, ...$params)
{
// The first param is usually empty, so scrap it.
if (empty($params[0]))
{
array_shift($params);
}
$this->index($params);
} | php | {
"resource": ""
} |
q254679 | CommandRunner.runCommand | test | protected function runCommand(string $command, array $params)
{
if (! isset($this->commands[$command]))
{
CLI::error(lang('CLI.commandNotFound', [$command]));
CLI::newLine();
return;
}
// The file would have already been loaded during the
// createCommandList function...
$className = $this->commands[$command]['class'];
$class = new $className($this->logger, $this);
return $class->run($params);
} | php | {
"resource": ""
} |
q254680 | CommandRunner.createCommandList | test | protected function createCommandList()
{
$files = Services::locator()->listFiles('Commands/');
// If no matching command files were found, bail
if (empty($files))
{
// This should never happen in unit testing.
// if it does, we have far bigger problems!
// @codeCoverageIgnoreStart
return;
// @codeCoverageIgnoreEnd
}
// Loop over each file checking to see if a command with that
// alias exists in the class. If so, return it. Otherwise, try the next.
foreach ($files as $file)
{
$className = Services::locator()->findQualifiedNameFromPath($file);
if (empty($className) || ! class_exists($className))
{
continue;
}
$class = new \ReflectionClass($className);
if (! $class->isInstantiable() || ! $class->isSubclassOf(BaseCommand::class))
{
continue;
}
$class = new $className($this->logger, $this);
// Store it!
if ($class->group !== null)
{
$this->commands[$class->name] = [
'class' => $className,
'file' => $file,
'group' => $class->group,
'description' => $class->description,
];
}
$class = null;
unset($class);
}
asort($this->commands);
} | php | {
"resource": ""
} |
q254681 | Config.connect | test | public static function connect($group = null, bool $getShared = true)
{
// If a DB connection is passed in, just pass it back
if ($group instanceof BaseConnection)
{
return $group;
}
if (is_array($group))
{
$config = $group;
$group = 'custom-' . md5(json_encode($config));
}
$config = $config ?? new \Config\Database();
if (empty($group))
{
$group = ENVIRONMENT === 'testing' ? 'tests' : $config->defaultGroup;
}
if (is_string($group) && ! isset($config->$group) && strpos($group, 'custom-') !== 0)
{
throw new \InvalidArgumentException($group . ' is not a valid database connection group.');
}
if ($getShared && isset(static::$instances[$group]))
{
return static::$instances[$group];
}
static::ensureFactory();
if (isset($config->$group))
{
$config = $config->$group;
}
$connection = static::$factory->load($config, $group);
static::$instances[$group] = & $connection;
return $connection;
} | php | {
"resource": ""
} |
q254682 | Config.seeder | test | public static function seeder(string $group = null)
{
$config = config('Database');
return new Seeder($config, static::connect($group));
} | php | {
"resource": ""
} |
q254683 | MigrateRollback.isAllNamespace | test | private function isAllNamespace(array $params): bool
{
if (array_search('-all', $params) !== false)
{
return true;
}
return ! is_null(CLI::getOption('all'));
} | php | {
"resource": ""
} |
q254684 | Iterator.add | test | public function add(string $name, \Closure $closure)
{
$name = strtolower($name);
$this->tests[$name] = $closure;
return $this;
} | php | {
"resource": ""
} |
q254685 | Iterator.run | test | public function run(int $iterations = 1000, bool $output = true)
{
foreach ($this->tests as $name => $test)
{
// clear memory before start
gc_collect_cycles();
$start = microtime(true);
$start_mem = $max_memory = memory_get_usage(true);
for ($i = 0; $i < $iterations; $i ++)
{
$result = $test();
$max_memory = max($max_memory, memory_get_usage(true));
unset($result);
}
$this->results[$name] = [
'time' => microtime(true) - $start,
'memory' => $max_memory - $start_mem,
'n' => $iterations,
];
}
if ($output)
{
return $this->getReport();
}
return null;
} | php | {
"resource": ""
} |
q254686 | Iterator.getReport | test | public function getReport(): string
{
if (empty($this->results))
{
return 'No results to display.';
}
helper('number');
// Template
$tpl = '<table>
<thead>
<tr>
<td>Test</td>
<td>Time</td>
<td>Memory</td>
</tr>
</thead>
<tbody>
{rows}
</tbody>
</table>';
$rows = '';
foreach ($this->results as $name => $result)
{
$memory = number_to_size($result['memory'], 4);
$rows .= "<tr>
<td>{$name}</td>
<td>" . number_format($result['time'], 4) . "</td>
<td>{$memory}</td>
</tr>";
}
$tpl = str_replace('{rows}', $rows, $tpl);
return $tpl . '<br/>';
} | php | {
"resource": ""
} |
q254687 | Query.setQuery | test | public function setQuery(string $sql, $binds = null, bool $setEscape = true)
{
$this->originalQueryString = $sql;
if (! is_null($binds))
{
if (! is_array($binds))
{
$binds = [$binds];
}
if ($setEscape)
{
array_walk($binds, function (&$item) {
$item = [
$item,
true,
];
});
}
$this->binds = $binds;
}
return $this;
} | php | {
"resource": ""
} |
q254688 | Query.getQuery | test | public function getQuery(): string
{
if (empty($this->finalQueryString))
{
$this->finalQueryString = $this->originalQueryString;
}
$this->compileBinds();
return $this->finalQueryString;
} | php | {
"resource": ""
} |
q254689 | Query.getStartTime | test | public function getStartTime(bool $returnRaw = false, int $decimals = 6): string
{
if ($returnRaw)
{
return $this->startTime;
}
return number_format($this->startTime, $decimals);
} | php | {
"resource": ""
} |
q254690 | Query.getDuration | test | public function getDuration(int $decimals = 6): string
{
return number_format(($this->endTime - $this->startTime), $decimals);
} | php | {
"resource": ""
} |
q254691 | Query.setError | test | public function setError(int $code, string $error)
{
$this->errorCode = $code;
$this->errorString = $error;
return $this;
} | php | {
"resource": ""
} |
q254692 | Query.swapPrefix | test | public function swapPrefix(string $orig, string $swap)
{
$sql = empty($this->finalQueryString) ? $this->originalQueryString : $this->finalQueryString;
$this->finalQueryString = preg_replace('/(\W)' . $orig . '(\S+?)/', '\\1' . $swap . '\\2', $sql);
return $this;
} | php | {
"resource": ""
} |
q254693 | Query.compileBinds | test | protected function compileBinds()
{
$sql = $this->finalQueryString;
$hasNamedBinds = strpos($sql, ':') !== false;
if (empty($this->binds) || empty($this->bindMarker) ||
(strpos($sql, $this->bindMarker) === false &&
$hasNamedBinds === false)
)
{
return;
}
if (! is_array($this->binds))
{
$binds = [$this->binds];
$bindCount = 1;
}
else
{
$binds = $this->binds;
$bindCount = count($binds);
}
// Reverse the binds so that duplicate named binds
// will be processed prior to the original binds.
if (! is_numeric(key(array_slice($binds, 0, 1))))
{
$binds = array_reverse($binds);
}
// We'll need marker length later
$ml = strlen($this->bindMarker);
if ($hasNamedBinds)
{
$sql = $this->matchNamedBinds($sql, $binds);
}
else
{
$sql = $this->matchSimpleBinds($sql, $binds, $bindCount, $ml);
}
$this->finalQueryString = $sql;
} | php | {
"resource": ""
} |
q254694 | Controller.loadHelpers | test | protected function loadHelpers()
{
if (empty($this->helpers))
{
return;
}
foreach ($this->helpers as $helper)
{
helper($helper);
}
} | php | {
"resource": ""
} |
q254695 | Autoloader.register | test | public function register()
{
// Since the default file extensions are searched
// in order of .inc then .php, but we always use .php,
// put the .php extension first to eek out a bit
// better performance.
// http://php.net/manual/en/function.spl-autoload.php#78053
spl_autoload_extensions('.php,.inc');
// Prepend the PSR4 autoloader for maximum performance.
spl_autoload_register([$this, 'loadClass'], true, true);
// Now prepend another loader for the files in our class map.
$config = is_array($this->classmap) ? $this->classmap : [];
spl_autoload_register(function ($class) use ($config) {
if (empty($config[$class]))
{
return false;
}
include_once $config[$class];
}, true, // Throw exception
true // Prepend
);
} | php | {
"resource": ""
} |
q254696 | Autoloader.addNamespace | test | public function addNamespace($namespace, string $path = null)
{
if (is_array($namespace))
{
foreach ($namespace as $prefix => $path)
{
$prefix = trim($prefix, '\\');
if (is_array($path))
{
foreach ($path as $dir)
{
$this->prefixes[$prefix][] = rtrim($dir, '/') . '/';
}
continue;
}
$this->prefixes[$prefix][] = rtrim($path, '/') . '/';
}
}
else
{
$this->prefixes[trim($namespace, '\\')][] = rtrim($path, '/') . '/';
}
return $this;
} | php | {
"resource": ""
} |
q254697 | Autoloader.getNamespace | test | public function getNamespace(string $prefix = null)
{
if ($prefix === null)
{
return $this->prefixes;
}
return $this->prefixes[trim($prefix, '\\')] ?? [];
} | php | {
"resource": ""
} |
q254698 | Autoloader.requireFile | test | protected function requireFile(string $file)
{
$file = $this->sanitizeFilename($file);
if (is_file($file))
{
require_once $file;
return $file;
}
return false;
} | php | {
"resource": ""
} |
q254699 | Autoloader.sanitizeFilename | test | public function sanitizeFilename(string $filename): string
{
// Only allow characters deemed safe for POSIX portable filenames.
// Plus the forward slash for directory separators since this might
// be a path.
// http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278
// Modified to allow backslash and colons for on Windows machines.
$filename = preg_replace('/[^a-zA-Z0-9\s\/\-\_\.\:\\\\]/', '', $filename);
// Clean up our filename edges.
$filename = trim($filename, '.-_');
return $filename;
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.