id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
7,400 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.getResponseHeader | public function getResponseHeader ($name) {
$this->throwIfNotSubmitted();
if (isset($this->responseHeaders[$name])) {
return $this->responseHeaders[$name];
} else {
return null;
}
} | php | public function getResponseHeader ($name) {
$this->throwIfNotSubmitted();
if (isset($this->responseHeaders[$name])) {
return $this->responseHeaders[$name];
} else {
return null;
}
} | [
"public",
"function",
"getResponseHeader",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"throwIfNotSubmitted",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"responseHeaders",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"responseHeaders",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Get a particular HTTP response header sent by the server.
@param string $name Header name
@return mixed Header value or null if not found. Value may be an array if
the named header occured more than once in the server's response.
@throws \RuntimeException If request has not been submitted. | [
"Get",
"a",
"particular",
"HTTP",
"response",
"header",
"sent",
"by",
"the",
"server",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L503-L510 |
7,401 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.submit | public function submit ($failIfNot200 = null) {
if ($this->wasSubmitted()) {
throw new Exception("Request be reused!");
}
$ch = $this->createCurlRequest();
$raw = curl_exec($ch);
$this->processCurlResponse($ch, curl_errno($ch), curl_error($ch), $raw);
$this->validateResponse($failIfNot200);
return $this;
} | php | public function submit ($failIfNot200 = null) {
if ($this->wasSubmitted()) {
throw new Exception("Request be reused!");
}
$ch = $this->createCurlRequest();
$raw = curl_exec($ch);
$this->processCurlResponse($ch, curl_errno($ch), curl_error($ch), $raw);
$this->validateResponse($failIfNot200);
return $this;
} | [
"public",
"function",
"submit",
"(",
"$",
"failIfNot200",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"wasSubmitted",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Request be reused!\"",
")",
";",
"}",
"$",
"ch",
"=",
"$",
"this",
"->",
"createCurlRequest",
"(",
")",
";",
"$",
"raw",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"this",
"->",
"processCurlResponse",
"(",
"$",
"ch",
",",
"curl_errno",
"(",
"$",
"ch",
")",
",",
"curl_error",
"(",
"$",
"ch",
")",
",",
"$",
"raw",
")",
";",
"$",
"this",
"->",
"validateResponse",
"(",
"$",
"failIfNot200",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Submit this request.
This request will be updated with the results of the request which can
then be retrieved using getResponseHttpCode() and releated methods.
@param bool $failIfNot200 Throw an exception if a non-200 status was sent?
@return Request Request with response data populated
@throws Exception On cURL failure | [
"Submit",
"this",
"request",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L575-L584 |
7,402 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.createCurlRequest | protected function createCurlRequest () {
// merge any custom cURL options into the default set
$curlOpts = Util::mergeCurlOptions(
self::$defaultCurlOpts, $this->getCurlOptions());
// set basic options that we always want to use
$curlOpts[CURLOPT_RETURNTRANSFER] = true;
$curlOpts[CURLOPT_HEADER] = true;
$curlOpts[CURLOPT_FAILONERROR] = false;
if (defined('CURLINFO_HEADER_OUT')) {
$curlOpts[CURLINFO_HEADER_OUT] = true;
}
// timeouts less than 1 sec fail unless we disable signals
// see http://www.php.net/manual/en/function.curl-setopt.php#104597
if (defined('CURLOPT_TIMEOUT_MS') ||
defined('CURLOPT_CONNECTTIMEOUT_MS')) {
if ((isset($curlOpts[CURLOPT_TIMEOUT_MS]) &&
$curlOpts[CURLOPT_TIMEOUT_MS] < 1000) ||
(isset($curlOpts[CURLOPT_CONNECTTIMEOUT_MS]) &&
$curlOpts[CURLOPT_CONNECTTIMEOUT_MS] < 1000)) {
$curlOpts[CURLOPT_NOSIGNAL] = true;
}
}
// prepare the request
$curlOpts[CURLOPT_URL] = $this->url;
if (self::METHOD_POST == $this->getMethod()) {
// using CURLOPT_CUSTOMREQUEST changes the behavior for POST
// this change forces strict RFC2616:10.3.3 compliance which doesn't
// work too well with many internet sites.
$curlOpts[CURLOPT_POST] = true;
} else {
$curlOpts[CURLOPT_CUSTOMREQUEST] = $this->getMethod();
}
$curlOpts[CURLOPT_USERAGENT] = $this->getUserAgent();
if ($this->getPostBody()) {
// add post payload
$pBody = $this->getPostBody();
if (!is_array($pBody)) {
// caller supplied a URI-encoded payload, so make sure we set the
// content-length header
$len = mb_strlen($pBody, 'latin1');
$this->addHeader("Content-Length: {$len}");
}
$curlOpts[CURLOPT_POSTFIELDS] = $pBody;
}
if ($this->getHeaders()) {
// add custom headers
$curlOpts[CURLOPT_HTTPHEADER] = $this->getHeaders();
}
// remember the options we used. Might be handy for debugging.
$this->setCurlOptions($curlOpts);
// create curl resource
$ch = curl_init();
// apply options
curl_setopt_array($ch, $curlOpts);
return $ch;
} | php | protected function createCurlRequest () {
// merge any custom cURL options into the default set
$curlOpts = Util::mergeCurlOptions(
self::$defaultCurlOpts, $this->getCurlOptions());
// set basic options that we always want to use
$curlOpts[CURLOPT_RETURNTRANSFER] = true;
$curlOpts[CURLOPT_HEADER] = true;
$curlOpts[CURLOPT_FAILONERROR] = false;
if (defined('CURLINFO_HEADER_OUT')) {
$curlOpts[CURLINFO_HEADER_OUT] = true;
}
// timeouts less than 1 sec fail unless we disable signals
// see http://www.php.net/manual/en/function.curl-setopt.php#104597
if (defined('CURLOPT_TIMEOUT_MS') ||
defined('CURLOPT_CONNECTTIMEOUT_MS')) {
if ((isset($curlOpts[CURLOPT_TIMEOUT_MS]) &&
$curlOpts[CURLOPT_TIMEOUT_MS] < 1000) ||
(isset($curlOpts[CURLOPT_CONNECTTIMEOUT_MS]) &&
$curlOpts[CURLOPT_CONNECTTIMEOUT_MS] < 1000)) {
$curlOpts[CURLOPT_NOSIGNAL] = true;
}
}
// prepare the request
$curlOpts[CURLOPT_URL] = $this->url;
if (self::METHOD_POST == $this->getMethod()) {
// using CURLOPT_CUSTOMREQUEST changes the behavior for POST
// this change forces strict RFC2616:10.3.3 compliance which doesn't
// work too well with many internet sites.
$curlOpts[CURLOPT_POST] = true;
} else {
$curlOpts[CURLOPT_CUSTOMREQUEST] = $this->getMethod();
}
$curlOpts[CURLOPT_USERAGENT] = $this->getUserAgent();
if ($this->getPostBody()) {
// add post payload
$pBody = $this->getPostBody();
if (!is_array($pBody)) {
// caller supplied a URI-encoded payload, so make sure we set the
// content-length header
$len = mb_strlen($pBody, 'latin1');
$this->addHeader("Content-Length: {$len}");
}
$curlOpts[CURLOPT_POSTFIELDS] = $pBody;
}
if ($this->getHeaders()) {
// add custom headers
$curlOpts[CURLOPT_HTTPHEADER] = $this->getHeaders();
}
// remember the options we used. Might be handy for debugging.
$this->setCurlOptions($curlOpts);
// create curl resource
$ch = curl_init();
// apply options
curl_setopt_array($ch, $curlOpts);
return $ch;
} | [
"protected",
"function",
"createCurlRequest",
"(",
")",
"{",
"// merge any custom cURL options into the default set",
"$",
"curlOpts",
"=",
"Util",
"::",
"mergeCurlOptions",
"(",
"self",
"::",
"$",
"defaultCurlOpts",
",",
"$",
"this",
"->",
"getCurlOptions",
"(",
")",
")",
";",
"// set basic options that we always want to use",
"$",
"curlOpts",
"[",
"CURLOPT_RETURNTRANSFER",
"]",
"=",
"true",
";",
"$",
"curlOpts",
"[",
"CURLOPT_HEADER",
"]",
"=",
"true",
";",
"$",
"curlOpts",
"[",
"CURLOPT_FAILONERROR",
"]",
"=",
"false",
";",
"if",
"(",
"defined",
"(",
"'CURLINFO_HEADER_OUT'",
")",
")",
"{",
"$",
"curlOpts",
"[",
"CURLINFO_HEADER_OUT",
"]",
"=",
"true",
";",
"}",
"// timeouts less than 1 sec fail unless we disable signals",
"// see http://www.php.net/manual/en/function.curl-setopt.php#104597",
"if",
"(",
"defined",
"(",
"'CURLOPT_TIMEOUT_MS'",
")",
"||",
"defined",
"(",
"'CURLOPT_CONNECTTIMEOUT_MS'",
")",
")",
"{",
"if",
"(",
"(",
"isset",
"(",
"$",
"curlOpts",
"[",
"CURLOPT_TIMEOUT_MS",
"]",
")",
"&&",
"$",
"curlOpts",
"[",
"CURLOPT_TIMEOUT_MS",
"]",
"<",
"1000",
")",
"||",
"(",
"isset",
"(",
"$",
"curlOpts",
"[",
"CURLOPT_CONNECTTIMEOUT_MS",
"]",
")",
"&&",
"$",
"curlOpts",
"[",
"CURLOPT_CONNECTTIMEOUT_MS",
"]",
"<",
"1000",
")",
")",
"{",
"$",
"curlOpts",
"[",
"CURLOPT_NOSIGNAL",
"]",
"=",
"true",
";",
"}",
"}",
"// prepare the request",
"$",
"curlOpts",
"[",
"CURLOPT_URL",
"]",
"=",
"$",
"this",
"->",
"url",
";",
"if",
"(",
"self",
"::",
"METHOD_POST",
"==",
"$",
"this",
"->",
"getMethod",
"(",
")",
")",
"{",
"// using CURLOPT_CUSTOMREQUEST changes the behavior for POST",
"// this change forces strict RFC2616:10.3.3 compliance which doesn't",
"// work too well with many internet sites.",
"$",
"curlOpts",
"[",
"CURLOPT_POST",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"curlOpts",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"$",
"this",
"->",
"getMethod",
"(",
")",
";",
"}",
"$",
"curlOpts",
"[",
"CURLOPT_USERAGENT",
"]",
"=",
"$",
"this",
"->",
"getUserAgent",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getPostBody",
"(",
")",
")",
"{",
"// add post payload",
"$",
"pBody",
"=",
"$",
"this",
"->",
"getPostBody",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"pBody",
")",
")",
"{",
"// caller supplied a URI-encoded payload, so make sure we set the",
"// content-length header",
"$",
"len",
"=",
"mb_strlen",
"(",
"$",
"pBody",
",",
"'latin1'",
")",
";",
"$",
"this",
"->",
"addHeader",
"(",
"\"Content-Length: {$len}\"",
")",
";",
"}",
"$",
"curlOpts",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"$",
"pBody",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
"{",
"// add custom headers",
"$",
"curlOpts",
"[",
"CURLOPT_HTTPHEADER",
"]",
"=",
"$",
"this",
"->",
"getHeaders",
"(",
")",
";",
"}",
"// remember the options we used. Might be handy for debugging.",
"$",
"this",
"->",
"setCurlOptions",
"(",
"$",
"curlOpts",
")",
";",
"// create curl resource",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"// apply options",
"curl_setopt_array",
"(",
"$",
"ch",
",",
"$",
"curlOpts",
")",
";",
"return",
"$",
"ch",
";",
"}"
] | Prepare a cURL handle for this request.
@return resource Curl handle ready to be submitted | [
"Prepare",
"a",
"cURL",
"handle",
"for",
"this",
"request",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L591-L655 |
7,403 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.processCurlResponse | protected function processCurlResponse ($ch, $errCode, $errMsg, $rawResp) {
// check error codes
$this->responseCurlErr = $errCode;
$this->responseCurlErrMessage = $errMsg;
if (CURLE_OK == $errCode) {
$info = curl_getinfo($ch);
$hdrSize = $info['header_size'];
$respCode = (int) $info['http_code'];
// parse the raw response
$rawHeaders = mb_substr($rawResp, 0, $hdrSize, 'latin1');
$respBody = mb_substr(
$rawResp, $hdrSize, mb_strlen($rawResp, 'latin1'), 'latin1');
// parse response headers
if ($info['redirect_count'] > 0) {
// discard redirect headers
// TODO: there may be useful info in here that we want to preserve
$headerChunks = explode("\r\n\r\n", $rawHeaders);
$rawHeaders = $headerChunks[$info['redirect_count']];
}
$respHeaderParts = explode("\r\n", $rawHeaders);
$respHeaders = array();
foreach ($respHeaderParts as $header) {
if ($header) {
$parts = explode(': ', $header, 2);
$name = $parts[0];
$value = '';
if (count($parts) == 2) {
$value = $parts[1];
}
if (isset($respHeaders[$name])) {
if (!is_array($respHeaders[$name])) {
// convert single value to collection
$respHeaders[$name] = array($respHeaders[$name]);
}
$respHeaders[$name][] = $value;
} else {
$respHeaders[$name] = $value;
}
}
} //end foreach $header
// fill in request with response
$this->setResponseCurlInfo($info);
$this->setResponseHttpCode($respCode);
$this->setResponseHeaders($respHeaders);
$this->setResponseBody($respBody);
} //end if CURLE_OK
curl_close($ch);
return $this;
} | php | protected function processCurlResponse ($ch, $errCode, $errMsg, $rawResp) {
// check error codes
$this->responseCurlErr = $errCode;
$this->responseCurlErrMessage = $errMsg;
if (CURLE_OK == $errCode) {
$info = curl_getinfo($ch);
$hdrSize = $info['header_size'];
$respCode = (int) $info['http_code'];
// parse the raw response
$rawHeaders = mb_substr($rawResp, 0, $hdrSize, 'latin1');
$respBody = mb_substr(
$rawResp, $hdrSize, mb_strlen($rawResp, 'latin1'), 'latin1');
// parse response headers
if ($info['redirect_count'] > 0) {
// discard redirect headers
// TODO: there may be useful info in here that we want to preserve
$headerChunks = explode("\r\n\r\n", $rawHeaders);
$rawHeaders = $headerChunks[$info['redirect_count']];
}
$respHeaderParts = explode("\r\n", $rawHeaders);
$respHeaders = array();
foreach ($respHeaderParts as $header) {
if ($header) {
$parts = explode(': ', $header, 2);
$name = $parts[0];
$value = '';
if (count($parts) == 2) {
$value = $parts[1];
}
if (isset($respHeaders[$name])) {
if (!is_array($respHeaders[$name])) {
// convert single value to collection
$respHeaders[$name] = array($respHeaders[$name]);
}
$respHeaders[$name][] = $value;
} else {
$respHeaders[$name] = $value;
}
}
} //end foreach $header
// fill in request with response
$this->setResponseCurlInfo($info);
$this->setResponseHttpCode($respCode);
$this->setResponseHeaders($respHeaders);
$this->setResponseBody($respBody);
} //end if CURLE_OK
curl_close($ch);
return $this;
} | [
"protected",
"function",
"processCurlResponse",
"(",
"$",
"ch",
",",
"$",
"errCode",
",",
"$",
"errMsg",
",",
"$",
"rawResp",
")",
"{",
"// check error codes",
"$",
"this",
"->",
"responseCurlErr",
"=",
"$",
"errCode",
";",
"$",
"this",
"->",
"responseCurlErrMessage",
"=",
"$",
"errMsg",
";",
"if",
"(",
"CURLE_OK",
"==",
"$",
"errCode",
")",
"{",
"$",
"info",
"=",
"curl_getinfo",
"(",
"$",
"ch",
")",
";",
"$",
"hdrSize",
"=",
"$",
"info",
"[",
"'header_size'",
"]",
";",
"$",
"respCode",
"=",
"(",
"int",
")",
"$",
"info",
"[",
"'http_code'",
"]",
";",
"// parse the raw response",
"$",
"rawHeaders",
"=",
"mb_substr",
"(",
"$",
"rawResp",
",",
"0",
",",
"$",
"hdrSize",
",",
"'latin1'",
")",
";",
"$",
"respBody",
"=",
"mb_substr",
"(",
"$",
"rawResp",
",",
"$",
"hdrSize",
",",
"mb_strlen",
"(",
"$",
"rawResp",
",",
"'latin1'",
")",
",",
"'latin1'",
")",
";",
"// parse response headers",
"if",
"(",
"$",
"info",
"[",
"'redirect_count'",
"]",
">",
"0",
")",
"{",
"// discard redirect headers",
"// TODO: there may be useful info in here that we want to preserve",
"$",
"headerChunks",
"=",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"$",
"rawHeaders",
")",
";",
"$",
"rawHeaders",
"=",
"$",
"headerChunks",
"[",
"$",
"info",
"[",
"'redirect_count'",
"]",
"]",
";",
"}",
"$",
"respHeaderParts",
"=",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"rawHeaders",
")",
";",
"$",
"respHeaders",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"respHeaderParts",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"$",
"header",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"': '",
",",
"$",
"header",
",",
"2",
")",
";",
"$",
"name",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"value",
"=",
"''",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"2",
")",
"{",
"$",
"value",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"respHeaders",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"respHeaders",
"[",
"$",
"name",
"]",
")",
")",
"{",
"// convert single value to collection",
"$",
"respHeaders",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
"$",
"respHeaders",
"[",
"$",
"name",
"]",
")",
";",
"}",
"$",
"respHeaders",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"respHeaders",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"//end foreach $header",
"// fill in request with response",
"$",
"this",
"->",
"setResponseCurlInfo",
"(",
"$",
"info",
")",
";",
"$",
"this",
"->",
"setResponseHttpCode",
"(",
"$",
"respCode",
")",
";",
"$",
"this",
"->",
"setResponseHeaders",
"(",
"$",
"respHeaders",
")",
";",
"$",
"this",
"->",
"setResponseBody",
"(",
"$",
"respBody",
")",
";",
"}",
"//end if CURLE_OK",
"curl_close",
"(",
"$",
"ch",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Process an submitted cURL response.
@param resource $ch Curl handle
@param int $errCode Curl error code
@param string $errMsg Curl error message
@param string $rawResp Raw response
@return Request Request with response data populated | [
"Process",
"an",
"submitted",
"cURL",
"response",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L666-L719 |
7,404 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.validateResponse | public function validateResponse ($failIfNot200 = null) {
if (null === $failIfNot200) {
$failIfNot200 = $this->defaultFailIfNot200;
}
if (CURLE_OK != $this->responseCurlErr) {
$exClazz = 'Moar\Net\Http\Exception';
switch ($this->responseCurlErr) {
case CURLE_UNSUPPORTED_PROTOCOL:
case CURLE_URL_MALFORMAT:
$exClazz = 'Moar\Net\Http\BadUrlException';
break;
case CURLE_COULDNT_RESOLVE_HOST:
$exClazz = 'Moar\Net\Http\DnsFailureException';
break;
case CURLE_COULDNT_CONNECT:
$exClazz = 'Moar\Net\Http\ConnectFailedException';
break;
case CURLE_HTTP_RETURNED_ERROR:
$exClazz = 'Moar\Net\Http\StatusCodeException';
break;
case CURLE_OPERATION_TIMEDOUT:
$exClazz = 'Moar\Net\Http\TimeoutException';
break;
case CURLE_PEER_FAILED_VERIFICATION:
case CURLE_SSL_CACERT:
case CURLE_SSL_CACERT_BADFILE:
case CURLE_SSL_CERTPROBLEM:
case CURLE_SSL_CERTPROBLEM:
case CURLE_SSL_CIPHER:
case CURLE_SSL_CONNECT_ERROR:
case CURLE_SSL_CRL_BADFILE:
case CURLE_SSL_ENGINE_INITFAILED:
case CURLE_SSL_ENGINE_NOTFOUND:
case CURLE_SSL_ENGINE_SETFAILED:
case CURLE_SSL_ISSUER_ERROR:
case CURLE_SSL_SHUTDOWN_FAILED:
case CURLE_USE_SSL_FAILED:
$exClazz = 'Moar\Net\Http\SslException';
break;
} //end switch
throw new $exClazz(
$this->responseCurlErrMessage, $this->responseCurlErr, $this);
} //end if !ok
if ($failIfNot200) {
$code = $this->getResponseHttpCode();
if ($code < 200 || $code > 299) {
throw new StatusCodeException(
"HTTP Error: ({$code}) from {$this->url}",
CURLE_HTTP_RETURNED_ERROR, $this);
}
}
} | php | public function validateResponse ($failIfNot200 = null) {
if (null === $failIfNot200) {
$failIfNot200 = $this->defaultFailIfNot200;
}
if (CURLE_OK != $this->responseCurlErr) {
$exClazz = 'Moar\Net\Http\Exception';
switch ($this->responseCurlErr) {
case CURLE_UNSUPPORTED_PROTOCOL:
case CURLE_URL_MALFORMAT:
$exClazz = 'Moar\Net\Http\BadUrlException';
break;
case CURLE_COULDNT_RESOLVE_HOST:
$exClazz = 'Moar\Net\Http\DnsFailureException';
break;
case CURLE_COULDNT_CONNECT:
$exClazz = 'Moar\Net\Http\ConnectFailedException';
break;
case CURLE_HTTP_RETURNED_ERROR:
$exClazz = 'Moar\Net\Http\StatusCodeException';
break;
case CURLE_OPERATION_TIMEDOUT:
$exClazz = 'Moar\Net\Http\TimeoutException';
break;
case CURLE_PEER_FAILED_VERIFICATION:
case CURLE_SSL_CACERT:
case CURLE_SSL_CACERT_BADFILE:
case CURLE_SSL_CERTPROBLEM:
case CURLE_SSL_CERTPROBLEM:
case CURLE_SSL_CIPHER:
case CURLE_SSL_CONNECT_ERROR:
case CURLE_SSL_CRL_BADFILE:
case CURLE_SSL_ENGINE_INITFAILED:
case CURLE_SSL_ENGINE_NOTFOUND:
case CURLE_SSL_ENGINE_SETFAILED:
case CURLE_SSL_ISSUER_ERROR:
case CURLE_SSL_SHUTDOWN_FAILED:
case CURLE_USE_SSL_FAILED:
$exClazz = 'Moar\Net\Http\SslException';
break;
} //end switch
throw new $exClazz(
$this->responseCurlErrMessage, $this->responseCurlErr, $this);
} //end if !ok
if ($failIfNot200) {
$code = $this->getResponseHttpCode();
if ($code < 200 || $code > 299) {
throw new StatusCodeException(
"HTTP Error: ({$code}) from {$this->url}",
CURLE_HTTP_RETURNED_ERROR, $this);
}
}
} | [
"public",
"function",
"validateResponse",
"(",
"$",
"failIfNot200",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"failIfNot200",
")",
"{",
"$",
"failIfNot200",
"=",
"$",
"this",
"->",
"defaultFailIfNot200",
";",
"}",
"if",
"(",
"CURLE_OK",
"!=",
"$",
"this",
"->",
"responseCurlErr",
")",
"{",
"$",
"exClazz",
"=",
"'Moar\\Net\\Http\\Exception'",
";",
"switch",
"(",
"$",
"this",
"->",
"responseCurlErr",
")",
"{",
"case",
"CURLE_UNSUPPORTED_PROTOCOL",
":",
"case",
"CURLE_URL_MALFORMAT",
":",
"$",
"exClazz",
"=",
"'Moar\\Net\\Http\\BadUrlException'",
";",
"break",
";",
"case",
"CURLE_COULDNT_RESOLVE_HOST",
":",
"$",
"exClazz",
"=",
"'Moar\\Net\\Http\\DnsFailureException'",
";",
"break",
";",
"case",
"CURLE_COULDNT_CONNECT",
":",
"$",
"exClazz",
"=",
"'Moar\\Net\\Http\\ConnectFailedException'",
";",
"break",
";",
"case",
"CURLE_HTTP_RETURNED_ERROR",
":",
"$",
"exClazz",
"=",
"'Moar\\Net\\Http\\StatusCodeException'",
";",
"break",
";",
"case",
"CURLE_OPERATION_TIMEDOUT",
":",
"$",
"exClazz",
"=",
"'Moar\\Net\\Http\\TimeoutException'",
";",
"break",
";",
"case",
"CURLE_PEER_FAILED_VERIFICATION",
":",
"case",
"CURLE_SSL_CACERT",
":",
"case",
"CURLE_SSL_CACERT_BADFILE",
":",
"case",
"CURLE_SSL_CERTPROBLEM",
":",
"case",
"CURLE_SSL_CERTPROBLEM",
":",
"case",
"CURLE_SSL_CIPHER",
":",
"case",
"CURLE_SSL_CONNECT_ERROR",
":",
"case",
"CURLE_SSL_CRL_BADFILE",
":",
"case",
"CURLE_SSL_ENGINE_INITFAILED",
":",
"case",
"CURLE_SSL_ENGINE_NOTFOUND",
":",
"case",
"CURLE_SSL_ENGINE_SETFAILED",
":",
"case",
"CURLE_SSL_ISSUER_ERROR",
":",
"case",
"CURLE_SSL_SHUTDOWN_FAILED",
":",
"case",
"CURLE_USE_SSL_FAILED",
":",
"$",
"exClazz",
"=",
"'Moar\\Net\\Http\\SslException'",
";",
"break",
";",
"}",
"//end switch",
"throw",
"new",
"$",
"exClazz",
"(",
"$",
"this",
"->",
"responseCurlErrMessage",
",",
"$",
"this",
"->",
"responseCurlErr",
",",
"$",
"this",
")",
";",
"}",
"//end if !ok",
"if",
"(",
"$",
"failIfNot200",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"getResponseHttpCode",
"(",
")",
";",
"if",
"(",
"$",
"code",
"<",
"200",
"||",
"$",
"code",
">",
"299",
")",
"{",
"throw",
"new",
"StatusCodeException",
"(",
"\"HTTP Error: ({$code}) from {$this->url}\"",
",",
"CURLE_HTTP_RETURNED_ERROR",
",",
"$",
"this",
")",
";",
"}",
"}",
"}"
] | Check the cURL response code and throw an exception if it is an error.
@param bool $failIfNot200 Throw an exception if a non-200 status was sent?
@return void
@throws Exception On cURL failure | [
"Check",
"the",
"cURL",
"response",
"code",
"and",
"throw",
"an",
"exception",
"if",
"it",
"is",
"an",
"error",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L728-L788 |
7,405 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.parallelSubmit | public static function parallelSubmit ($requests) {
$handles = array();
$mh = curl_multi_init();
// make a curl handle for each request
foreach ($requests as $req) {
$ch = $req->createCurlRequest();
$handles[(string) $ch] = $req;
curl_multi_add_handle($mh, $ch);
}
$reqsRunning = 0;
// fire off initial requests
do {
$status = curl_multi_exec($mh, $reqsRunning);
} while (CURLM_CALL_MULTI_PERFORM == $status);
// process the requests
while ($reqsRunning && CURLM_OK == $status) {
// wait to be woken up by network activity
$selectReady = curl_multi_select($mh);
if ($selectReady > 0) {
// one or more requests are finished
while ($info = curl_multi_info_read($mh)) {
self::handleMultiResponse($info, $mh, $handles);
}
} //end if selectReady
if (-1 != $selectReady) {
// continue processing
do {
$status = curl_multi_exec($mh, $reqsRunning);
} while (CURLM_CALL_MULTI_PERFORM == $status);
}
} //end while requests to process
// check for critical failure
if (CURLM_OK != $status) {
throw new Exception(
"Fatal error [{$status}] processing multiple requests", $status);
}
// any remaining results should be ready now
while ($handles && ($info = curl_multi_info_read($mh))) {
self::handleMultiResponse($info, $mh, $handles);
}
curl_multi_close($mh);
return $requests;
} | php | public static function parallelSubmit ($requests) {
$handles = array();
$mh = curl_multi_init();
// make a curl handle for each request
foreach ($requests as $req) {
$ch = $req->createCurlRequest();
$handles[(string) $ch] = $req;
curl_multi_add_handle($mh, $ch);
}
$reqsRunning = 0;
// fire off initial requests
do {
$status = curl_multi_exec($mh, $reqsRunning);
} while (CURLM_CALL_MULTI_PERFORM == $status);
// process the requests
while ($reqsRunning && CURLM_OK == $status) {
// wait to be woken up by network activity
$selectReady = curl_multi_select($mh);
if ($selectReady > 0) {
// one or more requests are finished
while ($info = curl_multi_info_read($mh)) {
self::handleMultiResponse($info, $mh, $handles);
}
} //end if selectReady
if (-1 != $selectReady) {
// continue processing
do {
$status = curl_multi_exec($mh, $reqsRunning);
} while (CURLM_CALL_MULTI_PERFORM == $status);
}
} //end while requests to process
// check for critical failure
if (CURLM_OK != $status) {
throw new Exception(
"Fatal error [{$status}] processing multiple requests", $status);
}
// any remaining results should be ready now
while ($handles && ($info = curl_multi_info_read($mh))) {
self::handleMultiResponse($info, $mh, $handles);
}
curl_multi_close($mh);
return $requests;
} | [
"public",
"static",
"function",
"parallelSubmit",
"(",
"$",
"requests",
")",
"{",
"$",
"handles",
"=",
"array",
"(",
")",
";",
"$",
"mh",
"=",
"curl_multi_init",
"(",
")",
";",
"// make a curl handle for each request",
"foreach",
"(",
"$",
"requests",
"as",
"$",
"req",
")",
"{",
"$",
"ch",
"=",
"$",
"req",
"->",
"createCurlRequest",
"(",
")",
";",
"$",
"handles",
"[",
"(",
"string",
")",
"$",
"ch",
"]",
"=",
"$",
"req",
";",
"curl_multi_add_handle",
"(",
"$",
"mh",
",",
"$",
"ch",
")",
";",
"}",
"$",
"reqsRunning",
"=",
"0",
";",
"// fire off initial requests",
"do",
"{",
"$",
"status",
"=",
"curl_multi_exec",
"(",
"$",
"mh",
",",
"$",
"reqsRunning",
")",
";",
"}",
"while",
"(",
"CURLM_CALL_MULTI_PERFORM",
"==",
"$",
"status",
")",
";",
"// process the requests",
"while",
"(",
"$",
"reqsRunning",
"&&",
"CURLM_OK",
"==",
"$",
"status",
")",
"{",
"// wait to be woken up by network activity",
"$",
"selectReady",
"=",
"curl_multi_select",
"(",
"$",
"mh",
")",
";",
"if",
"(",
"$",
"selectReady",
">",
"0",
")",
"{",
"// one or more requests are finished",
"while",
"(",
"$",
"info",
"=",
"curl_multi_info_read",
"(",
"$",
"mh",
")",
")",
"{",
"self",
"::",
"handleMultiResponse",
"(",
"$",
"info",
",",
"$",
"mh",
",",
"$",
"handles",
")",
";",
"}",
"}",
"//end if selectReady",
"if",
"(",
"-",
"1",
"!=",
"$",
"selectReady",
")",
"{",
"// continue processing",
"do",
"{",
"$",
"status",
"=",
"curl_multi_exec",
"(",
"$",
"mh",
",",
"$",
"reqsRunning",
")",
";",
"}",
"while",
"(",
"CURLM_CALL_MULTI_PERFORM",
"==",
"$",
"status",
")",
";",
"}",
"}",
"//end while requests to process",
"// check for critical failure",
"if",
"(",
"CURLM_OK",
"!=",
"$",
"status",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Fatal error [{$status}] processing multiple requests\"",
",",
"$",
"status",
")",
";",
"}",
"// any remaining results should be ready now",
"while",
"(",
"$",
"handles",
"&&",
"(",
"$",
"info",
"=",
"curl_multi_info_read",
"(",
"$",
"mh",
")",
")",
")",
"{",
"self",
"::",
"handleMultiResponse",
"(",
"$",
"info",
",",
"$",
"mh",
",",
"$",
"handles",
")",
";",
"}",
"curl_multi_close",
"(",
"$",
"mh",
")",
";",
"return",
"$",
"requests",
";",
"}"
] | Submit a group of requests in parallel.
Uses the curl_multi_exec engine to fire off several requests in parallel
and waits for all responses to finish before returing the collective
results.
@param array $requests List of requests to submit
@return array List of submitted requests
@throws Exception If a fatal multi error occurs. | [
"Submit",
"a",
"group",
"of",
"requests",
"in",
"parallel",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L802-L853 |
7,406 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.get | public static function get ($url, $parms = null, $options = null) {
$url = Util::addQueryData($url, $parms);
$r = new Request($url, self::METHOD_GET, null, null, $options);
return $r->submit();
} | php | public static function get ($url, $parms = null, $options = null) {
$url = Util::addQueryData($url, $parms);
$r = new Request($url, self::METHOD_GET, null, null, $options);
return $r->submit();
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"url",
",",
"$",
"parms",
"=",
"null",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"Util",
"::",
"addQueryData",
"(",
"$",
"url",
",",
"$",
"parms",
")",
";",
"$",
"r",
"=",
"new",
"Request",
"(",
"$",
"url",
",",
"self",
"::",
"METHOD_GET",
",",
"null",
",",
"null",
",",
"$",
"options",
")",
";",
"return",
"$",
"r",
"->",
"submit",
"(",
")",
";",
"}"
] | Convenience method to perform a GET request.
Provided parameters will be "application/x-www-form-urlencoded" encoded
and appended to the provided URL.
@param string $url URL to get (eg https://www.keynetics.com/page.php)
@param array $parms Array of key => value pairs to send
@param array $options Array of extra options to pass to cURL
@return Request Submitted request
@throws Exception On failure | [
"Convenience",
"method",
"to",
"perform",
"a",
"GET",
"request",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L894-L898 |
7,407 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.postContent | public static function postContent (
$url, $content, $contentType = 'text/xml', $options = null) {
$headers = array("Content-type: {$contentType}");
$r = new Request(
$url, self::METHOD_POST, $content, $headers, $options);
return $r->submit();
} | php | public static function postContent (
$url, $content, $contentType = 'text/xml', $options = null) {
$headers = array("Content-type: {$contentType}");
$r = new Request(
$url, self::METHOD_POST, $content, $headers, $options);
return $r->submit();
} | [
"public",
"static",
"function",
"postContent",
"(",
"$",
"url",
",",
"$",
"content",
",",
"$",
"contentType",
"=",
"'text/xml'",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
"\"Content-type: {$contentType}\"",
")",
";",
"$",
"r",
"=",
"new",
"Request",
"(",
"$",
"url",
",",
"self",
"::",
"METHOD_POST",
",",
"$",
"content",
",",
"$",
"headers",
",",
"$",
"options",
")",
";",
"return",
"$",
"r",
"->",
"submit",
"(",
")",
";",
"}"
] | Convenience method to POST content in the form of a raw string to a URL.
This is useful for manually constructed SOAP requests and other document
body type operations. Default content type is text/xml.
@param string $url Full URL to post to (eg
https://www.keynetics.com/page.php)
@param string $content Raw HTTP request body to be posted
@param string $contentType Value of the HTTP Content-Type header
@param array $options Array of extra options to pass to cURL
@return Request Submitted request
@throws Exception On failure | [
"Convenience",
"method",
"to",
"POST",
"content",
"in",
"the",
"form",
"of",
"a",
"raw",
"string",
"to",
"a",
"URL",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L936-L942 |
7,408 | philelson/VagrantTransient | src/Environments.php | Environments.getEnvironmentMessages | public function getEnvironmentMessages()
{
$messages = array();
foreach ($this->getEnvironments() as $environment) {
$style = 'general';
if (false == $this->vagrentExists($environment)) {
$style = 'warning';
}
$messages[$environment] = $style;
}
return $messages;
} | php | public function getEnvironmentMessages()
{
$messages = array();
foreach ($this->getEnvironments() as $environment) {
$style = 'general';
if (false == $this->vagrentExists($environment)) {
$style = 'warning';
}
$messages[$environment] = $style;
}
return $messages;
} | [
"public",
"function",
"getEnvironmentMessages",
"(",
")",
"{",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getEnvironments",
"(",
")",
"as",
"$",
"environment",
")",
"{",
"$",
"style",
"=",
"'general'",
";",
"if",
"(",
"false",
"==",
"$",
"this",
"->",
"vagrentExists",
"(",
"$",
"environment",
")",
")",
"{",
"$",
"style",
"=",
"'warning'",
";",
"}",
"$",
"messages",
"[",
"$",
"environment",
"]",
"=",
"$",
"style",
";",
"}",
"return",
"$",
"messages",
";",
"}"
] | This method returns an array of messages
@return array | [
"This",
"method",
"returns",
"an",
"array",
"of",
"messages"
] | cd82523e175ee3786c1a262fb7e75c38f24c0eb1 | https://github.com/philelson/VagrantTransient/blob/cd82523e175ee3786c1a262fb7e75c38f24c0eb1/src/Environments.php#L94-L105 |
7,409 | zepi/turbo-base | Zepi/Web/UserInterface/src/Renderer/Pagination.php | Pagination.prepare | public function prepare(DataRequest $dataRequest, $paginationUrl, $numberOfEntries, $numberOfEntriesPerPage = 10)
{
$this->paginationUrl = $paginationUrl;
$neededPages = ceil($numberOfEntries / $numberOfEntriesPerPage);
$activePage = $dataRequest->getPage();
$pagination = new PaginationObject();
if ($activePage > 1) {
// Add the first page button
$button = new Button('«', $this->buildUrl(1));
$pagination->addEntry($button);
// Add the prev page button
$button = new Button('‹', $this->buildUrl(($activePage - 1)));
$pagination->addEntry($button);
}
$this->addPages($pagination, $activePage, $neededPages);
if ($activePage < $neededPages) {
// Add the next page button
$button = new Button('›', $this->buildUrl(($activePage + 1)));
$pagination->addEntry($button);
// Add the last page button
$button = new Button('»', $this->buildUrl($neededPages));
$pagination->addEntry($button);
}
return $pagination;
} | php | public function prepare(DataRequest $dataRequest, $paginationUrl, $numberOfEntries, $numberOfEntriesPerPage = 10)
{
$this->paginationUrl = $paginationUrl;
$neededPages = ceil($numberOfEntries / $numberOfEntriesPerPage);
$activePage = $dataRequest->getPage();
$pagination = new PaginationObject();
if ($activePage > 1) {
// Add the first page button
$button = new Button('«', $this->buildUrl(1));
$pagination->addEntry($button);
// Add the prev page button
$button = new Button('‹', $this->buildUrl(($activePage - 1)));
$pagination->addEntry($button);
}
$this->addPages($pagination, $activePage, $neededPages);
if ($activePage < $neededPages) {
// Add the next page button
$button = new Button('›', $this->buildUrl(($activePage + 1)));
$pagination->addEntry($button);
// Add the last page button
$button = new Button('»', $this->buildUrl($neededPages));
$pagination->addEntry($button);
}
return $pagination;
} | [
"public",
"function",
"prepare",
"(",
"DataRequest",
"$",
"dataRequest",
",",
"$",
"paginationUrl",
",",
"$",
"numberOfEntries",
",",
"$",
"numberOfEntriesPerPage",
"=",
"10",
")",
"{",
"$",
"this",
"->",
"paginationUrl",
"=",
"$",
"paginationUrl",
";",
"$",
"neededPages",
"=",
"ceil",
"(",
"$",
"numberOfEntries",
"/",
"$",
"numberOfEntriesPerPage",
")",
";",
"$",
"activePage",
"=",
"$",
"dataRequest",
"->",
"getPage",
"(",
")",
";",
"$",
"pagination",
"=",
"new",
"PaginationObject",
"(",
")",
";",
"if",
"(",
"$",
"activePage",
">",
"1",
")",
"{",
"// Add the first page button",
"$",
"button",
"=",
"new",
"Button",
"(",
"'«'",
",",
"$",
"this",
"->",
"buildUrl",
"(",
"1",
")",
")",
";",
"$",
"pagination",
"->",
"addEntry",
"(",
"$",
"button",
")",
";",
"// Add the prev page button",
"$",
"button",
"=",
"new",
"Button",
"(",
"'‹'",
",",
"$",
"this",
"->",
"buildUrl",
"(",
"(",
"$",
"activePage",
"-",
"1",
")",
")",
")",
";",
"$",
"pagination",
"->",
"addEntry",
"(",
"$",
"button",
")",
";",
"}",
"$",
"this",
"->",
"addPages",
"(",
"$",
"pagination",
",",
"$",
"activePage",
",",
"$",
"neededPages",
")",
";",
"if",
"(",
"$",
"activePage",
"<",
"$",
"neededPages",
")",
"{",
"// Add the next page button",
"$",
"button",
"=",
"new",
"Button",
"(",
"'›'",
",",
"$",
"this",
"->",
"buildUrl",
"(",
"(",
"$",
"activePage",
"+",
"1",
")",
")",
")",
";",
"$",
"pagination",
"->",
"addEntry",
"(",
"$",
"button",
")",
";",
"// Add the last page button",
"$",
"button",
"=",
"new",
"Button",
"(",
"'»'",
",",
"$",
"this",
"->",
"buildUrl",
"(",
"$",
"neededPages",
")",
")",
";",
"$",
"pagination",
"->",
"addEntry",
"(",
"$",
"button",
")",
";",
"}",
"return",
"$",
"pagination",
";",
"}"
] | Prepares the Pagination object for the given DataRequest and number of entries per page
@access public
@param \Zepi\DataSource\Core\Entity\DataRequest $dataRequest
@param string $paginationUrl
@param integer $numberOfEntries
@param integer $numberOfEntriesPerPage
@return \Zepi\Web\UserInterface\Pagination\Pagination | [
"Prepares",
"the",
"Pagination",
"object",
"for",
"the",
"given",
"DataRequest",
"and",
"number",
"of",
"entries",
"per",
"page"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Renderer/Pagination.php#L71-L103 |
7,410 | zepi/turbo-base | Zepi/Web/UserInterface/src/Renderer/Pagination.php | Pagination.addPages | protected function addPages(PaginationObject $pagination, $activePage, $neededPages)
{
// Add the pages
for ($i = 1; $i <= $neededPages; $i++) {
if ($i == $activePage) {
$page = new ActivePage($i, $this->buildUrl($i));
$pagination->addEntry($page);
} else if ($i < 4 || $i > ($neededPages - 3) || ($i > ($activePage - 3) && $i < ($activePage + 3))) {
$page = new Page($i, $this->buildUrl($i));
$pagination->addEntry($page);
} else if (!($pagination->getLatestEntry() instanceof Dots)) {
$dots = new Dots();
$pagination->addEntry($dots);
}
}
} | php | protected function addPages(PaginationObject $pagination, $activePage, $neededPages)
{
// Add the pages
for ($i = 1; $i <= $neededPages; $i++) {
if ($i == $activePage) {
$page = new ActivePage($i, $this->buildUrl($i));
$pagination->addEntry($page);
} else if ($i < 4 || $i > ($neededPages - 3) || ($i > ($activePage - 3) && $i < ($activePage + 3))) {
$page = new Page($i, $this->buildUrl($i));
$pagination->addEntry($page);
} else if (!($pagination->getLatestEntry() instanceof Dots)) {
$dots = new Dots();
$pagination->addEntry($dots);
}
}
} | [
"protected",
"function",
"addPages",
"(",
"PaginationObject",
"$",
"pagination",
",",
"$",
"activePage",
",",
"$",
"neededPages",
")",
"{",
"// Add the pages",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"neededPages",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"i",
"==",
"$",
"activePage",
")",
"{",
"$",
"page",
"=",
"new",
"ActivePage",
"(",
"$",
"i",
",",
"$",
"this",
"->",
"buildUrl",
"(",
"$",
"i",
")",
")",
";",
"$",
"pagination",
"->",
"addEntry",
"(",
"$",
"page",
")",
";",
"}",
"else",
"if",
"(",
"$",
"i",
"<",
"4",
"||",
"$",
"i",
">",
"(",
"$",
"neededPages",
"-",
"3",
")",
"||",
"(",
"$",
"i",
">",
"(",
"$",
"activePage",
"-",
"3",
")",
"&&",
"$",
"i",
"<",
"(",
"$",
"activePage",
"+",
"3",
")",
")",
")",
"{",
"$",
"page",
"=",
"new",
"Page",
"(",
"$",
"i",
",",
"$",
"this",
"->",
"buildUrl",
"(",
"$",
"i",
")",
")",
";",
"$",
"pagination",
"->",
"addEntry",
"(",
"$",
"page",
")",
";",
"}",
"else",
"if",
"(",
"!",
"(",
"$",
"pagination",
"->",
"getLatestEntry",
"(",
")",
"instanceof",
"Dots",
")",
")",
"{",
"$",
"dots",
"=",
"new",
"Dots",
"(",
")",
";",
"$",
"pagination",
"->",
"addEntry",
"(",
"$",
"dots",
")",
";",
"}",
"}",
"}"
] | Add the pages to the pagination
@param \Zepi\Web\UserInterface\Pagination\Pagination $pagination
@param integer $activePage
@param integer $neededPages | [
"Add",
"the",
"pages",
"to",
"the",
"pagination"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Web/UserInterface/src/Renderer/Pagination.php#L112-L127 |
7,411 | robertboloc/zf2-components-list-generator | src/Zf2ComponentsList.php | Zf2ComponentsList.toFile | public function toFile($file)
{
$composer = json_decode(file_get_contents($file), true);
// Remove the zendframework/zendframework
unset($composer['require']['zendframework/zendframework']);
// Add all the found components
foreach (array_keys($this->components) as $component) {
$composer['require']['zendframework/' . $component] = $this->version;
}
file_put_contents($file, json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
} | php | public function toFile($file)
{
$composer = json_decode(file_get_contents($file), true);
// Remove the zendframework/zendframework
unset($composer['require']['zendframework/zendframework']);
// Add all the found components
foreach (array_keys($this->components) as $component) {
$composer['require']['zendframework/' . $component] = $this->version;
}
file_put_contents($file, json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
} | [
"public",
"function",
"toFile",
"(",
"$",
"file",
")",
"{",
"$",
"composer",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
",",
"true",
")",
";",
"// Remove the zendframework/zendframework",
"unset",
"(",
"$",
"composer",
"[",
"'require'",
"]",
"[",
"'zendframework/zendframework'",
"]",
")",
";",
"// Add all the found components",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"components",
")",
"as",
"$",
"component",
")",
"{",
"$",
"composer",
"[",
"'require'",
"]",
"[",
"'zendframework/'",
".",
"$",
"component",
"]",
"=",
"$",
"this",
"->",
"version",
";",
"}",
"file_put_contents",
"(",
"$",
"file",
",",
"json_encode",
"(",
"$",
"composer",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_SLASHES",
")",
")",
";",
"}"
] | Updates the composer.json file with the new components list.
@param string $file | [
"Updates",
"the",
"composer",
".",
"json",
"file",
"with",
"the",
"new",
"components",
"list",
"."
] | 320bbced30af4e93c32a602b0a93f684682d9b12 | https://github.com/robertboloc/zf2-components-list-generator/blob/320bbced30af4e93c32a602b0a93f684682d9b12/src/Zf2ComponentsList.php#L100-L113 |
7,412 | robertboloc/zf2-components-list-generator | src/Zf2ComponentsList.php | Zf2ComponentsList.toConsole | public function toConsole()
{
$this->getConsole()->writeLine(
'Replace "zendframework/zendframework" in your composer.json file with :', Color::YELLOW
);
$componentsCount = count($this->components);
$count = 0;
foreach (array_keys($this->components) as $component) {
$suffix = '';
$count++;
if ($count < $componentsCount) {
$suffix = ',';
}
$this->getConsole()->writeLine('"zendframework/' . $component . '": "' . $this->version . '"' . $suffix);
}
} | php | public function toConsole()
{
$this->getConsole()->writeLine(
'Replace "zendframework/zendframework" in your composer.json file with :', Color::YELLOW
);
$componentsCount = count($this->components);
$count = 0;
foreach (array_keys($this->components) as $component) {
$suffix = '';
$count++;
if ($count < $componentsCount) {
$suffix = ',';
}
$this->getConsole()->writeLine('"zendframework/' . $component . '": "' . $this->version . '"' . $suffix);
}
} | [
"public",
"function",
"toConsole",
"(",
")",
"{",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"writeLine",
"(",
"'Replace \"zendframework/zendframework\" in your composer.json file with :'",
",",
"Color",
"::",
"YELLOW",
")",
";",
"$",
"componentsCount",
"=",
"count",
"(",
"$",
"this",
"->",
"components",
")",
";",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"components",
")",
"as",
"$",
"component",
")",
"{",
"$",
"suffix",
"=",
"''",
";",
"$",
"count",
"++",
";",
"if",
"(",
"$",
"count",
"<",
"$",
"componentsCount",
")",
"{",
"$",
"suffix",
"=",
"','",
";",
"}",
"$",
"this",
"->",
"getConsole",
"(",
")",
"->",
"writeLine",
"(",
"'\"zendframework/'",
".",
"$",
"component",
".",
"'\": \"'",
".",
"$",
"this",
"->",
"version",
".",
"'\"'",
".",
"$",
"suffix",
")",
";",
"}",
"}"
] | Sends the components list to the console. | [
"Sends",
"the",
"components",
"list",
"to",
"the",
"console",
"."
] | 320bbced30af4e93c32a602b0a93f684682d9b12 | https://github.com/robertboloc/zf2-components-list-generator/blob/320bbced30af4e93c32a602b0a93f684682d9b12/src/Zf2ComponentsList.php#L118-L135 |
7,413 | fusible/fusible.authrole | src/AuthRoleTrait.php | AuthRoleTrait.getRoleFromAuth | protected function getRoleFromAuth(AuraAuth $auth)
{
if (! $auth->isValid()) {
return $this->guestRole;
}
$data = $auth->getUserData();
return isset($data[$this->roleKey])
? $data[$this->roleKey]
: $this->memberRole;
} | php | protected function getRoleFromAuth(AuraAuth $auth)
{
if (! $auth->isValid()) {
return $this->guestRole;
}
$data = $auth->getUserData();
return isset($data[$this->roleKey])
? $data[$this->roleKey]
: $this->memberRole;
} | [
"protected",
"function",
"getRoleFromAuth",
"(",
"AuraAuth",
"$",
"auth",
")",
"{",
"if",
"(",
"!",
"$",
"auth",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"guestRole",
";",
"}",
"$",
"data",
"=",
"$",
"auth",
"->",
"getUserData",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"data",
"[",
"$",
"this",
"->",
"roleKey",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"this",
"->",
"roleKey",
"]",
":",
"$",
"this",
"->",
"memberRole",
";",
"}"
] | Get Role from Auth
@param AuraAuth $auth Auth object
@return string
@access protected | [
"Get",
"Role",
"from",
"Auth"
] | f4fafaf47f320254a0820a7f6088ce0581f1ca53 | https://github.com/fusible/fusible.authrole/blob/f4fafaf47f320254a0820a7f6088ce0581f1ca53/src/AuthRoleTrait.php#L120-L131 |
7,414 | Dhii/data-container-base | src/CreateContainerExceptionCapableTrait.php | CreateContainerExceptionCapableTrait._createContainerException | protected function _createContainerException(
$message = null,
$code = null,
RootException $previous = null,
BaseContainerInterface $container = null
) {
return new ContainerException($message, $code, $previous, $container);
} | php | protected function _createContainerException(
$message = null,
$code = null,
RootException $previous = null,
BaseContainerInterface $container = null
) {
return new ContainerException($message, $code, $previous, $container);
} | [
"protected",
"function",
"_createContainerException",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"code",
"=",
"null",
",",
"RootException",
"$",
"previous",
"=",
"null",
",",
"BaseContainerInterface",
"$",
"container",
"=",
"null",
")",
"{",
"return",
"new",
"ContainerException",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
",",
"$",
"container",
")",
";",
"}"
] | Creates a new container exception.
@param string|Stringable|null $message The exception message, if any.
@param int|string|Stringable|null $code The numeric exception code, if any.
@param RootException|null $previous The inner exception, if any.
@param BaseContainerInterface|null $container The associated container, if any.
@since [*next-version*]
@return ContainerException The new exception. | [
"Creates",
"a",
"new",
"container",
"exception",
"."
] | ed3289171827cdc910d74c5ef76aab5f5985dace | https://github.com/Dhii/data-container-base/blob/ed3289171827cdc910d74c5ef76aab5f5985dace/src/CreateContainerExceptionCapableTrait.php#L24-L31 |
7,415 | lucidphp/xml | src/Parser.php | Parser.getPhpValue | public static function getPhpValue($val, $default = null, ParserInterface $parser = null)
{
if ($val instanceof DOMElement) {
$parser = $parser ?: new static;
return $parser->parseDomElement($val);
}
if (0 === strlen($val)) {
return $default;
}
if (0 === strpos($val, '0x') && preg_match('#^[[:xdigit:]]+$#', substr($val, 2))) {
return hexdec($val);
}
if (is_numeric($val)) {
return ctype_digit($val) ? intval($val) : floatval($val);
}
if (in_array($lval = strtolower($val), ['true', 'false'])) {
return $lval === 'true' ? true : false;
}
return $val;
} | php | public static function getPhpValue($val, $default = null, ParserInterface $parser = null)
{
if ($val instanceof DOMElement) {
$parser = $parser ?: new static;
return $parser->parseDomElement($val);
}
if (0 === strlen($val)) {
return $default;
}
if (0 === strpos($val, '0x') && preg_match('#^[[:xdigit:]]+$#', substr($val, 2))) {
return hexdec($val);
}
if (is_numeric($val)) {
return ctype_digit($val) ? intval($val) : floatval($val);
}
if (in_array($lval = strtolower($val), ['true', 'false'])) {
return $lval === 'true' ? true : false;
}
return $val;
} | [
"public",
"static",
"function",
"getPhpValue",
"(",
"$",
"val",
",",
"$",
"default",
"=",
"null",
",",
"ParserInterface",
"$",
"parser",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"val",
"instanceof",
"DOMElement",
")",
"{",
"$",
"parser",
"=",
"$",
"parser",
"?",
":",
"new",
"static",
";",
"return",
"$",
"parser",
"->",
"parseDomElement",
"(",
"$",
"val",
")",
";",
"}",
"if",
"(",
"0",
"===",
"strlen",
"(",
"$",
"val",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"val",
",",
"'0x'",
")",
"&&",
"preg_match",
"(",
"'#^[[:xdigit:]]+$#'",
",",
"substr",
"(",
"$",
"val",
",",
"2",
")",
")",
")",
"{",
"return",
"hexdec",
"(",
"$",
"val",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"val",
")",
")",
"{",
"return",
"ctype_digit",
"(",
"$",
"val",
")",
"?",
"intval",
"(",
"$",
"val",
")",
":",
"floatval",
"(",
"$",
"val",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"lval",
"=",
"strtolower",
"(",
"$",
"val",
")",
",",
"[",
"'true'",
",",
"'false'",
"]",
")",
")",
"{",
"return",
"$",
"lval",
"===",
"'true'",
"?",
"true",
":",
"false",
";",
"}",
"return",
"$",
"val",
";",
"}"
] | Get the php equivalent of an input value derived from any king of xml.
@param mixed $val
@param mixed $default
@param ParserInterface $parser
@return mixed | [
"Get",
"the",
"php",
"equivalent",
"of",
"an",
"input",
"value",
"derived",
"from",
"any",
"king",
"of",
"xml",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L238-L263 |
7,416 | lucidphp/xml | src/Parser.php | Parser.getElementText | public static function getElementText(DOMElement $element, $concat = true)
{
$textNodes = [];
foreach ($element->xpath('./text()') as $text) {
if ($value = static::clearValue($text->nodeValue)) {
$textNodes[] = $value;
}
}
return $concat ? implode($textNodes) : $textNodes;
} | php | public static function getElementText(DOMElement $element, $concat = true)
{
$textNodes = [];
foreach ($element->xpath('./text()') as $text) {
if ($value = static::clearValue($text->nodeValue)) {
$textNodes[] = $value;
}
}
return $concat ? implode($textNodes) : $textNodes;
} | [
"public",
"static",
"function",
"getElementText",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"concat",
"=",
"true",
")",
"{",
"$",
"textNodes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"element",
"->",
"xpath",
"(",
"'./text()'",
")",
"as",
"$",
"text",
")",
"{",
"if",
"(",
"$",
"value",
"=",
"static",
"::",
"clearValue",
"(",
"$",
"text",
"->",
"nodeValue",
")",
")",
"{",
"$",
"textNodes",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"concat",
"?",
"implode",
"(",
"$",
"textNodes",
")",
":",
"$",
"textNodes",
";",
"}"
] | Get the text of a `DOMElement` excluding the contents
of its child elements.
@param DOMElement $element
@param bool $concat
@return string|array returns an array of strings if `$concat` is `false` | [
"Get",
"the",
"text",
"of",
"a",
"DOMElement",
"excluding",
"the",
"contents",
"of",
"its",
"child",
"elements",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L274-L284 |
7,417 | lucidphp/xml | src/Parser.php | Parser.isListKey | protected function isListKey($name, $prefix = null)
{
return $this->prefixKey($this->getIndexKey(), $prefix) === $name;
} | php | protected function isListKey($name, $prefix = null)
{
return $this->prefixKey($this->getIndexKey(), $prefix) === $name;
} | [
"protected",
"function",
"isListKey",
"(",
"$",
"name",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"prefixKey",
"(",
"$",
"this",
"->",
"getIndexKey",
"(",
")",
",",
"$",
"prefix",
")",
"===",
"$",
"name",
";",
"}"
] | Check if a given string is the list identifier.
@param string $name
@param string $prefix
@return bool | [
"Check",
"if",
"a",
"given",
"string",
"is",
"the",
"list",
"identifier",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L318-L321 |
7,418 | lucidphp/xml | src/Parser.php | Parser.normalizeKey | protected function normalizeKey($key)
{
if (null !== $this->keyNormalizer) {
return call_user_func($this->keyNormalizer, $key);
}
return static::fixNodeName($key);
} | php | protected function normalizeKey($key)
{
if (null !== $this->keyNormalizer) {
return call_user_func($this->keyNormalizer, $key);
}
return static::fixNodeName($key);
} | [
"protected",
"function",
"normalizeKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"keyNormalizer",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"keyNormalizer",
",",
"$",
"key",
")",
";",
"}",
"return",
"static",
"::",
"fixNodeName",
"(",
"$",
"key",
")",
";",
"}"
] | Normalize a node key
@param mixed $key
@return mixed | [
"Normalize",
"a",
"node",
"key"
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L356-L363 |
7,419 | lucidphp/xml | src/Parser.php | Parser.prepareTextValue | private function prepareTextValue(DOMElement $xml, array $attributes = null)
{
$text = static::getElementText($xml, true);
return (isset($attributes['type']) && 'text' === $attributes['type']) ?
static::clearValue($text) :
static::getPhpValue($text, null, $this);
} | php | private function prepareTextValue(DOMElement $xml, array $attributes = null)
{
$text = static::getElementText($xml, true);
return (isset($attributes['type']) && 'text' === $attributes['type']) ?
static::clearValue($text) :
static::getPhpValue($text, null, $this);
} | [
"private",
"function",
"prepareTextValue",
"(",
"DOMElement",
"$",
"xml",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"$",
"text",
"=",
"static",
"::",
"getElementText",
"(",
"$",
"xml",
",",
"true",
")",
";",
"return",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'type'",
"]",
")",
"&&",
"'text'",
"===",
"$",
"attributes",
"[",
"'type'",
"]",
")",
"?",
"static",
"::",
"clearValue",
"(",
"$",
"text",
")",
":",
"static",
"::",
"getPhpValue",
"(",
"$",
"text",
",",
"null",
",",
"$",
"this",
")",
";",
"}"
] | Convert bool like and numeric values to their php equivalent values.
@param DOMElement $xml the element to get the value from
@param array $attributes
@return mixed | [
"Convert",
"bool",
"like",
"and",
"numeric",
"values",
"to",
"their",
"php",
"equivalent",
"values",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L372-L379 |
7,420 | lucidphp/xml | src/Parser.php | Parser.parseElementNodes | private function parseElementNodes($children, $parentName = null)
{
$result = [];
foreach ($children as $child) {
$prefix = $child->prefix ?: null;
$oname = $this->normalizeKey($child->nodeName);
$name = $this->prefixKey($oname, $prefix);
if (isset($result[$name])) {
$this->parseSetResultNodes($child, $name, $result);
continue;
}
$this->parseUnsetResultNodes($child, $name, $oname, $parentName, $result, $prefix);
}
return $result;
} | php | private function parseElementNodes($children, $parentName = null)
{
$result = [];
foreach ($children as $child) {
$prefix = $child->prefix ?: null;
$oname = $this->normalizeKey($child->nodeName);
$name = $this->prefixKey($oname, $prefix);
if (isset($result[$name])) {
$this->parseSetResultNodes($child, $name, $result);
continue;
}
$this->parseUnsetResultNodes($child, $name, $oname, $parentName, $result, $prefix);
}
return $result;
} | [
"private",
"function",
"parseElementNodes",
"(",
"$",
"children",
",",
"$",
"parentName",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"prefix",
"=",
"$",
"child",
"->",
"prefix",
"?",
":",
"null",
";",
"$",
"oname",
"=",
"$",
"this",
"->",
"normalizeKey",
"(",
"$",
"child",
"->",
"nodeName",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"prefixKey",
"(",
"$",
"oname",
",",
"$",
"prefix",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"parseSetResultNodes",
"(",
"$",
"child",
",",
"$",
"name",
",",
"$",
"result",
")",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"parseUnsetResultNodes",
"(",
"$",
"child",
",",
"$",
"name",
",",
"$",
"oname",
",",
"$",
"parentName",
",",
"$",
"result",
",",
"$",
"prefix",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Parse a nodelist into a array
@param \DOMNodeList|array $children elements to parse
@param string $parentName node name of the parent element
@return array | [
"Parse",
"a",
"nodelist",
"into",
"a",
"array"
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L389-L407 |
7,421 | lucidphp/xml | src/Parser.php | Parser.parseSetResultNodes | private function parseSetResultNodes(DOMElement $child, $name, array &$result = null)
{
if (!(is_array($result[$name]) && $this->valueIsList($result[$name]))) {
return false;
}
$value = static::getPhpValue($child, null, $this);
if (is_array($value) && $this->valueIsList($value)) {
return $result[$name] = array_merge($result[$name], $value);
}
return $result[$name][] = $value;
} | php | private function parseSetResultNodes(DOMElement $child, $name, array &$result = null)
{
if (!(is_array($result[$name]) && $this->valueIsList($result[$name]))) {
return false;
}
$value = static::getPhpValue($child, null, $this);
if (is_array($value) && $this->valueIsList($value)) {
return $result[$name] = array_merge($result[$name], $value);
}
return $result[$name][] = $value;
} | [
"private",
"function",
"parseSetResultNodes",
"(",
"DOMElement",
"$",
"child",
",",
"$",
"name",
",",
"array",
"&",
"$",
"result",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"is_array",
"(",
"$",
"result",
"[",
"$",
"name",
"]",
")",
"&&",
"$",
"this",
"->",
"valueIsList",
"(",
"$",
"result",
"[",
"$",
"name",
"]",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"value",
"=",
"static",
"::",
"getPhpValue",
"(",
"$",
"child",
",",
"null",
",",
"$",
"this",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"$",
"this",
"->",
"valueIsList",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"array_merge",
"(",
"$",
"result",
"[",
"$",
"name",
"]",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"result",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}"
] | Parse a `DOMElement` if a result key is set.
@param DOMElement $child
@param string $name
@param array $result
@return mixed|bool the result, else `false` if no result. | [
"Parse",
"a",
"DOMElement",
"if",
"a",
"result",
"key",
"is",
"set",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L418-L431 |
7,422 | lucidphp/xml | src/Parser.php | Parser.parseUnsetResultNodes | private function parseUnsetResultNodes(DOMElement $child, $name, $oname, $pName, array &$result, $prefix = null)
{
if ($this->isListKey($name, $prefix) || $this->isEqualOrPluralOf($this->normalizeKey($pName), $oname)) {
// if attributes index is set, use it as index
if (($index = $child->getAttribute($this->getIndexAttributeKey())) && 0 !== strlen($index)) {
$child->removeAttribute($this->getIndexAttributeKey());
return $result[static::getPhpValue($index)] = static::getPhpValue($child, null, $this);
}
return $result[] = static::getPhpValue($child, null, $this);
}
$value = static::getPhpValue($child, null, $this);
if (1 < $this->getEqualNodes($child, $prefix)->length) {
return $result[$name][] = $value;
}
return $result[$name] = $value;
} | php | private function parseUnsetResultNodes(DOMElement $child, $name, $oname, $pName, array &$result, $prefix = null)
{
if ($this->isListKey($name, $prefix) || $this->isEqualOrPluralOf($this->normalizeKey($pName), $oname)) {
// if attributes index is set, use it as index
if (($index = $child->getAttribute($this->getIndexAttributeKey())) && 0 !== strlen($index)) {
$child->removeAttribute($this->getIndexAttributeKey());
return $result[static::getPhpValue($index)] = static::getPhpValue($child, null, $this);
}
return $result[] = static::getPhpValue($child, null, $this);
}
$value = static::getPhpValue($child, null, $this);
if (1 < $this->getEqualNodes($child, $prefix)->length) {
return $result[$name][] = $value;
}
return $result[$name] = $value;
} | [
"private",
"function",
"parseUnsetResultNodes",
"(",
"DOMElement",
"$",
"child",
",",
"$",
"name",
",",
"$",
"oname",
",",
"$",
"pName",
",",
"array",
"&",
"$",
"result",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isListKey",
"(",
"$",
"name",
",",
"$",
"prefix",
")",
"||",
"$",
"this",
"->",
"isEqualOrPluralOf",
"(",
"$",
"this",
"->",
"normalizeKey",
"(",
"$",
"pName",
")",
",",
"$",
"oname",
")",
")",
"{",
"// if attributes index is set, use it as index",
"if",
"(",
"(",
"$",
"index",
"=",
"$",
"child",
"->",
"getAttribute",
"(",
"$",
"this",
"->",
"getIndexAttributeKey",
"(",
")",
")",
")",
"&&",
"0",
"!==",
"strlen",
"(",
"$",
"index",
")",
")",
"{",
"$",
"child",
"->",
"removeAttribute",
"(",
"$",
"this",
"->",
"getIndexAttributeKey",
"(",
")",
")",
";",
"return",
"$",
"result",
"[",
"static",
"::",
"getPhpValue",
"(",
"$",
"index",
")",
"]",
"=",
"static",
"::",
"getPhpValue",
"(",
"$",
"child",
",",
"null",
",",
"$",
"this",
")",
";",
"}",
"return",
"$",
"result",
"[",
"]",
"=",
"static",
"::",
"getPhpValue",
"(",
"$",
"child",
",",
"null",
",",
"$",
"this",
")",
";",
"}",
"$",
"value",
"=",
"static",
"::",
"getPhpValue",
"(",
"$",
"child",
",",
"null",
",",
"$",
"this",
")",
";",
"if",
"(",
"1",
"<",
"$",
"this",
"->",
"getEqualNodes",
"(",
"$",
"child",
",",
"$",
"prefix",
")",
"->",
"length",
")",
"{",
"return",
"$",
"result",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Parse a `DOMElement` if a result key is unset.
@param DOMElement $child
@param string $name
@param string $oname
@param string $pName
@param array $result
@param string $prefix
@param array $attrs
@return mixed the result | [
"Parse",
"a",
"DOMElement",
"if",
"a",
"result",
"key",
"is",
"unset",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L446-L466 |
7,423 | lucidphp/xml | src/Parser.php | Parser.parseElementAttributes | private function parseElementAttributes(DOMElement $xml)
{
$attrs = [];
$elementAttrs = $xml->xpath('./@*');
if (0 === $elementAttrs->length) {
return $attrs;
}
foreach ($elementAttrs as $key => $attribute) {
$value = static::getPhpValue($attribute->nodeValue, null, $this);
$name = $this->normalizeKey($attribute->nodeName);
$attrs[$this->prefixKey($name, $attribute->prefix ?: null)] = $value;
}
return [$this->getAttributesKey() => $attrs];
} | php | private function parseElementAttributes(DOMElement $xml)
{
$attrs = [];
$elementAttrs = $xml->xpath('./@*');
if (0 === $elementAttrs->length) {
return $attrs;
}
foreach ($elementAttrs as $key => $attribute) {
$value = static::getPhpValue($attribute->nodeValue, null, $this);
$name = $this->normalizeKey($attribute->nodeName);
$attrs[$this->prefixKey($name, $attribute->prefix ?: null)] = $value;
}
return [$this->getAttributesKey() => $attrs];
} | [
"private",
"function",
"parseElementAttributes",
"(",
"DOMElement",
"$",
"xml",
")",
"{",
"$",
"attrs",
"=",
"[",
"]",
";",
"$",
"elementAttrs",
"=",
"$",
"xml",
"->",
"xpath",
"(",
"'./@*'",
")",
";",
"if",
"(",
"0",
"===",
"$",
"elementAttrs",
"->",
"length",
")",
"{",
"return",
"$",
"attrs",
";",
"}",
"foreach",
"(",
"$",
"elementAttrs",
"as",
"$",
"key",
"=>",
"$",
"attribute",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"getPhpValue",
"(",
"$",
"attribute",
"->",
"nodeValue",
",",
"null",
",",
"$",
"this",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"normalizeKey",
"(",
"$",
"attribute",
"->",
"nodeName",
")",
";",
"$",
"attrs",
"[",
"$",
"this",
"->",
"prefixKey",
"(",
"$",
"name",
",",
"$",
"attribute",
"->",
"prefix",
"?",
":",
"null",
")",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"[",
"$",
"this",
"->",
"getAttributesKey",
"(",
")",
"=>",
"$",
"attrs",
"]",
";",
"}"
] | Parse element attributes into an array.
@param DOMElement $xml
@return array | [
"Parse",
"element",
"attributes",
"into",
"an",
"array",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L475-L491 |
7,424 | lucidphp/xml | src/Parser.php | Parser.isEqualOrPluralOf | private function isEqualOrPluralOf($name, $singular)
{
return 0 === strnatcmp($name, $singular) || 0 === strnatcmp($name, $this->pluralize($singular));
} | php | private function isEqualOrPluralOf($name, $singular)
{
return 0 === strnatcmp($name, $singular) || 0 === strnatcmp($name, $this->pluralize($singular));
} | [
"private",
"function",
"isEqualOrPluralOf",
"(",
"$",
"name",
",",
"$",
"singular",
")",
"{",
"return",
"0",
"===",
"strnatcmp",
"(",
"$",
"name",
",",
"$",
"singular",
")",
"||",
"0",
"===",
"strnatcmp",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"pluralize",
"(",
"$",
"singular",
")",
")",
";",
"}"
] | Check if the input string is a plural or equal to a given comparative string.
@param string $name the input string
@param string $singular the string to compare with
@return bool | [
"Check",
"if",
"the",
"input",
"string",
"is",
"a",
"plural",
"or",
"equal",
"to",
"a",
"given",
"comparative",
"string",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L501-L504 |
7,425 | lucidphp/xml | src/Parser.php | Parser.pluralize | private function pluralize($singular)
{
if (null === $this->pluralizer) {
return $singular;
}
return call_user_func($this->pluralizer, $singular);
} | php | private function pluralize($singular)
{
if (null === $this->pluralizer) {
return $singular;
}
return call_user_func($this->pluralizer, $singular);
} | [
"private",
"function",
"pluralize",
"(",
"$",
"singular",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"pluralizer",
")",
"{",
"return",
"$",
"singular",
";",
"}",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"pluralizer",
",",
"$",
"singular",
")",
";",
"}"
] | Attempt to pluralize a string.
@param string $singular
@return string | [
"Attempt",
"to",
"pluralize",
"a",
"string",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L513-L520 |
7,426 | lucidphp/xml | src/Parser.php | Parser.getEqualNodes | private function getEqualNodes(DOMElement $node, $prefix = null)
{
$name = $this->prefixKey($node->nodeName, $prefix);
return $node->xpath(
sprintf(".|following-sibling::*[name() = '%s']|preceding-sibling::*[name() = '%s']", $name, $name)
);
} | php | private function getEqualNodes(DOMElement $node, $prefix = null)
{
$name = $this->prefixKey($node->nodeName, $prefix);
return $node->xpath(
sprintf(".|following-sibling::*[name() = '%s']|preceding-sibling::*[name() = '%s']", $name, $name)
);
} | [
"private",
"function",
"getEqualNodes",
"(",
"DOMElement",
"$",
"node",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"prefixKey",
"(",
"$",
"node",
"->",
"nodeName",
",",
"$",
"prefix",
")",
";",
"return",
"$",
"node",
"->",
"xpath",
"(",
"sprintf",
"(",
"\".|following-sibling::*[name() = '%s']|preceding-sibling::*[name() = '%s']\"",
",",
"$",
"name",
",",
"$",
"name",
")",
")",
";",
"}"
] | A lookahead to find sibling elements with similar names.
@param DOMElement $node the node in charge.
@param string $prefix the element prefix
@return \DOMNodeList | [
"A",
"lookahead",
"to",
"find",
"sibling",
"elements",
"with",
"similar",
"names",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L530-L537 |
7,427 | lucidphp/xml | src/Parser.php | Parser.convertDocument | private function convertDocument(\DOMDocument $xml)
{
return $this->loader->load($xml->saveXML(), [LoaderInterface::FROM_STRING => true]);
} | php | private function convertDocument(\DOMDocument $xml)
{
return $this->loader->load($xml->saveXML(), [LoaderInterface::FROM_STRING => true]);
} | [
"private",
"function",
"convertDocument",
"(",
"\\",
"DOMDocument",
"$",
"xml",
")",
"{",
"return",
"$",
"this",
"->",
"loader",
"->",
"load",
"(",
"$",
"xml",
"->",
"saveXML",
"(",
")",
",",
"[",
"LoaderInterface",
"::",
"FROM_STRING",
"=>",
"true",
"]",
")",
";",
"}"
] | Converts a `\DOMDocument`that is not an instance of
`Selene\Module\Dom\DOMDocument`.
@param \DOMDocument $xml the document to convert
@return DOMDocument | [
"Converts",
"a",
"\\",
"DOMDocument",
"that",
"is",
"not",
"an",
"instance",
"of",
"Selene",
"\\",
"Module",
"\\",
"Dom",
"\\",
"DOMDocument",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Parser.php#L562-L565 |
7,428 | mlocati/composer-patcher | src/PatchExecutor/PatchPatcher.php | PatchPatcher.patchIsAlreadyApplied | public function patchIsAlreadyApplied(Patch $patch, $baseDirectory, $patchLevel)
{
$command = $this->buildCommand($patch->getLocalPath(), $baseDirectory, $patchLevel, true);
list($rc, $stdOut, $stdErr) = $this->run($command);
if ($stdErr === '') {
$stdErr = $stdOut;
}
if ($rc === 1 && strpos($stdErr, 'Skipping patch.') !== false && preg_match('/^(\\d+) out of \\1 hunks? ignored/m', $stdErr)) {
return true;
}
return false;
} | php | public function patchIsAlreadyApplied(Patch $patch, $baseDirectory, $patchLevel)
{
$command = $this->buildCommand($patch->getLocalPath(), $baseDirectory, $patchLevel, true);
list($rc, $stdOut, $stdErr) = $this->run($command);
if ($stdErr === '') {
$stdErr = $stdOut;
}
if ($rc === 1 && strpos($stdErr, 'Skipping patch.') !== false && preg_match('/^(\\d+) out of \\1 hunks? ignored/m', $stdErr)) {
return true;
}
return false;
} | [
"public",
"function",
"patchIsAlreadyApplied",
"(",
"Patch",
"$",
"patch",
",",
"$",
"baseDirectory",
",",
"$",
"patchLevel",
")",
"{",
"$",
"command",
"=",
"$",
"this",
"->",
"buildCommand",
"(",
"$",
"patch",
"->",
"getLocalPath",
"(",
")",
",",
"$",
"baseDirectory",
",",
"$",
"patchLevel",
",",
"true",
")",
";",
"list",
"(",
"$",
"rc",
",",
"$",
"stdOut",
",",
"$",
"stdErr",
")",
"=",
"$",
"this",
"->",
"run",
"(",
"$",
"command",
")",
";",
"if",
"(",
"$",
"stdErr",
"===",
"''",
")",
"{",
"$",
"stdErr",
"=",
"$",
"stdOut",
";",
"}",
"if",
"(",
"$",
"rc",
"===",
"1",
"&&",
"strpos",
"(",
"$",
"stdErr",
",",
"'Skipping patch.'",
")",
"!==",
"false",
"&&",
"preg_match",
"(",
"'/^(\\\\d+) out of \\\\1 hunks? ignored/m'",
",",
"$",
"stdErr",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if a patch is already applied.
@param \ComposerPatcher\Patch $patch the patch to be analyzed
@param string $baseDirectory the directory where the patch should be applied
@param string $patchLevel the patch level
@return bool | [
"Check",
"if",
"a",
"patch",
"is",
"already",
"applied",
"."
] | d8ba45c10b5cf8ac8da3591e09b6afd47fc10667 | https://github.com/mlocati/composer-patcher/blob/d8ba45c10b5cf8ac8da3591e09b6afd47fc10667/src/PatchExecutor/PatchPatcher.php#L57-L69 |
7,429 | mlocati/composer-patcher | src/PatchExecutor/PatchPatcher.php | PatchPatcher.initializeWindows | private function initializeWindows()
{
$gitFolder = $this->findWindowsGitFolder();
if ($gitFolder !== '') {
$patchPath = "{$gitFolder}\\usr\\bin\\patch.exe";
if (is_file($patchPath)) {
try {
$patchPath = escapeshellarg($patchPath);
$this->checkCommandExists($patchPath);
$this->command = $patchPath;
return;
} catch (Exception\CommandNotFound $x) {
}
}
}
try {
$this->checkCommandExists('patch');
$this->command = 'patch';
return;
} catch (Exception\CommandNotFound $x) {
}
throw new Exception\CommandNotFound('patch', <<<'EOT'
The patch command is currently not available.
You have these options:
1. Install Git for Windows, and add it to the PATH environment variable
2. Find a Windows port of the "patch" GNU utility and it to a directory in the current PATH
EOT
);
} | php | private function initializeWindows()
{
$gitFolder = $this->findWindowsGitFolder();
if ($gitFolder !== '') {
$patchPath = "{$gitFolder}\\usr\\bin\\patch.exe";
if (is_file($patchPath)) {
try {
$patchPath = escapeshellarg($patchPath);
$this->checkCommandExists($patchPath);
$this->command = $patchPath;
return;
} catch (Exception\CommandNotFound $x) {
}
}
}
try {
$this->checkCommandExists('patch');
$this->command = 'patch';
return;
} catch (Exception\CommandNotFound $x) {
}
throw new Exception\CommandNotFound('patch', <<<'EOT'
The patch command is currently not available.
You have these options:
1. Install Git for Windows, and add it to the PATH environment variable
2. Find a Windows port of the "patch" GNU utility and it to a directory in the current PATH
EOT
);
} | [
"private",
"function",
"initializeWindows",
"(",
")",
"{",
"$",
"gitFolder",
"=",
"$",
"this",
"->",
"findWindowsGitFolder",
"(",
")",
";",
"if",
"(",
"$",
"gitFolder",
"!==",
"''",
")",
"{",
"$",
"patchPath",
"=",
"\"{$gitFolder}\\\\usr\\\\bin\\\\patch.exe\"",
";",
"if",
"(",
"is_file",
"(",
"$",
"patchPath",
")",
")",
"{",
"try",
"{",
"$",
"patchPath",
"=",
"escapeshellarg",
"(",
"$",
"patchPath",
")",
";",
"$",
"this",
"->",
"checkCommandExists",
"(",
"$",
"patchPath",
")",
";",
"$",
"this",
"->",
"command",
"=",
"$",
"patchPath",
";",
"return",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"CommandNotFound",
"$",
"x",
")",
"{",
"}",
"}",
"}",
"try",
"{",
"$",
"this",
"->",
"checkCommandExists",
"(",
"'patch'",
")",
";",
"$",
"this",
"->",
"command",
"=",
"'patch'",
";",
"return",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"CommandNotFound",
"$",
"x",
")",
"{",
"}",
"throw",
"new",
"Exception",
"\\",
"CommandNotFound",
"(",
"'patch'",
",",
" <<<'EOT'\nThe patch command is currently not available.\nYou have these options:\n1. Install Git for Windows, and add it to the PATH environment variable\n2. Find a Windows port of the \"patch\" GNU utility and it to a directory in the current PATH\nEOT",
")",
";",
"}"
] | Configure the instance for Windows.
@throws \ComposerPatcher\Exception\CommandNotFound when the patch command is not available | [
"Configure",
"the",
"instance",
"for",
"Windows",
"."
] | d8ba45c10b5cf8ac8da3591e09b6afd47fc10667 | https://github.com/mlocati/composer-patcher/blob/d8ba45c10b5cf8ac8da3591e09b6afd47fc10667/src/PatchExecutor/PatchPatcher.php#L108-L138 |
7,430 | mlocati/composer-patcher | src/PatchExecutor/PatchPatcher.php | PatchPatcher.findWindowsGitFolder | private function findWindowsGitFolder()
{
list($rc, $stdOut) = $this->run('where git.exe');
if ($rc !== 0) {
return '';
}
$stdOut = str_replace("\r\n", "\n", $stdOut);
foreach (explode("\n", trim($stdOut)) as $path) {
$easierPath = str_replace('\\', '/', $path);
$match = null;
if (preg_match('_^(.+)/(?:cmd|bin)/git\.exe$_i', $easierPath, $match)) {
return str_replace('/', '\\', $match[1]);
}
}
return '';
} | php | private function findWindowsGitFolder()
{
list($rc, $stdOut) = $this->run('where git.exe');
if ($rc !== 0) {
return '';
}
$stdOut = str_replace("\r\n", "\n", $stdOut);
foreach (explode("\n", trim($stdOut)) as $path) {
$easierPath = str_replace('\\', '/', $path);
$match = null;
if (preg_match('_^(.+)/(?:cmd|bin)/git\.exe$_i', $easierPath, $match)) {
return str_replace('/', '\\', $match[1]);
}
}
return '';
} | [
"private",
"function",
"findWindowsGitFolder",
"(",
")",
"{",
"list",
"(",
"$",
"rc",
",",
"$",
"stdOut",
")",
"=",
"$",
"this",
"->",
"run",
"(",
"'where git.exe'",
")",
";",
"if",
"(",
"$",
"rc",
"!==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"stdOut",
"=",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"$",
"stdOut",
")",
";",
"foreach",
"(",
"explode",
"(",
"\"\\n\"",
",",
"trim",
"(",
"$",
"stdOut",
")",
")",
"as",
"$",
"path",
")",
"{",
"$",
"easierPath",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"match",
"=",
"null",
";",
"if",
"(",
"preg_match",
"(",
"'_^(.+)/(?:cmd|bin)/git\\.exe$_i'",
",",
"$",
"easierPath",
",",
"$",
"match",
")",
")",
"{",
"return",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"match",
"[",
"1",
"]",
")",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Search the path where git is installed on Windows.
@return string Empty string if not found | [
"Search",
"the",
"path",
"where",
"git",
"is",
"installed",
"on",
"Windows",
"."
] | d8ba45c10b5cf8ac8da3591e09b6afd47fc10667 | https://github.com/mlocati/composer-patcher/blob/d8ba45c10b5cf8ac8da3591e09b6afd47fc10667/src/PatchExecutor/PatchPatcher.php#L145-L161 |
7,431 | d1maz/simple_pdo | src/WrapperPDO.php | WrapperPDO.getHits | public function getHits()
{
if ($this->hits === null) {
$this->hits = $this->stmt->rowCount();
}
return $this->hits;
} | php | public function getHits()
{
if ($this->hits === null) {
$this->hits = $this->stmt->rowCount();
}
return $this->hits;
} | [
"public",
"function",
"getHits",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hits",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"hits",
"=",
"$",
"this",
"->",
"stmt",
"->",
"rowCount",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"hits",
";",
"}"
] | Get number of results.
@api
@return int | [
"Get",
"number",
"of",
"results",
"."
] | 58943ca8140267d98f3a2342efaca1497ca25b8b | https://github.com/d1maz/simple_pdo/blob/58943ca8140267d98f3a2342efaca1497ca25b8b/src/WrapperPDO.php#L131-L138 |
7,432 | d1maz/simple_pdo | src/WrapperPDO.php | WrapperPDO.getResults | public function getResults()
{
if (empty($this->results)) {
$this->results = $this->stmt->fetchAll();
}
return $this->results;
} | php | public function getResults()
{
if (empty($this->results)) {
$this->results = $this->stmt->fetchAll();
}
return $this->results;
} | [
"public",
"function",
"getResults",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"results",
")",
")",
"{",
"$",
"this",
"->",
"results",
"=",
"$",
"this",
"->",
"stmt",
"->",
"fetchAll",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"results",
";",
"}"
] | Get all results from the SELECT-Statement.
@api
@return mixed[] | [
"Get",
"all",
"results",
"from",
"the",
"SELECT",
"-",
"Statement",
"."
] | 58943ca8140267d98f3a2342efaca1497ca25b8b | https://github.com/d1maz/simple_pdo/blob/58943ca8140267d98f3a2342efaca1497ca25b8b/src/WrapperPDO.php#L146-L153 |
7,433 | d1maz/simple_pdo | src/WrapperPDO.php | WrapperPDO.getFirstResult | public function getFirstResult($field = null)
{
if (empty($this->results)) {
$this->results = isset($field) ? $this->stmt->fetch()[$field] : $this->stmt->fetch();
}
return $this->results;
} | php | public function getFirstResult($field = null)
{
if (empty($this->results)) {
$this->results = isset($field) ? $this->stmt->fetch()[$field] : $this->stmt->fetch();
}
return $this->results;
} | [
"public",
"function",
"getFirstResult",
"(",
"$",
"field",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"results",
")",
")",
"{",
"$",
"this",
"->",
"results",
"=",
"isset",
"(",
"$",
"field",
")",
"?",
"$",
"this",
"->",
"stmt",
"->",
"fetch",
"(",
")",
"[",
"$",
"field",
"]",
":",
"$",
"this",
"->",
"stmt",
"->",
"fetch",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"results",
";",
"}"
] | Get the first result from the SELECT-Statement.
@api
@param string $field
@return mixed | [
"Get",
"the",
"first",
"result",
"from",
"the",
"SELECT",
"-",
"Statement",
"."
] | 58943ca8140267d98f3a2342efaca1497ca25b8b | https://github.com/d1maz/simple_pdo/blob/58943ca8140267d98f3a2342efaca1497ca25b8b/src/WrapperPDO.php#L164-L171 |
7,434 | traq/installer | src/Controllers/Checks.php | Checks.licenseAgreementAction | public function licenseAgreementAction()
{
$this->title("License Agreement");
// Get license
$license = file_get_contents(dirname(dirname(__DIR__)) . '/COPYING');
$this->set("license", $license);
return $this->render("license_agreement.phtml");
} | php | public function licenseAgreementAction()
{
$this->title("License Agreement");
// Get license
$license = file_get_contents(dirname(dirname(__DIR__)) . '/COPYING');
$this->set("license", $license);
return $this->render("license_agreement.phtml");
} | [
"public",
"function",
"licenseAgreementAction",
"(",
")",
"{",
"$",
"this",
"->",
"title",
"(",
"\"License Agreement\"",
")",
";",
"// Get license",
"$",
"license",
"=",
"file_get_contents",
"(",
"dirname",
"(",
"dirname",
"(",
"__DIR__",
")",
")",
".",
"'/COPYING'",
")",
";",
"$",
"this",
"->",
"set",
"(",
"\"license\"",
",",
"$",
"license",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"\"license_agreement.phtml\"",
")",
";",
"}"
] | License agreement page. | [
"License",
"agreement",
"page",
"."
] | 7d82ee13d11c59cb63bcb7739962c85a994271ef | https://github.com/traq/installer/blob/7d82ee13d11c59cb63bcb7739962c85a994271ef/src/Controllers/Checks.php#L35-L44 |
7,435 | andela-womokoro/potato-orm | src/Base.php | Base.findByPosition | public static function findByPosition($position)
{
try {
$offset = $position - 1;
$tableName = self::getTableName();
$conn = self::getConnection();
$stmt = $conn->query('SELECT * FROM '.$tableName.' LIMIT '.$offset.', 1'); //mysql syntax
if(! $stmt) {
$stmt = $conn->query('SELECT * FROM '.$tableName.' OFFSET '.$offset.' LIMIT 1'); //pgsql syntax
}
return self::find($stmt);;
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | php | public static function findByPosition($position)
{
try {
$offset = $position - 1;
$tableName = self::getTableName();
$conn = self::getConnection();
$stmt = $conn->query('SELECT * FROM '.$tableName.' LIMIT '.$offset.', 1'); //mysql syntax
if(! $stmt) {
$stmt = $conn->query('SELECT * FROM '.$tableName.' OFFSET '.$offset.' LIMIT 1'); //pgsql syntax
}
return self::find($stmt);;
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | [
"public",
"static",
"function",
"findByPosition",
"(",
"$",
"position",
")",
"{",
"try",
"{",
"$",
"offset",
"=",
"$",
"position",
"-",
"1",
";",
"$",
"tableName",
"=",
"self",
"::",
"getTableName",
"(",
")",
";",
"$",
"conn",
"=",
"self",
"::",
"getConnection",
"(",
")",
";",
"$",
"stmt",
"=",
"$",
"conn",
"->",
"query",
"(",
"'SELECT * FROM '",
".",
"$",
"tableName",
".",
"' LIMIT '",
".",
"$",
"offset",
".",
"', 1'",
")",
";",
"//mysql syntax",
"if",
"(",
"!",
"$",
"stmt",
")",
"{",
"$",
"stmt",
"=",
"$",
"conn",
"->",
"query",
"(",
"'SELECT * FROM '",
".",
"$",
"tableName",
".",
"' OFFSET '",
".",
"$",
"offset",
".",
"' LIMIT 1'",
")",
";",
"//pgsql syntax",
"}",
"return",
"self",
"::",
"find",
"(",
"$",
"stmt",
")",
";",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pe",
")",
"{",
"return",
"$",
"pe",
"->",
"getMessage",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}"
] | Finds a record in the database table in the position denoted by the parameter passed
@param integer $position | [
"Finds",
"a",
"record",
"in",
"the",
"database",
"table",
"in",
"the",
"position",
"denoted",
"by",
"the",
"parameter",
"passed"
] | b8e8757fa8e520efdd61583c2ba489bc76f291ae | https://github.com/andela-womokoro/potato-orm/blob/b8e8757fa8e520efdd61583c2ba489bc76f291ae/src/Base.php#L46-L66 |
7,436 | andela-womokoro/potato-orm | src/Base.php | Base.findById | public static function findById($id)
{
try {
$tableName = self::getTableName();
$conn = self::getConnection();
$stmt = $conn->query('SELECT * FROM '.$tableName.' WHERE id='.$id);
return self::find($stmt);
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | php | public static function findById($id)
{
try {
$tableName = self::getTableName();
$conn = self::getConnection();
$stmt = $conn->query('SELECT * FROM '.$tableName.' WHERE id='.$id);
return self::find($stmt);
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | [
"public",
"static",
"function",
"findById",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"tableName",
"=",
"self",
"::",
"getTableName",
"(",
")",
";",
"$",
"conn",
"=",
"self",
"::",
"getConnection",
"(",
")",
";",
"$",
"stmt",
"=",
"$",
"conn",
"->",
"query",
"(",
"'SELECT * FROM '",
".",
"$",
"tableName",
".",
"' WHERE id='",
".",
"$",
"id",
")",
";",
"return",
"self",
"::",
"find",
"(",
"$",
"stmt",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pe",
")",
"{",
"return",
"$",
"pe",
"->",
"getMessage",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}"
] | Finds a record in the database table that has the id passed in as a parameter
@param integer $id | [
"Finds",
"a",
"record",
"in",
"the",
"database",
"table",
"that",
"has",
"the",
"id",
"passed",
"in",
"as",
"a",
"parameter"
] | b8e8757fa8e520efdd61583c2ba489bc76f291ae | https://github.com/andela-womokoro/potato-orm/blob/b8e8757fa8e520efdd61583c2ba489bc76f291ae/src/Base.php#L72-L88 |
7,437 | andela-womokoro/potato-orm | src/Base.php | Base.find | public static function find($stmt)
{
try {
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if(! $result) {
throw new Exception(" Record not found.");
}
$object = new static;
$object->id = $result['id'];
$object->result = json_encode($result);
return $object;
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | php | public static function find($stmt)
{
try {
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if(! $result) {
throw new Exception(" Record not found.");
}
$object = new static;
$object->id = $result['id'];
$object->result = json_encode($result);
return $object;
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | [
"public",
"static",
"function",
"find",
"(",
"$",
"stmt",
")",
"{",
"try",
"{",
"$",
"result",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\" Record not found.\"",
")",
";",
"}",
"$",
"object",
"=",
"new",
"static",
";",
"$",
"object",
"->",
"id",
"=",
"$",
"result",
"[",
"'id'",
"]",
";",
"$",
"object",
"->",
"result",
"=",
"json_encode",
"(",
"$",
"result",
")",
";",
"return",
"$",
"object",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pe",
")",
"{",
"return",
"$",
"pe",
"->",
"getMessage",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}"
] | Finds a record in the database using the statement object passed in
@param PDO statement $stmt | [
"Finds",
"a",
"record",
"in",
"the",
"database",
"using",
"the",
"statement",
"object",
"passed",
"in"
] | b8e8757fa8e520efdd61583c2ba489bc76f291ae | https://github.com/andela-womokoro/potato-orm/blob/b8e8757fa8e520efdd61583c2ba489bc76f291ae/src/Base.php#L94-L114 |
7,438 | andela-womokoro/potato-orm | src/Base.php | Base.getAll | public static function getAll()
{
try {
$tableName = self::getTableName();
$conn = self::getConnection();
$stmt = $conn->query('SELECT * FROM '.$tableName);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | php | public static function getAll()
{
try {
$tableName = self::getTableName();
$conn = self::getConnection();
$stmt = $conn->query('SELECT * FROM '.$tableName);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | [
"public",
"static",
"function",
"getAll",
"(",
")",
"{",
"try",
"{",
"$",
"tableName",
"=",
"self",
"::",
"getTableName",
"(",
")",
";",
"$",
"conn",
"=",
"self",
"::",
"getConnection",
"(",
")",
";",
"$",
"stmt",
"=",
"$",
"conn",
"->",
"query",
"(",
"'SELECT * FROM '",
".",
"$",
"tableName",
")",
";",
"return",
"$",
"stmt",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pe",
")",
"{",
"return",
"$",
"pe",
"->",
"getMessage",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}"
] | This method fetches all the records in the database table and returns them in an array | [
"This",
"method",
"fetches",
"all",
"the",
"records",
"in",
"the",
"database",
"table",
"and",
"returns",
"them",
"in",
"an",
"array"
] | b8e8757fa8e520efdd61583c2ba489bc76f291ae | https://github.com/andela-womokoro/potato-orm/blob/b8e8757fa8e520efdd61583c2ba489bc76f291ae/src/Base.php#L119-L135 |
7,439 | andela-womokoro/potato-orm | src/Base.php | Base.save | public static function save()
{
try {
$tableName = self::getTableName();
$affectedRows = 0;
$conn = self::getConnection();
if(array_key_exists("id", self::$fields)){
//update an existing record
$sql = self::makeUpdateSQL();
}
else {
//insert a new record
$tableColumns = implode(", ", array_keys(self::$fields));
$columnValues = "'".implode("', '", array_values(self::$fields))."'";
$sql = "INSERT INTO ".$tableName."($tableColumns) VALUES($columnValues)";
}
$affectedRows = $conn->exec($sql);
return $affectedRows;
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | php | public static function save()
{
try {
$tableName = self::getTableName();
$affectedRows = 0;
$conn = self::getConnection();
if(array_key_exists("id", self::$fields)){
//update an existing record
$sql = self::makeUpdateSQL();
}
else {
//insert a new record
$tableColumns = implode(", ", array_keys(self::$fields));
$columnValues = "'".implode("', '", array_values(self::$fields))."'";
$sql = "INSERT INTO ".$tableName."($tableColumns) VALUES($columnValues)";
}
$affectedRows = $conn->exec($sql);
return $affectedRows;
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | [
"public",
"static",
"function",
"save",
"(",
")",
"{",
"try",
"{",
"$",
"tableName",
"=",
"self",
"::",
"getTableName",
"(",
")",
";",
"$",
"affectedRows",
"=",
"0",
";",
"$",
"conn",
"=",
"self",
"::",
"getConnection",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"\"id\"",
",",
"self",
"::",
"$",
"fields",
")",
")",
"{",
"//update an existing record",
"$",
"sql",
"=",
"self",
"::",
"makeUpdateSQL",
"(",
")",
";",
"}",
"else",
"{",
"//insert a new record",
"$",
"tableColumns",
"=",
"implode",
"(",
"\", \"",
",",
"array_keys",
"(",
"self",
"::",
"$",
"fields",
")",
")",
";",
"$",
"columnValues",
"=",
"\"'\"",
".",
"implode",
"(",
"\"', '\"",
",",
"array_values",
"(",
"self",
"::",
"$",
"fields",
")",
")",
".",
"\"'\"",
";",
"$",
"sql",
"=",
"\"INSERT INTO \"",
".",
"$",
"tableName",
".",
"\"($tableColumns) VALUES($columnValues)\"",
";",
"}",
"$",
"affectedRows",
"=",
"$",
"conn",
"->",
"exec",
"(",
"$",
"sql",
")",
";",
"return",
"$",
"affectedRows",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pe",
")",
"{",
"return",
"$",
"pe",
"->",
"getMessage",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}"
] | This method inserts a new record into the database table or updates an already existing record | [
"This",
"method",
"inserts",
"a",
"new",
"record",
"into",
"the",
"database",
"table",
"or",
"updates",
"an",
"already",
"existing",
"record"
] | b8e8757fa8e520efdd61583c2ba489bc76f291ae | https://github.com/andela-womokoro/potato-orm/blob/b8e8757fa8e520efdd61583c2ba489bc76f291ae/src/Base.php#L140-L168 |
7,440 | andela-womokoro/potato-orm | src/Base.php | Base.makeUpdateSQL | public static function makeUpdateSQL()
{
$tableName = self::getTableName();
$setClause = "";
$whereClause = "";
$keysCount = count(self::$fields);
$iterations = 1;
foreach(self::$fields as $key => $val)
{
if($key == "id") {
$whereClause = " WHERE id = ".$val;
}
else if($key != "result") {
$setClause = $setClause.$key." = '".$val."'";
if($keysCount > 2 && $iterations < $keysCount) {
$setClause = $setClause.", ";
}
}
$iterations++;
}
$sql = "UPDATE ".$tableName." SET ".$setClause.$whereClause;
return $sql;
} | php | public static function makeUpdateSQL()
{
$tableName = self::getTableName();
$setClause = "";
$whereClause = "";
$keysCount = count(self::$fields);
$iterations = 1;
foreach(self::$fields as $key => $val)
{
if($key == "id") {
$whereClause = " WHERE id = ".$val;
}
else if($key != "result") {
$setClause = $setClause.$key." = '".$val."'";
if($keysCount > 2 && $iterations < $keysCount) {
$setClause = $setClause.", ";
}
}
$iterations++;
}
$sql = "UPDATE ".$tableName." SET ".$setClause.$whereClause;
return $sql;
} | [
"public",
"static",
"function",
"makeUpdateSQL",
"(",
")",
"{",
"$",
"tableName",
"=",
"self",
"::",
"getTableName",
"(",
")",
";",
"$",
"setClause",
"=",
"\"\"",
";",
"$",
"whereClause",
"=",
"\"\"",
";",
"$",
"keysCount",
"=",
"count",
"(",
"self",
"::",
"$",
"fields",
")",
";",
"$",
"iterations",
"=",
"1",
";",
"foreach",
"(",
"self",
"::",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"\"id\"",
")",
"{",
"$",
"whereClause",
"=",
"\" WHERE id = \"",
".",
"$",
"val",
";",
"}",
"else",
"if",
"(",
"$",
"key",
"!=",
"\"result\"",
")",
"{",
"$",
"setClause",
"=",
"$",
"setClause",
".",
"$",
"key",
".",
"\" = '\"",
".",
"$",
"val",
".",
"\"'\"",
";",
"if",
"(",
"$",
"keysCount",
">",
"2",
"&&",
"$",
"iterations",
"<",
"$",
"keysCount",
")",
"{",
"$",
"setClause",
"=",
"$",
"setClause",
".",
"\", \"",
";",
"}",
"}",
"$",
"iterations",
"++",
";",
"}",
"$",
"sql",
"=",
"\"UPDATE \"",
".",
"$",
"tableName",
".",
"\" SET \"",
".",
"$",
"setClause",
".",
"$",
"whereClause",
";",
"return",
"$",
"sql",
";",
"}"
] | This method generates the SQL statement used to update a record in the database | [
"This",
"method",
"generates",
"the",
"SQL",
"statement",
"used",
"to",
"update",
"a",
"record",
"in",
"the",
"database"
] | b8e8757fa8e520efdd61583c2ba489bc76f291ae | https://github.com/andela-womokoro/potato-orm/blob/b8e8757fa8e520efdd61583c2ba489bc76f291ae/src/Base.php#L173-L199 |
7,441 | andela-womokoro/potato-orm | src/Base.php | Base.destroy | public static function destroy($record)
{
if(is_string($record)) {
return $record;
}
$id = $record->id;
try {
$tableName = self::getTableName();
$conn = self::getConnection();
$sql = "DELETE FROM ".$tableName ." WHERE id = ".$id;
$affectedRows = $conn->exec($sql);
return $affectedRows;
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | php | public static function destroy($record)
{
if(is_string($record)) {
return $record;
}
$id = $record->id;
try {
$tableName = self::getTableName();
$conn = self::getConnection();
$sql = "DELETE FROM ".$tableName ." WHERE id = ".$id;
$affectedRows = $conn->exec($sql);
return $affectedRows;
}
catch(PDOException $pe) {
return $pe->getMessage();
}
catch(Exception $e) {
return $e->getMessage();
}
} | [
"public",
"static",
"function",
"destroy",
"(",
"$",
"record",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"record",
")",
")",
"{",
"return",
"$",
"record",
";",
"}",
"$",
"id",
"=",
"$",
"record",
"->",
"id",
";",
"try",
"{",
"$",
"tableName",
"=",
"self",
"::",
"getTableName",
"(",
")",
";",
"$",
"conn",
"=",
"self",
"::",
"getConnection",
"(",
")",
";",
"$",
"sql",
"=",
"\"DELETE FROM \"",
".",
"$",
"tableName",
".",
"\" WHERE id = \"",
".",
"$",
"id",
";",
"$",
"affectedRows",
"=",
"$",
"conn",
"->",
"exec",
"(",
"$",
"sql",
")",
";",
"return",
"$",
"affectedRows",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"pe",
")",
"{",
"return",
"$",
"pe",
"->",
"getMessage",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}"
] | This method deletes a record from the database table
@param integer $position | [
"This",
"method",
"deletes",
"a",
"record",
"from",
"the",
"database",
"table"
] | b8e8757fa8e520efdd61583c2ba489bc76f291ae | https://github.com/andela-womokoro/potato-orm/blob/b8e8757fa8e520efdd61583c2ba489bc76f291ae/src/Base.php#L227-L249 |
7,442 | gregorybesson/PlaygroundPartnership | src/Service/Partner.php | Partner.verifyProtocol | public function verifyProtocol($url, $append = 'http://')
{
if (strpos($url, 'http://') === false && strpos($url, 'https://') === false) {
$url = $append.$url;
}
return $url;
} | php | public function verifyProtocol($url, $append = 'http://')
{
if (strpos($url, 'http://') === false && strpos($url, 'https://') === false) {
$url = $append.$url;
}
return $url;
} | [
"public",
"function",
"verifyProtocol",
"(",
"$",
"url",
",",
"$",
"append",
"=",
"'http://'",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"url",
",",
"'http://'",
")",
"===",
"false",
"&&",
"strpos",
"(",
"$",
"url",
",",
"'https://'",
")",
"===",
"false",
")",
"{",
"$",
"url",
"=",
"$",
"append",
".",
"$",
"url",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Add protocol to an url if missing
@param url
@param append
@return string | [
"Add",
"protocol",
"to",
"an",
"url",
"if",
"missing"
] | f08f92ded3335726b87bed19cebb5fbf05eec696 | https://github.com/gregorybesson/PlaygroundPartnership/blob/f08f92ded3335726b87bed19cebb5fbf05eec696/src/Service/Partner.php#L295-L302 |
7,443 | factorio-item-browser/api-database | src/Entity/RecipeIngredient.php | RecipeIngredient.setAmount | public function setAmount(float $amount): self
{
$this->amount = (int) ($amount * self::FACTOR_AMOUNT);
return $this;
} | php | public function setAmount(float $amount): self
{
$this->amount = (int) ($amount * self::FACTOR_AMOUNT);
return $this;
} | [
"public",
"function",
"setAmount",
"(",
"float",
"$",
"amount",
")",
":",
"self",
"{",
"$",
"this",
"->",
"amount",
"=",
"(",
"int",
")",
"(",
"$",
"amount",
"*",
"self",
"::",
"FACTOR_AMOUNT",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the amount required for the recipe.
@param float $amount
@return $this Implementing fluent interface. | [
"Sets",
"the",
"amount",
"required",
"for",
"the",
"recipe",
"."
] | c3a27e5673462a58b5afafc0ea0e0002f6db9803 | https://github.com/factorio-item-browser/api-database/blob/c3a27e5673462a58b5afafc0ea0e0002f6db9803/src/Entity/RecipeIngredient.php#L100-L104 |
7,444 | ddliu/requery | src/ContextCollection.php | ContextCollection.find | public function find($re, $filter = null) {
$result = null;
$this->each(function($context) use ($re, $filter, &$result) {
$r = $context->find($re, $filter);
if (!$r->isEmpty()) {
$result = $r;
return false;
}
});
return $result?:Context::getEmptyContext();
} | php | public function find($re, $filter = null) {
$result = null;
$this->each(function($context) use ($re, $filter, &$result) {
$r = $context->find($re, $filter);
if (!$r->isEmpty()) {
$result = $r;
return false;
}
});
return $result?:Context::getEmptyContext();
} | [
"public",
"function",
"find",
"(",
"$",
"re",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"this",
"->",
"each",
"(",
"function",
"(",
"$",
"context",
")",
"use",
"(",
"$",
"re",
",",
"$",
"filter",
",",
"&",
"$",
"result",
")",
"{",
"$",
"r",
"=",
"$",
"context",
"->",
"find",
"(",
"$",
"re",
",",
"$",
"filter",
")",
";",
"if",
"(",
"!",
"$",
"r",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"result",
"=",
"$",
"r",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"return",
"$",
"result",
"?",
":",
"Context",
"::",
"getEmptyContext",
"(",
")",
";",
"}"
] | Find the first matching context in the collection
@param string $re
@param callable $filter
@return Context | [
"Find",
"the",
"first",
"matching",
"context",
"in",
"the",
"collection"
] | ed1a8d45644965cf464b5eb1eede6ed8236ae6e8 | https://github.com/ddliu/requery/blob/ed1a8d45644965cf464b5eb1eede6ed8236ae6e8/src/ContextCollection.php#L39-L50 |
7,445 | ddliu/requery | src/ContextCollection.php | ContextCollection.mustFind | public function mustFind($re, $filter = null) {
$result = $this->find($re, $filter);
if ($result->isEmpty()) {
throw new QueryException('No match for regexp: '.$re);
}
return $result;
} | php | public function mustFind($re, $filter = null) {
$result = $this->find($re, $filter);
if ($result->isEmpty()) {
throw new QueryException('No match for regexp: '.$re);
}
return $result;
} | [
"public",
"function",
"mustFind",
"(",
"$",
"re",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"re",
",",
"$",
"filter",
")",
";",
"if",
"(",
"$",
"result",
"->",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"QueryException",
"(",
"'No match for regexp: '",
".",
"$",
"re",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Find with assertion
@param string $re
@param callable $filter
@return Context
@throws QueryException If nothing found. | [
"Find",
"with",
"assertion"
] | ed1a8d45644965cf464b5eb1eede6ed8236ae6e8 | https://github.com/ddliu/requery/blob/ed1a8d45644965cf464b5eb1eede6ed8236ae6e8/src/ContextCollection.php#L59-L66 |
7,446 | ddliu/requery | src/ContextCollection.php | ContextCollection.findAll | public function findAll($re, $filter = null) {
$result = array();
$this->each(function($context) use ($re, $filter, &$result) {
$context->findAll($re, $filter)->each(
function($context) use (&$result) {
$result[] = $context;
}
);
});
return new self($result);
} | php | public function findAll($re, $filter = null) {
$result = array();
$this->each(function($context) use ($re, $filter, &$result) {
$context->findAll($re, $filter)->each(
function($context) use (&$result) {
$result[] = $context;
}
);
});
return new self($result);
} | [
"public",
"function",
"findAll",
"(",
"$",
"re",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"each",
"(",
"function",
"(",
"$",
"context",
")",
"use",
"(",
"$",
"re",
",",
"$",
"filter",
",",
"&",
"$",
"result",
")",
"{",
"$",
"context",
"->",
"findAll",
"(",
"$",
"re",
",",
"$",
"filter",
")",
"->",
"each",
"(",
"function",
"(",
"$",
"context",
")",
"use",
"(",
"&",
"$",
"result",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"context",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"new",
"self",
"(",
"$",
"result",
")",
";",
"}"
] | Find all matching contexts in the collection
@param string $re
@param callable $filter
@return ContextCollection | [
"Find",
"all",
"matching",
"contexts",
"in",
"the",
"collection"
] | ed1a8d45644965cf464b5eb1eede6ed8236ae6e8 | https://github.com/ddliu/requery/blob/ed1a8d45644965cf464b5eb1eede6ed8236ae6e8/src/ContextCollection.php#L74-L85 |
7,447 | ddliu/requery | src/ContextCollection.php | ContextCollection.mustFindAll | public function mustFindAll($re, $filter = null) {
$result = $this->findAll($re, $filter);
if ($result->count() == 0) {
throw new QueryException('No match for regexp: '.$re);
}
return $result;
} | php | public function mustFindAll($re, $filter = null) {
$result = $this->findAll($re, $filter);
if ($result->count() == 0) {
throw new QueryException('No match for regexp: '.$re);
}
return $result;
} | [
"public",
"function",
"mustFindAll",
"(",
"$",
"re",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"findAll",
"(",
"$",
"re",
",",
"$",
"filter",
")",
";",
"if",
"(",
"$",
"result",
"->",
"count",
"(",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"QueryException",
"(",
"'No match for regexp: '",
".",
"$",
"re",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Find all with assertion
@param string $re
@param callable $filter
@return ContextCollection
@throws QueryException If nothing found. | [
"Find",
"all",
"with",
"assertion"
] | ed1a8d45644965cf464b5eb1eede6ed8236ae6e8 | https://github.com/ddliu/requery/blob/ed1a8d45644965cf464b5eb1eede6ed8236ae6e8/src/ContextCollection.php#L94-L101 |
7,448 | ddliu/requery | src/ContextCollection.php | ContextCollection.extract | public function extract($parts = null) {
if ($parts === null) {
return $this->data;
}
if (is_array($parts)) {
$result = array();
foreach ($this->data as $match) {
$row = array();
foreach ($parts as $key) {
if (isset($match[$key])) {
$row[$key] = isset($match[$key])?$match[$key]:null;
}
}
$result[] = $row;
}
return $result;
}
$result = array();
foreach ($this->data as $match) {
$result[] = isset($match[$parts])?$match[$parts]:null;
}
return $result;
} | php | public function extract($parts = null) {
if ($parts === null) {
return $this->data;
}
if (is_array($parts)) {
$result = array();
foreach ($this->data as $match) {
$row = array();
foreach ($parts as $key) {
if (isset($match[$key])) {
$row[$key] = isset($match[$key])?$match[$key]:null;
}
}
$result[] = $row;
}
return $result;
}
$result = array();
foreach ($this->data as $match) {
$result[] = isset($match[$parts])?$match[$parts]:null;
}
return $result;
} | [
"public",
"function",
"extract",
"(",
"$",
"parts",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"parts",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"data",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"parts",
")",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"match",
")",
"{",
"$",
"row",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"row",
"[",
"$",
"key",
"]",
"=",
"isset",
"(",
"$",
"match",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"match",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}",
"}",
"$",
"result",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"return",
"$",
"result",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"match",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"isset",
"(",
"$",
"match",
"[",
"$",
"parts",
"]",
")",
"?",
"$",
"match",
"[",
"$",
"parts",
"]",
":",
"null",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Extract result parts of the collection.
@param mixed $parts
@return mixed | [
"Extract",
"result",
"parts",
"of",
"the",
"collection",
"."
] | ed1a8d45644965cf464b5eb1eede6ed8236ae6e8 | https://github.com/ddliu/requery/blob/ed1a8d45644965cf464b5eb1eede6ed8236ae6e8/src/ContextCollection.php#L118-L146 |
7,449 | ddliu/requery | src/ContextCollection.php | ContextCollection.each | public function each($cb) {
foreach ($this->data as $context) {
$context = new Context($context);
if (false === $cb($context)) {
break;
}
}
return $this;
} | php | public function each($cb) {
foreach ($this->data as $context) {
$context = new Context($context);
if (false === $cb($context)) {
break;
}
}
return $this;
} | [
"public",
"function",
"each",
"(",
"$",
"cb",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"context",
")",
"{",
"$",
"context",
"=",
"new",
"Context",
"(",
"$",
"context",
")",
";",
"if",
"(",
"false",
"===",
"$",
"cb",
"(",
"$",
"context",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Walk through the collection
@param callable $cb
@return ContextCollection | [
"Walk",
"through",
"the",
"collection"
] | ed1a8d45644965cf464b5eb1eede6ed8236ae6e8 | https://github.com/ddliu/requery/blob/ed1a8d45644965cf464b5eb1eede6ed8236ae6e8/src/ContextCollection.php#L153-L163 |
7,450 | spiral/validation | src/Checker/FileChecker.php | FileChecker.size | public function size($file, int $size): bool
{
if (empty($filename = $this->resolveFilename($file))) {
return false;
}
return $this->files->size($filename) <= ($size * 1024);
} | php | public function size($file, int $size): bool
{
if (empty($filename = $this->resolveFilename($file))) {
return false;
}
return $this->files->size($filename) <= ($size * 1024);
} | [
"public",
"function",
"size",
"(",
"$",
"file",
",",
"int",
"$",
"size",
")",
":",
"bool",
"{",
"if",
"(",
"empty",
"(",
"$",
"filename",
"=",
"$",
"this",
"->",
"resolveFilename",
"(",
"$",
"file",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"files",
"->",
"size",
"(",
"$",
"filename",
")",
"<=",
"(",
"$",
"size",
"*",
"1024",
")",
";",
"}"
] | Check if file size less that specified value in KB.
@param mixed $file Local file or uploaded file array.
@param int $size Size in KBytes.
@return bool | [
"Check",
"if",
"file",
"size",
"less",
"that",
"specified",
"value",
"in",
"KB",
"."
] | aa8977dfe93904acfcce354e000d7d384579e2e3 | https://github.com/spiral/validation/blob/aa8977dfe93904acfcce354e000d7d384579e2e3/src/Checker/FileChecker.php#L80-L87 |
7,451 | spiral/validation | src/Checker/FileChecker.php | FileChecker.extension | public function extension($file, $extensions): bool
{
if (!is_array($extensions)) {
$extensions = array_slice(func_get_args(), 1);
}
if ($file instanceof UploadedFileInterface) {
return in_array(
$this->files->extension($file->getClientFilename()),
$extensions
);
}
return in_array($this->files->extension($file), $extensions);
} | php | public function extension($file, $extensions): bool
{
if (!is_array($extensions)) {
$extensions = array_slice(func_get_args(), 1);
}
if ($file instanceof UploadedFileInterface) {
return in_array(
$this->files->extension($file->getClientFilename()),
$extensions
);
}
return in_array($this->files->extension($file), $extensions);
} | [
"public",
"function",
"extension",
"(",
"$",
"file",
",",
"$",
"extensions",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"extensions",
")",
")",
"{",
"$",
"extensions",
"=",
"array_slice",
"(",
"func_get_args",
"(",
")",
",",
"1",
")",
";",
"}",
"if",
"(",
"$",
"file",
"instanceof",
"UploadedFileInterface",
")",
"{",
"return",
"in_array",
"(",
"$",
"this",
"->",
"files",
"->",
"extension",
"(",
"$",
"file",
"->",
"getClientFilename",
"(",
")",
")",
",",
"$",
"extensions",
")",
";",
"}",
"return",
"in_array",
"(",
"$",
"this",
"->",
"files",
"->",
"extension",
"(",
"$",
"file",
")",
",",
"$",
"extensions",
")",
";",
"}"
] | Check if file extension in whitelist. Client name of uploaded file will be used!
It is recommended to use external validation like media type based on file mimetype or
ensure that resource is properly converted.
@param mixed $file
@param array|string $extensions
@return bool | [
"Check",
"if",
"file",
"extension",
"in",
"whitelist",
".",
"Client",
"name",
"of",
"uploaded",
"file",
"will",
"be",
"used!",
"It",
"is",
"recommended",
"to",
"use",
"external",
"validation",
"like",
"media",
"type",
"based",
"on",
"file",
"mimetype",
"or",
"ensure",
"that",
"resource",
"is",
"properly",
"converted",
"."
] | aa8977dfe93904acfcce354e000d7d384579e2e3 | https://github.com/spiral/validation/blob/aa8977dfe93904acfcce354e000d7d384579e2e3/src/Checker/FileChecker.php#L99-L113 |
7,452 | synapsestudios/synapse-base | src/Synapse/Validator/ValidationErrorFormatter.php | ValidationErrorFormatter.addViolationToOutput | protected function addViolationToOutput(array $errors, ConstraintViolationInterface $violation)
{
$path = $this->getPropertyPathAsArray($violation);
// Drill into errors and find where the error message should be added, building nonexistent portions of the path
$currentPointer = &$errors;
while (count($path) > 0) {
$currentField = array_shift($path);
if (! array_key_exists($currentField, $currentPointer) or ! is_array($currentPointer[$currentField])) {
$currentPointer[$currentField] = [];
}
if (is_numeric($currentField)) {
for ($i = 0; $i < (int) $currentField; $i++) {
if (! array_key_exists($i, $currentPointer)) {
$currentPointer[(int) $i] = null;
}
}
// Sort the elements of this array so JsonResponse converts this to an array rather than an object
ksort($currentPointer);
}
$currentPointer = &$currentPointer[$currentField];
}
$currentPointer[] = $violation->getMessage();
return $errors;
} | php | protected function addViolationToOutput(array $errors, ConstraintViolationInterface $violation)
{
$path = $this->getPropertyPathAsArray($violation);
// Drill into errors and find where the error message should be added, building nonexistent portions of the path
$currentPointer = &$errors;
while (count($path) > 0) {
$currentField = array_shift($path);
if (! array_key_exists($currentField, $currentPointer) or ! is_array($currentPointer[$currentField])) {
$currentPointer[$currentField] = [];
}
if (is_numeric($currentField)) {
for ($i = 0; $i < (int) $currentField; $i++) {
if (! array_key_exists($i, $currentPointer)) {
$currentPointer[(int) $i] = null;
}
}
// Sort the elements of this array so JsonResponse converts this to an array rather than an object
ksort($currentPointer);
}
$currentPointer = &$currentPointer[$currentField];
}
$currentPointer[] = $violation->getMessage();
return $errors;
} | [
"protected",
"function",
"addViolationToOutput",
"(",
"array",
"$",
"errors",
",",
"ConstraintViolationInterface",
"$",
"violation",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getPropertyPathAsArray",
"(",
"$",
"violation",
")",
";",
"// Drill into errors and find where the error message should be added, building nonexistent portions of the path",
"$",
"currentPointer",
"=",
"&",
"$",
"errors",
";",
"while",
"(",
"count",
"(",
"$",
"path",
")",
">",
"0",
")",
"{",
"$",
"currentField",
"=",
"array_shift",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"currentField",
",",
"$",
"currentPointer",
")",
"or",
"!",
"is_array",
"(",
"$",
"currentPointer",
"[",
"$",
"currentField",
"]",
")",
")",
"{",
"$",
"currentPointer",
"[",
"$",
"currentField",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"currentField",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"(",
"int",
")",
"$",
"currentField",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"i",
",",
"$",
"currentPointer",
")",
")",
"{",
"$",
"currentPointer",
"[",
"(",
"int",
")",
"$",
"i",
"]",
"=",
"null",
";",
"}",
"}",
"// Sort the elements of this array so JsonResponse converts this to an array rather than an object",
"ksort",
"(",
"$",
"currentPointer",
")",
";",
"}",
"$",
"currentPointer",
"=",
"&",
"$",
"currentPointer",
"[",
"$",
"currentField",
"]",
";",
"}",
"$",
"currentPointer",
"[",
"]",
"=",
"$",
"violation",
"->",
"getMessage",
"(",
")",
";",
"return",
"$",
"errors",
";",
"}"
] | Add a single constraint violation to a partially-built array of errors
in the format described in `groupViolationsByField`
@param array $errors Array of errors
@param ConstraintViolationInterface $violation Violation to add | [
"Add",
"a",
"single",
"constraint",
"violation",
"to",
"a",
"partially",
"-",
"built",
"array",
"of",
"errors",
"in",
"the",
"format",
"described",
"in",
"groupViolationsByField"
] | 60c830550491742a077ab063f924e2f0b63825da | https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Validator/ValidationErrorFormatter.php#L65-L96 |
7,453 | synapsestudios/synapse-base | src/Synapse/Validator/ValidationErrorFormatter.php | ValidationErrorFormatter.getPropertyPathAsArray | protected function getPropertyPathAsArray(ConstraintViolationInterface $violation)
{
$path = $violation->getPropertyPath();
// Remove outer brackets and explode fields into array
$path = substr($path, 1, strlen($path) - 2);
return explode('][', $path);
} | php | protected function getPropertyPathAsArray(ConstraintViolationInterface $violation)
{
$path = $violation->getPropertyPath();
// Remove outer brackets and explode fields into array
$path = substr($path, 1, strlen($path) - 2);
return explode('][', $path);
} | [
"protected",
"function",
"getPropertyPathAsArray",
"(",
"ConstraintViolationInterface",
"$",
"violation",
")",
"{",
"$",
"path",
"=",
"$",
"violation",
"->",
"getPropertyPath",
"(",
")",
";",
"// Remove outer brackets and explode fields into array",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"1",
",",
"strlen",
"(",
"$",
"path",
")",
"-",
"2",
")",
";",
"return",
"explode",
"(",
"']['",
",",
"$",
"path",
")",
";",
"}"
] | Given a constraint violation, return its property path as an array
Example:
Property path of violation: "[foo][0][bar][baz]"
Return value: array('foo', '0', 'bar', 'baz')
@param ConstraintViolationInterface $violation Violation whose path to return
@return array | [
"Given",
"a",
"constraint",
"violation",
"return",
"its",
"property",
"path",
"as",
"an",
"array"
] | 60c830550491742a077ab063f924e2f0b63825da | https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Validator/ValidationErrorFormatter.php#L108-L116 |
7,454 | avoo/FrameworkInstallerBundle | Command/InstallCommand.php | InstallCommand.install | protected function install()
{
$this->setupCore();
$this->setupBackend();
$this->initializeDatabase();
$this->runCommand('cache:clear', array('--no-warmup' => true));
} | php | protected function install()
{
$this->setupCore();
$this->setupBackend();
$this->initializeDatabase();
$this->runCommand('cache:clear', array('--no-warmup' => true));
} | [
"protected",
"function",
"install",
"(",
")",
"{",
"$",
"this",
"->",
"setupCore",
"(",
")",
";",
"$",
"this",
"->",
"setupBackend",
"(",
")",
";",
"$",
"this",
"->",
"initializeDatabase",
"(",
")",
";",
"$",
"this",
"->",
"runCommand",
"(",
"'cache:clear'",
",",
"array",
"(",
"'--no-warmup'",
"=>",
"true",
")",
")",
";",
"}"
] | Install Avoo framework | [
"Install",
"Avoo",
"framework"
] | 402032e01467359b176de19731ebbff744cc52f5 | https://github.com/avoo/FrameworkInstallerBundle/blob/402032e01467359b176de19731ebbff744cc52f5/Command/InstallCommand.php#L65-L71 |
7,455 | avoo/FrameworkInstallerBundle | Command/InstallCommand.php | InstallCommand.isDatabaseExist | private function isDatabaseExist()
{
$databaseName = $this->getContainer()->getParameter('database_name');
try {
/** @var MySqlSchemaManager $schemaManager */
$schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager();
} catch (\Exception $exception) {
$message = "SQLSTATE[42000] [1049] Unknown database '%s'";
if (false !== strpos($exception->getMessage(), sprintf($message, $databaseName))) {
return false;
}
throw $exception;
}
try {
return in_array($databaseName, $schemaManager->listDatabases());
} catch(\PDOException $e) {
return false;
}
} | php | private function isDatabaseExist()
{
$databaseName = $this->getContainer()->getParameter('database_name');
try {
/** @var MySqlSchemaManager $schemaManager */
$schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager();
} catch (\Exception $exception) {
$message = "SQLSTATE[42000] [1049] Unknown database '%s'";
if (false !== strpos($exception->getMessage(), sprintf($message, $databaseName))) {
return false;
}
throw $exception;
}
try {
return in_array($databaseName, $schemaManager->listDatabases());
} catch(\PDOException $e) {
return false;
}
} | [
"private",
"function",
"isDatabaseExist",
"(",
")",
"{",
"$",
"databaseName",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"getParameter",
"(",
"'database_name'",
")",
";",
"try",
"{",
"/** @var MySqlSchemaManager $schemaManager */",
"$",
"schemaManager",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'doctrine'",
")",
"->",
"getManager",
"(",
")",
"->",
"getConnection",
"(",
")",
"->",
"getSchemaManager",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"message",
"=",
"\"SQLSTATE[42000] [1049] Unknown database '%s'\"",
";",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"sprintf",
"(",
"$",
"message",
",",
"$",
"databaseName",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"throw",
"$",
"exception",
";",
"}",
"try",
"{",
"return",
"in_array",
"(",
"$",
"databaseName",
",",
"$",
"schemaManager",
"->",
"listDatabases",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Is database exist
@return bool
@throws \Exception | [
"Is",
"database",
"exist"
] | 402032e01467359b176de19731ebbff744cc52f5 | https://github.com/avoo/FrameworkInstallerBundle/blob/402032e01467359b176de19731ebbff744cc52f5/Command/InstallCommand.php#L106-L127 |
7,456 | bfitech/zaplate | src/Template.php | Template.load | public function load($template, $args=[], $filter_args=[], $buffered=null) {
if ($buffered)
ob_start();
if ($filter_args) {
foreach ($filter_args as $filter) {
$args = array_map($filter, $args);
}
}
extract($args, EXTR_SKIP);
require($template);
if ($buffered)
return ob_get_clean();
} | php | public function load($template, $args=[], $filter_args=[], $buffered=null) {
if ($buffered)
ob_start();
if ($filter_args) {
foreach ($filter_args as $filter) {
$args = array_map($filter, $args);
}
}
extract($args, EXTR_SKIP);
require($template);
if ($buffered)
return ob_get_clean();
} | [
"public",
"function",
"load",
"(",
"$",
"template",
",",
"$",
"args",
"=",
"[",
"]",
",",
"$",
"filter_args",
"=",
"[",
"]",
",",
"$",
"buffered",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"buffered",
")",
"ob_start",
"(",
")",
";",
"if",
"(",
"$",
"filter_args",
")",
"{",
"foreach",
"(",
"$",
"filter_args",
"as",
"$",
"filter",
")",
"{",
"$",
"args",
"=",
"array_map",
"(",
"$",
"filter",
",",
"$",
"args",
")",
";",
"}",
"}",
"extract",
"(",
"$",
"args",
",",
"EXTR_SKIP",
")",
";",
"require",
"(",
"$",
"template",
")",
";",
"if",
"(",
"$",
"buffered",
")",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
] | Template loader.
@param string $template Path to template file, a regular PHP file
containing variables registered in $args.
@param array $args Associative arrays with keys corresponding variables
in the $template. Each element can nest another array. It depends
on the template to render it.
@param array $filter_args Numeric arrays containing function that
takes $args as argument and return one new array. Typical usage is
applying htmlspecialchars() to each element to prevent HTML
breakage.
@param bool $buffered When true, a string of rendered template is
returned instead of directly echoed. Useful if you want to do some
post-processing such as minifying or caching to filesystem.
#### Example:
@code
# template.php
<p><?php echo $group ?></p>
<ul>
<?php foreach ($members as $member): ?>
<li><?php echo $member ?></li>
<?php endforeach; ?>
</ul>
# renderer.php
class Filter {
public function whoami($name) {
if (is_string($name))
return $name;
return array_map(function($iname){
if (stripos($iname, 'jekyll') !== false)
return 'Mr Hyde';
return $iname;
}, $name);
}
}
(new Template())->load('template.php',
[
'group' => "Extraordinary Gents",
'members' => [
'Allan Quatermain',
'Henry Jekyll',
],
], [
[(new Filter()), 'whoami']
]
);
@endcode | [
"Template",
"loader",
"."
] | 0165b262ade42b00e7beba7b94ddad14e0b1ecb1 | https://github.com/bfitech/zaplate/blob/0165b262ade42b00e7beba7b94ddad14e0b1ecb1/src/Template.php#L69-L86 |
7,457 | chigix/chiji-frontend | src/File/AbstractResourceFile.php | AbstractResourceFile.getRelativePath | public function getRelativePath(File $base_dir) {
return FileSystem::getFileSystem()->makePathRelative($this->file->getAbsoluteFile()->getParent(), $base_dir->getAbsolutePath()) . $this->file->getName();
} | php | public function getRelativePath(File $base_dir) {
return FileSystem::getFileSystem()->makePathRelative($this->file->getAbsoluteFile()->getParent(), $base_dir->getAbsolutePath()) . $this->file->getName();
} | [
"public",
"function",
"getRelativePath",
"(",
"File",
"$",
"base_dir",
")",
"{",
"return",
"FileSystem",
"::",
"getFileSystem",
"(",
")",
"->",
"makePathRelative",
"(",
"$",
"this",
"->",
"file",
"->",
"getAbsoluteFile",
"(",
")",
"->",
"getParent",
"(",
")",
",",
"$",
"base_dir",
"->",
"getAbsolutePath",
"(",
")",
")",
".",
"$",
"this",
"->",
"file",
"->",
"getName",
"(",
")",
";",
"}"
] | Returns the relative path
@param File $base_dir The base_dir to be based upon for relative path calculation
@return string the relative path | [
"Returns",
"the",
"relative",
"path"
] | 5407f98c21ee99f8bbef43c97a231c0f81ed3e74 | https://github.com/chigix/chiji-frontend/blob/5407f98c21ee99f8bbef43c97a231c0f81ed3e74/src/File/AbstractResourceFile.php#L66-L68 |
7,458 | chigix/chiji-frontend | src/File/AbstractResourceFile.php | AbstractResourceFile.getParentProject | public final function getParentProject() {
$result = \Chigi\Chiji\Util\ProjectUtil::searchRelativeProject($this);
if (count($result) < 1) {
throw new \Chigi\Chiji\Exception\ProjectMemberNotFoundException("MEMBER NOT FOUND");
}
return $result[0];
} | php | public final function getParentProject() {
$result = \Chigi\Chiji\Util\ProjectUtil::searchRelativeProject($this);
if (count($result) < 1) {
throw new \Chigi\Chiji\Exception\ProjectMemberNotFoundException("MEMBER NOT FOUND");
}
return $result[0];
} | [
"public",
"final",
"function",
"getParentProject",
"(",
")",
"{",
"$",
"result",
"=",
"\\",
"Chigi",
"\\",
"Chiji",
"\\",
"Util",
"\\",
"ProjectUtil",
"::",
"searchRelativeProject",
"(",
"$",
"this",
")",
";",
"if",
"(",
"count",
"(",
"$",
"result",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"\\",
"Chigi",
"\\",
"Chiji",
"\\",
"Exception",
"\\",
"ProjectMemberNotFoundException",
"(",
"\"MEMBER NOT FOUND\"",
")",
";",
"}",
"return",
"$",
"result",
"[",
"0",
"]",
";",
"}"
] | Gets the parent project of this registered resource.
@return \Chigi\Chiji\Project\Project The Parent Project of this resource.
@throws \Chigi\Chiji\Exception\ProjectMemberNotFoundException | [
"Gets",
"the",
"parent",
"project",
"of",
"this",
"registered",
"resource",
"."
] | 5407f98c21ee99f8bbef43c97a231c0f81ed3e74 | https://github.com/chigix/chiji-frontend/blob/5407f98c21ee99f8bbef43c97a231c0f81ed3e74/src/File/AbstractResourceFile.php#L107-L113 |
7,459 | chigix/chiji-frontend | src/File/AbstractResourceFile.php | AbstractResourceFile.getFinalCache | public final function getFinalCache() {
$resource = $this;
while (true) {
$cache_file = $this->getParentProject()->getCacheManager()->getCacheBuilt($resource);
if (\is_null($cache_file) ||
\is_null($this->getParentProject()->getResourceByFile($cache_file)) ||
$this->getParentProject()->getResourceByFile($cache_file)->getMemberId() === $resource->getMemberId()
) {
return $resource;
}
$resource = $this->getParentProject()->getResourceByFile($cache_file);
}
} | php | public final function getFinalCache() {
$resource = $this;
while (true) {
$cache_file = $this->getParentProject()->getCacheManager()->getCacheBuilt($resource);
if (\is_null($cache_file) ||
\is_null($this->getParentProject()->getResourceByFile($cache_file)) ||
$this->getParentProject()->getResourceByFile($cache_file)->getMemberId() === $resource->getMemberId()
) {
return $resource;
}
$resource = $this->getParentProject()->getResourceByFile($cache_file);
}
} | [
"public",
"final",
"function",
"getFinalCache",
"(",
")",
"{",
"$",
"resource",
"=",
"$",
"this",
";",
"while",
"(",
"true",
")",
"{",
"$",
"cache_file",
"=",
"$",
"this",
"->",
"getParentProject",
"(",
")",
"->",
"getCacheManager",
"(",
")",
"->",
"getCacheBuilt",
"(",
"$",
"resource",
")",
";",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"cache_file",
")",
"||",
"\\",
"is_null",
"(",
"$",
"this",
"->",
"getParentProject",
"(",
")",
"->",
"getResourceByFile",
"(",
"$",
"cache_file",
")",
")",
"||",
"$",
"this",
"->",
"getParentProject",
"(",
")",
"->",
"getResourceByFile",
"(",
"$",
"cache_file",
")",
"->",
"getMemberId",
"(",
")",
"===",
"$",
"resource",
"->",
"getMemberId",
"(",
")",
")",
"{",
"return",
"$",
"resource",
";",
"}",
"$",
"resource",
"=",
"$",
"this",
"->",
"getParentProject",
"(",
")",
"->",
"getResourceByFile",
"(",
"$",
"cache_file",
")",
";",
"}",
"}"
] | Returns the final cache resource built from this.
@return \Chigi\Chiji\File\AbstractResourceFile | [
"Returns",
"the",
"final",
"cache",
"resource",
"built",
"from",
"this",
"."
] | 5407f98c21ee99f8bbef43c97a231c0f81ed3e74 | https://github.com/chigix/chiji-frontend/blob/5407f98c21ee99f8bbef43c97a231c0f81ed3e74/src/File/AbstractResourceFile.php#L120-L132 |
7,460 | nodes-php/core | src/Support/UserAgent/Agents/Original.php | Original.parse | protected function parse()
{
try {
$data = app(Browscap::class)->getBrowser($this->userAgent);
} catch (Exception $e) {
return;
}
foreach ($data as $key => $value) {
// Force lowercase on key
$key = strtolower($key);
// Remove whitespaces from value
$value = trim($value);
// Switch it up!
switch ($key) {
case 'ismobiledevice':
$this->isMobile = !empty($value);
break;
case 'istablet':
$this->isTablet = !empty($value);
break;
case 'crawler':
$this->isCrawler = !empty($value);
break;
case 'majorver':
$this->majorVersion = (int) $value;
break;
case 'minorver':
$this->minorVersion = (int) $value;
break;
case 'device_type':
$this->device = $value;
break;
case 'device_pointing_method':
$this->devicePointer = $value;
break;
case 'browser_maker':
$this->publisher = $value;
break;
case 'comment':
$this->browserWithVersion = $value;
break;
case 'browser':
case 'platform':
$this->{$key} = $value;
break;
}
}
// Set version and if major and minor
// wasn't present in the data array
// we'll set them as well
$this->setVersion($data->version);
// Mark parsing as successful
$this->successful = true;
} | php | protected function parse()
{
try {
$data = app(Browscap::class)->getBrowser($this->userAgent);
} catch (Exception $e) {
return;
}
foreach ($data as $key => $value) {
// Force lowercase on key
$key = strtolower($key);
// Remove whitespaces from value
$value = trim($value);
// Switch it up!
switch ($key) {
case 'ismobiledevice':
$this->isMobile = !empty($value);
break;
case 'istablet':
$this->isTablet = !empty($value);
break;
case 'crawler':
$this->isCrawler = !empty($value);
break;
case 'majorver':
$this->majorVersion = (int) $value;
break;
case 'minorver':
$this->minorVersion = (int) $value;
break;
case 'device_type':
$this->device = $value;
break;
case 'device_pointing_method':
$this->devicePointer = $value;
break;
case 'browser_maker':
$this->publisher = $value;
break;
case 'comment':
$this->browserWithVersion = $value;
break;
case 'browser':
case 'platform':
$this->{$key} = $value;
break;
}
}
// Set version and if major and minor
// wasn't present in the data array
// we'll set them as well
$this->setVersion($data->version);
// Mark parsing as successful
$this->successful = true;
} | [
"protected",
"function",
"parse",
"(",
")",
"{",
"try",
"{",
"$",
"data",
"=",
"app",
"(",
"Browscap",
"::",
"class",
")",
"->",
"getBrowser",
"(",
"$",
"this",
"->",
"userAgent",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Force lowercase on key",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"key",
")",
";",
"// Remove whitespaces from value",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"// Switch it up!",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'ismobiledevice'",
":",
"$",
"this",
"->",
"isMobile",
"=",
"!",
"empty",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'istablet'",
":",
"$",
"this",
"->",
"isTablet",
"=",
"!",
"empty",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'crawler'",
":",
"$",
"this",
"->",
"isCrawler",
"=",
"!",
"empty",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'majorver'",
":",
"$",
"this",
"->",
"majorVersion",
"=",
"(",
"int",
")",
"$",
"value",
";",
"break",
";",
"case",
"'minorver'",
":",
"$",
"this",
"->",
"minorVersion",
"=",
"(",
"int",
")",
"$",
"value",
";",
"break",
";",
"case",
"'device_type'",
":",
"$",
"this",
"->",
"device",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'device_pointing_method'",
":",
"$",
"this",
"->",
"devicePointer",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'browser_maker'",
":",
"$",
"this",
"->",
"publisher",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'comment'",
":",
"$",
"this",
"->",
"browserWithVersion",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'browser'",
":",
"case",
"'platform'",
":",
"$",
"this",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"break",
";",
"}",
"}",
"// Set version and if major and minor",
"// wasn't present in the data array",
"// we'll set them as well",
"$",
"this",
"->",
"setVersion",
"(",
"$",
"data",
"->",
"version",
")",
";",
"// Mark parsing as successful",
"$",
"this",
"->",
"successful",
"=",
"true",
";",
"}"
] | Parse user agent with the help from Browscap.
@author Morten Rugaard <[email protected]>
@return void | [
"Parse",
"user",
"agent",
"with",
"the",
"help",
"from",
"Browscap",
"."
] | fc788bb3e9668872573838099f868ab162eb8a96 | https://github.com/nodes-php/core/blob/fc788bb3e9668872573838099f868ab162eb8a96/src/Support/UserAgent/Agents/Original.php#L134-L192 |
7,461 | nodes-php/core | src/Support/UserAgent/Agents/Original.php | Original.setVersion | protected function setVersion($version)
{
// Set version of browser
$this->version = $version;
// If major and minor versions hasn't been set
// we'll set them by parsing version.
//
// If version doesn't contain a "." then we'll only
// set the major version.
if (empty($this->majorVersion) && strpos($version, '.') !== false) {
// Split version by comma
$version = explode('.', $version);
// Set major and minor version
$this->majorVersion = (int) isset($version[0]) ? $version[0] : 0;
$this->minorVersion = (int) isset($version[1]) ? $version[1] : 0;
} else {
$this->majorVersion = (int) $version;
}
return $this;
} | php | protected function setVersion($version)
{
// Set version of browser
$this->version = $version;
// If major and minor versions hasn't been set
// we'll set them by parsing version.
//
// If version doesn't contain a "." then we'll only
// set the major version.
if (empty($this->majorVersion) && strpos($version, '.') !== false) {
// Split version by comma
$version = explode('.', $version);
// Set major and minor version
$this->majorVersion = (int) isset($version[0]) ? $version[0] : 0;
$this->minorVersion = (int) isset($version[1]) ? $version[1] : 0;
} else {
$this->majorVersion = (int) $version;
}
return $this;
} | [
"protected",
"function",
"setVersion",
"(",
"$",
"version",
")",
"{",
"// Set version of browser",
"$",
"this",
"->",
"version",
"=",
"$",
"version",
";",
"// If major and minor versions hasn't been set",
"// we'll set them by parsing version.",
"//",
"// If version doesn't contain a \".\" then we'll only",
"// set the major version.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"majorVersion",
")",
"&&",
"strpos",
"(",
"$",
"version",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"// Split version by comma",
"$",
"version",
"=",
"explode",
"(",
"'.'",
",",
"$",
"version",
")",
";",
"// Set major and minor version",
"$",
"this",
"->",
"majorVersion",
"=",
"(",
"int",
")",
"isset",
"(",
"$",
"version",
"[",
"0",
"]",
")",
"?",
"$",
"version",
"[",
"0",
"]",
":",
"0",
";",
"$",
"this",
"->",
"minorVersion",
"=",
"(",
"int",
")",
"isset",
"(",
"$",
"version",
"[",
"1",
"]",
")",
"?",
"$",
"version",
"[",
"1",
"]",
":",
"0",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"majorVersion",
"=",
"(",
"int",
")",
"$",
"version",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set version of browser.
@author Morten Rugaard <[email protected]>
@param string $version
@return $this | [
"Set",
"version",
"of",
"browser",
"."
] | fc788bb3e9668872573838099f868ab162eb8a96 | https://github.com/nodes-php/core/blob/fc788bb3e9668872573838099f868ab162eb8a96/src/Support/UserAgent/Agents/Original.php#L203-L225 |
7,462 | gossi/trixionary | src/model/Map/FunctionPhaseTableMap.php | FunctionPhaseTableMap.doInsert | public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(FunctionPhaseTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from FunctionPhase object
}
// Set the correct dbName
$query = FunctionPhaseQuery::create()->mergeWith($criteria);
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
return $con->transaction(function () use ($con, $query) {
return $query->doInsert($con);
});
} | php | public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(FunctionPhaseTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from FunctionPhase object
}
// Set the correct dbName
$query = FunctionPhaseQuery::create()->mergeWith($criteria);
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
return $con->transaction(function () use ($con, $query) {
return $query->doInsert($con);
});
} | [
"public",
"static",
"function",
"doInsert",
"(",
"$",
"criteria",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"con",
")",
"{",
"$",
"con",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getWriteConnection",
"(",
"FunctionPhaseTableMap",
"::",
"DATABASE_NAME",
")",
";",
"}",
"if",
"(",
"$",
"criteria",
"instanceof",
"Criteria",
")",
"{",
"$",
"criteria",
"=",
"clone",
"$",
"criteria",
";",
"// rename for clarity",
"}",
"else",
"{",
"$",
"criteria",
"=",
"$",
"criteria",
"->",
"buildCriteria",
"(",
")",
";",
"// build Criteria from FunctionPhase object",
"}",
"// Set the correct dbName",
"$",
"query",
"=",
"FunctionPhaseQuery",
"::",
"create",
"(",
")",
"->",
"mergeWith",
"(",
"$",
"criteria",
")",
";",
"// use transaction because $criteria could contain info",
"// for more than one table (I guess, conceivably)",
"return",
"$",
"con",
"->",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"con",
",",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"doInsert",
"(",
"$",
"con",
")",
";",
"}",
")",
";",
"}"
] | Performs an INSERT on the database, given a FunctionPhase or Criteria object.
@param mixed $criteria Criteria or FunctionPhase object containing data that is used to create the INSERT statement.
@param ConnectionInterface $con the ConnectionInterface connection to use
@return mixed The new primary key.
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException. | [
"Performs",
"an",
"INSERT",
"on",
"the",
"database",
"given",
"a",
"FunctionPhase",
"or",
"Criteria",
"object",
"."
] | 221a6c5322473d7d7f8e322958a3ee46d87da150 | https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Map/FunctionPhaseTableMap.php#L428-L449 |
7,463 | aedart/model | src/Traits/Strings/OutputPathTrait.php | OutputPathTrait.getOutputPath | public function getOutputPath() : ?string
{
if ( ! $this->hasOutputPath()) {
$this->setOutputPath($this->getDefaultOutputPath());
}
return $this->outputPath;
} | php | public function getOutputPath() : ?string
{
if ( ! $this->hasOutputPath()) {
$this->setOutputPath($this->getDefaultOutputPath());
}
return $this->outputPath;
} | [
"public",
"function",
"getOutputPath",
"(",
")",
":",
"?",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOutputPath",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setOutputPath",
"(",
"$",
"this",
"->",
"getDefaultOutputPath",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"outputPath",
";",
"}"
] | Get output path
If no "output path" value has been set, this method will
set and return a default "output path" value,
if any such value is available
@see getDefaultOutputPath()
@return string|null output path or null if no output path has been set | [
"Get",
"output",
"path"
] | 9a562c1c53a276d01ace0ab71f5305458bea542f | https://github.com/aedart/model/blob/9a562c1c53a276d01ace0ab71f5305458bea542f/src/Traits/Strings/OutputPathTrait.php#L48-L54 |
7,464 | alfredoem/ragnarok | app/Ragnarok/SecUsers/SecUser.php | SecUser.populate | public function populate($data)
{
$this->userId = $data->userId;
$this->email = $data->email;
$this->firstName = $data->firstName;
$this->lastName = $data->lastName;
$this->status = $data->status;
$this->remember_token = $data->remember_token;
$this->userSessionId = $data->userSessionId;
$this->sessionCode = $data->sessionCode;
$this->ipAddress = $data->ipAddress;
$this->environment = $data->environment;
return $this;
} | php | public function populate($data)
{
$this->userId = $data->userId;
$this->email = $data->email;
$this->firstName = $data->firstName;
$this->lastName = $data->lastName;
$this->status = $data->status;
$this->remember_token = $data->remember_token;
$this->userSessionId = $data->userSessionId;
$this->sessionCode = $data->sessionCode;
$this->ipAddress = $data->ipAddress;
$this->environment = $data->environment;
return $this;
} | [
"public",
"function",
"populate",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"userId",
"=",
"$",
"data",
"->",
"userId",
";",
"$",
"this",
"->",
"email",
"=",
"$",
"data",
"->",
"email",
";",
"$",
"this",
"->",
"firstName",
"=",
"$",
"data",
"->",
"firstName",
";",
"$",
"this",
"->",
"lastName",
"=",
"$",
"data",
"->",
"lastName",
";",
"$",
"this",
"->",
"status",
"=",
"$",
"data",
"->",
"status",
";",
"$",
"this",
"->",
"remember_token",
"=",
"$",
"data",
"->",
"remember_token",
";",
"$",
"this",
"->",
"userSessionId",
"=",
"$",
"data",
"->",
"userSessionId",
";",
"$",
"this",
"->",
"sessionCode",
"=",
"$",
"data",
"->",
"sessionCode",
";",
"$",
"this",
"->",
"ipAddress",
"=",
"$",
"data",
"->",
"ipAddress",
";",
"$",
"this",
"->",
"environment",
"=",
"$",
"data",
"->",
"environment",
";",
"return",
"$",
"this",
";",
"}"
] | Fill the user attributes
@param $data | [
"Fill",
"the",
"user",
"attributes"
] | e7de18cbe7a64e6ce480093d9d98d64078d35dff | https://github.com/alfredoem/ragnarok/blob/e7de18cbe7a64e6ce480093d9d98d64078d35dff/app/Ragnarok/SecUsers/SecUser.php#L35-L48 |
7,465 | mrferos/Email-Stripper | src/EmailStripper/EmailStripper.php | EmailStripper.addStripper | public function addStripper($stripper)
{
if (is_string($stripper)) {
if (!class_exists($stripper)) {
$stripper = '\\' . __NAMESPACE__ . '\\Stripper\\' . $stripper;
if (!class_exists($stripper)) {
throw new \InvalidArgumentException('Class ' . $stripper . ' can not be found');
}
}
$stripper = new $stripper;
if (!$stripper instanceof StripperInterface) {
throw new InvalidArgumentException('Class "' . get_class($stripper) . '" must implement StripperInterface');
}
} elseif (!$stripper instanceof StripperInterface) {
throw new InvalidArgumentException('Class "' . get_class($stripper) . '" must implement StripperInterface');
}
$this->_stippers[] = $stripper;
} | php | public function addStripper($stripper)
{
if (is_string($stripper)) {
if (!class_exists($stripper)) {
$stripper = '\\' . __NAMESPACE__ . '\\Stripper\\' . $stripper;
if (!class_exists($stripper)) {
throw new \InvalidArgumentException('Class ' . $stripper . ' can not be found');
}
}
$stripper = new $stripper;
if (!$stripper instanceof StripperInterface) {
throw new InvalidArgumentException('Class "' . get_class($stripper) . '" must implement StripperInterface');
}
} elseif (!$stripper instanceof StripperInterface) {
throw new InvalidArgumentException('Class "' . get_class($stripper) . '" must implement StripperInterface');
}
$this->_stippers[] = $stripper;
} | [
"public",
"function",
"addStripper",
"(",
"$",
"stripper",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"stripper",
")",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"stripper",
")",
")",
"{",
"$",
"stripper",
"=",
"'\\\\'",
".",
"__NAMESPACE__",
".",
"'\\\\Stripper\\\\'",
".",
"$",
"stripper",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"stripper",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Class '",
".",
"$",
"stripper",
".",
"' can not be found'",
")",
";",
"}",
"}",
"$",
"stripper",
"=",
"new",
"$",
"stripper",
";",
"if",
"(",
"!",
"$",
"stripper",
"instanceof",
"StripperInterface",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Class \"'",
".",
"get_class",
"(",
"$",
"stripper",
")",
".",
"'\" must implement StripperInterface'",
")",
";",
"}",
"}",
"elseif",
"(",
"!",
"$",
"stripper",
"instanceof",
"StripperInterface",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Class \"'",
".",
"get_class",
"(",
"$",
"stripper",
")",
".",
"'\" must implement StripperInterface'",
")",
";",
"}",
"$",
"this",
"->",
"_stippers",
"[",
"]",
"=",
"$",
"stripper",
";",
"}"
] | Accept an object or class name that implements StripperInterface
@param string|StripperInterface $stripper | [
"Accept",
"an",
"object",
"or",
"class",
"name",
"that",
"implements",
"StripperInterface"
] | 2c13ddb736c563dedc4686da474dd6dd2d7bad25 | https://github.com/mrferos/Email-Stripper/blob/2c13ddb736c563dedc4686da474dd6dd2d7bad25/src/EmailStripper/EmailStripper.php#L43-L63 |
7,466 | uthando-cms/uthando-file-manager | src/UthandoFileManager/View/File.php | File.fileExists | public function fileExists($directory = null)
{
$directory = ($directory) ?: $this->fileDirectory;
$fileExists = file_exists($this->publicDirectory . $directory . $this->file);
return $fileExists;
} | php | public function fileExists($directory = null)
{
$directory = ($directory) ?: $this->fileDirectory;
$fileExists = file_exists($this->publicDirectory . $directory . $this->file);
return $fileExists;
} | [
"public",
"function",
"fileExists",
"(",
"$",
"directory",
"=",
"null",
")",
"{",
"$",
"directory",
"=",
"(",
"$",
"directory",
")",
"?",
":",
"$",
"this",
"->",
"fileDirectory",
";",
"$",
"fileExists",
"=",
"file_exists",
"(",
"$",
"this",
"->",
"publicDirectory",
".",
"$",
"directory",
".",
"$",
"this",
"->",
"file",
")",
";",
"return",
"$",
"fileExists",
";",
"}"
] | Checks to see if file exists
@param null $directory
@return bool | [
"Checks",
"to",
"see",
"if",
"file",
"exists"
] | e0b562e9b79f93ffef33a1e4d5a8f400895e7588 | https://github.com/uthando-cms/uthando-file-manager/blob/e0b562e9b79f93ffef33a1e4d5a8f400895e7588/src/UthandoFileManager/View/File.php#L59-L64 |
7,467 | uthando-cms/uthando-file-manager | src/UthandoFileManager/View/File.php | File.isFile | public function isFile($directory = null)
{
$directory = ($directory) ?: $this->fileDirectory;
$isFile = is_file($this->publicDirectory . $directory . $this->file);
return $isFile;
} | php | public function isFile($directory = null)
{
$directory = ($directory) ?: $this->fileDirectory;
$isFile = is_file($this->publicDirectory . $directory . $this->file);
return $isFile;
} | [
"public",
"function",
"isFile",
"(",
"$",
"directory",
"=",
"null",
")",
"{",
"$",
"directory",
"=",
"(",
"$",
"directory",
")",
"?",
":",
"$",
"this",
"->",
"fileDirectory",
";",
"$",
"isFile",
"=",
"is_file",
"(",
"$",
"this",
"->",
"publicDirectory",
".",
"$",
"directory",
".",
"$",
"this",
"->",
"file",
")",
";",
"return",
"$",
"isFile",
";",
"}"
] | Checks to see if file is a file
@param null $directory
@return bool | [
"Checks",
"to",
"see",
"if",
"file",
"is",
"a",
"file"
] | e0b562e9b79f93ffef33a1e4d5a8f400895e7588 | https://github.com/uthando-cms/uthando-file-manager/blob/e0b562e9b79f93ffef33a1e4d5a8f400895e7588/src/UthandoFileManager/View/File.php#L72-L77 |
7,468 | phlexible/phlexible | src/Phlexible/Bundle/QueueBundle/Controller/DataController.php | DataController.indexAction | public function indexAction(Request $request)
{
$jobManager = $this->get('phlexible_queue.job_manager');
$limit = $request->get('limit', 25);
$offset = $request->get('start', 0);
$data = [];
foreach ($jobManager->findBy([], ['createdAt' => 'DESC'], $limit, $offset) as $queueItem) {
$data[] = [
'id' => $queueItem->getId(),
'command' => $queueItem->getCommand(),
'priority' => $queueItem->getPriority(),
'status' => $queueItem->getState(),
'create_time' => $queueItem->getCreatedAt()->format('Y-m-d H:i:s'),
'start_time' => $queueItem->getStartedAt() ? $queueItem->getStartedAt()->format('Y-m-d H:i:s') : null,
'end_time' => $queueItem->getFinishedAt() ? $queueItem->getFinishedAt()->format('Y-m-d H:i:s') : null,
'output' => nl2br($queueItem->getOutput()),
];
}
$total = $jobManager->countBy([]);
return new JsonResponse(['data' => $data, 'total' => $total]);
} | php | public function indexAction(Request $request)
{
$jobManager = $this->get('phlexible_queue.job_manager');
$limit = $request->get('limit', 25);
$offset = $request->get('start', 0);
$data = [];
foreach ($jobManager->findBy([], ['createdAt' => 'DESC'], $limit, $offset) as $queueItem) {
$data[] = [
'id' => $queueItem->getId(),
'command' => $queueItem->getCommand(),
'priority' => $queueItem->getPriority(),
'status' => $queueItem->getState(),
'create_time' => $queueItem->getCreatedAt()->format('Y-m-d H:i:s'),
'start_time' => $queueItem->getStartedAt() ? $queueItem->getStartedAt()->format('Y-m-d H:i:s') : null,
'end_time' => $queueItem->getFinishedAt() ? $queueItem->getFinishedAt()->format('Y-m-d H:i:s') : null,
'output' => nl2br($queueItem->getOutput()),
];
}
$total = $jobManager->countBy([]);
return new JsonResponse(['data' => $data, 'total' => $total]);
} | [
"public",
"function",
"indexAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"jobManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'phlexible_queue.job_manager'",
")",
";",
"$",
"limit",
"=",
"$",
"request",
"->",
"get",
"(",
"'limit'",
",",
"25",
")",
";",
"$",
"offset",
"=",
"$",
"request",
"->",
"get",
"(",
"'start'",
",",
"0",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"jobManager",
"->",
"findBy",
"(",
"[",
"]",
",",
"[",
"'createdAt'",
"=>",
"'DESC'",
"]",
",",
"$",
"limit",
",",
"$",
"offset",
")",
"as",
"$",
"queueItem",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"queueItem",
"->",
"getId",
"(",
")",
",",
"'command'",
"=>",
"$",
"queueItem",
"->",
"getCommand",
"(",
")",
",",
"'priority'",
"=>",
"$",
"queueItem",
"->",
"getPriority",
"(",
")",
",",
"'status'",
"=>",
"$",
"queueItem",
"->",
"getState",
"(",
")",
",",
"'create_time'",
"=>",
"$",
"queueItem",
"->",
"getCreatedAt",
"(",
")",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
",",
"'start_time'",
"=>",
"$",
"queueItem",
"->",
"getStartedAt",
"(",
")",
"?",
"$",
"queueItem",
"->",
"getStartedAt",
"(",
")",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
":",
"null",
",",
"'end_time'",
"=>",
"$",
"queueItem",
"->",
"getFinishedAt",
"(",
")",
"?",
"$",
"queueItem",
"->",
"getFinishedAt",
"(",
")",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
":",
"null",
",",
"'output'",
"=>",
"nl2br",
"(",
"$",
"queueItem",
"->",
"getOutput",
"(",
")",
")",
",",
"]",
";",
"}",
"$",
"total",
"=",
"$",
"jobManager",
"->",
"countBy",
"(",
"[",
"]",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"[",
"'data'",
"=>",
"$",
"data",
",",
"'total'",
"=>",
"$",
"total",
"]",
")",
";",
"}"
] | Job list.
@param Request $request
@return JsonResponse
@Route("/list", name="queue_list") | [
"Job",
"list",
"."
] | 132f24924c9bb0dbb6c1ea84db0a463f97fa3893 | https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/QueueBundle/Controller/DataController.php#L37-L61 |
7,469 | arvici/framework | src/Arvici/Exception/Response/HttpException.php | HttpException.toResponse | public function toResponse()
{
$response = Http::getInstance()->response();
$response->reset();
$response->status($this->code);
if (is_string($this->details)) {
$response->body($this->details);
} elseif (is_string($this->message)) {
$response->body($this->message);
}
return $response;
} | php | public function toResponse()
{
$response = Http::getInstance()->response();
$response->reset();
$response->status($this->code);
if (is_string($this->details)) {
$response->body($this->details);
} elseif (is_string($this->message)) {
$response->body($this->message);
}
return $response;
} | [
"public",
"function",
"toResponse",
"(",
")",
"{",
"$",
"response",
"=",
"Http",
"::",
"getInstance",
"(",
")",
"->",
"response",
"(",
")",
";",
"$",
"response",
"->",
"reset",
"(",
")",
";",
"$",
"response",
"->",
"status",
"(",
"$",
"this",
"->",
"code",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"details",
")",
")",
"{",
"$",
"response",
"->",
"body",
"(",
"$",
"this",
"->",
"details",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"this",
"->",
"message",
")",
")",
"{",
"$",
"response",
"->",
"body",
"(",
"$",
"this",
"->",
"message",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Converts the error to a response object.
@return Response response object. | [
"Converts",
"the",
"error",
"to",
"a",
"response",
"object",
"."
] | 4d0933912fef8f9edc756ef1ace009e96d9fc4b1 | https://github.com/arvici/framework/blob/4d0933912fef8f9edc756ef1ace009e96d9fc4b1/src/Arvici/Exception/Response/HttpException.php#L33-L45 |
7,470 | monolyth-php/cesession | src/Session.php | Session.registerHandler | public function registerHandler(Handler $handler, int $chainProbability = 0) : void
{
static $first = true;
if ($first) {
$this->handlers = [];
$first = false;
}
$this->handlers[] = [$handler, $chainProbability];
} | php | public function registerHandler(Handler $handler, int $chainProbability = 0) : void
{
static $first = true;
if ($first) {
$this->handlers = [];
$first = false;
}
$this->handlers[] = [$handler, $chainProbability];
} | [
"public",
"function",
"registerHandler",
"(",
"Handler",
"$",
"handler",
",",
"int",
"$",
"chainProbability",
"=",
"0",
")",
":",
"void",
"{",
"static",
"$",
"first",
"=",
"true",
";",
"if",
"(",
"$",
"first",
")",
"{",
"$",
"this",
"->",
"handlers",
"=",
"[",
"]",
";",
"$",
"first",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"handlers",
"[",
"]",
"=",
"[",
"$",
"handler",
",",
"$",
"chainProbability",
"]",
";",
"}"
] | Register a session handler.
@param Cesession\Handler $handler Handler object to use.
@param int $chainProbability The probability, expressed as a percentage,
that calls on this handler will afterwards be forwarded to the next
handler in the chain.
@return void
@see Cesession\Handler | [
"Register",
"a",
"session",
"handler",
"."
] | 4b1660396dab801177d34271154f7f6d286de6fa | https://github.com/monolyth-php/cesession/blob/4b1660396dab801177d34271154f7f6d286de6fa/src/Session.php#L37-L45 |
7,471 | monolyth-php/cesession | src/Session.php | Session.walk | private function walk(string $method, int $highProbability = null, array $args = [])
{
$result = false;
foreach ($this->handlers as $data) {
list($handler, $chainProbability) = $data;
$probability = isset($highProbability) ?
$highProbability :
$chainProbability;
$result = call_user_func_array([$handler, $method], $args);
if ($result and mt_rand(0, 100) > $probability) {
return $result;
}
}
return $result;
} | php | private function walk(string $method, int $highProbability = null, array $args = [])
{
$result = false;
foreach ($this->handlers as $data) {
list($handler, $chainProbability) = $data;
$probability = isset($highProbability) ?
$highProbability :
$chainProbability;
$result = call_user_func_array([$handler, $method], $args);
if ($result and mt_rand(0, 100) > $probability) {
return $result;
}
}
return $result;
} | [
"private",
"function",
"walk",
"(",
"string",
"$",
"method",
",",
"int",
"$",
"highProbability",
"=",
"null",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"result",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"handlers",
"as",
"$",
"data",
")",
"{",
"list",
"(",
"$",
"handler",
",",
"$",
"chainProbability",
")",
"=",
"$",
"data",
";",
"$",
"probability",
"=",
"isset",
"(",
"$",
"highProbability",
")",
"?",
"$",
"highProbability",
":",
"$",
"chainProbability",
";",
"$",
"result",
"=",
"call_user_func_array",
"(",
"[",
"$",
"handler",
",",
"$",
"method",
"]",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"result",
"and",
"mt_rand",
"(",
"0",
",",
"100",
")",
">",
"$",
"probability",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Internal method to walk the handler chain.
@param string $method Method name to call on each handler. Note that the
method definitions on handlers differ from those in
SessionHandlerInterface.
@param int|null $highProbability Override to the handler's defined
$chainProbability. Defaults to null, i.e. not used.
@param array $args The arguments to pass to $method.
@return mixed Whatever $method returned. | [
"Internal",
"method",
"to",
"walk",
"the",
"handler",
"chain",
"."
] | 4b1660396dab801177d34271154f7f6d286de6fa | https://github.com/monolyth-php/cesession/blob/4b1660396dab801177d34271154f7f6d286de6fa/src/Session.php#L58-L72 |
7,472 | monolyth-php/cesession | src/Session.php | Session.read | public function read($id) : string
{
if ($session = $this->walk('read', null, [$id])) {
self::$session = $session;
return self::$session['data'];
}
return '';
} | php | public function read($id) : string
{
if ($session = $this->walk('read', null, [$id])) {
self::$session = $session;
return self::$session['data'];
}
return '';
} | [
"public",
"function",
"read",
"(",
"$",
"id",
")",
":",
"string",
"{",
"if",
"(",
"$",
"session",
"=",
"$",
"this",
"->",
"walk",
"(",
"'read'",
",",
"null",
",",
"[",
"$",
"id",
"]",
")",
")",
"{",
"self",
"::",
"$",
"session",
"=",
"$",
"session",
";",
"return",
"self",
"::",
"$",
"session",
"[",
"'data'",
"]",
";",
"}",
"return",
"''",
";",
"}"
] | Read the requested session.
@param string $id The session ID.
@return string The read data. | [
"Read",
"the",
"requested",
"session",
"."
] | 4b1660396dab801177d34271154f7f6d286de6fa | https://github.com/monolyth-php/cesession/blob/4b1660396dab801177d34271154f7f6d286de6fa/src/Session.php#L119-L126 |
7,473 | monolyth-php/cesession | src/Session.php | Session.write | public function write($id, $data) : bool
{
return (bool)$this->walk(
'write',
null,
[$id, compact('data') + self::$session]
);
} | php | public function write($id, $data) : bool
{
return (bool)$this->walk(
'write',
null,
[$id, compact('data') + self::$session]
);
} | [
"public",
"function",
"write",
"(",
"$",
"id",
",",
"$",
"data",
")",
":",
"bool",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"walk",
"(",
"'write'",
",",
"null",
",",
"[",
"$",
"id",
",",
"compact",
"(",
"'data'",
")",
"+",
"self",
"::",
"$",
"session",
"]",
")",
";",
"}"
] | Write the requested session.
@param string $id The session ID.
@param string $data The serialized session data as passed by PHP.
@return boolean True on success, else false. | [
"Write",
"the",
"requested",
"session",
"."
] | 4b1660396dab801177d34271154f7f6d286de6fa | https://github.com/monolyth-php/cesession/blob/4b1660396dab801177d34271154f7f6d286de6fa/src/Session.php#L135-L142 |
7,474 | MAXakaWIZARD/MoReader | src/Reader.php | Reader.readMsgId | protected function readMsgId($index)
{
$msgId = $this->readStringFromTable($index, $this->msgIdTable);
if (false === $msgId) {
$msgId = array('');
}
return $msgId;
} | php | protected function readMsgId($index)
{
$msgId = $this->readStringFromTable($index, $this->msgIdTable);
if (false === $msgId) {
$msgId = array('');
}
return $msgId;
} | [
"protected",
"function",
"readMsgId",
"(",
"$",
"index",
")",
"{",
"$",
"msgId",
"=",
"$",
"this",
"->",
"readStringFromTable",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"msgIdTable",
")",
";",
"if",
"(",
"false",
"===",
"$",
"msgId",
")",
"{",
"$",
"msgId",
"=",
"array",
"(",
"''",
")",
";",
"}",
"return",
"$",
"msgId",
";",
"}"
] | Reads specified message id record
@param int $index
@return array | [
"Reads",
"specified",
"message",
"id",
"record"
] | 873bdc08c9c9e561405f6c99cda2999f31ab0b2f | https://github.com/MAXakaWIZARD/MoReader/blob/873bdc08c9c9e561405f6c99cda2999f31ab0b2f/src/Reader.php#L128-L136 |
7,475 | MAXakaWIZARD/MoReader | src/Reader.php | Reader.readTranslation | protected function readTranslation($index)
{
$msgStr = $this->readStringFromTable($index, $this->msgStrTable);
if (false === $msgStr) {
$msgStr = array();
}
return $msgStr;
} | php | protected function readTranslation($index)
{
$msgStr = $this->readStringFromTable($index, $this->msgStrTable);
if (false === $msgStr) {
$msgStr = array();
}
return $msgStr;
} | [
"protected",
"function",
"readTranslation",
"(",
"$",
"index",
")",
"{",
"$",
"msgStr",
"=",
"$",
"this",
"->",
"readStringFromTable",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"msgStrTable",
")",
";",
"if",
"(",
"false",
"===",
"$",
"msgStr",
")",
"{",
"$",
"msgStr",
"=",
"array",
"(",
")",
";",
"}",
"return",
"$",
"msgStr",
";",
"}"
] | Reads specified translation record
@param int $index
@return array | [
"Reads",
"specified",
"translation",
"record"
] | 873bdc08c9c9e561405f6c99cda2999f31ab0b2f | https://github.com/MAXakaWIZARD/MoReader/blob/873bdc08c9c9e561405f6c99cda2999f31ab0b2f/src/Reader.php#L145-L153 |
7,476 | MAXakaWIZARD/MoReader | src/Reader.php | Reader.openFile | protected function openFile($filename)
{
$this->filename = $filename;
if (!is_file($this->filename)) {
throw new \Exception(
sprintf(
'File %s does not exist',
$this->filename
)
);
}
$this->file = fopen($this->filename, 'rb');
if (false === $this->file) {
throw new \Exception(
sprintf(
'Could not open file %s for reading',
$this->filename
)
);
}
} | php | protected function openFile($filename)
{
$this->filename = $filename;
if (!is_file($this->filename)) {
throw new \Exception(
sprintf(
'File %s does not exist',
$this->filename
)
);
}
$this->file = fopen($this->filename, 'rb');
if (false === $this->file) {
throw new \Exception(
sprintf(
'Could not open file %s for reading',
$this->filename
)
);
}
} | [
"protected",
"function",
"openFile",
"(",
"$",
"filename",
")",
"{",
"$",
"this",
"->",
"filename",
"=",
"$",
"filename",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"this",
"->",
"filename",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'File %s does not exist'",
",",
"$",
"this",
"->",
"filename",
")",
")",
";",
"}",
"$",
"this",
"->",
"file",
"=",
"fopen",
"(",
"$",
"this",
"->",
"filename",
",",
"'rb'",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"file",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Could not open file %s for reading'",
",",
"$",
"this",
"->",
"filename",
")",
")",
";",
"}",
"}"
] | Prepare file for reading
@param $filename
@throws \Exception | [
"Prepare",
"file",
"for",
"reading"
] | 873bdc08c9c9e561405f6c99cda2999f31ab0b2f | https://github.com/MAXakaWIZARD/MoReader/blob/873bdc08c9c9e561405f6c99cda2999f31ab0b2f/src/Reader.php#L192-L214 |
7,477 | MAXakaWIZARD/MoReader | src/Reader.php | Reader.determineByteOrder | protected function determineByteOrder()
{
$orderHeader = fread($this->file, 4);
if ($orderHeader == "\x95\x04\x12\xde") {
$this->littleEndian = false;
} elseif ($orderHeader == "\xde\x12\x04\x95") {
$this->littleEndian = true;
} else {
fclose($this->file);
throw new \Exception(
sprintf(
'%s is not a valid gettext file',
$this->filename
)
);
}
} | php | protected function determineByteOrder()
{
$orderHeader = fread($this->file, 4);
if ($orderHeader == "\x95\x04\x12\xde") {
$this->littleEndian = false;
} elseif ($orderHeader == "\xde\x12\x04\x95") {
$this->littleEndian = true;
} else {
fclose($this->file);
throw new \Exception(
sprintf(
'%s is not a valid gettext file',
$this->filename
)
);
}
} | [
"protected",
"function",
"determineByteOrder",
"(",
")",
"{",
"$",
"orderHeader",
"=",
"fread",
"(",
"$",
"this",
"->",
"file",
",",
"4",
")",
";",
"if",
"(",
"$",
"orderHeader",
"==",
"\"\\x95\\x04\\x12\\xde\"",
")",
"{",
"$",
"this",
"->",
"littleEndian",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"orderHeader",
"==",
"\"\\xde\\x12\\x04\\x95\"",
")",
"{",
"$",
"this",
"->",
"littleEndian",
"=",
"true",
";",
"}",
"else",
"{",
"fclose",
"(",
"$",
"this",
"->",
"file",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'%s is not a valid gettext file'",
",",
"$",
"this",
"->",
"filename",
")",
")",
";",
"}",
"}"
] | Determines byte order
@throws \Exception | [
"Determines",
"byte",
"order"
] | 873bdc08c9c9e561405f6c99cda2999f31ab0b2f | https://github.com/MAXakaWIZARD/MoReader/blob/873bdc08c9c9e561405f6c99cda2999f31ab0b2f/src/Reader.php#L221-L238 |
7,478 | MAXakaWIZARD/MoReader | src/Reader.php | Reader.readInteger | protected function readInteger()
{
if ($this->littleEndian) {
$result = unpack('Vint', fread($this->file, 4));
} else {
$result = unpack('Nint', fread($this->file, 4));
}
return $result['int'];
} | php | protected function readInteger()
{
if ($this->littleEndian) {
$result = unpack('Vint', fread($this->file, 4));
} else {
$result = unpack('Nint', fread($this->file, 4));
}
return $result['int'];
} | [
"protected",
"function",
"readInteger",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"littleEndian",
")",
"{",
"$",
"result",
"=",
"unpack",
"(",
"'Vint'",
",",
"fread",
"(",
"$",
"this",
"->",
"file",
",",
"4",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"unpack",
"(",
"'Nint'",
",",
"fread",
"(",
"$",
"this",
"->",
"file",
",",
"4",
")",
")",
";",
"}",
"return",
"$",
"result",
"[",
"'int'",
"]",
";",
"}"
] | Read a single integer from the current file.
@return int | [
"Read",
"a",
"single",
"integer",
"from",
"the",
"current",
"file",
"."
] | 873bdc08c9c9e561405f6c99cda2999f31ab0b2f | https://github.com/MAXakaWIZARD/MoReader/blob/873bdc08c9c9e561405f6c99cda2999f31ab0b2f/src/Reader.php#L265-L274 |
7,479 | MAXakaWIZARD/MoReader | src/Reader.php | Reader.readIntegerList | protected function readIntegerList($num)
{
if ($this->littleEndian) {
return unpack('V' . $num, fread($this->file, 4 * $num));
}
return unpack('N' . $num, fread($this->file, 4 * $num));
} | php | protected function readIntegerList($num)
{
if ($this->littleEndian) {
return unpack('V' . $num, fread($this->file, 4 * $num));
}
return unpack('N' . $num, fread($this->file, 4 * $num));
} | [
"protected",
"function",
"readIntegerList",
"(",
"$",
"num",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"littleEndian",
")",
"{",
"return",
"unpack",
"(",
"'V'",
".",
"$",
"num",
",",
"fread",
"(",
"$",
"this",
"->",
"file",
",",
"4",
"*",
"$",
"num",
")",
")",
";",
"}",
"return",
"unpack",
"(",
"'N'",
".",
"$",
"num",
",",
"fread",
"(",
"$",
"this",
"->",
"file",
",",
"4",
"*",
"$",
"num",
")",
")",
";",
"}"
] | Read an integer from the current file.
@param int $num
@return array | [
"Read",
"an",
"integer",
"from",
"the",
"current",
"file",
"."
] | 873bdc08c9c9e561405f6c99cda2999f31ab0b2f | https://github.com/MAXakaWIZARD/MoReader/blob/873bdc08c9c9e561405f6c99cda2999f31ab0b2f/src/Reader.php#L282-L289 |
7,480 | thecodingmachine/integration.wordpress.moufpress | src/Mouf/Integration/Wordpress/Moufpress/MoufpressWidget.php | MoufpressWidget.widget | public function widget($args, $instance)
{
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? null : apply_filters('widget_title', $instance['title']);
if (!empty($title)) {
echo $before_title.$title.$after_title;
};
MoufManager::getMoufManager()->get($instance['instance'])->toHtml();
echo $after_widget;
} | php | public function widget($args, $instance)
{
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? null : apply_filters('widget_title', $instance['title']);
if (!empty($title)) {
echo $before_title.$title.$after_title;
};
MoufManager::getMoufManager()->get($instance['instance'])->toHtml();
echo $after_widget;
} | [
"public",
"function",
"widget",
"(",
"$",
"args",
",",
"$",
"instance",
")",
"{",
"extract",
"(",
"$",
"args",
",",
"EXTR_SKIP",
")",
";",
"echo",
"$",
"before_widget",
";",
"$",
"title",
"=",
"empty",
"(",
"$",
"instance",
"[",
"'title'",
"]",
")",
"?",
"null",
":",
"apply_filters",
"(",
"'widget_title'",
",",
"$",
"instance",
"[",
"'title'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"title",
")",
")",
"{",
"echo",
"$",
"before_title",
".",
"$",
"title",
".",
"$",
"after_title",
";",
"}",
";",
"MoufManager",
"::",
"getMoufManager",
"(",
")",
"->",
"get",
"(",
"$",
"instance",
"[",
"'instance'",
"]",
")",
"->",
"toHtml",
"(",
")",
";",
"echo",
"$",
"after_widget",
";",
"}"
] | Display widget. | [
"Display",
"widget",
"."
] | c0a3d7944d38450227d2cf4533410e3597bd2c3c | https://github.com/thecodingmachine/integration.wordpress.moufpress/blob/c0a3d7944d38450227d2cf4533410e3597bd2c3c/src/Mouf/Integration/Wordpress/Moufpress/MoufpressWidget.php#L30-L42 |
7,481 | thecodingmachine/integration.wordpress.moufpress | src/Mouf/Integration/Wordpress/Moufpress/MoufpressWidget.php | MoufpressWidget.form | public function form($instance)
{
$default = array(
'title' => '',
'instance' => null,
);
$instance = wp_parse_args((array) $instance, $default);
$title_id = $this->get_field_id('title');
$title_name = $this->get_field_name('title');
echo '<p>
<label for="'.$title_id.'">'.__('Title').
': <input type="text" class="widefat" id="'.$title_id.'" name="'.$title_name.'" value="'.esc_attr($instance ['title']).'" />
</label></p>';
$instance_id = $this->get_field_id('instance');
$instance_name = $this->get_field_name('instance');
$moufManager = MoufManager::getMoufManager();
$instances = $moufManager->findInstances('Mouf\\Html\\HtmlElement\\HtmlElementInterface');
sort($instances);
echo '<p>
<label for="'.$instance_id.'">'.__('Instance').':
<select class="widefat" id="'.$instance_id.'" name="'.$instance_name.'" >
';
foreach ($instances as $name) {
if ($moufManager->isInstanceAnonymous($name)) {
continue;
}
?>
<option value="<?php echo esc_attr($name);
?>" <?php if ($name == $instance ['instance']) {
echo "selected='selected'";
}
?>><?php echo esc_html($name);
?></option>
<?php
}
echo '
</select>
</label></p>';
} | php | public function form($instance)
{
$default = array(
'title' => '',
'instance' => null,
);
$instance = wp_parse_args((array) $instance, $default);
$title_id = $this->get_field_id('title');
$title_name = $this->get_field_name('title');
echo '<p>
<label for="'.$title_id.'">'.__('Title').
': <input type="text" class="widefat" id="'.$title_id.'" name="'.$title_name.'" value="'.esc_attr($instance ['title']).'" />
</label></p>';
$instance_id = $this->get_field_id('instance');
$instance_name = $this->get_field_name('instance');
$moufManager = MoufManager::getMoufManager();
$instances = $moufManager->findInstances('Mouf\\Html\\HtmlElement\\HtmlElementInterface');
sort($instances);
echo '<p>
<label for="'.$instance_id.'">'.__('Instance').':
<select class="widefat" id="'.$instance_id.'" name="'.$instance_name.'" >
';
foreach ($instances as $name) {
if ($moufManager->isInstanceAnonymous($name)) {
continue;
}
?>
<option value="<?php echo esc_attr($name);
?>" <?php if ($name == $instance ['instance']) {
echo "selected='selected'";
}
?>><?php echo esc_html($name);
?></option>
<?php
}
echo '
</select>
</label></p>';
} | [
"public",
"function",
"form",
"(",
"$",
"instance",
")",
"{",
"$",
"default",
"=",
"array",
"(",
"'title'",
"=>",
"''",
",",
"'instance'",
"=>",
"null",
",",
")",
";",
"$",
"instance",
"=",
"wp_parse_args",
"(",
"(",
"array",
")",
"$",
"instance",
",",
"$",
"default",
")",
";",
"$",
"title_id",
"=",
"$",
"this",
"->",
"get_field_id",
"(",
"'title'",
")",
";",
"$",
"title_name",
"=",
"$",
"this",
"->",
"get_field_name",
"(",
"'title'",
")",
";",
"echo",
"'<p>\n\t\t\t\t<label for=\"'",
".",
"$",
"title_id",
".",
"'\">'",
".",
"__",
"(",
"'Title'",
")",
".",
"': <input type=\"text\" class=\"widefat\" id=\"'",
".",
"$",
"title_id",
".",
"'\" name=\"'",
".",
"$",
"title_name",
".",
"'\" value=\"'",
".",
"esc_attr",
"(",
"$",
"instance",
"[",
"'title'",
"]",
")",
".",
"'\" />\n\t\t\t</label></p>'",
";",
"$",
"instance_id",
"=",
"$",
"this",
"->",
"get_field_id",
"(",
"'instance'",
")",
";",
"$",
"instance_name",
"=",
"$",
"this",
"->",
"get_field_name",
"(",
"'instance'",
")",
";",
"$",
"moufManager",
"=",
"MoufManager",
"::",
"getMoufManager",
"(",
")",
";",
"$",
"instances",
"=",
"$",
"moufManager",
"->",
"findInstances",
"(",
"'Mouf\\\\Html\\\\HtmlElement\\\\HtmlElementInterface'",
")",
";",
"sort",
"(",
"$",
"instances",
")",
";",
"echo",
"'<p>\n\t\t\t\t<label for=\"'",
".",
"$",
"instance_id",
".",
"'\">'",
".",
"__",
"(",
"'Instance'",
")",
".",
"':\n\t\t\t\t<select class=\"widefat\" id=\"'",
".",
"$",
"instance_id",
".",
"'\" name=\"'",
".",
"$",
"instance_name",
".",
"'\" >\n\t\t\t\t\t'",
";",
"foreach",
"(",
"$",
"instances",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"moufManager",
"->",
"isInstanceAnonymous",
"(",
"$",
"name",
")",
")",
"{",
"continue",
";",
"}",
"?>\n\t\t\t<option value=\"<?php",
"echo",
"esc_attr",
"(",
"$",
"name",
")",
";",
"?>\" <?php",
"if",
"(",
"$",
"name",
"==",
"$",
"instance",
"[",
"'instance'",
"]",
")",
"{",
"echo",
"\"selected='selected'\"",
";",
"}",
"?>><?php",
"echo",
"esc_html",
"(",
"$",
"name",
")",
";",
"?></option>\n\t\t\t<?php",
"}",
"echo",
"'\n\t\t\t\t</select>\n\t\t\t</label></p>'",
";",
"}"
] | admin control form. | [
"admin",
"control",
"form",
"."
] | c0a3d7944d38450227d2cf4533410e3597bd2c3c | https://github.com/thecodingmachine/integration.wordpress.moufpress/blob/c0a3d7944d38450227d2cf4533410e3597bd2c3c/src/Mouf/Integration/Wordpress/Moufpress/MoufpressWidget.php#L59-L101 |
7,482 | kore/CTXParser | src/php/CTXParser/Stack.php | Stack.offsetGet | public function offsetGet($key)
{
$key = $this->count - $key - 1;
if (!isset($this->data[$key])) {
throw new \OutOfRangeException("Out of range.");
}
return $this->data[$key];
} | php | public function offsetGet($key)
{
$key = $this->count - $key - 1;
if (!isset($this->data[$key])) {
throw new \OutOfRangeException("Out of range.");
}
return $this->data[$key];
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"count",
"-",
"$",
"key",
"-",
"1",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfRangeException",
"(",
"\"Out of range.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
";",
"}"
] | Returns the element with the given offset.
This method is part of the ArrayAccess interface to allow access to the
data of this object as if it was an array.
@param string $key
@return mixed
@throws ezcBasePropertyNotFoundException
If no dataset with identifier exists | [
"Returns",
"the",
"element",
"with",
"the",
"given",
"offset",
"."
] | 9b11c2311a9de61baee7edafe46d1671dd5833c4 | https://github.com/kore/CTXParser/blob/9b11c2311a9de61baee7edafe46d1671dd5833c4/src/php/CTXParser/Stack.php#L84-L92 |
7,483 | kore/CTXParser | src/php/CTXParser/Stack.php | Stack.offsetSet | public function offsetSet($key, $value)
{
$key = $this->count - $key - 1;
if (!isset($this->data[$key])) {
throw new \OutOfRangeException("Out of range.");
}
$this->data[$key] = $value;
} | php | public function offsetSet($key, $value)
{
$key = $this->count - $key - 1;
if (!isset($this->data[$key])) {
throw new \OutOfRangeException("Out of range.");
}
$this->data[$key] = $value;
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"count",
"-",
"$",
"key",
"-",
"1",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfRangeException",
"(",
"\"Out of range.\"",
")",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | Set the element with the given offset.
This method is part of the ArrayAccess interface to allow access to the
data of this object as if it was an array.
Setting of not yet existing offsets in the stack is not allowed and will
return a ezcBaseValueException.
@param string $key
@param mixed $value
@return void
@throws ezcBaseValueException
Setting unknown offsets is not allowed | [
"Set",
"the",
"element",
"with",
"the",
"given",
"offset",
"."
] | 9b11c2311a9de61baee7edafe46d1671dd5833c4 | https://github.com/kore/CTXParser/blob/9b11c2311a9de61baee7edafe46d1671dd5833c4/src/php/CTXParser/Stack.php#L110-L118 |
7,484 | ItinerisLtd/preflight-command | src/Runner.php | Runner.check | public static function check(
ConfigCollection $configCollection,
CheckerCollection $checkerCollection
): ResultCollection {
$resultCollection = new ResultCollection();
foreach ($checkerCollection->all() as $id => $checker) {
$resultCollection->add(
$checker->check(
$configCollection->getConfig($id)
)
);
}
return $resultCollection;
} | php | public static function check(
ConfigCollection $configCollection,
CheckerCollection $checkerCollection
): ResultCollection {
$resultCollection = new ResultCollection();
foreach ($checkerCollection->all() as $id => $checker) {
$resultCollection->add(
$checker->check(
$configCollection->getConfig($id)
)
);
}
return $resultCollection;
} | [
"public",
"static",
"function",
"check",
"(",
"ConfigCollection",
"$",
"configCollection",
",",
"CheckerCollection",
"$",
"checkerCollection",
")",
":",
"ResultCollection",
"{",
"$",
"resultCollection",
"=",
"new",
"ResultCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"checkerCollection",
"->",
"all",
"(",
")",
"as",
"$",
"id",
"=>",
"$",
"checker",
")",
"{",
"$",
"resultCollection",
"->",
"add",
"(",
"$",
"checker",
"->",
"check",
"(",
"$",
"configCollection",
"->",
"getConfig",
"(",
"$",
"id",
")",
")",
")",
";",
"}",
"return",
"$",
"resultCollection",
";",
"}"
] | Run all the checkers according to their configs.
@param ConfigCollection $configCollection The config collection instance.
@param CheckerCollection $checkerCollection The checker collection instance.
@return ResultCollection | [
"Run",
"all",
"the",
"checkers",
"according",
"to",
"their",
"configs",
"."
] | d1c1360ea8d7de0312b5c0c09c9c486949594049 | https://github.com/ItinerisLtd/preflight-command/blob/d1c1360ea8d7de0312b5c0c09c9c486949594049/src/Runner.php#L16-L31 |
7,485 | thecmsthread/theme | src/API.php | API.run | public function run(): array
{
try {
$result = null;
if ($this->match !== false && is_callable($this->match['target']) === true) {
if (func_num_args() > 0) {
foreach (func_get_args() as $argument) {
$this->match['params'][] = $argument;
}
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) === false) {
$this->match['params'][] = $_POST;
} elseif ($_SERVER['REQUEST_METHOD'] == 'GET' && empty($_GET) === false) {
$this->match['params'][] = $_GET;
} elseif ($_SERVER['REQUEST_METHOD'] == 'PUT') {
$_PUT = parse_str(file_get_contents("php://input"));
if (empty($_PUT) === false) {
$this->match['params'][] = $_PUT;
}
} elseif ($_SERVER['REQUEST_METHOD'] == 'PATCH') {
$_PATCH = parse_str(file_get_contents("php://input"));
if (empty($_PATCH) === false) {
$this->match['params'][] = $_PATCH;
}
}
$result = call_user_func_array($this->match['target'], $this->match['params']);
} else {
throw new \InvalidArgumentException("Method not found");
}
return $result;
} catch (\Throwable $e) {
if ($e instanceof \InvalidArgumentException) {
return [
"headers" => [
[
'X-PHP-Response-Code: 400',
true,
400
]
],
"response" => $e->getMessage()
];
} elseif ($e instanceof \DomainException) {
return [
"headers" => [
[
'X-PHP-Response-Code: 422',
true,
422
]
],
"response" => $e->getMessage()
];
} else {
return [
"headers" => [
[
'X-PHP-Response-Code: 500',
true,
500
]
],
"response" => $e->getMessage()
];
}
}
} | php | public function run(): array
{
try {
$result = null;
if ($this->match !== false && is_callable($this->match['target']) === true) {
if (func_num_args() > 0) {
foreach (func_get_args() as $argument) {
$this->match['params'][] = $argument;
}
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) === false) {
$this->match['params'][] = $_POST;
} elseif ($_SERVER['REQUEST_METHOD'] == 'GET' && empty($_GET) === false) {
$this->match['params'][] = $_GET;
} elseif ($_SERVER['REQUEST_METHOD'] == 'PUT') {
$_PUT = parse_str(file_get_contents("php://input"));
if (empty($_PUT) === false) {
$this->match['params'][] = $_PUT;
}
} elseif ($_SERVER['REQUEST_METHOD'] == 'PATCH') {
$_PATCH = parse_str(file_get_contents("php://input"));
if (empty($_PATCH) === false) {
$this->match['params'][] = $_PATCH;
}
}
$result = call_user_func_array($this->match['target'], $this->match['params']);
} else {
throw new \InvalidArgumentException("Method not found");
}
return $result;
} catch (\Throwable $e) {
if ($e instanceof \InvalidArgumentException) {
return [
"headers" => [
[
'X-PHP-Response-Code: 400',
true,
400
]
],
"response" => $e->getMessage()
];
} elseif ($e instanceof \DomainException) {
return [
"headers" => [
[
'X-PHP-Response-Code: 422',
true,
422
]
],
"response" => $e->getMessage()
];
} else {
return [
"headers" => [
[
'X-PHP-Response-Code: 500',
true,
500
]
],
"response" => $e->getMessage()
];
}
}
} | [
"public",
"function",
"run",
"(",
")",
":",
"array",
"{",
"try",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"match",
"!==",
"false",
"&&",
"is_callable",
"(",
"$",
"this",
"->",
"match",
"[",
"'target'",
"]",
")",
"===",
"true",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"$",
"this",
"->",
"match",
"[",
"'params'",
"]",
"[",
"]",
"=",
"$",
"argument",
";",
"}",
"}",
"elseif",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"'POST'",
"&&",
"empty",
"(",
"$",
"_POST",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"match",
"[",
"'params'",
"]",
"[",
"]",
"=",
"$",
"_POST",
";",
"}",
"elseif",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"'GET'",
"&&",
"empty",
"(",
"$",
"_GET",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"match",
"[",
"'params'",
"]",
"[",
"]",
"=",
"$",
"_GET",
";",
"}",
"elseif",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"'PUT'",
")",
"{",
"$",
"_PUT",
"=",
"parse_str",
"(",
"file_get_contents",
"(",
"\"php://input\"",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"_PUT",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"match",
"[",
"'params'",
"]",
"[",
"]",
"=",
"$",
"_PUT",
";",
"}",
"}",
"elseif",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"'PATCH'",
")",
"{",
"$",
"_PATCH",
"=",
"parse_str",
"(",
"file_get_contents",
"(",
"\"php://input\"",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"_PATCH",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"match",
"[",
"'params'",
"]",
"[",
"]",
"=",
"$",
"_PATCH",
";",
"}",
"}",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"match",
"[",
"'target'",
"]",
",",
"$",
"this",
"->",
"match",
"[",
"'params'",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Method not found\"",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"instanceof",
"\\",
"InvalidArgumentException",
")",
"{",
"return",
"[",
"\"headers\"",
"=>",
"[",
"[",
"'X-PHP-Response-Code: 400'",
",",
"true",
",",
"400",
"]",
"]",
",",
"\"response\"",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"elseif",
"(",
"$",
"e",
"instanceof",
"\\",
"DomainException",
")",
"{",
"return",
"[",
"\"headers\"",
"=>",
"[",
"[",
"'X-PHP-Response-Code: 422'",
",",
"true",
",",
"422",
"]",
"]",
",",
"\"response\"",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"\"headers\"",
"=>",
"[",
"[",
"'X-PHP-Response-Code: 500'",
",",
"true",
",",
"500",
"]",
"]",
",",
"\"response\"",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
";",
"}",
"}",
"}"
] | Runs the API function and returns the result
@return array | [
"Runs",
"the",
"API",
"function",
"and",
"returns",
"the",
"result"
] | 5031373d5af50cbd2d8862b919b1e1190cd4c84f | https://github.com/thecmsthread/theme/blob/5031373d5af50cbd2d8862b919b1e1190cd4c84f/src/API.php#L300-L365 |
7,486 | thecmsthread/theme | src/API.php | API.set | public function set(string $link = null, string $method = null): \TheCMSThread\Classes\API
{
if ($link === null) {
if (isset($_SERVER['REQUEST_URI']) === false) {
$_SERVER['REQUEST_URI'] = '/';
}
$link = str_replace("?" . $_SERVER["QUERY_STRING"], "", $_SERVER["REQUEST_URI"]);
}
$link = '/' . trim($link, '/');
if ($method === null) {
if (isset($_SERVER['REQUEST_METHOD']) === false) {
$_SERVER['REQUEST_METHOD'] = 'GET';
}
$method = $_SERVER['REQUEST_METHOD'];
}
if ($method == 'POST' && empty($_POST['_method']) === false) {
$method = $_POST['_method'];
unset($_POST['_method']);
}
$this->match = $this->router->match($link, $method);
return $this;
} | php | public function set(string $link = null, string $method = null): \TheCMSThread\Classes\API
{
if ($link === null) {
if (isset($_SERVER['REQUEST_URI']) === false) {
$_SERVER['REQUEST_URI'] = '/';
}
$link = str_replace("?" . $_SERVER["QUERY_STRING"], "", $_SERVER["REQUEST_URI"]);
}
$link = '/' . trim($link, '/');
if ($method === null) {
if (isset($_SERVER['REQUEST_METHOD']) === false) {
$_SERVER['REQUEST_METHOD'] = 'GET';
}
$method = $_SERVER['REQUEST_METHOD'];
}
if ($method == 'POST' && empty($_POST['_method']) === false) {
$method = $_POST['_method'];
unset($_POST['_method']);
}
$this->match = $this->router->match($link, $method);
return $this;
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"link",
"=",
"null",
",",
"string",
"$",
"method",
"=",
"null",
")",
":",
"\\",
"TheCMSThread",
"\\",
"Classes",
"\\",
"API",
"{",
"if",
"(",
"$",
"link",
"===",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
"===",
"false",
")",
"{",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
"=",
"'/'",
";",
"}",
"$",
"link",
"=",
"str_replace",
"(",
"\"?\"",
".",
"$",
"_SERVER",
"[",
"\"QUERY_STRING\"",
"]",
",",
"\"\"",
",",
"$",
"_SERVER",
"[",
"\"REQUEST_URI\"",
"]",
")",
";",
"}",
"$",
"link",
"=",
"'/'",
".",
"trim",
"(",
"$",
"link",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"method",
"===",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
"===",
"false",
")",
"{",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"=",
"'GET'",
";",
"}",
"$",
"method",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
";",
"}",
"if",
"(",
"$",
"method",
"==",
"'POST'",
"&&",
"empty",
"(",
"$",
"_POST",
"[",
"'_method'",
"]",
")",
"===",
"false",
")",
"{",
"$",
"method",
"=",
"$",
"_POST",
"[",
"'_method'",
"]",
";",
"unset",
"(",
"$",
"_POST",
"[",
"'_method'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"match",
"=",
"$",
"this",
"->",
"router",
"->",
"match",
"(",
"$",
"link",
",",
"$",
"method",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the active API link
@param string $link The route to be set to.
@param string $method The method to be set to.
@return TheCMSThread\Classes\API | [
"Set",
"the",
"active",
"API",
"link"
] | 5031373d5af50cbd2d8862b919b1e1190cd4c84f | https://github.com/thecmsthread/theme/blob/5031373d5af50cbd2d8862b919b1e1190cd4c84f/src/API.php#L375-L398 |
7,487 | milkyway-multimedia/ss-mwm-core | code/Core/Extensions/DBField.php | DBField.HTMLID | public function HTMLID($lowercase = false) {
$str = trim(str_replace(' ', '-', ucwords(str_replace(['_', '-', '/'], ' ', $this->owner->value))), '-');
return $lowercase ? strtolower($str) : $str;
} | php | public function HTMLID($lowercase = false) {
$str = trim(str_replace(' ', '-', ucwords(str_replace(['_', '-', '/'], ' ', $this->owner->value))), '-');
return $lowercase ? strtolower($str) : $str;
} | [
"public",
"function",
"HTMLID",
"(",
"$",
"lowercase",
"=",
"false",
")",
"{",
"$",
"str",
"=",
"trim",
"(",
"str_replace",
"(",
"' '",
",",
"'-'",
",",
"ucwords",
"(",
"str_replace",
"(",
"[",
"'_'",
",",
"'-'",
",",
"'/'",
"]",
",",
"' '",
",",
"$",
"this",
"->",
"owner",
"->",
"value",
")",
")",
")",
",",
"'-'",
")",
";",
"return",
"$",
"lowercase",
"?",
"strtolower",
"(",
"$",
"str",
")",
":",
"$",
"str",
";",
"}"
] | Convert value to an appropriate HTML ID
@param bool $lowercase
@return string | [
"Convert",
"value",
"to",
"an",
"appropriate",
"HTML",
"ID"
] | e7216653b7100ead5a7d56736a124bee1c76fcd5 | https://github.com/milkyway-multimedia/ss-mwm-core/blob/e7216653b7100ead5a7d56736a124bee1c76fcd5/code/Core/Extensions/DBField.php#L53-L56 |
7,488 | milkyway-multimedia/ss-mwm-core | code/Core/Extensions/DBField.php | DBField.nl2list | public function nl2list($class = '', $liClass = '', $tag = 'ul') {
$val = trim($this->owner->XML(), "\n");
$val = str_replace("\n", sprintf('</li><li%s>', $liClass ? 'class="' . $liClass . '"' : ''), $val);
$val = $liClass ? '<li class="' . $liClass . '">' . $val . '</li>' : '<li>' . $val . '</li>';
return $class ? '<' . $tag . ' class="' . $class . '">' . $val . '</' . $tag . '>' : '<' . $tag . '>' . $val . '</' . $tag . '>';
} | php | public function nl2list($class = '', $liClass = '', $tag = 'ul') {
$val = trim($this->owner->XML(), "\n");
$val = str_replace("\n", sprintf('</li><li%s>', $liClass ? 'class="' . $liClass . '"' : ''), $val);
$val = $liClass ? '<li class="' . $liClass . '">' . $val . '</li>' : '<li>' . $val . '</li>';
return $class ? '<' . $tag . ' class="' . $class . '">' . $val . '</' . $tag . '>' : '<' . $tag . '>' . $val . '</' . $tag . '>';
} | [
"public",
"function",
"nl2list",
"(",
"$",
"class",
"=",
"''",
",",
"$",
"liClass",
"=",
"''",
",",
"$",
"tag",
"=",
"'ul'",
")",
"{",
"$",
"val",
"=",
"trim",
"(",
"$",
"this",
"->",
"owner",
"->",
"XML",
"(",
")",
",",
"\"\\n\"",
")",
";",
"$",
"val",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"sprintf",
"(",
"'</li><li%s>'",
",",
"$",
"liClass",
"?",
"'class=\"'",
".",
"$",
"liClass",
".",
"'\"'",
":",
"''",
")",
",",
"$",
"val",
")",
";",
"$",
"val",
"=",
"$",
"liClass",
"?",
"'<li class=\"'",
".",
"$",
"liClass",
".",
"'\">'",
".",
"$",
"val",
".",
"'</li>'",
":",
"'<li>'",
".",
"$",
"val",
".",
"'</li>'",
";",
"return",
"$",
"class",
"?",
"'<'",
".",
"$",
"tag",
".",
"' class=\"'",
".",
"$",
"class",
".",
"'\">'",
".",
"$",
"val",
".",
"'</'",
".",
"$",
"tag",
".",
"'>'",
":",
"'<'",
".",
"$",
"tag",
".",
"'>'",
".",
"$",
"val",
".",
"'</'",
".",
"$",
"tag",
".",
"'>'",
";",
"}"
] | Convert new lines to a list
@param string $class
@param string $liClass
@param string $tag
@return string | [
"Convert",
"new",
"lines",
"to",
"a",
"list"
] | e7216653b7100ead5a7d56736a124bee1c76fcd5 | https://github.com/milkyway-multimedia/ss-mwm-core/blob/e7216653b7100ead5a7d56736a124bee1c76fcd5/code/Core/Extensions/DBField.php#L83-L91 |
7,489 | milkyway-multimedia/ss-mwm-core | code/Core/Extensions/DBField.php | DBField.FormatOrUnknown | public function FormatOrUnknown($format = 'Nice') {
return $this->owner->value && $this->owner->value != '0000-00-00 00:00:00' ? $this->owner->$format() : _t('_UNKNOWN_', '(unknown)');
} | php | public function FormatOrUnknown($format = 'Nice') {
return $this->owner->value && $this->owner->value != '0000-00-00 00:00:00' ? $this->owner->$format() : _t('_UNKNOWN_', '(unknown)');
} | [
"public",
"function",
"FormatOrUnknown",
"(",
"$",
"format",
"=",
"'Nice'",
")",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"value",
"&&",
"$",
"this",
"->",
"owner",
"->",
"value",
"!=",
"'0000-00-00 00:00:00'",
"?",
"$",
"this",
"->",
"owner",
"->",
"$",
"format",
"(",
")",
":",
"_t",
"(",
"'_UNKNOWN_'",
",",
"'(unknown)'",
")",
";",
"}"
] | Format a field or return as unknown
@param string $format
@return string | [
"Format",
"a",
"field",
"or",
"return",
"as",
"unknown"
] | e7216653b7100ead5a7d56736a124bee1c76fcd5 | https://github.com/milkyway-multimedia/ss-mwm-core/blob/e7216653b7100ead5a7d56736a124bee1c76fcd5/code/Core/Extensions/DBField.php#L126-L128 |
7,490 | milkyway-multimedia/ss-mwm-core | code/Core/Extensions/DBField.php | DBField.FormatOrNot | public function FormatOrNot($format = 'Nice') {
return $this->owner->value && $this->owner->value != '0000-00-00 00:00:00' ? $this->owner->$format() : '<span class="ui-button-icon-primary ui-icon btn-icon-decline"></span>';
} | php | public function FormatOrNot($format = 'Nice') {
return $this->owner->value && $this->owner->value != '0000-00-00 00:00:00' ? $this->owner->$format() : '<span class="ui-button-icon-primary ui-icon btn-icon-decline"></span>';
} | [
"public",
"function",
"FormatOrNot",
"(",
"$",
"format",
"=",
"'Nice'",
")",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"value",
"&&",
"$",
"this",
"->",
"owner",
"->",
"value",
"!=",
"'0000-00-00 00:00:00'",
"?",
"$",
"this",
"->",
"owner",
"->",
"$",
"format",
"(",
")",
":",
"'<span class=\"ui-button-icon-primary ui-icon btn-icon-decline\"></span>'",
";",
"}"
] | Format a field or return as cms false
@param string $format
@return string | [
"Format",
"a",
"field",
"or",
"return",
"as",
"cms",
"false"
] | e7216653b7100ead5a7d56736a124bee1c76fcd5 | https://github.com/milkyway-multimedia/ss-mwm-core/blob/e7216653b7100ead5a7d56736a124bee1c76fcd5/code/Core/Extensions/DBField.php#L136-L138 |
7,491 | budkit/budkit-framework | src/Budkit/Datastore/Table.php | Table.bindData | final public function bindData($data, $ignore = array(), $strict = true, $filter = array())
{
$validate = $this->validator;
if (!is_object($data) && !is_array($data)) {
throw new Exception(t("Data must be either an object or array"));
return false;
}
$dataArray = is_array($data);
$dataObject = is_object($data);
foreach ($this->schema as $k => $v) {
// internal attributes of an object are ignored
if (!in_array($k, $ignore)) {
if ($dataArray && isset($data[$k])) {
//If $data[k] is an array?
$this->schema[$k]->Value = $data[$k];
} else if ($dataObject && isset($data->$k)) {
$this->schema[$k]->Value = $data->$k;
}
}
//validate. if only just 1 fails, break and throw an error;
if (isset($this->schema[$k]->Validate) && isset($this->schema[$k]->Value)) {
$datatype = $this->schema[$k]->Validate;
$datavalue = $this->schema[$k]->Value;
if (method_exists($validate, $datatype)) {
if (!\call_user_func(array($validate, $datatype), $datavalue)) {
//unpair the value
unset($this->schema[$k]->Value);
//set the error
throw new Exception(sprintf(t("%s is not a valid %2s"), $k, $datatype));
//throw an exception if in strict mode
if ($strict) {
break;
}
}
}
}
}
//did we have any validation errors
return (count($this->getErrors()) > 0) ? false : true;
} | php | final public function bindData($data, $ignore = array(), $strict = true, $filter = array())
{
$validate = $this->validator;
if (!is_object($data) && !is_array($data)) {
throw new Exception(t("Data must be either an object or array"));
return false;
}
$dataArray = is_array($data);
$dataObject = is_object($data);
foreach ($this->schema as $k => $v) {
// internal attributes of an object are ignored
if (!in_array($k, $ignore)) {
if ($dataArray && isset($data[$k])) {
//If $data[k] is an array?
$this->schema[$k]->Value = $data[$k];
} else if ($dataObject && isset($data->$k)) {
$this->schema[$k]->Value = $data->$k;
}
}
//validate. if only just 1 fails, break and throw an error;
if (isset($this->schema[$k]->Validate) && isset($this->schema[$k]->Value)) {
$datatype = $this->schema[$k]->Validate;
$datavalue = $this->schema[$k]->Value;
if (method_exists($validate, $datatype)) {
if (!\call_user_func(array($validate, $datatype), $datavalue)) {
//unpair the value
unset($this->schema[$k]->Value);
//set the error
throw new Exception(sprintf(t("%s is not a valid %2s"), $k, $datatype));
//throw an exception if in strict mode
if ($strict) {
break;
}
}
}
}
}
//did we have any validation errors
return (count($this->getErrors()) > 0) ? false : true;
} | [
"final",
"public",
"function",
"bindData",
"(",
"$",
"data",
",",
"$",
"ignore",
"=",
"array",
"(",
")",
",",
"$",
"strict",
"=",
"true",
",",
"$",
"filter",
"=",
"array",
"(",
")",
")",
"{",
"$",
"validate",
"=",
"$",
"this",
"->",
"validator",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"data",
")",
"&&",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"\"Data must be either an object or array\"",
")",
")",
";",
"return",
"false",
";",
"}",
"$",
"dataArray",
"=",
"is_array",
"(",
"$",
"data",
")",
";",
"$",
"dataObject",
"=",
"is_object",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"schema",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"// internal attributes of an object are ignored",
"if",
"(",
"!",
"in_array",
"(",
"$",
"k",
",",
"$",
"ignore",
")",
")",
"{",
"if",
"(",
"$",
"dataArray",
"&&",
"isset",
"(",
"$",
"data",
"[",
"$",
"k",
"]",
")",
")",
"{",
"//If $data[k] is an array?",
"$",
"this",
"->",
"schema",
"[",
"$",
"k",
"]",
"->",
"Value",
"=",
"$",
"data",
"[",
"$",
"k",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"dataObject",
"&&",
"isset",
"(",
"$",
"data",
"->",
"$",
"k",
")",
")",
"{",
"$",
"this",
"->",
"schema",
"[",
"$",
"k",
"]",
"->",
"Value",
"=",
"$",
"data",
"->",
"$",
"k",
";",
"}",
"}",
"//validate. if only just 1 fails, break and throw an error;",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"schema",
"[",
"$",
"k",
"]",
"->",
"Validate",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"schema",
"[",
"$",
"k",
"]",
"->",
"Value",
")",
")",
"{",
"$",
"datatype",
"=",
"$",
"this",
"->",
"schema",
"[",
"$",
"k",
"]",
"->",
"Validate",
";",
"$",
"datavalue",
"=",
"$",
"this",
"->",
"schema",
"[",
"$",
"k",
"]",
"->",
"Value",
";",
"if",
"(",
"method_exists",
"(",
"$",
"validate",
",",
"$",
"datatype",
")",
")",
"{",
"if",
"(",
"!",
"\\",
"call_user_func",
"(",
"array",
"(",
"$",
"validate",
",",
"$",
"datatype",
")",
",",
"$",
"datavalue",
")",
")",
"{",
"//unpair the value",
"unset",
"(",
"$",
"this",
"->",
"schema",
"[",
"$",
"k",
"]",
"->",
"Value",
")",
";",
"//set the error",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"t",
"(",
"\"%s is not a valid %2s\"",
")",
",",
"$",
"k",
",",
"$",
"datatype",
")",
")",
";",
"//throw an exception if in strict mode",
"if",
"(",
"$",
"strict",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"//did we have any validation errors",
"return",
"(",
"count",
"(",
"$",
"this",
"->",
"getErrors",
"(",
")",
")",
">",
"0",
")",
"?",
"false",
":",
"true",
";",
"}"
] | Binds user data to the table;
@param type $data
@param type $ignore
@param type $strict
@param type $filter
@return type | [
"Binds",
"user",
"data",
"to",
"the",
"table",
";"
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Datastore/Table.php#L166-L218 |
7,492 | budkit/budkit-framework | src/Budkit/Datastore/Table.php | Table.getRowFieldValue | final public function getRowFieldValue($field)
{
//If value exists;
if (array_key_exists($field, $this->schema)) {
return $this->schema[$field]->Value;
}
return null;
} | php | final public function getRowFieldValue($field)
{
//If value exists;
if (array_key_exists($field, $this->schema)) {
return $this->schema[$field]->Value;
}
return null;
} | [
"final",
"public",
"function",
"getRowFieldValue",
"(",
"$",
"field",
")",
"{",
"//If value exists;",
"if",
"(",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"schema",
")",
")",
"{",
"return",
"$",
"this",
"->",
"schema",
"[",
"$",
"field",
"]",
"->",
"Value",
";",
"}",
"return",
"null",
";",
"}"
] | Gets the value of a field in the current ROW
@param type $field | [
"Gets",
"the",
"value",
"of",
"a",
"field",
"in",
"the",
"current",
"ROW"
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Datastore/Table.php#L256-L264 |
7,493 | budkit/budkit-framework | src/Budkit/Datastore/Table.php | Table.setRowFieldValue | final public function setRowFieldValue($field, $value)
{
//If value exists;
if (array_key_exists($field, $this->schema)) {
$this->schema[$field]->Value = $value;
return true;
}
return false;
} | php | final public function setRowFieldValue($field, $value)
{
//If value exists;
if (array_key_exists($field, $this->schema)) {
$this->schema[$field]->Value = $value;
return true;
}
return false;
} | [
"final",
"public",
"function",
"setRowFieldValue",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"//If value exists;",
"if",
"(",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"schema",
")",
")",
"{",
"$",
"this",
"->",
"schema",
"[",
"$",
"field",
"]",
"->",
"Value",
"=",
"$",
"value",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Sets a field value in the current row
@param type $field | [
"Sets",
"a",
"field",
"value",
"in",
"the",
"current",
"row"
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Datastore/Table.php#L271-L280 |
7,494 | indigophp-archive/codeception-fuel-module | fuel/fuel/packages/email/classes/email/driver/mail.php | Email_Driver_Mail._send | protected function _send()
{
$message = $this->build_message();
$return_path = ($this->config['return_path'] !== false) ? $this->config['return_path'] : $this->config['from']['email'];
if ( ! @mail(static::format_addresses($this->to), $this->subject, $message['body'], $message['header'], '-oi -f '.$return_path))
{
throw new \EmailSendingFailedException('Failed sending email');
}
return true;
} | php | protected function _send()
{
$message = $this->build_message();
$return_path = ($this->config['return_path'] !== false) ? $this->config['return_path'] : $this->config['from']['email'];
if ( ! @mail(static::format_addresses($this->to), $this->subject, $message['body'], $message['header'], '-oi -f '.$return_path))
{
throw new \EmailSendingFailedException('Failed sending email');
}
return true;
} | [
"protected",
"function",
"_send",
"(",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"build_message",
"(",
")",
";",
"$",
"return_path",
"=",
"(",
"$",
"this",
"->",
"config",
"[",
"'return_path'",
"]",
"!==",
"false",
")",
"?",
"$",
"this",
"->",
"config",
"[",
"'return_path'",
"]",
":",
"$",
"this",
"->",
"config",
"[",
"'from'",
"]",
"[",
"'email'",
"]",
";",
"if",
"(",
"!",
"@",
"mail",
"(",
"static",
"::",
"format_addresses",
"(",
"$",
"this",
"->",
"to",
")",
",",
"$",
"this",
"->",
"subject",
",",
"$",
"message",
"[",
"'body'",
"]",
",",
"$",
"message",
"[",
"'header'",
"]",
",",
"'-oi -f '",
".",
"$",
"return_path",
")",
")",
"{",
"throw",
"new",
"\\",
"EmailSendingFailedException",
"(",
"'Failed sending email'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Send the email using php's mail function.
@throws \EmailSendingFailedException Failed sending email
@return bool success boolean. | [
"Send",
"the",
"email",
"using",
"php",
"s",
"mail",
"function",
"."
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/packages/email/classes/email/driver/mail.php#L27-L36 |
7,495 | bishopb/vanilla | applications/dashboard/models/class.dbamodel.php | DBAModel.HtmlEntityDecode | public function HtmlEntityDecode($Table, $Column, $Limit = 100) {
// Construct a model to save the results.
$Model = $this->CreateModel($Table);
// Get the data to decode.
$Data = $this->SQL
->Select($Model->PrimaryKey)
->Select($Column)
->From($Table)
->Like($Column, '&%;', 'both')
->Limit($Limit)
->Get()->ResultArray();
$Result = array();
$Result['Count'] = count($Data);
$Result['Complete'] = FALSE;
$Result['Decoded'] = array();
$Result['NotDecoded'] = array();
// Loop through each row in the working set and decode the values.
foreach ($Data as $Row) {
$Value = $Row[$Column];
$DecodedValue = HtmlEntityDecode($Value);
$Item = array('From' => $Value, 'To' => $DecodedValue);
if ($Value != $DecodedValue) {
$Model->SetField($Row[$Model->PrimaryKey], $Column, $DecodedValue);
$Result['Decoded'] = $Item;
} else {
$Result['NotDecoded'] = $Item;
}
}
$Result['Complete'] = $Result['Count'] < $Limit;
return $Result;
} | php | public function HtmlEntityDecode($Table, $Column, $Limit = 100) {
// Construct a model to save the results.
$Model = $this->CreateModel($Table);
// Get the data to decode.
$Data = $this->SQL
->Select($Model->PrimaryKey)
->Select($Column)
->From($Table)
->Like($Column, '&%;', 'both')
->Limit($Limit)
->Get()->ResultArray();
$Result = array();
$Result['Count'] = count($Data);
$Result['Complete'] = FALSE;
$Result['Decoded'] = array();
$Result['NotDecoded'] = array();
// Loop through each row in the working set and decode the values.
foreach ($Data as $Row) {
$Value = $Row[$Column];
$DecodedValue = HtmlEntityDecode($Value);
$Item = array('From' => $Value, 'To' => $DecodedValue);
if ($Value != $DecodedValue) {
$Model->SetField($Row[$Model->PrimaryKey], $Column, $DecodedValue);
$Result['Decoded'] = $Item;
} else {
$Result['NotDecoded'] = $Item;
}
}
$Result['Complete'] = $Result['Count'] < $Limit;
return $Result;
} | [
"public",
"function",
"HtmlEntityDecode",
"(",
"$",
"Table",
",",
"$",
"Column",
",",
"$",
"Limit",
"=",
"100",
")",
"{",
"// Construct a model to save the results.",
"$",
"Model",
"=",
"$",
"this",
"->",
"CreateModel",
"(",
"$",
"Table",
")",
";",
"// Get the data to decode.",
"$",
"Data",
"=",
"$",
"this",
"->",
"SQL",
"->",
"Select",
"(",
"$",
"Model",
"->",
"PrimaryKey",
")",
"->",
"Select",
"(",
"$",
"Column",
")",
"->",
"From",
"(",
"$",
"Table",
")",
"->",
"Like",
"(",
"$",
"Column",
",",
"'&%;'",
",",
"'both'",
")",
"->",
"Limit",
"(",
"$",
"Limit",
")",
"->",
"Get",
"(",
")",
"->",
"ResultArray",
"(",
")",
";",
"$",
"Result",
"=",
"array",
"(",
")",
";",
"$",
"Result",
"[",
"'Count'",
"]",
"=",
"count",
"(",
"$",
"Data",
")",
";",
"$",
"Result",
"[",
"'Complete'",
"]",
"=",
"FALSE",
";",
"$",
"Result",
"[",
"'Decoded'",
"]",
"=",
"array",
"(",
")",
";",
"$",
"Result",
"[",
"'NotDecoded'",
"]",
"=",
"array",
"(",
")",
";",
"// Loop through each row in the working set and decode the values.",
"foreach",
"(",
"$",
"Data",
"as",
"$",
"Row",
")",
"{",
"$",
"Value",
"=",
"$",
"Row",
"[",
"$",
"Column",
"]",
";",
"$",
"DecodedValue",
"=",
"HtmlEntityDecode",
"(",
"$",
"Value",
")",
";",
"$",
"Item",
"=",
"array",
"(",
"'From'",
"=>",
"$",
"Value",
",",
"'To'",
"=>",
"$",
"DecodedValue",
")",
";",
"if",
"(",
"$",
"Value",
"!=",
"$",
"DecodedValue",
")",
"{",
"$",
"Model",
"->",
"SetField",
"(",
"$",
"Row",
"[",
"$",
"Model",
"->",
"PrimaryKey",
"]",
",",
"$",
"Column",
",",
"$",
"DecodedValue",
")",
";",
"$",
"Result",
"[",
"'Decoded'",
"]",
"=",
"$",
"Item",
";",
"}",
"else",
"{",
"$",
"Result",
"[",
"'NotDecoded'",
"]",
"=",
"$",
"Item",
";",
"}",
"}",
"$",
"Result",
"[",
"'Complete'",
"]",
"=",
"$",
"Result",
"[",
"'Count'",
"]",
"<",
"$",
"Limit",
";",
"return",
"$",
"Result",
";",
"}"
] | Remove html entities from a column in the database.
@param string $Table The name of the table.
@param array $Column The column to decode.
@param int $Limit The number of records to work on. | [
"Remove",
"html",
"entities",
"from",
"a",
"column",
"in",
"the",
"database",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.dbamodel.php#L105-L141 |
7,496 | bishopb/vanilla | applications/dashboard/models/class.dbamodel.php | DBAModel.PrimaryKeyRange | public function PrimaryKeyRange($Table) {
$Model = $this->CreateModel($Table);
$Data = $this->SQL
->Select($Model->PrimaryKey, 'min', 'MinValue')
->Select($Model->PrimaryKey, 'max', 'MaxValue')
->From($Table)
->Get()->FirstRow(DATASET_TYPE_ARRAY);
if ($Data)
return array($Data['MinValue'], $Data['MaxValue']);
else
return array(0, 0);
} | php | public function PrimaryKeyRange($Table) {
$Model = $this->CreateModel($Table);
$Data = $this->SQL
->Select($Model->PrimaryKey, 'min', 'MinValue')
->Select($Model->PrimaryKey, 'max', 'MaxValue')
->From($Table)
->Get()->FirstRow(DATASET_TYPE_ARRAY);
if ($Data)
return array($Data['MinValue'], $Data['MaxValue']);
else
return array(0, 0);
} | [
"public",
"function",
"PrimaryKeyRange",
"(",
"$",
"Table",
")",
"{",
"$",
"Model",
"=",
"$",
"this",
"->",
"CreateModel",
"(",
"$",
"Table",
")",
";",
"$",
"Data",
"=",
"$",
"this",
"->",
"SQL",
"->",
"Select",
"(",
"$",
"Model",
"->",
"PrimaryKey",
",",
"'min'",
",",
"'MinValue'",
")",
"->",
"Select",
"(",
"$",
"Model",
"->",
"PrimaryKey",
",",
"'max'",
",",
"'MaxValue'",
")",
"->",
"From",
"(",
"$",
"Table",
")",
"->",
"Get",
"(",
")",
"->",
"FirstRow",
"(",
"DATASET_TYPE_ARRAY",
")",
";",
"if",
"(",
"$",
"Data",
")",
"return",
"array",
"(",
"$",
"Data",
"[",
"'MinValue'",
"]",
",",
"$",
"Data",
"[",
"'MaxValue'",
"]",
")",
";",
"else",
"return",
"array",
"(",
"0",
",",
"0",
")",
";",
"}"
] | Return the min and max values of a table's primary key.
@param string $Table The name of the table to look at.
@return array An array in the form (min, max). | [
"Return",
"the",
"min",
"and",
"max",
"values",
"of",
"a",
"table",
"s",
"primary",
"key",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.dbamodel.php#L214-L227 |
7,497 | plvhx/psr7-http-message | src/ServerRequestFactory.php | ServerRequestFactory.aggregateHeaderFromServer | private static function aggregateHeaderFromServer($server = [])
{
$header = [];
if (isset($server['HTTP_HOST'])) {
$header['Host'] = $server['HTTP_HOST'];
}
if (isset($server['HTTP_USER_AGENT'])) {
$header['User-Agent'] = $server['HTTP_USER_AGENT'];
}
if (isset($server['HTTP_CONNECTION'])) {
$header['Connection'] = $server['HTTP_CONNECTION'];
}
if (isset($server['HTTP_ACCEPT_ENCODING'])) {
$header['Accept-Encoding'] = $server['HTTP_ACCEPT_ENCODING'];
}
if (isset($server['HTTP_ACCEPT_LANGUAGE'])) {
$header['Accept-Language'] = $server['HTTP_ACCEPT_LANGUAGE'];
}
if (isset($server['HTTP_CACHE_CONTROL'])) {
$header['Cache-Control'] = $server['HTTP_CACHE_CONTROL'];
}
if (isset($server['HTTP_ACCEPT'])) {
$header['Accept'] = $server['HTTP_ACCEPT'];
}
return $header;
} | php | private static function aggregateHeaderFromServer($server = [])
{
$header = [];
if (isset($server['HTTP_HOST'])) {
$header['Host'] = $server['HTTP_HOST'];
}
if (isset($server['HTTP_USER_AGENT'])) {
$header['User-Agent'] = $server['HTTP_USER_AGENT'];
}
if (isset($server['HTTP_CONNECTION'])) {
$header['Connection'] = $server['HTTP_CONNECTION'];
}
if (isset($server['HTTP_ACCEPT_ENCODING'])) {
$header['Accept-Encoding'] = $server['HTTP_ACCEPT_ENCODING'];
}
if (isset($server['HTTP_ACCEPT_LANGUAGE'])) {
$header['Accept-Language'] = $server['HTTP_ACCEPT_LANGUAGE'];
}
if (isset($server['HTTP_CACHE_CONTROL'])) {
$header['Cache-Control'] = $server['HTTP_CACHE_CONTROL'];
}
if (isset($server['HTTP_ACCEPT'])) {
$header['Accept'] = $server['HTTP_ACCEPT'];
}
return $header;
} | [
"private",
"static",
"function",
"aggregateHeaderFromServer",
"(",
"$",
"server",
"=",
"[",
"]",
")",
"{",
"$",
"header",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'HTTP_HOST'",
"]",
")",
")",
"{",
"$",
"header",
"[",
"'Host'",
"]",
"=",
"$",
"server",
"[",
"'HTTP_HOST'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
")",
"{",
"$",
"header",
"[",
"'User-Agent'",
"]",
"=",
"$",
"server",
"[",
"'HTTP_USER_AGENT'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'HTTP_CONNECTION'",
"]",
")",
")",
"{",
"$",
"header",
"[",
"'Connection'",
"]",
"=",
"$",
"server",
"[",
"'HTTP_CONNECTION'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
")",
")",
"{",
"$",
"header",
"[",
"'Accept-Encoding'",
"]",
"=",
"$",
"server",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
")",
"{",
"$",
"header",
"[",
"'Accept-Language'",
"]",
"=",
"$",
"server",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'HTTP_CACHE_CONTROL'",
"]",
")",
")",
"{",
"$",
"header",
"[",
"'Cache-Control'",
"]",
"=",
"$",
"server",
"[",
"'HTTP_CACHE_CONTROL'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'HTTP_ACCEPT'",
"]",
")",
")",
"{",
"$",
"header",
"[",
"'Accept'",
"]",
"=",
"$",
"server",
"[",
"'HTTP_ACCEPT'",
"]",
";",
"}",
"return",
"$",
"header",
";",
"}"
] | Aggregate request header information from server variables.
@param $server The server variables
@return array | [
"Aggregate",
"request",
"header",
"information",
"from",
"server",
"variables",
"."
] | d4f5ca4cc08c4e48bed596ead3b58e006ab57d6f | https://github.com/plvhx/psr7-http-message/blob/d4f5ca4cc08c4e48bed596ead3b58e006ab57d6f/src/ServerRequestFactory.php#L43-L76 |
7,498 | plvhx/psr7-http-message | src/ServerRequestFactory.php | ServerRequestFactory.aggregateHttpProtocolVersionFromServer | private static function aggregateHttpProtocolVersionFromServer($server)
{
if (!isset($server['SERVER_PROTOCOL'])) {
return null;
}
$pattern = '/^(?P<scheme>HTTP)\/(?P<protocol_version>1\.(0|1))$/';
if (!preg_match($pattern, $server['SERVER_PROTOCOL'], $q)) {
return null;
}
return $q['protocol_version'];
} | php | private static function aggregateHttpProtocolVersionFromServer($server)
{
if (!isset($server['SERVER_PROTOCOL'])) {
return null;
}
$pattern = '/^(?P<scheme>HTTP)\/(?P<protocol_version>1\.(0|1))$/';
if (!preg_match($pattern, $server['SERVER_PROTOCOL'], $q)) {
return null;
}
return $q['protocol_version'];
} | [
"private",
"static",
"function",
"aggregateHttpProtocolVersionFromServer",
"(",
"$",
"server",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"server",
"[",
"'SERVER_PROTOCOL'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"pattern",
"=",
"'/^(?P<scheme>HTTP)\\/(?P<protocol_version>1\\.(0|1))$/'",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"server",
"[",
"'SERVER_PROTOCOL'",
"]",
",",
"$",
"q",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"q",
"[",
"'protocol_version'",
"]",
";",
"}"
] | Get HTTP protocol version from server variables.
@param $server The server variables.
@return string | [
"Get",
"HTTP",
"protocol",
"version",
"from",
"server",
"variables",
"."
] | d4f5ca4cc08c4e48bed596ead3b58e006ab57d6f | https://github.com/plvhx/psr7-http-message/blob/d4f5ca4cc08c4e48bed596ead3b58e006ab57d6f/src/ServerRequestFactory.php#L84-L97 |
7,499 | plvhx/psr7-http-message | src/ServerRequestFactory.php | ServerRequestFactory.aggregateUriFromServer | private static function aggregateUriFromServer($server)
{
$uri = new Uri();
$scheme = 'http';
$uri = $uri->withScheme($scheme);
if (isset($server['SERVER_NAME'])) {
$uri = $uri->withHost($server['SERVER_NAME']);
}
if (isset($server['SERVER_PORT'])) {
$uri = $uri->withPort((int)$server['SERVER_PORT']);
}
if (isset($server['REQUEST_URI'])) {
$q = explode('?', $server['REQUEST_URI']);
if (isset($q[0])) {
$uri = $uri->withPath($q[0]);
}
}
if (isset($server['QUERY_STRING'])) {
$uri = $uri->withQuery($server['QUERY_STRING']);
}
return $uri;
} | php | private static function aggregateUriFromServer($server)
{
$uri = new Uri();
$scheme = 'http';
$uri = $uri->withScheme($scheme);
if (isset($server['SERVER_NAME'])) {
$uri = $uri->withHost($server['SERVER_NAME']);
}
if (isset($server['SERVER_PORT'])) {
$uri = $uri->withPort((int)$server['SERVER_PORT']);
}
if (isset($server['REQUEST_URI'])) {
$q = explode('?', $server['REQUEST_URI']);
if (isset($q[0])) {
$uri = $uri->withPath($q[0]);
}
}
if (isset($server['QUERY_STRING'])) {
$uri = $uri->withQuery($server['QUERY_STRING']);
}
return $uri;
} | [
"private",
"static",
"function",
"aggregateUriFromServer",
"(",
"$",
"server",
")",
"{",
"$",
"uri",
"=",
"new",
"Uri",
"(",
")",
";",
"$",
"scheme",
"=",
"'http'",
";",
"$",
"uri",
"=",
"$",
"uri",
"->",
"withScheme",
"(",
"$",
"scheme",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'SERVER_NAME'",
"]",
")",
")",
"{",
"$",
"uri",
"=",
"$",
"uri",
"->",
"withHost",
"(",
"$",
"server",
"[",
"'SERVER_NAME'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'SERVER_PORT'",
"]",
")",
")",
"{",
"$",
"uri",
"=",
"$",
"uri",
"->",
"withPort",
"(",
"(",
"int",
")",
"$",
"server",
"[",
"'SERVER_PORT'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'REQUEST_URI'",
"]",
")",
")",
"{",
"$",
"q",
"=",
"explode",
"(",
"'?'",
",",
"$",
"server",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"q",
"[",
"0",
"]",
")",
")",
"{",
"$",
"uri",
"=",
"$",
"uri",
"->",
"withPath",
"(",
"$",
"q",
"[",
"0",
"]",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'QUERY_STRING'",
"]",
")",
")",
"{",
"$",
"uri",
"=",
"$",
"uri",
"->",
"withQuery",
"(",
"$",
"server",
"[",
"'QUERY_STRING'",
"]",
")",
";",
"}",
"return",
"$",
"uri",
";",
"}"
] | Aggregate URI component from server variables.
@param $server The server variables.
@return UriInterface | [
"Aggregate",
"URI",
"component",
"from",
"server",
"variables",
"."
] | d4f5ca4cc08c4e48bed596ead3b58e006ab57d6f | https://github.com/plvhx/psr7-http-message/blob/d4f5ca4cc08c4e48bed596ead3b58e006ab57d6f/src/ServerRequestFactory.php#L105-L133 |
Subsets and Splits