_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q2800
Uri.getNormalizedUriPath
train
private function getNormalizedUriPath() { $path = $this->getPath(); if ($this->getAuthority() === '') { return preg_replace('#^/+#', '/', $path); } elseif ($path === '' || $path[0] === '/') { return $path; } return '/' . $path; }
php
{ "resource": "" }
q2801
RedisCacheService.hGet
train
public function hGet($hashKey, $key) { $value = $this->redis->hGet($hashKey, $key); if ($value) { $value = gzinflate($value); } $jsonData = json_decode($value, true); return ($jsonData === NULL) ? $value : $jsonData; }
php
{ "resource": "" }
q2802
RedisCacheService.hSet
train
public function hSet($hashKey, $key, $data, $expireTime = 3600) { $data = (is_object($data) || is_array($data)) ? json_encode($data) : $data; $data = gzdeflate($data, 0); if (strlen($data) > 4096) { $data = gzdeflate($data, 6); } $status = $this->redis->hSet($hashKey, $key, $data); $this->redis->expire($hashKey, $expireTime); return $status; }
php
{ "resource": "" }
q2803
Negotiation.header
train
public function header($header, $level = self::HIGH) { $header = strtolower($header); if (empty($this->headers[$header])) { return false; } return self::qFactor($this->headers[$header], $level); }
php
{ "resource": "" }
q2804
Negotiation.qFactor
train
public static function qFactor($value, $level = self::HIGH) { $multivalues = explode(',', $value); $headers = array(); foreach ($multivalues as $hvalues) { if (substr_count($hvalues, ';') > 1) { throw new Exception('Header contains a value with multiple semicolons: "' . $value . '"', 2); } $current = explode(';', $hvalues, 2); if (empty($current[1])) { $qvalue = 1.0; } else { $qvalue = self::parseQValue($current[1]); } $headers[ trim($current[0]) ] = $qvalue; } $multivalues = null; if ($level === self::ALL) { return array_keys($headers); } if ($level === self::LOW) { asort($headers, SORT_NUMERIC); } else { arsort($headers, SORT_NUMERIC); } return $headers; }
php
{ "resource": "" }
q2805
Select.joinCondition
train
public function joinCondition() { if (!isset($this->_joinCondition)) { $this->_joinCondition = Factory::filter($this); } return $this->_joinCondition; }
php
{ "resource": "" }
q2806
File.portion
train
public static function portion($path, $init = 0, $end = 1024, $lines = false) { self::fullpath($path); if ($lines !== true) { return file_get_contents($path, false, null, $init, $end); } $i = 1; $output = ''; $handle = fopen($path, 'rb'); while (false === feof($handle) && $i <= $end) { $data = fgets($handle); if ($i >= $init) { $output .= $data; } ++$i; } fclose($handle); return $output; }
php
{ "resource": "" }
q2807
File.isBinary
train
public static function isBinary($path) { self::fullpath($path); $size = filesize($path); if ($size >= 0 && $size < 2) { return false; } $finfo = finfo_open(FILEINFO_MIME_ENCODING); $encode = finfo_buffer($finfo, file_get_contents($path, false, null, 0, 5012)); finfo_close($finfo); return strcasecmp($encode, 'binary') === 0; }
php
{ "resource": "" }
q2808
File.size
train
public static function size($path) { $path = ltrim(self::fullpath($path), '/'); $ch = curl_init('file://' . $path); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); $headers = curl_exec($ch); curl_close($ch); $ch = null; if (preg_match('#content-length:(\s+?|)(\d+)#i', $headers, $matches)) { return $matches[2]; } return false; }
php
{ "resource": "" }
q2809
Selector.get
train
public function get($selector, \DOMNode $context = null, $registerNodeNS = true) { return $this->exec('query', $selector, $context, $registerNodeNS); }
php
{ "resource": "" }
q2810
AbstractEvent.isRunning
train
public function isRunning(Datetime $current = null) { $current = $current ?: new Datetime; return $this->hasStarted($current) && !$this->hasEnded($current); }
php
{ "resource": "" }
q2811
AbstractEvent.detach
train
public function detach() { $this->calendar->getEvents()->removeEvent($this); $this->calendar = null; return $this; }
php
{ "resource": "" }
q2812
DefaultCertificateValidator.validateCert
train
public function validateCert($certPem) { if ($this->getCaCert()) { self::validate($certPem, $this->getCaCert(), $this->getCrl(), $this->getCrlDistCert()); } }
php
{ "resource": "" }
q2813
DefaultCertificateValidator.getCrlUrl
train
public function getCrlUrl() { if ($this->crlUrl === self::AUTOLOAD) { $this->crlUrl = NULL; // Default if we can't find something else. $caCertObj = X509Util::loadCACert($this->getCaCert()); // There can be multiple DPs, but in practice CiviRootCA only has one. $crlDPs = $caCertObj->getExtension('id-ce-cRLDistributionPoints'); if (is_array($crlDPs)) { foreach ($crlDPs as $crlDP) { foreach ($crlDP['distributionPoint']['fullName'] as $fullName) { if (isset($fullName['uniformResourceIdentifier'])) { $this->crlUrl = $fullName['uniformResourceIdentifier']; break 2; } } } } } return $this->crlUrl; }
php
{ "resource": "" }
q2814
UriPattern.matchUri
train
public function matchUri($uri, & $matches = []) { if ($this->matchAbsoluteUri($uri, $matches)) { return true; } return $this->matchRelativeUri($uri, $matches); }
php
{ "resource": "" }
q2815
UriPattern.match
train
private function match($pattern, $subject, & $matches) { $matches = []; $subject = (string) $subject; if ($this->allowNonAscii || preg_match('/^[\\x00-\\x7F]*$/', $subject)) { if (preg_match($pattern, $subject, $match)) { $matches = $this->getNamedPatterns($match); return true; } } return false; }
php
{ "resource": "" }
q2816
UriPattern.getNamedPatterns
train
private function getNamedPatterns($matches) { foreach ($matches as $key => $value) { if (!is_string($key) || strlen($value) < 1) { unset($matches[$key]); } } return $matches; }
php
{ "resource": "" }
q2817
UriPattern.buildPatterns
train
private static function buildPatterns() { $alpha = 'A-Za-z'; $digit = '0-9'; $hex = $digit . 'A-Fa-f'; $unreserved = "$alpha$digit\\-._~"; $delimiters = "!$&'()*+,;="; $utf8 = '\\x80-\\xFF'; $octet = "(?:[$digit]|[1-9][$digit]|1[$digit]{2}|2[0-4]$digit|25[0-5])"; $ipv4address = "(?>$octet\\.$octet\\.$octet\\.$octet)"; $encoded = "%[$hex]{2}"; $h16 = "[$hex]{1,4}"; $ls32 = "(?:$h16:$h16|$ipv4address)"; $data = "[$unreserved$delimiters:@$utf8]++|$encoded"; // Defining the scheme $scheme = "(?'scheme'(?>[$alpha][$alpha$digit+\\-.]*+))"; // Defining the authority $ipv6address = "(?'IPv6address'" . "(?:(?:$h16:){6}$ls32)|" . "(?:::(?:$h16:){5}$ls32)|" . "(?:(?:$h16)?::(?:$h16:){4}$ls32)|" . "(?:(?:(?:$h16:){0,1}$h16)?::(?:$h16:){3}$ls32)|" . "(?:(?:(?:$h16:){0,2}$h16)?::(?:$h16:){2}$ls32)|" . "(?:(?:(?:$h16:){0,3}$h16)?::$h16:$ls32)|" . "(?:(?:(?:$h16:){0,4}$h16)?::$ls32)|" . "(?:(?:(?:$h16:){0,5}$h16)?::$h16)|" . "(?:(?:(?:$h16:){0,6}$h16)?::))"; $regularName = "(?'reg_name'(?>(?:[$unreserved$delimiters$utf8]++|$encoded)*))"; $ipvFuture = "(?'IPvFuture'v[$hex]++\\.[$unreserved$delimiters:]++)"; $ipLiteral = "(?'IP_literal'\\[(?>$ipv6address|$ipvFuture)\\])"; $port = "(?'port'(?>[$digit]*+))"; $host = "(?'host'$ipLiteral|(?'IPv4address'$ipv4address)|$regularName)"; $userInfo = "(?'userinfo'(?>(?:[$unreserved$delimiters:$utf8]++|$encoded)*))"; $authority = "(?'authority'(?:$userInfo@)?$host(?::$port)?)"; // Defining the path $segment = "(?>(?:$data)*)"; $segmentNotEmpty = "(?>(?:$data)+)"; $segmentNoScheme = "(?>([$unreserved$delimiters@$utf8]++|$encoded)+)"; $pathAbsoluteEmpty = "(?'path_abempty'(?:/$segment)*)"; $pathAbsolute = "(?'path_absolute'/(?:$segmentNotEmpty(?:/$segment)*)?)"; $pathNoScheme = "(?'path_noscheme'$segmentNoScheme(?:/$segment)*)"; $pathRootless = "(?'path_rootless'$segmentNotEmpty(?:/$segment)*)"; $pathEmpty = "(?'path_empty')"; // Defining other parts $query = "(?'query'(?>(?:$data|[/?])*))"; $fragment = "(?'fragment'(?>(?:$data|[/?])*))"; $absolutePath = "(?'hier_part'//$authority$pathAbsoluteEmpty|$pathAbsolute|$pathRootless|$pathEmpty)"; $relativePath = "(?'relative_part'//$authority$pathAbsoluteEmpty|$pathAbsolute|$pathNoScheme|$pathEmpty)"; self::$absoluteUri = "#^$scheme:$absolutePath(?:\\?$query)?(?:\\#$fragment)?$#"; self::$relativeUri = "#^$relativePath(?:\\?$query)?(?:\\#$fragment)?$#"; self::$scheme = "#^$scheme$#"; self::$host = "#^$host$#"; }
php
{ "resource": "" }
q2818
FileSystem.createDirectories
train
public static function createDirectories(string $path, int $mode = 0777) : void { $exception = null; try { $success = ErrorCatcher::run(static function() use ($path, $mode) { return mkdir($path, $mode, true); }); if ($success === true) { return; } } catch (\ErrorException $e) { $exception = $e; } if (self::isDirectory($path)) { return; } throw new IoException('Error creating directories ' . $path, 0, $exception); }
php
{ "resource": "" }
q2819
FileSystem.isFile
train
public static function isFile(string $path) : bool { try { return ErrorCatcher::run(static function() use ($path) { return is_file($path); }); } catch (\ErrorException $e) { throw new IoException('Error checking if ' . $path . ' is a file', 0, $e); } }
php
{ "resource": "" }
q2820
FileSystem.isDirectory
train
public static function isDirectory(string $path) : bool { try { return ErrorCatcher::run(static function() use ($path) { return is_dir($path); }); } catch (\ErrorException $e) { throw new IoException('Error checking if ' . $path . ' is a directory', 0, $e); } }
php
{ "resource": "" }
q2821
FileSystem.isSymbolicLink
train
public static function isSymbolicLink(string $path) : bool { try { return ErrorCatcher::run(static function() use ($path) { return is_link($path); }); } catch (\ErrorException $e) { throw new IoException('Error checking if ' . $path . ' is a symbolic link', 0, $e); } }
php
{ "resource": "" }
q2822
FileSystem.createSymbolicLink
train
public static function createSymbolicLink(string $link, string $target) : void { $exception = null; try { $success = ErrorCatcher::run(static function() use ($link, $target) { return symlink($target, $link); }); if ($success === true) { return; } } catch (\ErrorException $e) { $exception = $e; } throw new IoException('Error creating symbolic link ' . $link . ' to ' . $target, 0, $exception); }
php
{ "resource": "" }
q2823
FileSystem.readSymbolicLink
train
public static function readSymbolicLink(string $path) : string { $exception = null; try { $result = ErrorCatcher::run(static function() use ($path) { return readlink($path); }); if ($result !== false) { return $result; } } catch (\ErrorException $e) { $exception = $e; } throw new IoException('Error reading symbolic link ' . $path, 0, $exception); }
php
{ "resource": "" }
q2824
FileSystem.getRealPath
train
public static function getRealPath(string $path) : string { $exception = null; try { $result = ErrorCatcher::run(static function() use ($path) { return realpath($path); }); if ($result !== false) { return $result; } } catch (\ErrorException $e) { $exception = $e; } throw new IoException('Error getting real path of ' . $path . ', check that the path exists', 0, $exception); }
php
{ "resource": "" }
q2825
FileSystem.write
train
public static function write(string $path, $data, bool $append = false, bool $lock = false) : int { $flags = 0; if ($append) { $flags |= FILE_APPEND; } if ($lock) { $flags |= LOCK_EX; } $exception = null; try { $result = ErrorCatcher::run(static function() use ($path, $data, $flags) { return file_put_contents($path, $data, $flags); }); if ($result !== false) { return $result; } } catch (\ErrorException $e) { $exception = $e; } throw new IoException('Error writing to ' . $path, 0, $exception); }
php
{ "resource": "" }
q2826
FileSystem.read
train
public static function read(string $path, int $offset = 0, int $maxLength = null) : string { $exception = null; try { $result = ErrorCatcher::run(static function() use ($path, $offset, $maxLength) { if ($maxLength === null) { return file_get_contents($path, false, null, $offset); } return file_get_contents($path, false, null, $offset, $maxLength); }); if ($result !== false) { return $result; } } catch (\ErrorException $e) { $exception = $e; } throw new IoException('Error reading from ' . $path, 0, $exception); }
php
{ "resource": "" }
q2827
Curl.getInfo
train
public function getInfo(int $opt = null) { if ($opt === null) { return curl_getinfo($this->curl); } return curl_getinfo($this->curl, $opt); }
php
{ "resource": "" }
q2828
UriParser.parse
train
public function parse($uri) { if (!$this->isValidString($uri)) { return null; } $pattern = new UriPattern(); $pattern->allowNonAscii($this->mode !== self::MODE_RFC3986); if ($pattern->matchUri($uri, $match)) { try { return $this->buildUri($match); } catch (\InvalidArgumentException $exception) { return null; } } return null; }
php
{ "resource": "" }
q2829
UriParser.isValidString
train
private function isValidString($uri) { if (preg_match('/^[\\x00-\\x7F]*$/', $uri)) { return true; } elseif ($this->mode === self::MODE_RFC3986) { return false; } // Validate UTF-8 via regular expression to avoid mbstring dependency $pattern = '/^(?> [\x00-\x7F]+ # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding over longs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$/x'; return (bool) preg_match($pattern, $uri); }
php
{ "resource": "" }
q2830
UriParser.buildUri
train
private function buildUri(array $components) { $uri = new Uri(); if (isset($components['reg_name'])) { $components['host'] = $this->decodeHost($components['host']); } foreach (array_intersect_key(self::$setters, $components) as $key => $method) { $uri = call_user_func([$uri, $method], $components[$key]); } if (isset($components['userinfo'])) { list($username, $password) = preg_split('/:|$/', $components['userinfo'], 2); $uri = $uri->withUserInfo(rawurldecode($username), rawurldecode($password)); } return $uri; }
php
{ "resource": "" }
q2831
UriParser.decodeHost
train
private function decodeHost($hostname) { if (preg_match('/^[\\x00-\\x7F]*$/', $hostname)) { return $hostname; } elseif ($this->mode !== self::MODE_IDNA2003) { throw new \InvalidArgumentException("Invalid hostname '$hostname'"); } $hostname = idn_to_ascii($hostname); if ($hostname === false) { throw new \InvalidArgumentException("Invalid hostname '$hostname'"); } return $hostname; }
php
{ "resource": "" }
q2832
App.env
train
public static function env($key, $value = null) { if (is_string($value) || is_bool($value) || is_numeric($value)) { self::$configs[$key] = $value; } elseif ($value === null && isset(self::$configs[$key])) { return self::$configs[$key]; } }
php
{ "resource": "" }
q2833
App.config
train
public static function config($path) { $data = \UtilsSandboxLoader('application/Config/' . strtr($path, '.', '/') . '.php'); foreach ($data as $key => $value) { self::env($key, $value); } $data = null; }
php
{ "resource": "" }
q2834
App.trigger
train
public static function trigger($name, array $args = array()) { if ($name === 'error') { self::$state = 5; } if (empty(self::$events[$name])) { return null; } $listen = self::$events[$name]; usort($listen, function ($a, $b) { return $b[1] >= $a[1]; }); foreach ($listen as $callback) { call_user_func_array($callback[0], $args); } $listen = null; }
php
{ "resource": "" }
q2835
App.off
train
public static function off($name, $callback = null) { if (empty(self::$events[$name])) { return null; } elseif ($callback === null) { self::$events[$name] = array(); return null; } $evts = self::$events[$name]; foreach ($evts as $key => $value) { if ($value[0] === $callback) { unset($evts[$key]); } } self::$events[$name] = $evts; $evts = null; }
php
{ "resource": "" }
q2836
App.stop
train
public static function stop($code, $msg = null) { Response::status($code, false) && self::trigger('changestatus', array($code, $msg)); if (self::$state < 4) { self::$state = 4; self::trigger('finish'); } exit; }
php
{ "resource": "" }
q2837
App.exec
train
public static function exec() { if (self::$state > 0) { return null; } self::$state = 1; self::trigger('init'); if (self::env('maintenance')) { self::$state = 4; self::stop(503); } self::trigger('changestatus', array(\UtilsStatusCode(), null)); $resp = Route::get(); if (is_integer($resp)) { self::$state = 5; self::stop($resp, 'Invalid route'); } $callback = $resp['callback']; if (!$callback instanceof \Closure) { $parsed = explode(':', $callback, 2); $callback = '\\Controller\\' . strtr($parsed[0], '.', '\\'); $callback = array(new $callback, $parsed[1]); } $output = call_user_func_array($callback, $resp['args']); if (class_exists('\\Inphinit\\Http\\Response', false)) { Response::dispatch(); } if (class_exists('\\Inphinit\\Viewing\\View', false)) { View::dispatch(); } if (self::$state < 2) { self::$state = 2; } self::trigger('ready'); if ($output || is_numeric($output)) { echo $output; } if (self::$state < 3) { self::$state = 3; } self::trigger('finish'); if (self::$state < 4) { self::$state = 4; } }
php
{ "resource": "" }
q2838
FixedArray.swap
train
public function swap(int $index1, int $index2) : void { if ($index1 !== $index2) { $value = $this[$index1]; $this[$index1] = $this[$index2]; $this[$index2] = $value; } }
php
{ "resource": "" }
q2839
FixedArray.shiftUp
train
public function shiftUp(int $index) : void { if ($index + 1 === $this->count()) { return; } $this->swap($index, $index + 1); }
php
{ "resource": "" }
q2840
FixedArray.shiftTo
train
public function shiftTo(int $index, int $newIndex) : void { while ($index > $newIndex) { $this->shiftDown($index); $index--; } while ($index < $newIndex) { $this->shiftUp($index); $index++; } }
php
{ "resource": "" }
q2841
PadStringExtension.padStringFilter
train
public function padStringFilter($value, $padCharacter, $maxLength, $padType = 'STR_PAD_RIGHT') { if ($this->isNullOrEmptyString($padCharacter)) { throw new \InvalidArgumentException('Pad String Filter cannot accept a null value or empty string as its first argument'); } if ( ! is_int($maxLength)) { throw new \InvalidArgumentException('Pad String Filter expects its second argument to be an integer'); } $diff = (function_exists('mb_strlen'))? strlen($value) - mb_strlen($value) : 0; $padType = constant($padType); return str_pad($value, $maxLength + $diff, $padCharacter, $padType); }
php
{ "resource": "" }
q2842
OpenGraphGenerator.generate
train
public function generate() { $html = array(); foreach ($this->properties as $property => $value): if (is_array($value)): foreach ($value as $_value) { $html[] = strtr( static::OPENGRAPH_TAG, array( '[property]' => static::OPENGRAPH_PREFIX . $property, '[value]' => $_value ) ); } else: $html[] = strtr( static::OPENGRAPH_TAG, array( '[property]' => static::OPENGRAPH_PREFIX . $property, '[value]' => $value ) ); endif; endforeach; return implode(PHP_EOL, $html); }
php
{ "resource": "" }
q2843
OpenGraphGenerator.fromRaw
train
public function fromRaw($properties) { $this->validateProperties($properties); foreach ($properties as $property => $value) { $this->properties[$property] = $value; } }
php
{ "resource": "" }
q2844
OpenGraphGenerator.fromObject
train
public function fromObject(OpenGraphAware $object) { $properties = $object->getOpenGraphData(); $this->validateProperties($properties); foreach ($properties as $property => $value) { $this->properties[$property] = $value; } }
php
{ "resource": "" }
q2845
OpenGraphGenerator.validateProperties
train
protected function validateProperties($properties) { foreach ($this->required as $required) { if (!array_key_exists($required, $properties)) { throw new \InvalidArgumentException("Required open graph property [$required] is not present."); } } }
php
{ "resource": "" }
q2846
DataTablesTwigExtension.jQueryDataTablesStandaloneFunction
train
public function jQueryDataTablesStandaloneFunction(array $args = []) { return $this->jQueryDataTablesStandalone(ArrayHelper::get($args, "selector", ".table"), ArrayHelper::get($args, "language"), ArrayHelper::get($args, "options", [])); }
php
{ "resource": "" }
q2847
HttpRequest.execute
train
public function execute() { $ch = \curl_init(); $this->setAuth($ch); try { switch (strtoupper($this->method)) { case 'GET': $this->executeGet($ch); break; case 'POST': $this->executePost($ch); break; case 'PUT': $this->executePut($ch); break; case 'PATCH': $this->executePatch($ch); break; case 'DELETE': $this->executeDelete($ch); break; // This custom case is used to execute a Multipart PUT request case 'PUT_MP': $this->method = 'PUT'; $this->executePutMultipart($ch); break; case 'POST_MP': $this->method = 'POST'; $this->executePostMultipart($ch); break; default: throw new \InvalidArgumentException('Current method (' . $this->method . ') is an invalid REST method.'); } } catch (\InvalidArgumentException $e) { \curl_close($ch); throw $e; } catch (\Exception $e) { \curl_close($ch); throw $e; } }
php
{ "resource": "" }
q2848
HttpRequest.buildPostBody
train
public function buildPostBody($data = null) { $reqBody = ($data !== null) ? $data : $this->request_body; $this->request_body = (string) $reqBody; }
php
{ "resource": "" }
q2849
HttpRequest.executePutMultipart
train
protected function executePutMultipart($ch) { $xml = $this->request_body; $uri_string = $this->file_to_upload[0]; $file_name = $this->file_to_upload[1]; $post = array( 'ResourceDescriptor' => $xml, $uri_string => '@' . $file_name . ';filename=' . basename($file_name) ); \curl_setopt($ch, CURLOPT_TIMEOUT, 10); \curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); \curl_setopt($ch, CURLOPT_POSTFIELDS, $post); \curl_setopt($ch, CURLOPT_URL, $this->url); \curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $this->response_body = \curl_exec($ch); $this->response_info = \curl_getinfo($ch); \curl_close($ch); }
php
{ "resource": "" }
q2850
HttpRequest.doExecute
train
protected function doExecute(&$curlHandle) { $this->setCurlOpts($curlHandle); $response = \curl_exec($curlHandle); $header_size = \curl_getinfo($curlHandle, CURLINFO_HEADER_SIZE); $this->response_body = substr($response, $header_size); $this->response_headers = []; $lines = explode("\r\n", substr($response, 0, $header_size)); foreach ($lines as $i => $line) { if ($i === 0) { $this->response_headers['http_code'] = $line; $piece = explode(" ", $line); if (count($piece) > 1) { $this->response_headers['protocol'] = $piece[0]; $this->response_headers['status_code'] = $piece[1]; array_splice($piece, 0, 2); //Remove protocol and code $this->response_headers['reason_phrase'] = implode(" ", $piece); } } else { $piece = explode(': ', $line, 2); if (count($piece) == 2) { list ($key, $value) = $piece; if (trim($key) !== "") { $this->response_headers[$key] = trim($value); } } } } $this->response_info = \curl_getinfo($curlHandle); \curl_close($curlHandle); }
php
{ "resource": "" }
q2851
HttpRequest.setCurlOpts
train
protected function setCurlOpts(&$curlHandle) { \curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10); \curl_setopt($curlHandle, CURLOPT_URL, $this->url); \curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); \curl_setopt($curlHandle, CURLOPT_VERBOSE, false); \curl_setopt($curlHandle, CURLOPT_HEADER, true); \curl_setopt($curlHandle, CURLOPT_COOKIEFILE, '/dev/null'); \curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $this->getDefaultHeader()); }
php
{ "resource": "" }
q2852
HttpRequest.setAuth
train
protected function setAuth(&$curlHandle) { if ($this->username !== null && $this->password !== null) { \curl_setopt($curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); \curl_setopt($curlHandle, CURLOPT_USERPWD, base64_encode($this->username . ':' . $this->password)); // \curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // \curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); } }
php
{ "resource": "" }
q2853
HttpRequest.getResponseHeader
train
public function getResponseHeader($key = null) { if (null != $key) { if (array_key_exists($key, $this->response_headers)) { return $this->response_headers[$key]; } } else { return $this->response_headers; } }
php
{ "resource": "" }
q2854
Translatable.bootTranslatable
train
public static function bootTranslatable() { static::addGlobalScope(new TranslatableScope); try { $observer = app(TranslatableObserverContract::class); static::observe($observer); } catch (\Exception $exception) {} }
php
{ "resource": "" }
q2855
DataTablesNormalizer.normalizeColumn
train
public static function normalizeColumn(DataTablesColumnInterface $column) { $output = []; ArrayHelper::set($output, "cellType", $column->getCellType(), [null]); ArrayHelper::set($output, "classname", $column->getClassname(), [null]); ArrayHelper::set($output, "contentPadding", $column->getContentPadding(), [null]); ArrayHelper::set($output, "data", $column->getData(), [null]); ArrayHelper::set($output, "defaultContent", $column->getDefaultContent(), [null]); ArrayHelper::set($output, "name", $column->getName(), [null]); ArrayHelper::set($output, "orderable", $column->getOrderable(), [null, true]); ArrayHelper::set($output, "orderData", $column->getOrderData(), [null]); ArrayHelper::set($output, "orderDataType", $column->getOrderDataType(), [null]); ArrayHelper::set($output, "orderSequence", $column->getOrderSequence(), [null]); ArrayHelper::set($output, "searchable", $column->getSearchable(), [null, true]); ArrayHelper::set($output, "type", $column->getType(), [null]); ArrayHelper::set($output, "visible", $column->getVisible(), [null, true]); ArrayHelper::set($output, "width", $column->getWidth(), [null]); return $output; }
php
{ "resource": "" }
q2856
DataTablesNormalizer.normalizeResponse
train
public static function normalizeResponse(DataTablesResponseInterface $response) { $output = []; $output["data"] = $response->getData(); $output["draw"] = $response->getDraw(); $output["recordsFiltered"] = $response->getRecordsFiltered(); $output["recordsTotal"] = $response->getRecordsTotal(); return $output; }
php
{ "resource": "" }
q2857
Language.isValidCode
train
public static function isValidCode( $code ) { return strcspn( $code, ":/\\\000" ) === strlen( $code ) && !preg_match( Title::getTitleInvalidRegex(), $code ); }
php
{ "resource": "" }
q2858
Language.getLocalisationCache
train
public static function getLocalisationCache() { if ( is_null( self::$dataCache ) ) { global $wgLocalisationCacheConf; $class = $wgLocalisationCacheConf['class']; self::$dataCache = new $class( $wgLocalisationCacheConf ); } return self::$dataCache; }
php
{ "resource": "" }
q2859
Language.getGenderNsText
train
function getGenderNsText( $index, $gender ) { $ns = self::$dataCache->getItem( $this->mCode, 'namespaceGenderAliases' ); return isset( $ns[$index][$gender] ) ? $ns[$index][$gender] : $this->getNsText( $index ); }
php
{ "resource": "" }
q2860
Language.getLocalNsIndex
train
function getLocalNsIndex( $text ) { $lctext = $this->lc( $text ); $ids = $this->getNamespaceIds(); return isset( $ids[$lctext] ) ? $ids[$lctext] : false; }
php
{ "resource": "" }
q2861
Language.getNsIndex
train
function getNsIndex( $text ) { $lctext = $this->lc( $text ); if ( ( $ns = MWNamespace::getCanonicalIndex( $lctext ) ) !== null ) { return $ns; } $ids = $this->getNamespaceIds(); return isset( $ids[$lctext] ) ? $ids[$lctext] : false; }
php
{ "resource": "" }
q2862
Language.hebrewYearStart
train
private static function hebrewYearStart( $year ) { $a = intval( ( 12 * ( $year - 1 ) + 17 ) % 19 ); $b = intval( ( $year - 1 ) % 4 ); $m = 32.044093161144 + 1.5542417966212 * $a + $b / 4.0 - 0.0031777940220923 * ( $year - 1 ); if ( $m < 0 ) { $m--; } $Mar = intval( $m ); if ( $m < 0 ) { $m++; } $m -= $Mar; $c = intval( ( $Mar + 3 * ( $year - 1 ) + 5 * $b + 5 ) % 7 ); if ( $c == 0 && $a > 11 && $m >= 0.89772376543210 ) { $Mar++; } elseif ( $c == 1 && $a > 6 && $m >= 0.63287037037037 ) { $Mar += 2; } elseif ( $c == 2 || $c == 4 || $c == 6 ) { $Mar++; } $Mar += intval( ( $year - 3761 ) / 100 ) - intval( ( $year - 3761 ) / 400 ) - 24; return $Mar; }
php
{ "resource": "" }
q2863
Language.romanNumeral
train
static function romanNumeral( $num ) { static $table = array( array( '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' ), array( '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' ), array( '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', 'M' ), array( '', 'M', 'MM', 'MMM' ) ); $num = intval( $num ); if ( $num > 3000 || $num <= 0 ) { return $num; } $s = ''; for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) { if ( $num >= $pow10 ) { $s .= $table[$i][floor( $num / $pow10 )]; } $num = $num % $pow10; } return $s; }
php
{ "resource": "" }
q2864
Language.uc
train
function uc( $str, $first = false ) { if ( function_exists( 'mb_strtoupper' ) ) { if ( $first ) { if ( $this->isMultibyte( $str ) ) { return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 ); } else { return ucfirst( $str ); } } else { return $this->isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str ); } } else { if ( $this->isMultibyte( $str ) ) { $x = $first ? '^' : ''; return preg_replace_callback( "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/", array( $this, 'ucCallback' ), $str ); } else { return $first ? ucfirst( $str ) : strtoupper( $str ); } } }
php
{ "resource": "" }
q2865
Language.ucwordbreaks
train
function ucwordbreaks( $str ) { if ( $this->isMultibyte( $str ) ) { $str = $this->lc( $str ); // since \b doesn't work for UTF-8, we explicitely define word break chars $breaks = "[ \-\(\)\}\{\.,\?!]"; // find first letter after word break $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/"; if ( function_exists( 'mb_strtoupper' ) ) { return preg_replace_callback( $replaceRegexp, array( $this, 'ucwordbreaksCallbackMB' ), $str ); } else { return preg_replace_callback( $replaceRegexp, array( $this, 'ucwordsCallbackWiki' ), $str ); } } else { return preg_replace_callback( '/\b([\w\x80-\xff]+)\b/', array( $this, 'ucwordbreaksCallbackAscii' ), $str ); } }
php
{ "resource": "" }
q2866
Language.firstChar
train
function firstChar( $s ) { $matches = array(); preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' . '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})/', $s, $matches ); if ( isset( $matches[1] ) ) { if ( strlen( $matches[1] ) != 3 ) { return $matches[1]; } // Break down Hangul syllables to grab the first jamo $code = utf8ToCodepoint( $matches[1] ); if ( $code < 0xac00 || 0xd7a4 <= $code ) { return $matches[1]; } elseif ( $code < 0xb098 ) { return "\xe3\x84\xb1"; } elseif ( $code < 0xb2e4 ) { return "\xe3\x84\xb4"; } elseif ( $code < 0xb77c ) { return "\xe3\x84\xb7"; } elseif ( $code < 0xb9c8 ) { return "\xe3\x84\xb9"; } elseif ( $code < 0xbc14 ) { return "\xe3\x85\x81"; } elseif ( $code < 0xc0ac ) { return "\xe3\x85\x82"; } elseif ( $code < 0xc544 ) { return "\xe3\x85\x85"; } elseif ( $code < 0xc790 ) { return "\xe3\x85\x87"; } elseif ( $code < 0xcc28 ) { return "\xe3\x85\x88"; } elseif ( $code < 0xce74 ) { return "\xe3\x85\x8a"; } elseif ( $code < 0xd0c0 ) { return "\xe3\x85\x8b"; } elseif ( $code < 0xd30c ) { return "\xe3\x85\x8c"; } elseif ( $code < 0xd558 ) { return "\xe3\x85\x8d"; } else { return "\xe3\x85\x8e"; } } else { return ''; } }
php
{ "resource": "" }
q2867
Language.normalize
train
function normalize( $s ) { global $wgAllUnicodeFixes; $s = UtfNormal::cleanUp( $s ); if ( $wgAllUnicodeFixes ) { $s = $this->transformUsingPairFile( 'normalize-ar.ser', $s ); $s = $this->transformUsingPairFile( 'normalize-ml.ser', $s ); } return $s; }
php
{ "resource": "" }
q2868
Language.getMagic
train
function getMagic( $mw ) { $this->doMagicHook(); if ( isset( $this->mMagicExtensions[$mw->mId] ) ) { $rawEntry = $this->mMagicExtensions[$mw->mId]; } else { $magicWords = $this->getMagicWords(); if ( isset( $magicWords[$mw->mId] ) ) { $rawEntry = $magicWords[$mw->mId]; } else { $rawEntry = false; } } if ( !is_array( $rawEntry ) ) { error_log( "\"$rawEntry\" is not a valid magic word for \"$mw->mId\"" ); } else { $mw->mCaseSensitive = $rawEntry[0]; $mw->mSynonyms = array_slice( $rawEntry, 1 ); } }
php
{ "resource": "" }
q2869
Language.addMagicWordsByLang
train
function addMagicWordsByLang( $newWords ) { $code = $this->getCode(); $fallbackChain = array(); while ( $code && !in_array( $code, $fallbackChain ) ) { $fallbackChain[] = $code; $code = self::getFallbackFor( $code ); } if ( !in_array( 'en', $fallbackChain ) ) { $fallbackChain[] = 'en'; } $fallbackChain = array_reverse( $fallbackChain ); foreach ( $fallbackChain as $code ) { if ( isset( $newWords[$code] ) ) { $this->mMagicExtensions = $newWords[$code] + $this->mMagicExtensions; } } }
php
{ "resource": "" }
q2870
Language.getSpecialPageAliases
train
function getSpecialPageAliases() { // Cache aliases because it may be slow to load them if ( is_null( $this->mExtendedSpecialPageAliases ) ) { // Initialise array $this->mExtendedSpecialPageAliases = self::$dataCache->getItem( $this->mCode, 'specialPageAliases' ); wfRunHooks( 'LanguageGetSpecialPageAliases', array( &$this->mExtendedSpecialPageAliases, $this->getCode() ) ); } return $this->mExtendedSpecialPageAliases; }
php
{ "resource": "" }
q2871
Language.preConvertPlural
train
protected function preConvertPlural( /* Array */ $forms, $count ) { while ( count( $forms ) < $count ) { $forms[] = $forms[count( $forms ) - 1]; } return $forms; }
php
{ "resource": "" }
q2872
Language.getFileName
train
static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) { // Protect against path traversal if ( !Language::isValidCode( $code ) || strcspn( $code, ":/\\\000" ) !== strlen( $code ) ) { throw new MWException( "Invalid language code \"$code\"" ); } return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix; }
php
{ "resource": "" }
q2873
MorrisBase.toArray
train
public function toArray() { $return = []; foreach ( $this as $property => $value ) { if ( '__' == substr( $property, 0, 2 ) || '' === $value || is_null( $value ) || ( is_array( $value ) && empty( $value ) ) ) { continue; } if ( in_array( $property, $this->functions ) && substr( $value, 0, 8 ) == 'function' ) { $value = "%{$property}%"; } $return[ $property ] = $value; } return $return; }
php
{ "resource": "" }
q2874
MorrisBase.toJSON
train
public function toJSON() { $json = json_encode( $this->toArray() ); return str_replace( [ '"%hoverCallback%"', '"%formatter%"', '"%dateFormat%"', ], [ $this->hoverCallback, $this->formatter, $this->dateFormat, ], $json ); }
php
{ "resource": "" }
q2875
MorrisBase.toJavascript
train
public function toJavascript() { ob_start(); ?> <script type="text/javascript"> jQuery( function( $ ) { "use strict"; Morris.<?php echo $this->__chart_type ?>( <?php echo $this->toJSON() ?> ); } ); </script> <?php $buffer = ob_get_contents(); ob_end_clean(); return $buffer; }
php
{ "resource": "" }
q2876
Tx_Oelib_MapperRegistry.getByClassName
train
private function getByClassName($className) { if ($className === '') { throw new \InvalidArgumentException('$className must not be empty.', 1331488868); } $unifiedClassName = self::unifyClassName($className); if (!isset($this->mappers[$unifiedClassName])) { if (!class_exists($className, true)) { throw new \InvalidArgumentException( 'No mapper class "' . $className . '" could be found.' ); } /** @var \Tx_Oelib_DataMapper $mapper */ $mapper = GeneralUtility::makeInstance($unifiedClassName); $this->mappers[$unifiedClassName] = $mapper; } else { /** @var \Tx_Oelib_DataMapper $mapper */ $mapper = $this->mappers[$unifiedClassName]; } if ($this->testingMode) { $mapper->setTestingFramework($this->testingFramework); } if ($this->denyDatabaseAccess) { $mapper->disableDatabaseAccess(); } return $mapper; }
php
{ "resource": "" }
q2877
AbstractDataTablesProvider.renderButtons
train
protected function renderButtons($entity, $editRoute, $deleteRoute = null, $enableDelete = true) { // Initialize the titles. $titles = []; $titles[] = $this->getTranslator()->trans("label.edit", [], "CoreBundle"); $titles[] = $this->getTranslator()->trans("label.delete", [], "CoreBundle"); // Initialize the actions. $actions = []; $actions[] = $this->getButtonTwigExtension()->bootstrapButtonDefaultFunction(["icon" => "pencil", "title" => $titles[0], "size" => "xs"]); $actions[] = $this->getButtonTwigExtension()->bootstrapButtonDangerFunction(["icon" => "trash", "title" => $titles[1], "size" => "xs"]); // Initialize the routes. $routes = []; $routes[] = $this->getRouter()->generate($editRoute, ["id" => $entity->getId()]); $routes[] = $this->getRouter()->generate("jquery_datatables_delete", ["name" => $this->getName(), "id" => $entity->getId()]); // Check the delete route and use it if provided. if (null !== $deleteRoute) { $routes[1] = $this->getRouter()->generate($deleteRoute, ["id" => $entity->getId()]); } // Initialize the links. $links = []; $links[] = $this->getButtonTwigExtension()->bootstrapButtonLinkFilter($actions[0], $routes[0]); if (true === $enableDelete) { $links[] = $this->getButtonTwigExtension()->bootstrapButtonLinkFilter($actions[1], $routes[1]); } return implode(" ", $links); }
php
{ "resource": "" }
q2878
AbstractDataTablesProvider.renderFloat
train
protected function renderFloat($number, $decimals = 2, $decPoint = ".", $thousandsSep = ",") { if (null === $number) { return ""; } return number_format($number, $decimals, $decPoint, $thousandsSep); }
php
{ "resource": "" }
q2879
AbstractDataTablesProvider.wrapContent
train
protected function wrapContent($prefix, $content, $suffix) { $output = []; if (null !== $prefix) { $output[] = $prefix; } $output[] = $content; if (null !== $suffix) { $output[] = $suffix; } return implode("", $output); }
php
{ "resource": "" }
q2880
Tx_Oelib_Session.getInstance
train
public static function getInstance($type) { self::checkType($type); if (!isset(self::$instances[$type])) { self::$instances[$type] = new \Tx_Oelib_Session($type); } return self::$instances[$type]; }
php
{ "resource": "" }
q2881
Tx_Oelib_Session.setInstance
train
public static function setInstance($type, \Tx_Oelib_Session $instance) { self::checkType($type); self::$instances[$type] = $instance; }
php
{ "resource": "" }
q2882
GiroCheckout_SDK_PaydirektTransaction.validateParams
train
public function validateParams( $p_aParams, &$p_strError ) { if( isset($p_aParams['shoppingCartType']) ) { $strShoppingCartType = trim($p_aParams['shoppingCartType']); } if (empty($strShoppingCartType)) { $strShoppingCartType = "MIXED"; // Default value } if( isset($p_aParams['shippingAddresseFirstName']) ) { $strFirstName = trim( $p_aParams['shippingAddresseFirstName'] ); } else { $strFirstName = ""; } if( isset($p_aParams['shippingAddresseLastName']) ) { $strLastName = trim( $p_aParams['shippingAddresseLastName'] ); } else { $strLastName = ""; } if( isset($p_aParams['shippingEmail']) ) { $strEmail = trim( $p_aParams['shippingEmail'] ); } else { $strEmail = ""; } if( isset($p_aParams['shippingZipCode']) ) { $strZipCode = trim($p_aParams['shippingZipCode']); } else { $strZipCode = ""; } if( isset($p_aParams['shippingCity']) ) { $strCity = trim( $p_aParams['shippingCity'] ); } else { $strCity = ""; } if( isset($p_aParams['shippingCountry']) ) { $strCountry = trim( $p_aParams['shippingCountry'] ); } else { $strCountry = ""; } // Validate shopping cart type if ( !in_array($strShoppingCartType, array( 'PHYSICAL', 'DIGITAL', 'MIXED', 'ANONYMOUS_DONATION', 'AUTHORITIES_PAYMENT', ))) { $p_strError = "Shopping cart type"; return FALSE; } // Validate other address fields depending on shoppingCartType // First and last name are mandatory for mixed, physical and digital shopping carts if( in_array( $strShoppingCartType, array('MIXED', 'PHYSICAL', 'DIGITAL') ) ) { if (empty($strFirstName)) { $p_strError = "First Name"; return FALSE; } if (empty($strLastName)) { $p_strError = "Last Name"; return FALSE; } } if( $strShoppingCartType == 'DIGITAL' ) { if( empty($strEmail) ) { $p_strError = "Shipping Email"; return FALSE; } } elseif( in_array( $strShoppingCartType, array('MIXED', 'PHYSICAL') ) ) { if( empty($strZipCode) ) { $p_strError = "Shipping Address Zip code"; return FALSE; } if( empty($strCity) ) { $p_strError = "Shipping Address City"; return FALSE; } if( empty($strCountry) ) { $p_strError = "Shipping Address Country"; return FALSE; } } return TRUE; }
php
{ "resource": "" }
q2883
AnnotationLoader.loadClassMetadata
train
public function loadClassMetadata(Mapping\ClassMetadataInterface $metadata) { $reflClass = $metadata->getReflectionClass(); //Iterate over properties to get annotations foreach($reflClass->getProperties() as $property) { $this->readProperty($property, $metadata); } }
php
{ "resource": "" }
q2884
SitewideContentTaxonomy.updateColumns
train
public function updateColumns($itemType, &$columns) { if ($itemType !== 'Pages') { return; } // Check if pages has the tags field if (!self::enabled()) { return; } // Set column $field = Config::inst()->get(__CLASS__, 'tag_field'); $columns['Terms'] = [ 'printonly' => true, // Hide on page report 'title' => _t('SilverStripe\\SiteWideContentReport\\SitewideContentReport.Tags', 'Tags'), 'datasource' => function ($record) use ($field) { $tags = $record->$field()->column('Name'); return implode(', ', $tags); }, ]; }
php
{ "resource": "" }
q2885
SitewideContentTaxonomy.enabled
train
public static function enabled() { if (!class_exists(TaxonomyTerm::class)) { return false; } // Check if pages has the tags field $field = Config::inst()->get(__CLASS__, 'tag_field'); return singleton('Page')->hasMethod($field); }
php
{ "resource": "" }
q2886
SubscriptionFactory.addEntitySubject
train
public function addEntitySubject($id, $type = null, $idKey = "id", $typeKey = "type") { if(!isset($this->_subscription->subject)){ $this->_subscription->subject = (object) [ "entities" => [], "condition" => (object)["attrs" => []] ]; } $entity = (object) []; $entity->$idKey = $id; if (null != $type) { $entity->$typeKey = (string)$type; } $this->_subscription->subject->entities[] = $entity; return $this; }
php
{ "resource": "" }
q2887
SubscriptionFactory.addAttrCondition
train
public function addAttrCondition($attr) { if(!isset($this->_subscription->subject)){ $this->_subscription->subject = (object) []; } if(!isset($this->_subscription->subject->condition)){ $this->_subscription->subject->condition = (object) []; } if (!isset($this->_subscription->subject->condition->attrs)) { $this->_subscription->subject->condition->attrs = []; } array_push($this->_subscription->subject->condition->attrs, $attr); return $this; }
php
{ "resource": "" }
q2888
SubscriptionFactory.addExpressionCondition
train
public function addExpressionCondition($expression) { if(!isset($this->_subscription->subject)){ $this->_subscription->subject = (object) []; } if(!isset($this->_subscription->subject->condition)){ $this->_subscription->subject->condition = (object) []; } $this->_subscription->subject->condition->expression = $expression; return $this; }
php
{ "resource": "" }
q2889
Backoff.setOptions
train
public function setOptions(array $options) : BackoffInterface { $this->options = array_merge($this->options, $options); return $this; }
php
{ "resource": "" }
q2890
Backoff.exponential
train
public function exponential(int $attempt) : float { if (!is_int($attempt)) { throw new InvalidArgumentException('Attempt must be an integer'); } if ($attempt < 1) { throw new InvalidArgumentException('Attempt must be >= 1'); } if ($this->maxAttempsExceeded($attempt)) { throw new BackoffException( sprintf( "The number of max attempts (%s) was exceeded", $this->options['maxAttempts'] ) ); } $wait = (1 << ($attempt - 1)) * 1000; return ($this->options['cap'] < $wait) ? $this->options['cap'] : $wait; }
php
{ "resource": "" }
q2891
Backoff.equalJitter
train
public function equalJitter(int $attempt) : int { $half = ($this->exponential($attempt) / 2); return (int) floor($half + $this->random(0.0, $half)); }
php
{ "resource": "" }
q2892
Backoff.fullJitter
train
public function fullJitter(int $attempt) : int { return (int) floor($this->random(0.0, $this->exponential($attempt) / 2)); }
php
{ "resource": "" }
q2893
Backoff.random
train
protected function random(float $min, float $max) : float { return ($min + lcg_value() * (abs($max - $min))); }
php
{ "resource": "" }
q2894
AbstractRequest.getRequestHeaders
train
public function getRequestHeaders() { // common headers $headers = array( 'Accept' => 'application/json', ); // set content type if ($this->getHttpMethod() !== 'GET') { $headers['Content-Type'] = 'application/x-www-form-urlencoded'; } // prevent duplicate POSTs if ($this->getHttpMethod() === 'POST') { $headers['Idempotency-Key'] = $this->getIdempotencyKey(); } return $headers; }
php
{ "resource": "" }
q2895
AbstractRequest.sendData
train
public function sendData($data) { // enforce TLS >= v1.2 (https://www.payway.com.au/rest-docs/index.html#basics) $config = $this->httpClient->getConfig(); $curlOptions = $config->get('curl.options'); $curlOptions[CURLOPT_SSLVERSION] = 6; $config->set('curl.options', $curlOptions); $this->httpClient->setConfig($config); // don't throw exceptions for 4xx errors $this->httpClient->getEventDispatcher()->addListener( 'request.error', function ($event) { if ($event['response']->isClientError()) { $event->stopPropagation(); } } ); if ($this->getSSLCertificatePath()) { $this->httpClient->setSslVerification($this->getSSLCertificatePath()); } $request = $this->httpClient->createRequest( $this->getHttpMethod(), $this->getEndpoint(), $this->getRequestHeaders(), $data ); // get the appropriate API key $apikey = ($this->getUseSecretKey()) ? $this->getApiKeySecret() : $this->getApiKeyPublic(); $request->setHeader('Authorization', 'Basic ' . base64_encode($apikey . ':')); // send the request $response = $request->send(); $this->response = new Response($this, $response->json()); // save additional info $this->response->setHttpResponseCode($response->getStatusCode()); $this->response->setTransactionType($this->getTransactionType()); return $this->response; }
php
{ "resource": "" }
q2896
AbstractRequest.addToData
train
public function addToData(array $data = array(), array $parms = array()) { foreach ($parms as $parm) { $getter = 'get' . ucfirst($parm); if (method_exists($this, $getter) && $this->$getter()) { $data[$parm] = $this->$getter(); } } return $data; }
php
{ "resource": "" }
q2897
Tx_Oelib_ConfigurationRegistry.getByNamespace
train
private function getByNamespace($namespace) { $this->checkForNonEmptyNamespace($namespace); if (!isset($this->configurations[$namespace])) { $this->configurations[$namespace] = $this->retrieveConfigurationFromTypoScriptSetup($namespace); } return $this->configurations[$namespace]; }
php
{ "resource": "" }
q2898
Tx_Oelib_ConfigurationRegistry.set
train
public function set($namespace, \Tx_Oelib_Configuration $configuration) { $this->checkForNonEmptyNamespace($namespace); if (isset($this->configurations[$namespace])) { $this->dropConfiguration($namespace); } $this->configurations[$namespace] = $configuration; }
php
{ "resource": "" }
q2899
Tx_Oelib_ConfigurationRegistry.retrieveConfigurationFromTypoScriptSetup
train
private function retrieveConfigurationFromTypoScriptSetup($namespace) { $data = $this->getCompleteTypoScriptSetup(); $namespaceParts = explode('.', $namespace); foreach ($namespaceParts as $namespacePart) { if (!array_key_exists($namespacePart . '.', $data)) { $data = []; break; } $data = $data[$namespacePart . '.']; } /** @var \Tx_Oelib_Configuration $configuration */ $configuration = GeneralUtility::makeInstance(\Tx_Oelib_Configuration::class); $configuration->setData($data); return $configuration; }
php
{ "resource": "" }