_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q261100
AbstractFormatter.formatNumber
test
protected function formatNumber($float, $suffix, $precision = null) { if ($precision === null) { $precision = $this->precision; } $precision = $this->normalizePrecision($precision); return sprintf("%.{$precision}f%s", $float, $suffix); }
php
{ "resource": "" }
q261101
AbstractFormatter.normalizeBytes
test
protected function normalizeBytes($bytes) { $filteredBytes = filter_var($bytes, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); list ($bytes, $part) = explode('.', $filteredBytes . '.0'); if (bccomp($part, 0) == 1) { $bytes = bcadd($bytes, 1); } return $bytes; }
php
{ "resource": "" }
q261102
AbstractFormatter.normalizePrecision
test
protected function normalizePrecision($precision) { $precisionFiltered = filter_var($precision, FILTER_SANITIZE_NUMBER_INT); return (int) min(10, max(0, $precisionFiltered)); }
php
{ "resource": "" }
q261103
Request.withMethod
test
public function withMethod($method) { $method = strtoupper($method); $knownMethods = [ 'HEAD', 'OPTIONS', 'GET', 'POST', 'PUT', 'DELETE', 'CONNECT', 'TRACE', 'PATCH', 'PURGE' ]; if (! in_array($method, $knownMethods)) { throw new InvalidArgumentException( "Invalid or unknown method name." ); } $message = clone $this; $message->method = $method; return $message; }
php
{ "resource": "" }
q261104
Request.setUri
test
protected function setUri(UriInterface $uri, $preserveHost = false) { if (! $preserveHost && $uri->getHost() !== '') { $key = $this->headerKey('Host'); $this->headers[$key] = [$uri->getHost()]; } $this->uri = $uri; }
php
{ "resource": "" }
q261105
Request.getTargetFromUri
test
private function getTargetFromUri() { $target = "/{$this->uri->getPath()}"; $target .= $this->uri->getQuery() !== '' ? "?{$this->uri->getQuery()}" : ''; $target .= $this->uri->getFragment() !== '' ? "#{$this->uri->getFragment()}" : ''; return str_replace('//', '/', $target); }
php
{ "resource": "" }
q261106
MiddlewareStack.push
test
public function push($middleware) { if (! $middleware instanceof MiddlewareInterface && ! is_callable($middleware) ) { throw new InvalidArgumentException( "Middleware stack accepts only MiddlewareInterface object or callable" ); } array_push($this->middlewareStack, $middleware); return $this; }
php
{ "resource": "" }
q261107
HttpCodes.reasonPhraseFor
test
public static function reasonPhraseFor($code) { $status = ''; if (array_key_exists($code, self::$codes)) { $status = self::$codes[$code]; } return $status; }
php
{ "resource": "" }
q261108
HipChatDriver.getMessages
test
public function getMessages() { return [ new IncomingMessage($this->event->get('message')['message'], $this->event->get('message')['from']['id'], $this->event->get('room')['id'], $this->event), ]; }
php
{ "resource": "" }
q261109
HipChatDriver.getUser
test
public function getUser(IncomingMessage $matchingMessage) { $payload = $matchingMessage->getPayload(); return new User($payload->get('message')['from']['id'], $payload->get('message')['from']['name'], null, $payload->get('message')['from']['mention_name']); }
php
{ "resource": "" }
q261110
file.getExtension
test
static function getExtension($filename, $toLower=true) { return preg_match('/^.*\.([^\.]*)$/s', $filename, $patt) ? ($toLower ? strtolower($patt[1]) : $patt[1]) : ""; }
php
{ "resource": "" }
q261111
file.normalizeFilename
test
static function normalizeFilename($filename) { $string = htmlentities($filename, ENT_QUOTES, 'UTF-8'); if (strpos($string, '&') !== false) $filename = html_entity_decode(preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|tilde|uml);~i', '$1', $string), ENT_QUOTES, 'UTF-8'); $filename = trim(preg_replace('~[^0-9a-z\.\- ]~i', "_", $filename)); return $filename; }
php
{ "resource": "" }
q261112
Stream.getContents
test
public function getContents() { if (!$this->isReadable() || ($contents = stream_get_contents($this->fp, -1, 0)) === false) { throw new \RuntimeException('Unable to get contents of stream'); } return $contents; }
php
{ "resource": "" }
q261113
MultisiteDirectoryResolver.fixSiteUrlFilter
test
public function fixSiteUrlFilter($url, $path, $scheme) { if (strpos($url, $this->wpDirectoryPath)) { return $url; } $wordpressUrl = ['/(wp-login\.php)/', '/(wp-admin)/']; $multiSiteUrl = [trim($this->wpDirectoryPath, '/').'/wp-login.php', trim($this->wpDirectoryPath, '/').'/wp-admin']; return preg_replace($wordpressUrl, $multiSiteUrl, $url, 1); }
php
{ "resource": "" }
q261114
MultisiteDirectoryResolver.fixWpIncludeFolder
test
public function fixWpIncludeFolder($url, $path) { if (strpos($url, $this->wpDirectoryPath)) { return $url; } $wordpressUrl = ['/(wp-includes)/']; $multiSiteUrl = [trim($this->wpDirectoryPath, '/').'/wp-includes']; return preg_replace($wordpressUrl, $multiSiteUrl, $url, 1); }
php
{ "resource": "" }
q261115
AbstractResolver.fixNetworkAdminUrlFilter
test
public function fixNetworkAdminUrlFilter($path = '', $scheme = 'admin') { if (strpos($path, $this->wpDirectoryPath)) { return $path; } $wordpressUrl = [ '/(wp-admin)/', '/(wp-login\.php)/', '/(wp-activate\.php)/', '/(wp-signup\.php)/', ]; $multiSiteUrl = [ $this->wpFolderName.'/wp-admin', $this->wpFolderName.'/wp-login.php', $this->wpFolderName.'/wp-activate.php', $this->wpFolderName.'/wp-signup.php', ]; return preg_replace($wordpressUrl, $multiSiteUrl, $path, 1); }
php
{ "resource": "" }
q261116
AbstractResolver.fixWpDoubleSlashFilter
test
public function fixWpDoubleSlashFilter($urls) { foreach ($urls as &$url) { if ($url) { $url = str_replace('//app', '/app', $url); } } return $urls; }
php
{ "resource": "" }
q261117
AbstractResolver.init
test
public function init() { $this->getWpBridge()->addFilter('network_admin_url', [$this, 'fixNetworkAdminUrlFilter'], 10, 2); $this->getWpBridge()->addFilter('script_loader_src', [$this, 'fixStyleScriptPathFilter'], 10, 2); $this->getWpBridge()->addFilter('style_loader_src', [$this, 'fixStyleScriptPathFilter'], 10, 2); $this->getWpBridge()->addFilter('upload_dir', [$this, 'fixWpDoubleSlashFilter'], 10, 1); $this->getWpBridge()->addFilter('upload_dir', [$this, 'fixWpProtocolFilter'], 10, 1); }
php
{ "resource": "" }
q261118
AbstractResolver.setWpFolderName
test
protected function setWpFolderName() { $dirs = explode('/', $this->wpDirectoryPath); $this->wpFolderName = $dirs[count($dirs) - 2]; }
php
{ "resource": "" }
q261119
path.url2fullPath
test
static function url2fullPath($url) { $url = self::normalize($url); $uri = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : (isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : false); $uri = self::normalize($uri); if (substr($url, 0, 1) !== "/") { if ($uri === false) return false; $url = dirname($uri) . "/$url"; } if (isset($_SERVER['DOCUMENT_ROOT'])) { return self::normalize($_SERVER['DOCUMENT_ROOT'] . "/$url"); } else { if ($uri === false) return false; if (isset($_SERVER['SCRIPT_FILENAME'])) { $scr_filename = self::normalize($_SERVER['SCRIPT_FILENAME']); return self::normalize(substr($scr_filename, 0, -strlen($uri)) . "/$url"); } $count = count(explode('/', $uri)) - 1; for ($i = 0, $chdir = ""; $i < $count; $i++) $chdir .= "../"; $chdir = self::normalize($chdir); $dir = getcwd(); if (($dir === false) || !@chdir($chdir)) return false; $rdir = getcwd(); chdir($dir); return ($rdir !== false) ? self::normalize($rdir . "/$url") : false; } }
php
{ "resource": "" }
q261120
path.urlPathEncode
test
static function urlPathEncode($path) { $path = self::normalize($path); $encoded = ""; foreach (explode("/", $path) as $dir) $encoded .= rawurlencode($dir) . "/"; $encoded = substr($encoded, 0, -1); return $encoded; }
php
{ "resource": "" }
q261121
path.urlPathDecode
test
static function urlPathDecode($path) { $path = self::normalize($path); $decoded = ""; foreach (explode("/", $path) as $dir) $decoded .= rawurldecode($dir) . "/"; $decoded = substr($decoded, 0, -1); return $decoded; }
php
{ "resource": "" }
q261122
dir.content
test
static function content($dir, array $options=null) { $defaultOptions = array( 'types' => "all", // Allowed: "all" or possible return values // of filetype(), or an array with them 'addPath' => true, // Whether to add directory path to filenames 'pattern' => '/./', // Regular expression pattern for filename 'followLinks' => true ); if (!is_dir($dir) || !is_readable($dir)) return false; if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") $dir = str_replace("\\", "/", $dir); $dir = rtrim($dir, "/"); $dh = @opendir($dir); if ($dh === false) return false; if ($options === null) $options = $defaultOptions; foreach ($defaultOptions as $key => $val) if (!isset($options[$key])) $options[$key] = $val; $files = array(); while (($file = @readdir($dh)) !== false) { if (($file == '.') || ($file == '..') || !preg_match($options['pattern'], $file) ) continue; $fullpath = "$dir/$file"; $type = filetype($fullpath); // If file is a symlink, get the true type of its destination if ($options['followLinks'] && ($type == "link")) $type = filetype(realpath($fullpath)); if (($options['types'] === "all") || ($type === $options['types']) || (is_array($options['types']) && in_array($type, $options['types'])) ) $files[] = $options['addPath'] ? $fullpath : $file; } closedir($dh); usort($files, array(__NAMESPACE__ . "\\dir", "fileSort")); return $files; }
php
{ "resource": "" }
q261123
Console.database
test
public function database($data, $time_start, $memory_start = null) { if (!array_key_exists('Database', $this->Profiler->log_sections)) { return ; } if (!is_string($data)) { return ; } if (!is_float($time_start)) { $time_start = $this->Profiler->getMicrotime(); } if ($memory_start === null) { // is dev still not using memory start? trigger error. trigger_error('You did not enter $memory_start argument for \Rundiz\Profiler\Console->database() method. Please set the $memory_start to memory_get_usage() in your code.', E_USER_NOTICE); } if (!is_int($memory_start)) { $memory_start = memory_get_usage(); } $backtrace = debug_backtrace(); $trace_items = []; if (is_array($backtrace)) { foreach ($backtrace as $items) { if (is_array($items) && array_key_exists('file', $items) && array_key_exists('line', $items)) { $trace_items[] = ['file' => $items['file'], 'line' => $items['line']]; } } } unset($backtrace, $items); $section_database = $this->Profiler->log_sections['Database']; $section_database_data = []; $section_database_data[] = [ 'data' => $data, 'memory_start' => $memory_start, 'memory' => memory_get_usage(),// @deprecated [rundizprofiler] and will be removed in the future 'memory_end' => memory_get_usage(), 'time_start' => $time_start, 'time_end' => $this->Profiler->getMicrotime(), 'call_trace' => $trace_items, ]; $section_database = array_merge($section_database, $section_database_data); $this->Profiler->log_sections['Database'] = $section_database; unset($section_database, $section_database_data, $trace_items); //$this->writeLogSections('Database', $data, $file, $line); }
php
{ "resource": "" }
q261124
Console.log
test
public function log($logtype, $data, $file = '', $line = '') { $data = [ 'logtype' => $logtype, 'data' => $data, ]; $this->writeLogSections('Logs', $data, $file, $line); }
php
{ "resource": "" }
q261125
Console.memoryUsage
test
public function memoryUsage($data, $file = '', $line = '', $matchKey = null) { $this->writeLogSections('Memory Usage', $data, $file, $line, $matchKey); }
php
{ "resource": "" }
q261126
Console.timeload
test
public function timeload($data, $file = '', $line = '', $matchKey = null) { $this->writeLogSections('Time Load', $data, $file, $line, $matchKey); }
php
{ "resource": "" }
q261127
Console.writeLogSections
test
public function writeLogSections($section, $data, $file = '', $line = '', $matchKey = null) { if (!is_array($this->Profiler->log_sections)) { $this->Profiler->log_sections = []; } if (!array_key_exists($section, $this->Profiler->log_sections)) { // if section is not exists in the key means it was not registered, get out of this function. return ; } if (!is_string($matchKey)) { $matchKey = null; } if ($section == 'Logs') { if (is_array($data) && array_key_exists('logtype', $data) && array_key_exists('data', $data)) { $logtype = $data['logtype']; $data = $data['data']; } } $section_data_array = [ 'data' => $data, 'file' => $file, 'line' => $line, ]; if ($matchKey !== null) { $section_data_array['matchKey'] = $matchKey; } if ($section == 'Time Load') { $section_data_array['time'] = $this->Profiler->getMicrotime(); } if ($section == 'Memory Usage') { $section_data_array['memory'] = memory_get_usage(); } if (isset($logtype)) { $section_data_array['logtype'] = $logtype; } $this->Profiler->log_sections[$section][] = $section_data_array; unset($section_data_array); }
php
{ "resource": "" }
q261128
UploadedFile.filesFlip
test
public static function filesFlip(&$result, $keys, $value) { if (is_array($value)) { foreach ($value as $k => $v) { $newKeys = $keys; array_push($newKeys, $k); self::filesFlip($result, $newKeys, $v); } } else { $res = $value; // Move the innermost key to the outer spot $first = array_shift($keys); array_push($keys, $first); foreach (array_reverse($keys) as $k) { // You might think we'd say $res[$k] = $res, but $res starts out not as an array $res = [$k => $res]; } $result = array_replace_recursive($result, $res); } }
php
{ "resource": "" }
q261129
UploadedFile.setStream
test
public function setStream(StreamInterface $stream): UploadedFile { if ($this->hasMoved()) { throw new \RuntimeException(sprintf('Uploaded file "%s" has already moved', $this->file)); } $this->stream = $stream; return $this; }
php
{ "resource": "" }
q261130
UploadedFile.getHash
test
public function getHash($algo = 'sha1') { if ($this->hasMoved()) { throw new \RuntimeException(sprintf('Uploaded file "%s" has already moved', $this->file)); } return hash_file($algo, $this->file); }
php
{ "resource": "" }
q261131
UploadedFile.getMediaType
test
public function getMediaType() { if ($this->hasMoved()) { throw new \RuntimeException(sprintf('Uploaded file "%s" has already moved', $this->file)); } if (extension_loaded('fileinfo')) { $finfo = finfo_open(FILEINFO_MIME); $mime = finfo_file($finfo, $this->file); finfo_close($finfo); $mime = explode(";", $mime); $mime = trim($mime[0]); return $mime; } else { throw new \RuntimeException(sprintf('You must install fileinfo extension to determine the real type of uploaded file "%s"', $this->file)); } }
php
{ "resource": "" }
q261132
ServerRequest.getQueryParams
test
public function getQueryParams() { if (!is_null($this->queryParams)) { return $this->queryParams; } else { if (!is_null($this->getUri())) { parse_str($this->getUri()->getQuery(), $this->queryParams); return $this->queryParams; } else { return []; } } }
php
{ "resource": "" }
q261133
ServerRequest.isAjaxRequest
test
public function isAjaxRequest() { // Check if ajax request { $ajaxRequest = $this->hasHeader('AjaxRequest'); $serverParams = $this->getServerParams(); if (!$ajaxRequest && !empty($serverParams['HTTP_X_REQUESTED_WITH']) && strtolower($serverParams['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { $ajaxRequest = true; } } return $ajaxRequest; }
php
{ "resource": "" }
q261134
Handler.toDocument
test
public function toDocument($json) { $data = json_decode($json, true); $document = new Document(); if (isset($data['class']) && is_array($data['class'])) { $document->setClass($data['class']); } if (isset($data['properties']) && is_array($data['properties'])) { $document->setProperties($data['properties']); } if (isset($data['entities']) && is_array($data['entities'])) { $entities = $this->getEntitiesFromDataArray($data['entities']); $document->setEntities($entities); } if (isset($data['actions']) && is_array($data['actions'])) { $actions = $this->getActionsFromDataArray($data['actions']); $document->setActions($actions); } if (isset($data['links']) && is_array($data['links'])) { $links = $this->getLinksFromDataArray($data['links']); $document->setLinks($links); } return $document; }
php
{ "resource": "" }
q261135
Handler.getEntitiesFromDataArray
test
protected function getEntitiesFromDataArray(array $entitiesArray) { $entities = array(); foreach ($entitiesArray as $entityArray) { $entity = new Entity(); if (isset($entityArray['class']) && is_array($entityArray['class'])) { $entity->setClass($entityArray['class']); } if (isset($entityArray['rel']) && is_array($entityArray['rel'])) { $entity->setRel($entityArray['rel']); } if (isset($entityArray['href']) && is_string($entityArray['href'])) { $entity->setHref($entityArray['href']); } if (isset($entityArray['properties']) && is_array($entityArray['properties'])) { $entity->setProperties($entityArray['properties']); } if (isset($entityArray['links']) && is_array($entityArray['links'])) { $links = $this->getLinksFromDataArray($entityArray['links']); $entity->setLinks($links); } $entities[] = $entity; } return $entities; }
php
{ "resource": "" }
q261136
Handler.getActionsFromDataArray
test
protected function getActionsFromDataArray(array $actionsArray) { $actions = array(); foreach ($actionsArray as $actionArray) { $action = new Action(); if (isset($actionArray['name']) && is_string($actionArray['name'])) { $action->setName($actionArray['name']); } if (isset($actionArray['title']) && is_string($actionArray['title'])) { $action->setTitle($actionArray['title']); } if (isset($actionArray['method']) && is_string($actionArray['method'])) { $action->setMethod($actionArray['method']); } if (isset($actionArray['href']) && is_string($actionArray['href'])) { $action->setHref($actionArray['href']); } if (isset($actionArray['type']) && is_string($actionArray['type'])) { $action->setType($actionArray['type']); } if (isset($actionArray['fields']) && is_array($actionArray['fields'])) { $fields = $this->getFieldsFromDataArray($actionArray['fields']); $action->setFields($fields); } $actions[] = $action; } return $actions; }
php
{ "resource": "" }
q261137
Handler.getFieldsFromDataArray
test
protected function getFieldsFromDataArray(array $fieldsArray) { $fields = array(); foreach ($fieldsArray as $fieldArray) { $field = new Field(); if (isset($fieldArray['name']) && is_string($fieldArray['name'])) { $field->setName($fieldArray['name']); } if (isset($fieldArray['type']) && is_string($fieldArray['type'])) { $field->setType($fieldArray['type']); } if (isset($fieldArray['value'])) { $field->setValue($fieldArray['value']); } $fields[] = $field; } return $fields; }
php
{ "resource": "" }
q261138
Handler.getLinksFromDataArray
test
protected function getLinksFromDataArray(array $linksArray) { $links = array(); foreach ($linksArray as $linkArray) { $link = new Link(); if (isset($linkArray['rel']) && is_array($linkArray['rel'])) { $link->setRel($linkArray['rel']); } if (isset($linkArray['href']) && is_string($linkArray['href'])) { $link->setHref($linkArray['href']); } $links[] = $link; } return $links; }
php
{ "resource": "" }
q261139
CurlHttpClient.send
test
public function send(RequestInterface $request) { $deferred = new Deferred(); try { $response = $this->call($request); $deferred->resolve($response); } catch (\Exception $caught) { $deferred->reject($caught); } return $deferred->promise(); }
php
{ "resource": "" }
q261140
CurlHttpClient.call
test
private function call(RequestInterface $request) { $this->prepare($request); $result = curl_exec($this->handler); if (curl_errno($this->handler) !== 0) { throw new RuntimeException( "Error connecting to server: ".curl_error($this->handler) ); } $response = $this->createResponse($result); $this->checkClientError($response, $request); $this->checkServerError($response, $request); return $response; }
php
{ "resource": "" }
q261141
CurlHttpClient.prepare
test
private function prepare(RequestInterface $request) { $this->reset($this->handler); $this->setUrl($request); $this->options[CURLOPT_CUSTOMREQUEST] = $request->getMethod(); $this->setHeaders($request); $this->options[CURLOPT_POSTFIELDS] = (string) $request->getBody(); if ($this->auth instanceof HttpClientAuthentication) { $this->options[CURLOPT_USERPWD] = "{$this->auth->username()}:{$this->auth->password()}"; $this->options[CURLOPT_HTTPAUTH] = $this->auth->type(); } curl_setopt_array($this->handler, $this->options); }
php
{ "resource": "" }
q261142
CurlHttpClient.setUrl
test
private function setUrl(RequestInterface $request) { $target = $request->getRequestTarget(); $parts = parse_url($target); $uri = $this->url instanceof Uri ? $this->url : $request->getUri(); $uri = $uri->withPath($parts['path']); $uri = array_key_exists('query', $parts) ? $uri->withQuery($parts['query']) : $uri; $this->options[CURLOPT_URL] = (string) $uri; }
php
{ "resource": "" }
q261143
CurlHttpClient.setHeaders
test
private function setHeaders(RequestInterface $request) { $headers = []; foreach ($request->getHeaders() as $header => $values) { $headers[] = "{$header}: ".implode('; ', $values); } $this->options[CURLOPT_HTTPHEADER] = $headers; }
php
{ "resource": "" }
q261144
CurlHttpClient.createResponse
test
private function createResponse($result) { $status = curl_getinfo($this->handler, CURLINFO_HTTP_CODE); list($header, $body) = $this->splitHeaderFromBody($result); return new Response($status, trim($body), $this->parseHeaders($header)); }
php
{ "resource": "" }
q261145
CurlHttpClient.splitHeaderFromBody
test
private function splitHeaderFromBody($result) { $header_size = curl_getinfo($this->handler, CURLINFO_HEADER_SIZE); $header = substr($result, 0, $header_size); $body = substr($result, $header_size); return [trim($header), trim($body)]; }
php
{ "resource": "" }
q261146
CurlHttpClient.parseHeaders
test
private function parseHeaders($header) { $lines = explode("\n", $header); $headers = []; foreach ($lines as $line) { if (strpos($line, ':') === false) { continue; } $middle=explode(":", $line); $headers[trim($middle[0])] = trim($middle[1]); } return $headers; }
php
{ "resource": "" }
q261147
Profiler.countTotalLogType
test
public function countTotalLogType($logtype) { $count = 0; if (isset($this->log_sections['Logs']) && is_array($this->log_sections['Logs'])) { foreach ($this->log_sections['Logs'] as $item) { if (isset($item['logtype']) && $item['logtype'] == $logtype) { $count++; } }// endforeach; unset($item); } return $count; }
php
{ "resource": "" }
q261148
Profiler.display
test
public function display($dbh = '', $display_db_function = '') { $this->gatherAll(); global $rundizProfilerBeautifulIndent; $rundizProfilerBeautifulIndent = $this->beautifulIndent; // return display views. ob_start(); require __DIR__.DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'display.php'; $this->reset(); $output = ob_get_contents(); ob_end_clean(); return $output; }
php
{ "resource": "" }
q261149
Profiler.gatherFiles
test
private function gatherFiles() { if (!array_key_exists('Files', $this->log_sections)) { return ; } $files = get_included_files(); $section_data_array = []; $total_size = 0; $largest_size = 0; if (is_array($files)) { foreach ($files as $file) { $size = filesize($file); $section_data_array[] = [ 'data' => $file, 'size' => $size, ]; $total_size = bcadd($total_size, $size); if ($size > $largest_size) { $largest_size = $size; } }// endforeach; unset($file, $size); } $section_data_array['total_size'] = $total_size; $section_data_array['largest_size'] = $largest_size; unset($largest_size, $total_size); $this->log_sections['Files'] = $section_data_array; unset($files, $section_data_array); }
php
{ "resource": "" }
q261150
Profiler.gatherInputGet
test
private function gatherInputGet() { if (!array_key_exists('Get', $this->log_sections)) { return ; } $section_data_array = []; if (isset($_GET) && is_array($_GET)) { foreach ($_GET as $name => $value) { $section_data_array[] = [ 'data' => $name, 'inputvalue' => $value, ]; }// endforeach; unset($name, $value); } $this->log_sections['Get'] = $section_data_array; unset($section_data_array); }
php
{ "resource": "" }
q261151
Profiler.gatherInputPost
test
private function gatherInputPost() { if (!array_key_exists('Post', $this->log_sections)) { return ; } $section_data_array = []; if (isset($_POST) && is_array($_POST)) { foreach ($_POST as $name => $value) { $section_data_array[] = [ 'data' => $name, 'inputvalue' => $value, ]; }// endforeach; unset($name, $value); } $this->log_sections['Post'] = $section_data_array; unset($section_data_array); }
php
{ "resource": "" }
q261152
Profiler.gatherInputSession
test
private function gatherInputSession() { if (!array_key_exists('Session', $this->log_sections)) { return ; } $section_data_array = []; if (isset($_SESSION) && is_array($_SESSION)) { foreach ($_SESSION as $name => $value) { $section_data_array[] = [ 'data' => $name, 'inputvalue' => $value, ]; }// endforeach; unset($name, $value); } $this->log_sections['Session'] = $section_data_array; unset($section_data_array); }
php
{ "resource": "" }
q261153
Profiler.getMicrotime
test
public function getMicrotime($at_start = false) { if ($at_start === true && is_array($_SERVER) && array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) { return floatval($_SERVER['REQUEST_TIME_FLOAT']); } return floatval(microtime(true)); }
php
{ "resource": "" }
q261154
Profiler.summaryMatchKey
test
public function summaryMatchKey($section, $matchKey, $sectionKey) { if (!is_string($section)) { $section = null; } if (!is_string($matchKey)) { $matchKey = null; } if (!is_numeric($sectionKey)) { $sectionKey = 0; } $output = ''; if (isset($this->log_sections[$section]) && is_array($this->log_sections[$section]) && $matchKey !== null) { $matchKeyTime = []; $matchKeyMemory = []; foreach ($this->log_sections[$section] as $key => $item) { if (isset($item['matchKey']) && $item['matchKey'] == $matchKey && $key <= $sectionKey) { if (count($matchKeyMemory) >= 2 || count($matchKeyTime) >= 2) { break; } if (isset($item['time'])) { $matchKeyTime[] = $item['time']; } if (isset($item['memory'])) { $matchKeyMemory[] = $item['memory']; } } }// endforeach; unset($item, $key); if (count($matchKeyTime) >= 2) { $output = $this->getReadableTime((max($matchKeyTime)-min($matchKeyTime))*1000); } elseif (count($matchKeyMemory) >= 2) { $output = $this->getReadableFileSize(max($matchKeyMemory)-min($matchKeyMemory)); } unset($matchKeyMemory, $matchKeyTime); } return $output; }
php
{ "resource": "" }
q261155
UploadedFilesFactory.createFiles
test
public static function createFiles() { $fixer = new static(); $files = $fixer->saneFilesArray($_FILES); $fixed = []; foreach ($files as $key => $data) { $fixed[$key] = $fixer->createUploadedFile($data); } return $fixed; }
php
{ "resource": "" }
q261156
UploadedFilesFactory.createUploadedFile
test
private function createUploadedFile($data) { if (array_key_exists('tmp_name', $data)) { return UploadedFile::create($data); } $result = []; foreach ($data as $key => $datum) { $result[$key] = $this->createUploadedFile($datum); } return $result; }
php
{ "resource": "" }
q261157
UploadedFilesFactory.filesFlip
test
private function filesFlip(&$result, $keys, $value) { if (is_array($value)) { foreach ($value as $k => $v) { $newKeys = $keys; array_push($newKeys, $k); $this->filesFlip($result, $newKeys, $v); } return; } $res = $value; // Move the innermost key to the outer spot $first = array_shift($keys); array_push($keys, $first); foreach (array_reverse($keys) as $kk) { // You might think we'd say $res[$kk] = $res, but $res starts // out not as an array $res = array($kk => $res); } $result = $this->arrayMergeRecursive($result, $res); }
php
{ "resource": "" }
q261158
UploadedFilesFactory.arrayMergeRecursive
test
private function arrayMergeRecursive($array1, $array2) { if (!is_array($array1) or !is_array($array2)) { return $array2; } foreach ($array2 as $sKey2 => $sValue2) { $array1[$sKey2] = $this->arrayMergeRecursive(@$array1[$sKey2], $sValue2); } return $array1; }
php
{ "resource": "" }
q261159
SessionMiddleware.process
test
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $request = $request->withAttribute('sessionDriver', $this->sessionDriver); return $handler->handle($request); }
php
{ "resource": "" }
q261160
AdminCrudController.add
test
public function add() { // Are we creating this object from the menu add wizard? // Toss the menu_id URL variable into the session instead if (Input::get('menu_id')) { return Redirect::to($this->uri('add'))->with('menu_id', Input::get('menu_id')); } // And grab the menu_id from the session or the old input, depending on whether we're new here if (Session::has('menu_id')) { $this->data['menu_id'] = Session::get('menu_id'); } else if (Input::old('menu_id')) { $this->data['menu_id'] = Input::old('menu_id'); } $this->data['action'] = 'add'; return View::make($this->view('add-or-edit'), $this->data); }
php
{ "resource": "" }
q261161
AdminCrudController.edit
test
public function edit($id) { $Model = App::make($this->Model); $this->data[$this->singular] = $Model::withTrashed()->findOrFail($id); $this->data['action'] = 'edit'; return View::make($this->view('add-or-edit'), $this->data); }
php
{ "resource": "" }
q261162
AdminCrudController.attempt_edit
test
public function attempt_edit($id) { $Model = App::make($this->Model); $object = $Model::withTrashed()->findOrFail($id); $errors = $object->validate(); if (count($errors)) { return Redirect::to($this->uri('edit/' . $id))->withInput()->withErrors($errors); } $object->save(); return $this->edit_redirect($object); }
php
{ "resource": "" }
q261163
AdminCrudController.edit_redirect
test
public function edit_redirect($object) { return Redirect::to($this->uri('edit/' . $object->id))->with('success', ' <p>' . $this->Model . ' successfully updated.</p> <p><a href="' . $this->uri('', true) . '">Return to index</a></p> '); }
php
{ "resource": "" }
q261164
AdminCrudController.order
test
public function order() { $Model = App::make($this->Model); $orders = Input::get('orders'); $objects = $Model::whereIn('id', array_keys($orders))->get(); foreach ($objects as $object) { $object->order = $orders[$object->id]; $object->save(); } return 1; }
php
{ "resource": "" }
q261165
AdminCrudController.delete
test
public function delete($id, $ajax = false) { $Model = App::make($this->Model); $object = $Model::findOrFail($id); $object->delete(); if ($ajax) return 1; return $this->delete_redirect(); }
php
{ "resource": "" }
q261166
Request.getUploadedFiles
test
public function getUploadedFiles() { if (null === $this->uploadedFiles) { $this->uploadedFiles = UploadedFilesFactory::createFiles(); } return $this->uploadedFiles; }
php
{ "resource": "" }
q261167
Request.withUploadedFiles
test
public function withUploadedFiles(array $uploadedFiles) { if (! $this->checkUploadedFiles($uploadedFiles)) { throw new InvalidArgumentException( "The uploaded files array given has at least one leaf that is not ". "an UploadedFile object." ); } $request = clone $this; $request->uploadedFiles = $uploadedFiles; return $request; }
php
{ "resource": "" }
q261168
Request.checkUploadedFiles
test
private function checkUploadedFiles(array $files) { $valid = true; foreach ($files as $file) { if (is_array($file)) { $valid = $this->checkUploadedFiles($files); break; } if (! $file instanceof UploadedFile) { $valid = false; break; } } return $valid; }
php
{ "resource": "" }
q261169
Request.loadHeaders
test
private function loadHeaders() { foreach ($_SERVER as $key => $value) { $subset = substr($key, 0, 5); if ($subset <> 'HTTP_' && $subset <> 'CONTE') { continue; } $header = str_replace( ' ', '-', ucwords( str_replace(['http_', '_'], ['', ' '], strtolower($key)) ) ); $this->headers[$this->headerKey($header)] = [$value]; } }
php
{ "resource": "" }
q261170
Request.withAttribute
test
public function withAttribute($name, $value) { $request = clone $this; $request->attributes[$name] = $value; return $request; }
php
{ "resource": "" }
q261171
Request.withoutAttribute
test
public function withoutAttribute($name) { $request = clone $this; if (array_key_exists($name, $request->attributes)) { unset($request->attributes[$name]); } return $request; }
php
{ "resource": "" }
q261172
httpCache.checkMTime
test
static function checkMTime($mtime, $sendHeaders=null) { header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT"); $headers = function_exists("getallheaders") ? getallheaders() : (function_exists("apache_request_headers") ? apache_request_headers() : false); if (is_array($headers) && isset($headers['If-Modified-Since'])) { $client_mtime = explode(';', $headers['If-Modified-Since']); $client_mtime = @strtotime($client_mtime[0]); if ($client_mtime >= $mtime) { header('HTTP/1.1 304 Not Modified'); if (is_array($sendHeaders) && count($sendHeaders)) foreach ($sendHeaders as $header) header($header); elseif ($sendHeaders !== null) header($sendHeaders); die; } } }
php
{ "resource": "" }
q261173
Message.getHeader
test
public function getHeader($name) { $key = $this->headerKey($name); if (array_key_exists($key, $this->headers)) { return $this->headers[$key]; } return []; }
php
{ "resource": "" }
q261174
Response.setStatus
test
private function setStatus($status, $reasonPhrase = '') { HttpCodes::check($status); $this->status = intval($status, 10); if ($reasonPhrase === '') { $this->reasonPhrase = HttpCodes::reasonPhraseFor($this->status); } }
php
{ "resource": "" }
q261175
CallableMiddleware.process
test
public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { $response = self::execute($this->callable, [$request, $handler]); if (!$response instanceof ResponseInterface) { throw new UnexpectedValueException( sprintf('The middleware must return an instance of %s', ResponseInterface::class) ); } return $response; }
php
{ "resource": "" }
q261176
ToolBelt.mysql_version
test
static function mysql_version() { $version = DB::select('SELECT VERSION() AS `version`'); $version = explode('-', $version[0]->version); $version = $version[0]; return $version; }
php
{ "resource": "" }
q261177
UserManager.authenticate
test
public function authenticate(array $credentials) { list($username, $password) = $credentials; $user = $this->repository->getActiveUser($username); if (!$user) { throw new Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND); } elseif (!Passwords::verify($password, $user->password)) { throw new Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL); } elseif (Passwords::needsRehash($user->password)) { $this->repository->update($user->id, ['password' => Passwords::hash($password)]); } $data = $user->toArray(); unset($data['password']); return new Security\Identity($user->id, $user->role, $data); }
php
{ "resource": "" }
q261178
UserManager.findAll
test
public function findAll() { if ($this->user && $this->user->isInRole('root')) { return $this->repository->findAllActive(); } else { return $this->repository->findAllActive() ->where('role !=', 'root'); } }
php
{ "resource": "" }
q261179
UserManager.findAllDeactivated
test
public function findAllDeactivated() { if ($this->user && $this->user->isInRole('root')) { return $this->repository->findAll() ->where('active', '0'); } else { return $this->repository->findAll() ->where('active', '0') ->where('role !=', 'root'); } }
php
{ "resource": "" }
q261180
UserManager.add
test
public function add($data = []) { if (isset($data['email']) && isset($data['password'])) { if ((isset($data['username']) && $data['username'] === '') or !$this->useUsernames ){ $data['username'] = $data['email']; } if (!Validators::isEmail($data['email'])){ throw new \InvalidArgumentException('Bad email address format'); } if (!Validators::is($data['password'], 'string:6..')){ throw new \InvalidArgumentException('Too short password'); } $create = [ 'email' => $data['email'], 'username' => self::clearUsername($data['username']), 'password' => Passwords::hash($data['password']), ]; } else { throw new \InvalidArgumentException('We need email and password'); } if (isset($data['role'])) { $create['role'] = $data['role']; } else { $create['role'] = 'user'; } if (isset($data['name'])) { $create['name'] = $data['name']; } if ($this->isImage() && isset($data['avatar_namespace']) && isset($data['avatar_filename'])) { $create['avatar_namespace'] = $data['avatar_namespace']; $create['avatar_filename'] = $data['avatar_filename']; } $person = $this->repository->insert($create); return $person; }
php
{ "resource": "" }
q261181
Metric.getOption
test
public function getOption($value) { if(!in_array($value, $this->allowedValues, true)) { throw new InvalidOptionValueException('Invalid $metricOption argument "' . $value . '", allowed values: ' . implode(', ', $this->allowedValues)); } return '-metric ' . $value . ' '; }
php
{ "resource": "" }
q261182
Post.set_current_lang_from_post_id
test
private static function set_current_lang_from_post_id($postId) { if (WpCxense::instance()->settings->languagesIsEnabled()) { WpCxense::instance()->settings->setCurrentLocale(LanguageProvider::getPostLanguage($postId)); } }
php
{ "resource": "" }
q261183
StringCheckerTrait.isEncryptedContainer
test
public function isEncryptedContainer($encrypted, $key) { try { $data = JWT::decode($encrypted, $key); } catch(Exception $e) { return false; } return $this->isJson($data->container); }
php
{ "resource": "" }
q261184
StringCheckerTrait.isEncryptedString
test
public function isEncryptedString($encrypted, $key) { try { $data = JWT::decode($encrypted, $key); } catch(Exception $e) { return false; } return is_string($data->string); }
php
{ "resource": "" }
q261185
Dumper.dump
test
public function dump() { return $this->startFile(). $this->addNamespace(). $this->startClass(). $this->addProperties(). $this->addMethods(). $this->endClass() ; }
php
{ "resource": "" }
q261186
Dumper.exportArray
test
static public function exportArray(array $array, $indent) { $code = array(); foreach ($array as $key => $value) { if (is_array($value)) { $value = self::exportArray($value, $indent + 4); } else { $value = null === $value ? 'null' : var_export($value, true); } $code[] = sprintf('%s%s => %s,', str_repeat(' ', $indent), var_export($key, true), $value); } return sprintf("array(\n%s\n%s)", implode("\n", $code), str_repeat(' ', $indent - 4)); }
php
{ "resource": "" }
q261187
Extension.preGlobalProcess
test
public function preGlobalProcess(\ArrayObject $configClasses, Container $container) { $this->configClasses = $configClasses; $this->definitions = $container; $this->doPreGlobalProcess(); $this->configClasses = null; $this->definitions = null; }
php
{ "resource": "" }
q261188
Extension.postGlobalProcess
test
public function postGlobalProcess(\ArrayObject $configClasses, Container $container) { $this->configClasses = $configClasses; $this->definitions = $container; $this->doPostGlobalProcess(); $this->configClasses = null; $this->definitions = null; }
php
{ "resource": "" }
q261189
ParseException.noTokenForTokenTypes
test
public static function noTokenForTokenTypes($tokenTypes) : ParseException { $message = "No token could be found for any of types "; $message .= join(", ", $tokenTypes); return new ParseException($message, self::NO_TOKEN); }
php
{ "resource": "" }
q261190
ContainerFactory.make
test
public function make($from, $type) { $type = $type ?: static::SIMPLE; switch ($type) { case static::SIMPLE: return new Container($from); case static::REVERTABLE: return new RevertableContainer($from); default: throw new InvalidArgumentException('Argument 2 is invalid'); } }
php
{ "resource": "" }
q261191
TSoftDelete.recover
test
public function recover($id, $user = TRUE) { $recover = array( 'deleted_at' => NULL, ); if ($user) { $recover['deleted_by'] = NULL; } $this->rawGet($id)->update($recover); return $this->get($id); }
php
{ "resource": "" }
q261192
ClassExtension.newClassExtensionsProcess
test
public function newClassExtensionsProcess($class, \ArrayObject $configClasses, \ArrayObject $newClassExtensions) { $this->class = $class; $this->configClasses = $configClasses; $this->configClass = $configClasses[$class]; $this->newClassExtensions = $newClassExtensions; $this->doNewClassExtensionsProcess(); $this->class = null; $this->configClasses = null; $this->configClass = null; $this->newClassExtensions = null; }
php
{ "resource": "" }
q261193
ClassExtension.newConfigClassesProcess
test
public function newConfigClassesProcess($class, \ArrayObject $configClasses, \ArrayObject $newConfigClasses) { $this->class = $class; $this->configClasses = $configClasses; $this->configClass = $configClasses[$class]; $this->newConfigClasses = $newConfigClasses; $this->doNewConfigClassesProcess(); $this->class = null; $this->configClasses = null; $this->configClass = null; $this->newConfigClasses = null; }
php
{ "resource": "" }
q261194
ClassExtension.configClassProcess
test
public function configClassProcess($class, \ArrayObject $configClasses) { $this->class = $class; $this->configClasses = $configClasses; $this->configClass = $configClasses[$class]; $this->doConfigClassProcess(); $this->class = null; $this->configClasses = null; $this->configClass = null; }
php
{ "resource": "" }
q261195
ClassExtension.classProcess
test
public function classProcess($class, \ArrayObject $configClasses, Container $container) { $this->class = $class; $this->configClasses = $configClasses; $this->configClass = $configClasses[$class]; $this->definitions = $container; $this->doClassProcess(); $this->class = null; $this->configClasses = null; $this->configClass = null; $this->definitions = null; }
php
{ "resource": "" }
q261196
Container.setDefinitions
test
public function setDefinitions(array $definitions) { $this->definitions = array(); foreach ($definitions as $name => $definition) { $this->setDefinition($name, $definition); } }
php
{ "resource": "" }
q261197
Container.getDefinition
test
public function getDefinition($name) { if (!$this->hasDefinition($name)) { throw new \InvalidArgumentException(sprintf('The definition "%s" does not exists.', $name)); } return $this->definitions[$name]; }
php
{ "resource": "" }
q261198
Container.removeDefinition
test
public function removeDefinition($name) { if (!$this->hasDefinition($name)) { throw new \InvalidArgumentException(sprintf('The definition "%s" does not exists.', $name)); } unset($this->definitions[$name]); }
php
{ "resource": "" }
q261199
Mondator.setConfigClasses
test
public function setConfigClasses(array $configClasses) { $this->configClasses = array(); foreach ($configClasses as $class => $configClass) { $this->setConfigClass($class, $configClass); } }
php
{ "resource": "" }