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
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
224,900
|
pdeans/http
|
src/Builders/ResponseBuilder.php
|
ResponseBuilder.addHeader
|
public function addHeader($header_line)
{
$header_parts = explode(':', $header_line, 2);
if (count($header_parts) !== 2) {
throw new InvalidArgumentException("'$header_line' is not a valid HTTP header line");
}
$header_name = trim($header_parts[0]);
$header_value = trim($header_parts[1]);
if ($this->response->hasHeader($header_name)) {
$this->response = $this->response->withAddedHeader($header_name, $header_value);
}
else {
$this->response = $this->response->withHeader($header_name, $header_value);
}
return $this;
}
|
php
|
public function addHeader($header_line)
{
$header_parts = explode(':', $header_line, 2);
if (count($header_parts) !== 2) {
throw new InvalidArgumentException("'$header_line' is not a valid HTTP header line");
}
$header_name = trim($header_parts[0]);
$header_value = trim($header_parts[1]);
if ($this->response->hasHeader($header_name)) {
$this->response = $this->response->withAddedHeader($header_name, $header_value);
}
else {
$this->response = $this->response->withHeader($header_name, $header_value);
}
return $this;
}
|
[
"public",
"function",
"addHeader",
"(",
"$",
"header_line",
")",
"{",
"$",
"header_parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"header_line",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"header_parts",
")",
"!==",
"2",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"'$header_line' is not a valid HTTP header line\"",
")",
";",
"}",
"$",
"header_name",
"=",
"trim",
"(",
"$",
"header_parts",
"[",
"0",
"]",
")",
";",
"$",
"header_value",
"=",
"trim",
"(",
"$",
"header_parts",
"[",
"1",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"response",
"->",
"hasHeader",
"(",
"$",
"header_name",
")",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"$",
"this",
"->",
"response",
"->",
"withAddedHeader",
"(",
"$",
"header_name",
",",
"$",
"header_value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"response",
"=",
"$",
"this",
"->",
"response",
"->",
"withHeader",
"(",
"$",
"header_name",
",",
"$",
"header_value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add response header from header line string
@param string $header_line Response header line string
@return \pdeans\Http\Builders\ResponseBuilder $this
@throws \InvalidArgumentException Invalid header line argument
|
[
"Add",
"response",
"header",
"from",
"header",
"line",
"string"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Builders/ResponseBuilder.php#L67-L86
|
224,901
|
pdeans/http
|
src/Builders/ResponseBuilder.php
|
ResponseBuilder.setHeadersFromArray
|
public function setHeadersFromArray(array $headers)
{
$status = array_shift($headers);
$this->setStatus($status);
foreach ($headers as $header) {
$header_line = trim($header);
if ($header_line === '') {
continue;
}
$this->addHeader($header_line);
}
return $this;
}
|
php
|
public function setHeadersFromArray(array $headers)
{
$status = array_shift($headers);
$this->setStatus($status);
foreach ($headers as $header) {
$header_line = trim($header);
if ($header_line === '') {
continue;
}
$this->addHeader($header_line);
}
return $this;
}
|
[
"public",
"function",
"setHeadersFromArray",
"(",
"array",
"$",
"headers",
")",
"{",
"$",
"status",
"=",
"array_shift",
"(",
"$",
"headers",
")",
";",
"$",
"this",
"->",
"setStatus",
"(",
"$",
"status",
")",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"header",
")",
"{",
"$",
"header_line",
"=",
"trim",
"(",
"$",
"header",
")",
";",
"if",
"(",
"$",
"header_line",
"===",
"''",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"addHeader",
"(",
"$",
"header_line",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set response headers from header line array
@param array $headers Array of header lines
@return \pdeans\Http\Builders\ResponseBuilder $this
@throws \InvalidArgumentException Invalid status code argument value
@throws \UnexpectedValueException Invalid header value(s)
|
[
"Set",
"response",
"headers",
"from",
"header",
"line",
"array"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Builders/ResponseBuilder.php#L96-L113
|
224,902
|
pdeans/http
|
src/Builders/ResponseBuilder.php
|
ResponseBuilder.setHeadersFromString
|
public function setHeadersFromString($headers)
{
if (is_string($headers) || (is_object($headers) && method_exists($headers, '__toString'))) {
$this->setHeadersFromArray(explode("\r\n", $headers));
return $this;
}
throw new InvalidArgumentException(
sprintf(
'%s expects parameter 1 to be a string, %s given',
__METHOD__,
is_object($headers) ? get_class($headers) : gettype($headers)
)
);
}
|
php
|
public function setHeadersFromString($headers)
{
if (is_string($headers) || (is_object($headers) && method_exists($headers, '__toString'))) {
$this->setHeadersFromArray(explode("\r\n", $headers));
return $this;
}
throw new InvalidArgumentException(
sprintf(
'%s expects parameter 1 to be a string, %s given',
__METHOD__,
is_object($headers) ? get_class($headers) : gettype($headers)
)
);
}
|
[
"public",
"function",
"setHeadersFromString",
"(",
"$",
"headers",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"headers",
")",
"||",
"(",
"is_object",
"(",
"$",
"headers",
")",
"&&",
"method_exists",
"(",
"$",
"headers",
",",
"'__toString'",
")",
")",
")",
"{",
"$",
"this",
"->",
"setHeadersFromArray",
"(",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"headers",
")",
")",
";",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s expects parameter 1 to be a string, %s given'",
",",
"__METHOD__",
",",
"is_object",
"(",
"$",
"headers",
")",
"?",
"get_class",
"(",
"$",
"headers",
")",
":",
"gettype",
"(",
"$",
"headers",
")",
")",
")",
";",
"}"
] |
Set response headers from header line string
@param string $headers String of header lines
@return \pdeans\Http\Builders\ResponseBuilder $this
@throws \InvalidArgumentException Header string is not a string on object with __toString()
@throws \UnexpectedValueException Invalid header value(s)
|
[
"Set",
"response",
"headers",
"from",
"header",
"line",
"string"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Builders/ResponseBuilder.php#L123-L138
|
224,903
|
pdeans/http
|
src/Builders/ResponseBuilder.php
|
ResponseBuilder.setStatus
|
public function setStatus($status_line)
{
$status_parts = explode(' ', $status_line, 3);
$parts_count = count($status_parts);
if ($parts_count < 2 || strpos(strtoupper($status_parts[0]), 'HTTP/') !== 0) {
throw new InvalidArgumentException("'$status_line' is not a valid HTTP status line");
}
$reason_phrase = ($parts_count > 2 ? $status_parts[2] : '');
$this->response = $this->response
->withStatus((int)$status_parts[1], $reason_phrase)
->withProtocolVersion(substr($status_parts[0], 5));
return $this;
}
|
php
|
public function setStatus($status_line)
{
$status_parts = explode(' ', $status_line, 3);
$parts_count = count($status_parts);
if ($parts_count < 2 || strpos(strtoupper($status_parts[0]), 'HTTP/') !== 0) {
throw new InvalidArgumentException("'$status_line' is not a valid HTTP status line");
}
$reason_phrase = ($parts_count > 2 ? $status_parts[2] : '');
$this->response = $this->response
->withStatus((int)$status_parts[1], $reason_phrase)
->withProtocolVersion(substr($status_parts[0], 5));
return $this;
}
|
[
"public",
"function",
"setStatus",
"(",
"$",
"status_line",
")",
"{",
"$",
"status_parts",
"=",
"explode",
"(",
"' '",
",",
"$",
"status_line",
",",
"3",
")",
";",
"$",
"parts_count",
"=",
"count",
"(",
"$",
"status_parts",
")",
";",
"if",
"(",
"$",
"parts_count",
"<",
"2",
"||",
"strpos",
"(",
"strtoupper",
"(",
"$",
"status_parts",
"[",
"0",
"]",
")",
",",
"'HTTP/'",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"'$status_line' is not a valid HTTP status line\"",
")",
";",
"}",
"$",
"reason_phrase",
"=",
"(",
"$",
"parts_count",
">",
"2",
"?",
"$",
"status_parts",
"[",
"2",
"]",
":",
"''",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"this",
"->",
"response",
"->",
"withStatus",
"(",
"(",
"int",
")",
"$",
"status_parts",
"[",
"1",
"]",
",",
"$",
"reason_phrase",
")",
"->",
"withProtocolVersion",
"(",
"substr",
"(",
"$",
"status_parts",
"[",
"0",
"]",
",",
"5",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set reponse status
@param string $status_line Response status line string
@return \pdeans\Http\Builders\ResponseBuilder $this
@throws \InvalidArgumentException Invalid status line argument
|
[
"Set",
"reponse",
"status"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Builders/ResponseBuilder.php#L151-L167
|
224,904
|
seancheung/laravel-vuforia
|
src/VuforiaWebService.php
|
VuforiaWebService.updateTarget
|
function updateTarget($id, $target) {
if(is_array($target)) {
$target = new Target($target);
}
else if(!($target instanceof Target)) {
throw new Exception("Invalid target type. Only array and VuforiaWebService/Target are supported");
}
if(!empty($target->name)) {
if(!empty($this->namingRule) && !preg_match($this->namingRule, $target->name)) {
throw new Exception("Invalid naming");
}
}
if(is_numeric($target->width)) {
if($target->width <= 0) {
throw new Exception("Target width should be a number");
}
}
if(!empty($target->image) && is_numeric($this->maxImageSize) && strlen($target->image) > $this->maxImageSize) {
throw new Exception("Image is too large");
}
if(!empty($target->metadata) && is_numeric($this->maxMetaSize) && strlen($target->metadata) > $this->maxMetaSize) {
throw new Exception("Metadata is too large");
}
return $this->makeRequest(
$this->targets . "/$id",
HTTP_Request2::METHOD_PUT,
json_encode($target),
['Content-Type' => 'application/json']);
}
|
php
|
function updateTarget($id, $target) {
if(is_array($target)) {
$target = new Target($target);
}
else if(!($target instanceof Target)) {
throw new Exception("Invalid target type. Only array and VuforiaWebService/Target are supported");
}
if(!empty($target->name)) {
if(!empty($this->namingRule) && !preg_match($this->namingRule, $target->name)) {
throw new Exception("Invalid naming");
}
}
if(is_numeric($target->width)) {
if($target->width <= 0) {
throw new Exception("Target width should be a number");
}
}
if(!empty($target->image) && is_numeric($this->maxImageSize) && strlen($target->image) > $this->maxImageSize) {
throw new Exception("Image is too large");
}
if(!empty($target->metadata) && is_numeric($this->maxMetaSize) && strlen($target->metadata) > $this->maxMetaSize) {
throw new Exception("Metadata is too large");
}
return $this->makeRequest(
$this->targets . "/$id",
HTTP_Request2::METHOD_PUT,
json_encode($target),
['Content-Type' => 'application/json']);
}
|
[
"function",
"updateTarget",
"(",
"$",
"id",
",",
"$",
"target",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"target",
")",
")",
"{",
"$",
"target",
"=",
"new",
"Target",
"(",
"$",
"target",
")",
";",
"}",
"else",
"if",
"(",
"!",
"(",
"$",
"target",
"instanceof",
"Target",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Invalid target type. Only array and VuforiaWebService/Target are supported\"",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"target",
"->",
"name",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"namingRule",
")",
"&&",
"!",
"preg_match",
"(",
"$",
"this",
"->",
"namingRule",
",",
"$",
"target",
"->",
"name",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Invalid naming\"",
")",
";",
"}",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"target",
"->",
"width",
")",
")",
"{",
"if",
"(",
"$",
"target",
"->",
"width",
"<=",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Target width should be a number\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"target",
"->",
"image",
")",
"&&",
"is_numeric",
"(",
"$",
"this",
"->",
"maxImageSize",
")",
"&&",
"strlen",
"(",
"$",
"target",
"->",
"image",
")",
">",
"$",
"this",
"->",
"maxImageSize",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Image is too large\"",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"target",
"->",
"metadata",
")",
"&&",
"is_numeric",
"(",
"$",
"this",
"->",
"maxMetaSize",
")",
"&&",
"strlen",
"(",
"$",
"target",
"->",
"metadata",
")",
">",
"$",
"this",
"->",
"maxMetaSize",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Metadata is too large\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"makeRequest",
"(",
"$",
"this",
"->",
"targets",
".",
"\"/$id\"",
",",
"HTTP_Request2",
"::",
"METHOD_PUT",
",",
"json_encode",
"(",
"$",
"target",
")",
",",
"[",
"'Content-Type'",
"=>",
"'application/json'",
"]",
")",
";",
"}"
] |
Update target with info by ID
@param string $id Target Unique ID
@param mixed $target Target to update from
@return array
@example ['status' => 200, 'body' => "--JSON--"]
@example ['status' => 400, 'body' => "--ERROR--"]
@example ['status' => 500, 'body' => "--EXCEPTION--"]
|
[
"Update",
"target",
"with",
"info",
"by",
"ID"
] |
cecc57a457a25b7b5fa4ad39fe14b15b7389d136
|
https://github.com/seancheung/laravel-vuforia/blob/cecc57a457a25b7b5fa4ad39fe14b15b7389d136/src/VuforiaWebService.php#L152-L185
|
224,905
|
ongr-io/TranslationsBundle
|
Service/TranslationManager.php
|
TranslationManager.edit
|
public function edit($id, Request $request)
{
$content = json_decode($request->getContent(), true);
if (empty($content)) {
return;
}
$document = $this->get($id);
if (isset($content['messages'])) {
$this->updateMessages($document, $content['messages']);
unset($content['messages']);
}
try {
foreach ($content as $key => $value) {
$document->{'set'.ucfirst($key)}($value);
}
$document->setUpdatedAt(new \DateTime());
} catch (\Exception $e) {
throw new \LogicException('Illegal variable provided for translation');
}
$this->repository->getManager()->persist($document);
$this->repository->getManager()->commit();
}
|
php
|
public function edit($id, Request $request)
{
$content = json_decode($request->getContent(), true);
if (empty($content)) {
return;
}
$document = $this->get($id);
if (isset($content['messages'])) {
$this->updateMessages($document, $content['messages']);
unset($content['messages']);
}
try {
foreach ($content as $key => $value) {
$document->{'set'.ucfirst($key)}($value);
}
$document->setUpdatedAt(new \DateTime());
} catch (\Exception $e) {
throw new \LogicException('Illegal variable provided for translation');
}
$this->repository->getManager()->persist($document);
$this->repository->getManager()->commit();
}
|
[
"public",
"function",
"edit",
"(",
"$",
"id",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"content",
"=",
"json_decode",
"(",
"$",
"request",
"->",
"getContent",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"content",
")",
")",
"{",
"return",
";",
"}",
"$",
"document",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"content",
"[",
"'messages'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"updateMessages",
"(",
"$",
"document",
",",
"$",
"content",
"[",
"'messages'",
"]",
")",
";",
"unset",
"(",
"$",
"content",
"[",
"'messages'",
"]",
")",
";",
"}",
"try",
"{",
"foreach",
"(",
"$",
"content",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"document",
"->",
"{",
"'set'",
".",
"ucfirst",
"(",
"$",
"key",
")",
"}",
"(",
"$",
"value",
")",
";",
"}",
"$",
"document",
"->",
"setUpdatedAt",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Illegal variable provided for translation'",
")",
";",
"}",
"$",
"this",
"->",
"repository",
"->",
"getManager",
"(",
")",
"->",
"persist",
"(",
"$",
"document",
")",
";",
"$",
"this",
"->",
"repository",
"->",
"getManager",
"(",
")",
"->",
"commit",
"(",
")",
";",
"}"
] |
Edits object from translation.
@param string $id
@param Request $request Http request object.
|
[
"Edits",
"object",
"from",
"translation",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/TranslationManager.php#L64-L91
|
224,906
|
ongr-io/TranslationsBundle
|
Service/TranslationManager.php
|
TranslationManager.getAll
|
public function getAll(array $filters = null)
{
$search = $this->repository->createSearch();
$search->addQuery(new MatchAllQuery());
$search->setScroll('2m');
if ($filters) {
foreach ($filters as $field => $value) {
$search->addQuery(new TermsQuery($field, $value));
}
}
return $this->repository->findDocuments($search);
}
|
php
|
public function getAll(array $filters = null)
{
$search = $this->repository->createSearch();
$search->addQuery(new MatchAllQuery());
$search->setScroll('2m');
if ($filters) {
foreach ($filters as $field => $value) {
$search->addQuery(new TermsQuery($field, $value));
}
}
return $this->repository->findDocuments($search);
}
|
[
"public",
"function",
"getAll",
"(",
"array",
"$",
"filters",
"=",
"null",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"repository",
"->",
"createSearch",
"(",
")",
";",
"$",
"search",
"->",
"addQuery",
"(",
"new",
"MatchAllQuery",
"(",
")",
")",
";",
"$",
"search",
"->",
"setScroll",
"(",
"'2m'",
")",
";",
"if",
"(",
"$",
"filters",
")",
"{",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"search",
"->",
"addQuery",
"(",
"new",
"TermsQuery",
"(",
"$",
"field",
",",
"$",
"value",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"repository",
"->",
"findDocuments",
"(",
"$",
"search",
")",
";",
"}"
] |
Returns all translations if filters are not specified
@param array $filters An array with specified limitations for results
@return DocumentIterator
|
[
"Returns",
"all",
"translations",
"if",
"filters",
"are",
"not",
"specified"
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/TranslationManager.php#L128-L141
|
224,907
|
ongr-io/TranslationsBundle
|
Service/TranslationManager.php
|
TranslationManager.getGroupTypeInfo
|
private function getGroupTypeInfo($type)
{
$search = $this->repository->createSearch();
$search->addAggregation(new TermsAggregation($type, $type));
$result = $this->repository->findDocuments($search);
$aggregation = $result->getAggregation($type);
$items = [];
foreach ($aggregation as $item) {
$items[] = $item['key'];
}
return $items;
}
|
php
|
private function getGroupTypeInfo($type)
{
$search = $this->repository->createSearch();
$search->addAggregation(new TermsAggregation($type, $type));
$result = $this->repository->findDocuments($search);
$aggregation = $result->getAggregation($type);
$items = [];
foreach ($aggregation as $item) {
$items[] = $item['key'];
}
return $items;
}
|
[
"private",
"function",
"getGroupTypeInfo",
"(",
"$",
"type",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"repository",
"->",
"createSearch",
"(",
")",
";",
"$",
"search",
"->",
"addAggregation",
"(",
"new",
"TermsAggregation",
"(",
"$",
"type",
",",
"$",
"type",
")",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"repository",
"->",
"findDocuments",
"(",
"$",
"search",
")",
";",
"$",
"aggregation",
"=",
"$",
"result",
"->",
"getAggregation",
"(",
"$",
"type",
")",
";",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aggregation",
"as",
"$",
"item",
")",
"{",
"$",
"items",
"[",
"]",
"=",
"$",
"item",
"[",
"'key'",
"]",
";",
"}",
"return",
"$",
"items",
";",
"}"
] |
Returns a list of available tags or domains.
@param string $type
@return array
|
[
"Returns",
"a",
"list",
"of",
"available",
"tags",
"or",
"domains",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/TranslationManager.php#L211-L224
|
224,908
|
valga/fbns-react
|
src/Lite.php
|
Lite.establishConnection
|
private function establishConnection($host, $port, Connection $connection, $timeout)
{
$this->logger->info(sprintf('Connecting to %s:%d...', $host, $port));
return $this->client->connect($host, $port, $connection, $timeout);
}
|
php
|
private function establishConnection($host, $port, Connection $connection, $timeout)
{
$this->logger->info(sprintf('Connecting to %s:%d...', $host, $port));
return $this->client->connect($host, $port, $connection, $timeout);
}
|
[
"private",
"function",
"establishConnection",
"(",
"$",
"host",
",",
"$",
"port",
",",
"Connection",
"$",
"connection",
",",
"$",
"timeout",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"sprintf",
"(",
"'Connecting to %s:%d...'",
",",
"$",
"host",
",",
"$",
"port",
")",
")",
";",
"return",
"$",
"this",
"->",
"client",
"->",
"connect",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"connection",
",",
"$",
"timeout",
")",
";",
"}"
] |
Establishes a connection to the FBNS server.
@param string $host
@param int $port
@param Connection $connection
@param int $timeout
@return PromiseInterface
|
[
"Establishes",
"a",
"connection",
"to",
"the",
"FBNS",
"server",
"."
] |
4bbf513a8ffed7e0c9ca10776033d34515bb8b37
|
https://github.com/valga/fbns-react/blob/4bbf513a8ffed7e0c9ca10776033d34515bb8b37/src/Lite.php#L235-L240
|
224,909
|
valga/fbns-react
|
src/Lite.php
|
Lite.connect
|
public function connect($host, $port, Connection $connection, $timeout = 5)
{
$deferred = new Deferred();
$this->disconnect()
->then(function () use ($deferred, $host, $port, $connection, $timeout) {
$this->establishConnection($host, $port, $connection, $timeout)
->then(function () use ($deferred) {
$deferred->resolve($this);
})
->otherwise(function (\Exception $error) use ($deferred) {
$deferred->reject($error);
});
})
->otherwise(function () use ($deferred) {
$deferred->reject($this);
});
return $deferred->promise();
}
|
php
|
public function connect($host, $port, Connection $connection, $timeout = 5)
{
$deferred = new Deferred();
$this->disconnect()
->then(function () use ($deferred, $host, $port, $connection, $timeout) {
$this->establishConnection($host, $port, $connection, $timeout)
->then(function () use ($deferred) {
$deferred->resolve($this);
})
->otherwise(function (\Exception $error) use ($deferred) {
$deferred->reject($error);
});
})
->otherwise(function () use ($deferred) {
$deferred->reject($this);
});
return $deferred->promise();
}
|
[
"public",
"function",
"connect",
"(",
"$",
"host",
",",
"$",
"port",
",",
"Connection",
"$",
"connection",
",",
"$",
"timeout",
"=",
"5",
")",
"{",
"$",
"deferred",
"=",
"new",
"Deferred",
"(",
")",
";",
"$",
"this",
"->",
"disconnect",
"(",
")",
"->",
"then",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"deferred",
",",
"$",
"host",
",",
"$",
"port",
",",
"$",
"connection",
",",
"$",
"timeout",
")",
"{",
"$",
"this",
"->",
"establishConnection",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"connection",
",",
"$",
"timeout",
")",
"->",
"then",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"deferred",
")",
"{",
"$",
"deferred",
"->",
"resolve",
"(",
"$",
"this",
")",
";",
"}",
")",
"->",
"otherwise",
"(",
"function",
"(",
"\\",
"Exception",
"$",
"error",
")",
"use",
"(",
"$",
"deferred",
")",
"{",
"$",
"deferred",
"->",
"reject",
"(",
"$",
"error",
")",
";",
"}",
")",
";",
"}",
")",
"->",
"otherwise",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"deferred",
")",
"{",
"$",
"deferred",
"->",
"reject",
"(",
"$",
"this",
")",
";",
"}",
")",
";",
"return",
"$",
"deferred",
"->",
"promise",
"(",
")",
";",
"}"
] |
Connects to a FBNS server.
@param string $host
@param int $port
@param Connection $connection
@param int $timeout
@return PromiseInterface
|
[
"Connects",
"to",
"a",
"FBNS",
"server",
"."
] |
4bbf513a8ffed7e0c9ca10776033d34515bb8b37
|
https://github.com/valga/fbns-react/blob/4bbf513a8ffed7e0c9ca10776033d34515bb8b37/src/Lite.php#L252-L270
|
224,910
|
valga/fbns-react
|
src/Lite.php
|
Lite.mapTopic
|
private function mapTopic($topic)
{
if (array_key_exists($topic, self::TOPIC_TO_ID_ENUM)) {
$result = self::TOPIC_TO_ID_ENUM[$topic];
$this->logger->debug(sprintf('Topic "%s" has been mapped to "%s".', $topic, $result));
} else {
$result = $topic;
$this->logger->debug(sprintf('Topic "%s" does not exist in enum.', $topic));
}
return $result;
}
|
php
|
private function mapTopic($topic)
{
if (array_key_exists($topic, self::TOPIC_TO_ID_ENUM)) {
$result = self::TOPIC_TO_ID_ENUM[$topic];
$this->logger->debug(sprintf('Topic "%s" has been mapped to "%s".', $topic, $result));
} else {
$result = $topic;
$this->logger->debug(sprintf('Topic "%s" does not exist in enum.', $topic));
}
return $result;
}
|
[
"private",
"function",
"mapTopic",
"(",
"$",
"topic",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"topic",
",",
"self",
"::",
"TOPIC_TO_ID_ENUM",
")",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"TOPIC_TO_ID_ENUM",
"[",
"$",
"topic",
"]",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"'Topic \"%s\" has been mapped to \"%s\".'",
",",
"$",
"topic",
",",
"$",
"result",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"topic",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"'Topic \"%s\" does not exist in enum.'",
",",
"$",
"topic",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Maps human readable topic to its ID.
@param string $topic
@return string
|
[
"Maps",
"human",
"readable",
"topic",
"to",
"its",
"ID",
"."
] |
4bbf513a8ffed7e0c9ca10776033d34515bb8b37
|
https://github.com/valga/fbns-react/blob/4bbf513a8ffed7e0c9ca10776033d34515bb8b37/src/Lite.php#L300-L311
|
224,911
|
valga/fbns-react
|
src/Lite.php
|
Lite.unmapTopic
|
private function unmapTopic($topic)
{
if (array_key_exists($topic, self::ID_TO_TOPIC_ENUM)) {
$result = self::ID_TO_TOPIC_ENUM[$topic];
$this->logger->debug(sprintf('Topic ID "%s" has been unmapped to "%s".', $topic, $result));
} else {
$result = $topic;
$this->logger->debug(sprintf('Topic ID "%s" does not exist in enum.', $topic));
}
return $result;
}
|
php
|
private function unmapTopic($topic)
{
if (array_key_exists($topic, self::ID_TO_TOPIC_ENUM)) {
$result = self::ID_TO_TOPIC_ENUM[$topic];
$this->logger->debug(sprintf('Topic ID "%s" has been unmapped to "%s".', $topic, $result));
} else {
$result = $topic;
$this->logger->debug(sprintf('Topic ID "%s" does not exist in enum.', $topic));
}
return $result;
}
|
[
"private",
"function",
"unmapTopic",
"(",
"$",
"topic",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"topic",
",",
"self",
"::",
"ID_TO_TOPIC_ENUM",
")",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"ID_TO_TOPIC_ENUM",
"[",
"$",
"topic",
"]",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"'Topic ID \"%s\" has been unmapped to \"%s\".'",
",",
"$",
"topic",
",",
"$",
"result",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"topic",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"sprintf",
"(",
"'Topic ID \"%s\" does not exist in enum.'",
",",
"$",
"topic",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Maps topic ID to human readable name.
@param string $topic
@return string
|
[
"Maps",
"topic",
"ID",
"to",
"human",
"readable",
"name",
"."
] |
4bbf513a8ffed7e0c9ca10776033d34515bb8b37
|
https://github.com/valga/fbns-react/blob/4bbf513a8ffed7e0c9ca10776033d34515bb8b37/src/Lite.php#L320-L331
|
224,912
|
valga/fbns-react
|
src/Lite.php
|
Lite.register
|
public function register($packageName, $appId)
{
$this->logger->info(sprintf('Registering application "%s" (%s).', $packageName, $appId));
$message = json_encode([
'pkg_name' => (string) $packageName,
'appid' => (string) $appId,
]);
return $this->publish(self::REG_REQ_TOPIC, $message, self::QOS_LEVEL);
}
|
php
|
public function register($packageName, $appId)
{
$this->logger->info(sprintf('Registering application "%s" (%s).', $packageName, $appId));
$message = json_encode([
'pkg_name' => (string) $packageName,
'appid' => (string) $appId,
]);
return $this->publish(self::REG_REQ_TOPIC, $message, self::QOS_LEVEL);
}
|
[
"public",
"function",
"register",
"(",
"$",
"packageName",
",",
"$",
"appId",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"sprintf",
"(",
"'Registering application \"%s\" (%s).'",
",",
"$",
"packageName",
",",
"$",
"appId",
")",
")",
";",
"$",
"message",
"=",
"json_encode",
"(",
"[",
"'pkg_name'",
"=>",
"(",
"string",
")",
"$",
"packageName",
",",
"'appid'",
"=>",
"(",
"string",
")",
"$",
"appId",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"publish",
"(",
"self",
"::",
"REG_REQ_TOPIC",
",",
"$",
"message",
",",
"self",
"::",
"QOS_LEVEL",
")",
";",
"}"
] |
Registers an application.
@param string $packageName
@param string|int $appId
@return PromiseInterface
|
[
"Registers",
"an",
"application",
"."
] |
4bbf513a8ffed7e0c9ca10776033d34515bb8b37
|
https://github.com/valga/fbns-react/blob/4bbf513a8ffed7e0c9ca10776033d34515bb8b37/src/Lite.php#L359-L368
|
224,913
|
theofidry/LoopBackApiBundle
|
src/Filter/WhereFilter.php
|
WhereFilter.handleFilter
|
private function handleFilter(
QueryBuilder $queryBuilder,
ClassMetadata $resourceMetadata,
array $aliases,
array $associationsMetadata,
$property,
$value,
$parameter = null
) {
$queryExpr = [];
/*
* simple (case 1):
* $property = name
*
* relation (case 2):
* $property = relatedDummy_name
* $property = relatedDymmy_id
* $property = relatedDummy_user_id
* $property = relatedDummy_user_name
*/
if (false !== strpos($property, '.')) {
$explodedProperty = explode('.', $property);
} else {
$explodedProperty = explode('_', $property);
}
// we are in case 2
$property = array_pop($explodedProperty);
$alias = $this->getResourceAliasForProperty($aliases, $explodedProperty);
$aliasMetadata = $this->getAssociationMetadataForProperty(
$resourceMetadata,
$associationsMetadata,
$explodedProperty
);
if (true === $aliasMetadata->hasField($property)) {
// Entity has the property
if (is_array($value)) {
foreach ($value as $operator => $operand) {
// Case where there is an operator
$queryExpr[] = $this->handleOperator(
$queryBuilder,
$alias,
$aliasMetadata,
$property,
$operator,
$operand,
$parameter
);
}
} else {
// Simple where
$value = $this->normalizeValue($aliasMetadata, $property, $value);
if (null === $value) {
$queryExpr[] = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $property));
} else {
if (null === $parameter) {
$parameter = $property;
}
$queryExpr[] = $queryBuilder->expr()->eq(
sprintf('%s.%s', $alias, $property),
sprintf(':%s', $parameter)
);
$queryBuilder->setParameter($parameter, $value);
}
}
}
return $queryExpr;
}
|
php
|
private function handleFilter(
QueryBuilder $queryBuilder,
ClassMetadata $resourceMetadata,
array $aliases,
array $associationsMetadata,
$property,
$value,
$parameter = null
) {
$queryExpr = [];
/*
* simple (case 1):
* $property = name
*
* relation (case 2):
* $property = relatedDummy_name
* $property = relatedDymmy_id
* $property = relatedDummy_user_id
* $property = relatedDummy_user_name
*/
if (false !== strpos($property, '.')) {
$explodedProperty = explode('.', $property);
} else {
$explodedProperty = explode('_', $property);
}
// we are in case 2
$property = array_pop($explodedProperty);
$alias = $this->getResourceAliasForProperty($aliases, $explodedProperty);
$aliasMetadata = $this->getAssociationMetadataForProperty(
$resourceMetadata,
$associationsMetadata,
$explodedProperty
);
if (true === $aliasMetadata->hasField($property)) {
// Entity has the property
if (is_array($value)) {
foreach ($value as $operator => $operand) {
// Case where there is an operator
$queryExpr[] = $this->handleOperator(
$queryBuilder,
$alias,
$aliasMetadata,
$property,
$operator,
$operand,
$parameter
);
}
} else {
// Simple where
$value = $this->normalizeValue($aliasMetadata, $property, $value);
if (null === $value) {
$queryExpr[] = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $property));
} else {
if (null === $parameter) {
$parameter = $property;
}
$queryExpr[] = $queryBuilder->expr()->eq(
sprintf('%s.%s', $alias, $property),
sprintf(':%s', $parameter)
);
$queryBuilder->setParameter($parameter, $value);
}
}
}
return $queryExpr;
}
|
[
"private",
"function",
"handleFilter",
"(",
"QueryBuilder",
"$",
"queryBuilder",
",",
"ClassMetadata",
"$",
"resourceMetadata",
",",
"array",
"$",
"aliases",
",",
"array",
"$",
"associationsMetadata",
",",
"$",
"property",
",",
"$",
"value",
",",
"$",
"parameter",
"=",
"null",
")",
"{",
"$",
"queryExpr",
"=",
"[",
"]",
";",
"/*\n * simple (case 1):\n * $property = name\n *\n * relation (case 2):\n * $property = relatedDummy_name\n * $property = relatedDymmy_id\n * $property = relatedDummy_user_id\n * $property = relatedDummy_user_name\n */",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"property",
",",
"'.'",
")",
")",
"{",
"$",
"explodedProperty",
"=",
"explode",
"(",
"'.'",
",",
"$",
"property",
")",
";",
"}",
"else",
"{",
"$",
"explodedProperty",
"=",
"explode",
"(",
"'_'",
",",
"$",
"property",
")",
";",
"}",
"// we are in case 2",
"$",
"property",
"=",
"array_pop",
"(",
"$",
"explodedProperty",
")",
";",
"$",
"alias",
"=",
"$",
"this",
"->",
"getResourceAliasForProperty",
"(",
"$",
"aliases",
",",
"$",
"explodedProperty",
")",
";",
"$",
"aliasMetadata",
"=",
"$",
"this",
"->",
"getAssociationMetadataForProperty",
"(",
"$",
"resourceMetadata",
",",
"$",
"associationsMetadata",
",",
"$",
"explodedProperty",
")",
";",
"if",
"(",
"true",
"===",
"$",
"aliasMetadata",
"->",
"hasField",
"(",
"$",
"property",
")",
")",
"{",
"// Entity has the property",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"operator",
"=>",
"$",
"operand",
")",
"{",
"// Case where there is an operator",
"$",
"queryExpr",
"[",
"]",
"=",
"$",
"this",
"->",
"handleOperator",
"(",
"$",
"queryBuilder",
",",
"$",
"alias",
",",
"$",
"aliasMetadata",
",",
"$",
"property",
",",
"$",
"operator",
",",
"$",
"operand",
",",
"$",
"parameter",
")",
";",
"}",
"}",
"else",
"{",
"// Simple where",
"$",
"value",
"=",
"$",
"this",
"->",
"normalizeValue",
"(",
"$",
"aliasMetadata",
",",
"$",
"property",
",",
"$",
"value",
")",
";",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"$",
"queryExpr",
"[",
"]",
"=",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"isNull",
"(",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"alias",
",",
"$",
"property",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"null",
"===",
"$",
"parameter",
")",
"{",
"$",
"parameter",
"=",
"$",
"property",
";",
"}",
"$",
"queryExpr",
"[",
"]",
"=",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"alias",
",",
"$",
"property",
")",
",",
"sprintf",
"(",
"':%s'",
",",
"$",
"parameter",
")",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"$",
"parameter",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"return",
"$",
"queryExpr",
";",
"}"
] |
Handles the given filter to call the proper operator. At this point, it's unclear if the value passed is the real
value operator.
@param QueryBuilder $queryBuilder
@param ClassMetadata $resourceMetadata
@param string[] $aliases
@param ClassMetadata[] $associationsMetadata
@param string $property
@param array|string $value
@param string|null $parameter If is string is used to construct the parameter to avoid parameter conflicts.
@return array
|
[
"Handles",
"the",
"given",
"filter",
"to",
"call",
"the",
"proper",
"operator",
".",
"At",
"this",
"point",
"it",
"s",
"unclear",
"if",
"the",
"value",
"passed",
"is",
"the",
"real",
"value",
"operator",
"."
] |
b66b295088b364e3c4aba5b0feb8d660c4141730
|
https://github.com/theofidry/LoopBackApiBundle/blob/b66b295088b364e3c4aba5b0feb8d660c4141730/src/Filter/WhereFilter.php#L197-L266
|
224,914
|
theofidry/LoopBackApiBundle
|
src/Filter/WhereFilter.php
|
WhereFilter.normalizeValue
|
private function normalizeValue(ClassMetadata $metadata, $property, $value)
{
if (self::PARAMETER_ID_KEY === $property) {
return $this->getFilterValueFromUrl($value);
}
if (self::PARAMETER_NULL_VALUE === $value) {
return null;
}
switch ($metadata->getTypeOfField($property)) {
case 'boolean':
return (bool) $value;
case 'integer':
return (int) $value;
case 'float':
return (float) $value;
case 'datetime':
// the input has the format `2015-04-28T02:23:50 00:00`, transform it to match the database format
// `2015-04-28 02:23:50`
return preg_replace('/(\d{4}(-\d{2}){2})T(\d{2}(:\d{2}){2}) \d{2}:\d{2}/', '$1 $3', $value);
}
return $value;
}
|
php
|
private function normalizeValue(ClassMetadata $metadata, $property, $value)
{
if (self::PARAMETER_ID_KEY === $property) {
return $this->getFilterValueFromUrl($value);
}
if (self::PARAMETER_NULL_VALUE === $value) {
return null;
}
switch ($metadata->getTypeOfField($property)) {
case 'boolean':
return (bool) $value;
case 'integer':
return (int) $value;
case 'float':
return (float) $value;
case 'datetime':
// the input has the format `2015-04-28T02:23:50 00:00`, transform it to match the database format
// `2015-04-28 02:23:50`
return preg_replace('/(\d{4}(-\d{2}){2})T(\d{2}(:\d{2}){2}) \d{2}:\d{2}/', '$1 $3', $value);
}
return $value;
}
|
[
"private",
"function",
"normalizeValue",
"(",
"ClassMetadata",
"$",
"metadata",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"if",
"(",
"self",
"::",
"PARAMETER_ID_KEY",
"===",
"$",
"property",
")",
"{",
"return",
"$",
"this",
"->",
"getFilterValueFromUrl",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"self",
"::",
"PARAMETER_NULL_VALUE",
"===",
"$",
"value",
")",
"{",
"return",
"null",
";",
"}",
"switch",
"(",
"$",
"metadata",
"->",
"getTypeOfField",
"(",
"$",
"property",
")",
")",
"{",
"case",
"'boolean'",
":",
"return",
"(",
"bool",
")",
"$",
"value",
";",
"case",
"'integer'",
":",
"return",
"(",
"int",
")",
"$",
"value",
";",
"case",
"'float'",
":",
"return",
"(",
"float",
")",
"$",
"value",
";",
"case",
"'datetime'",
":",
"// the input has the format `2015-04-28T02:23:50 00:00`, transform it to match the database format",
"// `2015-04-28 02:23:50`",
"return",
"preg_replace",
"(",
"'/(\\d{4}(-\\d{2}){2})T(\\d{2}(:\\d{2}){2}) \\d{2}:\\d{2}/'",
",",
"'$1 $3'",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Normalizes the value. If the key is an ID, get the real ID value. If is null, set the value to null. Otherwise
return unchanged value.
@param ClassMetadata $metadata
@param string $property
@param string $value
@return null|string
|
[
"Normalizes",
"the",
"value",
".",
"If",
"the",
"key",
"is",
"an",
"ID",
"get",
"the",
"real",
"ID",
"value",
".",
"If",
"is",
"null",
"set",
"the",
"value",
"to",
"null",
".",
"Otherwise",
"return",
"unchanged",
"value",
"."
] |
b66b295088b364e3c4aba5b0feb8d660c4141730
|
https://github.com/theofidry/LoopBackApiBundle/blob/b66b295088b364e3c4aba5b0feb8d660c4141730/src/Filter/WhereFilter.php#L385-L412
|
224,915
|
theofidry/LoopBackApiBundle
|
src/Filter/WhereFilter.php
|
WhereFilter.getFilterValueFromUrl
|
protected function getFilterValueFromUrl($value)
{
try {
if ($item = $this->iriConverter->getItemFromIri($value)) {
return $this->propertyAccessor->getValue($item, 'id');
}
} catch (\InvalidArgumentException $e) {
// Do nothing, return the raw value
}
return $value;
}
|
php
|
protected function getFilterValueFromUrl($value)
{
try {
if ($item = $this->iriConverter->getItemFromIri($value)) {
return $this->propertyAccessor->getValue($item, 'id');
}
} catch (\InvalidArgumentException $e) {
// Do nothing, return the raw value
}
return $value;
}
|
[
"protected",
"function",
"getFilterValueFromUrl",
"(",
"$",
"value",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"item",
"=",
"$",
"this",
"->",
"iriConverter",
"->",
"getItemFromIri",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"item",
",",
"'id'",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"// Do nothing, return the raw value",
"}",
"return",
"$",
"value",
";",
"}"
] |
Gets the ID from an URI or a raw ID.
@param string $value
@return string
|
[
"Gets",
"the",
"ID",
"from",
"an",
"URI",
"or",
"a",
"raw",
"ID",
"."
] |
b66b295088b364e3c4aba5b0feb8d660c4141730
|
https://github.com/theofidry/LoopBackApiBundle/blob/b66b295088b364e3c4aba5b0feb8d660c4141730/src/Filter/WhereFilter.php#L431-L442
|
224,916
|
theofidry/LoopBackApiBundle
|
src/Filter/WhereFilter.php
|
WhereFilter.getResourceAliasForProperty
|
private function getResourceAliasForProperty(array &$aliases, array $explodedProperty)
{
if (0 === count($explodedProperty)) {
return 'o';
}
foreach ($explodedProperty as $property) {
if (false === isset($aliases[$property])) {
$aliases[$property] = sprintf('WhereFilter_%sAlias', implode('_', $explodedProperty));
}
}
return $aliases[end($explodedProperty)];
}
|
php
|
private function getResourceAliasForProperty(array &$aliases, array $explodedProperty)
{
if (0 === count($explodedProperty)) {
return 'o';
}
foreach ($explodedProperty as $property) {
if (false === isset($aliases[$property])) {
$aliases[$property] = sprintf('WhereFilter_%sAlias', implode('_', $explodedProperty));
}
}
return $aliases[end($explodedProperty)];
}
|
[
"private",
"function",
"getResourceAliasForProperty",
"(",
"array",
"&",
"$",
"aliases",
",",
"array",
"$",
"explodedProperty",
")",
"{",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"explodedProperty",
")",
")",
"{",
"return",
"'o'",
";",
"}",
"foreach",
"(",
"$",
"explodedProperty",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"aliases",
"[",
"$",
"property",
"]",
")",
")",
"{",
"$",
"aliases",
"[",
"$",
"property",
"]",
"=",
"sprintf",
"(",
"'WhereFilter_%sAlias'",
",",
"implode",
"(",
"'_'",
",",
"$",
"explodedProperty",
")",
")",
";",
"}",
"}",
"return",
"$",
"aliases",
"[",
"end",
"(",
"$",
"explodedProperty",
")",
"]",
";",
"}"
] |
Gets the alias used for the entity to which the property belongs.
@example
$property was `name`
$explodedProperty then is []
=> 'o'
$property was `relatedDummy_name`
$explodedProperty then is ['relatedDummy']
=> WhereFilter_relatedDummyAlias
$property was `relatedDummy_anotherDummy_name`
$explodedProperty then is ['relatedDummy', 'anotherDummy']
=> WhereFilter_relatedDummy_anotherDummyAlias
@param string[] $aliases Array containing all the properties for each an alias is used. The key is the
property and the value the actual alias.
@param string[] $explodedProperty
@return string alias
|
[
"Gets",
"the",
"alias",
"used",
"for",
"the",
"entity",
"to",
"which",
"the",
"property",
"belongs",
"."
] |
b66b295088b364e3c4aba5b0feb8d660c4141730
|
https://github.com/theofidry/LoopBackApiBundle/blob/b66b295088b364e3c4aba5b0feb8d660c4141730/src/Filter/WhereFilter.php#L466-L479
|
224,917
|
theofidry/LoopBackApiBundle
|
src/Filter/WhereFilter.php
|
WhereFilter.getAssociationMetadataForProperty
|
private function getAssociationMetadataForProperty(
ClassMetadata $resourceMetadata,
array &$associationsMetadata,
array
$explodedProperty
) {
if (0 === count($explodedProperty)) {
return $resourceMetadata;
}
$parentResourceMetadata = $resourceMetadata;
foreach ($explodedProperty as $index => $property) {
if (1 <= $index) {
$parentResourceMetadata = $associationsMetadata[$explodedProperty[$index - 1]];
}
if (false === $parentResourceMetadata->hasAssociation($property)) {
throw new \RuntimeException(sprintf(
'Class %s::%s is not an association.',
$parentResourceMetadata->getName
(),
$property)
);
}
if (false === isset($associationsMetadata[$property])) {
$associationsMetadata[$property] = $this->getMetadata(
$parentResourceMetadata->getAssociationTargetClass($property)
);
}
}
return $associationsMetadata[end($explodedProperty)];
}
|
php
|
private function getAssociationMetadataForProperty(
ClassMetadata $resourceMetadata,
array &$associationsMetadata,
array
$explodedProperty
) {
if (0 === count($explodedProperty)) {
return $resourceMetadata;
}
$parentResourceMetadata = $resourceMetadata;
foreach ($explodedProperty as $index => $property) {
if (1 <= $index) {
$parentResourceMetadata = $associationsMetadata[$explodedProperty[$index - 1]];
}
if (false === $parentResourceMetadata->hasAssociation($property)) {
throw new \RuntimeException(sprintf(
'Class %s::%s is not an association.',
$parentResourceMetadata->getName
(),
$property)
);
}
if (false === isset($associationsMetadata[$property])) {
$associationsMetadata[$property] = $this->getMetadata(
$parentResourceMetadata->getAssociationTargetClass($property)
);
}
}
return $associationsMetadata[end($explodedProperty)];
}
|
[
"private",
"function",
"getAssociationMetadataForProperty",
"(",
"ClassMetadata",
"$",
"resourceMetadata",
",",
"array",
"&",
"$",
"associationsMetadata",
",",
"array",
"$",
"explodedProperty",
")",
"{",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"explodedProperty",
")",
")",
"{",
"return",
"$",
"resourceMetadata",
";",
"}",
"$",
"parentResourceMetadata",
"=",
"$",
"resourceMetadata",
";",
"foreach",
"(",
"$",
"explodedProperty",
"as",
"$",
"index",
"=>",
"$",
"property",
")",
"{",
"if",
"(",
"1",
"<=",
"$",
"index",
")",
"{",
"$",
"parentResourceMetadata",
"=",
"$",
"associationsMetadata",
"[",
"$",
"explodedProperty",
"[",
"$",
"index",
"-",
"1",
"]",
"]",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"parentResourceMetadata",
"->",
"hasAssociation",
"(",
"$",
"property",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Class %s::%s is not an association.'",
",",
"$",
"parentResourceMetadata",
"->",
"getName",
"(",
")",
",",
"$",
"property",
")",
")",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"associationsMetadata",
"[",
"$",
"property",
"]",
")",
")",
"{",
"$",
"associationsMetadata",
"[",
"$",
"property",
"]",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
"$",
"parentResourceMetadata",
"->",
"getAssociationTargetClass",
"(",
"$",
"property",
")",
")",
";",
"}",
"}",
"return",
"$",
"associationsMetadata",
"[",
"end",
"(",
"$",
"explodedProperty",
")",
"]",
";",
"}"
] |
Gets the metadata to which belongs the property.
@example
$property was `name`
$explodedProperty then is []
=> $resourceMetadata
$property was `relatedDummy_name`
$explodedProperty then is ['relatedDummy']
=> metadata of relatedDummy
$property was `relatedDummy_anotherDummy_name`
$explodedProperty then is ['relatedDummy', 'anotherDummy']
=> metadata of anotherDummy
@param ClassMetadata $resourceMetadata
@param ClassMetadata[] $associationsMetadata
@param array $explodedProperty
@return ClassMetadata
|
[
"Gets",
"the",
"metadata",
"to",
"which",
"belongs",
"the",
"property",
"."
] |
b66b295088b364e3c4aba5b0feb8d660c4141730
|
https://github.com/theofidry/LoopBackApiBundle/blob/b66b295088b364e3c4aba5b0feb8d660c4141730/src/Filter/WhereFilter.php#L503-L536
|
224,918
|
ongr-io/TranslationsBundle
|
DependencyInjection/ONGRTranslationsExtension.php
|
ONGRTranslationsExtension.setFiltersManager
|
private function setFiltersManager($repository, ContainerBuilder $container)
{
$definition = new Definition(
'ONGR\FilterManagerBundle\Search\FilterManager',
[
new Reference('ongr_translations.filters_container'),
new Reference($repository),
new Reference('event_dispatcher'),
new Reference('jms_serializer')
]
);
$container->setDefinition('ongr_translations.filter_manager', $definition);
}
|
php
|
private function setFiltersManager($repository, ContainerBuilder $container)
{
$definition = new Definition(
'ONGR\FilterManagerBundle\Search\FilterManager',
[
new Reference('ongr_translations.filters_container'),
new Reference($repository),
new Reference('event_dispatcher'),
new Reference('jms_serializer')
]
);
$container->setDefinition('ongr_translations.filter_manager', $definition);
}
|
[
"private",
"function",
"setFiltersManager",
"(",
"$",
"repository",
",",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"definition",
"=",
"new",
"Definition",
"(",
"'ONGR\\FilterManagerBundle\\Search\\FilterManager'",
",",
"[",
"new",
"Reference",
"(",
"'ongr_translations.filters_container'",
")",
",",
"new",
"Reference",
"(",
"$",
"repository",
")",
",",
"new",
"Reference",
"(",
"'event_dispatcher'",
")",
",",
"new",
"Reference",
"(",
"'jms_serializer'",
")",
"]",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"'ongr_translations.filter_manager'",
",",
"$",
"definition",
")",
";",
"}"
] |
Adds filter manager for displaying translations gui.
@param string $repository Elasticsearch repository id.
@param ContainerBuilder $container Service container.
|
[
"Adds",
"filter",
"manager",
"for",
"displaying",
"translations",
"gui",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/DependencyInjection/ONGRTranslationsExtension.php#L54-L67
|
224,919
|
Nyholm/google-api-php-client
|
src/GoogleApi/Auth/OAuth2.php
|
OAuth2.verifySignedJwtWithCerts
|
function verifySignedJwtWithCerts($jwt, $certs, $required_audience) {
$segments = explode(".", $jwt);
if (count($segments) != 3) {
throw new AuthException("Wrong number of segments in token: $jwt");
}
$signed = $segments[0] . "." . $segments[1];
$signature = Utils::urlSafeB64Decode($segments[2]);
// Parse envelope.
$envelope = json_decode(Utils::urlSafeB64Decode($segments[0]), true);
if (!$envelope) {
throw new AuthException("Can't parse token envelope: " . $segments[0]);
}
// Parse token
$json_body = Utils::urlSafeB64Decode($segments[1]);
$payload = json_decode($json_body, true);
if (!$payload) {
throw new AuthException("Can't parse token payload: " . $segments[1]);
}
// Check signature
$verified = false;
foreach ($certs as $keyName => $pem) {
$public_key = new PemVerifier($pem);
if ($public_key->verify($signed, $signature)) {
$verified = true;
break;
}
}
if (!$verified) {
throw new AuthException("Invalid token signature: $jwt");
}
// Check issued-at timestamp
$iat = 0;
if (array_key_exists("iat", $payload)) {
$iat = $payload["iat"];
}
if (!$iat) {
throw new AuthException("No issue time in token: $json_body");
}
$earliest = $iat - self::CLOCK_SKEW_SECS;
// Check expiration timestamp
$now = time();
$exp = 0;
if (array_key_exists("exp", $payload)) {
$exp = $payload["exp"];
}
if (!$exp) {
throw new AuthException("No expiration time in token: $json_body");
}
if ($exp >= $now + self::MAX_TOKEN_LIFETIME_SECS) {
throw new AuthException(
"Expiration time too far in future: $json_body");
}
$latest = $exp + self::CLOCK_SKEW_SECS;
if ($now < $earliest) {
throw new AuthException(
"Token used too early, $now < $earliest: $json_body");
}
if ($now > $latest) {
throw new AuthException(
"Token used too late, $now > $latest: $json_body");
}
// TODO(beaton): check issuer field?
// Check audience
$aud = $payload["aud"];
if ($aud != $required_audience) {
throw new AuthException("Wrong recipient, $aud != $required_audience: $json_body");
}
// All good.
return new LoginTicket($envelope, $payload);
}
|
php
|
function verifySignedJwtWithCerts($jwt, $certs, $required_audience) {
$segments = explode(".", $jwt);
if (count($segments) != 3) {
throw new AuthException("Wrong number of segments in token: $jwt");
}
$signed = $segments[0] . "." . $segments[1];
$signature = Utils::urlSafeB64Decode($segments[2]);
// Parse envelope.
$envelope = json_decode(Utils::urlSafeB64Decode($segments[0]), true);
if (!$envelope) {
throw new AuthException("Can't parse token envelope: " . $segments[0]);
}
// Parse token
$json_body = Utils::urlSafeB64Decode($segments[1]);
$payload = json_decode($json_body, true);
if (!$payload) {
throw new AuthException("Can't parse token payload: " . $segments[1]);
}
// Check signature
$verified = false;
foreach ($certs as $keyName => $pem) {
$public_key = new PemVerifier($pem);
if ($public_key->verify($signed, $signature)) {
$verified = true;
break;
}
}
if (!$verified) {
throw new AuthException("Invalid token signature: $jwt");
}
// Check issued-at timestamp
$iat = 0;
if (array_key_exists("iat", $payload)) {
$iat = $payload["iat"];
}
if (!$iat) {
throw new AuthException("No issue time in token: $json_body");
}
$earliest = $iat - self::CLOCK_SKEW_SECS;
// Check expiration timestamp
$now = time();
$exp = 0;
if (array_key_exists("exp", $payload)) {
$exp = $payload["exp"];
}
if (!$exp) {
throw new AuthException("No expiration time in token: $json_body");
}
if ($exp >= $now + self::MAX_TOKEN_LIFETIME_SECS) {
throw new AuthException(
"Expiration time too far in future: $json_body");
}
$latest = $exp + self::CLOCK_SKEW_SECS;
if ($now < $earliest) {
throw new AuthException(
"Token used too early, $now < $earliest: $json_body");
}
if ($now > $latest) {
throw new AuthException(
"Token used too late, $now > $latest: $json_body");
}
// TODO(beaton): check issuer field?
// Check audience
$aud = $payload["aud"];
if ($aud != $required_audience) {
throw new AuthException("Wrong recipient, $aud != $required_audience: $json_body");
}
// All good.
return new LoginTicket($envelope, $payload);
}
|
[
"function",
"verifySignedJwtWithCerts",
"(",
"$",
"jwt",
",",
"$",
"certs",
",",
"$",
"required_audience",
")",
"{",
"$",
"segments",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"jwt",
")",
";",
"if",
"(",
"count",
"(",
"$",
"segments",
")",
"!=",
"3",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Wrong number of segments in token: $jwt\"",
")",
";",
"}",
"$",
"signed",
"=",
"$",
"segments",
"[",
"0",
"]",
".",
"\".\"",
".",
"$",
"segments",
"[",
"1",
"]",
";",
"$",
"signature",
"=",
"Utils",
"::",
"urlSafeB64Decode",
"(",
"$",
"segments",
"[",
"2",
"]",
")",
";",
"// Parse envelope.",
"$",
"envelope",
"=",
"json_decode",
"(",
"Utils",
"::",
"urlSafeB64Decode",
"(",
"$",
"segments",
"[",
"0",
"]",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"envelope",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Can't parse token envelope: \"",
".",
"$",
"segments",
"[",
"0",
"]",
")",
";",
"}",
"// Parse token",
"$",
"json_body",
"=",
"Utils",
"::",
"urlSafeB64Decode",
"(",
"$",
"segments",
"[",
"1",
"]",
")",
";",
"$",
"payload",
"=",
"json_decode",
"(",
"$",
"json_body",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"payload",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Can't parse token payload: \"",
".",
"$",
"segments",
"[",
"1",
"]",
")",
";",
"}",
"// Check signature",
"$",
"verified",
"=",
"false",
";",
"foreach",
"(",
"$",
"certs",
"as",
"$",
"keyName",
"=>",
"$",
"pem",
")",
"{",
"$",
"public_key",
"=",
"new",
"PemVerifier",
"(",
"$",
"pem",
")",
";",
"if",
"(",
"$",
"public_key",
"->",
"verify",
"(",
"$",
"signed",
",",
"$",
"signature",
")",
")",
"{",
"$",
"verified",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"verified",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Invalid token signature: $jwt\"",
")",
";",
"}",
"// Check issued-at timestamp",
"$",
"iat",
"=",
"0",
";",
"if",
"(",
"array_key_exists",
"(",
"\"iat\"",
",",
"$",
"payload",
")",
")",
"{",
"$",
"iat",
"=",
"$",
"payload",
"[",
"\"iat\"",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"iat",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"No issue time in token: $json_body\"",
")",
";",
"}",
"$",
"earliest",
"=",
"$",
"iat",
"-",
"self",
"::",
"CLOCK_SKEW_SECS",
";",
"// Check expiration timestamp",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"exp",
"=",
"0",
";",
"if",
"(",
"array_key_exists",
"(",
"\"exp\"",
",",
"$",
"payload",
")",
")",
"{",
"$",
"exp",
"=",
"$",
"payload",
"[",
"\"exp\"",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"exp",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"No expiration time in token: $json_body\"",
")",
";",
"}",
"if",
"(",
"$",
"exp",
">=",
"$",
"now",
"+",
"self",
"::",
"MAX_TOKEN_LIFETIME_SECS",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Expiration time too far in future: $json_body\"",
")",
";",
"}",
"$",
"latest",
"=",
"$",
"exp",
"+",
"self",
"::",
"CLOCK_SKEW_SECS",
";",
"if",
"(",
"$",
"now",
"<",
"$",
"earliest",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Token used too early, $now < $earliest: $json_body\"",
")",
";",
"}",
"if",
"(",
"$",
"now",
">",
"$",
"latest",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Token used too late, $now > $latest: $json_body\"",
")",
";",
"}",
"// TODO(beaton): check issuer field?",
"// Check audience",
"$",
"aud",
"=",
"$",
"payload",
"[",
"\"aud\"",
"]",
";",
"if",
"(",
"$",
"aud",
"!=",
"$",
"required_audience",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Wrong recipient, $aud != $required_audience: $json_body\"",
")",
";",
"}",
"// All good.",
"return",
"new",
"LoginTicket",
"(",
"$",
"envelope",
",",
"$",
"payload",
")",
";",
"}"
] |
Visible for testing.
|
[
"Visible",
"for",
"testing",
"."
] |
249743b90f165f0159a748d3b9ca507b98b2d496
|
https://github.com/Nyholm/google-api-php-client/blob/249743b90f165f0159a748d3b9ca507b98b2d496/src/GoogleApi/Auth/OAuth2.php#L375-L454
|
224,920
|
bem/bh-php
|
src/BH.php
|
BH.groupBy
|
public static function groupBy($data, $key)
{
$res = [];
for ($i = 0, $l = sizeof($data); $i < $l; $i++) {
$item = $data[$i];
$value = empty($item[$key]) ? __undefined : $item[$key];
if (empty($res[$value])) {
$res[$value] = [];
}
$res[$value][] = $item;
}
return $res;
}
|
php
|
public static function groupBy($data, $key)
{
$res = [];
for ($i = 0, $l = sizeof($data); $i < $l; $i++) {
$item = $data[$i];
$value = empty($item[$key]) ? __undefined : $item[$key];
if (empty($res[$value])) {
$res[$value] = [];
}
$res[$value][] = $item;
}
return $res;
}
|
[
"public",
"static",
"function",
"groupBy",
"(",
"$",
"data",
",",
"$",
"key",
")",
"{",
"$",
"res",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"l",
"=",
"sizeof",
"(",
"$",
"data",
")",
";",
"$",
"i",
"<",
"$",
"l",
";",
"$",
"i",
"++",
")",
"{",
"$",
"item",
"=",
"$",
"data",
"[",
"$",
"i",
"]",
";",
"$",
"value",
"=",
"empty",
"(",
"$",
"item",
"[",
"$",
"key",
"]",
")",
"?",
"__undefined",
":",
"$",
"item",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"res",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"res",
"[",
"$",
"value",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"res",
"[",
"$",
"value",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"return",
"$",
"res",
";",
"}"
] |
Group up selectors by some key
@param array $data
@param string $key
@return array
|
[
"Group",
"up",
"selectors",
"by",
"some",
"key"
] |
2f46ccb3f32cba1836ed70d28ee0d02b0e7684e2
|
https://github.com/bem/bh-php/blob/2f46ccb3f32cba1836ed70d28ee0d02b0e7684e2/src/BH.php#L788-L800
|
224,921
|
ongr-io/TranslationsBundle
|
Document/Translation.php
|
Translation.getId
|
public function getId()
{
if (!$this->id) {
$this->setId(sha1($this->getDomain() . $this->getKey()));
}
return $this->id;
}
|
php
|
public function getId()
{
if (!$this->id) {
$this->setId(sha1($this->getDomain() . $this->getKey()));
}
return $this->id;
}
|
[
"public",
"function",
"getId",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"id",
")",
"{",
"$",
"this",
"->",
"setId",
"(",
"sha1",
"(",
"$",
"this",
"->",
"getDomain",
"(",
")",
".",
"$",
"this",
"->",
"getKey",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"id",
";",
"}"
] |
Returns document id.
@return string
|
[
"Returns",
"document",
"id",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Document/Translation.php#L123-L130
|
224,922
|
ongr-io/TranslationsBundle
|
Document/Translation.php
|
Translation.getMessagesArray
|
public function getMessagesArray()
{
$result = [];
foreach ($this->getMessages() as $message) {
$result[$message->getLocale()] = $message;
}
return $result;
}
|
php
|
public function getMessagesArray()
{
$result = [];
foreach ($this->getMessages() as $message) {
$result[$message->getLocale()] = $message;
}
return $result;
}
|
[
"public",
"function",
"getMessagesArray",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getMessages",
"(",
")",
"as",
"$",
"message",
")",
"{",
"$",
"result",
"[",
"$",
"message",
"->",
"getLocale",
"(",
")",
"]",
"=",
"$",
"message",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Returns messages as array.
Format: ['locale' => 'message'].
@return array
|
[
"Returns",
"messages",
"as",
"array",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Document/Translation.php#L317-L325
|
224,923
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.copyItem
|
public function copyItem(string $targetId, string $itemId, bool $overwrite = false):array
{
$parameters = $this->buildHttpQuery(
[
'targetid' => $targetId,
'overwrite' => $overwrite,
]
);
return $this->post("Items({$itemId})/Copy?{$parameters}");
}
|
php
|
public function copyItem(string $targetId, string $itemId, bool $overwrite = false):array
{
$parameters = $this->buildHttpQuery(
[
'targetid' => $targetId,
'overwrite' => $overwrite,
]
);
return $this->post("Items({$itemId})/Copy?{$parameters}");
}
|
[
"public",
"function",
"copyItem",
"(",
"string",
"$",
"targetId",
",",
"string",
"$",
"itemId",
",",
"bool",
"$",
"overwrite",
"=",
"false",
")",
":",
"array",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"buildHttpQuery",
"(",
"[",
"'targetid'",
"=>",
"$",
"targetId",
",",
"'overwrite'",
"=>",
"$",
"overwrite",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"\"Items({$itemId})/Copy?{$parameters}\"",
")",
";",
"}"
] |
Copy an item.
@param string $targetId Id of the target folder
@param string $itemId Id of the copied item
@param bool $overwrite Indicates whether items with the same name will be overwritten or not (optional)
@return array
|
[
"Copy",
"an",
"item",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L222-L232
|
224,924
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.getItemDownloadUrl
|
public function getItemDownloadUrl(string $itemId, bool $includeallversions = false):array
{
$parameters = $this->buildHttpQuery(
[
'includeallversions' => $includeallversions,
'redirect' => false,
]
);
return $this->get("Items({$itemId})/Download?{$parameters}");
}
|
php
|
public function getItemDownloadUrl(string $itemId, bool $includeallversions = false):array
{
$parameters = $this->buildHttpQuery(
[
'includeallversions' => $includeallversions,
'redirect' => false,
]
);
return $this->get("Items({$itemId})/Download?{$parameters}");
}
|
[
"public",
"function",
"getItemDownloadUrl",
"(",
"string",
"$",
"itemId",
",",
"bool",
"$",
"includeallversions",
"=",
"false",
")",
":",
"array",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"buildHttpQuery",
"(",
"[",
"'includeallversions'",
"=>",
"$",
"includeallversions",
",",
"'redirect'",
"=>",
"false",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"get",
"(",
"\"Items({$itemId})/Download?{$parameters}\"",
")",
";",
"}"
] |
Get temporary download URL for an item.
@param string $itemId Item id
@param bool $includeallversions For folder downloads only, includes old versions of files in the folder in the zip when true, current versions only when false (default)
@return array
|
[
"Get",
"temporary",
"download",
"URL",
"for",
"an",
"item",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L285-L295
|
224,925
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.getItemContents
|
public function getItemContents(string $itemId, bool $includeallversions = false)
{
$parameters = $this->buildHttpQuery(
[
'includeallversions' => $includeallversions,
'redirect' => true,
]
);
return $this->get("Items({$itemId})/Download?{$parameters}");
}
|
php
|
public function getItemContents(string $itemId, bool $includeallversions = false)
{
$parameters = $this->buildHttpQuery(
[
'includeallversions' => $includeallversions,
'redirect' => true,
]
);
return $this->get("Items({$itemId})/Download?{$parameters}");
}
|
[
"public",
"function",
"getItemContents",
"(",
"string",
"$",
"itemId",
",",
"bool",
"$",
"includeallversions",
"=",
"false",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"buildHttpQuery",
"(",
"[",
"'includeallversions'",
"=>",
"$",
"includeallversions",
",",
"'redirect'",
"=>",
"true",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"get",
"(",
"\"Items({$itemId})/Download?{$parameters}\"",
")",
";",
"}"
] |
Get contents of and item.
@param string $itemId Item id
@param bool $includeallversions $includeallversions For folder downloads only, includes old versions of files in the folder in the zip when true, current versions only when false (default)
@return mixed
|
[
"Get",
"contents",
"of",
"and",
"item",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L305-L315
|
224,926
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.getChunkUri
|
public function getChunkUri(string $method, string $filename, string $folderId, bool $unzip = false, $overwrite = true, bool $notify = true, bool $raw = false, $stream = null):array
{
$parameters = $this->buildHttpQuery(
[
'method' => $method,
'raw' => $raw,
'fileName' => basename($filename),
'fileSize' => $stream == null ? filesize($filename) : fstat($stream)['size'],
'canResume' => false,
'startOver' => false,
'unzip' => $unzip,
'tool' => 'apiv3',
'overwrite' => $overwrite,
'title' => basename($filename),
'isSend' => false,
'responseFormat' => 'json',
'notify' => $notify,
'clientCreatedDateUTC' => $stream == null ? filectime($filename) : fstat($stream)['ctime'],
'clientModifiedDateUTC' => $stream == null ? filemtime($filename) : fstat($stream)['mtime'],
]
);
return $this->post("Items({$folderId})/Upload?{$parameters}");
}
|
php
|
public function getChunkUri(string $method, string $filename, string $folderId, bool $unzip = false, $overwrite = true, bool $notify = true, bool $raw = false, $stream = null):array
{
$parameters = $this->buildHttpQuery(
[
'method' => $method,
'raw' => $raw,
'fileName' => basename($filename),
'fileSize' => $stream == null ? filesize($filename) : fstat($stream)['size'],
'canResume' => false,
'startOver' => false,
'unzip' => $unzip,
'tool' => 'apiv3',
'overwrite' => $overwrite,
'title' => basename($filename),
'isSend' => false,
'responseFormat' => 'json',
'notify' => $notify,
'clientCreatedDateUTC' => $stream == null ? filectime($filename) : fstat($stream)['ctime'],
'clientModifiedDateUTC' => $stream == null ? filemtime($filename) : fstat($stream)['mtime'],
]
);
return $this->post("Items({$folderId})/Upload?{$parameters}");
}
|
[
"public",
"function",
"getChunkUri",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"filename",
",",
"string",
"$",
"folderId",
",",
"bool",
"$",
"unzip",
"=",
"false",
",",
"$",
"overwrite",
"=",
"true",
",",
"bool",
"$",
"notify",
"=",
"true",
",",
"bool",
"$",
"raw",
"=",
"false",
",",
"$",
"stream",
"=",
"null",
")",
":",
"array",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"buildHttpQuery",
"(",
"[",
"'method'",
"=>",
"$",
"method",
",",
"'raw'",
"=>",
"$",
"raw",
",",
"'fileName'",
"=>",
"basename",
"(",
"$",
"filename",
")",
",",
"'fileSize'",
"=>",
"$",
"stream",
"==",
"null",
"?",
"filesize",
"(",
"$",
"filename",
")",
":",
"fstat",
"(",
"$",
"stream",
")",
"[",
"'size'",
"]",
",",
"'canResume'",
"=>",
"false",
",",
"'startOver'",
"=>",
"false",
",",
"'unzip'",
"=>",
"$",
"unzip",
",",
"'tool'",
"=>",
"'apiv3'",
",",
"'overwrite'",
"=>",
"$",
"overwrite",
",",
"'title'",
"=>",
"basename",
"(",
"$",
"filename",
")",
",",
"'isSend'",
"=>",
"false",
",",
"'responseFormat'",
"=>",
"'json'",
",",
"'notify'",
"=>",
"$",
"notify",
",",
"'clientCreatedDateUTC'",
"=>",
"$",
"stream",
"==",
"null",
"?",
"filectime",
"(",
"$",
"filename",
")",
":",
"fstat",
"(",
"$",
"stream",
")",
"[",
"'ctime'",
"]",
",",
"'clientModifiedDateUTC'",
"=>",
"$",
"stream",
"==",
"null",
"?",
"filemtime",
"(",
"$",
"filename",
")",
":",
"fstat",
"(",
"$",
"stream",
")",
"[",
"'mtime'",
"]",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"\"Items({$folderId})/Upload?{$parameters}\"",
")",
";",
"}"
] |
Get the Chunk Uri to start a file-upload.
@param string $method Upload method (Standard or Streamed)
@param string $filename Name of file
@param string $folderId Id of the parent folder
@param bool $unzip Indicates that the upload is a Zip file, and contents must be extracted at the end of upload. The resulting files and directories will be placed in the target folder. If set to false, the ZIP file is uploaded as a single file. Default is false (optional)
@param bool $overwrite Indicates whether items with the same name will be overwritten or not (optional)
@param bool $notify Indicates whether users will be notified of this upload - based on folder preferences (optional)
@param bool $raw Send contents contents directly in the POST body (=true) or send contents in MIME format (=false) (optional)
@param resource $stream Resource stream of the contents (optional)
@return array
|
[
"Get",
"the",
"Chunk",
"Uri",
"to",
"start",
"a",
"file",
"-",
"upload",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L331-L354
|
224,927
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.uploadFileStandard
|
public function uploadFileStandard(string $filename, string $folderId, bool $unzip = false, bool $overwrite = true, bool $notify = true):string
{
$chunkUri = $this->getChunkUri('standard', $filename, $folderId, $unzip, $overwrite, $notify);
$response = $this->client->request(
'POST',
$chunkUri['ChunkUri'],
[
'multipart' => [
[
'name' => 'File1',
'contents' => fopen($filename, 'r'),
],
],
]
);
return (string) $response->getBody();
}
|
php
|
public function uploadFileStandard(string $filename, string $folderId, bool $unzip = false, bool $overwrite = true, bool $notify = true):string
{
$chunkUri = $this->getChunkUri('standard', $filename, $folderId, $unzip, $overwrite, $notify);
$response = $this->client->request(
'POST',
$chunkUri['ChunkUri'],
[
'multipart' => [
[
'name' => 'File1',
'contents' => fopen($filename, 'r'),
],
],
]
);
return (string) $response->getBody();
}
|
[
"public",
"function",
"uploadFileStandard",
"(",
"string",
"$",
"filename",
",",
"string",
"$",
"folderId",
",",
"bool",
"$",
"unzip",
"=",
"false",
",",
"bool",
"$",
"overwrite",
"=",
"true",
",",
"bool",
"$",
"notify",
"=",
"true",
")",
":",
"string",
"{",
"$",
"chunkUri",
"=",
"$",
"this",
"->",
"getChunkUri",
"(",
"'standard'",
",",
"$",
"filename",
",",
"$",
"folderId",
",",
"$",
"unzip",
",",
"$",
"overwrite",
",",
"$",
"notify",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'POST'",
",",
"$",
"chunkUri",
"[",
"'ChunkUri'",
"]",
",",
"[",
"'multipart'",
"=>",
"[",
"[",
"'name'",
"=>",
"'File1'",
",",
"'contents'",
"=>",
"fopen",
"(",
"$",
"filename",
",",
"'r'",
")",
",",
"]",
",",
"]",
",",
"]",
")",
";",
"return",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}"
] |
Upload a file using a single HTTP POST.
@param string $filename Name of file
@param string $folderId Id of the parent folder
@param bool $unzip Indicates that the upload is a Zip file, and contents must be extracted at the end of upload. The resulting files and directories will be placed in the target folder. If set to false, the ZIP file is uploaded as a single file. Default is false (optional)
@param bool $overwrite Indicates whether items with the same name will be overwritten or not (optional)
@param bool $notify Indicates whether users will be notified of this upload - based on folder preferences (optional)
@return string
|
[
"Upload",
"a",
"file",
"using",
"a",
"single",
"HTTP",
"POST",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L367-L385
|
224,928
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.uploadFileStreamed
|
public function uploadFileStreamed($stream, string $folderId, string $filename = null, bool $unzip = false, bool $overwrite = true, bool $notify = true, int $chunkSize = null):string
{
$filename = $filename ?? stream_get_meta_data($stream)['uri'];
if (empty($filename)) {
return 'Error: no filename';
}
$chunkUri = $this->getChunkUri('streamed', $filename, $folderId, $unzip, $overwrite, $notify, true, $stream);
$chunkSize = $chunkSize ?? SELF::DEFAULT_CHUNK_SIZE;
$index = 0;
// First Chunk
$data = $this->readChunk($stream, $chunkSize);
while (! ((strlen($data) < $chunkSize) || feof($stream))) {
$parameters = $this->buildHttpQuery(
[
'index' => $index,
'byteOffset' => $index * $chunkSize,
'hash' => md5($data),
]
);
$response = $this->uploadChunk("{$chunkUri['ChunkUri']}&{$parameters}", $data);
if ($response != 'true') {
return $response;
}
// Next chunk
$index++;
$data = $this->readChunk($stream, $chunkSize);
}
// Final chunk
$parameters = $this->buildHttpQuery(
[
'index' => $index,
'byteOffset' => $index * $chunkSize,
'hash' => md5($data),
'filehash' => Psr7\hash(Psr7\stream_for($stream), 'md5'),
'finish' => true,
]
);
return $this->uploadChunk("{$chunkUri['ChunkUri']}&{$parameters}", $data);
}
|
php
|
public function uploadFileStreamed($stream, string $folderId, string $filename = null, bool $unzip = false, bool $overwrite = true, bool $notify = true, int $chunkSize = null):string
{
$filename = $filename ?? stream_get_meta_data($stream)['uri'];
if (empty($filename)) {
return 'Error: no filename';
}
$chunkUri = $this->getChunkUri('streamed', $filename, $folderId, $unzip, $overwrite, $notify, true, $stream);
$chunkSize = $chunkSize ?? SELF::DEFAULT_CHUNK_SIZE;
$index = 0;
// First Chunk
$data = $this->readChunk($stream, $chunkSize);
while (! ((strlen($data) < $chunkSize) || feof($stream))) {
$parameters = $this->buildHttpQuery(
[
'index' => $index,
'byteOffset' => $index * $chunkSize,
'hash' => md5($data),
]
);
$response = $this->uploadChunk("{$chunkUri['ChunkUri']}&{$parameters}", $data);
if ($response != 'true') {
return $response;
}
// Next chunk
$index++;
$data = $this->readChunk($stream, $chunkSize);
}
// Final chunk
$parameters = $this->buildHttpQuery(
[
'index' => $index,
'byteOffset' => $index * $chunkSize,
'hash' => md5($data),
'filehash' => Psr7\hash(Psr7\stream_for($stream), 'md5'),
'finish' => true,
]
);
return $this->uploadChunk("{$chunkUri['ChunkUri']}&{$parameters}", $data);
}
|
[
"public",
"function",
"uploadFileStreamed",
"(",
"$",
"stream",
",",
"string",
"$",
"folderId",
",",
"string",
"$",
"filename",
"=",
"null",
",",
"bool",
"$",
"unzip",
"=",
"false",
",",
"bool",
"$",
"overwrite",
"=",
"true",
",",
"bool",
"$",
"notify",
"=",
"true",
",",
"int",
"$",
"chunkSize",
"=",
"null",
")",
":",
"string",
"{",
"$",
"filename",
"=",
"$",
"filename",
"??",
"stream_get_meta_data",
"(",
"$",
"stream",
")",
"[",
"'uri'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"'Error: no filename'",
";",
"}",
"$",
"chunkUri",
"=",
"$",
"this",
"->",
"getChunkUri",
"(",
"'streamed'",
",",
"$",
"filename",
",",
"$",
"folderId",
",",
"$",
"unzip",
",",
"$",
"overwrite",
",",
"$",
"notify",
",",
"true",
",",
"$",
"stream",
")",
";",
"$",
"chunkSize",
"=",
"$",
"chunkSize",
"??",
"SELF",
"::",
"DEFAULT_CHUNK_SIZE",
";",
"$",
"index",
"=",
"0",
";",
"// First Chunk",
"$",
"data",
"=",
"$",
"this",
"->",
"readChunk",
"(",
"$",
"stream",
",",
"$",
"chunkSize",
")",
";",
"while",
"(",
"!",
"(",
"(",
"strlen",
"(",
"$",
"data",
")",
"<",
"$",
"chunkSize",
")",
"||",
"feof",
"(",
"$",
"stream",
")",
")",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"buildHttpQuery",
"(",
"[",
"'index'",
"=>",
"$",
"index",
",",
"'byteOffset'",
"=>",
"$",
"index",
"*",
"$",
"chunkSize",
",",
"'hash'",
"=>",
"md5",
"(",
"$",
"data",
")",
",",
"]",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"uploadChunk",
"(",
"\"{$chunkUri['ChunkUri']}&{$parameters}\"",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"response",
"!=",
"'true'",
")",
"{",
"return",
"$",
"response",
";",
"}",
"// Next chunk",
"$",
"index",
"++",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"readChunk",
"(",
"$",
"stream",
",",
"$",
"chunkSize",
")",
";",
"}",
"// Final chunk",
"$",
"parameters",
"=",
"$",
"this",
"->",
"buildHttpQuery",
"(",
"[",
"'index'",
"=>",
"$",
"index",
",",
"'byteOffset'",
"=>",
"$",
"index",
"*",
"$",
"chunkSize",
",",
"'hash'",
"=>",
"md5",
"(",
"$",
"data",
")",
",",
"'filehash'",
"=>",
"Psr7",
"\\",
"hash",
"(",
"Psr7",
"\\",
"stream_for",
"(",
"$",
"stream",
")",
",",
"'md5'",
")",
",",
"'finish'",
"=>",
"true",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"uploadChunk",
"(",
"\"{$chunkUri['ChunkUri']}&{$parameters}\"",
",",
"$",
"data",
")",
";",
"}"
] |
Upload a file using multiple HTTP POSTs.
@param mixed $stream Stream resource
@param string $folderId Id of the parent folder
@param string $filename Filename (optional)
@param bool $unzip Indicates that the upload is a Zip file, and contents must be extracted at the end of upload. The resulting files and directories will be placed in the target folder. If set to false, the ZIP file is uploaded as a single file. Default is false (optional)
@param bool $overwrite Indicates whether items with the same name will be overwritten or not (optional)
@param bool $notify Indicates whether users will be notified of this upload - based on folder preferences (optional)
@param int $chunkSize Maximum size of the individual HTTP posts in bytes
@return string
|
[
"Upload",
"a",
"file",
"using",
"multiple",
"HTTP",
"POSTs",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L400-L445
|
224,929
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.getThumbnailUrl
|
public function getThumbnailUrl(string $itemId, int $size = 75):array
{
$parameters = $this->buildHttpQuery(
[
'size' => $size,
'redirect' => false,
]
);
return $this->get("Items({$itemId})/Thumbnail?{$parameters}");
}
|
php
|
public function getThumbnailUrl(string $itemId, int $size = 75):array
{
$parameters = $this->buildHttpQuery(
[
'size' => $size,
'redirect' => false,
]
);
return $this->get("Items({$itemId})/Thumbnail?{$parameters}");
}
|
[
"public",
"function",
"getThumbnailUrl",
"(",
"string",
"$",
"itemId",
",",
"int",
"$",
"size",
"=",
"75",
")",
":",
"array",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"buildHttpQuery",
"(",
"[",
"'size'",
"=>",
"$",
"size",
",",
"'redirect'",
"=>",
"false",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"get",
"(",
"\"Items({$itemId})/Thumbnail?{$parameters}\"",
")",
";",
"}"
] |
Get Thumbnail of an item.
@param string $itemId Item id
@param int $size Thumbnail size: THUMBNAIL_SIZE_M or THUMBNAIL_SIZE_L (optional)
@return array
|
[
"Get",
"Thumbnail",
"of",
"an",
"item",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L455-L465
|
224,930
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.createShare
|
public function createShare(array $options, $notify = false):array
{
$parameters = $this->buildHttpQuery(
[
'notify' => $notify,
'direct' => true,
]
);
return $this->post("Shares?{$parameters}", $options);
}
|
php
|
public function createShare(array $options, $notify = false):array
{
$parameters = $this->buildHttpQuery(
[
'notify' => $notify,
'direct' => true,
]
);
return $this->post("Shares?{$parameters}", $options);
}
|
[
"public",
"function",
"createShare",
"(",
"array",
"$",
"options",
",",
"$",
"notify",
"=",
"false",
")",
":",
"array",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"buildHttpQuery",
"(",
"[",
"'notify'",
"=>",
"$",
"notify",
",",
"'direct'",
"=>",
"true",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"\"Shares?{$parameters}\"",
",",
"$",
"options",
")",
";",
"}"
] |
Share Share for external user.
@param array $options Share options
@param bool $notify Indicates whether user will be notified if item is downloaded (optional)
@return array
|
[
"Share",
"Share",
"for",
"external",
"user",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L487-L497
|
224,931
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.getItemAccessControls
|
public function getItemAccessControls(string $itemId, string $userId = ''):array
{
if (! empty($userId)) {
return $this->get("AccessControls(principalid={$userId},itemid={$itemId})");
} else {
return $this->get("Items({$itemId})/AccessControls");
}
}
|
php
|
public function getItemAccessControls(string $itemId, string $userId = ''):array
{
if (! empty($userId)) {
return $this->get("AccessControls(principalid={$userId},itemid={$itemId})");
} else {
return $this->get("Items({$itemId})/AccessControls");
}
}
|
[
"public",
"function",
"getItemAccessControls",
"(",
"string",
"$",
"itemId",
",",
"string",
"$",
"userId",
"=",
"''",
")",
":",
"array",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"userId",
")",
")",
"{",
"return",
"$",
"this",
"->",
"get",
"(",
"\"AccessControls(principalid={$userId},itemid={$itemId})\"",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"get",
"(",
"\"Items({$itemId})/AccessControls\"",
")",
";",
"}",
"}"
] |
Get AccessControl List for an item.
@param string $itemId Id of an item
@param string $userId Id of an user
@return array
|
[
"Get",
"AccessControl",
"List",
"for",
"an",
"item",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L507-L514
|
224,932
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.uploadChunk
|
protected function uploadChunk($uri, $data)
{
$response = $this->client->request(
'POST',
$uri,
[
'headers' => [
'Content-Length' => strlen($data),
'Content-Type' => 'application/octet-stream',
],
'body' => $data,
]
);
return (string) $response->getBody();
}
|
php
|
protected function uploadChunk($uri, $data)
{
$response = $this->client->request(
'POST',
$uri,
[
'headers' => [
'Content-Length' => strlen($data),
'Content-Type' => 'application/octet-stream',
],
'body' => $data,
]
);
return (string) $response->getBody();
}
|
[
"protected",
"function",
"uploadChunk",
"(",
"$",
"uri",
",",
"$",
"data",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'POST'",
",",
"$",
"uri",
",",
"[",
"'headers'",
"=>",
"[",
"'Content-Length'",
"=>",
"strlen",
"(",
"$",
"data",
")",
",",
"'Content-Type'",
"=>",
"'application/octet-stream'",
",",
"]",
",",
"'body'",
"=>",
"$",
"data",
",",
"]",
")",
";",
"return",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}"
] |
Upload a chunk of data using HTTP POST body.
@param string $uri Upload URI
@param string $data Contents to upload
@return string|array
|
[
"Upload",
"a",
"chunk",
"of",
"data",
"using",
"HTTP",
"POST",
"body",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L613-L628
|
224,933
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.determineException
|
protected function determineException(ClientException $exception): Exception
{
if (in_array($exception->getResponse()->getStatusCode(), [400, 403, 404, 409])) {
return new BadRequest($exception->getResponse());
}
return $exception;
}
|
php
|
protected function determineException(ClientException $exception): Exception
{
if (in_array($exception->getResponse()->getStatusCode(), [400, 403, 404, 409])) {
return new BadRequest($exception->getResponse());
}
return $exception;
}
|
[
"protected",
"function",
"determineException",
"(",
"ClientException",
"$",
"exception",
")",
":",
"Exception",
"{",
"if",
"(",
"in_array",
"(",
"$",
"exception",
"->",
"getResponse",
"(",
")",
"->",
"getStatusCode",
"(",
")",
",",
"[",
"400",
",",
"403",
",",
"404",
",",
"409",
"]",
")",
")",
"{",
"return",
"new",
"BadRequest",
"(",
"$",
"exception",
"->",
"getResponse",
"(",
")",
")",
";",
"}",
"return",
"$",
"exception",
";",
"}"
] |
Handle ClientException.
@param ClientException $exception ClientException
@return Exception
|
[
"Handle",
"ClientException",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L663-L670
|
224,934
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.buildHttpQuery
|
protected function buildHttpQuery(array $parameters):string
{
return http_build_query(
array_map(
function ($parameter) {
if (! is_bool($parameter)) {
return $parameter;
}
return $parameter ? 'true' : 'false';
},
$parameters
)
);
}
|
php
|
protected function buildHttpQuery(array $parameters):string
{
return http_build_query(
array_map(
function ($parameter) {
if (! is_bool($parameter)) {
return $parameter;
}
return $parameter ? 'true' : 'false';
},
$parameters
)
);
}
|
[
"protected",
"function",
"buildHttpQuery",
"(",
"array",
"$",
"parameters",
")",
":",
"string",
"{",
"return",
"http_build_query",
"(",
"array_map",
"(",
"function",
"(",
"$",
"parameter",
")",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"parameter",
")",
")",
"{",
"return",
"$",
"parameter",
";",
"}",
"return",
"$",
"parameter",
"?",
"'true'",
":",
"'false'",
";",
"}",
",",
"$",
"parameters",
")",
")",
";",
"}"
] |
Build HTTP query.
@param array $parameters Query parameters
@return string
|
[
"Build",
"HTTP",
"query",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L679-L693
|
224,935
|
kapersoft/sharefile-api
|
src/Client.php
|
Client.jsonValidator
|
protected function jsonValidator($data = null):bool
{
if (! empty($data)) {
@json_decode($data);
return json_last_error() === JSON_ERROR_NONE;
}
return false;
}
|
php
|
protected function jsonValidator($data = null):bool
{
if (! empty($data)) {
@json_decode($data);
return json_last_error() === JSON_ERROR_NONE;
}
return false;
}
|
[
"protected",
"function",
"jsonValidator",
"(",
"$",
"data",
"=",
"null",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"@",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"json_last_error",
"(",
")",
"===",
"JSON_ERROR_NONE",
";",
"}",
"return",
"false",
";",
"}"
] |
Validate JSON.
@param mixed $data JSON variable
@return bool
|
[
"Validate",
"JSON",
"."
] |
b2e8e0fce018e102a914aa4323d41ff3a953d3b9
|
https://github.com/kapersoft/sharefile-api/blob/b2e8e0fce018e102a914aa4323d41ff3a953d3b9/src/Client.php#L702-L711
|
224,936
|
moeen-basra/laravel-passport-mongodb
|
src/Passport.php
|
Passport.routes
|
public static function routes($callback = null, array $options = [])
{
$callback = $callback ?: function ($router) {
$router->all();
};
$defaultOptions = [
'prefix' => 'oauth',
'namespace' => '\MoeenBasra\LaravelPassportMongoDB\Http\Controllers',
];
$options = array_merge($defaultOptions, $options);
Route::group($options, function ($router) use ($callback) {
$callback(new RouteRegistrar($router));
});
}
|
php
|
public static function routes($callback = null, array $options = [])
{
$callback = $callback ?: function ($router) {
$router->all();
};
$defaultOptions = [
'prefix' => 'oauth',
'namespace' => '\MoeenBasra\LaravelPassportMongoDB\Http\Controllers',
];
$options = array_merge($defaultOptions, $options);
Route::group($options, function ($router) use ($callback) {
$callback(new RouteRegistrar($router));
});
}
|
[
"public",
"static",
"function",
"routes",
"(",
"$",
"callback",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"callback",
"=",
"$",
"callback",
"?",
":",
"function",
"(",
"$",
"router",
")",
"{",
"$",
"router",
"->",
"all",
"(",
")",
";",
"}",
";",
"$",
"defaultOptions",
"=",
"[",
"'prefix'",
"=>",
"'oauth'",
",",
"'namespace'",
"=>",
"'\\MoeenBasra\\LaravelPassportMongoDB\\Http\\Controllers'",
",",
"]",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"defaultOptions",
",",
"$",
"options",
")",
";",
"Route",
"::",
"group",
"(",
"$",
"options",
",",
"function",
"(",
"$",
"router",
")",
"use",
"(",
"$",
"callback",
")",
"{",
"$",
"callback",
"(",
"new",
"RouteRegistrar",
"(",
"$",
"router",
")",
")",
";",
"}",
")",
";",
"}"
] |
Binds the Passport routes into the controller.
@param callable|null $callback
@param array $options
@return void
|
[
"Binds",
"the",
"Passport",
"routes",
"into",
"the",
"controller",
"."
] |
738261912672e39f9f4f4e5bf420b99dbe303ef8
|
https://github.com/moeen-basra/laravel-passport-mongodb/blob/738261912672e39f9f4f4e5bf420b99dbe303ef8/src/Passport.php#L104-L120
|
224,937
|
moeen-basra/laravel-passport-mongodb
|
src/Passport.php
|
Passport.scopesFor
|
public static function scopesFor(array $ids)
{
return collect($ids)->map(function ($id) {
if (isset(static::$scopes[$id])) {
return new Scope($id, static::$scopes[$id]);
}
return;
})->filter()->values()->all();
}
|
php
|
public static function scopesFor(array $ids)
{
return collect($ids)->map(function ($id) {
if (isset(static::$scopes[$id])) {
return new Scope($id, static::$scopes[$id]);
}
return;
})->filter()->values()->all();
}
|
[
"public",
"static",
"function",
"scopesFor",
"(",
"array",
"$",
"ids",
")",
"{",
"return",
"collect",
"(",
"$",
"ids",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"scopes",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"new",
"Scope",
"(",
"$",
"id",
",",
"static",
"::",
"$",
"scopes",
"[",
"$",
"id",
"]",
")",
";",
"}",
"return",
";",
"}",
")",
"->",
"filter",
"(",
")",
"->",
"values",
"(",
")",
"->",
"all",
"(",
")",
";",
"}"
] |
Get all of the scopes matching the given IDs.
@param array $ids
@return array
|
[
"Get",
"all",
"of",
"the",
"scopes",
"matching",
"the",
"given",
"IDs",
"."
] |
738261912672e39f9f4f4e5bf420b99dbe303ef8
|
https://github.com/moeen-basra/laravel-passport-mongodb/blob/738261912672e39f9f4f4e5bf420b99dbe303ef8/src/Passport.php#L198-L207
|
224,938
|
ongr-io/TranslationsBundle
|
Service/Export/YmlExport.php
|
YmlExport.export
|
public function export($file, $translations)
{
$bytes = false;
if (pathinfo($file, PATHINFO_EXTENSION) === 'yml') {
$ymlDumper = new Dumper();
$ymlContent = '';
$ymlContent .= $ymlDumper->dump($translations, 10);
$bytes = file_put_contents($file, $ymlContent);
}
return ($bytes !== false);
}
|
php
|
public function export($file, $translations)
{
$bytes = false;
if (pathinfo($file, PATHINFO_EXTENSION) === 'yml') {
$ymlDumper = new Dumper();
$ymlContent = '';
$ymlContent .= $ymlDumper->dump($translations, 10);
$bytes = file_put_contents($file, $ymlContent);
}
return ($bytes !== false);
}
|
[
"public",
"function",
"export",
"(",
"$",
"file",
",",
"$",
"translations",
")",
"{",
"$",
"bytes",
"=",
"false",
";",
"if",
"(",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
"===",
"'yml'",
")",
"{",
"$",
"ymlDumper",
"=",
"new",
"Dumper",
"(",
")",
";",
"$",
"ymlContent",
"=",
"''",
";",
"$",
"ymlContent",
".=",
"$",
"ymlDumper",
"->",
"dump",
"(",
"$",
"translations",
",",
"10",
")",
";",
"$",
"bytes",
"=",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"ymlContent",
")",
";",
"}",
"return",
"(",
"$",
"bytes",
"!==",
"false",
")",
";",
"}"
] |
Export translations in to the given file.
@param string $file
@param array $translations
@return bool
|
[
"Export",
"translations",
"in",
"to",
"the",
"given",
"file",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/Export/YmlExport.php#L29-L41
|
224,939
|
lucisgit/php-panopto-api
|
examples/samplelib.php
|
panopto_interface.get_recorders
|
function get_recorders($page, $perpage) {
try {
$pagination = new \Panopto\RemoteRecorderManagement\Pagination();
$pagination->setPageNumber($page);
$pagination->setMaxNumberResults($perpage);
$param = new \Panopto\RemoteRecorderManagement\ListRecorders($this->auth, $pagination, 'Name');
$recorderslist = $this->rrmclient->ListRecorders($param)->getListRecordersResult();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return array('count' => $recorderslist->TotalResultCount, 'recorders' => $recorderslist->PagedResults->getRemoteRecorder());
}
|
php
|
function get_recorders($page, $perpage) {
try {
$pagination = new \Panopto\RemoteRecorderManagement\Pagination();
$pagination->setPageNumber($page);
$pagination->setMaxNumberResults($perpage);
$param = new \Panopto\RemoteRecorderManagement\ListRecorders($this->auth, $pagination, 'Name');
$recorderslist = $this->rrmclient->ListRecorders($param)->getListRecordersResult();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return array('count' => $recorderslist->TotalResultCount, 'recorders' => $recorderslist->PagedResults->getRemoteRecorder());
}
|
[
"function",
"get_recorders",
"(",
"$",
"page",
",",
"$",
"perpage",
")",
"{",
"try",
"{",
"$",
"pagination",
"=",
"new",
"\\",
"Panopto",
"\\",
"RemoteRecorderManagement",
"\\",
"Pagination",
"(",
")",
";",
"$",
"pagination",
"->",
"setPageNumber",
"(",
"$",
"page",
")",
";",
"$",
"pagination",
"->",
"setMaxNumberResults",
"(",
"$",
"perpage",
")",
";",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"RemoteRecorderManagement",
"\\",
"ListRecorders",
"(",
"$",
"this",
"->",
"auth",
",",
"$",
"pagination",
",",
"'Name'",
")",
";",
"$",
"recorderslist",
"=",
"$",
"this",
"->",
"rrmclient",
"->",
"ListRecorders",
"(",
"$",
"param",
")",
"->",
"getListRecordersResult",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SoapFault",
"(",
"'client'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"array",
"(",
"'count'",
"=>",
"$",
"recorderslist",
"->",
"TotalResultCount",
",",
"'recorders'",
"=>",
"$",
"recorderslist",
"->",
"PagedResults",
"->",
"getRemoteRecorder",
"(",
")",
")",
";",
"}"
] |
Get the list of remote recorders.
@param int $page The number of page for pagination.
@param int $perpage The number of items per page for pagination.
@return array of the structure ('count' => int total number of records, 'recorders' => array of RemoteRecorder instances).
|
[
"Get",
"the",
"list",
"of",
"remote",
"recorders",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/examples/samplelib.php#L87-L98
|
224,940
|
lucisgit/php-panopto-api
|
examples/samplelib.php
|
panopto_interface.get_recorder
|
function get_recorder($id) {
try {
$param = new \Panopto\RemoteRecorderManagement\GetRemoteRecordersById($this->auth, array($id));
$recorder = $this->rrmclient->GetRemoteRecordersById($param)->getGetRemoteRecordersByIdResult();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return $recorder->getRemoteRecorder()[0];
}
|
php
|
function get_recorder($id) {
try {
$param = new \Panopto\RemoteRecorderManagement\GetRemoteRecordersById($this->auth, array($id));
$recorder = $this->rrmclient->GetRemoteRecordersById($param)->getGetRemoteRecordersByIdResult();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return $recorder->getRemoteRecorder()[0];
}
|
[
"function",
"get_recorder",
"(",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"RemoteRecorderManagement",
"\\",
"GetRemoteRecordersById",
"(",
"$",
"this",
"->",
"auth",
",",
"array",
"(",
"$",
"id",
")",
")",
";",
"$",
"recorder",
"=",
"$",
"this",
"->",
"rrmclient",
"->",
"GetRemoteRecordersById",
"(",
"$",
"param",
")",
"->",
"getGetRemoteRecordersByIdResult",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SoapFault",
"(",
"'client'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"recorder",
"->",
"getRemoteRecorder",
"(",
")",
"[",
"0",
"]",
";",
"}"
] |
Get the single remote recorder instance.
@param string $id The Id of remote recorder.
@return stdClass RemoteRecorder instance.
|
[
"Get",
"the",
"single",
"remote",
"recorder",
"instance",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/examples/samplelib.php#L106-L114
|
224,941
|
lucisgit/php-panopto-api
|
examples/samplelib.php
|
panopto_interface.get_recorders_by_external_id
|
function get_recorders_by_external_id($externalid) {
try {
$param = new \Panopto\RemoteRecorderManagement\GetRemoteRecordersByExternalId($this->auth, array($externalid));
$recorders = $this->rrmclient->GetRemoteRecordersByExternalId($param)->getGetRemoteRecordersByExternalIdResult();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
if (count($recorders)) {
return $recorders;
}
return false;
}
|
php
|
function get_recorders_by_external_id($externalid) {
try {
$param = new \Panopto\RemoteRecorderManagement\GetRemoteRecordersByExternalId($this->auth, array($externalid));
$recorders = $this->rrmclient->GetRemoteRecordersByExternalId($param)->getGetRemoteRecordersByExternalIdResult();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
if (count($recorders)) {
return $recorders;
}
return false;
}
|
[
"function",
"get_recorders_by_external_id",
"(",
"$",
"externalid",
")",
"{",
"try",
"{",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"RemoteRecorderManagement",
"\\",
"GetRemoteRecordersByExternalId",
"(",
"$",
"this",
"->",
"auth",
",",
"array",
"(",
"$",
"externalid",
")",
")",
";",
"$",
"recorders",
"=",
"$",
"this",
"->",
"rrmclient",
"->",
"GetRemoteRecordersByExternalId",
"(",
"$",
"param",
")",
"->",
"getGetRemoteRecordersByExternalIdResult",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SoapFault",
"(",
"'client'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"recorders",
")",
")",
"{",
"return",
"$",
"recorders",
";",
"}",
"return",
"false",
";",
"}"
] |
Get the remote recorders instances by ExternalID.
@param string $externalid External Id of remote recorder.
@return stdClass ArrayOfRemoteRecorder instance.
|
[
"Get",
"the",
"remote",
"recorders",
"instances",
"by",
"ExternalID",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/examples/samplelib.php#L122-L133
|
224,942
|
lucisgit/php-panopto-api
|
examples/samplelib.php
|
panopto_interface.set_recorder_externalid
|
function set_recorder_externalid($id, $externalid) {
if ($externalid === 'NULL') {
$externalid = null;
}
try {
$param = new \Panopto\RemoteRecorderManagement\UpdateRemoteRecorderExternalId($this->auth, $id, $externalid);
$result = $this->rrmclient->UpdateRemoteRecorderExternalId($param);
} catch (Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return $result;
}
|
php
|
function set_recorder_externalid($id, $externalid) {
if ($externalid === 'NULL') {
$externalid = null;
}
try {
$param = new \Panopto\RemoteRecorderManagement\UpdateRemoteRecorderExternalId($this->auth, $id, $externalid);
$result = $this->rrmclient->UpdateRemoteRecorderExternalId($param);
} catch (Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return $result;
}
|
[
"function",
"set_recorder_externalid",
"(",
"$",
"id",
",",
"$",
"externalid",
")",
"{",
"if",
"(",
"$",
"externalid",
"===",
"'NULL'",
")",
"{",
"$",
"externalid",
"=",
"null",
";",
"}",
"try",
"{",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"RemoteRecorderManagement",
"\\",
"UpdateRemoteRecorderExternalId",
"(",
"$",
"this",
"->",
"auth",
",",
"$",
"id",
",",
"$",
"externalid",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"rrmclient",
"->",
"UpdateRemoteRecorderExternalId",
"(",
"$",
"param",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SoapFault",
"(",
"'client'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Set ExternalID for remote recorder.
@param string $id Remote recorder id.
@param string $externalid External Id of remote recorder.
@return stdClass RemoteRecorder instance.
|
[
"Set",
"ExternalID",
"for",
"remote",
"recorder",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/examples/samplelib.php#L143-L154
|
224,943
|
lucisgit/php-panopto-api
|
examples/samplelib.php
|
panopto_interface.schedule_recording
|
function schedule_recording($name, $folderid, $start, $end, $primaryrecorderid, $secondaryrecorderid = '', $isbroadcast = false) {
$recordersettings = array();
$primaryrecorder = $this->get_recorder($primaryrecorderid);
$recordersetting = new \Panopto\RemoteRecorderManagement\RecorderSettings();
$recordersetting->setRecorderId($primaryrecorder->getId());
$recordersetting->setSuppressPrimary(false);
$recordersetting->setSuppressSecondary(false);
$recordersettings[] = $recordersetting;
if ($secondaryrecorderid) {
$secondaryrecorder = $this->get_recorder($secondaryrecorderid);
$recordersetting = new \Panopto\RemoteRecorderManagement\RecorderSettings();
$recordersetting->setRecorderId($secondaryrecorder->getId());
$recordersetting->setSuppressPrimary(true);
$recordersetting->setSuppressSecondary(false);
$recordersettings[] = $recordersetting;
}
$params = new \Panopto\RemoteRecorderManagement\ScheduleRecording($this->auth, $name, $folderid, $isbroadcast, $start, $end, $recordersettings);
$response = $this->rrmclient->ScheduleRecording($params)->getScheduleRecordingResult();
return $response;
}
|
php
|
function schedule_recording($name, $folderid, $start, $end, $primaryrecorderid, $secondaryrecorderid = '', $isbroadcast = false) {
$recordersettings = array();
$primaryrecorder = $this->get_recorder($primaryrecorderid);
$recordersetting = new \Panopto\RemoteRecorderManagement\RecorderSettings();
$recordersetting->setRecorderId($primaryrecorder->getId());
$recordersetting->setSuppressPrimary(false);
$recordersetting->setSuppressSecondary(false);
$recordersettings[] = $recordersetting;
if ($secondaryrecorderid) {
$secondaryrecorder = $this->get_recorder($secondaryrecorderid);
$recordersetting = new \Panopto\RemoteRecorderManagement\RecorderSettings();
$recordersetting->setRecorderId($secondaryrecorder->getId());
$recordersetting->setSuppressPrimary(true);
$recordersetting->setSuppressSecondary(false);
$recordersettings[] = $recordersetting;
}
$params = new \Panopto\RemoteRecorderManagement\ScheduleRecording($this->auth, $name, $folderid, $isbroadcast, $start, $end, $recordersettings);
$response = $this->rrmclient->ScheduleRecording($params)->getScheduleRecordingResult();
return $response;
}
|
[
"function",
"schedule_recording",
"(",
"$",
"name",
",",
"$",
"folderid",
",",
"$",
"start",
",",
"$",
"end",
",",
"$",
"primaryrecorderid",
",",
"$",
"secondaryrecorderid",
"=",
"''",
",",
"$",
"isbroadcast",
"=",
"false",
")",
"{",
"$",
"recordersettings",
"=",
"array",
"(",
")",
";",
"$",
"primaryrecorder",
"=",
"$",
"this",
"->",
"get_recorder",
"(",
"$",
"primaryrecorderid",
")",
";",
"$",
"recordersetting",
"=",
"new",
"\\",
"Panopto",
"\\",
"RemoteRecorderManagement",
"\\",
"RecorderSettings",
"(",
")",
";",
"$",
"recordersetting",
"->",
"setRecorderId",
"(",
"$",
"primaryrecorder",
"->",
"getId",
"(",
")",
")",
";",
"$",
"recordersetting",
"->",
"setSuppressPrimary",
"(",
"false",
")",
";",
"$",
"recordersetting",
"->",
"setSuppressSecondary",
"(",
"false",
")",
";",
"$",
"recordersettings",
"[",
"]",
"=",
"$",
"recordersetting",
";",
"if",
"(",
"$",
"secondaryrecorderid",
")",
"{",
"$",
"secondaryrecorder",
"=",
"$",
"this",
"->",
"get_recorder",
"(",
"$",
"secondaryrecorderid",
")",
";",
"$",
"recordersetting",
"=",
"new",
"\\",
"Panopto",
"\\",
"RemoteRecorderManagement",
"\\",
"RecorderSettings",
"(",
")",
";",
"$",
"recordersetting",
"->",
"setRecorderId",
"(",
"$",
"secondaryrecorder",
"->",
"getId",
"(",
")",
")",
";",
"$",
"recordersetting",
"->",
"setSuppressPrimary",
"(",
"true",
")",
";",
"$",
"recordersetting",
"->",
"setSuppressSecondary",
"(",
"false",
")",
";",
"$",
"recordersettings",
"[",
"]",
"=",
"$",
"recordersetting",
";",
"}",
"$",
"params",
"=",
"new",
"\\",
"Panopto",
"\\",
"RemoteRecorderManagement",
"\\",
"ScheduleRecording",
"(",
"$",
"this",
"->",
"auth",
",",
"$",
"name",
",",
"$",
"folderid",
",",
"$",
"isbroadcast",
",",
"$",
"start",
",",
"$",
"end",
",",
"$",
"recordersettings",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"rrmclient",
"->",
"ScheduleRecording",
"(",
"$",
"params",
")",
"->",
"getScheduleRecordingResult",
"(",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Schedule a new recording.
@param string $name Session name
@param string $folderid Remote folder id.
@param string $start Session start time.
@param string $end Session end time.
@param string $primaryrecorderid Remote recorder id to be used as primary.
@param string $secondaryrecorderid Remote recorder id to be used as secondary.
@param bool $isbroadcast.
@return stdClass ScheduleRecordingResponse instance.
|
[
"Schedule",
"a",
"new",
"recording",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/examples/samplelib.php#L168-L190
|
224,944
|
lucisgit/php-panopto-api
|
examples/samplelib.php
|
panopto_interface.add_folder
|
function add_folder($name, $externalid, $parentfolderid = '') {
// Check parent folder existense first.
if (empty($parentfolderid)) {
$parentfolderid = null;
} else {
$param = new \Panopto\SessionManagement\GetFoldersById($this->auth, array($parentfolderid));
$folders = $this->smclient->GetFoldersById($param)->getGetFoldersByIdResult();
if (!count($folders)) {
throw new SoapFault('client', "Folder $parentfolderid does not exist.");
}
}
// Add new folder.
try {
$param = new \Panopto\SessionManagement\AddFolder($this->auth, $name, $parentfolderid, false);
$folderid = $this->smclient->AddFolder($param)->getAddFolderResult()->getId();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
// Update folder external ID.
try {
$param = new \Panopto\SessionManagement\UpdateFolderExternalId($this->auth, $folderid, $externalid);
$this->smclient->UpdateFolderExternalId($param);
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return $folderid;
}
|
php
|
function add_folder($name, $externalid, $parentfolderid = '') {
// Check parent folder existense first.
if (empty($parentfolderid)) {
$parentfolderid = null;
} else {
$param = new \Panopto\SessionManagement\GetFoldersById($this->auth, array($parentfolderid));
$folders = $this->smclient->GetFoldersById($param)->getGetFoldersByIdResult();
if (!count($folders)) {
throw new SoapFault('client', "Folder $parentfolderid does not exist.");
}
}
// Add new folder.
try {
$param = new \Panopto\SessionManagement\AddFolder($this->auth, $name, $parentfolderid, false);
$folderid = $this->smclient->AddFolder($param)->getAddFolderResult()->getId();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
// Update folder external ID.
try {
$param = new \Panopto\SessionManagement\UpdateFolderExternalId($this->auth, $folderid, $externalid);
$this->smclient->UpdateFolderExternalId($param);
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return $folderid;
}
|
[
"function",
"add_folder",
"(",
"$",
"name",
",",
"$",
"externalid",
",",
"$",
"parentfolderid",
"=",
"''",
")",
"{",
"// Check parent folder existense first.",
"if",
"(",
"empty",
"(",
"$",
"parentfolderid",
")",
")",
"{",
"$",
"parentfolderid",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"SessionManagement",
"\\",
"GetFoldersById",
"(",
"$",
"this",
"->",
"auth",
",",
"array",
"(",
"$",
"parentfolderid",
")",
")",
";",
"$",
"folders",
"=",
"$",
"this",
"->",
"smclient",
"->",
"GetFoldersById",
"(",
"$",
"param",
")",
"->",
"getGetFoldersByIdResult",
"(",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"folders",
")",
")",
"{",
"throw",
"new",
"SoapFault",
"(",
"'client'",
",",
"\"Folder $parentfolderid does not exist.\"",
")",
";",
"}",
"}",
"// Add new folder.",
"try",
"{",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"SessionManagement",
"\\",
"AddFolder",
"(",
"$",
"this",
"->",
"auth",
",",
"$",
"name",
",",
"$",
"parentfolderid",
",",
"false",
")",
";",
"$",
"folderid",
"=",
"$",
"this",
"->",
"smclient",
"->",
"AddFolder",
"(",
"$",
"param",
")",
"->",
"getAddFolderResult",
"(",
")",
"->",
"getId",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SoapFault",
"(",
"'client'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"// Update folder external ID.",
"try",
"{",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"SessionManagement",
"\\",
"UpdateFolderExternalId",
"(",
"$",
"this",
"->",
"auth",
",",
"$",
"folderid",
",",
"$",
"externalid",
")",
";",
"$",
"this",
"->",
"smclient",
"->",
"UpdateFolderExternalId",
"(",
"$",
"param",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SoapFault",
"(",
"'client'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"folderid",
";",
"}"
] |
Create a new folder and assign it an external id.
@param str $name Folder name.
@param str $externalid External ID of the folder.
@param str $parentfolderid Parent folder internal id.
@return str $folderid Folder id.
|
[
"Create",
"a",
"new",
"folder",
"and",
"assign",
"it",
"an",
"external",
"id",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/examples/samplelib.php#L200-L229
|
224,945
|
lucisgit/php-panopto-api
|
examples/samplelib.php
|
panopto_interface.get_folderid_by_externalid
|
function get_folderid_by_externalid($externalid) {
try {
$param = new \Panopto\SessionManagement\GetFoldersByExternalId($this->auth, array($externalid));
$folders = $this->smclient->GetFoldersByExternalId($param)->getGetFoldersByExternalIdResult();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
if (count($folders)) {
return $folders[0]->getId();
}
return false;
}
|
php
|
function get_folderid_by_externalid($externalid) {
try {
$param = new \Panopto\SessionManagement\GetFoldersByExternalId($this->auth, array($externalid));
$folders = $this->smclient->GetFoldersByExternalId($param)->getGetFoldersByExternalIdResult();
} catch(Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
if (count($folders)) {
return $folders[0]->getId();
}
return false;
}
|
[
"function",
"get_folderid_by_externalid",
"(",
"$",
"externalid",
")",
"{",
"try",
"{",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"SessionManagement",
"\\",
"GetFoldersByExternalId",
"(",
"$",
"this",
"->",
"auth",
",",
"array",
"(",
"$",
"externalid",
")",
")",
";",
"$",
"folders",
"=",
"$",
"this",
"->",
"smclient",
"->",
"GetFoldersByExternalId",
"(",
"$",
"param",
")",
"->",
"getGetFoldersByExternalIdResult",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SoapFault",
"(",
"'client'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"folders",
")",
")",
"{",
"return",
"$",
"folders",
"[",
"0",
"]",
"->",
"getId",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Get the single folderid by external id.
@param string $externalid Folder external id.
@return mixed $folderid Folder id or false if no folder is found.
|
[
"Get",
"the",
"single",
"folderid",
"by",
"external",
"id",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/examples/samplelib.php#L237-L248
|
224,946
|
lucisgit/php-panopto-api
|
examples/samplelib.php
|
panopto_interface.delete_session
|
function delete_session($sessionid) {
try {
$param = new \Panopto\SessionManagement\DeleteSessions($this->auth, array($sessionid));
$this->smclient->DeleteSessions($param);
} catch (Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return true;
}
|
php
|
function delete_session($sessionid) {
try {
$param = new \Panopto\SessionManagement\DeleteSessions($this->auth, array($sessionid));
$this->smclient->DeleteSessions($param);
} catch (Exception $e) {
throw new SoapFault('client', $e->getMessage());
}
return true;
}
|
[
"function",
"delete_session",
"(",
"$",
"sessionid",
")",
"{",
"try",
"{",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"SessionManagement",
"\\",
"DeleteSessions",
"(",
"$",
"this",
"->",
"auth",
",",
"array",
"(",
"$",
"sessionid",
")",
")",
";",
"$",
"this",
"->",
"smclient",
"->",
"DeleteSessions",
"(",
"$",
"param",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"SoapFault",
"(",
"'client'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Delete session.
@param string $sessionid Remote session id.
@param string $externalid External Id of remote recorder.
@return bool true.
|
[
"Delete",
"session",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/examples/samplelib.php#L347-L355
|
224,947
|
lucisgit/php-panopto-api
|
examples/samplelib.php
|
panopto_interface.get_session_by_id
|
function get_session_by_id($sessionid) {
try {
$param = new \Panopto\SessionManagement\GetSessionsById($this->auth, array($sessionid));
$sessions = $this->smclient->GetSessionsById($param)->getGetSessionsByIdResult()->getSession();
} catch (Exception $e) {
return false;
}
if (count($sessions)) {
return $sessions[0];
}
return false;
}
|
php
|
function get_session_by_id($sessionid) {
try {
$param = new \Panopto\SessionManagement\GetSessionsById($this->auth, array($sessionid));
$sessions = $this->smclient->GetSessionsById($param)->getGetSessionsByIdResult()->getSession();
} catch (Exception $e) {
return false;
}
if (count($sessions)) {
return $sessions[0];
}
return false;
}
|
[
"function",
"get_session_by_id",
"(",
"$",
"sessionid",
")",
"{",
"try",
"{",
"$",
"param",
"=",
"new",
"\\",
"Panopto",
"\\",
"SessionManagement",
"\\",
"GetSessionsById",
"(",
"$",
"this",
"->",
"auth",
",",
"array",
"(",
"$",
"sessionid",
")",
")",
";",
"$",
"sessions",
"=",
"$",
"this",
"->",
"smclient",
"->",
"GetSessionsById",
"(",
"$",
"param",
")",
"->",
"getGetSessionsByIdResult",
"(",
")",
"->",
"getSession",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"sessions",
")",
")",
"{",
"return",
"$",
"sessions",
"[",
"0",
"]",
";",
"}",
"return",
"false",
";",
"}"
] |
Get session by id.
@param string $sessionid Remote session id.
@return mixed Session object on success, false on failure.
|
[
"Get",
"session",
"by",
"id",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/examples/samplelib.php#L363-L374
|
224,948
|
thephpleague/di
|
src/League/Di/Container.php
|
Container.build
|
public function build($concrete)
{
$reflection = new \ReflectionClass($concrete);
if (! $reflection->isInstantiable()) {
throw new \InvalidArgumentException(sprintf('Class %s is not instantiable.', $concrete));
}
$constructor = $reflection->getConstructor();
if (is_null($constructor)) {
return new $concrete;
}
$dependencies = $this->getDependencies($constructor);
return $reflection->newInstanceArgs($dependencies);
}
|
php
|
public function build($concrete)
{
$reflection = new \ReflectionClass($concrete);
if (! $reflection->isInstantiable()) {
throw new \InvalidArgumentException(sprintf('Class %s is not instantiable.', $concrete));
}
$constructor = $reflection->getConstructor();
if (is_null($constructor)) {
return new $concrete;
}
$dependencies = $this->getDependencies($constructor);
return $reflection->newInstanceArgs($dependencies);
}
|
[
"public",
"function",
"build",
"(",
"$",
"concrete",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"concrete",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Class %s is not instantiable.'",
",",
"$",
"concrete",
")",
")",
";",
"}",
"$",
"constructor",
"=",
"$",
"reflection",
"->",
"getConstructor",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"constructor",
")",
")",
"{",
"return",
"new",
"$",
"concrete",
";",
"}",
"$",
"dependencies",
"=",
"$",
"this",
"->",
"getDependencies",
"(",
"$",
"constructor",
")",
";",
"return",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"dependencies",
")",
";",
"}"
] |
Build a concrete instance of a class.
@param string $concrete The name of the class to buld.
@return mixed The instantiated class.
@throws \InvalidArgumentException
|
[
"Build",
"a",
"concrete",
"instance",
"of",
"a",
"class",
"."
] |
5ab97529cc687d65733fc8feb96a8331c4eda4e1
|
https://github.com/thephpleague/di/blob/5ab97529cc687d65733fc8feb96a8331c4eda4e1/src/League/Di/Container.php#L99-L116
|
224,949
|
thephpleague/di
|
src/League/Di/Container.php
|
Container.extend
|
public function extend($binding, \Closure $closure)
{
$rawObject = $this->getRaw($binding);
if (is_null($rawObject)) {
throw new \InvalidArgumentException(sprintf('Cannot extend %s because it has not yet been bound.', $binding));
}
$this->bind($binding, function ($container) use ($closure, $rawObject) {
return $closure($container, $rawObject($container));
});
}
|
php
|
public function extend($binding, \Closure $closure)
{
$rawObject = $this->getRaw($binding);
if (is_null($rawObject)) {
throw new \InvalidArgumentException(sprintf('Cannot extend %s because it has not yet been bound.', $binding));
}
$this->bind($binding, function ($container) use ($closure, $rawObject) {
return $closure($container, $rawObject($container));
});
}
|
[
"public",
"function",
"extend",
"(",
"$",
"binding",
",",
"\\",
"Closure",
"$",
"closure",
")",
"{",
"$",
"rawObject",
"=",
"$",
"this",
"->",
"getRaw",
"(",
"$",
"binding",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"rawObject",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot extend %s because it has not yet been bound.'",
",",
"$",
"binding",
")",
")",
";",
"}",
"$",
"this",
"->",
"bind",
"(",
"$",
"binding",
",",
"function",
"(",
"$",
"container",
")",
"use",
"(",
"$",
"closure",
",",
"$",
"rawObject",
")",
"{",
"return",
"$",
"closure",
"(",
"$",
"container",
",",
"$",
"rawObject",
"(",
"$",
"container",
")",
")",
";",
"}",
")",
";",
"}"
] |
Extend an existing binding.
@param string $binding The name of the binding to extend.
@param \Closure $closure The function to use to extend the existing binding.
@return void
@throws \InvalidArgumentException
|
[
"Extend",
"an",
"existing",
"binding",
"."
] |
5ab97529cc687d65733fc8feb96a8331c4eda4e1
|
https://github.com/thephpleague/di/blob/5ab97529cc687d65733fc8feb96a8331c4eda4e1/src/League/Di/Container.php#L127-L138
|
224,950
|
thephpleague/di
|
src/League/Di/Container.php
|
Container.getDependencies
|
protected function getDependencies(\ReflectionMethod $method)
{
$dependencies = array();
foreach ($method->getParameters() as $param) {
$dependency = $param->getClass();
if (is_null($dependency)) {
if ($param->isOptional()) {
$dependencies[] = $param->getDefaultValue();
continue;
}
} else {
$dependencies[] = $this->resolve($dependency->name);
continue;
}
throw new \InvalidArgumentException('Could not resolve ' . $param->getName());
}
return $dependencies;
}
|
php
|
protected function getDependencies(\ReflectionMethod $method)
{
$dependencies = array();
foreach ($method->getParameters() as $param) {
$dependency = $param->getClass();
if (is_null($dependency)) {
if ($param->isOptional()) {
$dependencies[] = $param->getDefaultValue();
continue;
}
} else {
$dependencies[] = $this->resolve($dependency->name);
continue;
}
throw new \InvalidArgumentException('Could not resolve ' . $param->getName());
}
return $dependencies;
}
|
[
"protected",
"function",
"getDependencies",
"(",
"\\",
"ReflectionMethod",
"$",
"method",
")",
"{",
"$",
"dependencies",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"method",
"->",
"getParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"$",
"dependency",
"=",
"$",
"param",
"->",
"getClass",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"dependency",
")",
")",
"{",
"if",
"(",
"$",
"param",
"->",
"isOptional",
"(",
")",
")",
"{",
"$",
"dependencies",
"[",
"]",
"=",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
";",
"continue",
";",
"}",
"}",
"else",
"{",
"$",
"dependencies",
"[",
"]",
"=",
"$",
"this",
"->",
"resolve",
"(",
"$",
"dependency",
"->",
"name",
")",
";",
"continue",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Could not resolve '",
".",
"$",
"param",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"$",
"dependencies",
";",
"}"
] |
Recursively build the dependency list for the provided method.
@param \ReflectionMethod $method The method for which to obtain dependencies.
@return array An array containing the method dependencies.
@throws \InvalidArgumentException
|
[
"Recursively",
"build",
"the",
"dependency",
"list",
"for",
"the",
"provided",
"method",
"."
] |
5ab97529cc687d65733fc8feb96a8331c4eda4e1
|
https://github.com/thephpleague/di/blob/5ab97529cc687d65733fc8feb96a8331c4eda4e1/src/League/Di/Container.php#L148-L169
|
224,951
|
thephpleague/di
|
src/League/Di/Container.php
|
Container.getRaw
|
public function getRaw($binding)
{
if (isset($this->bindings[$binding])) {
return $this->bindings[$binding];
} elseif (isset($this->parent)) {
return $this->parent->getRaw($binding);
}
return null;
}
|
php
|
public function getRaw($binding)
{
if (isset($this->bindings[$binding])) {
return $this->bindings[$binding];
} elseif (isset($this->parent)) {
return $this->parent->getRaw($binding);
}
return null;
}
|
[
"public",
"function",
"getRaw",
"(",
"$",
"binding",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"bindings",
"[",
"$",
"binding",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"bindings",
"[",
"$",
"binding",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"parent",
")",
")",
"{",
"return",
"$",
"this",
"->",
"parent",
"->",
"getRaw",
"(",
"$",
"binding",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the raw object prior to resolution.
@param string $binding The $binding key to get the raw value from.
@return Definition|\Closure Value of the $binding.
|
[
"Get",
"the",
"raw",
"object",
"prior",
"to",
"resolution",
"."
] |
5ab97529cc687d65733fc8feb96a8331c4eda4e1
|
https://github.com/thephpleague/di/blob/5ab97529cc687d65733fc8feb96a8331c4eda4e1/src/League/Di/Container.php#L178-L187
|
224,952
|
ongr-io/TranslationsBundle
|
Service/Export/ExportManager.php
|
ExportManager.export
|
public function export($domains = [], $force = null)
{
foreach ($this->formExportList($domains, $force) as $file => $translations) {
if (!file_exists($file)) {
(new Filesystem())->touch($file);
}
$currentTranslations = $this->parser->parse(file_get_contents($file)) ?? [];
$currentTranslations = $this->flatten($currentTranslations);
$translations = array_replace_recursive($currentTranslations, $translations);
$this->exporter->export($file, $translations);
}
$this->translationManager->save($this->refresh);
$this->refresh = [];
}
|
php
|
public function export($domains = [], $force = null)
{
foreach ($this->formExportList($domains, $force) as $file => $translations) {
if (!file_exists($file)) {
(new Filesystem())->touch($file);
}
$currentTranslations = $this->parser->parse(file_get_contents($file)) ?? [];
$currentTranslations = $this->flatten($currentTranslations);
$translations = array_replace_recursive($currentTranslations, $translations);
$this->exporter->export($file, $translations);
}
$this->translationManager->save($this->refresh);
$this->refresh = [];
}
|
[
"public",
"function",
"export",
"(",
"$",
"domains",
"=",
"[",
"]",
",",
"$",
"force",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"formExportList",
"(",
"$",
"domains",
",",
"$",
"force",
")",
"as",
"$",
"file",
"=>",
"$",
"translations",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"(",
"new",
"Filesystem",
"(",
")",
")",
"->",
"touch",
"(",
"$",
"file",
")",
";",
"}",
"$",
"currentTranslations",
"=",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
"??",
"[",
"]",
";",
"$",
"currentTranslations",
"=",
"$",
"this",
"->",
"flatten",
"(",
"$",
"currentTranslations",
")",
";",
"$",
"translations",
"=",
"array_replace_recursive",
"(",
"$",
"currentTranslations",
",",
"$",
"translations",
")",
";",
"$",
"this",
"->",
"exporter",
"->",
"export",
"(",
"$",
"file",
",",
"$",
"translations",
")",
";",
"}",
"$",
"this",
"->",
"translationManager",
"->",
"save",
"(",
"$",
"this",
"->",
"refresh",
")",
";",
"$",
"this",
"->",
"refresh",
"=",
"[",
"]",
";",
"}"
] |
Exports translations from ES to files.
@param array $domains To export.
@param bool $force
|
[
"Exports",
"translations",
"from",
"ES",
"to",
"files",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/Export/ExportManager.php#L86-L104
|
224,953
|
ongr-io/TranslationsBundle
|
Service/Export/ExportManager.php
|
ExportManager.flatten
|
private function flatten($array, $prefix = '') {
$result = [];
foreach($array as $key=>$value) {
if(is_array($value)) {
$result = $result + $this->flatten($value, $prefix . $key . '.');
}
else {
$result[$prefix . $key] = $value;
}
}
return $result;
}
|
php
|
private function flatten($array, $prefix = '') {
$result = [];
foreach($array as $key=>$value) {
if(is_array($value)) {
$result = $result + $this->flatten($value, $prefix . $key . '.');
}
else {
$result[$prefix . $key] = $value;
}
}
return $result;
}
|
[
"private",
"function",
"flatten",
"(",
"$",
"array",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"result",
"=",
"$",
"result",
"+",
"$",
"this",
"->",
"flatten",
"(",
"$",
"value",
",",
"$",
"prefix",
".",
"$",
"key",
".",
"'.'",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"prefix",
".",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Flatten multidimensional array and concatenating keys
@param $array
@return array
|
[
"Flatten",
"multidimensional",
"array",
"and",
"concatenating",
"keys"
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/Export/ExportManager.php#L113-L124
|
224,954
|
ongr-io/TranslationsBundle
|
Service/Export/ExportManager.php
|
ExportManager.formExportList
|
private function formExportList($domains, $force)
{
$output = [];
$filters = array_filter([
'messages.locale' => $this->getLocales(),
'domain' => $domains
]);
$translations = $this->translationManager->getAll($filters);
/** @var Translation $translation */
foreach ($translations as $translation) {
$messages = $translation->getMessages();
foreach ($messages as $key => $message) {
if ($message->getStatus() === Message::DIRTY || $force) {
$path = sprintf(
'%s' . DIRECTORY_SEPARATOR . '%s.%s.%s',
$translation->getPath(),
'messages',
$message->getLocale(),
$translation->getFormat()
);
$output[$path][$translation->getKey()] = $message->getMessage();
$message->setStatus(Message::FRESH);
$this->refresh[] = $translation;
}
}
}
return $output;
}
|
php
|
private function formExportList($domains, $force)
{
$output = [];
$filters = array_filter([
'messages.locale' => $this->getLocales(),
'domain' => $domains
]);
$translations = $this->translationManager->getAll($filters);
/** @var Translation $translation */
foreach ($translations as $translation) {
$messages = $translation->getMessages();
foreach ($messages as $key => $message) {
if ($message->getStatus() === Message::DIRTY || $force) {
$path = sprintf(
'%s' . DIRECTORY_SEPARATOR . '%s.%s.%s',
$translation->getPath(),
'messages',
$message->getLocale(),
$translation->getFormat()
);
$output[$path][$translation->getKey()] = $message->getMessage();
$message->setStatus(Message::FRESH);
$this->refresh[] = $translation;
}
}
}
return $output;
}
|
[
"private",
"function",
"formExportList",
"(",
"$",
"domains",
",",
"$",
"force",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"$",
"filters",
"=",
"array_filter",
"(",
"[",
"'messages.locale'",
"=>",
"$",
"this",
"->",
"getLocales",
"(",
")",
",",
"'domain'",
"=>",
"$",
"domains",
"]",
")",
";",
"$",
"translations",
"=",
"$",
"this",
"->",
"translationManager",
"->",
"getAll",
"(",
"$",
"filters",
")",
";",
"/** @var Translation $translation */",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"translation",
")",
"{",
"$",
"messages",
"=",
"$",
"translation",
"->",
"getMessages",
"(",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"key",
"=>",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"message",
"->",
"getStatus",
"(",
")",
"===",
"Message",
"::",
"DIRTY",
"||",
"$",
"force",
")",
"{",
"$",
"path",
"=",
"sprintf",
"(",
"'%s'",
".",
"DIRECTORY_SEPARATOR",
".",
"'%s.%s.%s'",
",",
"$",
"translation",
"->",
"getPath",
"(",
")",
",",
"'messages'",
",",
"$",
"message",
"->",
"getLocale",
"(",
")",
",",
"$",
"translation",
"->",
"getFormat",
"(",
")",
")",
";",
"$",
"output",
"[",
"$",
"path",
"]",
"[",
"$",
"translation",
"->",
"getKey",
"(",
")",
"]",
"=",
"$",
"message",
"->",
"getMessage",
"(",
")",
";",
"$",
"message",
"->",
"setStatus",
"(",
"Message",
"::",
"FRESH",
")",
";",
"$",
"this",
"->",
"refresh",
"[",
"]",
"=",
"$",
"translation",
";",
"}",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] |
Get translations for export.
@param array $domains To read from storage.
@param bool $force Determines if the message status is relevant.
@return array
|
[
"Get",
"translations",
"for",
"export",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/Export/ExportManager.php#L134-L166
|
224,955
|
kzykhys/PHPCsvParser
|
src/KzykHys/CsvParser/Iterator/CsvIterator.php
|
CsvIterator.processEnclosedField
|
private function processEnclosedField($value, array $option)
{
// then, remove enclosure and line feed
$cell = $this->trimEnclosure($value, $option['enclosure']);
// replace the escape sequence "" to "
$cell = $this->unescapeEnclosure($cell, $option['enclosure']);
$this->setCell($cell);
$this->col++;
$this->continue = false;
}
|
php
|
private function processEnclosedField($value, array $option)
{
// then, remove enclosure and line feed
$cell = $this->trimEnclosure($value, $option['enclosure']);
// replace the escape sequence "" to "
$cell = $this->unescapeEnclosure($cell, $option['enclosure']);
$this->setCell($cell);
$this->col++;
$this->continue = false;
}
|
[
"private",
"function",
"processEnclosedField",
"(",
"$",
"value",
",",
"array",
"$",
"option",
")",
"{",
"// then, remove enclosure and line feed",
"$",
"cell",
"=",
"$",
"this",
"->",
"trimEnclosure",
"(",
"$",
"value",
",",
"$",
"option",
"[",
"'enclosure'",
"]",
")",
";",
"// replace the escape sequence \"\" to \"",
"$",
"cell",
"=",
"$",
"this",
"->",
"unescapeEnclosure",
"(",
"$",
"cell",
",",
"$",
"option",
"[",
"'enclosure'",
"]",
")",
";",
"$",
"this",
"->",
"setCell",
"(",
"$",
"cell",
")",
";",
"$",
"this",
"->",
"col",
"++",
";",
"$",
"this",
"->",
"continue",
"=",
"false",
";",
"}"
] |
Process enclosed field
example: "value"
@param string $value Current token
@param array $option Option
|
[
"Process",
"enclosed",
"field"
] |
a7d20bbfe1ec6402d736975571d8f4dcece6b489
|
https://github.com/kzykhys/PHPCsvParser/blob/a7d20bbfe1ec6402d736975571d8f4dcece6b489/src/KzykHys/CsvParser/Iterator/CsvIterator.php#L133-L143
|
224,956
|
kzykhys/PHPCsvParser
|
src/KzykHys/CsvParser/Iterator/CsvIterator.php
|
CsvIterator.processContinuousField
|
private function processContinuousField($value, array $option)
{
$cell = $this->trimLeftEnclosure($value, $option['enclosure']);
$cell = $this->unescapeEnclosure($cell, $option['enclosure']);
$this->setCell($cell);
$this->continue = true;
}
|
php
|
private function processContinuousField($value, array $option)
{
$cell = $this->trimLeftEnclosure($value, $option['enclosure']);
$cell = $this->unescapeEnclosure($cell, $option['enclosure']);
$this->setCell($cell);
$this->continue = true;
}
|
[
"private",
"function",
"processContinuousField",
"(",
"$",
"value",
",",
"array",
"$",
"option",
")",
"{",
"$",
"cell",
"=",
"$",
"this",
"->",
"trimLeftEnclosure",
"(",
"$",
"value",
",",
"$",
"option",
"[",
"'enclosure'",
"]",
")",
";",
"$",
"cell",
"=",
"$",
"this",
"->",
"unescapeEnclosure",
"(",
"$",
"cell",
",",
"$",
"option",
"[",
"'enclosure'",
"]",
")",
";",
"$",
"this",
"->",
"setCell",
"(",
"$",
"cell",
")",
";",
"$",
"this",
"->",
"continue",
"=",
"true",
";",
"}"
] |
Process enclosed and multiple line field
example: "value\n
@param string $value Current token
@param array $option Option
|
[
"Process",
"enclosed",
"and",
"multiple",
"line",
"field"
] |
a7d20bbfe1ec6402d736975571d8f4dcece6b489
|
https://github.com/kzykhys/PHPCsvParser/blob/a7d20bbfe1ec6402d736975571d8f4dcece6b489/src/KzykHys/CsvParser/Iterator/CsvIterator.php#L153-L160
|
224,957
|
kzykhys/PHPCsvParser
|
src/KzykHys/CsvParser/Iterator/CsvIterator.php
|
CsvIterator.processClosingField
|
private function processClosingField($value, array $option)
{
$cell = $this->trimRightEnclosure($value, $option['enclosure']);
$cell = $this->unescapeEnclosure($cell, $option['enclosure']);
$this->joinCell($this->revert . $cell);
$this->continue = false;
$this->col++;
}
|
php
|
private function processClosingField($value, array $option)
{
$cell = $this->trimRightEnclosure($value, $option['enclosure']);
$cell = $this->unescapeEnclosure($cell, $option['enclosure']);
$this->joinCell($this->revert . $cell);
$this->continue = false;
$this->col++;
}
|
[
"private",
"function",
"processClosingField",
"(",
"$",
"value",
",",
"array",
"$",
"option",
")",
"{",
"$",
"cell",
"=",
"$",
"this",
"->",
"trimRightEnclosure",
"(",
"$",
"value",
",",
"$",
"option",
"[",
"'enclosure'",
"]",
")",
";",
"$",
"cell",
"=",
"$",
"this",
"->",
"unescapeEnclosure",
"(",
"$",
"cell",
",",
"$",
"option",
"[",
"'enclosure'",
"]",
")",
";",
"$",
"this",
"->",
"joinCell",
"(",
"$",
"this",
"->",
"revert",
".",
"$",
"cell",
")",
";",
"$",
"this",
"->",
"continue",
"=",
"false",
";",
"$",
"this",
"->",
"col",
"++",
";",
"}"
] |
Process end of enclosure
example: value"
If previous token was not closed, this token is joined,
otherwise this token is a new cell.
@param string $value Current token
@param array $option Option
|
[
"Process",
"end",
"of",
"enclosure"
] |
a7d20bbfe1ec6402d736975571d8f4dcece6b489
|
https://github.com/kzykhys/PHPCsvParser/blob/a7d20bbfe1ec6402d736975571d8f4dcece6b489/src/KzykHys/CsvParser/Iterator/CsvIterator.php#L173-L181
|
224,958
|
kzykhys/PHPCsvParser
|
src/KzykHys/CsvParser/Iterator/CsvIterator.php
|
CsvIterator.processField
|
private function processField($value, array $option)
{
if($this->continue) {
$cell = $this->unescapeEnclosure($value, $option['enclosure']);
$this->joinCell($this->revert . $cell);
} else {
$cell = rtrim($value);
$cell = $this->unescapeEnclosure($cell, $option['enclosure']);
$this->setCell($cell);
$this->col++;
}
}
|
php
|
private function processField($value, array $option)
{
if($this->continue) {
$cell = $this->unescapeEnclosure($value, $option['enclosure']);
$this->joinCell($this->revert . $cell);
} else {
$cell = rtrim($value);
$cell = $this->unescapeEnclosure($cell, $option['enclosure']);
$this->setCell($cell);
$this->col++;
}
}
|
[
"private",
"function",
"processField",
"(",
"$",
"value",
",",
"array",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"continue",
")",
"{",
"$",
"cell",
"=",
"$",
"this",
"->",
"unescapeEnclosure",
"(",
"$",
"value",
",",
"$",
"option",
"[",
"'enclosure'",
"]",
")",
";",
"$",
"this",
"->",
"joinCell",
"(",
"$",
"this",
"->",
"revert",
".",
"$",
"cell",
")",
";",
"}",
"else",
"{",
"$",
"cell",
"=",
"rtrim",
"(",
"$",
"value",
")",
";",
"$",
"cell",
"=",
"$",
"this",
"->",
"unescapeEnclosure",
"(",
"$",
"cell",
",",
"$",
"option",
"[",
"'enclosure'",
"]",
")",
";",
"$",
"this",
"->",
"setCell",
"(",
"$",
"cell",
")",
";",
"$",
"this",
"->",
"col",
"++",
";",
"}",
"}"
] |
Process unenclosed field
example: value
@param string $value Current token
@param array $option Option
|
[
"Process",
"unenclosed",
"field"
] |
a7d20bbfe1ec6402d736975571d8f4dcece6b489
|
https://github.com/kzykhys/PHPCsvParser/blob/a7d20bbfe1ec6402d736975571d8f4dcece6b489/src/KzykHys/CsvParser/Iterator/CsvIterator.php#L191-L202
|
224,959
|
kzykhys/PHPCsvParser
|
src/KzykHys/CsvParser/Iterator/CsvIterator.php
|
CsvIterator.trimEnclosure
|
private function trimEnclosure($value, $enclosure)
{
$value = $this->trimLeftEnclosure($value, $enclosure);
$value = $this->trimRightEnclosure($value, $enclosure);
return $value;
}
|
php
|
private function trimEnclosure($value, $enclosure)
{
$value = $this->trimLeftEnclosure($value, $enclosure);
$value = $this->trimRightEnclosure($value, $enclosure);
return $value;
}
|
[
"private",
"function",
"trimEnclosure",
"(",
"$",
"value",
",",
"$",
"enclosure",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"trimLeftEnclosure",
"(",
"$",
"value",
",",
"$",
"enclosure",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"trimRightEnclosure",
"(",
"$",
"value",
",",
"$",
"enclosure",
")",
";",
"return",
"$",
"value",
";",
"}"
] |
String enclosure string from beginning and end of the string
@param string $value
@param string $enclosure
@return string
|
[
"String",
"enclosure",
"string",
"from",
"beginning",
"and",
"end",
"of",
"the",
"string"
] |
a7d20bbfe1ec6402d736975571d8f4dcece6b489
|
https://github.com/kzykhys/PHPCsvParser/blob/a7d20bbfe1ec6402d736975571d8f4dcece6b489/src/KzykHys/CsvParser/Iterator/CsvIterator.php#L244-L250
|
224,960
|
kzykhys/PHPCsvParser
|
src/KzykHys/CsvParser/Iterator/CsvIterator.php
|
CsvIterator.trimLeftEnclosure
|
private function trimLeftEnclosure($value, $enclosure)
{
if (substr($value, 0, 1) == $enclosure) {
$value = substr($value, 1);
}
return $value;
}
|
php
|
private function trimLeftEnclosure($value, $enclosure)
{
if (substr($value, 0, 1) == $enclosure) {
$value = substr($value, 1);
}
return $value;
}
|
[
"private",
"function",
"trimLeftEnclosure",
"(",
"$",
"value",
",",
"$",
"enclosure",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"1",
")",
"==",
"$",
"enclosure",
")",
"{",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"1",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Strip an enclosure string from beginning of the string
@param string $value
@param string $enclosure
@return string
|
[
"Strip",
"an",
"enclosure",
"string",
"from",
"beginning",
"of",
"the",
"string"
] |
a7d20bbfe1ec6402d736975571d8f4dcece6b489
|
https://github.com/kzykhys/PHPCsvParser/blob/a7d20bbfe1ec6402d736975571d8f4dcece6b489/src/KzykHys/CsvParser/Iterator/CsvIterator.php#L259-L266
|
224,961
|
kzykhys/PHPCsvParser
|
src/KzykHys/CsvParser/Iterator/CsvIterator.php
|
CsvIterator.trimRightEnclosure
|
private function trimRightEnclosure($value, $enclosure)
{
if (substr($value, -1) == $enclosure) {
$value = substr($value, 0, -1);
}
return $value;
}
|
php
|
private function trimRightEnclosure($value, $enclosure)
{
if (substr($value, -1) == $enclosure) {
$value = substr($value, 0, -1);
}
return $value;
}
|
[
"private",
"function",
"trimRightEnclosure",
"(",
"$",
"value",
",",
"$",
"enclosure",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"value",
",",
"-",
"1",
")",
"==",
"$",
"enclosure",
")",
"{",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Strip an enclosure string from end of the string
@param string $value
@param string $enclosure
@return string
|
[
"Strip",
"an",
"enclosure",
"string",
"from",
"end",
"of",
"the",
"string"
] |
a7d20bbfe1ec6402d736975571d8f4dcece6b489
|
https://github.com/kzykhys/PHPCsvParser/blob/a7d20bbfe1ec6402d736975571d8f4dcece6b489/src/KzykHys/CsvParser/Iterator/CsvIterator.php#L275-L282
|
224,962
|
valga/fbns-react
|
src/Lite/ReactMqttClient.php
|
ReactMqttClient.connect
|
public function connect($host, $port, Connection $connection, $timeout = 5)
{
if ($this->isConnected || $this->isConnecting) {
return new RejectedPromise(new \LogicException('The client is already connected.'));
}
$this->isConnecting = true;
$this->isConnected = false;
$this->host = $host;
$this->port = $port;
$deferred = new Deferred();
$this->establishConnection($this->host, $this->port, $timeout)
->then(function (DuplexStreamInterface $stream) use ($connection, $deferred, $timeout) {
$this->stream = $stream;
$this->emit('open', [$connection, $this]);
$this->registerClient($connection, $timeout)
->then(function (ConnectResponsePacket $responsePacket) use ($deferred, $connection) {
$this->isConnecting = false;
$this->isConnected = true;
$this->connection = $connection;
$this->emit('connect', [$responsePacket, $this]);
$deferred->resolve($responsePacket);
})
->otherwise(function (\Exception $e) use ($deferred, $connection) {
$this->isConnecting = false;
$this->emitError($e);
$deferred->reject($e);
if ($this->stream !== null) {
$this->stream->close();
}
$this->emit('close', [$connection, $this]);
});
})
->otherwise(function (\Exception $e) use ($deferred) {
$this->isConnecting = false;
$this->emitError($e);
$deferred->reject($e);
});
return $deferred->promise();
}
|
php
|
public function connect($host, $port, Connection $connection, $timeout = 5)
{
if ($this->isConnected || $this->isConnecting) {
return new RejectedPromise(new \LogicException('The client is already connected.'));
}
$this->isConnecting = true;
$this->isConnected = false;
$this->host = $host;
$this->port = $port;
$deferred = new Deferred();
$this->establishConnection($this->host, $this->port, $timeout)
->then(function (DuplexStreamInterface $stream) use ($connection, $deferred, $timeout) {
$this->stream = $stream;
$this->emit('open', [$connection, $this]);
$this->registerClient($connection, $timeout)
->then(function (ConnectResponsePacket $responsePacket) use ($deferred, $connection) {
$this->isConnecting = false;
$this->isConnected = true;
$this->connection = $connection;
$this->emit('connect', [$responsePacket, $this]);
$deferred->resolve($responsePacket);
})
->otherwise(function (\Exception $e) use ($deferred, $connection) {
$this->isConnecting = false;
$this->emitError($e);
$deferred->reject($e);
if ($this->stream !== null) {
$this->stream->close();
}
$this->emit('close', [$connection, $this]);
});
})
->otherwise(function (\Exception $e) use ($deferred) {
$this->isConnecting = false;
$this->emitError($e);
$deferred->reject($e);
});
return $deferred->promise();
}
|
[
"public",
"function",
"connect",
"(",
"$",
"host",
",",
"$",
"port",
",",
"Connection",
"$",
"connection",
",",
"$",
"timeout",
"=",
"5",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isConnected",
"||",
"$",
"this",
"->",
"isConnecting",
")",
"{",
"return",
"new",
"RejectedPromise",
"(",
"new",
"\\",
"LogicException",
"(",
"'The client is already connected.'",
")",
")",
";",
"}",
"$",
"this",
"->",
"isConnecting",
"=",
"true",
";",
"$",
"this",
"->",
"isConnected",
"=",
"false",
";",
"$",
"this",
"->",
"host",
"=",
"$",
"host",
";",
"$",
"this",
"->",
"port",
"=",
"$",
"port",
";",
"$",
"deferred",
"=",
"new",
"Deferred",
"(",
")",
";",
"$",
"this",
"->",
"establishConnection",
"(",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
",",
"$",
"timeout",
")",
"->",
"then",
"(",
"function",
"(",
"DuplexStreamInterface",
"$",
"stream",
")",
"use",
"(",
"$",
"connection",
",",
"$",
"deferred",
",",
"$",
"timeout",
")",
"{",
"$",
"this",
"->",
"stream",
"=",
"$",
"stream",
";",
"$",
"this",
"->",
"emit",
"(",
"'open'",
",",
"[",
"$",
"connection",
",",
"$",
"this",
"]",
")",
";",
"$",
"this",
"->",
"registerClient",
"(",
"$",
"connection",
",",
"$",
"timeout",
")",
"->",
"then",
"(",
"function",
"(",
"ConnectResponsePacket",
"$",
"responsePacket",
")",
"use",
"(",
"$",
"deferred",
",",
"$",
"connection",
")",
"{",
"$",
"this",
"->",
"isConnecting",
"=",
"false",
";",
"$",
"this",
"->",
"isConnected",
"=",
"true",
";",
"$",
"this",
"->",
"connection",
"=",
"$",
"connection",
";",
"$",
"this",
"->",
"emit",
"(",
"'connect'",
",",
"[",
"$",
"responsePacket",
",",
"$",
"this",
"]",
")",
";",
"$",
"deferred",
"->",
"resolve",
"(",
"$",
"responsePacket",
")",
";",
"}",
")",
"->",
"otherwise",
"(",
"function",
"(",
"\\",
"Exception",
"$",
"e",
")",
"use",
"(",
"$",
"deferred",
",",
"$",
"connection",
")",
"{",
"$",
"this",
"->",
"isConnecting",
"=",
"false",
";",
"$",
"this",
"->",
"emitError",
"(",
"$",
"e",
")",
";",
"$",
"deferred",
"->",
"reject",
"(",
"$",
"e",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stream",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"stream",
"->",
"close",
"(",
")",
";",
"}",
"$",
"this",
"->",
"emit",
"(",
"'close'",
",",
"[",
"$",
"connection",
",",
"$",
"this",
"]",
")",
";",
"}",
")",
";",
"}",
")",
"->",
"otherwise",
"(",
"function",
"(",
"\\",
"Exception",
"$",
"e",
")",
"use",
"(",
"$",
"deferred",
")",
"{",
"$",
"this",
"->",
"isConnecting",
"=",
"false",
";",
"$",
"this",
"->",
"emitError",
"(",
"$",
"e",
")",
";",
"$",
"deferred",
"->",
"reject",
"(",
"$",
"e",
")",
";",
"}",
")",
";",
"return",
"$",
"deferred",
"->",
"promise",
"(",
")",
";",
"}"
] |
Connects to a broker.
@param string $host
@param int $port
@param Connection $connection
@param int $timeout
@return ExtendedPromiseInterface
|
[
"Connects",
"to",
"a",
"broker",
"."
] |
4bbf513a8ffed7e0c9ca10776033d34515bb8b37
|
https://github.com/valga/fbns-react/blob/4bbf513a8ffed7e0c9ca10776033d34515bb8b37/src/Lite/ReactMqttClient.php#L174-L224
|
224,963
|
valga/fbns-react
|
src/Lite/ReactMqttClient.php
|
ReactMqttClient.cleanPreviousSession
|
private function cleanPreviousSession()
{
$error = new \RuntimeException('Connection has been closed.');
foreach ($this->receivingFlows as $receivingFlow) {
$receivingFlow->getDeferred()->reject($error);
}
$this->receivingFlows = [];
foreach ($this->sendingFlows as $sendingFlow) {
$sendingFlow->getDeferred()->reject($error);
}
$this->sendingFlows = [];
}
|
php
|
private function cleanPreviousSession()
{
$error = new \RuntimeException('Connection has been closed.');
foreach ($this->receivingFlows as $receivingFlow) {
$receivingFlow->getDeferred()->reject($error);
}
$this->receivingFlows = [];
foreach ($this->sendingFlows as $sendingFlow) {
$sendingFlow->getDeferred()->reject($error);
}
$this->sendingFlows = [];
}
|
[
"private",
"function",
"cleanPreviousSession",
"(",
")",
"{",
"$",
"error",
"=",
"new",
"\\",
"RuntimeException",
"(",
"'Connection has been closed.'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"receivingFlows",
"as",
"$",
"receivingFlow",
")",
"{",
"$",
"receivingFlow",
"->",
"getDeferred",
"(",
")",
"->",
"reject",
"(",
"$",
"error",
")",
";",
"}",
"$",
"this",
"->",
"receivingFlows",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"sendingFlows",
"as",
"$",
"sendingFlow",
")",
"{",
"$",
"sendingFlow",
"->",
"getDeferred",
"(",
")",
"->",
"reject",
"(",
"$",
"error",
")",
";",
"}",
"$",
"this",
"->",
"sendingFlows",
"=",
"[",
"]",
";",
"}"
] |
Cleans previous session by rejecting all pending flows.
|
[
"Cleans",
"previous",
"session",
"by",
"rejecting",
"all",
"pending",
"flows",
"."
] |
4bbf513a8ffed7e0c9ca10776033d34515bb8b37
|
https://github.com/valga/fbns-react/blob/4bbf513a8ffed7e0c9ca10776033d34515bb8b37/src/Lite/ReactMqttClient.php#L683-L694
|
224,964
|
ongr-io/TranslationsBundle
|
Service/HistoryManager.php
|
HistoryManager.getHistory
|
public function getHistory(Translation $translation)
{
$ordered = [];
$histories = $this->getUnorderedHistory($translation);
/** @var History $history */
foreach ($histories as $history) {
$ordered[$history->getLocale()][] = $history;
}
return $ordered;
}
|
php
|
public function getHistory(Translation $translation)
{
$ordered = [];
$histories = $this->getUnorderedHistory($translation);
/** @var History $history */
foreach ($histories as $history) {
$ordered[$history->getLocale()][] = $history;
}
return $ordered;
}
|
[
"public",
"function",
"getHistory",
"(",
"Translation",
"$",
"translation",
")",
"{",
"$",
"ordered",
"=",
"[",
"]",
";",
"$",
"histories",
"=",
"$",
"this",
"->",
"getUnorderedHistory",
"(",
"$",
"translation",
")",
";",
"/** @var History $history */",
"foreach",
"(",
"$",
"histories",
"as",
"$",
"history",
")",
"{",
"$",
"ordered",
"[",
"$",
"history",
"->",
"getLocale",
"(",
")",
"]",
"[",
"]",
"=",
"$",
"history",
";",
"}",
"return",
"$",
"ordered",
";",
"}"
] |
Returns an array of history objects grouped by locales
@param Translation $translation
@return array
|
[
"Returns",
"an",
"array",
"of",
"history",
"objects",
"grouped",
"by",
"locales"
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/HistoryManager.php#L47-L58
|
224,965
|
ongr-io/TranslationsBundle
|
Service/HistoryManager.php
|
HistoryManager.getUnorderedHistory
|
private function getUnorderedHistory(Translation $translation)
{
$search = $this->repository->createSearch();
$search->addQuery(new TermQuery('key', $translation->getKey()));
$search->addQuery(new TermQuery('domain', $translation->getDomain()));
$search->addSort(new FieldSort('created_at', FieldSort::DESC));
return $this->repository->findDocuments($search);
}
|
php
|
private function getUnorderedHistory(Translation $translation)
{
$search = $this->repository->createSearch();
$search->addQuery(new TermQuery('key', $translation->getKey()));
$search->addQuery(new TermQuery('domain', $translation->getDomain()));
$search->addSort(new FieldSort('created_at', FieldSort::DESC));
return $this->repository->findDocuments($search);
}
|
[
"private",
"function",
"getUnorderedHistory",
"(",
"Translation",
"$",
"translation",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"repository",
"->",
"createSearch",
"(",
")",
";",
"$",
"search",
"->",
"addQuery",
"(",
"new",
"TermQuery",
"(",
"'key'",
",",
"$",
"translation",
"->",
"getKey",
"(",
")",
")",
")",
";",
"$",
"search",
"->",
"addQuery",
"(",
"new",
"TermQuery",
"(",
"'domain'",
",",
"$",
"translation",
"->",
"getDomain",
"(",
")",
")",
")",
";",
"$",
"search",
"->",
"addSort",
"(",
"new",
"FieldSort",
"(",
"'created_at'",
",",
"FieldSort",
"::",
"DESC",
")",
")",
";",
"return",
"$",
"this",
"->",
"repository",
"->",
"findDocuments",
"(",
"$",
"search",
")",
";",
"}"
] |
Returns message history.
@param Translation $translation
@return DocumentIterator
|
[
"Returns",
"message",
"history",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/HistoryManager.php#L83-L91
|
224,966
|
lucisgit/php-panopto-api
|
lib/Client.php
|
Client.setAuthenticationInfo
|
public function setAuthenticationInfo($userkey = '', $password = '', $applicationkey = '') {
// Create AuthenticationInfo instance.
$this->authinfo = new \Panopto\Auth\AuthenticationInfo();
// Populate authentication settings.
if (!empty($userkey)) {
$this->authinfo->setUserKey($userkey);
}
if (!empty($password)) {
$this->authinfo->setPassword($password);
} else if (!empty($applicationkey)) {
$authcode = $this->createAuthCode($userkey, $applicationkey);
$this->authinfo->setAuthCode($authcode);
}
}
|
php
|
public function setAuthenticationInfo($userkey = '', $password = '', $applicationkey = '') {
// Create AuthenticationInfo instance.
$this->authinfo = new \Panopto\Auth\AuthenticationInfo();
// Populate authentication settings.
if (!empty($userkey)) {
$this->authinfo->setUserKey($userkey);
}
if (!empty($password)) {
$this->authinfo->setPassword($password);
} else if (!empty($applicationkey)) {
$authcode = $this->createAuthCode($userkey, $applicationkey);
$this->authinfo->setAuthCode($authcode);
}
}
|
[
"public",
"function",
"setAuthenticationInfo",
"(",
"$",
"userkey",
"=",
"''",
",",
"$",
"password",
"=",
"''",
",",
"$",
"applicationkey",
"=",
"''",
")",
"{",
"// Create AuthenticationInfo instance.",
"$",
"this",
"->",
"authinfo",
"=",
"new",
"\\",
"Panopto",
"\\",
"Auth",
"\\",
"AuthenticationInfo",
"(",
")",
";",
"// Populate authentication settings.",
"if",
"(",
"!",
"empty",
"(",
"$",
"userkey",
")",
")",
"{",
"$",
"this",
"->",
"authinfo",
"->",
"setUserKey",
"(",
"$",
"userkey",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"password",
")",
")",
"{",
"$",
"this",
"->",
"authinfo",
"->",
"setPassword",
"(",
"$",
"password",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"applicationkey",
")",
")",
"{",
"$",
"authcode",
"=",
"$",
"this",
"->",
"createAuthCode",
"(",
"$",
"userkey",
",",
"$",
"applicationkey",
")",
";",
"$",
"this",
"->",
"authinfo",
"->",
"setAuthCode",
"(",
"$",
"authcode",
")",
";",
"}",
"}"
] |
Sets AuthenticationInfo object for using in requests.
This creates an instance of \Panopto\Auth\AuthenticationInfo that
has been pre-configured with provided credentials.
@param string $userkey User on the server to use for API calls. If used with Application Key from Identity Provider, user needs to be preceed with corresponding Instance Name, e.g. 'MyInstanceName\someuser'.
@param string $password Password for user authentication (not required if $applicationkey is specified).
@param string $applicationkey Application Key value from Identity Provider setting, e.g. '00000000-0000-0000-0000-000000000000'
|
[
"Sets",
"AuthenticationInfo",
"object",
"for",
"using",
"in",
"requests",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/lib/Client.php#L126-L141
|
224,967
|
lucisgit/php-panopto-api
|
lib/Client.php
|
Client.createAuthCode
|
protected function createAuthCode($userkey, $applicationkey) {
$payload = $userkey . "@" . strtolower($this->serverhostname) . "|" . strtolower($applicationkey);
return strtoupper(sha1($payload));
}
|
php
|
protected function createAuthCode($userkey, $applicationkey) {
$payload = $userkey . "@" . strtolower($this->serverhostname) . "|" . strtolower($applicationkey);
return strtoupper(sha1($payload));
}
|
[
"protected",
"function",
"createAuthCode",
"(",
"$",
"userkey",
",",
"$",
"applicationkey",
")",
"{",
"$",
"payload",
"=",
"$",
"userkey",
".",
"\"@\"",
".",
"strtolower",
"(",
"$",
"this",
"->",
"serverhostname",
")",
".",
"\"|\"",
".",
"strtolower",
"(",
"$",
"applicationkey",
")",
";",
"return",
"strtoupper",
"(",
"sha1",
"(",
"$",
"payload",
")",
")",
";",
"}"
] |
Generates authentication code.
For using with \Panopto\Auth\AuthenticationInfo.
@param string $userkey
@param string $applicationkey
@return string Authentication code.
|
[
"Generates",
"authentication",
"code",
"."
] |
2996184eff11bf69932c69074e0b225498c17574
|
https://github.com/lucisgit/php-panopto-api/blob/2996184eff11bf69932c69074e0b225498c17574/lib/Client.php#L152-L155
|
224,968
|
pdeans/http
|
src/Client.php
|
Client.trace
|
public function trace($uri, array $headers = [])
{
return $this->sendRequest(
$this->message->createRequest('TRACE', $uri, $headers, null)
);
}
|
php
|
public function trace($uri, array $headers = [])
{
return $this->sendRequest(
$this->message->createRequest('TRACE', $uri, $headers, null)
);
}
|
[
"public",
"function",
"trace",
"(",
"$",
"uri",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"this",
"->",
"message",
"->",
"createRequest",
"(",
"'TRACE'",
",",
"$",
"uri",
",",
"$",
"headers",
",",
"null",
")",
")",
";",
"}"
] |
Send a TRACE request
@param \Psr\Http\Message\UriInterface|string $uri
@param array $headers
@return \Psr\Http\Message\ResponseInterface
|
[
"Send",
"a",
"TRACE",
"request"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Client.php#L210-L215
|
224,969
|
pdeans/http
|
src/Client.php
|
Client.sendRequest
|
public function sendRequest(RequestInterface $request)
{
$response = $this->createResponse();
$options = $this->createOptions($request, $response);
// Reset cURL handler
if (is_resource($this->ch)) {
if (function_exists('curl_reset')) {
curl_reset($this->ch);
}
else {
curl_close($this->ch);
$this->ch = curl_init();
}
}
else {
$this->ch = curl_init();
}
// Setup the cURL request
curl_setopt_array($this->ch, $options);
// Execute the request
curl_exec($this->ch);
// Check for any request errors
switch (curl_errno($this->ch)) {
case CURLE_OK:
break;
case CURLE_COULDNT_RESOLVE_PROXY:
case CURLE_COULDNT_RESOLVE_HOST:
case CURLE_COULDNT_CONNECT:
case CURLE_OPERATION_TIMEOUTED:
case CURLE_SSL_CONNECT_ERROR:
throw new NetworkException(curl_error($this->ch), $request);
default:
throw new RequestException(curl_error($this->ch), $request);
}
// Get the response
$response = $response->getResponse();
// Seek to the beginning of the request body
$response->getBody()->seek(0);
return $response;
}
|
php
|
public function sendRequest(RequestInterface $request)
{
$response = $this->createResponse();
$options = $this->createOptions($request, $response);
// Reset cURL handler
if (is_resource($this->ch)) {
if (function_exists('curl_reset')) {
curl_reset($this->ch);
}
else {
curl_close($this->ch);
$this->ch = curl_init();
}
}
else {
$this->ch = curl_init();
}
// Setup the cURL request
curl_setopt_array($this->ch, $options);
// Execute the request
curl_exec($this->ch);
// Check for any request errors
switch (curl_errno($this->ch)) {
case CURLE_OK:
break;
case CURLE_COULDNT_RESOLVE_PROXY:
case CURLE_COULDNT_RESOLVE_HOST:
case CURLE_COULDNT_CONNECT:
case CURLE_OPERATION_TIMEOUTED:
case CURLE_SSL_CONNECT_ERROR:
throw new NetworkException(curl_error($this->ch), $request);
default:
throw new RequestException(curl_error($this->ch), $request);
}
// Get the response
$response = $response->getResponse();
// Seek to the beginning of the request body
$response->getBody()->seek(0);
return $response;
}
|
[
"public",
"function",
"sendRequest",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"createResponse",
"(",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"createOptions",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"// Reset cURL handler",
"if",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"ch",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'curl_reset'",
")",
")",
"{",
"curl_reset",
"(",
"$",
"this",
"->",
"ch",
")",
";",
"}",
"else",
"{",
"curl_close",
"(",
"$",
"this",
"->",
"ch",
")",
";",
"$",
"this",
"->",
"ch",
"=",
"curl_init",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"ch",
"=",
"curl_init",
"(",
")",
";",
"}",
"// Setup the cURL request",
"curl_setopt_array",
"(",
"$",
"this",
"->",
"ch",
",",
"$",
"options",
")",
";",
"// Execute the request",
"curl_exec",
"(",
"$",
"this",
"->",
"ch",
")",
";",
"// Check for any request errors",
"switch",
"(",
"curl_errno",
"(",
"$",
"this",
"->",
"ch",
")",
")",
"{",
"case",
"CURLE_OK",
":",
"break",
";",
"case",
"CURLE_COULDNT_RESOLVE_PROXY",
":",
"case",
"CURLE_COULDNT_RESOLVE_HOST",
":",
"case",
"CURLE_COULDNT_CONNECT",
":",
"case",
"CURLE_OPERATION_TIMEOUTED",
":",
"case",
"CURLE_SSL_CONNECT_ERROR",
":",
"throw",
"new",
"NetworkException",
"(",
"curl_error",
"(",
"$",
"this",
"->",
"ch",
")",
",",
"$",
"request",
")",
";",
"default",
":",
"throw",
"new",
"RequestException",
"(",
"curl_error",
"(",
"$",
"this",
"->",
"ch",
")",
",",
"$",
"request",
")",
";",
"}",
"// Get the response",
"$",
"response",
"=",
"$",
"response",
"->",
"getResponse",
"(",
")",
";",
"// Seek to the beginning of the request body",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"seek",
"(",
"0",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Send a PSR-7 Request
@param \Psr\Http\Message\RequestInterface $request
@return \Psr\Http\Message\ResponseInterface
@throws \pdeans\Http\Exceptions\NetworkException Invalid request due to network issue
@throws \pdeans\Http\Exceptions\RequestException Invalid request
@throws \InvalidArgumentException Invalid header names and/or values
@throws \RuntimeException Failure to create stream
|
[
"Send",
"a",
"PSR",
"-",
"7",
"Request"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Client.php#L232-L278
|
224,970
|
pdeans/http
|
src/Client.php
|
Client.createResponse
|
protected function createResponse()
{
try {
$body = $this->stream->createStream(fopen('php://temp', 'w+b'));
}
catch (InvalidArgumentException $e) {
throw new RuntimeException('Unable to create stream "php://temp"');
}
return new ResponseBuilder(
$this->message->createResponse(200, null, [], $body)
);
}
|
php
|
protected function createResponse()
{
try {
$body = $this->stream->createStream(fopen('php://temp', 'w+b'));
}
catch (InvalidArgumentException $e) {
throw new RuntimeException('Unable to create stream "php://temp"');
}
return new ResponseBuilder(
$this->message->createResponse(200, null, [], $body)
);
}
|
[
"protected",
"function",
"createResponse",
"(",
")",
"{",
"try",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"stream",
"->",
"createStream",
"(",
"fopen",
"(",
"'php://temp'",
",",
"'w+b'",
")",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Unable to create stream \"php://temp\"'",
")",
";",
"}",
"return",
"new",
"ResponseBuilder",
"(",
"$",
"this",
"->",
"message",
"->",
"createResponse",
"(",
"200",
",",
"null",
",",
"[",
"]",
",",
"$",
"body",
")",
")",
";",
"}"
] |
Create a new http response
@return \pdeans\Http\Builders\ResponseBuilder
@throws \RuntimeException Failure to create stream
|
[
"Create",
"a",
"new",
"http",
"response"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Client.php#L291-L303
|
224,971
|
pdeans/http
|
src/Client.php
|
Client.createHeaders
|
protected function createHeaders(RequestInterface $request, array $options)
{
$headers = [];
$request_headers = $request->getHeaders();
foreach ($request_headers as $name => $values) {
$header = strtoupper($name);
// cURL does not support 'Expect-Continue', skip all 'EXPECT' headers
if ($header === 'EXPECT') {
continue;
}
if ($header === 'CONTENT-LENGTH') {
if (array_key_exists(CURLOPT_POSTFIELDS, $options)) {
$values = [strlen($options[CURLOPT_POSTFIELDS])];
}
// Force content length to '0' if body is empty
else if (!array_key_exists(CURLOPT_READFUNCTION, $options)) {
$values = [0];
}
}
foreach ($values as $value) {
$headers[] = $name.': '.$value;
}
}
// Although cURL does not support 'Expect-Continue', it adds the 'Expect'
// header by default, so we need to force 'Expect' to empty.
$headers[] = 'Expect:';
return $headers;
}
|
php
|
protected function createHeaders(RequestInterface $request, array $options)
{
$headers = [];
$request_headers = $request->getHeaders();
foreach ($request_headers as $name => $values) {
$header = strtoupper($name);
// cURL does not support 'Expect-Continue', skip all 'EXPECT' headers
if ($header === 'EXPECT') {
continue;
}
if ($header === 'CONTENT-LENGTH') {
if (array_key_exists(CURLOPT_POSTFIELDS, $options)) {
$values = [strlen($options[CURLOPT_POSTFIELDS])];
}
// Force content length to '0' if body is empty
else if (!array_key_exists(CURLOPT_READFUNCTION, $options)) {
$values = [0];
}
}
foreach ($values as $value) {
$headers[] = $name.': '.$value;
}
}
// Although cURL does not support 'Expect-Continue', it adds the 'Expect'
// header by default, so we need to force 'Expect' to empty.
$headers[] = 'Expect:';
return $headers;
}
|
[
"protected",
"function",
"createHeaders",
"(",
"RequestInterface",
"$",
"request",
",",
"array",
"$",
"options",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"request_headers",
"=",
"$",
"request",
"->",
"getHeaders",
"(",
")",
";",
"foreach",
"(",
"$",
"request_headers",
"as",
"$",
"name",
"=>",
"$",
"values",
")",
"{",
"$",
"header",
"=",
"strtoupper",
"(",
"$",
"name",
")",
";",
"// cURL does not support 'Expect-Continue', skip all 'EXPECT' headers",
"if",
"(",
"$",
"header",
"===",
"'EXPECT'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"header",
"===",
"'CONTENT-LENGTH'",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"CURLOPT_POSTFIELDS",
",",
"$",
"options",
")",
")",
"{",
"$",
"values",
"=",
"[",
"strlen",
"(",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
")",
"]",
";",
"}",
"// Force content length to '0' if body is empty",
"else",
"if",
"(",
"!",
"array_key_exists",
"(",
"CURLOPT_READFUNCTION",
",",
"$",
"options",
")",
")",
"{",
"$",
"values",
"=",
"[",
"0",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"$",
"name",
".",
"': '",
".",
"$",
"value",
";",
"}",
"}",
"// Although cURL does not support 'Expect-Continue', it adds the 'Expect'",
"// header by default, so we need to force 'Expect' to empty.",
"$",
"headers",
"[",
"]",
"=",
"'Expect:'",
";",
"return",
"$",
"headers",
";",
"}"
] |
Create array of headers to pass to CURLOPT_HTTPHEADER
@param \Psr\Http\Message\RequestInterface $request Request object
@param array $options cURL options
@return array Array of http header lines
|
[
"Create",
"array",
"of",
"headers",
"to",
"pass",
"to",
"CURLOPT_HTTPHEADER"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Client.php#L316-L349
|
224,972
|
pdeans/http
|
src/Client.php
|
Client.createOptions
|
protected function createOptions(RequestInterface $request, ResponseBuilder $response)
{
$options = $this->options;
// These options default to false and cannot be changed on set up.
// The options should be provided with the request instead.
$options[CURLOPT_FOLLOWLOCATION] = false;
$options[CURLOPT_HEADER] = false;
$options[CURLOPT_RETURNTRANSFER] = false;
try {
$options[CURLOPT_HTTP_VERSION] = $this->getProtocolVersion($request->getProtocolVersion());
}
catch (UnexpectedValueException $e) {
throw new RequestException($e->getMessage(), $request);
}
$options[CURLOPT_URL] = (string)$request->getUri();
$options = $this->addRequestBodyOptions($request, $options);
$options[CURLOPT_HTTPHEADER] = $this->createHeaders($request, $options);
if ($request->getUri()->getUserInfo()) {
$options[CURLOPT_USERPWD] = $request->getUri()->getUserInfo();
}
$options[CURLOPT_HEADERFUNCTION] = function ($ch, $data) use ($response) {
$clean_data = trim($data);
if ($clean_data !== '') {
if (strpos(strtoupper($clean_data), 'HTTP/') === 0) {
$response->setStatus($clean_data)->getResponse();
}
else {
$response->addHeader($clean_data);
}
}
return strlen($data);
};
$options[CURLOPT_WRITEFUNCTION] = function ($ch, $data) use ($response) {
return $response->getResponse()->getBody()->write($data);
};
return $options;
}
|
php
|
protected function createOptions(RequestInterface $request, ResponseBuilder $response)
{
$options = $this->options;
// These options default to false and cannot be changed on set up.
// The options should be provided with the request instead.
$options[CURLOPT_FOLLOWLOCATION] = false;
$options[CURLOPT_HEADER] = false;
$options[CURLOPT_RETURNTRANSFER] = false;
try {
$options[CURLOPT_HTTP_VERSION] = $this->getProtocolVersion($request->getProtocolVersion());
}
catch (UnexpectedValueException $e) {
throw new RequestException($e->getMessage(), $request);
}
$options[CURLOPT_URL] = (string)$request->getUri();
$options = $this->addRequestBodyOptions($request, $options);
$options[CURLOPT_HTTPHEADER] = $this->createHeaders($request, $options);
if ($request->getUri()->getUserInfo()) {
$options[CURLOPT_USERPWD] = $request->getUri()->getUserInfo();
}
$options[CURLOPT_HEADERFUNCTION] = function ($ch, $data) use ($response) {
$clean_data = trim($data);
if ($clean_data !== '') {
if (strpos(strtoupper($clean_data), 'HTTP/') === 0) {
$response->setStatus($clean_data)->getResponse();
}
else {
$response->addHeader($clean_data);
}
}
return strlen($data);
};
$options[CURLOPT_WRITEFUNCTION] = function ($ch, $data) use ($response) {
return $response->getResponse()->getBody()->write($data);
};
return $options;
}
|
[
"protected",
"function",
"createOptions",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseBuilder",
"$",
"response",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"options",
";",
"// These options default to false and cannot be changed on set up.",
"// The options should be provided with the request instead.",
"$",
"options",
"[",
"CURLOPT_FOLLOWLOCATION",
"]",
"=",
"false",
";",
"$",
"options",
"[",
"CURLOPT_HEADER",
"]",
"=",
"false",
";",
"$",
"options",
"[",
"CURLOPT_RETURNTRANSFER",
"]",
"=",
"false",
";",
"try",
"{",
"$",
"options",
"[",
"CURLOPT_HTTP_VERSION",
"]",
"=",
"$",
"this",
"->",
"getProtocolVersion",
"(",
"$",
"request",
"->",
"getProtocolVersion",
"(",
")",
")",
";",
"}",
"catch",
"(",
"UnexpectedValueException",
"$",
"e",
")",
"{",
"throw",
"new",
"RequestException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"request",
")",
";",
"}",
"$",
"options",
"[",
"CURLOPT_URL",
"]",
"=",
"(",
"string",
")",
"$",
"request",
"->",
"getUri",
"(",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"addRequestBodyOptions",
"(",
"$",
"request",
",",
"$",
"options",
")",
";",
"$",
"options",
"[",
"CURLOPT_HTTPHEADER",
"]",
"=",
"$",
"this",
"->",
"createHeaders",
"(",
"$",
"request",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getUserInfo",
"(",
")",
")",
"{",
"$",
"options",
"[",
"CURLOPT_USERPWD",
"]",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getUserInfo",
"(",
")",
";",
"}",
"$",
"options",
"[",
"CURLOPT_HEADERFUNCTION",
"]",
"=",
"function",
"(",
"$",
"ch",
",",
"$",
"data",
")",
"use",
"(",
"$",
"response",
")",
"{",
"$",
"clean_data",
"=",
"trim",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"clean_data",
"!==",
"''",
")",
"{",
"if",
"(",
"strpos",
"(",
"strtoupper",
"(",
"$",
"clean_data",
")",
",",
"'HTTP/'",
")",
"===",
"0",
")",
"{",
"$",
"response",
"->",
"setStatus",
"(",
"$",
"clean_data",
")",
"->",
"getResponse",
"(",
")",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"addHeader",
"(",
"$",
"clean_data",
")",
";",
"}",
"}",
"return",
"strlen",
"(",
"$",
"data",
")",
";",
"}",
";",
"$",
"options",
"[",
"CURLOPT_WRITEFUNCTION",
"]",
"=",
"function",
"(",
"$",
"ch",
",",
"$",
"data",
")",
"use",
"(",
"$",
"response",
")",
"{",
"return",
"$",
"response",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"$",
"data",
")",
";",
"}",
";",
"return",
"$",
"options",
";",
"}"
] |
Create cURL request options
@param \Psr\Http\Message\RequestInterface $request
@param \pdeans\Http\Builders\ResponseBuilder $response
@return array cURL options
@throws \pdeans\Http\Exceptions\RequestException Invalid request
@throws \InvalidArgumentException Invalid header names and/or values
@throws \RuntimeException Unable to read request body
|
[
"Create",
"cURL",
"request",
"options"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Client.php#L366-L413
|
224,973
|
pdeans/http
|
src/Client.php
|
Client.addRequestBodyOptions
|
protected function addRequestBodyOptions(RequestInterface $request, array $options)
{
/*
* HTTP methods that cannot have payload:
* - GET => cURL will automatically change method to PUT or POST if we
* set CURLOPT_UPLOAD or CURLOPT_POSTFIELDS.
* - HEAD => cURL treats HEAD as GET request with a same restrictions.
* - TRACE => According to RFC7231: a client MUST NOT send a message body
* in a TRACE request.
*/
$http_methods = [
'GET',
'HEAD',
'TRACE',
];
if (!in_array($request->getMethod(), $http_methods, true)) {
$body = $request->getBody();
$body_size = $body->getSize();
if ($body_size !== 0) {
if ($body->isSeekable()) {
$body->rewind();
}
if ($body_size === null || $body_size > self::$MAX_BODY_SIZE) {
$options[CURLOPT_UPLOAD] = true;
if ($body_size !== null) {
$options[CURLOPT_INFILESIZE] = $body_size;
}
$options[CURLOPT_READFUNCTION] = function ($ch, $fd, $len) use ($body) {
return $body->read($len);
};
}
else {
$options[CURLOPT_POSTFIELDS] = (string)$body;
}
}
}
if ($request->getMethod() === 'HEAD') {
$options[CURLOPT_NOBODY] = true;
}
else if ($request->getMethod() !== 'GET') {
$options[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
}
return $options;
}
|
php
|
protected function addRequestBodyOptions(RequestInterface $request, array $options)
{
/*
* HTTP methods that cannot have payload:
* - GET => cURL will automatically change method to PUT or POST if we
* set CURLOPT_UPLOAD or CURLOPT_POSTFIELDS.
* - HEAD => cURL treats HEAD as GET request with a same restrictions.
* - TRACE => According to RFC7231: a client MUST NOT send a message body
* in a TRACE request.
*/
$http_methods = [
'GET',
'HEAD',
'TRACE',
];
if (!in_array($request->getMethod(), $http_methods, true)) {
$body = $request->getBody();
$body_size = $body->getSize();
if ($body_size !== 0) {
if ($body->isSeekable()) {
$body->rewind();
}
if ($body_size === null || $body_size > self::$MAX_BODY_SIZE) {
$options[CURLOPT_UPLOAD] = true;
if ($body_size !== null) {
$options[CURLOPT_INFILESIZE] = $body_size;
}
$options[CURLOPT_READFUNCTION] = function ($ch, $fd, $len) use ($body) {
return $body->read($len);
};
}
else {
$options[CURLOPT_POSTFIELDS] = (string)$body;
}
}
}
if ($request->getMethod() === 'HEAD') {
$options[CURLOPT_NOBODY] = true;
}
else if ($request->getMethod() !== 'GET') {
$options[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
}
return $options;
}
|
[
"protected",
"function",
"addRequestBodyOptions",
"(",
"RequestInterface",
"$",
"request",
",",
"array",
"$",
"options",
")",
"{",
"/*\n\t\t * HTTP methods that cannot have payload:\n\t\t * - GET => cURL will automatically change method to PUT or POST if we\n\t\t * set CURLOPT_UPLOAD or CURLOPT_POSTFIELDS.\n\t\t * - HEAD => cURL treats HEAD as GET request with a same restrictions.\n\t\t * - TRACE => According to RFC7231: a client MUST NOT send a message body\n\t\t * in a TRACE request.\n\t\t */",
"$",
"http_methods",
"=",
"[",
"'GET'",
",",
"'HEAD'",
",",
"'TRACE'",
",",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"http_methods",
",",
"true",
")",
")",
"{",
"$",
"body",
"=",
"$",
"request",
"->",
"getBody",
"(",
")",
";",
"$",
"body_size",
"=",
"$",
"body",
"->",
"getSize",
"(",
")",
";",
"if",
"(",
"$",
"body_size",
"!==",
"0",
")",
"{",
"if",
"(",
"$",
"body",
"->",
"isSeekable",
"(",
")",
")",
"{",
"$",
"body",
"->",
"rewind",
"(",
")",
";",
"}",
"if",
"(",
"$",
"body_size",
"===",
"null",
"||",
"$",
"body_size",
">",
"self",
"::",
"$",
"MAX_BODY_SIZE",
")",
"{",
"$",
"options",
"[",
"CURLOPT_UPLOAD",
"]",
"=",
"true",
";",
"if",
"(",
"$",
"body_size",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"CURLOPT_INFILESIZE",
"]",
"=",
"$",
"body_size",
";",
"}",
"$",
"options",
"[",
"CURLOPT_READFUNCTION",
"]",
"=",
"function",
"(",
"$",
"ch",
",",
"$",
"fd",
",",
"$",
"len",
")",
"use",
"(",
"$",
"body",
")",
"{",
"return",
"$",
"body",
"->",
"read",
"(",
"$",
"len",
")",
";",
"}",
";",
"}",
"else",
"{",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"(",
"string",
")",
"$",
"body",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"===",
"'HEAD'",
")",
"{",
"$",
"options",
"[",
"CURLOPT_NOBODY",
"]",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"!==",
"'GET'",
")",
"{",
"$",
"options",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
] |
Add cURL options related to the request body
@param \Psr\Http\Message\RequestInterface $request Request object
@param array $options cURL options
|
[
"Add",
"cURL",
"options",
"related",
"to",
"the",
"request",
"body"
] |
6ebd9d9926ed815d85d47c8808ca87b236e49d88
|
https://github.com/pdeans/http/blob/6ebd9d9926ed815d85d47c8808ca87b236e49d88/src/Client.php#L421-L471
|
224,974
|
theofidry/LoopBackApiBundle
|
features/bootstrap/FeatureContext.php
|
FeatureContext.theJsonNodeShouldBeNull
|
public function theJsonNodeShouldBeNull($node)
{
$actual = $this->getJsonNodeValue($node);
PHPUnit::assertNull($actual, sprintf('The node value is `%s`', json_encode($actual)));
}
|
php
|
public function theJsonNodeShouldBeNull($node)
{
$actual = $this->getJsonNodeValue($node);
PHPUnit::assertNull($actual, sprintf('The node value is `%s`', json_encode($actual)));
}
|
[
"public",
"function",
"theJsonNodeShouldBeNull",
"(",
"$",
"node",
")",
"{",
"$",
"actual",
"=",
"$",
"this",
"->",
"getJsonNodeValue",
"(",
"$",
"node",
")",
";",
"PHPUnit",
"::",
"assertNull",
"(",
"$",
"actual",
",",
"sprintf",
"(",
"'The node value is `%s`'",
",",
"json_encode",
"(",
"$",
"actual",
")",
")",
")",
";",
"}"
] |
Checks that given JSON node is null
@Then the JSON node :node should be null
|
[
"Checks",
"that",
"given",
"JSON",
"node",
"is",
"null"
] |
b66b295088b364e3c4aba5b0feb8d660c4141730
|
https://github.com/theofidry/LoopBackApiBundle/blob/b66b295088b364e3c4aba5b0feb8d660c4141730/features/bootstrap/FeatureContext.php#L76-L80
|
224,975
|
silverstripe/silverstripe-mathspamprotection
|
code/MathSpamProtectorField.php
|
MathSpamProtectorField.Title
|
public function Title()
{
$prefix = $this->config()->get('question_prefix');
if (!$prefix) {
$prefix = _t('MathSpamProtectionField.SPAMQUESTION', "Spam protection question: %s");
}
return sprintf(
$prefix,
$this->getMathsQuestion()
);
}
|
php
|
public function Title()
{
$prefix = $this->config()->get('question_prefix');
if (!$prefix) {
$prefix = _t('MathSpamProtectionField.SPAMQUESTION', "Spam protection question: %s");
}
return sprintf(
$prefix,
$this->getMathsQuestion()
);
}
|
[
"public",
"function",
"Title",
"(",
")",
"{",
"$",
"prefix",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'question_prefix'",
")",
";",
"if",
"(",
"!",
"$",
"prefix",
")",
"{",
"$",
"prefix",
"=",
"_t",
"(",
"'MathSpamProtectionField.SPAMQUESTION'",
",",
"\"Spam protection question: %s\"",
")",
";",
"}",
"return",
"sprintf",
"(",
"$",
"prefix",
",",
"$",
"this",
"->",
"getMathsQuestion",
"(",
")",
")",
";",
"}"
] |
Returns the spam question
@return string
|
[
"Returns",
"the",
"spam",
"question"
] |
570eec324c89578f299e2340681b74edb7b3c712
|
https://github.com/silverstripe/silverstripe-mathspamprotection/blob/570eec324c89578f299e2340681b74edb7b3c712/code/MathSpamProtectorField.php#L61-L73
|
224,976
|
silverstripe/silverstripe-mathspamprotection
|
code/MathSpamProtectorField.php
|
MathSpamProtectorField.getMathsQuestion
|
public function getMathsQuestion()
{
/** @var Session $session */
$session = Controller::curr()->getRequest()->getSession();
if (!$session->get("mathQuestionV1") && !$session->get("mathQuestionV2")) {
$v1 = rand(1, 9);
$v2 = rand(1, 9);
$session->set("mathQuestionV1", $v1);
$session->set("mathQuestionV2", $v2);
} else {
$v1 = $session->get("mathQuestionV1");
$v2 = $session->get("mathQuestionV2");
}
return sprintf(
_t('MathSpamProtection.WHATIS', "What is %s plus %s?"),
MathSpamProtectorField::digit_to_word($v1),
MathSpamProtectorField::digit_to_word($v2)
);
}
|
php
|
public function getMathsQuestion()
{
/** @var Session $session */
$session = Controller::curr()->getRequest()->getSession();
if (!$session->get("mathQuestionV1") && !$session->get("mathQuestionV2")) {
$v1 = rand(1, 9);
$v2 = rand(1, 9);
$session->set("mathQuestionV1", $v1);
$session->set("mathQuestionV2", $v2);
} else {
$v1 = $session->get("mathQuestionV1");
$v2 = $session->get("mathQuestionV2");
}
return sprintf(
_t('MathSpamProtection.WHATIS', "What is %s plus %s?"),
MathSpamProtectorField::digit_to_word($v1),
MathSpamProtectorField::digit_to_word($v2)
);
}
|
[
"public",
"function",
"getMathsQuestion",
"(",
")",
"{",
"/** @var Session $session */",
"$",
"session",
"=",
"Controller",
"::",
"curr",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getSession",
"(",
")",
";",
"if",
"(",
"!",
"$",
"session",
"->",
"get",
"(",
"\"mathQuestionV1\"",
")",
"&&",
"!",
"$",
"session",
"->",
"get",
"(",
"\"mathQuestionV2\"",
")",
")",
"{",
"$",
"v1",
"=",
"rand",
"(",
"1",
",",
"9",
")",
";",
"$",
"v2",
"=",
"rand",
"(",
"1",
",",
"9",
")",
";",
"$",
"session",
"->",
"set",
"(",
"\"mathQuestionV1\"",
",",
"$",
"v1",
")",
";",
"$",
"session",
"->",
"set",
"(",
"\"mathQuestionV2\"",
",",
"$",
"v2",
")",
";",
"}",
"else",
"{",
"$",
"v1",
"=",
"$",
"session",
"->",
"get",
"(",
"\"mathQuestionV1\"",
")",
";",
"$",
"v2",
"=",
"$",
"session",
"->",
"get",
"(",
"\"mathQuestionV2\"",
")",
";",
"}",
"return",
"sprintf",
"(",
"_t",
"(",
"'MathSpamProtection.WHATIS'",
",",
"\"What is %s plus %s?\"",
")",
",",
"MathSpamProtectorField",
"::",
"digit_to_word",
"(",
"$",
"v1",
")",
",",
"MathSpamProtectorField",
"::",
"digit_to_word",
"(",
"$",
"v2",
")",
")",
";",
"}"
] |
Creates the question from random variables, which are also saved to the session.
@return string
|
[
"Creates",
"the",
"question",
"from",
"random",
"variables",
"which",
"are",
"also",
"saved",
"to",
"the",
"session",
"."
] |
570eec324c89578f299e2340681b74edb7b3c712
|
https://github.com/silverstripe/silverstripe-mathspamprotection/blob/570eec324c89578f299e2340681b74edb7b3c712/code/MathSpamProtectorField.php#L110-L131
|
224,977
|
silverstripe/silverstripe-mathspamprotection
|
code/MathSpamProtectorField.php
|
MathSpamProtectorField.isCorrectAnswer
|
public function isCorrectAnswer($answer)
{
$session = Controller::curr()->getRequest()->getSession();
$v1 = $session->get("mathQuestionV1");
$v2 = $session->get("mathQuestionV2");
$session->clear('mathQuestionV1');
$session->clear('mathQuestionV2');
$word = MathSpamProtectorField::digit_to_word($v1 + $v2);
return ($word == strtolower($answer) || ($this->config()->get('allow_numeric_answer') && (($v1 + $v2) == $answer)));
}
|
php
|
public function isCorrectAnswer($answer)
{
$session = Controller::curr()->getRequest()->getSession();
$v1 = $session->get("mathQuestionV1");
$v2 = $session->get("mathQuestionV2");
$session->clear('mathQuestionV1');
$session->clear('mathQuestionV2');
$word = MathSpamProtectorField::digit_to_word($v1 + $v2);
return ($word == strtolower($answer) || ($this->config()->get('allow_numeric_answer') && (($v1 + $v2) == $answer)));
}
|
[
"public",
"function",
"isCorrectAnswer",
"(",
"$",
"answer",
")",
"{",
"$",
"session",
"=",
"Controller",
"::",
"curr",
"(",
")",
"->",
"getRequest",
"(",
")",
"->",
"getSession",
"(",
")",
";",
"$",
"v1",
"=",
"$",
"session",
"->",
"get",
"(",
"\"mathQuestionV1\"",
")",
";",
"$",
"v2",
"=",
"$",
"session",
"->",
"get",
"(",
"\"mathQuestionV2\"",
")",
";",
"$",
"session",
"->",
"clear",
"(",
"'mathQuestionV1'",
")",
";",
"$",
"session",
"->",
"clear",
"(",
"'mathQuestionV2'",
")",
";",
"$",
"word",
"=",
"MathSpamProtectorField",
"::",
"digit_to_word",
"(",
"$",
"v1",
"+",
"$",
"v2",
")",
";",
"return",
"(",
"$",
"word",
"==",
"strtolower",
"(",
"$",
"answer",
")",
"||",
"(",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'allow_numeric_answer'",
")",
"&&",
"(",
"(",
"$",
"v1",
"+",
"$",
"v2",
")",
"==",
"$",
"answer",
")",
")",
")",
";",
"}"
] |
Checks the given answer if it matches the addition of the saved session
variables.
Users can answer using words or digits.
@return bool
|
[
"Checks",
"the",
"given",
"answer",
"if",
"it",
"matches",
"the",
"addition",
"of",
"the",
"saved",
"session",
"variables",
"."
] |
570eec324c89578f299e2340681b74edb7b3c712
|
https://github.com/silverstripe/silverstripe-mathspamprotection/blob/570eec324c89578f299e2340681b74edb7b3c712/code/MathSpamProtectorField.php#L141-L155
|
224,978
|
silverstripe/silverstripe-mathspamprotection
|
code/MathSpamProtectorField.php
|
MathSpamProtectorField.digit_to_word
|
public static function digit_to_word($num)
{
$numbers = array(_t('MathSpamProtection.ZERO', 'zero'),
_t('MathSpamProtection.ONE', 'one'),
_t('MathSpamProtection.TWO', 'two'),
_t('MathSpamProtection.THREE', 'three'),
_t('MathSpamProtection.FOUR', 'four'),
_t('MathSpamProtection.FIVE', 'five'),
_t('MathSpamProtection.SIX', 'six'),
_t('MathSpamProtection.SEVEN', 'seven'),
_t('MathSpamProtection.EIGHT', 'eight'),
_t('MathSpamProtection.NINE', 'nine'),
_t('MathSpamProtection.TEN', 'ten'),
_t('MathSpamProtection.ELEVEN', 'eleven'),
_t('MathSpamProtection.TWELVE', 'twelve'),
_t('MathSpamProtection.THIRTEEN', 'thirteen'),
_t('MathSpamProtection.FOURTEEN', 'fourteen'),
_t('MathSpamProtection.FIFTEEN', 'fifteen'),
_t('MathSpamProtection.SIXTEEN', 'sixteen'),
_t('MathSpamProtection.SEVENTEEN', 'seventeen'),
_t('MathSpamProtection.EIGHTEEN', 'eighteen'));
if ($num < 0) {
return "minus ".($numbers[-1*$num]);
}
return $numbers[$num];
}
|
php
|
public static function digit_to_word($num)
{
$numbers = array(_t('MathSpamProtection.ZERO', 'zero'),
_t('MathSpamProtection.ONE', 'one'),
_t('MathSpamProtection.TWO', 'two'),
_t('MathSpamProtection.THREE', 'three'),
_t('MathSpamProtection.FOUR', 'four'),
_t('MathSpamProtection.FIVE', 'five'),
_t('MathSpamProtection.SIX', 'six'),
_t('MathSpamProtection.SEVEN', 'seven'),
_t('MathSpamProtection.EIGHT', 'eight'),
_t('MathSpamProtection.NINE', 'nine'),
_t('MathSpamProtection.TEN', 'ten'),
_t('MathSpamProtection.ELEVEN', 'eleven'),
_t('MathSpamProtection.TWELVE', 'twelve'),
_t('MathSpamProtection.THIRTEEN', 'thirteen'),
_t('MathSpamProtection.FOURTEEN', 'fourteen'),
_t('MathSpamProtection.FIFTEEN', 'fifteen'),
_t('MathSpamProtection.SIXTEEN', 'sixteen'),
_t('MathSpamProtection.SEVENTEEN', 'seventeen'),
_t('MathSpamProtection.EIGHTEEN', 'eighteen'));
if ($num < 0) {
return "minus ".($numbers[-1*$num]);
}
return $numbers[$num];
}
|
[
"public",
"static",
"function",
"digit_to_word",
"(",
"$",
"num",
")",
"{",
"$",
"numbers",
"=",
"array",
"(",
"_t",
"(",
"'MathSpamProtection.ZERO'",
",",
"'zero'",
")",
",",
"_t",
"(",
"'MathSpamProtection.ONE'",
",",
"'one'",
")",
",",
"_t",
"(",
"'MathSpamProtection.TWO'",
",",
"'two'",
")",
",",
"_t",
"(",
"'MathSpamProtection.THREE'",
",",
"'three'",
")",
",",
"_t",
"(",
"'MathSpamProtection.FOUR'",
",",
"'four'",
")",
",",
"_t",
"(",
"'MathSpamProtection.FIVE'",
",",
"'five'",
")",
",",
"_t",
"(",
"'MathSpamProtection.SIX'",
",",
"'six'",
")",
",",
"_t",
"(",
"'MathSpamProtection.SEVEN'",
",",
"'seven'",
")",
",",
"_t",
"(",
"'MathSpamProtection.EIGHT'",
",",
"'eight'",
")",
",",
"_t",
"(",
"'MathSpamProtection.NINE'",
",",
"'nine'",
")",
",",
"_t",
"(",
"'MathSpamProtection.TEN'",
",",
"'ten'",
")",
",",
"_t",
"(",
"'MathSpamProtection.ELEVEN'",
",",
"'eleven'",
")",
",",
"_t",
"(",
"'MathSpamProtection.TWELVE'",
",",
"'twelve'",
")",
",",
"_t",
"(",
"'MathSpamProtection.THIRTEEN'",
",",
"'thirteen'",
")",
",",
"_t",
"(",
"'MathSpamProtection.FOURTEEN'",
",",
"'fourteen'",
")",
",",
"_t",
"(",
"'MathSpamProtection.FIFTEEN'",
",",
"'fifteen'",
")",
",",
"_t",
"(",
"'MathSpamProtection.SIXTEEN'",
",",
"'sixteen'",
")",
",",
"_t",
"(",
"'MathSpamProtection.SEVENTEEN'",
",",
"'seventeen'",
")",
",",
"_t",
"(",
"'MathSpamProtection.EIGHTEEN'",
",",
"'eighteen'",
")",
")",
";",
"if",
"(",
"$",
"num",
"<",
"0",
")",
"{",
"return",
"\"minus \"",
".",
"(",
"$",
"numbers",
"[",
"-",
"1",
"*",
"$",
"num",
"]",
")",
";",
"}",
"return",
"$",
"numbers",
"[",
"$",
"num",
"]",
";",
"}"
] |
Helper method for converting digits to their equivalent english words
@return string
|
[
"Helper",
"method",
"for",
"converting",
"digits",
"to",
"their",
"equivalent",
"english",
"words"
] |
570eec324c89578f299e2340681b74edb7b3c712
|
https://github.com/silverstripe/silverstripe-mathspamprotection/blob/570eec324c89578f299e2340681b74edb7b3c712/code/MathSpamProtectorField.php#L162-L189
|
224,979
|
moeen-basra/laravel-passport-mongodb
|
src/PassportServiceProvider.php
|
PassportServiceProvider.registerMigrations
|
protected function registerMigrations()
{
if (Passport::$runsMigrations) {
return $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}
$this->publishes([
__DIR__.'/../database/migrations' => database_path('migrations'),
], 'passport-migrations');
}
|
php
|
protected function registerMigrations()
{
if (Passport::$runsMigrations) {
return $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}
$this->publishes([
__DIR__.'/../database/migrations' => database_path('migrations'),
], 'passport-migrations');
}
|
[
"protected",
"function",
"registerMigrations",
"(",
")",
"{",
"if",
"(",
"Passport",
"::",
"$",
"runsMigrations",
")",
"{",
"return",
"$",
"this",
"->",
"loadMigrationsFrom",
"(",
"__DIR__",
".",
"'/../database/migrations'",
")",
";",
"}",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../database/migrations'",
"=>",
"database_path",
"(",
"'migrations'",
")",
",",
"]",
",",
"'passport-migrations'",
")",
";",
"}"
] |
Register Passport's migration files.
@return void
|
[
"Register",
"Passport",
"s",
"migration",
"files",
"."
] |
738261912672e39f9f4f4e5bf420b99dbe303ef8
|
https://github.com/moeen-basra/laravel-passport-mongodb/blob/738261912672e39f9f4f4e5bf420b99dbe303ef8/src/PassportServiceProvider.php#L62-L71
|
224,980
|
moeen-basra/laravel-passport-mongodb
|
src/PassportServiceProvider.php
|
PassportServiceProvider.registerResourceServer
|
protected function registerResourceServer()
{
$this->app->singleton(ResourceServer::class, function () {
return new ResourceServer(
$this->app->make(Bridge\AccessTokenRepository::class),
$this->makeCryptKey('oauth-public.key')
);
});
}
|
php
|
protected function registerResourceServer()
{
$this->app->singleton(ResourceServer::class, function () {
return new ResourceServer(
$this->app->make(Bridge\AccessTokenRepository::class),
$this->makeCryptKey('oauth-public.key')
);
});
}
|
[
"protected",
"function",
"registerResourceServer",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"ResourceServer",
"::",
"class",
",",
"function",
"(",
")",
"{",
"return",
"new",
"ResourceServer",
"(",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Bridge",
"\\",
"AccessTokenRepository",
"::",
"class",
")",
",",
"$",
"this",
"->",
"makeCryptKey",
"(",
"'oauth-public.key'",
")",
")",
";",
"}",
")",
";",
"}"
] |
Register the resource server.
@return void
|
[
"Register",
"the",
"resource",
"server",
"."
] |
738261912672e39f9f4f4e5bf420b99dbe303ef8
|
https://github.com/moeen-basra/laravel-passport-mongodb/blob/738261912672e39f9f4f4e5bf420b99dbe303ef8/src/PassportServiceProvider.php#L213-L221
|
224,981
|
daylerees/kurenai
|
src/Parser.php
|
Parser.parse
|
public function parse($path)
{
$rawDocument = $this->loadDocument($path);
list($rawMetadata, $rawContent) = $this->splitDocument($rawDocument);
return $this->createDocument($rawDocument, $rawMetadata, $rawContent);
}
|
php
|
public function parse($path)
{
$rawDocument = $this->loadDocument($path);
list($rawMetadata, $rawContent) = $this->splitDocument($rawDocument);
return $this->createDocument($rawDocument, $rawMetadata, $rawContent);
}
|
[
"public",
"function",
"parse",
"(",
"$",
"path",
")",
"{",
"$",
"rawDocument",
"=",
"$",
"this",
"->",
"loadDocument",
"(",
"$",
"path",
")",
";",
"list",
"(",
"$",
"rawMetadata",
",",
"$",
"rawContent",
")",
"=",
"$",
"this",
"->",
"splitDocument",
"(",
"$",
"rawDocument",
")",
";",
"return",
"$",
"this",
"->",
"createDocument",
"(",
"$",
"rawDocument",
",",
"$",
"rawMetadata",
",",
"$",
"rawContent",
")",
";",
"}"
] |
Parse a document from string or file path.
@param string $path
@return void
|
[
"Parse",
"a",
"document",
"from",
"string",
"or",
"file",
"path",
"."
] |
1f8b42709666ae1d6735a970627a76fa63ed0d27
|
https://github.com/daylerees/kurenai/blob/1f8b42709666ae1d6735a970627a76fa63ed0d27/src/Parser.php#L55-L60
|
224,982
|
daylerees/kurenai
|
src/Parser.php
|
Parser.createDocument
|
protected function createDocument($raw, $rawMetadata, $rawContent)
{
return new Document(
$raw,
$this->parseMetadata(trim($rawMetadata)),
$this->parseContent(trim($rawContent))
);
}
|
php
|
protected function createDocument($raw, $rawMetadata, $rawContent)
{
return new Document(
$raw,
$this->parseMetadata(trim($rawMetadata)),
$this->parseContent(trim($rawContent))
);
}
|
[
"protected",
"function",
"createDocument",
"(",
"$",
"raw",
",",
"$",
"rawMetadata",
",",
"$",
"rawContent",
")",
"{",
"return",
"new",
"Document",
"(",
"$",
"raw",
",",
"$",
"this",
"->",
"parseMetadata",
"(",
"trim",
"(",
"$",
"rawMetadata",
")",
")",
",",
"$",
"this",
"->",
"parseContent",
"(",
"trim",
"(",
"$",
"rawContent",
")",
")",
")",
";",
"}"
] |
Create a new parsed document instance.
@param string $raw
@param string $rawMetadata
@param string $rawContent
@return \Kurenai\Document
|
[
"Create",
"a",
"new",
"parsed",
"document",
"instance",
"."
] |
1f8b42709666ae1d6735a970627a76fa63ed0d27
|
https://github.com/daylerees/kurenai/blob/1f8b42709666ae1d6735a970627a76fa63ed0d27/src/Parser.php#L99-L106
|
224,983
|
kevinem/lime-light-crm-php
|
src/LimeLightCRM.php
|
LimeLightCRM.parseResponse
|
public function parseResponse($response)
{
$array = [];
$exploded = explode('&', $response);
foreach ($exploded as $explode) {
$line = explode('=', $explode);
if (isset($line[1])) {
$array[$line[0]] = urldecode($line[1]);
} else {
$array[] = $explode;
}
}
return $array;
}
|
php
|
public function parseResponse($response)
{
$array = [];
$exploded = explode('&', $response);
foreach ($exploded as $explode) {
$line = explode('=', $explode);
if (isset($line[1])) {
$array[$line[0]] = urldecode($line[1]);
} else {
$array[] = $explode;
}
}
return $array;
}
|
[
"public",
"function",
"parseResponse",
"(",
"$",
"response",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"$",
"exploded",
"=",
"explode",
"(",
"'&'",
",",
"$",
"response",
")",
";",
"foreach",
"(",
"$",
"exploded",
"as",
"$",
"explode",
")",
"{",
"$",
"line",
"=",
"explode",
"(",
"'='",
",",
"$",
"explode",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"line",
"[",
"1",
"]",
")",
")",
"{",
"$",
"array",
"[",
"$",
"line",
"[",
"0",
"]",
"]",
"=",
"urldecode",
"(",
"$",
"line",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"array",
"[",
"]",
"=",
"$",
"explode",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] |
Parse response returned by LimeLightCRM into an array
@param $response
@return array
|
[
"Parse",
"response",
"returned",
"by",
"LimeLightCRM",
"into",
"an",
"array"
] |
33d542782ebdcee30077b9f8b35247ddf13fb5c8
|
https://github.com/kevinem/lime-light-crm-php/blob/33d542782ebdcee30077b9f8b35247ddf13fb5c8/src/LimeLightCRM.php#L134-L151
|
224,984
|
ongr-io/TranslationsBundle
|
Service/Import/ImportManager.php
|
ImportManager.writeToStorage
|
public function writeToStorage($domain, $translations)
{
foreach ($translations as $keys) {
foreach ($keys as $key => $transMeta) {
$search = $this->repository->createSearch();
$search->addQuery(new MatchQuery('key', $key));
$results = $this->repository->findDocuments($search);
if (count($results)) {
continue;
}
$document = new Translation();
$document->setDomain($domain);
$document->setKey($key);
$document->setPath($transMeta['path']);
$document->setFormat($transMeta['format']);
foreach ($transMeta['messages'] as $locale => $text) {
$message = new Message();
$message->setLocale($locale);
$message->setMessage($text);
$document->addMessage($message);
}
$this->manager->persist($document);
}
}
$this->manager->commit();
}
|
php
|
public function writeToStorage($domain, $translations)
{
foreach ($translations as $keys) {
foreach ($keys as $key => $transMeta) {
$search = $this->repository->createSearch();
$search->addQuery(new MatchQuery('key', $key));
$results = $this->repository->findDocuments($search);
if (count($results)) {
continue;
}
$document = new Translation();
$document->setDomain($domain);
$document->setKey($key);
$document->setPath($transMeta['path']);
$document->setFormat($transMeta['format']);
foreach ($transMeta['messages'] as $locale => $text) {
$message = new Message();
$message->setLocale($locale);
$message->setMessage($text);
$document->addMessage($message);
}
$this->manager->persist($document);
}
}
$this->manager->commit();
}
|
[
"public",
"function",
"writeToStorage",
"(",
"$",
"domain",
",",
"$",
"translations",
")",
"{",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"keys",
")",
"{",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
"=>",
"$",
"transMeta",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"repository",
"->",
"createSearch",
"(",
")",
";",
"$",
"search",
"->",
"addQuery",
"(",
"new",
"MatchQuery",
"(",
"'key'",
",",
"$",
"key",
")",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"repository",
"->",
"findDocuments",
"(",
"$",
"search",
")",
";",
"if",
"(",
"count",
"(",
"$",
"results",
")",
")",
"{",
"continue",
";",
"}",
"$",
"document",
"=",
"new",
"Translation",
"(",
")",
";",
"$",
"document",
"->",
"setDomain",
"(",
"$",
"domain",
")",
";",
"$",
"document",
"->",
"setKey",
"(",
"$",
"key",
")",
";",
"$",
"document",
"->",
"setPath",
"(",
"$",
"transMeta",
"[",
"'path'",
"]",
")",
";",
"$",
"document",
"->",
"setFormat",
"(",
"$",
"transMeta",
"[",
"'format'",
"]",
")",
";",
"foreach",
"(",
"$",
"transMeta",
"[",
"'messages'",
"]",
"as",
"$",
"locale",
"=>",
"$",
"text",
")",
"{",
"$",
"message",
"=",
"new",
"Message",
"(",
")",
";",
"$",
"message",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"$",
"message",
"->",
"setMessage",
"(",
"$",
"text",
")",
";",
"$",
"document",
"->",
"addMessage",
"(",
"$",
"message",
")",
";",
"}",
"$",
"this",
"->",
"manager",
"->",
"persist",
"(",
"$",
"document",
")",
";",
"}",
"}",
"$",
"this",
"->",
"manager",
"->",
"commit",
"(",
")",
";",
"}"
] |
Write translations to storage.
@param $translations
|
[
"Write",
"translations",
"to",
"storage",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/Import/ImportManager.php#L91-L118
|
224,985
|
ongr-io/TranslationsBundle
|
Service/Import/ImportManager.php
|
ImportManager.importTranslationFiles
|
public function importTranslationFiles($domain, $dir)
{
$translations = $this->getTranslationsFromFiles($domain, $dir);
$this->writeToStorage($domain, $translations);
}
|
php
|
public function importTranslationFiles($domain, $dir)
{
$translations = $this->getTranslationsFromFiles($domain, $dir);
$this->writeToStorage($domain, $translations);
}
|
[
"public",
"function",
"importTranslationFiles",
"(",
"$",
"domain",
",",
"$",
"dir",
")",
"{",
"$",
"translations",
"=",
"$",
"this",
"->",
"getTranslationsFromFiles",
"(",
"$",
"domain",
",",
"$",
"dir",
")",
";",
"$",
"this",
"->",
"writeToStorage",
"(",
"$",
"domain",
",",
"$",
"translations",
")",
";",
"}"
] |
Imports translation files from a directory.
@param string $dir
|
[
"Imports",
"translation",
"files",
"from",
"a",
"directory",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Service/Import/ImportManager.php#L139-L143
|
224,986
|
hendrikmaus/drafter-php
|
src/Drafter.php
|
Drafter.getProcessCommand
|
private function getProcessCommand()
{
$options = $this->transformOptions();
$options[] = escapeshellarg($this->input);
$command = $this->binary . ' ' . implode(' ', $options);
return $command;
}
|
php
|
private function getProcessCommand()
{
$options = $this->transformOptions();
$options[] = escapeshellarg($this->input);
$command = $this->binary . ' ' . implode(' ', $options);
return $command;
}
|
[
"private",
"function",
"getProcessCommand",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"transformOptions",
"(",
")",
";",
"$",
"options",
"[",
"]",
"=",
"escapeshellarg",
"(",
"$",
"this",
"->",
"input",
")",
";",
"$",
"command",
"=",
"$",
"this",
"->",
"binary",
".",
"' '",
".",
"implode",
"(",
"' '",
",",
"$",
"options",
")",
";",
"return",
"$",
"command",
";",
"}"
] |
Get command to pass it into the process.
The method will append the input file path argument to the end, like
described in the `drafter --help` output.
@return string
|
[
"Get",
"command",
"to",
"pass",
"it",
"into",
"the",
"process",
"."
] |
c6f91b2472c7dfb23ac63a6a69515280ccc227ed
|
https://github.com/hendrikmaus/drafter-php/blob/c6f91b2472c7dfb23ac63a6a69515280ccc227ed/src/Drafter.php#L247-L255
|
224,987
|
hendrikmaus/drafter-php
|
src/Drafter.php
|
Drafter.transformOptions
|
private function transformOptions()
{
$processOptions = [];
foreach ($this->options as $key => $value) {
$option = $key;
if ($value) {
$option .= '=' . escapeshellarg($value);
}
$processOptions[] = $option;
}
return $processOptions;
}
|
php
|
private function transformOptions()
{
$processOptions = [];
foreach ($this->options as $key => $value) {
$option = $key;
if ($value) {
$option .= '=' . escapeshellarg($value);
}
$processOptions[] = $option;
}
return $processOptions;
}
|
[
"private",
"function",
"transformOptions",
"(",
")",
"{",
"$",
"processOptions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"option",
"=",
"$",
"key",
";",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"option",
".=",
"'='",
".",
"escapeshellarg",
"(",
"$",
"value",
")",
";",
"}",
"$",
"processOptions",
"[",
"]",
"=",
"$",
"option",
";",
"}",
"return",
"$",
"processOptions",
";",
"}"
] |
Return options prepared to be passed into the Process.
E.g.: ["--output" => "path/to/file"] -> ["--output=path/to/file"]
The original format is an associative array, where the key is the
option name and the value is the respective value.
The process will want those as single strings to escape them
for the command line. Hence, we have to turn ["--output" => "path/to/file"]
into ["--output=path/to/file"].
@return \string[]
|
[
"Return",
"options",
"prepared",
"to",
"be",
"passed",
"into",
"the",
"Process",
"."
] |
c6f91b2472c7dfb23ac63a6a69515280ccc227ed
|
https://github.com/hendrikmaus/drafter-php/blob/c6f91b2472c7dfb23ac63a6a69515280ccc227ed/src/Drafter.php#L270-L285
|
224,988
|
moeen-basra/laravel-passport-mongodb
|
src/Http/Controllers/HandlesOAuthErrors.php
|
HandlesOAuthErrors.withErrorHandling
|
protected function withErrorHandling($callback)
{
try {
return $callback();
} catch (OAuthServerException $e) {
$this->exceptionHandler()->report($e);
return $this->convertResponse(
$e->generateHttpResponse(new Psr7Response)
);
} catch (Exception $e) {
$this->exceptionHandler()->report($e);
return new Response($e->getMessage(), 500);
} catch (Throwable $e) {
$this->exceptionHandler()->report(new FatalThrowableError($e));
return new Response($e->getMessage(), 500);
}
}
|
php
|
protected function withErrorHandling($callback)
{
try {
return $callback();
} catch (OAuthServerException $e) {
$this->exceptionHandler()->report($e);
return $this->convertResponse(
$e->generateHttpResponse(new Psr7Response)
);
} catch (Exception $e) {
$this->exceptionHandler()->report($e);
return new Response($e->getMessage(), 500);
} catch (Throwable $e) {
$this->exceptionHandler()->report(new FatalThrowableError($e));
return new Response($e->getMessage(), 500);
}
}
|
[
"protected",
"function",
"withErrorHandling",
"(",
"$",
"callback",
")",
"{",
"try",
"{",
"return",
"$",
"callback",
"(",
")",
";",
"}",
"catch",
"(",
"OAuthServerException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"exceptionHandler",
"(",
")",
"->",
"report",
"(",
"$",
"e",
")",
";",
"return",
"$",
"this",
"->",
"convertResponse",
"(",
"$",
"e",
"->",
"generateHttpResponse",
"(",
"new",
"Psr7Response",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"exceptionHandler",
"(",
")",
"->",
"report",
"(",
"$",
"e",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"500",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"exceptionHandler",
"(",
")",
"->",
"report",
"(",
"new",
"FatalThrowableError",
"(",
"$",
"e",
")",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"500",
")",
";",
"}",
"}"
] |
Perform the given callback with exception handling.
@param \Closure $callback
@return \Illuminate\Http\Response
|
[
"Perform",
"the",
"given",
"callback",
"with",
"exception",
"handling",
"."
] |
738261912672e39f9f4f4e5bf420b99dbe303ef8
|
https://github.com/moeen-basra/laravel-passport-mongodb/blob/738261912672e39f9f4f4e5bf420b99dbe303ef8/src/Http/Controllers/HandlesOAuthErrors.php#L24-L43
|
224,989
|
unholyknight/active-directory-authenticate
|
src/Auth/AdldapAuthenticate.php
|
AdldapAuthenticate._cleanAttributes
|
protected function _cleanAttributes($attributes)
{
foreach ($attributes as $key => $value) {
if (is_int($key) || in_array($key, $this->_config['ignored'])) {
unset($attributes[$key]);
} else if ($key != 'memberof' && is_array($value) && count($value) == 1) {
$attributes[$key] = $value[0];
}
}
return $attributes;
}
|
php
|
protected function _cleanAttributes($attributes)
{
foreach ($attributes as $key => $value) {
if (is_int($key) || in_array($key, $this->_config['ignored'])) {
unset($attributes[$key]);
} else if ($key != 'memberof' && is_array($value) && count($value) == 1) {
$attributes[$key] = $value[0];
}
}
return $attributes;
}
|
[
"protected",
"function",
"_cleanAttributes",
"(",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
"||",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"_config",
"[",
"'ignored'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"key",
"!=",
"'memberof'",
"&&",
"is_array",
"(",
"$",
"value",
")",
"&&",
"count",
"(",
"$",
"value",
")",
"==",
"1",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"$",
"attributes",
";",
"}"
] |
Clean an array of user attributes
@param array $attributes Array of attributes to clean up against the ignored setting.
@return array An array of attributes stripped of ignored keys.
|
[
"Clean",
"an",
"array",
"of",
"user",
"attributes"
] |
73c34c5ebfded0e6e9b8148dd9350e8c9c59473e
|
https://github.com/unholyknight/active-directory-authenticate/blob/73c34c5ebfded0e6e9b8148dd9350e8c9c59473e/src/Auth/AdldapAuthenticate.php#L50-L61
|
224,990
|
unholyknight/active-directory-authenticate
|
src/Auth/AdldapAuthenticate.php
|
AdldapAuthenticate._cleanGroups
|
protected function _cleanGroups($memberships)
{
$groups = [];
foreach ($memberships as $group) {
$parts = explode(',', $group);
foreach ($parts as $part) {
if (substr($part, 0, 3) == 'CN=') {
$groups[] = substr($part, 3);
break;
}
}
}
return $groups;
}
|
php
|
protected function _cleanGroups($memberships)
{
$groups = [];
foreach ($memberships as $group) {
$parts = explode(',', $group);
foreach ($parts as $part) {
if (substr($part, 0, 3) == 'CN=') {
$groups[] = substr($part, 3);
break;
}
}
}
return $groups;
}
|
[
"protected",
"function",
"_cleanGroups",
"(",
"$",
"memberships",
")",
"{",
"$",
"groups",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"memberships",
"as",
"$",
"group",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"','",
",",
"$",
"group",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"part",
",",
"0",
",",
"3",
")",
"==",
"'CN='",
")",
"{",
"$",
"groups",
"[",
"]",
"=",
"substr",
"(",
"$",
"part",
",",
"3",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"groups",
";",
"}"
] |
Create a friendly, formatted groups array
@param array $memberships Array of memberships to create a friendly array for.
@return array An array of friendly group names.
|
[
"Create",
"a",
"friendly",
"formatted",
"groups",
"array"
] |
73c34c5ebfded0e6e9b8148dd9350e8c9c59473e
|
https://github.com/unholyknight/active-directory-authenticate/blob/73c34c5ebfded0e6e9b8148dd9350e8c9c59473e/src/Auth/AdldapAuthenticate.php#L69-L84
|
224,991
|
unholyknight/active-directory-authenticate
|
src/Auth/AdldapAuthenticate.php
|
AdldapAuthenticate.findAdUser
|
public function findAdUser($username, $password)
{
try {
$this->ad->connect('default');
if ($this->provider->auth()->attempt($username, $password, true)) {
$search = $this->provider->search();
if (is_array($this->_config['select'])) {
if (!in_array('memberof', $this->_config['select'])) {
$this->_config['select'][] = 'memberof';
}
$search->select($this->_config['select']);
}
$user = $search->whereEquals('samaccountname', $username)->first();
$attributes = $user->getAttributes();
if (!is_array($this->_config['ignored'])) {
$this->_config['ignored'] = [];
}
$attributes = $this->_cleanAttributes($attributes);
$attributes['groups'] = $this->_cleanGroups($attributes['memberof']);
return $attributes;
}
return false;
} catch (\Adldap\Exceptions\Auth\BindException $e) {
throw new \RuntimeException('Failed to bind to LDAP server. Check Auth configuration settings.');
}
}
|
php
|
public function findAdUser($username, $password)
{
try {
$this->ad->connect('default');
if ($this->provider->auth()->attempt($username, $password, true)) {
$search = $this->provider->search();
if (is_array($this->_config['select'])) {
if (!in_array('memberof', $this->_config['select'])) {
$this->_config['select'][] = 'memberof';
}
$search->select($this->_config['select']);
}
$user = $search->whereEquals('samaccountname', $username)->first();
$attributes = $user->getAttributes();
if (!is_array($this->_config['ignored'])) {
$this->_config['ignored'] = [];
}
$attributes = $this->_cleanAttributes($attributes);
$attributes['groups'] = $this->_cleanGroups($attributes['memberof']);
return $attributes;
}
return false;
} catch (\Adldap\Exceptions\Auth\BindException $e) {
throw new \RuntimeException('Failed to bind to LDAP server. Check Auth configuration settings.');
}
}
|
[
"public",
"function",
"findAdUser",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"ad",
"->",
"connect",
"(",
"'default'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"provider",
"->",
"auth",
"(",
")",
"->",
"attempt",
"(",
"$",
"username",
",",
"$",
"password",
",",
"true",
")",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"provider",
"->",
"search",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_config",
"[",
"'select'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"'memberof'",
",",
"$",
"this",
"->",
"_config",
"[",
"'select'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'select'",
"]",
"[",
"]",
"=",
"'memberof'",
";",
"}",
"$",
"search",
"->",
"select",
"(",
"$",
"this",
"->",
"_config",
"[",
"'select'",
"]",
")",
";",
"}",
"$",
"user",
"=",
"$",
"search",
"->",
"whereEquals",
"(",
"'samaccountname'",
",",
"$",
"username",
")",
"->",
"first",
"(",
")",
";",
"$",
"attributes",
"=",
"$",
"user",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"_config",
"[",
"'ignored'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'ignored'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"attributes",
"=",
"$",
"this",
"->",
"_cleanAttributes",
"(",
"$",
"attributes",
")",
";",
"$",
"attributes",
"[",
"'groups'",
"]",
"=",
"$",
"this",
"->",
"_cleanGroups",
"(",
"$",
"attributes",
"[",
"'memberof'",
"]",
")",
";",
"return",
"$",
"attributes",
";",
"}",
"return",
"false",
";",
"}",
"catch",
"(",
"\\",
"Adldap",
"\\",
"Exceptions",
"\\",
"Auth",
"\\",
"BindException",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Failed to bind to LDAP server. Check Auth configuration settings.'",
")",
";",
"}",
"}"
] |
Connect to Active Directory on behalf of a user and return that user's data.
@param string $username The username (samaccountname).
@param string $password The password.
@return mixed False on failure. An array of user data on success.
|
[
"Connect",
"to",
"Active",
"Directory",
"on",
"behalf",
"of",
"a",
"user",
"and",
"return",
"that",
"user",
"s",
"data",
"."
] |
73c34c5ebfded0e6e9b8148dd9350e8c9c59473e
|
https://github.com/unholyknight/active-directory-authenticate/blob/73c34c5ebfded0e6e9b8148dd9350e8c9c59473e/src/Auth/AdldapAuthenticate.php#L109-L141
|
224,992
|
bem/bh-php
|
src/JsonCollection.php
|
JsonCollection.normalize
|
public static function normalize($bemJson)
{
switch (true) {
// instance of JsonCollection
case $bemJson instanceof self:
return $bemJson;
// casual list
case isList($bemJson);
$bemJson = static::flattenList($bemJson);
case $bemJson instanceof \Iterator:
$content = [];
foreach ($bemJson as $node) {
$content[] = static::normalizeItem($node);
}
$ret = $content;
break;
// casual bemJson node
case is_array($bemJson):
$ret = [static::normalizeItem($bemJson)];
break;
// instance of Json
case $bemJson instanceof Json:
$ret = [$bemJson];
break;
// custom object (not array)
case is_object($bemJson):
$ret = [new Json($bemJson)];
break;
case is_scalar($bemJson):
$ret = [$bemJson];
break;
default:
throw new \InvalidArgumentException('Passed variable is not an array or object or string');
}
$res = new static($ret);
return $res;
}
|
php
|
public static function normalize($bemJson)
{
switch (true) {
// instance of JsonCollection
case $bemJson instanceof self:
return $bemJson;
// casual list
case isList($bemJson);
$bemJson = static::flattenList($bemJson);
case $bemJson instanceof \Iterator:
$content = [];
foreach ($bemJson as $node) {
$content[] = static::normalizeItem($node);
}
$ret = $content;
break;
// casual bemJson node
case is_array($bemJson):
$ret = [static::normalizeItem($bemJson)];
break;
// instance of Json
case $bemJson instanceof Json:
$ret = [$bemJson];
break;
// custom object (not array)
case is_object($bemJson):
$ret = [new Json($bemJson)];
break;
case is_scalar($bemJson):
$ret = [$bemJson];
break;
default:
throw new \InvalidArgumentException('Passed variable is not an array or object or string');
}
$res = new static($ret);
return $res;
}
|
[
"public",
"static",
"function",
"normalize",
"(",
"$",
"bemJson",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"// instance of JsonCollection",
"case",
"$",
"bemJson",
"instanceof",
"self",
":",
"return",
"$",
"bemJson",
";",
"// casual list",
"case",
"isList",
"(",
"$",
"bemJson",
")",
";",
"$",
"bemJson",
"=",
"static",
"::",
"flattenList",
"(",
"$",
"bemJson",
")",
";",
"case",
"$",
"bemJson",
"instanceof",
"\\",
"Iterator",
":",
"$",
"content",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"bemJson",
"as",
"$",
"node",
")",
"{",
"$",
"content",
"[",
"]",
"=",
"static",
"::",
"normalizeItem",
"(",
"$",
"node",
")",
";",
"}",
"$",
"ret",
"=",
"$",
"content",
";",
"break",
";",
"// casual bemJson node",
"case",
"is_array",
"(",
"$",
"bemJson",
")",
":",
"$",
"ret",
"=",
"[",
"static",
"::",
"normalizeItem",
"(",
"$",
"bemJson",
")",
"]",
";",
"break",
";",
"// instance of Json",
"case",
"$",
"bemJson",
"instanceof",
"Json",
":",
"$",
"ret",
"=",
"[",
"$",
"bemJson",
"]",
";",
"break",
";",
"// custom object (not array)",
"case",
"is_object",
"(",
"$",
"bemJson",
")",
":",
"$",
"ret",
"=",
"[",
"new",
"Json",
"(",
"$",
"bemJson",
")",
"]",
";",
"break",
";",
"case",
"is_scalar",
"(",
"$",
"bemJson",
")",
":",
"$",
"ret",
"=",
"[",
"$",
"bemJson",
"]",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Passed variable is not an array or object or string'",
")",
";",
"}",
"$",
"res",
"=",
"new",
"static",
"(",
"$",
"ret",
")",
";",
"return",
"$",
"res",
";",
"}"
] |
Normalize bemJson node or list or tree
@param array|object $bemJson
@return JsonCollection
|
[
"Normalize",
"bemJson",
"node",
"or",
"list",
"or",
"tree"
] |
2f46ccb3f32cba1836ed70d28ee0d02b0e7684e2
|
https://github.com/bem/bh-php/blob/2f46ccb3f32cba1836ed70d28ee0d02b0e7684e2/src/JsonCollection.php#L48-L92
|
224,993
|
bem/bh-php
|
src/JsonCollection.php
|
JsonCollection.flattenList
|
public static function flattenList($a)
{
if (!isList($a)) {
return $a;
}
do {
$flatten = false;
for ($i = 0, $l = sizeof($a); $i < $l; $i++) {
if (isList($a[$i])) {
$flatten = true;
break;
}
}
if (!$flatten) {
break;
}
$res = [];
for ($i = 0; $i < $l; $i++) {
if (!isList($a[$i])) {
// filter empty arrays inside
if (!(is_array($a[$i]) && empty($a[$i]))) {
$res[] = $a[$i];
}
} else {
$res = array_merge($res, (array)$a[$i]);
}
}
$a = $res;
} while ($flatten);
return $a;
}
|
php
|
public static function flattenList($a)
{
if (!isList($a)) {
return $a;
}
do {
$flatten = false;
for ($i = 0, $l = sizeof($a); $i < $l; $i++) {
if (isList($a[$i])) {
$flatten = true;
break;
}
}
if (!$flatten) {
break;
}
$res = [];
for ($i = 0; $i < $l; $i++) {
if (!isList($a[$i])) {
// filter empty arrays inside
if (!(is_array($a[$i]) && empty($a[$i]))) {
$res[] = $a[$i];
}
} else {
$res = array_merge($res, (array)$a[$i]);
}
}
$a = $res;
} while ($flatten);
return $a;
}
|
[
"public",
"static",
"function",
"flattenList",
"(",
"$",
"a",
")",
"{",
"if",
"(",
"!",
"isList",
"(",
"$",
"a",
")",
")",
"{",
"return",
"$",
"a",
";",
"}",
"do",
"{",
"$",
"flatten",
"=",
"false",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"l",
"=",
"sizeof",
"(",
"$",
"a",
")",
";",
"$",
"i",
"<",
"$",
"l",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isList",
"(",
"$",
"a",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"flatten",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"flatten",
")",
"{",
"break",
";",
"}",
"$",
"res",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"l",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isList",
"(",
"$",
"a",
"[",
"$",
"i",
"]",
")",
")",
"{",
"// filter empty arrays inside",
"if",
"(",
"!",
"(",
"is_array",
"(",
"$",
"a",
"[",
"$",
"i",
"]",
")",
"&&",
"empty",
"(",
"$",
"a",
"[",
"$",
"i",
"]",
")",
")",
")",
"{",
"$",
"res",
"[",
"]",
"=",
"$",
"a",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"res",
"=",
"array_merge",
"(",
"$",
"res",
",",
"(",
"array",
")",
"$",
"a",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"$",
"a",
"=",
"$",
"res",
";",
"}",
"while",
"(",
"$",
"flatten",
")",
";",
"return",
"$",
"a",
";",
"}"
] |
Brings items of inner simple arrays to root level if exists
@param array $a
@return array
|
[
"Brings",
"items",
"of",
"inner",
"simple",
"arrays",
"to",
"root",
"level",
"if",
"exists"
] |
2f46ccb3f32cba1836ed70d28ee0d02b0e7684e2
|
https://github.com/bem/bh-php/blob/2f46ccb3f32cba1836ed70d28ee0d02b0e7684e2/src/JsonCollection.php#L120-L152
|
224,994
|
auraphp/Aura.Uri
|
src/Aura/Uri/PublicSuffixList.php
|
PublicSuffixList.getPublicSuffix
|
public function getPublicSuffix($host)
{
if (strpos($host, '.') === 0) {
return null;
}
if (strpos($host, '.') === false) {
return null;
}
$host = strtolower($host);
$parts = array_reverse(explode('.', $host));
$publicSuffix = array();
$psl = $this->psl;
foreach ($parts as $part) {
if (array_key_exists($part, $psl)
&& array_key_exists('!', $psl[$part])) {
break;
}
if (array_key_exists($part, $psl)) {
array_unshift($publicSuffix, $part);
$psl = $psl[$part];
continue;
}
if (array_key_exists('*', $psl)) {
array_unshift($publicSuffix, $part);
$psl = $psl['*'];
continue;
}
// Avoids improper parsing when $host's subdomain + public suffix ===
// a valid public suffix (e.g. host 'us.example.com' and public suffix 'us.com')
break;
}
// Apply algorithm rule #2: If no rules match, the prevailing rule is "*".
if (empty($publicSuffix)) {
$publicSuffix[0] = $parts[0];
}
return implode('.', array_filter($publicSuffix, 'strlen'));
}
|
php
|
public function getPublicSuffix($host)
{
if (strpos($host, '.') === 0) {
return null;
}
if (strpos($host, '.') === false) {
return null;
}
$host = strtolower($host);
$parts = array_reverse(explode('.', $host));
$publicSuffix = array();
$psl = $this->psl;
foreach ($parts as $part) {
if (array_key_exists($part, $psl)
&& array_key_exists('!', $psl[$part])) {
break;
}
if (array_key_exists($part, $psl)) {
array_unshift($publicSuffix, $part);
$psl = $psl[$part];
continue;
}
if (array_key_exists('*', $psl)) {
array_unshift($publicSuffix, $part);
$psl = $psl['*'];
continue;
}
// Avoids improper parsing when $host's subdomain + public suffix ===
// a valid public suffix (e.g. host 'us.example.com' and public suffix 'us.com')
break;
}
// Apply algorithm rule #2: If no rules match, the prevailing rule is "*".
if (empty($publicSuffix)) {
$publicSuffix[0] = $parts[0];
}
return implode('.', array_filter($publicSuffix, 'strlen'));
}
|
[
"public",
"function",
"getPublicSuffix",
"(",
"$",
"host",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"host",
",",
"'.'",
")",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"host",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"$",
"host",
"=",
"strtolower",
"(",
"$",
"host",
")",
";",
"$",
"parts",
"=",
"array_reverse",
"(",
"explode",
"(",
"'.'",
",",
"$",
"host",
")",
")",
";",
"$",
"publicSuffix",
"=",
"array",
"(",
")",
";",
"$",
"psl",
"=",
"$",
"this",
"->",
"psl",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"part",
",",
"$",
"psl",
")",
"&&",
"array_key_exists",
"(",
"'!'",
",",
"$",
"psl",
"[",
"$",
"part",
"]",
")",
")",
"{",
"break",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"part",
",",
"$",
"psl",
")",
")",
"{",
"array_unshift",
"(",
"$",
"publicSuffix",
",",
"$",
"part",
")",
";",
"$",
"psl",
"=",
"$",
"psl",
"[",
"$",
"part",
"]",
";",
"continue",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'*'",
",",
"$",
"psl",
")",
")",
"{",
"array_unshift",
"(",
"$",
"publicSuffix",
",",
"$",
"part",
")",
";",
"$",
"psl",
"=",
"$",
"psl",
"[",
"'*'",
"]",
";",
"continue",
";",
"}",
"// Avoids improper parsing when $host's subdomain + public suffix === ",
"// a valid public suffix (e.g. host 'us.example.com' and public suffix 'us.com')",
"break",
";",
"}",
"// Apply algorithm rule #2: If no rules match, the prevailing rule is \"*\".",
"if",
"(",
"empty",
"(",
"$",
"publicSuffix",
")",
")",
"{",
"$",
"publicSuffix",
"[",
"0",
"]",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"}",
"return",
"implode",
"(",
"'.'",
",",
"array_filter",
"(",
"$",
"publicSuffix",
",",
"'strlen'",
")",
")",
";",
"}"
] |
Returns the public suffix portion of provided host
@param string $host host
@return string public suffix
|
[
"Returns",
"the",
"public",
"suffix",
"portion",
"of",
"provided",
"host"
] |
e3b4ae381daaa8737f0a23ba9c7e2c9f52219a3a
|
https://github.com/auraphp/Aura.Uri/blob/e3b4ae381daaa8737f0a23ba9c7e2c9f52219a3a/src/Aura/Uri/PublicSuffixList.php#L49-L93
|
224,995
|
auraphp/Aura.Uri
|
src/Aura/Uri/PublicSuffixList.php
|
PublicSuffixList.getRegisterableDomain
|
public function getRegisterableDomain($host)
{
if (strpos($host, '.') === false) {
return null;
}
$host = strtolower($host);
$publicSuffix = $this->getPublicSuffix($host);
if ($publicSuffix === null || $host == $publicSuffix) {
return null;
}
$publicSuffixParts = array_reverse(explode('.', $publicSuffix));
$hostParts = array_reverse(explode('.', $host));
$registerableDomainParts = array_slice($hostParts, 0, count($publicSuffixParts) + 1);
return implode('.', array_reverse($registerableDomainParts));
}
|
php
|
public function getRegisterableDomain($host)
{
if (strpos($host, '.') === false) {
return null;
}
$host = strtolower($host);
$publicSuffix = $this->getPublicSuffix($host);
if ($publicSuffix === null || $host == $publicSuffix) {
return null;
}
$publicSuffixParts = array_reverse(explode('.', $publicSuffix));
$hostParts = array_reverse(explode('.', $host));
$registerableDomainParts = array_slice($hostParts, 0, count($publicSuffixParts) + 1);
return implode('.', array_reverse($registerableDomainParts));
}
|
[
"public",
"function",
"getRegisterableDomain",
"(",
"$",
"host",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"host",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"$",
"host",
"=",
"strtolower",
"(",
"$",
"host",
")",
";",
"$",
"publicSuffix",
"=",
"$",
"this",
"->",
"getPublicSuffix",
"(",
"$",
"host",
")",
";",
"if",
"(",
"$",
"publicSuffix",
"===",
"null",
"||",
"$",
"host",
"==",
"$",
"publicSuffix",
")",
"{",
"return",
"null",
";",
"}",
"$",
"publicSuffixParts",
"=",
"array_reverse",
"(",
"explode",
"(",
"'.'",
",",
"$",
"publicSuffix",
")",
")",
";",
"$",
"hostParts",
"=",
"array_reverse",
"(",
"explode",
"(",
"'.'",
",",
"$",
"host",
")",
")",
";",
"$",
"registerableDomainParts",
"=",
"array_slice",
"(",
"$",
"hostParts",
",",
"0",
",",
"count",
"(",
"$",
"publicSuffixParts",
")",
"+",
"1",
")",
";",
"return",
"implode",
"(",
"'.'",
",",
"array_reverse",
"(",
"$",
"registerableDomainParts",
")",
")",
";",
"}"
] |
Returns registerable domain portion of provided host
Per the test cases provided by Mozilla
(http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1),
this method should return null if the domain provided is a public suffix.
@param string $host host
@return string registerable domain
|
[
"Returns",
"registerable",
"domain",
"portion",
"of",
"provided",
"host"
] |
e3b4ae381daaa8737f0a23ba9c7e2c9f52219a3a
|
https://github.com/auraphp/Aura.Uri/blob/e3b4ae381daaa8737f0a23ba9c7e2c9f52219a3a/src/Aura/Uri/PublicSuffixList.php#L105-L123
|
224,996
|
auraphp/Aura.Uri
|
src/Aura/Uri/PublicSuffixList.php
|
PublicSuffixList.getSubdomain
|
public function getSubdomain($host)
{
$host = strtolower($host);
$registerableDomain = $this->getRegisterableDomain($host);
if ($registerableDomain === null || $host == $registerableDomain) {
return null;
}
$registerableDomainParts = array_reverse(explode('.', $registerableDomain));
$hostParts = array_reverse(explode('.', $host));
$subdomainParts = array_slice($hostParts, count($registerableDomainParts));
return implode('.', array_reverse($subdomainParts));
}
|
php
|
public function getSubdomain($host)
{
$host = strtolower($host);
$registerableDomain = $this->getRegisterableDomain($host);
if ($registerableDomain === null || $host == $registerableDomain) {
return null;
}
$registerableDomainParts = array_reverse(explode('.', $registerableDomain));
$hostParts = array_reverse(explode('.', $host));
$subdomainParts = array_slice($hostParts, count($registerableDomainParts));
return implode('.', array_reverse($subdomainParts));
}
|
[
"public",
"function",
"getSubdomain",
"(",
"$",
"host",
")",
"{",
"$",
"host",
"=",
"strtolower",
"(",
"$",
"host",
")",
";",
"$",
"registerableDomain",
"=",
"$",
"this",
"->",
"getRegisterableDomain",
"(",
"$",
"host",
")",
";",
"if",
"(",
"$",
"registerableDomain",
"===",
"null",
"||",
"$",
"host",
"==",
"$",
"registerableDomain",
")",
"{",
"return",
"null",
";",
"}",
"$",
"registerableDomainParts",
"=",
"array_reverse",
"(",
"explode",
"(",
"'.'",
",",
"$",
"registerableDomain",
")",
")",
";",
"$",
"hostParts",
"=",
"array_reverse",
"(",
"explode",
"(",
"'.'",
",",
"$",
"host",
")",
")",
";",
"$",
"subdomainParts",
"=",
"array_slice",
"(",
"$",
"hostParts",
",",
"count",
"(",
"$",
"registerableDomainParts",
")",
")",
";",
"return",
"implode",
"(",
"'.'",
",",
"array_reverse",
"(",
"$",
"subdomainParts",
")",
")",
";",
"}"
] |
Returns the subdomain portion of provided host
@param string $host host
@return string subdomain
|
[
"Returns",
"the",
"subdomain",
"portion",
"of",
"provided",
"host"
] |
e3b4ae381daaa8737f0a23ba9c7e2c9f52219a3a
|
https://github.com/auraphp/Aura.Uri/blob/e3b4ae381daaa8737f0a23ba9c7e2c9f52219a3a/src/Aura/Uri/PublicSuffixList.php#L131-L145
|
224,997
|
ongr-io/TranslationsBundle
|
Controller/ApiController.php
|
ApiController.updateAction
|
public function updateAction(Request $request, $id)
{
$response = ['error' => false];
try {
$this->get('ongr_translations.translation_manager')->edit($id, $request);
} catch (\LogicException $e) {
$response = ['error' => true];
}
return new JsonResponse($response);
}
|
php
|
public function updateAction(Request $request, $id)
{
$response = ['error' => false];
try {
$this->get('ongr_translations.translation_manager')->edit($id, $request);
} catch (\LogicException $e) {
$response = ['error' => true];
}
return new JsonResponse($response);
}
|
[
"public",
"function",
"updateAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"response",
"=",
"[",
"'error'",
"=>",
"false",
"]",
";",
"try",
"{",
"$",
"this",
"->",
"get",
"(",
"'ongr_translations.translation_manager'",
")",
"->",
"edit",
"(",
"$",
"id",
",",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"\\",
"LogicException",
"$",
"e",
")",
"{",
"$",
"response",
"=",
"[",
"'error'",
"=>",
"true",
"]",
";",
"}",
"return",
"new",
"JsonResponse",
"(",
"$",
"response",
")",
";",
"}"
] |
Action for editing translation objects.
@param Request $request Http request object.
@param string $id
@return JsonResponse
|
[
"Action",
"for",
"editing",
"translation",
"objects",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Controller/ApiController.php#L33-L44
|
224,998
|
ongr-io/TranslationsBundle
|
Controller/ApiController.php
|
ApiController.exportAction
|
public function exportAction()
{
$cwd = getcwd();
if (substr($cwd, -3) === 'web') {
chdir($cwd . DIRECTORY_SEPARATOR . '..');
}
$output = ['error' => false];
if ($this->get('ongr_translations.command.export')->run(new ArrayInput([]), new NullOutput()) != 0) {
$output['error'] = true;
}
return new JsonResponse($output);
}
|
php
|
public function exportAction()
{
$cwd = getcwd();
if (substr($cwd, -3) === 'web') {
chdir($cwd . DIRECTORY_SEPARATOR . '..');
}
$output = ['error' => false];
if ($this->get('ongr_translations.command.export')->run(new ArrayInput([]), new NullOutput()) != 0) {
$output['error'] = true;
}
return new JsonResponse($output);
}
|
[
"public",
"function",
"exportAction",
"(",
")",
"{",
"$",
"cwd",
"=",
"getcwd",
"(",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"cwd",
",",
"-",
"3",
")",
"===",
"'web'",
")",
"{",
"chdir",
"(",
"$",
"cwd",
".",
"DIRECTORY_SEPARATOR",
".",
"'..'",
")",
";",
"}",
"$",
"output",
"=",
"[",
"'error'",
"=>",
"false",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'ongr_translations.command.export'",
")",
"->",
"run",
"(",
"new",
"ArrayInput",
"(",
"[",
"]",
")",
",",
"new",
"NullOutput",
"(",
")",
")",
"!=",
"0",
")",
"{",
"$",
"output",
"[",
"'error'",
"]",
"=",
"true",
";",
"}",
"return",
"new",
"JsonResponse",
"(",
"$",
"output",
")",
";",
"}"
] |
Action for executing export command.
@return JsonResponse
|
[
"Action",
"for",
"executing",
"export",
"command",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Controller/ApiController.php#L73-L87
|
224,999
|
ongr-io/TranslationsBundle
|
Controller/ApiController.php
|
ApiController.historyAction
|
public function historyAction(Request $request, $id)
{
$document = $this->get('ongr_translations.translation_manager')->get($id);
if (empty($document)) {
return new JsonResponse(['error' => true, 'message' => 'translation not found']);
}
return new JsonResponse($this->get('ongr_translations.history_manager')->get($document));
}
|
php
|
public function historyAction(Request $request, $id)
{
$document = $this->get('ongr_translations.translation_manager')->get($id);
if (empty($document)) {
return new JsonResponse(['error' => true, 'message' => 'translation not found']);
}
return new JsonResponse($this->get('ongr_translations.history_manager')->get($document));
}
|
[
"public",
"function",
"historyAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"document",
"=",
"$",
"this",
"->",
"get",
"(",
"'ongr_translations.translation_manager'",
")",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"document",
")",
")",
"{",
"return",
"new",
"JsonResponse",
"(",
"[",
"'error'",
"=>",
"true",
",",
"'message'",
"=>",
"'translation not found'",
"]",
")",
";",
"}",
"return",
"new",
"JsonResponse",
"(",
"$",
"this",
"->",
"get",
"(",
"'ongr_translations.history_manager'",
")",
"->",
"get",
"(",
"$",
"document",
")",
")",
";",
"}"
] |
Action for executing history command.
@param Request $request Http request object.
@param string $id
@return JsonResponse
|
[
"Action",
"for",
"executing",
"history",
"command",
"."
] |
a441d7641144eddf3d75d930270d87428b791c0a
|
https://github.com/ongr-io/TranslationsBundle/blob/a441d7641144eddf3d75d930270d87428b791c0a/Controller/ApiController.php#L97-L106
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.