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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
230,300
|
deanblackborough/zf3-view-helpers
|
src/Bootstrap4Card.php
|
Bootstrap4Card.addCustomBodyClass
|
public function addCustomBodyClass(string $class, string $element, bool $first = false) : Bootstrap4Card
{
if (in_array($element, $this->body_elements) === true) {
$this->body_classes[$element][] = $class;
if ($first === true) {
$this->body_classes_first[$element][$class] = true;
}
}
return $this;
}
|
php
|
public function addCustomBodyClass(string $class, string $element, bool $first = false) : Bootstrap4Card
{
if (in_array($element, $this->body_elements) === true) {
$this->body_classes[$element][] = $class;
if ($first === true) {
$this->body_classes_first[$element][$class] = true;
}
}
return $this;
}
|
[
"public",
"function",
"addCustomBodyClass",
"(",
"string",
"$",
"class",
",",
"string",
"$",
"element",
",",
"bool",
"$",
"first",
"=",
"false",
")",
":",
"Bootstrap4Card",
"{",
"if",
"(",
"in_array",
"(",
"$",
"element",
",",
"$",
"this",
"->",
"body_elements",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"body_classes",
"[",
"$",
"element",
"]",
"[",
"]",
"=",
"$",
"class",
";",
"if",
"(",
"$",
"first",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"body_classes_first",
"[",
"$",
"element",
"]",
"[",
"$",
"class",
"]",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add a custom class to a card body element, if there are multiple body elements of
the same type the class will be added to all of them.
Silently errors, if the element is invalid the attribute is not assigned to the body classes array
@param string $class Class to assign to element
@param string $element Body element to attach the class to [title|subtitle|text|link]
@param boolean $first Only apply the class to the first body element of the given type rather than all elements
@return Bootstrap4Card
|
[
"Add",
"a",
"custom",
"class",
"to",
"a",
"card",
"body",
"element",
"if",
"there",
"are",
"multiple",
"body",
"elements",
"of",
"the",
"same",
"type",
"the",
"class",
"will",
"be",
"added",
"to",
"all",
"of",
"them",
"."
] |
db8bea4ca62709b2ac8c732aedbb2a5235223f23
|
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Card.php#L390-L401
|
230,301
|
deanblackborough/zf3-view-helpers
|
src/Bootstrap4Card.php
|
Bootstrap4Card.addCustomAttr
|
public function addCustomAttr(string $attr, string $element) : Bootstrap4Card
{
if (in_array($element, $this->elements) === true) {
$this->attr[$element][] = $attr;
}
return $this;
}
|
php
|
public function addCustomAttr(string $attr, string $element) : Bootstrap4Card
{
if (in_array($element, $this->elements) === true) {
$this->attr[$element][] = $attr;
}
return $this;
}
|
[
"public",
"function",
"addCustomAttr",
"(",
"string",
"$",
"attr",
",",
"string",
"$",
"element",
")",
":",
"Bootstrap4Card",
"{",
"if",
"(",
"in_array",
"(",
"$",
"element",
",",
"$",
"this",
"->",
"elements",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"attr",
"[",
"$",
"element",
"]",
"[",
"]",
"=",
"$",
"attr",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add a custom attribute to a card element
Silently errors, if the element is invalid the attribute is not assigned to the attributes array
@param string $attr Attribute to assign to element
@param string $element Element to attach the attribute to [card|body|header|footer]
@return Bootstrap4Card
|
[
"Add",
"a",
"custom",
"attribute",
"to",
"a",
"card",
"element"
] |
db8bea4ca62709b2ac8c732aedbb2a5235223f23
|
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Card.php#L413-L420
|
230,302
|
deanblackborough/zf3-view-helpers
|
src/Bootstrap4Card.php
|
Bootstrap4Card.addCustomBodyAttr
|
public function addCustomBodyAttr(string $attr, string $element, bool $first = false) : Bootstrap4Card
{
if (in_array($element, $this->body_elements) === true) {
$this->body_attr[$element][] = $attr;
if ($first === true) {
$this->body_attr_first[$element][$attr] = true;
}
}
return $this;
}
|
php
|
public function addCustomBodyAttr(string $attr, string $element, bool $first = false) : Bootstrap4Card
{
if (in_array($element, $this->body_elements) === true) {
$this->body_attr[$element][] = $attr;
if ($first === true) {
$this->body_attr_first[$element][$attr] = true;
}
}
return $this;
}
|
[
"public",
"function",
"addCustomBodyAttr",
"(",
"string",
"$",
"attr",
",",
"string",
"$",
"element",
",",
"bool",
"$",
"first",
"=",
"false",
")",
":",
"Bootstrap4Card",
"{",
"if",
"(",
"in_array",
"(",
"$",
"element",
",",
"$",
"this",
"->",
"body_elements",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"body_attr",
"[",
"$",
"element",
"]",
"[",
"]",
"=",
"$",
"attr",
";",
"if",
"(",
"$",
"first",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"body_attr_first",
"[",
"$",
"element",
"]",
"[",
"$",
"attr",
"]",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add a custom attribute to a card body element, if there are multiple body elements of
the same type the attribute will be added to all of them.
Silently errors, if the element is invalid the attribute is not assigned to the body attributes array
@param string $attr Attribute to assign to element
@param string $element Body element to attach the attribute to [title|subtitle|text|link]
@param boolean $first Only apply the attribute to the first body element of the given type rather than all elements
@return Bootstrap4Card
|
[
"Add",
"a",
"custom",
"attribute",
"to",
"a",
"card",
"body",
"element",
"if",
"there",
"are",
"multiple",
"body",
"elements",
"of",
"the",
"same",
"type",
"the",
"attribute",
"will",
"be",
"added",
"to",
"all",
"of",
"them",
"."
] |
db8bea4ca62709b2ac8c732aedbb2a5235223f23
|
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Card.php#L434-L445
|
230,303
|
deanblackborough/zf3-view-helpers
|
src/Bootstrap4Card.php
|
Bootstrap4Card.addTitleToBody
|
public function addTitleToBody(string $content, string $tag = 'h4') : Bootstrap4Card
{
$this->body_sections[] = [
'type' => 'title',
'tag' => $tag,
'content' => $content
];
return $this;
}
|
php
|
public function addTitleToBody(string $content, string $tag = 'h4') : Bootstrap4Card
{
$this->body_sections[] = [
'type' => 'title',
'tag' => $tag,
'content' => $content
];
return $this;
}
|
[
"public",
"function",
"addTitleToBody",
"(",
"string",
"$",
"content",
",",
"string",
"$",
"tag",
"=",
"'h4'",
")",
":",
"Bootstrap4Card",
"{",
"$",
"this",
"->",
"body_sections",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"'title'",
",",
"'tag'",
"=>",
"$",
"tag",
",",
"'content'",
"=>",
"$",
"content",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a title section to the body
@param string $content
@param string $tag title tag, defaults to h4
@return Bootstrap4Card
|
[
"Add",
"a",
"title",
"section",
"to",
"the",
"body"
] |
db8bea4ca62709b2ac8c732aedbb2a5235223f23
|
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Card.php#L487-L496
|
230,304
|
deanblackborough/zf3-view-helpers
|
src/Bootstrap4Card.php
|
Bootstrap4Card.addSubtitleToBody
|
public function addSubtitleToBody(string $content, string $tag = 'h6') : Bootstrap4Card
{
$this->body_sections[] = [
'type' => 'subtitle',
'tag' => $tag,
'content' => $content
];
return $this;
}
|
php
|
public function addSubtitleToBody(string $content, string $tag = 'h6') : Bootstrap4Card
{
$this->body_sections[] = [
'type' => 'subtitle',
'tag' => $tag,
'content' => $content
];
return $this;
}
|
[
"public",
"function",
"addSubtitleToBody",
"(",
"string",
"$",
"content",
",",
"string",
"$",
"tag",
"=",
"'h6'",
")",
":",
"Bootstrap4Card",
"{",
"$",
"this",
"->",
"body_sections",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"'subtitle'",
",",
"'tag'",
"=>",
"$",
"tag",
",",
"'content'",
"=>",
"$",
"content",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a subtitle section to the body
@param string $content
@param string $tag title tag, defaults to h6
@return Bootstrap4Card
|
[
"Add",
"a",
"subtitle",
"section",
"to",
"the",
"body"
] |
db8bea4ca62709b2ac8c732aedbb2a5235223f23
|
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Card.php#L506-L515
|
230,305
|
deanblackborough/zf3-view-helpers
|
src/Bootstrap4Card.php
|
Bootstrap4Card.addLinkToBody
|
public function addLinkToBody(string $content, string $uri) : Bootstrap4Card
{
$this->body_sections[] = [
'type' => 'link',
'uri' => $uri,
'content' => $content
];
return $this;
}
|
php
|
public function addLinkToBody(string $content, string $uri) : Bootstrap4Card
{
$this->body_sections[] = [
'type' => 'link',
'uri' => $uri,
'content' => $content
];
return $this;
}
|
[
"public",
"function",
"addLinkToBody",
"(",
"string",
"$",
"content",
",",
"string",
"$",
"uri",
")",
":",
"Bootstrap4Card",
"{",
"$",
"this",
"->",
"body_sections",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"'link'",
",",
"'uri'",
"=>",
"$",
"uri",
",",
"'content'",
"=>",
"$",
"content",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a link section to the body
@param string $content
@param string $uri URI
@return Bootstrap4Card
|
[
"Add",
"a",
"link",
"section",
"to",
"the",
"body"
] |
db8bea4ca62709b2ac8c732aedbb2a5235223f23
|
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Card.php#L525-L534
|
230,306
|
deanblackborough/zf3-view-helpers
|
src/Bootstrap4Card.php
|
Bootstrap4Card.assignBgStyle
|
protected function assignBgStyle(string $color)
{
if (in_array($color, $this->supported_bg_styles) === true) {
$this->classes['card'][] = 'bg-' . $color;
}
}
|
php
|
protected function assignBgStyle(string $color)
{
if (in_array($color, $this->supported_bg_styles) === true) {
$this->classes['card'][] = 'bg-' . $color;
}
}
|
[
"protected",
"function",
"assignBgStyle",
"(",
"string",
"$",
"color",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"color",
",",
"$",
"this",
"->",
"supported_bg_styles",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"classes",
"[",
"'card'",
"]",
"[",
"]",
"=",
"'bg-'",
".",
"$",
"color",
";",
"}",
"}"
] |
Validate and assign the background colour, overrides the method in Bootstrap4Helper
@param string $color
|
[
"Validate",
"and",
"assign",
"the",
"background",
"colour",
"overrides",
"the",
"method",
"in",
"Bootstrap4Helper"
] |
db8bea4ca62709b2ac8c732aedbb2a5235223f23
|
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Card.php#L570-L575
|
230,307
|
Webiny/Framework
|
src/Webiny/Component/Http/Response.php
|
Response.setStatusCode
|
public function setStatusCode($statusCode, $message = '')
{
if (empty($message)) {
if (!isset(self::$httpStatuses[$statusCode])) {
throw new ResponseException('Invalid status code provided: "' . $statusCode . '".');
} else {
$this->statusMessage = self::$httpStatuses[$statusCode];
}
} else {
$this->statusMessage = $message;
}
$this->statusCode = $statusCode;
return $this;
}
|
php
|
public function setStatusCode($statusCode, $message = '')
{
if (empty($message)) {
if (!isset(self::$httpStatuses[$statusCode])) {
throw new ResponseException('Invalid status code provided: "' . $statusCode . '".');
} else {
$this->statusMessage = self::$httpStatuses[$statusCode];
}
} else {
$this->statusMessage = $message;
}
$this->statusCode = $statusCode;
return $this;
}
|
[
"public",
"function",
"setStatusCode",
"(",
"$",
"statusCode",
",",
"$",
"message",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"message",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"httpStatuses",
"[",
"$",
"statusCode",
"]",
")",
")",
"{",
"throw",
"new",
"ResponseException",
"(",
"'Invalid status code provided: \"'",
".",
"$",
"statusCode",
".",
"'\".'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"statusMessage",
"=",
"self",
"::",
"$",
"httpStatuses",
"[",
"$",
"statusCode",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"statusMessage",
"=",
"$",
"message",
";",
"}",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"statusCode",
";",
"return",
"$",
"this",
";",
"}"
] |
Set HTTP response status code. The status code must be a valid HTTP status code, or an exception will be thrown.
@param int $statusCode Http status code.
@param string $message Http status message. If not set we will use the default message by RFC2616.
@return $this
@throws Response\ResponseException
|
[
"Set",
"HTTP",
"response",
"status",
"code",
".",
"The",
"status",
"code",
"must",
"be",
"a",
"valid",
"HTTP",
"status",
"code",
"or",
"an",
"exception",
"will",
"be",
"thrown",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Response.php#L214-L229
|
230,308
|
Webiny/Framework
|
src/Webiny/Component/Http/Response.php
|
Response.setContentType
|
public function setContentType($contentType)
{
$this->contentType = $contentType;
$this->setHeader('Content-Type', $contentType . '; charset=' . $this->getCharset());
return $this;
}
|
php
|
public function setContentType($contentType)
{
$this->contentType = $contentType;
$this->setHeader('Content-Type', $contentType . '; charset=' . $this->getCharset());
return $this;
}
|
[
"public",
"function",
"setContentType",
"(",
"$",
"contentType",
")",
"{",
"$",
"this",
"->",
"contentType",
"=",
"$",
"contentType",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"$",
"contentType",
".",
"'; charset='",
".",
"$",
"this",
"->",
"getCharset",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the Content-Type header value.
@param string $contentType
@return $this
|
[
"Sets",
"the",
"Content",
"-",
"Type",
"header",
"value",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Response.php#L248-L255
|
230,309
|
Webiny/Framework
|
src/Webiny/Component/Http/Response.php
|
Response.setCharset
|
public function setCharset($charset)
{
$this->charset = $charset;
$this->setContentType($this->getContentType()); // update charset which is set on content-type
return $this;
}
|
php
|
public function setCharset($charset)
{
$this->charset = $charset;
$this->setContentType($this->getContentType()); // update charset which is set on content-type
return $this;
}
|
[
"public",
"function",
"setCharset",
"(",
"$",
"charset",
")",
"{",
"$",
"this",
"->",
"charset",
"=",
"$",
"charset",
";",
"$",
"this",
"->",
"setContentType",
"(",
"$",
"this",
"->",
"getContentType",
"(",
")",
")",
";",
"// update charset which is set on content-type",
"return",
"$",
"this",
";",
"}"
] |
Set the response charset.
@param string $charset Charset name.
@return $this
|
[
"Set",
"the",
"response",
"charset",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Response.php#L274-L280
|
230,310
|
Webiny/Framework
|
src/Webiny/Component/Http/Response.php
|
Response.setAsNotModified
|
public function setAsNotModified()
{
$this->setStatusCode(304);
$this->setContent('');
// remove headers that MUST NOT be included with 304 Not Modified responses
$headersToRemove = [
'Allow',
'Content-Encoding',
'Content-Language',
'Content-Length',
'Content-MD5',
'Content-Type',
'Last-Modified'
];
foreach ($headersToRemove as $header) {
$this->headers->removeKey($header);
}
return $this;
}
|
php
|
public function setAsNotModified()
{
$this->setStatusCode(304);
$this->setContent('');
// remove headers that MUST NOT be included with 304 Not Modified responses
$headersToRemove = [
'Allow',
'Content-Encoding',
'Content-Language',
'Content-Length',
'Content-MD5',
'Content-Type',
'Last-Modified'
];
foreach ($headersToRemove as $header) {
$this->headers->removeKey($header);
}
return $this;
}
|
[
"public",
"function",
"setAsNotModified",
"(",
")",
"{",
"$",
"this",
"->",
"setStatusCode",
"(",
"304",
")",
";",
"$",
"this",
"->",
"setContent",
"(",
"''",
")",
";",
"// remove headers that MUST NOT be included with 304 Not Modified responses",
"$",
"headersToRemove",
"=",
"[",
"'Allow'",
",",
"'Content-Encoding'",
",",
"'Content-Language'",
",",
"'Content-Length'",
",",
"'Content-MD5'",
",",
"'Content-Type'",
",",
"'Last-Modified'",
"]",
";",
"foreach",
"(",
"$",
"headersToRemove",
"as",
"$",
"header",
")",
"{",
"$",
"this",
"->",
"headers",
"->",
"removeKey",
"(",
"$",
"header",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the response as not modified.
@return $this
|
[
"Sets",
"the",
"response",
"as",
"not",
"modified",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Response.php#L322-L342
|
230,311
|
Webiny/Framework
|
src/Webiny/Component/Http/Response.php
|
Response.sendHeaders
|
public function sendHeaders()
{
// first build headers -> only if they haven't already been sent
if (!headers_sent()) {
// status code header
header(self::PROTOCOL . ' ' . $this->getStatusCode() . ' ' . $this->statusMessage
);
// other headers
foreach ($this->headers as $k => $v) {
header($k . ': ' . $v);
}
// cache control headers
$cacheControlHeaders = $this->cacheControl->getCacheControl();
foreach ($cacheControlHeaders as $k => $v) {
header($k . ': ' . $v);
}
}
return $this;
}
|
php
|
public function sendHeaders()
{
// first build headers -> only if they haven't already been sent
if (!headers_sent()) {
// status code header
header(self::PROTOCOL . ' ' . $this->getStatusCode() . ' ' . $this->statusMessage
);
// other headers
foreach ($this->headers as $k => $v) {
header($k . ': ' . $v);
}
// cache control headers
$cacheControlHeaders = $this->cacheControl->getCacheControl();
foreach ($cacheControlHeaders as $k => $v) {
header($k . ': ' . $v);
}
}
return $this;
}
|
[
"public",
"function",
"sendHeaders",
"(",
")",
"{",
"// first build headers -> only if they haven't already been sent",
"if",
"(",
"!",
"headers_sent",
"(",
")",
")",
"{",
"// status code header",
"header",
"(",
"self",
"::",
"PROTOCOL",
".",
"' '",
".",
"$",
"this",
"->",
"getStatusCode",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"statusMessage",
")",
";",
"// other headers",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"header",
"(",
"$",
"k",
".",
"': '",
".",
"$",
"v",
")",
";",
"}",
"// cache control headers",
"$",
"cacheControlHeaders",
"=",
"$",
"this",
"->",
"cacheControl",
"->",
"getCacheControl",
"(",
")",
";",
"foreach",
"(",
"$",
"cacheControlHeaders",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"header",
"(",
"$",
"k",
".",
"': '",
".",
"$",
"v",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Send the currently defined headers.
This also sends the cache control headers.
@return $this
|
[
"Send",
"the",
"currently",
"defined",
"headers",
".",
"This",
"also",
"sends",
"the",
"cache",
"control",
"headers",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Response.php#L360-L381
|
230,312
|
letyii/yii2-rbac-cached
|
RbacCached.php
|
RbacCached.setCache
|
protected function setCache($key, $value) {
$this->cachedData = $this->resolveCacheComponent()->get($this->cacheKeyName);
if (empty($this->cachedData))
$this->cachedData = [];
$this->cachedData[$key] = $value;
return $this->resolveCacheComponent()->set($this->cacheKeyName, $this->cachedData, $this->cacheDuration);
}
|
php
|
protected function setCache($key, $value) {
$this->cachedData = $this->resolveCacheComponent()->get($this->cacheKeyName);
if (empty($this->cachedData))
$this->cachedData = [];
$this->cachedData[$key] = $value;
return $this->resolveCacheComponent()->set($this->cacheKeyName, $this->cachedData, $this->cacheDuration);
}
|
[
"protected",
"function",
"setCache",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"cachedData",
"=",
"$",
"this",
"->",
"resolveCacheComponent",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"cacheKeyName",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"cachedData",
")",
")",
"$",
"this",
"->",
"cachedData",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"cachedData",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
"->",
"resolveCacheComponent",
"(",
")",
"->",
"set",
"(",
"$",
"this",
"->",
"cacheKeyName",
",",
"$",
"this",
"->",
"cachedData",
",",
"$",
"this",
"->",
"cacheDuration",
")",
";",
"}"
] |
Set a value in cache
@param $key
@param $value
@return mixed
|
[
"Set",
"a",
"value",
"in",
"cache"
] |
0e9ace4c6464a8a352e4af3cba0cf3333eaf06c3
|
https://github.com/letyii/yii2-rbac-cached/blob/0e9ace4c6464a8a352e4af3cba0cf3333eaf06c3/RbacCached.php#L106-L112
|
230,313
|
Webiny/Framework
|
src/Webiny/Component/Amazon/S3.php
|
S3.putObject
|
public function putObject($bucket, $key, $content, array $params = [])
{
return $this->instance->putObject($bucket, $key, $content, $params);
}
|
php
|
public function putObject($bucket, $key, $content, array $params = [])
{
return $this->instance->putObject($bucket, $key, $content, $params);
}
|
[
"public",
"function",
"putObject",
"(",
"$",
"bucket",
",",
"$",
"key",
",",
"$",
"content",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"instance",
"->",
"putObject",
"(",
"$",
"bucket",
",",
"$",
"key",
",",
"$",
"content",
",",
"$",
"params",
")",
";",
"}"
] |
Adds an object to a bucket.
@param string $bucket
@param string $key
@param string $content
@param array $params
@return mixed
|
[
"Adds",
"an",
"object",
"to",
"a",
"bucket",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Amazon/S3.php#L255-L258
|
230,314
|
Webiny/Framework
|
src/Webiny/Component/Cache/Storage/Redis.php
|
Redis.getInstance
|
public static function getInstance($host = 'localhost', $port = 6379)
{
return \Webiny\Component\Cache\Bridge\Redis::getInstance($host, $port);
}
|
php
|
public static function getInstance($host = 'localhost', $port = 6379)
{
return \Webiny\Component\Cache\Bridge\Redis::getInstance($host, $port);
}
|
[
"public",
"static",
"function",
"getInstance",
"(",
"$",
"host",
"=",
"'localhost'",
",",
"$",
"port",
"=",
"6379",
")",
"{",
"return",
"\\",
"Webiny",
"\\",
"Component",
"\\",
"Cache",
"\\",
"Bridge",
"\\",
"Redis",
"::",
"getInstance",
"(",
"$",
"host",
",",
"$",
"port",
")",
";",
"}"
] |
Get an instance of Redis cache storage.
@param string $host Host on which Redis server is running.
@param int $port Port on which Redis server is running.
@return CacheStorageInterface
|
[
"Get",
"an",
"instance",
"of",
"Redis",
"cache",
"storage",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Cache/Storage/Redis.php#L28-L31
|
230,315
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.getItems
|
public function getItems($batch = false) {
$entities = new ElggBatch($this->getter, $this->getOptions());
if ($batch) {
return $entities;
}
$items = [];
foreach ($entities as $entity) {
$items[] = $entity;
}
return $items;
}
|
php
|
public function getItems($batch = false) {
$entities = new ElggBatch($this->getter, $this->getOptions());
if ($batch) {
return $entities;
}
$items = [];
foreach ($entities as $entity) {
$items[] = $entity;
}
return $items;
}
|
[
"public",
"function",
"getItems",
"(",
"$",
"batch",
"=",
"false",
")",
"{",
"$",
"entities",
"=",
"new",
"ElggBatch",
"(",
"$",
"this",
"->",
"getter",
",",
"$",
"this",
"->",
"getOptions",
"(",
")",
")",
";",
"if",
"(",
"$",
"batch",
")",
"{",
"return",
"$",
"entities",
";",
"}",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"entity",
")",
"{",
"$",
"items",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"return",
"$",
"items",
";",
"}"
] |
Returns items of the list as an array or batch
@param bool $batch Return ElggBatch
@return mixed
|
[
"Returns",
"items",
"of",
"the",
"list",
"as",
"an",
"array",
"or",
"batch"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L131-L141
|
230,316
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.getGUIDs
|
public function getGUIDs() {
$options = $this->getOptions();
$options['callback'] = false;
$rows = new ElggBatch($this->getter, $options);
$guids = [];
foreach ($rows as $row) {
$guids[] = $row->guid;
}
return $guids;
}
|
php
|
public function getGUIDs() {
$options = $this->getOptions();
$options['callback'] = false;
$rows = new ElggBatch($this->getter, $options);
$guids = [];
foreach ($rows as $row) {
$guids[] = $row->guid;
}
return $guids;
}
|
[
"public",
"function",
"getGUIDs",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"options",
"[",
"'callback'",
"]",
"=",
"false",
";",
"$",
"rows",
"=",
"new",
"ElggBatch",
"(",
"$",
"this",
"->",
"getter",
",",
"$",
"options",
")",
";",
"$",
"guids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"guids",
"[",
"]",
"=",
"$",
"row",
"->",
"guid",
";",
"}",
"return",
"$",
"guids",
";",
"}"
] |
Returns an array of GUIDs of items in the batch
@return int[]
|
[
"Returns",
"an",
"array",
"of",
"GUIDs",
"of",
"items",
"in",
"the",
"batch"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L147-L158
|
230,317
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.toObject
|
public function toObject() {
$options = $this->getOptions();
$result = (object) [
'type' => 'list',
'count' => $this->getCount(),
'limit' => elgg_extract('limit', $options, elgg_get_config('default_limit')),
'offset' => elgg_extract('offset', $options, 0),
'sorts' => $this->sorts,
'filters' => array_map(function($e) {
return [
'filter' => $e['filter'],
'target' => $e['target'] ? $e['target']->guid : 0,
];
}, $this->fiilters),
'items' => [],
];
$entities = new ElggBatch($this->getter, $options);
foreach ($entities as $entity) {
if (is_object($entity) && is_callable([$entity, 'toObject'])) {
$result->items[] = $entity->toObject();
} else {
$result->items[] = $entity;
}
}
return $result;
}
|
php
|
public function toObject() {
$options = $this->getOptions();
$result = (object) [
'type' => 'list',
'count' => $this->getCount(),
'limit' => elgg_extract('limit', $options, elgg_get_config('default_limit')),
'offset' => elgg_extract('offset', $options, 0),
'sorts' => $this->sorts,
'filters' => array_map(function($e) {
return [
'filter' => $e['filter'],
'target' => $e['target'] ? $e['target']->guid : 0,
];
}, $this->fiilters),
'items' => [],
];
$entities = new ElggBatch($this->getter, $options);
foreach ($entities as $entity) {
if (is_object($entity) && is_callable([$entity, 'toObject'])) {
$result->items[] = $entity->toObject();
} else {
$result->items[] = $entity;
}
}
return $result;
}
|
[
"public",
"function",
"toObject",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"result",
"=",
"(",
"object",
")",
"[",
"'type'",
"=>",
"'list'",
",",
"'count'",
"=>",
"$",
"this",
"->",
"getCount",
"(",
")",
",",
"'limit'",
"=>",
"elgg_extract",
"(",
"'limit'",
",",
"$",
"options",
",",
"elgg_get_config",
"(",
"'default_limit'",
")",
")",
",",
"'offset'",
"=>",
"elgg_extract",
"(",
"'offset'",
",",
"$",
"options",
",",
"0",
")",
",",
"'sorts'",
"=>",
"$",
"this",
"->",
"sorts",
",",
"'filters'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"e",
")",
"{",
"return",
"[",
"'filter'",
"=>",
"$",
"e",
"[",
"'filter'",
"]",
",",
"'target'",
"=>",
"$",
"e",
"[",
"'target'",
"]",
"?",
"$",
"e",
"[",
"'target'",
"]",
"->",
"guid",
":",
"0",
",",
"]",
";",
"}",
",",
"$",
"this",
"->",
"fiilters",
")",
",",
"'items'",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"entities",
"=",
"new",
"ElggBatch",
"(",
"$",
"this",
"->",
"getter",
",",
"$",
"options",
")",
";",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"entity",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"entity",
")",
"&&",
"is_callable",
"(",
"[",
"$",
"entity",
",",
"'toObject'",
"]",
")",
")",
"{",
"$",
"result",
"->",
"items",
"[",
"]",
"=",
"$",
"entity",
"->",
"toObject",
"(",
")",
";",
"}",
"else",
"{",
"$",
"result",
"->",
"items",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Exports a list into a serializable object
@return stdClass
|
[
"Exports",
"a",
"list",
"into",
"a",
"serializable",
"object"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L164-L192
|
230,318
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.addSort
|
public function addSort($field = 'time_created', $direction = 'DESC', $priority = 500) {
if (!$field || !$direction) {
return $this;
}
while (isset($this->sorts[$priority])) {
$priority++;
}
$field = sanitize_string($field);
$direction = strtoupper(sanitize_string($direction));
if (!in_array($direction, array('ASC', 'DESC'))) {
$direction = self::DEFAULT_SORT_DIRECTION;
}
$this->removeSort($field);
$this->sorts[$priority] = [
'field' => $field,
'direction' => $direction,
];
ksort($this->sorts);
return $this;
}
|
php
|
public function addSort($field = 'time_created', $direction = 'DESC', $priority = 500) {
if (!$field || !$direction) {
return $this;
}
while (isset($this->sorts[$priority])) {
$priority++;
}
$field = sanitize_string($field);
$direction = strtoupper(sanitize_string($direction));
if (!in_array($direction, array('ASC', 'DESC'))) {
$direction = self::DEFAULT_SORT_DIRECTION;
}
$this->removeSort($field);
$this->sorts[$priority] = [
'field' => $field,
'direction' => $direction,
];
ksort($this->sorts);
return $this;
}
|
[
"public",
"function",
"addSort",
"(",
"$",
"field",
"=",
"'time_created'",
",",
"$",
"direction",
"=",
"'DESC'",
",",
"$",
"priority",
"=",
"500",
")",
"{",
"if",
"(",
"!",
"$",
"field",
"||",
"!",
"$",
"direction",
")",
"{",
"return",
"$",
"this",
";",
"}",
"while",
"(",
"isset",
"(",
"$",
"this",
"->",
"sorts",
"[",
"$",
"priority",
"]",
")",
")",
"{",
"$",
"priority",
"++",
";",
"}",
"$",
"field",
"=",
"sanitize_string",
"(",
"$",
"field",
")",
";",
"$",
"direction",
"=",
"strtoupper",
"(",
"sanitize_string",
"(",
"$",
"direction",
")",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"direction",
",",
"array",
"(",
"'ASC'",
",",
"'DESC'",
")",
")",
")",
"{",
"$",
"direction",
"=",
"self",
"::",
"DEFAULT_SORT_DIRECTION",
";",
"}",
"$",
"this",
"->",
"removeSort",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"sorts",
"[",
"$",
"priority",
"]",
"=",
"[",
"'field'",
"=>",
"$",
"field",
",",
"'direction'",
"=>",
"$",
"direction",
",",
"]",
";",
"ksort",
"(",
"$",
"this",
"->",
"sorts",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set sort field and direction
@param string $field Field name
@param string $direction Sort direction
@param int $priority Priority
@return self
|
[
"Set",
"sort",
"field",
"and",
"direction"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L202-L229
|
230,319
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.removeSort
|
public function removeSort($field) {
foreach ($this->sorts as $key => $value) {
if ($value['field'] == $field) {
unset($this->sorts[$key]);
}
}
return $this;
}
|
php
|
public function removeSort($field) {
foreach ($this->sorts as $key => $value) {
if ($value['field'] == $field) {
unset($this->sorts[$key]);
}
}
return $this;
}
|
[
"public",
"function",
"removeSort",
"(",
"$",
"field",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sorts",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"[",
"'field'",
"]",
"==",
"$",
"field",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"sorts",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Remove sort field
@param string $field Field name
@return self
|
[
"Remove",
"sort",
"field"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L237-L245
|
230,320
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.getSortOptions
|
public function getSortOptions(array $params = []) {
$options = $this->getOptions();
$plugin = elgg_get_plugin_from_id('hypeLists');
$settings = $plugin->getAllSettings();
foreach ($settings as $k => $val) {
if (!$val) {
continue;
}
list(, $entity_type, $field, $direction) = explode('::', $k);
if ($entity_type != $this->getEntityType()) {
continue;
}
if ($field && in_array(strtolower($direction), array('asc', 'desc'))) {
$sort_options[] = "$field::$direction";
}
}
$params['list'] = $this;
$sort_options = elgg_trigger_plugin_hook('sort_fields', $this->getEntityType(), $params, $sort_options);
$subtypes = elgg_extract('subtype', $options);
if (!$subtypes) {
$subtypes = elgg_extract('subtypes', $options);
}
if (!empty($subtypes)) {
$subtypes = (array) $subtypes;
$subtype = array_shift($subtypes);
$sort_options = elgg_trigger_plugin_hook('sort_fields', "object:$subtype", $params, $sort_options);
}
return $sort_options;
}
|
php
|
public function getSortOptions(array $params = []) {
$options = $this->getOptions();
$plugin = elgg_get_plugin_from_id('hypeLists');
$settings = $plugin->getAllSettings();
foreach ($settings as $k => $val) {
if (!$val) {
continue;
}
list(, $entity_type, $field, $direction) = explode('::', $k);
if ($entity_type != $this->getEntityType()) {
continue;
}
if ($field && in_array(strtolower($direction), array('asc', 'desc'))) {
$sort_options[] = "$field::$direction";
}
}
$params['list'] = $this;
$sort_options = elgg_trigger_plugin_hook('sort_fields', $this->getEntityType(), $params, $sort_options);
$subtypes = elgg_extract('subtype', $options);
if (!$subtypes) {
$subtypes = elgg_extract('subtypes', $options);
}
if (!empty($subtypes)) {
$subtypes = (array) $subtypes;
$subtype = array_shift($subtypes);
$sort_options = elgg_trigger_plugin_hook('sort_fields', "object:$subtype", $params, $sort_options);
}
return $sort_options;
}
|
[
"public",
"function",
"getSortOptions",
"(",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"plugin",
"=",
"elgg_get_plugin_from_id",
"(",
"'hypeLists'",
")",
";",
"$",
"settings",
"=",
"$",
"plugin",
"->",
"getAllSettings",
"(",
")",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"k",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"$",
"val",
")",
"{",
"continue",
";",
"}",
"list",
"(",
",",
"$",
"entity_type",
",",
"$",
"field",
",",
"$",
"direction",
")",
"=",
"explode",
"(",
"'::'",
",",
"$",
"k",
")",
";",
"if",
"(",
"$",
"entity_type",
"!=",
"$",
"this",
"->",
"getEntityType",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"field",
"&&",
"in_array",
"(",
"strtolower",
"(",
"$",
"direction",
")",
",",
"array",
"(",
"'asc'",
",",
"'desc'",
")",
")",
")",
"{",
"$",
"sort_options",
"[",
"]",
"=",
"\"$field::$direction\"",
";",
"}",
"}",
"$",
"params",
"[",
"'list'",
"]",
"=",
"$",
"this",
";",
"$",
"sort_options",
"=",
"elgg_trigger_plugin_hook",
"(",
"'sort_fields'",
",",
"$",
"this",
"->",
"getEntityType",
"(",
")",
",",
"$",
"params",
",",
"$",
"sort_options",
")",
";",
"$",
"subtypes",
"=",
"elgg_extract",
"(",
"'subtype'",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"$",
"subtypes",
")",
"{",
"$",
"subtypes",
"=",
"elgg_extract",
"(",
"'subtypes'",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"subtypes",
")",
")",
"{",
"$",
"subtypes",
"=",
"(",
"array",
")",
"$",
"subtypes",
";",
"$",
"subtype",
"=",
"array_shift",
"(",
"$",
"subtypes",
")",
";",
"$",
"sort_options",
"=",
"elgg_trigger_plugin_hook",
"(",
"'sort_fields'",
",",
"\"object:$subtype\"",
",",
"$",
"params",
",",
"$",
"sort_options",
")",
";",
"}",
"return",
"$",
"sort_options",
";",
"}"
] |
Returns a list of sort options
@return array $params Params to pass to the hook
@return array
|
[
"Returns",
"a",
"list",
"of",
"sort",
"options"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L253-L288
|
230,321
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.getSubtypeOptions
|
public function getSubtypeOptions() {
$types = get_registered_entity_types();
$types = elgg_trigger_plugin_hook('search_types', 'get_queries', [], $types);
return elgg_extract($this->getEntityType(), $types);
}
|
php
|
public function getSubtypeOptions() {
$types = get_registered_entity_types();
$types = elgg_trigger_plugin_hook('search_types', 'get_queries', [], $types);
return elgg_extract($this->getEntityType(), $types);
}
|
[
"public",
"function",
"getSubtypeOptions",
"(",
")",
"{",
"$",
"types",
"=",
"get_registered_entity_types",
"(",
")",
";",
"$",
"types",
"=",
"elgg_trigger_plugin_hook",
"(",
"'search_types'",
",",
"'get_queries'",
",",
"[",
"]",
",",
"$",
"types",
")",
";",
"return",
"elgg_extract",
"(",
"$",
"this",
"->",
"getEntityType",
"(",
")",
",",
"$",
"types",
")",
";",
"}"
] |
Returns a list of subtype options
@return array
|
[
"Returns",
"a",
"list",
"of",
"subtype",
"options"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L302-L307
|
230,322
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.setQuery
|
public function setQuery($search_query = '', array $search_options = []) {
$this->search_query = sanitize_string(stripslashes($search_query));
$this->search_options = $search_options;
return $this;
}
|
php
|
public function setQuery($search_query = '', array $search_options = []) {
$this->search_query = sanitize_string(stripslashes($search_query));
$this->search_options = $search_options;
return $this;
}
|
[
"public",
"function",
"setQuery",
"(",
"$",
"search_query",
"=",
"''",
",",
"array",
"$",
"search_options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"search_query",
"=",
"sanitize_string",
"(",
"stripslashes",
"(",
"$",
"search_query",
")",
")",
";",
"$",
"this",
"->",
"search_options",
"=",
"$",
"search_options",
";",
"return",
"$",
"this",
";",
"}"
] |
Set a search query
@param string $search_query Search query
@param array $search_options Search options
- 'fields' - optional array of attribute and metadata names to search in
- 'advanced' - extend search to tags/profile fields
@return self
|
[
"Set",
"a",
"search",
"query"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L318-L322
|
230,323
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.addFilter
|
public function addFilter($filter, ElggEntity $target = null, $priority = 500) {
if (!$filter) {
return $this;
}
while (isset($this->filters[$priority])) {
$priority++;
}
$this->removeFilter($filter);
if (!isset($target)) {
$target = elgg_get_logged_in_user_entity();
}
$this->filters[$priority] = [
'filter' => $filter,
'target' => $target,
];
ksort($this->filters);
return $this;
}
|
php
|
public function addFilter($filter, ElggEntity $target = null, $priority = 500) {
if (!$filter) {
return $this;
}
while (isset($this->filters[$priority])) {
$priority++;
}
$this->removeFilter($filter);
if (!isset($target)) {
$target = elgg_get_logged_in_user_entity();
}
$this->filters[$priority] = [
'filter' => $filter,
'target' => $target,
];
ksort($this->filters);
return $this;
}
|
[
"public",
"function",
"addFilter",
"(",
"$",
"filter",
",",
"ElggEntity",
"$",
"target",
"=",
"null",
",",
"$",
"priority",
"=",
"500",
")",
"{",
"if",
"(",
"!",
"$",
"filter",
")",
"{",
"return",
"$",
"this",
";",
"}",
"while",
"(",
"isset",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"priority",
"]",
")",
")",
"{",
"$",
"priority",
"++",
";",
"}",
"$",
"this",
"->",
"removeFilter",
"(",
"$",
"filter",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"target",
")",
")",
"{",
"$",
"target",
"=",
"elgg_get_logged_in_user_entity",
"(",
")",
";",
"}",
"$",
"this",
"->",
"filters",
"[",
"$",
"priority",
"]",
"=",
"[",
"'filter'",
"=>",
"$",
"filter",
",",
"'target'",
"=>",
"$",
"target",
",",
"]",
";",
"ksort",
"(",
"$",
"this",
"->",
"filters",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add relationship filter
@param string $filter Filter name
@param ElggEntity $target Target entity
@param int $priority Priority
@return self
|
[
"Add",
"relationship",
"filter"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L342-L365
|
230,324
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.getFieldSearchWhereClause
|
public static function getFieldSearchWhereClause($table, $fields, $params, $use_fulltext = TRUE) {
if (is_callable('search_get_where_sql')) {
return search_get_where_sql($table, $fields, $params, $use_fulltext);
}
$query = $params['query'];
// add the table prefix to the fields
foreach ($fields as $i => $field) {
if ($table) {
$fields[$i] = "$table.$field";
}
}
$where = '';
$search_info = elgg_get_config('search_info');
// if query is shorter than the min for fts words
// it's likely a single acronym or similar
// switch to literal mode
if (elgg_strlen($query) < $search_info['min_chars']) {
$likes = array();
$query = sanitise_string($query);
foreach ($fields as $field) {
$likes[] = "$field LIKE '%$query%'";
}
$likes_str = implode(' OR ', $likes);
$where = "($likes_str)";
} else {
// if we're not using full text, rewrite the query for bool mode.
// exploiting a feature(ish) of bool mode where +-word is the same as -word
if (!$use_fulltext) {
$query = '+' . str_replace(' ', ' +', $query);
}
// if using advanced, boolean operators, or paired "s, switch into boolean mode
$booleans_used = preg_match("/([\-\+~])([\w]+)/i", $query);
$advanced_search = (isset($params['advanced_search']) && $params['advanced_search']);
$quotes_used = (elgg_substr_count($query, '"') >= 2);
$options = '';
if (!$use_fulltext || $booleans_used || $advanced_search || $quotes_used) {
$options = 'IN BOOLEAN MODE';
}
$query = sanitise_string($query);
$fields_str = implode(',', $fields);
$where = "(MATCH ($fields_str) AGAINST ('$query' $options))";
}
return $where;
}
|
php
|
public static function getFieldSearchWhereClause($table, $fields, $params, $use_fulltext = TRUE) {
if (is_callable('search_get_where_sql')) {
return search_get_where_sql($table, $fields, $params, $use_fulltext);
}
$query = $params['query'];
// add the table prefix to the fields
foreach ($fields as $i => $field) {
if ($table) {
$fields[$i] = "$table.$field";
}
}
$where = '';
$search_info = elgg_get_config('search_info');
// if query is shorter than the min for fts words
// it's likely a single acronym or similar
// switch to literal mode
if (elgg_strlen($query) < $search_info['min_chars']) {
$likes = array();
$query = sanitise_string($query);
foreach ($fields as $field) {
$likes[] = "$field LIKE '%$query%'";
}
$likes_str = implode(' OR ', $likes);
$where = "($likes_str)";
} else {
// if we're not using full text, rewrite the query for bool mode.
// exploiting a feature(ish) of bool mode where +-word is the same as -word
if (!$use_fulltext) {
$query = '+' . str_replace(' ', ' +', $query);
}
// if using advanced, boolean operators, or paired "s, switch into boolean mode
$booleans_used = preg_match("/([\-\+~])([\w]+)/i", $query);
$advanced_search = (isset($params['advanced_search']) && $params['advanced_search']);
$quotes_used = (elgg_substr_count($query, '"') >= 2);
$options = '';
if (!$use_fulltext || $booleans_used || $advanced_search || $quotes_used) {
$options = 'IN BOOLEAN MODE';
}
$query = sanitise_string($query);
$fields_str = implode(',', $fields);
$where = "(MATCH ($fields_str) AGAINST ('$query' $options))";
}
return $where;
}
|
[
"public",
"static",
"function",
"getFieldSearchWhereClause",
"(",
"$",
"table",
",",
"$",
"fields",
",",
"$",
"params",
",",
"$",
"use_fulltext",
"=",
"TRUE",
")",
"{",
"if",
"(",
"is_callable",
"(",
"'search_get_where_sql'",
")",
")",
"{",
"return",
"search_get_where_sql",
"(",
"$",
"table",
",",
"$",
"fields",
",",
"$",
"params",
",",
"$",
"use_fulltext",
")",
";",
"}",
"$",
"query",
"=",
"$",
"params",
"[",
"'query'",
"]",
";",
"// add the table prefix to the fields",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"i",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"table",
")",
"{",
"$",
"fields",
"[",
"$",
"i",
"]",
"=",
"\"$table.$field\"",
";",
"}",
"}",
"$",
"where",
"=",
"''",
";",
"$",
"search_info",
"=",
"elgg_get_config",
"(",
"'search_info'",
")",
";",
"// if query is shorter than the min for fts words",
"// it's likely a single acronym or similar",
"// switch to literal mode",
"if",
"(",
"elgg_strlen",
"(",
"$",
"query",
")",
"<",
"$",
"search_info",
"[",
"'min_chars'",
"]",
")",
"{",
"$",
"likes",
"=",
"array",
"(",
")",
";",
"$",
"query",
"=",
"sanitise_string",
"(",
"$",
"query",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"likes",
"[",
"]",
"=",
"\"$field LIKE '%$query%'\"",
";",
"}",
"$",
"likes_str",
"=",
"implode",
"(",
"' OR '",
",",
"$",
"likes",
")",
";",
"$",
"where",
"=",
"\"($likes_str)\"",
";",
"}",
"else",
"{",
"// if we're not using full text, rewrite the query for bool mode.",
"// exploiting a feature(ish) of bool mode where +-word is the same as -word",
"if",
"(",
"!",
"$",
"use_fulltext",
")",
"{",
"$",
"query",
"=",
"'+'",
".",
"str_replace",
"(",
"' '",
",",
"' +'",
",",
"$",
"query",
")",
";",
"}",
"// if using advanced, boolean operators, or paired \"s, switch into boolean mode",
"$",
"booleans_used",
"=",
"preg_match",
"(",
"\"/([\\-\\+~])([\\w]+)/i\"",
",",
"$",
"query",
")",
";",
"$",
"advanced_search",
"=",
"(",
"isset",
"(",
"$",
"params",
"[",
"'advanced_search'",
"]",
")",
"&&",
"$",
"params",
"[",
"'advanced_search'",
"]",
")",
";",
"$",
"quotes_used",
"=",
"(",
"elgg_substr_count",
"(",
"$",
"query",
",",
"'\"'",
")",
">=",
"2",
")",
";",
"$",
"options",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"use_fulltext",
"||",
"$",
"booleans_used",
"||",
"$",
"advanced_search",
"||",
"$",
"quotes_used",
")",
"{",
"$",
"options",
"=",
"'IN BOOLEAN MODE'",
";",
"}",
"$",
"query",
"=",
"sanitise_string",
"(",
"$",
"query",
")",
";",
"$",
"fields_str",
"=",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
";",
"$",
"where",
"=",
"\"(MATCH ($fields_str) AGAINST ('$query' $options))\"",
";",
"}",
"return",
"$",
"where",
";",
"}"
] |
Returns a where clause for a search query.
@see search_get_where_sql
@param str $table Prefix for table to search on
@param array $fields Fields to match against
@param array $params Original search params
@param bool $use_fulltext Use fulltext search
@return str
|
[
"Returns",
"a",
"where",
"clause",
"for",
"a",
"search",
"query",
"."
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L394-L447
|
230,325
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.getBaseURL
|
public function getBaseURL() {
$options = $this->getOptions();
$base_url = elgg_extract('base_url', $options);
$offset_key = elgg_extract('offset_key', $options, 'offset');
if (!$base_url) {
$base_url = current_page_url();
}
$base_url = elgg_http_remove_url_query_element($base_url, 'query');
$base_url = elgg_http_remove_url_query_element($base_url, 'sort');
$base_url = elgg_http_remove_url_query_element($base_url, 'limit');
$base_url = elgg_http_remove_url_query_element($base_url, $offset_key);
return $base_url;
}
|
php
|
public function getBaseURL() {
$options = $this->getOptions();
$base_url = elgg_extract('base_url', $options);
$offset_key = elgg_extract('offset_key', $options, 'offset');
if (!$base_url) {
$base_url = current_page_url();
}
$base_url = elgg_http_remove_url_query_element($base_url, 'query');
$base_url = elgg_http_remove_url_query_element($base_url, 'sort');
$base_url = elgg_http_remove_url_query_element($base_url, 'limit');
$base_url = elgg_http_remove_url_query_element($base_url, $offset_key);
return $base_url;
}
|
[
"public",
"function",
"getBaseURL",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"base_url",
"=",
"elgg_extract",
"(",
"'base_url'",
",",
"$",
"options",
")",
";",
"$",
"offset_key",
"=",
"elgg_extract",
"(",
"'offset_key'",
",",
"$",
"options",
",",
"'offset'",
")",
";",
"if",
"(",
"!",
"$",
"base_url",
")",
"{",
"$",
"base_url",
"=",
"current_page_url",
"(",
")",
";",
"}",
"$",
"base_url",
"=",
"elgg_http_remove_url_query_element",
"(",
"$",
"base_url",
",",
"'query'",
")",
";",
"$",
"base_url",
"=",
"elgg_http_remove_url_query_element",
"(",
"$",
"base_url",
",",
"'sort'",
")",
";",
"$",
"base_url",
"=",
"elgg_http_remove_url_query_element",
"(",
"$",
"base_url",
",",
"'limit'",
")",
";",
"$",
"base_url",
"=",
"elgg_http_remove_url_query_element",
"(",
"$",
"base_url",
",",
"$",
"offset_key",
")",
";",
"return",
"$",
"base_url",
";",
"}"
] |
Returns base URL of the list
@return string
|
[
"Returns",
"base",
"URL",
"of",
"the",
"list"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L453-L468
|
230,326
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.getId
|
public function getId() {
$options = $this->getOptions();
$id = elgg_extract('list_id', $options);
if (!$id) {
$id = md5($this->getBaseURL());
}
return $id;
}
|
php
|
public function getId() {
$options = $this->getOptions();
$id = elgg_extract('list_id', $options);
if (!$id) {
$id = md5($this->getBaseURL());
}
return $id;
}
|
[
"public",
"function",
"getId",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"id",
"=",
"elgg_extract",
"(",
"'list_id'",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"$",
"id",
"=",
"md5",
"(",
"$",
"this",
"->",
"getBaseURL",
"(",
")",
")",
";",
"}",
"return",
"$",
"id",
";",
"}"
] |
Returns list id
@return string
|
[
"Returns",
"list",
"id"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L474-L481
|
230,327
|
hypeJunction/hypeLists
|
classes/hypeJunction/Lists/EntityList.php
|
EntityList.render
|
public function render() {
$type = $this->getEntityType();
$options = $this->getOptions();
$options['base_url'] = $this->getBaseURL();
$options['list_id'] = $this->getId();
$list = elgg_list_entities($options, $this->getter);
$list = elgg_format_element('div', [
'class' => 'elgg-sortable-list-view',
], $list);
if (empty($this->search_query) && empty($this->filters) && !preg_match_all("/<ul.*>.*<\/ul>/s", $list)) {
// List is empty
return $list;
}
$sort_options = (array) elgg_extract('sort_options', $options, $this->getSortOptions());
$filter_options = (array) elgg_extract('filter_options', $options, $this->getFilterOptions());
$subtype_options = (array) elgg_extract('subtype_options', $options, $this->getSubtypeOptions());
$show_subtype = elgg_extract('show_subtype', $options, false) && !empty($subtype_options);
$show_sort = elgg_extract('show_sort', $options, false) && !empty($sort_options);
$show_search = elgg_extract('show_search', $options, false);
if (isset($options['show_rel'])) {
// BC
$show_filter = $options['show_rel'] && !empty($filter_options);
} else {
$show_filter = elgg_extract('show_filter', $options, false) && !empty($filter_options);
}
$form = '';
if ($show_sort || $show_search || $show_filter || $show_subtype) {
$form_vars = [
'entity_type' => $this->getEntityType(),
'show_sort' => $show_sort,
'show_search' => $show_search,
'show_filter' => $show_filter,
'show_subtype' => $show_subtype,
'filter' => array_map(function($e) {
return $e['filter'];
}, $this->filters),
'query' => $this->search_query,
'sort' => array_map(function($e) {
return strtolower("{$e['field']}::{$e['direction']}");
}, $this->sorts),
'sort_options' => $sort_options,
'filter_options' => $filter_options,
'subtype_options' => $subtype_options,
'expand_form' => elgg_extract('expand_form', $options),
];
$form = elgg_view_form('lists/sort', array(
'action' => $this->getBaseURL(),
'method' => 'GET',
'disable_security' => true,
'class' => 'elgg-form-sortable-list',
), $form_vars);
}
echo elgg_format_element('div', [
'id' => "$type-sort-{$this->getId()}",
'class' => "elgg-sortable-list $type-sort-list",
], $form . $list);
}
|
php
|
public function render() {
$type = $this->getEntityType();
$options = $this->getOptions();
$options['base_url'] = $this->getBaseURL();
$options['list_id'] = $this->getId();
$list = elgg_list_entities($options, $this->getter);
$list = elgg_format_element('div', [
'class' => 'elgg-sortable-list-view',
], $list);
if (empty($this->search_query) && empty($this->filters) && !preg_match_all("/<ul.*>.*<\/ul>/s", $list)) {
// List is empty
return $list;
}
$sort_options = (array) elgg_extract('sort_options', $options, $this->getSortOptions());
$filter_options = (array) elgg_extract('filter_options', $options, $this->getFilterOptions());
$subtype_options = (array) elgg_extract('subtype_options', $options, $this->getSubtypeOptions());
$show_subtype = elgg_extract('show_subtype', $options, false) && !empty($subtype_options);
$show_sort = elgg_extract('show_sort', $options, false) && !empty($sort_options);
$show_search = elgg_extract('show_search', $options, false);
if (isset($options['show_rel'])) {
// BC
$show_filter = $options['show_rel'] && !empty($filter_options);
} else {
$show_filter = elgg_extract('show_filter', $options, false) && !empty($filter_options);
}
$form = '';
if ($show_sort || $show_search || $show_filter || $show_subtype) {
$form_vars = [
'entity_type' => $this->getEntityType(),
'show_sort' => $show_sort,
'show_search' => $show_search,
'show_filter' => $show_filter,
'show_subtype' => $show_subtype,
'filter' => array_map(function($e) {
return $e['filter'];
}, $this->filters),
'query' => $this->search_query,
'sort' => array_map(function($e) {
return strtolower("{$e['field']}::{$e['direction']}");
}, $this->sorts),
'sort_options' => $sort_options,
'filter_options' => $filter_options,
'subtype_options' => $subtype_options,
'expand_form' => elgg_extract('expand_form', $options),
];
$form = elgg_view_form('lists/sort', array(
'action' => $this->getBaseURL(),
'method' => 'GET',
'disable_security' => true,
'class' => 'elgg-form-sortable-list',
), $form_vars);
}
echo elgg_format_element('div', [
'id' => "$type-sort-{$this->getId()}",
'class' => "elgg-sortable-list $type-sort-list",
], $form . $list);
}
|
[
"public",
"function",
"render",
"(",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"getEntityType",
"(",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"$",
"options",
"[",
"'base_url'",
"]",
"=",
"$",
"this",
"->",
"getBaseURL",
"(",
")",
";",
"$",
"options",
"[",
"'list_id'",
"]",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"$",
"list",
"=",
"elgg_list_entities",
"(",
"$",
"options",
",",
"$",
"this",
"->",
"getter",
")",
";",
"$",
"list",
"=",
"elgg_format_element",
"(",
"'div'",
",",
"[",
"'class'",
"=>",
"'elgg-sortable-list-view'",
",",
"]",
",",
"$",
"list",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"search_query",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"filters",
")",
"&&",
"!",
"preg_match_all",
"(",
"\"/<ul.*>.*<\\/ul>/s\"",
",",
"$",
"list",
")",
")",
"{",
"// List is empty",
"return",
"$",
"list",
";",
"}",
"$",
"sort_options",
"=",
"(",
"array",
")",
"elgg_extract",
"(",
"'sort_options'",
",",
"$",
"options",
",",
"$",
"this",
"->",
"getSortOptions",
"(",
")",
")",
";",
"$",
"filter_options",
"=",
"(",
"array",
")",
"elgg_extract",
"(",
"'filter_options'",
",",
"$",
"options",
",",
"$",
"this",
"->",
"getFilterOptions",
"(",
")",
")",
";",
"$",
"subtype_options",
"=",
"(",
"array",
")",
"elgg_extract",
"(",
"'subtype_options'",
",",
"$",
"options",
",",
"$",
"this",
"->",
"getSubtypeOptions",
"(",
")",
")",
";",
"$",
"show_subtype",
"=",
"elgg_extract",
"(",
"'show_subtype'",
",",
"$",
"options",
",",
"false",
")",
"&&",
"!",
"empty",
"(",
"$",
"subtype_options",
")",
";",
"$",
"show_sort",
"=",
"elgg_extract",
"(",
"'show_sort'",
",",
"$",
"options",
",",
"false",
")",
"&&",
"!",
"empty",
"(",
"$",
"sort_options",
")",
";",
"$",
"show_search",
"=",
"elgg_extract",
"(",
"'show_search'",
",",
"$",
"options",
",",
"false",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'show_rel'",
"]",
")",
")",
"{",
"// BC",
"$",
"show_filter",
"=",
"$",
"options",
"[",
"'show_rel'",
"]",
"&&",
"!",
"empty",
"(",
"$",
"filter_options",
")",
";",
"}",
"else",
"{",
"$",
"show_filter",
"=",
"elgg_extract",
"(",
"'show_filter'",
",",
"$",
"options",
",",
"false",
")",
"&&",
"!",
"empty",
"(",
"$",
"filter_options",
")",
";",
"}",
"$",
"form",
"=",
"''",
";",
"if",
"(",
"$",
"show_sort",
"||",
"$",
"show_search",
"||",
"$",
"show_filter",
"||",
"$",
"show_subtype",
")",
"{",
"$",
"form_vars",
"=",
"[",
"'entity_type'",
"=>",
"$",
"this",
"->",
"getEntityType",
"(",
")",
",",
"'show_sort'",
"=>",
"$",
"show_sort",
",",
"'show_search'",
"=>",
"$",
"show_search",
",",
"'show_filter'",
"=>",
"$",
"show_filter",
",",
"'show_subtype'",
"=>",
"$",
"show_subtype",
",",
"'filter'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"[",
"'filter'",
"]",
";",
"}",
",",
"$",
"this",
"->",
"filters",
")",
",",
"'query'",
"=>",
"$",
"this",
"->",
"search_query",
",",
"'sort'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"e",
")",
"{",
"return",
"strtolower",
"(",
"\"{$e['field']}::{$e['direction']}\"",
")",
";",
"}",
",",
"$",
"this",
"->",
"sorts",
")",
",",
"'sort_options'",
"=>",
"$",
"sort_options",
",",
"'filter_options'",
"=>",
"$",
"filter_options",
",",
"'subtype_options'",
"=>",
"$",
"subtype_options",
",",
"'expand_form'",
"=>",
"elgg_extract",
"(",
"'expand_form'",
",",
"$",
"options",
")",
",",
"]",
";",
"$",
"form",
"=",
"elgg_view_form",
"(",
"'lists/sort'",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"getBaseURL",
"(",
")",
",",
"'method'",
"=>",
"'GET'",
",",
"'disable_security'",
"=>",
"true",
",",
"'class'",
"=>",
"'elgg-form-sortable-list'",
",",
")",
",",
"$",
"form_vars",
")",
";",
"}",
"echo",
"elgg_format_element",
"(",
"'div'",
",",
"[",
"'id'",
"=>",
"\"$type-sort-{$this->getId()}\"",
",",
"'class'",
"=>",
"\"elgg-sortable-list $type-sort-list\"",
",",
"]",
",",
"$",
"form",
".",
"$",
"list",
")",
";",
"}"
] |
Render a list of items
@return string
|
[
"Render",
"a",
"list",
"of",
"items"
] |
6d93d609972d9e4c7aa7b99ba12bddcf5466444a
|
https://github.com/hypeJunction/hypeLists/blob/6d93d609972d9e4c7aa7b99ba12bddcf5466444a/classes/hypeJunction/Lists/EntityList.php#L487-L553
|
230,328
|
wikimedia/mediawiki-extensions-Auth_remoteuser
|
src/UserNameSessionProvider.php
|
UserNameSessionProvider.mergeMetadata
|
public function mergeMetadata( array $savedMetadata, array $providedMetadata ) {
$keys = [
'userId',
'remoteUserName',
'filteredUserName',
'canonicalUserName',
'canonicalUserNameUsed'
];
foreach ( $keys as $key ) {
$savedMetadata[ $key ] = $providedMetadata[ $key ];
}
return parent::mergeMetadata( $savedMetadata, $providedMetadata );
}
|
php
|
public function mergeMetadata( array $savedMetadata, array $providedMetadata ) {
$keys = [
'userId',
'remoteUserName',
'filteredUserName',
'canonicalUserName',
'canonicalUserNameUsed'
];
foreach ( $keys as $key ) {
$savedMetadata[ $key ] = $providedMetadata[ $key ];
}
return parent::mergeMetadata( $savedMetadata, $providedMetadata );
}
|
[
"public",
"function",
"mergeMetadata",
"(",
"array",
"$",
"savedMetadata",
",",
"array",
"$",
"providedMetadata",
")",
"{",
"$",
"keys",
"=",
"[",
"'userId'",
",",
"'remoteUserName'",
",",
"'filteredUserName'",
",",
"'canonicalUserName'",
",",
"'canonicalUserNameUsed'",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"savedMetadata",
"[",
"$",
"key",
"]",
"=",
"$",
"providedMetadata",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"parent",
"::",
"mergeMetadata",
"(",
"$",
"savedMetadata",
",",
"$",
"providedMetadata",
")",
";",
"}"
] |
Never use the stored metadata and return the provided one in any case.
But let our parents implementation of this method decide on his own for the
other members.
@since 2.0.0
|
[
"Never",
"use",
"the",
"stored",
"metadata",
"and",
"return",
"the",
"provided",
"one",
"in",
"any",
"case",
"."
] |
1436b981d6ff721cb7e0072cf32779d56ce03f45
|
https://github.com/wikimedia/mediawiki-extensions-Auth_remoteuser/blob/1436b981d6ff721cb7e0072cf32779d56ce03f45/src/UserNameSessionProvider.php#L446-L458
|
230,329
|
wikimedia/mediawiki-extensions-Auth_remoteuser
|
src/UserNameSessionProvider.php
|
UserNameSessionProvider.persistSession
|
public function persistSession( SessionBackend $session, WebRequest $request ) {
$metadata = $session->getProviderMetadata();
$this->remoteToken = $metadata[ 'filteredUserName' ];
return parent::persistSession( $session, $request );
}
|
php
|
public function persistSession( SessionBackend $session, WebRequest $request ) {
$metadata = $session->getProviderMetadata();
$this->remoteToken = $metadata[ 'filteredUserName' ];
return parent::persistSession( $session, $request );
}
|
[
"public",
"function",
"persistSession",
"(",
"SessionBackend",
"$",
"session",
",",
"WebRequest",
"$",
"request",
")",
"{",
"$",
"metadata",
"=",
"$",
"session",
"->",
"getProviderMetadata",
"(",
")",
";",
"$",
"this",
"->",
"remoteToken",
"=",
"$",
"metadata",
"[",
"'filteredUserName'",
"]",
";",
"return",
"parent",
"::",
"persistSession",
"(",
"$",
"session",
",",
"$",
"request",
")",
";",
"}"
] |
Specify remote token.
@since 2.0.0
|
[
"Specify",
"remote",
"token",
"."
] |
1436b981d6ff721cb7e0072cf32779d56ce03f45
|
https://github.com/wikimedia/mediawiki-extensions-Auth_remoteuser/blob/1436b981d6ff721cb7e0072cf32779d56ce03f45/src/UserNameSessionProvider.php#L755-L759
|
230,330
|
naneau/semver
|
src/Naneau/SemVer/Sort.php
|
Sort.sort
|
public static function sort()
{
$arguments = func_get_args();
if (count($arguments) === 0) {
return array();
}
// Versions array
$versions = array();
// If the first argument is an array, use that
if (is_array($arguments[0])) {
$versions = $arguments[0];
} else {
$versions = $arguments;
}
// Parse into Version isntances
foreach($versions as $key => $version) {
if ($version instanceof Version) {
$versions[$key] = $version;
} else if (is_string($version)) {
$versions[$key] = Parser::parse($version);
} else {
throw new InvalidArgumentException(
'Invalid version given, pass either Version instances or strings'
);
}
}
// Use the array sorter
return self::sortArray($versions);
}
|
php
|
public static function sort()
{
$arguments = func_get_args();
if (count($arguments) === 0) {
return array();
}
// Versions array
$versions = array();
// If the first argument is an array, use that
if (is_array($arguments[0])) {
$versions = $arguments[0];
} else {
$versions = $arguments;
}
// Parse into Version isntances
foreach($versions as $key => $version) {
if ($version instanceof Version) {
$versions[$key] = $version;
} else if (is_string($version)) {
$versions[$key] = Parser::parse($version);
} else {
throw new InvalidArgumentException(
'Invalid version given, pass either Version instances or strings'
);
}
}
// Use the array sorter
return self::sortArray($versions);
}
|
[
"public",
"static",
"function",
"sort",
"(",
")",
"{",
"$",
"arguments",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"arguments",
")",
"===",
"0",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"// Versions array",
"$",
"versions",
"=",
"array",
"(",
")",
";",
"// If the first argument is an array, use that",
"if",
"(",
"is_array",
"(",
"$",
"arguments",
"[",
"0",
"]",
")",
")",
"{",
"$",
"versions",
"=",
"$",
"arguments",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"versions",
"=",
"$",
"arguments",
";",
"}",
"// Parse into Version isntances",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"key",
"=>",
"$",
"version",
")",
"{",
"if",
"(",
"$",
"version",
"instanceof",
"Version",
")",
"{",
"$",
"versions",
"[",
"$",
"key",
"]",
"=",
"$",
"version",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"version",
")",
")",
"{",
"$",
"versions",
"[",
"$",
"key",
"]",
"=",
"Parser",
"::",
"parse",
"(",
"$",
"version",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid version given, pass either Version instances or strings'",
")",
";",
"}",
"}",
"// Use the array sorter",
"return",
"self",
"::",
"sortArray",
"(",
"$",
"versions",
")",
";",
"}"
] |
Sort a set of SemVer versions
This method is a catch-all and accepts:
- A single array of strings or Versions
- A variable number of strings and Versions
Strings will be parsed into Version instances
The result will be a sorted array of Versions, in ascending order
@param array|string|Version $v1
@param string|Version $v1
...
@param string|Version $vn
@return array[int]SemVer
|
[
"Sort",
"a",
"set",
"of",
"SemVer",
"versions"
] |
c771ad1e6c89064c0a4fa714979639dc3649d6c8
|
https://github.com/naneau/semver/blob/c771ad1e6c89064c0a4fa714979639dc3649d6c8/src/Naneau/SemVer/Sort.php#L44-L77
|
230,331
|
naneau/semver
|
src/Naneau/SemVer/Sort.php
|
Sort.sortArray
|
public static function sortArray(array $versions)
{
// Empty array does not needs sorting
if (count($versions) === 0) {
return array();
}
// Array of one item (pivot) from the middle
$pivotArray = array_splice(
$versions,
(int) floor((count($versions) - 1) / 2),
1
);
// Smaller/greater than pivot stack
$smaller = array();
$greater = array();
// Fill stacks
foreach($versions as $version) {
if (Compare::greaterThan($version, $pivotArray[0])) {
$greater[] = $version;
} else {
$smaller[] = $version;
}
}
// Recurse and merge results
return array_merge(
self::sortArray($smaller),
$pivotArray,
self::sortArray($greater)
);
}
|
php
|
public static function sortArray(array $versions)
{
// Empty array does not needs sorting
if (count($versions) === 0) {
return array();
}
// Array of one item (pivot) from the middle
$pivotArray = array_splice(
$versions,
(int) floor((count($versions) - 1) / 2),
1
);
// Smaller/greater than pivot stack
$smaller = array();
$greater = array();
// Fill stacks
foreach($versions as $version) {
if (Compare::greaterThan($version, $pivotArray[0])) {
$greater[] = $version;
} else {
$smaller[] = $version;
}
}
// Recurse and merge results
return array_merge(
self::sortArray($smaller),
$pivotArray,
self::sortArray($greater)
);
}
|
[
"public",
"static",
"function",
"sortArray",
"(",
"array",
"$",
"versions",
")",
"{",
"// Empty array does not needs sorting",
"if",
"(",
"count",
"(",
"$",
"versions",
")",
"===",
"0",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"// Array of one item (pivot) from the middle",
"$",
"pivotArray",
"=",
"array_splice",
"(",
"$",
"versions",
",",
"(",
"int",
")",
"floor",
"(",
"(",
"count",
"(",
"$",
"versions",
")",
"-",
"1",
")",
"/",
"2",
")",
",",
"1",
")",
";",
"// Smaller/greater than pivot stack",
"$",
"smaller",
"=",
"array",
"(",
")",
";",
"$",
"greater",
"=",
"array",
"(",
")",
";",
"// Fill stacks",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"version",
")",
"{",
"if",
"(",
"Compare",
"::",
"greaterThan",
"(",
"$",
"version",
",",
"$",
"pivotArray",
"[",
"0",
"]",
")",
")",
"{",
"$",
"greater",
"[",
"]",
"=",
"$",
"version",
";",
"}",
"else",
"{",
"$",
"smaller",
"[",
"]",
"=",
"$",
"version",
";",
"}",
"}",
"// Recurse and merge results",
"return",
"array_merge",
"(",
"self",
"::",
"sortArray",
"(",
"$",
"smaller",
")",
",",
"$",
"pivotArray",
",",
"self",
"::",
"sortArray",
"(",
"$",
"greater",
")",
")",
";",
"}"
] |
Sort an array of Versions
unlike sort() this method accepts only an array of Version instances
This method uses QuickSort for the actual sorting
@param array[int]Version
@return array[int]Version
|
[
"Sort",
"an",
"array",
"of",
"Versions"
] |
c771ad1e6c89064c0a4fa714979639dc3649d6c8
|
https://github.com/naneau/semver/blob/c771ad1e6c89064c0a4fa714979639dc3649d6c8/src/Naneau/SemVer/Sort.php#L89-L122
|
230,332
|
addiks/phpsql
|
src/Addiks/PHPSQL/Index/BTreeNodePage.php
|
BTreeNodePage.getLastReference
|
public function getLastReference()
{
return substr($this->data, $this->forkRate * $this->keyLength*3, $this->keyLength);
}
|
php
|
public function getLastReference()
{
return substr($this->data, $this->forkRate * $this->keyLength*3, $this->keyLength);
}
|
[
"public",
"function",
"getLastReference",
"(",
")",
"{",
"return",
"substr",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"forkRate",
"*",
"$",
"this",
"->",
"keyLength",
"*",
"3",
",",
"$",
"this",
"->",
"keyLength",
")",
";",
"}"
] |
When not in 'leaf-mode', all references get used when search-value
is lower then corresponding reference-value.
This leaves the case open that the search-value is bigger then all reference-values.
In that case, this extra reference is used.
|
[
"When",
"not",
"in",
"leaf",
"-",
"mode",
"all",
"references",
"get",
"used",
"when",
"search",
"-",
"value",
"is",
"lower",
"then",
"corresponding",
"reference",
"-",
"value",
".",
"This",
"leaves",
"the",
"case",
"open",
"that",
"the",
"search",
"-",
"value",
"is",
"bigger",
"then",
"all",
"reference",
"-",
"values",
".",
"In",
"that",
"case",
"this",
"extra",
"reference",
"is",
"used",
"."
] |
28dae64ffc2123f39f801a50ab53bfe29890cbd9
|
https://github.com/addiks/phpsql/blob/28dae64ffc2123f39f801a50ab53bfe29890cbd9/src/Addiks/PHPSQL/Index/BTreeNodePage.php#L183-L186
|
230,333
|
naneau/semver
|
src/Naneau/SemVer/Parser/Versionable.php
|
Versionable.parse
|
public static function parse($string, $className)
{
// Sanity check
if (substr_count($string, '.') !== 2) {
throw new InvalidArgumentException(
'part "' . $string . '" can not be parsed into a SemVer'
. ' major.minor.patch version'
);
}
// Simple explode will do here
$parts = explode('.', $string);
// Instantiate
$versionable = new $className;
// Sanity check of class type
if (!($versionable instanceof VersionableVersion)) {
throw new InvalidArgumentException(
'"' . $className . '" is not Versionable'
);
}
// Versionable parts
$versionable
->setMajor((int) $parts[0])
->setMinor((int) $parts[1])
->setPatch((int) $parts[2]);
return $versionable;
}
|
php
|
public static function parse($string, $className)
{
// Sanity check
if (substr_count($string, '.') !== 2) {
throw new InvalidArgumentException(
'part "' . $string . '" can not be parsed into a SemVer'
. ' major.minor.patch version'
);
}
// Simple explode will do here
$parts = explode('.', $string);
// Instantiate
$versionable = new $className;
// Sanity check of class type
if (!($versionable instanceof VersionableVersion)) {
throw new InvalidArgumentException(
'"' . $className . '" is not Versionable'
);
}
// Versionable parts
$versionable
->setMajor((int) $parts[0])
->setMinor((int) $parts[1])
->setPatch((int) $parts[2]);
return $versionable;
}
|
[
"public",
"static",
"function",
"parse",
"(",
"$",
"string",
",",
"$",
"className",
")",
"{",
"// Sanity check",
"if",
"(",
"substr_count",
"(",
"$",
"string",
",",
"'.'",
")",
"!==",
"2",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'part \"'",
".",
"$",
"string",
".",
"'\" can not be parsed into a SemVer'",
".",
"' major.minor.patch version'",
")",
";",
"}",
"// Simple explode will do here",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"string",
")",
";",
"// Instantiate",
"$",
"versionable",
"=",
"new",
"$",
"className",
";",
"// Sanity check of class type",
"if",
"(",
"!",
"(",
"$",
"versionable",
"instanceof",
"VersionableVersion",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'\"'",
".",
"$",
"className",
".",
"'\" is not Versionable'",
")",
";",
"}",
"// Versionable parts",
"$",
"versionable",
"->",
"setMajor",
"(",
"(",
"int",
")",
"$",
"parts",
"[",
"0",
"]",
")",
"->",
"setMinor",
"(",
"(",
"int",
")",
"$",
"parts",
"[",
"1",
"]",
")",
"->",
"setPatch",
"(",
"(",
"int",
")",
"$",
"parts",
"[",
"2",
"]",
")",
";",
"return",
"$",
"versionable",
";",
"}"
] |
Parse a string into Versionable properties
@throws InvalidArgumentException
@param string $string
@param string $className
@return VersionableVersion
|
[
"Parse",
"a",
"string",
"into",
"Versionable",
"properties"
] |
c771ad1e6c89064c0a4fa714979639dc3649d6c8
|
https://github.com/naneau/semver/blob/c771ad1e6c89064c0a4fa714979639dc3649d6c8/src/Naneau/SemVer/Parser/Versionable.php#L36-L66
|
230,334
|
Webiny/Framework
|
src/Webiny/Component/Config/Bridge/Yaml/SymfonyYaml/SymfonyYaml.php
|
SymfonyYaml.parseResource
|
private function parseResource()
{
if ($this->isArray($this->resource)) {
return StdObjectWrapper::toArray($this->resource);
} elseif ($this->isString($this->resource)) {
return Yaml::parse($this->resource);
} elseif ($this->isInstanceOf($this->resource, ConfigObject::class)) {
return $this->resource->toArray();
}
throw new SymfonyYamlException(SymfonyYamlException::UNABLE_TO_PARSE, [gettype($this->resource)]);
}
|
php
|
private function parseResource()
{
if ($this->isArray($this->resource)) {
return StdObjectWrapper::toArray($this->resource);
} elseif ($this->isString($this->resource)) {
return Yaml::parse($this->resource);
} elseif ($this->isInstanceOf($this->resource, ConfigObject::class)) {
return $this->resource->toArray();
}
throw new SymfonyYamlException(SymfonyYamlException::UNABLE_TO_PARSE, [gettype($this->resource)]);
}
|
[
"private",
"function",
"parseResource",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isArray",
"(",
"$",
"this",
"->",
"resource",
")",
")",
"{",
"return",
"StdObjectWrapper",
"::",
"toArray",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isString",
"(",
"$",
"this",
"->",
"resource",
")",
")",
"{",
"return",
"Yaml",
"::",
"parse",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isInstanceOf",
"(",
"$",
"this",
"->",
"resource",
",",
"ConfigObject",
"::",
"class",
")",
")",
"{",
"return",
"$",
"this",
"->",
"resource",
"->",
"toArray",
"(",
")",
";",
"}",
"throw",
"new",
"SymfonyYamlException",
"(",
"SymfonyYamlException",
"::",
"UNABLE_TO_PARSE",
",",
"[",
"gettype",
"(",
"$",
"this",
"->",
"resource",
")",
"]",
")",
";",
"}"
] |
Parse given Yaml resource and build array
@throws SymfonyYamlException
@return array
|
[
"Parse",
"given",
"Yaml",
"resource",
"and",
"build",
"array"
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/Bridge/Yaml/SymfonyYaml/SymfonyYaml.php#L73-L84
|
230,335
|
Webiny/Framework
|
src/Webiny/Component/Security/User/AbstractUser.php
|
AbstractUser.populate
|
public function populate($username, $password, array $roles, $isAuthenticated = false)
{
// store general data
$this->username = $username;
$this->password = $password;
$this->isAuthenticated = $isAuthenticated;
$this->roles = $this->arr([]);
foreach ($roles as $r) {
if($this->isInstanceOf($r, Role::class)) {
$this->roles->append($r);
} else {
$this->roles->append(new Role($r));
}
}
// append anonymous role
$this->roles->append(new Role('ROLE_ANONYMOUS'));
}
|
php
|
public function populate($username, $password, array $roles, $isAuthenticated = false)
{
// store general data
$this->username = $username;
$this->password = $password;
$this->isAuthenticated = $isAuthenticated;
$this->roles = $this->arr([]);
foreach ($roles as $r) {
if($this->isInstanceOf($r, Role::class)) {
$this->roles->append($r);
} else {
$this->roles->append(new Role($r));
}
}
// append anonymous role
$this->roles->append(new Role('ROLE_ANONYMOUS'));
}
|
[
"public",
"function",
"populate",
"(",
"$",
"username",
",",
"$",
"password",
",",
"array",
"$",
"roles",
",",
"$",
"isAuthenticated",
"=",
"false",
")",
"{",
"// store general data",
"$",
"this",
"->",
"username",
"=",
"$",
"username",
";",
"$",
"this",
"->",
"password",
"=",
"$",
"password",
";",
"$",
"this",
"->",
"isAuthenticated",
"=",
"$",
"isAuthenticated",
";",
"$",
"this",
"->",
"roles",
"=",
"$",
"this",
"->",
"arr",
"(",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"r",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isInstanceOf",
"(",
"$",
"r",
",",
"Role",
"::",
"class",
")",
")",
"{",
"$",
"this",
"->",
"roles",
"->",
"append",
"(",
"$",
"r",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"roles",
"->",
"append",
"(",
"new",
"Role",
"(",
"$",
"r",
")",
")",
";",
"}",
"}",
"// append anonymous role",
"$",
"this",
"->",
"roles",
"->",
"append",
"(",
"new",
"Role",
"(",
"'ROLE_ANONYMOUS'",
")",
")",
";",
"}"
] |
Populate the user object.
@param string $username Username.
@param string $password Hashed password.
@param array $roles Array of the assigned roles.
@param bool $isAuthenticated Boolean flag that tells us if user is already authenticated or not.
|
[
"Populate",
"the",
"user",
"object",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/User/AbstractUser.php#L76-L94
|
230,336
|
Webiny/Framework
|
src/Webiny/Component/Security/User/AbstractUser.php
|
AbstractUser.hasRole
|
public function hasRole($role)
{
foreach ($this->roles as $roleObj) {
if($role == $roleObj->getRole()){
return true;
}
}
return false;
}
|
php
|
public function hasRole($role)
{
foreach ($this->roles as $roleObj) {
if($role == $roleObj->getRole()){
return true;
}
}
return false;
}
|
[
"public",
"function",
"hasRole",
"(",
"$",
"role",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"roles",
"as",
"$",
"roleObj",
")",
"{",
"if",
"(",
"$",
"role",
"==",
"$",
"roleObj",
"->",
"getRole",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if current user has the defined role.
@param string $role Role name
@return bool True if user has the role, otherwise false.
|
[
"Check",
"if",
"current",
"user",
"has",
"the",
"defined",
"role",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/User/AbstractUser.php#L128-L136
|
230,337
|
Webiny/Framework
|
src/Webiny/Component/Http/Request/Files/File.php
|
File.store
|
public function store($folder, $filename = null)
{
// check for errors
if ($this->getError() == UPLOAD_ERR_OK) {
throw new FilesException('Unable to move the file because an upload error occurred.');
}
// validate filename
$filename = isset($filename) ? $filename : $this->getName();
// validate folder
$folder = $this->str($folder);
if (!$folder->endsWith('/') && !$folder->endsWith('\\')) {
$folder = $folder->val() . DIRECTORY_SEPARATOR;
} else {
$folder->val();
}
// check if we have already stored the file
$path = $folder . $filename;
if ($this->stored && $this->storedPath == $path) {
return true;
}
// move the file
try {
$result = move_uploaded_file($this->tmpName, $path);
if (!$result) {
throw new FilesException('Unable to store file.');
}
$this->stored = $result;
$this->storedPath = $folder . $filename;
} catch (\Exception $e) {
throw new FilesException($e->getMessage());
}
return $result;
}
|
php
|
public function store($folder, $filename = null)
{
// check for errors
if ($this->getError() == UPLOAD_ERR_OK) {
throw new FilesException('Unable to move the file because an upload error occurred.');
}
// validate filename
$filename = isset($filename) ? $filename : $this->getName();
// validate folder
$folder = $this->str($folder);
if (!$folder->endsWith('/') && !$folder->endsWith('\\')) {
$folder = $folder->val() . DIRECTORY_SEPARATOR;
} else {
$folder->val();
}
// check if we have already stored the file
$path = $folder . $filename;
if ($this->stored && $this->storedPath == $path) {
return true;
}
// move the file
try {
$result = move_uploaded_file($this->tmpName, $path);
if (!$result) {
throw new FilesException('Unable to store file.');
}
$this->stored = $result;
$this->storedPath = $folder . $filename;
} catch (\Exception $e) {
throw new FilesException($e->getMessage());
}
return $result;
}
|
[
"public",
"function",
"store",
"(",
"$",
"folder",
",",
"$",
"filename",
"=",
"null",
")",
"{",
"// check for errors",
"if",
"(",
"$",
"this",
"->",
"getError",
"(",
")",
"==",
"UPLOAD_ERR_OK",
")",
"{",
"throw",
"new",
"FilesException",
"(",
"'Unable to move the file because an upload error occurred.'",
")",
";",
"}",
"// validate filename",
"$",
"filename",
"=",
"isset",
"(",
"$",
"filename",
")",
"?",
"$",
"filename",
":",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"// validate folder",
"$",
"folder",
"=",
"$",
"this",
"->",
"str",
"(",
"$",
"folder",
")",
";",
"if",
"(",
"!",
"$",
"folder",
"->",
"endsWith",
"(",
"'/'",
")",
"&&",
"!",
"$",
"folder",
"->",
"endsWith",
"(",
"'\\\\'",
")",
")",
"{",
"$",
"folder",
"=",
"$",
"folder",
"->",
"val",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"else",
"{",
"$",
"folder",
"->",
"val",
"(",
")",
";",
"}",
"// check if we have already stored the file",
"$",
"path",
"=",
"$",
"folder",
".",
"$",
"filename",
";",
"if",
"(",
"$",
"this",
"->",
"stored",
"&&",
"$",
"this",
"->",
"storedPath",
"==",
"$",
"path",
")",
"{",
"return",
"true",
";",
"}",
"// move the file",
"try",
"{",
"$",
"result",
"=",
"move_uploaded_file",
"(",
"$",
"this",
"->",
"tmpName",
",",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"FilesException",
"(",
"'Unable to store file.'",
")",
";",
"}",
"$",
"this",
"->",
"stored",
"=",
"$",
"result",
";",
"$",
"this",
"->",
"storedPath",
"=",
"$",
"folder",
".",
"$",
"filename",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"FilesException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Store the uploaded file to a designated destination.
@param string $folder Folder under which the file will be saved.
@param null|string $filename If you wish to store the file under a different name, other than the original uploaded name.
@return bool True if file was successfully saved in the designated destination.
@throws FilesException
|
[
"Store",
"the",
"uploaded",
"file",
"to",
"a",
"designated",
"destination",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/Request/Files/File.php#L107-L144
|
230,338
|
alexandresalome/php-webdriver
|
src/WebDriver/Browser.php
|
Browser.execute
|
public function execute($javascript, array $args = array())
{
$response = $this->request('POST', 'execute', json_encode(array(
'script' => $javascript,
'args' => $args
)));
$data = json_decode($response->getContent(), true);
return $data['value'];
}
|
php
|
public function execute($javascript, array $args = array())
{
$response = $this->request('POST', 'execute', json_encode(array(
'script' => $javascript,
'args' => $args
)));
$data = json_decode($response->getContent(), true);
return $data['value'];
}
|
[
"public",
"function",
"execute",
"(",
"$",
"javascript",
",",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"request",
"(",
"'POST'",
",",
"'execute'",
",",
"json_encode",
"(",
"array",
"(",
"'script'",
"=>",
"$",
"javascript",
",",
"'args'",
"=>",
"$",
"args",
")",
")",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getContent",
"(",
")",
",",
"true",
")",
";",
"return",
"$",
"data",
"[",
"'value'",
"]",
";",
"}"
] |
Run a Javascript snippet on browser.
@param string $javascript The javascript snippet to execute
@param array $args Arguments to pass to snippet (accessible by arguments[0], ...)
@return mixed Result of javascript execution
|
[
"Run",
"a",
"Javascript",
"snippet",
"on",
"browser",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Browser.php#L176-L186
|
230,339
|
alexandresalome/php-webdriver
|
src/WebDriver/Browser.php
|
Browser.moveTo
|
public function moveTo($x, $y, Element $element = null)
{
$this->request('POST', 'moveto', json_encode(array(
'element' => $element ? $element->getId() : null,
'xoffset' => $x,
'yoffset' => $y
)));
return $this;
}
|
php
|
public function moveTo($x, $y, Element $element = null)
{
$this->request('POST', 'moveto', json_encode(array(
'element' => $element ? $element->getId() : null,
'xoffset' => $x,
'yoffset' => $y
)));
return $this;
}
|
[
"public",
"function",
"moveTo",
"(",
"$",
"x",
",",
"$",
"y",
",",
"Element",
"$",
"element",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"request",
"(",
"'POST'",
",",
"'moveto'",
",",
"json_encode",
"(",
"array",
"(",
"'element'",
"=>",
"$",
"element",
"?",
"$",
"element",
"->",
"getId",
"(",
")",
":",
"null",
",",
"'xoffset'",
"=>",
"$",
"x",
",",
"'yoffset'",
"=>",
"$",
"y",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Moves the mouse to a given position.
@param int $x X offset
@param int $y Y offset
@param Element $element Relative to an element
@return Browser
|
[
"Moves",
"the",
"mouse",
"to",
"a",
"given",
"position",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Browser.php#L226-L235
|
230,340
|
alexandresalome/php-webdriver
|
src/WebDriver/Browser.php
|
Browser.close
|
public function close()
{
if (null === $this->sessionId) {
return;
}
$this->client->closeBrowser($this->getSessionId());
$this->sessionId = null;
return $this;
}
|
php
|
public function close()
{
if (null === $this->sessionId) {
return;
}
$this->client->closeBrowser($this->getSessionId());
$this->sessionId = null;
return $this;
}
|
[
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"sessionId",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"client",
"->",
"closeBrowser",
"(",
"$",
"this",
"->",
"getSessionId",
"(",
")",
")",
";",
"$",
"this",
"->",
"sessionId",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
] |
Closes the session and disable this session.
@return Browser fluid interface
|
[
"Closes",
"the",
"session",
"and",
"disable",
"this",
"session",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Browser.php#L288-L298
|
230,341
|
alexandresalome/php-webdriver
|
src/WebDriver/Browser.php
|
Browser.request
|
public function request($verb, $path, $content = null, array $headers = array())
{
return $this->client->request($verb, sprintf('/session/%s/%s', $this->sessionId, $path), $content, $headers);
}
|
php
|
public function request($verb, $path, $content = null, array $headers = array())
{
return $this->client->request($verb, sprintf('/session/%s/%s', $this->sessionId, $path), $content, $headers);
}
|
[
"public",
"function",
"request",
"(",
"$",
"verb",
",",
"$",
"path",
",",
"$",
"content",
"=",
"null",
",",
"array",
"$",
"headers",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"$",
"verb",
",",
"sprintf",
"(",
"'/session/%s/%s'",
",",
"$",
"this",
"->",
"sessionId",
",",
"$",
"path",
")",
",",
"$",
"content",
",",
"$",
"headers",
")",
";",
"}"
] |
Ease requesting in session directory.
@return Response
|
[
"Ease",
"requesting",
"in",
"session",
"directory",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Browser.php#L475-L478
|
230,342
|
alexandresalome/php-webdriver
|
src/WebDriver/Browser.php
|
Browser.requestValue
|
public function requestValue($name)
{
$response = $this->client->request('GET', sprintf('/session/%s/%s', $this->sessionId, $name));
$content = json_decode($response->getContent(), true);
if (!isset($content['value'])) {
throw new LibraryException('Malformed response: expected a key "value" in JSON response: '.$response->getContent());
}
return $content['value'];
}
|
php
|
public function requestValue($name)
{
$response = $this->client->request('GET', sprintf('/session/%s/%s', $this->sessionId, $name));
$content = json_decode($response->getContent(), true);
if (!isset($content['value'])) {
throw new LibraryException('Malformed response: expected a key "value" in JSON response: '.$response->getContent());
}
return $content['value'];
}
|
[
"public",
"function",
"requestValue",
"(",
"$",
"name",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"'GET'",
",",
"sprintf",
"(",
"'/session/%s/%s'",
",",
"$",
"this",
"->",
"sessionId",
",",
"$",
"name",
")",
")",
";",
"$",
"content",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getContent",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"content",
"[",
"'value'",
"]",
")",
")",
"{",
"throw",
"new",
"LibraryException",
"(",
"'Malformed response: expected a key \"value\" in JSON response: '",
".",
"$",
"response",
"->",
"getContent",
"(",
")",
")",
";",
"}",
"return",
"$",
"content",
"[",
"'value'",
"]",
";",
"}"
] |
Internal method to get a scalar value from server.
@return mixed
|
[
"Internal",
"method",
"to",
"get",
"a",
"scalar",
"value",
"from",
"server",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Browser.php#L485-L495
|
230,343
|
Webiny/Framework
|
src/Webiny/Component/Rest/Parser/Parser.php
|
Parser.parseApi
|
public function parseApi($class, $normalize)
{
$versions = $this->getVersions($class);
$parsedApi = new ParsedApi($class);
foreach ($versions['versions'] as $v => $versionClass) {
$classParser = new ClassParser($versionClass, $normalize);
$parsedApi->addVersion($classParser->getParsedClass(), $v);
}
$parsedApi->setCurrentVersion($versions['current']);
$parsedApi->setLatestVersion($versions['latest']);
return $parsedApi;
}
|
php
|
public function parseApi($class, $normalize)
{
$versions = $this->getVersions($class);
$parsedApi = new ParsedApi($class);
foreach ($versions['versions'] as $v => $versionClass) {
$classParser = new ClassParser($versionClass, $normalize);
$parsedApi->addVersion($classParser->getParsedClass(), $v);
}
$parsedApi->setCurrentVersion($versions['current']);
$parsedApi->setLatestVersion($versions['latest']);
return $parsedApi;
}
|
[
"public",
"function",
"parseApi",
"(",
"$",
"class",
",",
"$",
"normalize",
")",
"{",
"$",
"versions",
"=",
"$",
"this",
"->",
"getVersions",
"(",
"$",
"class",
")",
";",
"$",
"parsedApi",
"=",
"new",
"ParsedApi",
"(",
"$",
"class",
")",
";",
"foreach",
"(",
"$",
"versions",
"[",
"'versions'",
"]",
"as",
"$",
"v",
"=>",
"$",
"versionClass",
")",
"{",
"$",
"classParser",
"=",
"new",
"ClassParser",
"(",
"$",
"versionClass",
",",
"$",
"normalize",
")",
";",
"$",
"parsedApi",
"->",
"addVersion",
"(",
"$",
"classParser",
"->",
"getParsedClass",
"(",
")",
",",
"$",
"v",
")",
";",
"}",
"$",
"parsedApi",
"->",
"setCurrentVersion",
"(",
"$",
"versions",
"[",
"'current'",
"]",
")",
";",
"$",
"parsedApi",
"->",
"setLatestVersion",
"(",
"$",
"versions",
"[",
"'latest'",
"]",
")",
";",
"return",
"$",
"parsedApi",
";",
"}"
] |
Parses the api class and all its versions.
@param string $class Fully qualified name of the api class.
@param bool $normalize Should the class name and the method name be normalized.
@return ParsedApi
|
[
"Parses",
"the",
"api",
"class",
"and",
"all",
"its",
"versions",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/Parser.php#L27-L41
|
230,344
|
Webiny/Framework
|
src/Webiny/Component/Entity/Attribute/Many2OneAttribute.php
|
Many2OneAttribute.getDbValue
|
public function getDbValue()
{
$value = $this->getValue();
if (is_null($value)) {
// Process default value
$value = $this->getDefaultValue();
if ($this->isInstanceOf($value, AbstractEntity::class)) {
if (!$value->exists()) {
$value->save();
}
$value = $value->id;
}
return $this->processToDbValue($value);
}
// Save if new or if updating is allowed
if (!$value->exists() || $this->getUpdateExisting()) {
$value->save();
}
return $this->processToDbValue($value->id);
}
|
php
|
public function getDbValue()
{
$value = $this->getValue();
if (is_null($value)) {
// Process default value
$value = $this->getDefaultValue();
if ($this->isInstanceOf($value, AbstractEntity::class)) {
if (!$value->exists()) {
$value->save();
}
$value = $value->id;
}
return $this->processToDbValue($value);
}
// Save if new or if updating is allowed
if (!$value->exists() || $this->getUpdateExisting()) {
$value->save();
}
return $this->processToDbValue($value->id);
}
|
[
"public",
"function",
"getDbValue",
"(",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"// Process default value",
"$",
"value",
"=",
"$",
"this",
"->",
"getDefaultValue",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isInstanceOf",
"(",
"$",
"value",
",",
"AbstractEntity",
"::",
"class",
")",
")",
"{",
"if",
"(",
"!",
"$",
"value",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"value",
"->",
"save",
"(",
")",
";",
"}",
"$",
"value",
"=",
"$",
"value",
"->",
"id",
";",
"}",
"return",
"$",
"this",
"->",
"processToDbValue",
"(",
"$",
"value",
")",
";",
"}",
"// Save if new or if updating is allowed",
"if",
"(",
"!",
"$",
"value",
"->",
"exists",
"(",
")",
"||",
"$",
"this",
"->",
"getUpdateExisting",
"(",
")",
")",
"{",
"$",
"value",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"processToDbValue",
"(",
"$",
"value",
"->",
"id",
")",
";",
"}"
] |
Get value that will be stored to database
@return string
|
[
"Get",
"value",
"that",
"will",
"be",
"stored",
"to",
"database"
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Entity/Attribute/Many2OneAttribute.php#L109-L132
|
230,345
|
alexandresalome/php-webdriver
|
src/WebDriver/WindowList.php
|
WindowList.setSize
|
public function setSize($width, $height, $name = null)
{
if (null === $name) {
$name = 'current';
}
$this->browser->request('POST', 'window/'.urlencode($name).'/size', json_encode(array('width' => $width, 'height' => $height)));
return $this;
}
|
php
|
public function setSize($width, $height, $name = null)
{
if (null === $name) {
$name = 'current';
}
$this->browser->request('POST', 'window/'.urlencode($name).'/size', json_encode(array('width' => $width, 'height' => $height)));
return $this;
}
|
[
"public",
"function",
"setSize",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"'current'",
";",
"}",
"$",
"this",
"->",
"browser",
"->",
"request",
"(",
"'POST'",
",",
"'window/'",
".",
"urlencode",
"(",
"$",
"name",
")",
".",
"'/size'",
",",
"json_encode",
"(",
"array",
"(",
"'width'",
"=>",
"$",
"width",
",",
"'height'",
"=>",
"$",
"height",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Changes a window size.
@return WindowList
|
[
"Changes",
"a",
"window",
"size",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/WindowList.php#L92-L101
|
230,346
|
alexandresalome/php-webdriver
|
src/WebDriver/WindowList.php
|
WindowList.setPosition
|
public function setPosition($x, $y, $name = 'current')
{
if (null === $name) {
$name = 'current';
}
$this->browser->request('POST', 'window/'.urlencode($name).'/position', json_encode(array('x' => $x, 'y' => $y)));
return $this;
}
|
php
|
public function setPosition($x, $y, $name = 'current')
{
if (null === $name) {
$name = 'current';
}
$this->browser->request('POST', 'window/'.urlencode($name).'/position', json_encode(array('x' => $x, 'y' => $y)));
return $this;
}
|
[
"public",
"function",
"setPosition",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"name",
"=",
"'current'",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"'current'",
";",
"}",
"$",
"this",
"->",
"browser",
"->",
"request",
"(",
"'POST'",
",",
"'window/'",
".",
"urlencode",
"(",
"$",
"name",
")",
".",
"'/position'",
",",
"json_encode",
"(",
"array",
"(",
"'x'",
"=>",
"$",
"x",
",",
"'y'",
"=>",
"$",
"y",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Changes a window position.
@return WindowList
|
[
"Changes",
"a",
"window",
"position",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/WindowList.php#L121-L130
|
230,347
|
alexandresalome/php-webdriver
|
src/WebDriver/WindowList.php
|
WindowList.maximize
|
public function maximize($name = 'current')
{
if (null === $name) {
$name = 'current';
}
$this->browser->request('POST', 'window/'.urlencode($name).'/maximize');
return $this;
}
|
php
|
public function maximize($name = 'current')
{
if (null === $name) {
$name = 'current';
}
$this->browser->request('POST', 'window/'.urlencode($name).'/maximize');
return $this;
}
|
[
"public",
"function",
"maximize",
"(",
"$",
"name",
"=",
"'current'",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"'current'",
";",
"}",
"$",
"this",
"->",
"browser",
"->",
"request",
"(",
"'POST'",
",",
"'window/'",
".",
"urlencode",
"(",
"$",
"name",
")",
".",
"'/maximize'",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Maximizes a window.
@return WindowList
|
[
"Maximizes",
"a",
"window",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/WindowList.php#L137-L146
|
230,348
|
addiks/phpsql
|
src/Addiks/PHPSQL/Value/Database/Dsn/MySQLDsn.php
|
MySQLDsn.getAsAssociative
|
protected function getAsAssociative()
{
$value = $this->getValue();
$value = explode(":", $value);
$value = $value[1];
$value = explode(";", $value);
$values = array();
foreach ($value as $value) {
$value = explode("=", $value);
list($key, $value) = $value;
$values[$key] = $value;
}
return $values;
}
|
php
|
protected function getAsAssociative()
{
$value = $this->getValue();
$value = explode(":", $value);
$value = $value[1];
$value = explode(";", $value);
$values = array();
foreach ($value as $value) {
$value = explode("=", $value);
list($key, $value) = $value;
$values[$key] = $value;
}
return $values;
}
|
[
"protected",
"function",
"getAsAssociative",
"(",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"$",
"value",
"=",
"explode",
"(",
"\":\"",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"$",
"value",
"[",
"1",
"]",
";",
"$",
"value",
"=",
"explode",
"(",
"\";\"",
",",
"$",
"value",
")",
";",
"$",
"values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"explode",
"(",
"\"=\"",
",",
"$",
"value",
")",
";",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"$",
"value",
";",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"values",
";",
"}"
] |
Gets the parts of the DSN as an associative array.
@see Value::getValue()
@return array
|
[
"Gets",
"the",
"parts",
"of",
"the",
"DSN",
"as",
"an",
"associative",
"array",
"."
] |
28dae64ffc2123f39f801a50ab53bfe29890cbd9
|
https://github.com/addiks/phpsql/blob/28dae64ffc2123f39f801a50ab53bfe29890cbd9/src/Addiks/PHPSQL/Value/Database/Dsn/MySQLDsn.php#L40-L60
|
230,349
|
Webiny/Framework
|
src/Webiny/Component/Security/User/Providers/Memory/Memory.php
|
Memory.addUsers
|
private function addUsers($users)
{
if (!is_array($users)) {
return false;
}
foreach ($users as $username => $data) {
if ($username == '' || !$this->isString($username)) {
throw new MemoryException('Cannot store a user that doesn\'t have a username.');
}
if (!isset($data['password'])) {
$data['password'] = '';
}
if (!isset($data['roles']) || empty($data['roles'])) {
$data['roles'] = [];
} else {
$data['roles'] = (array)$data['roles'];
}
$this->users[$username] = $data;
}
return true;
}
|
php
|
private function addUsers($users)
{
if (!is_array($users)) {
return false;
}
foreach ($users as $username => $data) {
if ($username == '' || !$this->isString($username)) {
throw new MemoryException('Cannot store a user that doesn\'t have a username.');
}
if (!isset($data['password'])) {
$data['password'] = '';
}
if (!isset($data['roles']) || empty($data['roles'])) {
$data['roles'] = [];
} else {
$data['roles'] = (array)$data['roles'];
}
$this->users[$username] = $data;
}
return true;
}
|
[
"private",
"function",
"addUsers",
"(",
"$",
"users",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"users",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"users",
"as",
"$",
"username",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"username",
"==",
"''",
"||",
"!",
"$",
"this",
"->",
"isString",
"(",
"$",
"username",
")",
")",
"{",
"throw",
"new",
"MemoryException",
"(",
"'Cannot store a user that doesn\\'t have a username.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'password'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'password'",
"]",
"=",
"''",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'roles'",
"]",
")",
"||",
"empty",
"(",
"$",
"data",
"[",
"'roles'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'roles'",
"]",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'roles'",
"]",
"=",
"(",
"array",
")",
"$",
"data",
"[",
"'roles'",
"]",
";",
"}",
"$",
"this",
"->",
"users",
"[",
"$",
"username",
"]",
"=",
"$",
"data",
";",
"}",
"return",
"true",
";",
"}"
] |
Check user data and, if valid, store them.
@param array $users List of user accounts.
@return bool
@throws MemoryException
|
[
"Check",
"user",
"data",
"and",
"if",
"valid",
"store",
"them",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/User/Providers/Memory/Memory.php#L48-L73
|
230,350
|
EdgedesignCZ/ares
|
Decorator/ProxyCurlDecorator.php
|
ProxyCurlDecorator.decorate
|
public function decorate($resource)
{
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt(
$resource,
CURLOPT_PROXY,
sprintf(
'%s:%s',
$this->proxyHost,
$this->proxyPort
)
);
if ($this->proxyUser && $this->proxyPassword) {
curl_setopt(
$resource,
CURLOPT_PROXYUSERPWD,
sprintf(
'%s:%s',
$this->proxyUser,
$this->proxyPassword
)
);
}
}
|
php
|
public function decorate($resource)
{
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt(
$resource,
CURLOPT_PROXY,
sprintf(
'%s:%s',
$this->proxyHost,
$this->proxyPort
)
);
if ($this->proxyUser && $this->proxyPassword) {
curl_setopt(
$resource,
CURLOPT_PROXYUSERPWD,
sprintf(
'%s:%s',
$this->proxyUser,
$this->proxyPassword
)
);
}
}
|
[
"public",
"function",
"decorate",
"(",
"$",
"resource",
")",
"{",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_FOLLOWLOCATION",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_PROXY",
",",
"sprintf",
"(",
"'%s:%s'",
",",
"$",
"this",
"->",
"proxyHost",
",",
"$",
"this",
"->",
"proxyPort",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"proxyUser",
"&&",
"$",
"this",
"->",
"proxyPassword",
")",
"{",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_PROXYUSERPWD",
",",
"sprintf",
"(",
"'%s:%s'",
",",
"$",
"this",
"->",
"proxyUser",
",",
"$",
"this",
"->",
"proxyPassword",
")",
")",
";",
"}",
"}"
] |
Sets up given cURL resource with desired parameters.
@param resource $resource
|
[
"Sets",
"up",
"given",
"cURL",
"resource",
"with",
"desired",
"parameters",
"."
] |
ae0f50155571875d09ba969e7b062854c823b57d
|
https://github.com/EdgedesignCZ/ares/blob/ae0f50155571875d09ba969e7b062854c823b57d/Decorator/ProxyCurlDecorator.php#L41-L65
|
230,351
|
Webiny/Framework
|
src/Webiny/Component/OAuth2/OAuth2User.php
|
OAuth2User.setGender
|
public function setGender($gender)
{
$gender = strtolower($gender);
if ($gender != '' && $gender != 'male' && $gender != 'female') {
throw new OAuth2Exception('Gender can be either "male" or "female", you tried to set it to "' . $gender . '".');
}
$this->gender = $gender;
}
|
php
|
public function setGender($gender)
{
$gender = strtolower($gender);
if ($gender != '' && $gender != 'male' && $gender != 'female') {
throw new OAuth2Exception('Gender can be either "male" or "female", you tried to set it to "' . $gender . '".');
}
$this->gender = $gender;
}
|
[
"public",
"function",
"setGender",
"(",
"$",
"gender",
")",
"{",
"$",
"gender",
"=",
"strtolower",
"(",
"$",
"gender",
")",
";",
"if",
"(",
"$",
"gender",
"!=",
"''",
"&&",
"$",
"gender",
"!=",
"'male'",
"&&",
"$",
"gender",
"!=",
"'female'",
")",
"{",
"throw",
"new",
"OAuth2Exception",
"(",
"'Gender can be either \"male\" or \"female\", you tried to set it to \"'",
".",
"$",
"gender",
".",
"'\".'",
")",
";",
"}",
"$",
"this",
"->",
"gender",
"=",
"$",
"gender",
";",
"}"
] |
Set the gender of the user, can be 'male' or 'female'.
@param $gender
@throws OAuth2Exception
|
[
"Set",
"the",
"gender",
"of",
"the",
"user",
"can",
"be",
"male",
"or",
"female",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/OAuth2/OAuth2User.php#L220-L229
|
230,352
|
Webiny/Framework
|
src/Webiny/Component/Router/Matcher/UrlMatcher.php
|
UrlMatcher.extractParameters
|
private function extractParameters($matches, CompiledRoute $compiledRoute)
{
$params = [];
foreach ($compiledRoute->getVariables() as $index => $var) {
$params[$var['name']] = $matches[($index + 1)][0];
}
return $params;
}
|
php
|
private function extractParameters($matches, CompiledRoute $compiledRoute)
{
$params = [];
foreach ($compiledRoute->getVariables() as $index => $var) {
$params[$var['name']] = $matches[($index + 1)][0];
}
return $params;
}
|
[
"private",
"function",
"extractParameters",
"(",
"$",
"matches",
",",
"CompiledRoute",
"$",
"compiledRoute",
")",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"compiledRoute",
"->",
"getVariables",
"(",
")",
"as",
"$",
"index",
"=>",
"$",
"var",
")",
"{",
"$",
"params",
"[",
"$",
"var",
"[",
"'name'",
"]",
"]",
"=",
"$",
"matches",
"[",
"(",
"$",
"index",
"+",
"1",
")",
"]",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"params",
";",
"}"
] |
Extracts and matches the parameters with their defined names.
@param $matches
@param CompiledRoute $compiledRoute
@return array
|
[
"Extracts",
"and",
"matches",
"the",
"parameters",
"with",
"their",
"defined",
"names",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Router/Matcher/UrlMatcher.php#L133-L141
|
230,353
|
clue/php-socket-react
|
src/Stream/Factory.php
|
Factory.createClient
|
public function createClient($address)
{
$that = $this;
$factory = $this->rawFactory;
return $this->resolve($address)->then(function ($address) use ($factory, $that){
$deferred = new Deferred();
$socket = $factory->createFromString($address, $scheme);
if ($socket->getType() !== SOCK_STREAM) {
$socket->close();
throw new Exception('Not a stream address scheme');
}
$socket->setBlocking(false);
try{
// socket is nonblocking, so connect should emit EINPROGRESS
$socket->connect($address);
// socket is already connected immediately?
$deferred->resolve(new Connection($socket, $that->getSocketLoop()));
}
catch(Exception $exception)
{
if ($exception->getCode() === SOCKET_EINPROGRESS) {
// connection in progress => wait for the socket to become writable
$that->getSocketLoop()->addWriteStream($socket->getResource(), function ($resource, $loop) use ($deferred, $socket){
// only poll for writable event once
$loop->removeWriteStream($resource);
try {
// assert that socket error is 0 (no TCP RST received)
$socket->assertAlive();
}
catch (Exception $e) {
// error returned => connected failed
$socket->close();
$deferred->reject(new Exception('Error while establishing connection' , $e->getCode(), $e));
return;
}
// no error => connection established
$deferred->resolve(new Connection($socket, $loop));
});
} else {
// re-throw any other socket error
$socket->close();
$deferred->reject($exception);
}
}
return $deferred->promise();
});
}
|
php
|
public function createClient($address)
{
$that = $this;
$factory = $this->rawFactory;
return $this->resolve($address)->then(function ($address) use ($factory, $that){
$deferred = new Deferred();
$socket = $factory->createFromString($address, $scheme);
if ($socket->getType() !== SOCK_STREAM) {
$socket->close();
throw new Exception('Not a stream address scheme');
}
$socket->setBlocking(false);
try{
// socket is nonblocking, so connect should emit EINPROGRESS
$socket->connect($address);
// socket is already connected immediately?
$deferred->resolve(new Connection($socket, $that->getSocketLoop()));
}
catch(Exception $exception)
{
if ($exception->getCode() === SOCKET_EINPROGRESS) {
// connection in progress => wait for the socket to become writable
$that->getSocketLoop()->addWriteStream($socket->getResource(), function ($resource, $loop) use ($deferred, $socket){
// only poll for writable event once
$loop->removeWriteStream($resource);
try {
// assert that socket error is 0 (no TCP RST received)
$socket->assertAlive();
}
catch (Exception $e) {
// error returned => connected failed
$socket->close();
$deferred->reject(new Exception('Error while establishing connection' , $e->getCode(), $e));
return;
}
// no error => connection established
$deferred->resolve(new Connection($socket, $loop));
});
} else {
// re-throw any other socket error
$socket->close();
$deferred->reject($exception);
}
}
return $deferred->promise();
});
}
|
[
"public",
"function",
"createClient",
"(",
"$",
"address",
")",
"{",
"$",
"that",
"=",
"$",
"this",
";",
"$",
"factory",
"=",
"$",
"this",
"->",
"rawFactory",
";",
"return",
"$",
"this",
"->",
"resolve",
"(",
"$",
"address",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"address",
")",
"use",
"(",
"$",
"factory",
",",
"$",
"that",
")",
"{",
"$",
"deferred",
"=",
"new",
"Deferred",
"(",
")",
";",
"$",
"socket",
"=",
"$",
"factory",
"->",
"createFromString",
"(",
"$",
"address",
",",
"$",
"scheme",
")",
";",
"if",
"(",
"$",
"socket",
"->",
"getType",
"(",
")",
"!==",
"SOCK_STREAM",
")",
"{",
"$",
"socket",
"->",
"close",
"(",
")",
";",
"throw",
"new",
"Exception",
"(",
"'Not a stream address scheme'",
")",
";",
"}",
"$",
"socket",
"->",
"setBlocking",
"(",
"false",
")",
";",
"try",
"{",
"// socket is nonblocking, so connect should emit EINPROGRESS",
"$",
"socket",
"->",
"connect",
"(",
"$",
"address",
")",
";",
"// socket is already connected immediately?",
"$",
"deferred",
"->",
"resolve",
"(",
"new",
"Connection",
"(",
"$",
"socket",
",",
"$",
"that",
"->",
"getSocketLoop",
"(",
")",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"if",
"(",
"$",
"exception",
"->",
"getCode",
"(",
")",
"===",
"SOCKET_EINPROGRESS",
")",
"{",
"// connection in progress => wait for the socket to become writable",
"$",
"that",
"->",
"getSocketLoop",
"(",
")",
"->",
"addWriteStream",
"(",
"$",
"socket",
"->",
"getResource",
"(",
")",
",",
"function",
"(",
"$",
"resource",
",",
"$",
"loop",
")",
"use",
"(",
"$",
"deferred",
",",
"$",
"socket",
")",
"{",
"// only poll for writable event once",
"$",
"loop",
"->",
"removeWriteStream",
"(",
"$",
"resource",
")",
";",
"try",
"{",
"// assert that socket error is 0 (no TCP RST received)",
"$",
"socket",
"->",
"assertAlive",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// error returned => connected failed",
"$",
"socket",
"->",
"close",
"(",
")",
";",
"$",
"deferred",
"->",
"reject",
"(",
"new",
"Exception",
"(",
"'Error while establishing connection'",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"return",
";",
"}",
"// no error => connection established",
"$",
"deferred",
"->",
"resolve",
"(",
"new",
"Connection",
"(",
"$",
"socket",
",",
"$",
"loop",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"// re-throw any other socket error",
"$",
"socket",
"->",
"close",
"(",
")",
";",
"$",
"deferred",
"->",
"reject",
"(",
"$",
"exception",
")",
";",
"}",
"}",
"return",
"$",
"deferred",
"->",
"promise",
"(",
")",
";",
"}",
")",
";",
"}"
] |
create stream client socket connected to given address
@param string $address
@return PromiseInterface to return a \Sockets\Stream
@uses RawFactory::createFromString()
@uses RawSocket::setBlocking() to turn on non-blocking mode
@uses RawSocket::connect() to initiate async connection
@uses LoopInterface::addWriteStream() to wait for connection result once
@uses RawSocket::assertAlive() to check connection result
|
[
"create",
"stream",
"client",
"socket",
"connected",
"to",
"given",
"address"
] |
420dcbc20e8b007a7df2a12373af94b0b70ec15e
|
https://github.com/clue/php-socket-react/blob/420dcbc20e8b007a7df2a12373af94b0b70ec15e/src/Stream/Factory.php#L36-L90
|
230,354
|
clue/php-socket-react
|
src/Stream/Factory.php
|
Factory.createServer
|
public function createServer($address)
{
return $this->resolve($address)->then(function ($address) {
$server = new Server($this->getSocketLoop(), $this->rawFactory);
$server->listenAddress($address);
return $server;
});
}
|
php
|
public function createServer($address)
{
return $this->resolve($address)->then(function ($address) {
$server = new Server($this->getSocketLoop(), $this->rawFactory);
$server->listenAddress($address);
return $server;
});
}
|
[
"public",
"function",
"createServer",
"(",
"$",
"address",
")",
"{",
"return",
"$",
"this",
"->",
"resolve",
"(",
"$",
"address",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"address",
")",
"{",
"$",
"server",
"=",
"new",
"Server",
"(",
"$",
"this",
"->",
"getSocketLoop",
"(",
")",
",",
"$",
"this",
"->",
"rawFactory",
")",
";",
"$",
"server",
"->",
"listenAddress",
"(",
"$",
"address",
")",
";",
"return",
"$",
"server",
";",
"}",
")",
";",
"}"
] |
create stream server socket bound to and listening on the given address for incomming stream client connections
@param string $address
@return PromiseInterface to return a \Sockets\Server
@throws Exception on error
@uses Server::listenAddress()
|
[
"create",
"stream",
"server",
"socket",
"bound",
"to",
"and",
"listening",
"on",
"the",
"given",
"address",
"for",
"incomming",
"stream",
"client",
"connections"
] |
420dcbc20e8b007a7df2a12373af94b0b70ec15e
|
https://github.com/clue/php-socket-react/blob/420dcbc20e8b007a7df2a12373af94b0b70ec15e/src/Stream/Factory.php#L100-L108
|
230,355
|
clue/php-socket-react
|
src/Stream/Factory.php
|
Factory.getSocketLoop
|
public function getSocketLoop()
{
if ($this->socketLoop === null) {
if ($this->loop instanceof StreamSelectLoop) {
$this->socketLoop = new SelectPoller($this->loop);
} else {
$this->socketLoop = $this->loop;
}
}
return $this->socketLoop;
}
|
php
|
public function getSocketLoop()
{
if ($this->socketLoop === null) {
if ($this->loop instanceof StreamSelectLoop) {
$this->socketLoop = new SelectPoller($this->loop);
} else {
$this->socketLoop = $this->loop;
}
}
return $this->socketLoop;
}
|
[
"public",
"function",
"getSocketLoop",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"socketLoop",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"loop",
"instanceof",
"StreamSelectLoop",
")",
"{",
"$",
"this",
"->",
"socketLoop",
"=",
"new",
"SelectPoller",
"(",
"$",
"this",
"->",
"loop",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"socketLoop",
"=",
"$",
"this",
"->",
"loop",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"socketLoop",
";",
"}"
] |
return a loop interface that supports adding socket resources
@return LoopInterface
|
[
"return",
"a",
"loop",
"interface",
"that",
"supports",
"adding",
"socket",
"resources"
] |
420dcbc20e8b007a7df2a12373af94b0b70ec15e
|
https://github.com/clue/php-socket-react/blob/420dcbc20e8b007a7df2a12373af94b0b70ec15e/src/Stream/Factory.php#L115-L125
|
230,356
|
deanblackborough/zf3-view-helpers
|
src/Bootstrap4Alert.php
|
Bootstrap4Alert.setHeading
|
public function setHeading(string $heading, int $heading_level = 4) : Bootstrap4Alert
{
$this->heading = $heading;
$this->heading_level = $heading_level;
return $this;
}
|
php
|
public function setHeading(string $heading, int $heading_level = 4) : Bootstrap4Alert
{
$this->heading = $heading;
$this->heading_level = $heading_level;
return $this;
}
|
[
"public",
"function",
"setHeading",
"(",
"string",
"$",
"heading",
",",
"int",
"$",
"heading_level",
"=",
"4",
")",
":",
"Bootstrap4Alert",
"{",
"$",
"this",
"->",
"heading",
"=",
"$",
"heading",
";",
"$",
"this",
"->",
"heading_level",
"=",
"$",
"heading_level",
";",
"return",
"$",
"this",
";",
"}"
] |
Set an optional heading for the alert
@param string $heading
@param integer $heading_level Optional heading level, 1-7 defaults to 4
@return Bootstrap4Alert
|
[
"Set",
"an",
"optional",
"heading",
"for",
"the",
"alert"
] |
db8bea4ca62709b2ac8c732aedbb2a5235223f23
|
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Alert.php#L70-L76
|
230,357
|
deanblackborough/zf3-view-helpers
|
src/Bootstrap4Alert.php
|
Bootstrap4Alert.classes
|
private function classes(): string
{
$classes = 'alert';
if ($this->bg_color !== null) {
$classes .= ' alert-' . $this->bg_color;
}
if ($this->text_color !== null) {
$classes .= ' text-' . $this->text_color;
}
return $classes;
}
|
php
|
private function classes(): string
{
$classes = 'alert';
if ($this->bg_color !== null) {
$classes .= ' alert-' . $this->bg_color;
}
if ($this->text_color !== null) {
$classes .= ' text-' . $this->text_color;
}
return $classes;
}
|
[
"private",
"function",
"classes",
"(",
")",
":",
"string",
"{",
"$",
"classes",
"=",
"'alert'",
";",
"if",
"(",
"$",
"this",
"->",
"bg_color",
"!==",
"null",
")",
"{",
"$",
"classes",
".=",
"' alert-'",
".",
"$",
"this",
"->",
"bg_color",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"text_color",
"!==",
"null",
")",
"{",
"$",
"classes",
".=",
"' text-'",
".",
"$",
"this",
"->",
"text_color",
";",
"}",
"return",
"$",
"classes",
";",
"}"
] |
Generate the classes for the alert component based on the set options
@return string
|
[
"Generate",
"the",
"classes",
"for",
"the",
"alert",
"component",
"based",
"on",
"the",
"set",
"options"
] |
db8bea4ca62709b2ac8c732aedbb2a5235223f23
|
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4Alert.php#L116-L129
|
230,358
|
Webiny/Framework
|
src/Webiny/Component/TwitterOAuth/Bridge/League/TwitterOAuth.php
|
TwitterOAuth.getUserDetails
|
public function getUserDetails()
{
$accessToken = $this->getAccessToken();
$tc = new TokenCredentials();
$tc->setIdentifier($accessToken['oauth_token']);
$tc->setSecret($accessToken['oauth_token_secret']);
$user = $this->instance->getUserDetails($tc);
$twUserObj = new TwitterOAuthUser($user->nickname);
$twUserObj->setAvatarUrl($user->imageUrl);
$twUserObj->setName($user->name);
$twUserObj->setLocation($user->location);
$twUserObj->setProfileUrl('https://twitter.com/' . $user->screen_name);
$twUserObj->setWebsite($user->urls['url']);
$twUserObj->setDescription($user->description);
$twUserObj->setProfileId($user->uid);
return $twUserObj;
}
|
php
|
public function getUserDetails()
{
$accessToken = $this->getAccessToken();
$tc = new TokenCredentials();
$tc->setIdentifier($accessToken['oauth_token']);
$tc->setSecret($accessToken['oauth_token_secret']);
$user = $this->instance->getUserDetails($tc);
$twUserObj = new TwitterOAuthUser($user->nickname);
$twUserObj->setAvatarUrl($user->imageUrl);
$twUserObj->setName($user->name);
$twUserObj->setLocation($user->location);
$twUserObj->setProfileUrl('https://twitter.com/' . $user->screen_name);
$twUserObj->setWebsite($user->urls['url']);
$twUserObj->setDescription($user->description);
$twUserObj->setProfileId($user->uid);
return $twUserObj;
}
|
[
"public",
"function",
"getUserDetails",
"(",
")",
"{",
"$",
"accessToken",
"=",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
";",
"$",
"tc",
"=",
"new",
"TokenCredentials",
"(",
")",
";",
"$",
"tc",
"->",
"setIdentifier",
"(",
"$",
"accessToken",
"[",
"'oauth_token'",
"]",
")",
";",
"$",
"tc",
"->",
"setSecret",
"(",
"$",
"accessToken",
"[",
"'oauth_token_secret'",
"]",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"instance",
"->",
"getUserDetails",
"(",
"$",
"tc",
")",
";",
"$",
"twUserObj",
"=",
"new",
"TwitterOAuthUser",
"(",
"$",
"user",
"->",
"nickname",
")",
";",
"$",
"twUserObj",
"->",
"setAvatarUrl",
"(",
"$",
"user",
"->",
"imageUrl",
")",
";",
"$",
"twUserObj",
"->",
"setName",
"(",
"$",
"user",
"->",
"name",
")",
";",
"$",
"twUserObj",
"->",
"setLocation",
"(",
"$",
"user",
"->",
"location",
")",
";",
"$",
"twUserObj",
"->",
"setProfileUrl",
"(",
"'https://twitter.com/'",
".",
"$",
"user",
"->",
"screen_name",
")",
";",
"$",
"twUserObj",
"->",
"setWebsite",
"(",
"$",
"user",
"->",
"urls",
"[",
"'url'",
"]",
")",
";",
"$",
"twUserObj",
"->",
"setDescription",
"(",
"$",
"user",
"->",
"description",
")",
";",
"$",
"twUserObj",
"->",
"setProfileId",
"(",
"$",
"user",
"->",
"uid",
")",
";",
"return",
"$",
"twUserObj",
";",
"}"
] |
Returns an instance of TwitterOAuthUser.
@return TwitterOAuthUser
|
[
"Returns",
"an",
"instance",
"of",
"TwitterOAuthUser",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TwitterOAuth/Bridge/League/TwitterOAuth.php#L183-L202
|
230,359
|
Webiny/Framework
|
src/Webiny/Component/TwitterOAuth/Bridge/League/TwitterOAuth.php
|
TwitterOAuth.get
|
public function get($url, array $headers = [], array $params = [])
{
return $this->instance->createHttpClient()->get($url, $headers, $params);
}
|
php
|
public function get($url, array $headers = [], array $params = [])
{
return $this->instance->createHttpClient()->get($url, $headers, $params);
}
|
[
"public",
"function",
"get",
"(",
"$",
"url",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"instance",
"->",
"createHttpClient",
"(",
")",
"->",
"get",
"(",
"$",
"url",
",",
"$",
"headers",
",",
"$",
"params",
")",
";",
"}"
] |
Make a GET request to Twitter API.
@param string $url Api url.
@param array $headers Request headers.
@param array $params Additional parameters.
@return string|array Api response (if json) it will be returned as array.
|
[
"Make",
"a",
"GET",
"request",
"to",
"Twitter",
"API",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TwitterOAuth/Bridge/League/TwitterOAuth.php#L213-L216
|
230,360
|
Webiny/Framework
|
src/Webiny/Component/TwitterOAuth/Bridge/League/TwitterOAuth.php
|
TwitterOAuth.post
|
public function post($url, array $postBody, array $headers = [], array $params = [])
{
return $this->instance->createHttpClient()->post($url, $headers, $postBody, $params);
}
|
php
|
public function post($url, array $postBody, array $headers = [], array $params = [])
{
return $this->instance->createHttpClient()->post($url, $headers, $postBody, $params);
}
|
[
"public",
"function",
"post",
"(",
"$",
"url",
",",
"array",
"$",
"postBody",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"instance",
"->",
"createHttpClient",
"(",
")",
"->",
"post",
"(",
"$",
"url",
",",
"$",
"headers",
",",
"$",
"postBody",
",",
"$",
"params",
")",
";",
"}"
] |
Make a POST request to Twitter API.
@param string $url Api url.
@param array $postBody Post body.
@param array $headers Request headers.
@param array $params Additional parameters.
@return string|array Api response (if json) it will be returned as array.
|
[
"Make",
"a",
"POST",
"request",
"to",
"Twitter",
"API",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TwitterOAuth/Bridge/League/TwitterOAuth.php#L228-L231
|
230,361
|
Webiny/Framework
|
src/Webiny/Component/TwitterOAuth/Bridge/League/TwitterOAuth.php
|
TwitterOAuth.delete
|
public function delete($url, array $headers = [], array $params = [])
{
return $this->instance->createHttpClient()->delete($url, $headers, $params);
}
|
php
|
public function delete($url, array $headers = [], array $params = [])
{
return $this->instance->createHttpClient()->delete($url, $headers, $params);
}
|
[
"public",
"function",
"delete",
"(",
"$",
"url",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"instance",
"->",
"createHttpClient",
"(",
")",
"->",
"delete",
"(",
"$",
"url",
",",
"$",
"headers",
",",
"$",
"params",
")",
";",
"}"
] |
Make a DELETE request to Twitter API.
@param string $url Api url.
@param array $headers Request headers.
@param array $params Additional parameters.
@return string|array Api response (if json) it will be returned as array.
|
[
"Make",
"a",
"DELETE",
"request",
"to",
"Twitter",
"API",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TwitterOAuth/Bridge/League/TwitterOAuth.php#L242-L245
|
230,362
|
Webiny/Framework
|
src/Webiny/Component/Cache/Storage/SessionArray.php
|
SessionArray.save
|
public function save($key, $value, $ttl = 600, $tags = null)
{
$this->cache[md5($key)] = $value;
if (is_array($tags)) {
foreach ($tags as $t) {
$this->tags[$t][] = $key;
}
}
return true;
}
|
php
|
public function save($key, $value, $ttl = 600, $tags = null)
{
$this->cache[md5($key)] = $value;
if (is_array($tags)) {
foreach ($tags as $t) {
$this->tags[$t][] = $key;
}
}
return true;
}
|
[
"public",
"function",
"save",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"ttl",
"=",
"600",
",",
"$",
"tags",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"cache",
"[",
"md5",
"(",
"$",
"key",
")",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"is_array",
"(",
"$",
"tags",
")",
")",
"{",
"foreach",
"(",
"$",
"tags",
"as",
"$",
"t",
")",
"{",
"$",
"this",
"->",
"tags",
"[",
"$",
"t",
"]",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Save a value into memory.
@param string $key Name of the key.
@param mixed $value Value you wish to save.
@param int $ttl For how long to store value. (in seconds)
@param array|string $tags Tags you wish to assign to this cache entry.
@return bool True if value was stored successfully, otherwise false.
|
[
"Save",
"a",
"value",
"into",
"memory",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Cache/Storage/SessionArray.php#L62-L73
|
230,363
|
Webiny/Framework
|
src/Webiny/Component/Cache/Storage/SessionArray.php
|
SessionArray.deleteByTags
|
public function deleteByTags($tag)
{
if (!isset($this->tags[$tag])) {
return false;
}
foreach ($this->tags[$tag] as $key) {
$this->delete($key);
}
return true;
}
|
php
|
public function deleteByTags($tag)
{
if (!isset($this->tags[$tag])) {
return false;
}
foreach ($this->tags[$tag] as $key) {
$this->delete($key);
}
return true;
}
|
[
"public",
"function",
"deleteByTags",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"]",
"as",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"delete",
"(",
"$",
"key",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Delete keys by tags.
@param array|string $tag Tag, or an array of tags, for which you wish to delete the cache.
@return boolean
|
[
"Delete",
"keys",
"by",
"tags",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Cache/Storage/SessionArray.php#L131-L142
|
230,364
|
Webiny/Framework
|
src/Webiny/Component/TwitterOAuth/Bridge/TwitterOAuth.php
|
TwitterOAuth.getInstance
|
public static function getInstance($clientId, $clientSecret, $redirectUri)
{
$driver = static::getLibrary();
try {
$instance = new $driver($clientId, $clientSecret, $redirectUri);
} catch (\Exception $e) {
throw new TwitterOAuthException('Unable to create an instance of ' . $driver);
}
if (!self::isInstanceOf($instance, TwitterOAuthInterface::class)) {
throw new TwitterOAuthException(TwitterOAuthException::MSG_INVALID_ARG, ['driver', TwitterOAuthInterface::class]);
}
return $instance;
}
|
php
|
public static function getInstance($clientId, $clientSecret, $redirectUri)
{
$driver = static::getLibrary();
try {
$instance = new $driver($clientId, $clientSecret, $redirectUri);
} catch (\Exception $e) {
throw new TwitterOAuthException('Unable to create an instance of ' . $driver);
}
if (!self::isInstanceOf($instance, TwitterOAuthInterface::class)) {
throw new TwitterOAuthException(TwitterOAuthException::MSG_INVALID_ARG, ['driver', TwitterOAuthInterface::class]);
}
return $instance;
}
|
[
"public",
"static",
"function",
"getInstance",
"(",
"$",
"clientId",
",",
"$",
"clientSecret",
",",
"$",
"redirectUri",
")",
"{",
"$",
"driver",
"=",
"static",
"::",
"getLibrary",
"(",
")",
";",
"try",
"{",
"$",
"instance",
"=",
"new",
"$",
"driver",
"(",
"$",
"clientId",
",",
"$",
"clientSecret",
",",
"$",
"redirectUri",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"TwitterOAuthException",
"(",
"'Unable to create an instance of '",
".",
"$",
"driver",
")",
";",
"}",
"if",
"(",
"!",
"self",
"::",
"isInstanceOf",
"(",
"$",
"instance",
",",
"TwitterOAuthInterface",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"TwitterOAuthException",
"(",
"TwitterOAuthException",
"::",
"MSG_INVALID_ARG",
",",
"[",
"'driver'",
",",
"TwitterOAuthInterface",
"::",
"class",
"]",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
Create an instance of an TwitterOAuth driver.
@param string $clientId Client id.
@param string $clientSecret Client secret.
@param string $redirectUri Target url where to redirect after authentication.
@throws TwitterOAuthException
@return TwitterOAuthInterface
|
[
"Create",
"an",
"instance",
"of",
"an",
"TwitterOAuth",
"driver",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/TwitterOAuth/Bridge/TwitterOAuth.php#L59-L74
|
230,365
|
takatost/wechat_open_platform
|
src/Server/Server.php
|
Server.serve
|
public function serve()
{
Log::debug('Request received:', [
'Method' => $this->request->getMethod(),
'URI' => $this->request->getRequestUri(),
'Query' => $this->request->getQueryString(),
'Protocal' => $this->request->server->get('SERVER_PROTOCOL'),
'Content' => $this->request->getContent(),
]);
$result = $this->handleRequest();
$response = $this->buildResponse($result['response']);
Log::debug('Server response created:', compact('response'));
return new Response($response);
}
|
php
|
public function serve()
{
Log::debug('Request received:', [
'Method' => $this->request->getMethod(),
'URI' => $this->request->getRequestUri(),
'Query' => $this->request->getQueryString(),
'Protocal' => $this->request->server->get('SERVER_PROTOCOL'),
'Content' => $this->request->getContent(),
]);
$result = $this->handleRequest();
$response = $this->buildResponse($result['response']);
Log::debug('Server response created:', compact('response'));
return new Response($response);
}
|
[
"public",
"function",
"serve",
"(",
")",
"{",
"Log",
"::",
"debug",
"(",
"'Request received:'",
",",
"[",
"'Method'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getMethod",
"(",
")",
",",
"'URI'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getRequestUri",
"(",
")",
",",
"'Query'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getQueryString",
"(",
")",
",",
"'Protocal'",
"=>",
"$",
"this",
"->",
"request",
"->",
"server",
"->",
"get",
"(",
"'SERVER_PROTOCOL'",
")",
",",
"'Content'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getContent",
"(",
")",
",",
"]",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"handleRequest",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"buildResponse",
"(",
"$",
"result",
"[",
"'response'",
"]",
")",
";",
"Log",
"::",
"debug",
"(",
"'Server response created:'",
",",
"compact",
"(",
"'response'",
")",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"response",
")",
";",
"}"
] |
Handle and return response.
@return Response
@throws BadRequestException
|
[
"Handle",
"and",
"return",
"response",
"."
] |
e3173f529236f6203a0d8f85ee20f4486183a85e
|
https://github.com/takatost/wechat_open_platform/blob/e3173f529236f6203a0d8f85ee20f4486183a85e/src/Server/Server.php#L93-L110
|
230,366
|
takatost/wechat_open_platform
|
src/Server/Server.php
|
Server.handleMessage
|
protected function handleMessage($message)
{
$handler = $this->messageHandler;
if (!is_callable($handler)) {
Log::debug('No handler enabled.');
return null;
}
Log::debug('Message detail:', $message->all());
$type = $this->messageTypeMapping[ $message->get('InfoType') ];
$response = null;
if ($type) {
$response = call_user_func_array($handler, [$message]);
}
return $response;
}
|
php
|
protected function handleMessage($message)
{
$handler = $this->messageHandler;
if (!is_callable($handler)) {
Log::debug('No handler enabled.');
return null;
}
Log::debug('Message detail:', $message->all());
$type = $this->messageTypeMapping[ $message->get('InfoType') ];
$response = null;
if ($type) {
$response = call_user_func_array($handler, [$message]);
}
return $response;
}
|
[
"protected",
"function",
"handleMessage",
"(",
"$",
"message",
")",
"{",
"$",
"handler",
"=",
"$",
"this",
"->",
"messageHandler",
";",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"handler",
")",
")",
"{",
"Log",
"::",
"debug",
"(",
"'No handler enabled.'",
")",
";",
"return",
"null",
";",
"}",
"Log",
"::",
"debug",
"(",
"'Message detail:'",
",",
"$",
"message",
"->",
"all",
"(",
")",
")",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"messageTypeMapping",
"[",
"$",
"message",
"->",
"get",
"(",
"'InfoType'",
")",
"]",
";",
"$",
"response",
"=",
"null",
";",
"if",
"(",
"$",
"type",
")",
"{",
"$",
"response",
"=",
"call_user_func_array",
"(",
"$",
"handler",
",",
"[",
"$",
"message",
"]",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Handle message.
@param Collection $message
@return mixed
|
[
"Handle",
"message",
"."
] |
e3173f529236f6203a0d8f85ee20f4486183a85e
|
https://github.com/takatost/wechat_open_platform/blob/e3173f529236f6203a0d8f85ee20f4486183a85e/src/Server/Server.php#L154-L175
|
230,367
|
themsaid/katana-core
|
src/Markdown.php
|
Markdown.parseWithYAML
|
public static function parseWithYAML($text)
{
$parser = new Parser();
$parsed = $parser->parse($text);
return [$parsed->getContent(), $parsed->getYAML()];
}
|
php
|
public static function parseWithYAML($text)
{
$parser = new Parser();
$parsed = $parser->parse($text);
return [$parsed->getContent(), $parsed->getYAML()];
}
|
[
"public",
"static",
"function",
"parseWithYAML",
"(",
"$",
"text",
")",
"{",
"$",
"parser",
"=",
"new",
"Parser",
"(",
")",
";",
"$",
"parsed",
"=",
"$",
"parser",
"->",
"parse",
"(",
"$",
"text",
")",
";",
"return",
"[",
"$",
"parsed",
"->",
"getContent",
"(",
")",
",",
"$",
"parsed",
"->",
"getYAML",
"(",
")",
"]",
";",
"}"
] |
Parse markdown with YAML headers
This method returns an array of: content as the first member and
YAML values as the second member.
@param string $text
@return array
|
[
"Parse",
"markdown",
"with",
"YAML",
"headers"
] |
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
|
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/Markdown.php#L35-L42
|
230,368
|
themsaid/katana-core
|
src/Markdown.php
|
Markdown.cleanLeadingSpace
|
protected static function cleanLeadingSpace($text)
{
$i = 0;
while (! $firstLine = explode("\n", $text)[$i]) {
$i ++;
}
preg_match('/^( *)/', $firstLine, $matches);
return preg_replace('/^[ ]{'.strlen($matches[1]).'}/m', '', $text);
}
|
php
|
protected static function cleanLeadingSpace($text)
{
$i = 0;
while (! $firstLine = explode("\n", $text)[$i]) {
$i ++;
}
preg_match('/^( *)/', $firstLine, $matches);
return preg_replace('/^[ ]{'.strlen($matches[1]).'}/m', '', $text);
}
|
[
"protected",
"static",
"function",
"cleanLeadingSpace",
"(",
"$",
"text",
")",
"{",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"!",
"$",
"firstLine",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"text",
")",
"[",
"$",
"i",
"]",
")",
"{",
"$",
"i",
"++",
";",
"}",
"preg_match",
"(",
"'/^( *)/'",
",",
"$",
"firstLine",
",",
"$",
"matches",
")",
";",
"return",
"preg_replace",
"(",
"'/^[ ]{'",
".",
"strlen",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
".",
"'}/m'",
",",
"''",
",",
"$",
"text",
")",
";",
"}"
] |
Remove initial leading space from each line
Since @markdown can be placed inside any HTML element, there might
be leading space due to code editor indentation, here we trim it
to avoid compiling the whole markdown block as a code block.
@param $text
@return string
|
[
"Remove",
"initial",
"leading",
"space",
"from",
"each",
"line"
] |
897c1adb6863d5145f1f104cbc8c9200cd98c3fb
|
https://github.com/themsaid/katana-core/blob/897c1adb6863d5145f1f104cbc8c9200cd98c3fb/src/Markdown.php#L55-L66
|
230,369
|
alexandresalome/php-webdriver
|
src/WebDriver/Cookie.php
|
Cookie.fromArray
|
static public function fromArray(array $array)
{
$name = $array['name'];
$value = $array['value'];
$path = isset($array['path']) ? $array['path'] : null;
$domain = isset($array['domain']) ? $array['domain'] : null;
$isSecure = isset($array['secure']) ? $array['secure'] : null;
$expiry = isset($array['expiry']) ? \DateTime::createFromFormat('U', $array['expiry']) : null;
if (false === $expiry) {
throw new \InvalidArgumentException(sprintf('Unable to parse cookie expiry: "%s".', $array['expiry']));
}
return new self($name, $value, $path, $domain, $isSecure, $expiry);
}
|
php
|
static public function fromArray(array $array)
{
$name = $array['name'];
$value = $array['value'];
$path = isset($array['path']) ? $array['path'] : null;
$domain = isset($array['domain']) ? $array['domain'] : null;
$isSecure = isset($array['secure']) ? $array['secure'] : null;
$expiry = isset($array['expiry']) ? \DateTime::createFromFormat('U', $array['expiry']) : null;
if (false === $expiry) {
throw new \InvalidArgumentException(sprintf('Unable to parse cookie expiry: "%s".', $array['expiry']));
}
return new self($name, $value, $path, $domain, $isSecure, $expiry);
}
|
[
"static",
"public",
"function",
"fromArray",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"name",
"=",
"$",
"array",
"[",
"'name'",
"]",
";",
"$",
"value",
"=",
"$",
"array",
"[",
"'value'",
"]",
";",
"$",
"path",
"=",
"isset",
"(",
"$",
"array",
"[",
"'path'",
"]",
")",
"?",
"$",
"array",
"[",
"'path'",
"]",
":",
"null",
";",
"$",
"domain",
"=",
"isset",
"(",
"$",
"array",
"[",
"'domain'",
"]",
")",
"?",
"$",
"array",
"[",
"'domain'",
"]",
":",
"null",
";",
"$",
"isSecure",
"=",
"isset",
"(",
"$",
"array",
"[",
"'secure'",
"]",
")",
"?",
"$",
"array",
"[",
"'secure'",
"]",
":",
"null",
";",
"$",
"expiry",
"=",
"isset",
"(",
"$",
"array",
"[",
"'expiry'",
"]",
")",
"?",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"'U'",
",",
"$",
"array",
"[",
"'expiry'",
"]",
")",
":",
"null",
";",
"if",
"(",
"false",
"===",
"$",
"expiry",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unable to parse cookie expiry: \"%s\".'",
",",
"$",
"array",
"[",
"'expiry'",
"]",
")",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"path",
",",
"$",
"domain",
",",
"$",
"isSecure",
",",
"$",
"expiry",
")",
";",
"}"
] |
Creates a Cookie from an array.
@param array $array the array to load from
@return Cookie a cookie object
|
[
"Creates",
"a",
"Cookie",
"from",
"an",
"array",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Cookie.php#L75-L89
|
230,370
|
alexandresalome/php-webdriver
|
src/WebDriver/Cookie.php
|
Cookie.toArray
|
public function toArray()
{
return array(
'name' => $this->name,
'value' => $this->value,
'path' => $this->path,
'domain' => $this->domain,
'secure' => $this->isSecure,
'expiry' => null === $this->expiry ? null : $this->expiry->getTimestamp()
);
}
|
php
|
public function toArray()
{
return array(
'name' => $this->name,
'value' => $this->value,
'path' => $this->path,
'domain' => $this->domain,
'secure' => $this->isSecure,
'expiry' => null === $this->expiry ? null : $this->expiry->getTimestamp()
);
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"array",
"(",
"'name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'value'",
"=>",
"$",
"this",
"->",
"value",
",",
"'path'",
"=>",
"$",
"this",
"->",
"path",
",",
"'domain'",
"=>",
"$",
"this",
"->",
"domain",
",",
"'secure'",
"=>",
"$",
"this",
"->",
"isSecure",
",",
"'expiry'",
"=>",
"null",
"===",
"$",
"this",
"->",
"expiry",
"?",
"null",
":",
"$",
"this",
"->",
"expiry",
"->",
"getTimestamp",
"(",
")",
")",
";",
"}"
] |
Converts the cookie to an array.
@return array
|
[
"Converts",
"the",
"cookie",
"to",
"an",
"array",
"."
] |
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
|
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Cookie.php#L96-L106
|
230,371
|
Webiny/Framework
|
src/Webiny/Component/Rest/Parser/ClassParser.php
|
ClassParser.parseClass
|
private function parseClass()
{
// check which interfaces are implemented
$interfaces = [];
foreach ($this->parentClasses as $pc) {
$interfaces = array_merge($interfaces,
$pc->getInterfaceNames()); // returns only the interfaces that the current class implements
}
$interfaces = array_unique($interfaces);
foreach ($interfaces as $i) {
if ($i == AccessInterface::class) {
$this->parsedClass->accessInterface = true;
}
if ($i == CacheKeyInterface::class) {
$this->parsedClass->cacheKeyInterface = true;
}
}
}
|
php
|
private function parseClass()
{
// check which interfaces are implemented
$interfaces = [];
foreach ($this->parentClasses as $pc) {
$interfaces = array_merge($interfaces,
$pc->getInterfaceNames()); // returns only the interfaces that the current class implements
}
$interfaces = array_unique($interfaces);
foreach ($interfaces as $i) {
if ($i == AccessInterface::class) {
$this->parsedClass->accessInterface = true;
}
if ($i == CacheKeyInterface::class) {
$this->parsedClass->cacheKeyInterface = true;
}
}
}
|
[
"private",
"function",
"parseClass",
"(",
")",
"{",
"// check which interfaces are implemented",
"$",
"interfaces",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"parentClasses",
"as",
"$",
"pc",
")",
"{",
"$",
"interfaces",
"=",
"array_merge",
"(",
"$",
"interfaces",
",",
"$",
"pc",
"->",
"getInterfaceNames",
"(",
")",
")",
";",
"// returns only the interfaces that the current class implements",
"}",
"$",
"interfaces",
"=",
"array_unique",
"(",
"$",
"interfaces",
")",
";",
"foreach",
"(",
"$",
"interfaces",
"as",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"i",
"==",
"AccessInterface",
"::",
"class",
")",
"{",
"$",
"this",
"->",
"parsedClass",
"->",
"accessInterface",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"i",
"==",
"CacheKeyInterface",
"::",
"class",
")",
"{",
"$",
"this",
"->",
"parsedClass",
"->",
"cacheKeyInterface",
"=",
"true",
";",
"}",
"}",
"}"
] |
Internal method that does the actual parsing of class properties.
|
[
"Internal",
"method",
"that",
"does",
"the",
"actual",
"parsing",
"of",
"class",
"properties",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/ClassParser.php#L96-L115
|
230,372
|
Webiny/Framework
|
src/Webiny/Component/Rest/Parser/ClassParser.php
|
ClassParser.parseMethods
|
private function parseMethods()
{
$methods = $this->reflectionClass->getMethods(); // this still returns the methods for all parent classes
if (!is_array($methods) || count($methods) < 1) {
throw new RestException('Parser: The class "' . $this->class . '" doesn\'t have any methods defined.');
}
foreach ($methods as $m) {
if ($m->isPublic()) {
$methodParser = new MethodParser($this->parentClasses, $m, $this->normalize);
$parsedMethod = $methodParser->parse();
if ($parsedMethod) {
$this->parsedClass->addApiMethod($parsedMethod);
}
}
}
}
|
php
|
private function parseMethods()
{
$methods = $this->reflectionClass->getMethods(); // this still returns the methods for all parent classes
if (!is_array($methods) || count($methods) < 1) {
throw new RestException('Parser: The class "' . $this->class . '" doesn\'t have any methods defined.');
}
foreach ($methods as $m) {
if ($m->isPublic()) {
$methodParser = new MethodParser($this->parentClasses, $m, $this->normalize);
$parsedMethod = $methodParser->parse();
if ($parsedMethod) {
$this->parsedClass->addApiMethod($parsedMethod);
}
}
}
}
|
[
"private",
"function",
"parseMethods",
"(",
")",
"{",
"$",
"methods",
"=",
"$",
"this",
"->",
"reflectionClass",
"->",
"getMethods",
"(",
")",
";",
"// this still returns the methods for all parent classes",
"if",
"(",
"!",
"is_array",
"(",
"$",
"methods",
")",
"||",
"count",
"(",
"$",
"methods",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'Parser: The class \"'",
".",
"$",
"this",
"->",
"class",
".",
"'\" doesn\\'t have any methods defined.'",
")",
";",
"}",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"m",
")",
"{",
"if",
"(",
"$",
"m",
"->",
"isPublic",
"(",
")",
")",
"{",
"$",
"methodParser",
"=",
"new",
"MethodParser",
"(",
"$",
"this",
"->",
"parentClasses",
",",
"$",
"m",
",",
"$",
"this",
"->",
"normalize",
")",
";",
"$",
"parsedMethod",
"=",
"$",
"methodParser",
"->",
"parse",
"(",
")",
";",
"if",
"(",
"$",
"parsedMethod",
")",
"{",
"$",
"this",
"->",
"parsedClass",
"->",
"addApiMethod",
"(",
"$",
"parsedMethod",
")",
";",
"}",
"}",
"}",
"}"
] |
Parsed the class methods and assigns them to the ParsedClass instance.
@throws RestException
|
[
"Parsed",
"the",
"class",
"methods",
"and",
"assigns",
"them",
"to",
"the",
"ParsedClass",
"instance",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/ClassParser.php#L122-L138
|
230,373
|
Webiny/Framework
|
src/Webiny/Component/Logger/LoggerTrait.php
|
LoggerTrait.logger
|
public static function logger($name = 'Webiny')
{
try {
return ServiceManager::getInstance()->getService('Logger.' . $name);
} catch (ServiceManagerException $e) {
if ($e->getCode() == ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND) {
return new Logger($name, new NullDriver());
}
throw $e;
}
}
|
php
|
public static function logger($name = 'Webiny')
{
try {
return ServiceManager::getInstance()->getService('Logger.' . $name);
} catch (ServiceManagerException $e) {
if ($e->getCode() == ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND) {
return new Logger($name, new NullDriver());
}
throw $e;
}
}
|
[
"public",
"static",
"function",
"logger",
"(",
"$",
"name",
"=",
"'Webiny'",
")",
"{",
"try",
"{",
"return",
"ServiceManager",
"::",
"getInstance",
"(",
")",
"->",
"getService",
"(",
"'Logger.'",
".",
"$",
"name",
")",
";",
"}",
"catch",
"(",
"ServiceManagerException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"==",
"ServiceManagerException",
"::",
"SERVICE_DEFINITION_NOT_FOUND",
")",
"{",
"return",
"new",
"Logger",
"(",
"$",
"name",
",",
"new",
"NullDriver",
"(",
")",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"}"
] |
Get logger.
Just provide the logger name without the 'logger.' prefix.
The name must match the name of your service.
@param string $name Logger service name.
@return LoggerDriverInterface
@throws ServiceManagerException
|
[
"Get",
"logger",
".",
"Just",
"provide",
"the",
"logger",
"name",
"without",
"the",
"logger",
".",
"prefix",
".",
"The",
"name",
"must",
"match",
"the",
"name",
"of",
"your",
"service",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Logger/LoggerTrait.php#L33-L45
|
230,374
|
Webiny/Framework
|
src/Webiny/Component/Bootstrap/Dispatcher.php
|
Dispatcher.mvcDispatcher
|
public static function mvcDispatcher($module, $controller, $action, $params)
{
$dispatcher = new self;
$dispatcher->setModule($module);
$dispatcher->setController($controller);
$dispatcher->setAction($action);
$dispatcher->setParams($params);
// get current application config
$applicationConfig = Bootstrap::getInstance()->getEnvironment()->getApplicationConfig();
// build the class name
$className = '\\' . $applicationConfig->Namespace . '\Modules\\' . $dispatcher->getModule() . '\Controllers\\' . $dispatcher->getController();
$dispatcher->setClassName($className);
return $dispatcher;
}
|
php
|
public static function mvcDispatcher($module, $controller, $action, $params)
{
$dispatcher = new self;
$dispatcher->setModule($module);
$dispatcher->setController($controller);
$dispatcher->setAction($action);
$dispatcher->setParams($params);
// get current application config
$applicationConfig = Bootstrap::getInstance()->getEnvironment()->getApplicationConfig();
// build the class name
$className = '\\' . $applicationConfig->Namespace . '\Modules\\' . $dispatcher->getModule() . '\Controllers\\' . $dispatcher->getController();
$dispatcher->setClassName($className);
return $dispatcher;
}
|
[
"public",
"static",
"function",
"mvcDispatcher",
"(",
"$",
"module",
",",
"$",
"controller",
",",
"$",
"action",
",",
"$",
"params",
")",
"{",
"$",
"dispatcher",
"=",
"new",
"self",
";",
"$",
"dispatcher",
"->",
"setModule",
"(",
"$",
"module",
")",
";",
"$",
"dispatcher",
"->",
"setController",
"(",
"$",
"controller",
")",
";",
"$",
"dispatcher",
"->",
"setAction",
"(",
"$",
"action",
")",
";",
"$",
"dispatcher",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"// get current application config",
"$",
"applicationConfig",
"=",
"Bootstrap",
"::",
"getInstance",
"(",
")",
"->",
"getEnvironment",
"(",
")",
"->",
"getApplicationConfig",
"(",
")",
";",
"// build the class name",
"$",
"className",
"=",
"'\\\\'",
".",
"$",
"applicationConfig",
"->",
"Namespace",
".",
"'\\Modules\\\\'",
".",
"$",
"dispatcher",
"->",
"getModule",
"(",
")",
".",
"'\\Controllers\\\\'",
".",
"$",
"dispatcher",
"->",
"getController",
"(",
")",
";",
"$",
"dispatcher",
"->",
"setClassName",
"(",
"$",
"className",
")",
";",
"return",
"$",
"dispatcher",
";",
"}"
] |
Creates a Dispatcher instance from MVC parameters.
@param string $module Module name.
@param string $controller Controller name.
@param string $action Action name.
@param array $params Parameters.
@return Dispatcher
|
[
"Creates",
"a",
"Dispatcher",
"instance",
"from",
"MVC",
"parameters",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Dispatcher.php#L62-L78
|
230,375
|
Webiny/Framework
|
src/Webiny/Component/Bootstrap/Dispatcher.php
|
Dispatcher.customDispatcher
|
public static function customDispatcher($className, $action, $params)
{
$dispatcher = new self;
$dispatcher->setClassName($className);
$dispatcher->setAction($action);
$dispatcher->setParams($params);
return $dispatcher;
}
|
php
|
public static function customDispatcher($className, $action, $params)
{
$dispatcher = new self;
$dispatcher->setClassName($className);
$dispatcher->setAction($action);
$dispatcher->setParams($params);
return $dispatcher;
}
|
[
"public",
"static",
"function",
"customDispatcher",
"(",
"$",
"className",
",",
"$",
"action",
",",
"$",
"params",
")",
"{",
"$",
"dispatcher",
"=",
"new",
"self",
";",
"$",
"dispatcher",
"->",
"setClassName",
"(",
"$",
"className",
")",
";",
"$",
"dispatcher",
"->",
"setAction",
"(",
"$",
"action",
")",
";",
"$",
"dispatcher",
"->",
"setParams",
"(",
"$",
"params",
")",
";",
"return",
"$",
"dispatcher",
";",
"}"
] |
Creates a Dispatcher instance from a class name.
@param string $className Fully qualified class name.
@param string $action Action name.
@param array $params Parameters.
@return Dispatcher
|
[
"Creates",
"a",
"Dispatcher",
"instance",
"from",
"a",
"class",
"name",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Dispatcher.php#L89-L97
|
230,376
|
Webiny/Framework
|
src/Webiny/Component/Bootstrap/Dispatcher.php
|
Dispatcher.setClassName
|
public function setClassName($className)
{
try {
$classFilename = ClassLoader::getInstance()->findClass($className);
if (!file_exists($classFilename)) {
throw new BootstrapException('The provided callback class "' . $className . '" does not exist.');
} else {
$this->className = $className;
}
} catch (\Exception $e) {
throw $e;
}
}
|
php
|
public function setClassName($className)
{
try {
$classFilename = ClassLoader::getInstance()->findClass($className);
if (!file_exists($classFilename)) {
throw new BootstrapException('The provided callback class "' . $className . '" does not exist.');
} else {
$this->className = $className;
}
} catch (\Exception $e) {
throw $e;
}
}
|
[
"public",
"function",
"setClassName",
"(",
"$",
"className",
")",
"{",
"try",
"{",
"$",
"classFilename",
"=",
"ClassLoader",
"::",
"getInstance",
"(",
")",
"->",
"findClass",
"(",
"$",
"className",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"classFilename",
")",
")",
"{",
"throw",
"new",
"BootstrapException",
"(",
"'The provided callback class \"'",
".",
"$",
"className",
".",
"'\" does not exist.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"className",
"=",
"$",
"className",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}"
] |
Sets the class name. Note, this will overwrite the current class name, also valid in case of MVC callback.
@param string $className Fully qualified class name.
@throws \Exception | BootstrapException
|
[
"Sets",
"the",
"class",
"name",
".",
"Note",
"this",
"will",
"overwrite",
"the",
"current",
"class",
"name",
"also",
"valid",
"in",
"case",
"of",
"MVC",
"callback",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Dispatcher.php#L188-L200
|
230,377
|
Webiny/Framework
|
src/Webiny/Component/Bootstrap/Dispatcher.php
|
Dispatcher.issueCallback
|
public function issueCallback()
{
$instance = $this->getCallbackClassInstance();
// call the controller
call_user_func_array([
$instance,
$this->getAction() . 'Action'
], $this->getParams());
$response = $instance->app()->httpResponse();
if ($response) {
$response->send();
}
}
|
php
|
public function issueCallback()
{
$instance = $this->getCallbackClassInstance();
// call the controller
call_user_func_array([
$instance,
$this->getAction() . 'Action'
], $this->getParams());
$response = $instance->app()->httpResponse();
if ($response) {
$response->send();
}
}
|
[
"public",
"function",
"issueCallback",
"(",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"getCallbackClassInstance",
"(",
")",
";",
"// call the controller",
"call_user_func_array",
"(",
"[",
"$",
"instance",
",",
"$",
"this",
"->",
"getAction",
"(",
")",
".",
"'Action'",
"]",
",",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
";",
"$",
"response",
"=",
"$",
"instance",
"->",
"app",
"(",
")",
"->",
"httpResponse",
"(",
")",
";",
"if",
"(",
"$",
"response",
")",
"{",
"$",
"response",
"->",
"send",
"(",
")",
";",
"}",
"}"
] |
Calls the defined action on the current class name, passing along the parameters.
@throws BootstrapException
|
[
"Calls",
"the",
"defined",
"action",
"on",
"the",
"current",
"class",
"name",
"passing",
"along",
"the",
"parameters",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Dispatcher.php#L217-L231
|
230,378
|
Webiny/Framework
|
src/Webiny/Component/Bootstrap/Dispatcher.php
|
Dispatcher.getCallbackClassInstance
|
private function getCallbackClassInstance()
{
// create and validate the instance
$className = $this->getClassName();
$instance = new $className();
// check that the app implements the trait
// is we use the class_traits method, we only get the traits of the current level, we don't get the traits
// if the class extends another class that actually implements the trait
if (!method_exists($instance, 'setAppInstance')) {
if (!isset($traits[AppTrait::class])) {
throw new BootstrapException('Class "' . $className . '" must use "' . AppTrait::class . '" trait.');
}
}
$app = $this->getApplicationInstance();
// assign the app to the app trait
$instance->setAppInstance($app);
// set the instance template
$this->setTemplate($instance);
// call the setUp method
$instance->setUp();
return $instance;
}
|
php
|
private function getCallbackClassInstance()
{
// create and validate the instance
$className = $this->getClassName();
$instance = new $className();
// check that the app implements the trait
// is we use the class_traits method, we only get the traits of the current level, we don't get the traits
// if the class extends another class that actually implements the trait
if (!method_exists($instance, 'setAppInstance')) {
if (!isset($traits[AppTrait::class])) {
throw new BootstrapException('Class "' . $className . '" must use "' . AppTrait::class . '" trait.');
}
}
$app = $this->getApplicationInstance();
// assign the app to the app trait
$instance->setAppInstance($app);
// set the instance template
$this->setTemplate($instance);
// call the setUp method
$instance->setUp();
return $instance;
}
|
[
"private",
"function",
"getCallbackClassInstance",
"(",
")",
"{",
"// create and validate the instance",
"$",
"className",
"=",
"$",
"this",
"->",
"getClassName",
"(",
")",
";",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
")",
";",
"// check that the app implements the trait",
"// is we use the class_traits method, we only get the traits of the current level, we don't get the traits",
"// if the class extends another class that actually implements the trait",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"instance",
",",
"'setAppInstance'",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"traits",
"[",
"AppTrait",
"::",
"class",
"]",
")",
")",
"{",
"throw",
"new",
"BootstrapException",
"(",
"'Class \"'",
".",
"$",
"className",
".",
"'\" must use \"'",
".",
"AppTrait",
"::",
"class",
".",
"'\" trait.'",
")",
";",
"}",
"}",
"$",
"app",
"=",
"$",
"this",
"->",
"getApplicationInstance",
"(",
")",
";",
"// assign the app to the app trait",
"$",
"instance",
"->",
"setAppInstance",
"(",
"$",
"app",
")",
";",
"// set the instance template",
"$",
"this",
"->",
"setTemplate",
"(",
"$",
"instance",
")",
";",
"// call the setUp method",
"$",
"instance",
"->",
"setUp",
"(",
")",
";",
"return",
"$",
"instance",
";",
"}"
] |
Creates class instance from the defined class name.
Method automatically also tries to set the view template - only in case of an MVC callback.
In all cases the callback class must implement the AppTrait, because the method also calls the setUp method on
the class instance.
@return mixed
@throws BootstrapException
|
[
"Creates",
"class",
"instance",
"from",
"the",
"defined",
"class",
"name",
".",
"Method",
"automatically",
"also",
"tries",
"to",
"set",
"the",
"view",
"template",
"-",
"only",
"in",
"case",
"of",
"an",
"MVC",
"callback",
".",
"In",
"all",
"cases",
"the",
"callback",
"class",
"must",
"implement",
"the",
"AppTrait",
"because",
"the",
"method",
"also",
"calls",
"the",
"setUp",
"method",
"on",
"the",
"class",
"instance",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Dispatcher.php#L242-L269
|
230,379
|
Webiny/Framework
|
src/Webiny/Component/Rest/Response/CallbackResult.php
|
CallbackResult.setHeaderResponse
|
public function setHeaderResponse($statusCode, $message = '')
{
$this->statusCode = $statusCode;
$this->message = $message;
if ($message == '') {
$this->message = self::$defaultMessages[$statusCode];
}
if (empty($this->message)) {
throw new RestException('Invalid http response status code: ' . $statusCode);
}
return $this;
}
|
php
|
public function setHeaderResponse($statusCode, $message = '')
{
$this->statusCode = $statusCode;
$this->message = $message;
if ($message == '') {
$this->message = self::$defaultMessages[$statusCode];
}
if (empty($this->message)) {
throw new RestException('Invalid http response status code: ' . $statusCode);
}
return $this;
}
|
[
"public",
"function",
"setHeaderResponse",
"(",
"$",
"statusCode",
",",
"$",
"message",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"statusCode",
";",
"$",
"this",
"->",
"message",
"=",
"$",
"message",
";",
"if",
"(",
"$",
"message",
"==",
"''",
")",
"{",
"$",
"this",
"->",
"message",
"=",
"self",
"::",
"$",
"defaultMessages",
"[",
"$",
"statusCode",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"message",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'Invalid http response status code: '",
".",
"$",
"statusCode",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set response header status code and message.
@param int $statusCode Response status code.
@param string $message Response message.
@return $this
@throws \Webiny\Component\Rest\RestException
|
[
"Set",
"response",
"header",
"status",
"code",
"and",
"message",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/CallbackResult.php#L109-L122
|
230,380
|
Webiny/Framework
|
src/Webiny/Component/Rest/Response/CallbackResult.php
|
CallbackResult.setErrorResponse
|
public function setErrorResponse($message, $description = '', $code = '')
{
$this->outputArray['errorReport']['message'] = $message;
if (!empty($description)) {
$this->outputArray['errorReport']['description'] = $description;
}
if (!empty($code)) {
$this->outputArray['errorReport']['code'] = $code;
}
return $this;
}
|
php
|
public function setErrorResponse($message, $description = '', $code = '')
{
$this->outputArray['errorReport']['message'] = $message;
if (!empty($description)) {
$this->outputArray['errorReport']['description'] = $description;
}
if (!empty($code)) {
$this->outputArray['errorReport']['code'] = $code;
}
return $this;
}
|
[
"public",
"function",
"setErrorResponse",
"(",
"$",
"message",
",",
"$",
"description",
"=",
"''",
",",
"$",
"code",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"outputArray",
"[",
"'errorReport'",
"]",
"[",
"'message'",
"]",
"=",
"$",
"message",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"description",
")",
")",
"{",
"$",
"this",
"->",
"outputArray",
"[",
"'errorReport'",
"]",
"[",
"'description'",
"]",
"=",
"$",
"description",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"code",
")",
")",
"{",
"$",
"this",
"->",
"outputArray",
"[",
"'errorReport'",
"]",
"[",
"'code'",
"]",
"=",
"$",
"code",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Adds a general error to the response.
@param string $message Error message.
@param string $description Error description.
@param string $code Error code.
@return $this
|
[
"Adds",
"a",
"general",
"error",
"to",
"the",
"response",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/CallbackResult.php#L133-L146
|
230,381
|
Webiny/Framework
|
src/Webiny/Component/Rest/Response/CallbackResult.php
|
CallbackResult.attachDebugHeader
|
public function attachDebugHeader($name, $value, $ignoreEnv = false)
{
if ($this->env != 'development' && !$ignoreEnv) {
return $this;
}
if (strpos($name, 'X-Webiny-Rest') === false) {
$name = 'X-Webiny-Rest-' . $name;
}
$this->debugHeaders[$name] = $value;
return $this;
}
|
php
|
public function attachDebugHeader($name, $value, $ignoreEnv = false)
{
if ($this->env != 'development' && !$ignoreEnv) {
return $this;
}
if (strpos($name, 'X-Webiny-Rest') === false) {
$name = 'X-Webiny-Rest-' . $name;
}
$this->debugHeaders[$name] = $value;
return $this;
}
|
[
"public",
"function",
"attachDebugHeader",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"ignoreEnv",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"env",
"!=",
"'development'",
"&&",
"!",
"$",
"ignoreEnv",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'X-Webiny-Rest'",
")",
"===",
"false",
")",
"{",
"$",
"name",
"=",
"'X-Webiny-Rest-'",
".",
"$",
"name",
";",
"}",
"$",
"this",
"->",
"debugHeaders",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a debug header information.
@param string $name Header name.
@param string $value Header value.
@param bool $ignoreEnv Headers will be added only if we are in development mode, unless you set this to true.
@return $this
|
[
"Adds",
"a",
"debug",
"header",
"information",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/CallbackResult.php#L219-L233
|
230,382
|
Webiny/Framework
|
src/Webiny/Component/Rest/Response/CallbackResult.php
|
CallbackResult.sendOutput
|
public function sendOutput()
{
// check environment to see what and how to do the output
$prettyPrint = false;
if ($this->env == 'development') {
$prettyPrint = true;
unset($this->outputArray['debug']);
}
// if there is an error, we always dump the content
if (!empty($this->outputArray['errorReport'])) {
unset($this->outputArray['data']);
}
// build response
if (empty($this->outputArray)) {
$response = $this->httpResponse();
} else {
$response = new JsonResponse($this->outputArray, $this->debugHeaders, $prettyPrint);
}
// set proper status code to the response
$response->setStatusCode($this->statusCode, $this->message);
// check the expires header
if ($this->expiresIn > 0) {
$expiration = $this->dateTime()->add('PT' . $this->expiresIn . 'S');
$response->cacheControl()->setAsCache($expiration);
}
// send it to the browser
$response->send();
}
|
php
|
public function sendOutput()
{
// check environment to see what and how to do the output
$prettyPrint = false;
if ($this->env == 'development') {
$prettyPrint = true;
unset($this->outputArray['debug']);
}
// if there is an error, we always dump the content
if (!empty($this->outputArray['errorReport'])) {
unset($this->outputArray['data']);
}
// build response
if (empty($this->outputArray)) {
$response = $this->httpResponse();
} else {
$response = new JsonResponse($this->outputArray, $this->debugHeaders, $prettyPrint);
}
// set proper status code to the response
$response->setStatusCode($this->statusCode, $this->message);
// check the expires header
if ($this->expiresIn > 0) {
$expiration = $this->dateTime()->add('PT' . $this->expiresIn . 'S');
$response->cacheControl()->setAsCache($expiration);
}
// send it to the browser
$response->send();
}
|
[
"public",
"function",
"sendOutput",
"(",
")",
"{",
"// check environment to see what and how to do the output",
"$",
"prettyPrint",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"env",
"==",
"'development'",
")",
"{",
"$",
"prettyPrint",
"=",
"true",
";",
"unset",
"(",
"$",
"this",
"->",
"outputArray",
"[",
"'debug'",
"]",
")",
";",
"}",
"// if there is an error, we always dump the content",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"outputArray",
"[",
"'errorReport'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"outputArray",
"[",
"'data'",
"]",
")",
";",
"}",
"// build response",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"outputArray",
")",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpResponse",
"(",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"this",
"->",
"outputArray",
",",
"$",
"this",
"->",
"debugHeaders",
",",
"$",
"prettyPrint",
")",
";",
"}",
"// set proper status code to the response",
"$",
"response",
"->",
"setStatusCode",
"(",
"$",
"this",
"->",
"statusCode",
",",
"$",
"this",
"->",
"message",
")",
";",
"// check the expires header",
"if",
"(",
"$",
"this",
"->",
"expiresIn",
">",
"0",
")",
"{",
"$",
"expiration",
"=",
"$",
"this",
"->",
"dateTime",
"(",
")",
"->",
"add",
"(",
"'PT'",
".",
"$",
"this",
"->",
"expiresIn",
".",
"'S'",
")",
";",
"$",
"response",
"->",
"cacheControl",
"(",
")",
"->",
"setAsCache",
"(",
"$",
"expiration",
")",
";",
"}",
"// send it to the browser",
"$",
"response",
"->",
"send",
"(",
")",
";",
"}"
] |
Sends the output to browser.
|
[
"Sends",
"the",
"output",
"to",
"browser",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Response/CallbackResult.php#L274-L306
|
230,383
|
Webiny/Framework
|
src/Webiny/Component/Storage/Storage.php
|
Storage.setContents
|
public function setContents($key, $contents, $append = false)
{
return $this->driver->setContents($key, $contents, $append);
}
|
php
|
public function setContents($key, $contents, $append = false)
{
return $this->driver->setContents($key, $contents, $append);
}
|
[
"public",
"function",
"setContents",
"(",
"$",
"key",
",",
"$",
"contents",
",",
"$",
"append",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"driver",
"->",
"setContents",
"(",
"$",
"key",
",",
"$",
"contents",
",",
"$",
"append",
")",
";",
"}"
] |
Writes the given contents into the file
@param string $key
@param string $contents
@param bool $append
@return bool|int The number of bytes that were written into the file
|
[
"Writes",
"the",
"given",
"contents",
"into",
"the",
"file"
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Storage/Storage.php#L76-L79
|
230,384
|
Webiny/Framework
|
src/Webiny/Component/Storage/Storage.php
|
Storage.getTimeModified
|
public function getTimeModified($key, $asDateTimeObject = false)
{
$time = $this->driver->getTimeModified($key);
if ($asDateTimeObject) {
$datetime = new DateTimeObject();
return $datetime->setTimestamp($time);
}
return $time;
}
|
php
|
public function getTimeModified($key, $asDateTimeObject = false)
{
$time = $this->driver->getTimeModified($key);
if ($asDateTimeObject) {
$datetime = new DateTimeObject();
return $datetime->setTimestamp($time);
}
return $time;
}
|
[
"public",
"function",
"getTimeModified",
"(",
"$",
"key",
",",
"$",
"asDateTimeObject",
"=",
"false",
")",
"{",
"$",
"time",
"=",
"$",
"this",
"->",
"driver",
"->",
"getTimeModified",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"asDateTimeObject",
")",
"{",
"$",
"datetime",
"=",
"new",
"DateTimeObject",
"(",
")",
";",
"return",
"$",
"datetime",
"->",
"setTimestamp",
"(",
"$",
"time",
")",
";",
"}",
"return",
"$",
"time",
";",
"}"
] |
Returns the last modified time
@param string $key
@param bool $asDateTimeObject (Optional) Return as DateTimeObject if true
@return UNIX Timestamp or DateTimeObject
|
[
"Returns",
"the",
"last",
"modified",
"time"
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Storage/Storage.php#L116-L126
|
230,385
|
Webiny/Framework
|
src/Webiny/Component/Image/Bridge/Imagine/Image.php
|
Image.getBinary
|
public function getBinary($options = [])
{
$options['quality'] = isset($options['quality']) ? $options['quality'] : self::QUALITY;
return $this->image->get($this->getFormat(), $options);
}
|
php
|
public function getBinary($options = [])
{
$options['quality'] = isset($options['quality']) ? $options['quality'] : self::QUALITY;
return $this->image->get($this->getFormat(), $options);
}
|
[
"public",
"function",
"getBinary",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"[",
"'quality'",
"]",
"=",
"isset",
"(",
"$",
"options",
"[",
"'quality'",
"]",
")",
"?",
"$",
"options",
"[",
"'quality'",
"]",
":",
"self",
"::",
"QUALITY",
";",
"return",
"$",
"this",
"->",
"image",
"->",
"get",
"(",
"$",
"this",
"->",
"getFormat",
"(",
")",
",",
"$",
"options",
")",
";",
"}"
] |
Get image as a binary string.
@param array $options An array of options. Possible keys are [quality, filters].
@return string
|
[
"Get",
"image",
"as",
"a",
"binary",
"string",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/Imagine/Image.php#L54-L59
|
230,386
|
Webiny/Framework
|
src/Webiny/Component/Image/Bridge/Imagine/Image.php
|
Image.getSize
|
public function getSize()
{
$size = $this->image->getSize();
return $this->arr([
'width' => $size->getWidth(),
'height' => $size->getHeight()
]
);
}
|
php
|
public function getSize()
{
$size = $this->image->getSize();
return $this->arr([
'width' => $size->getWidth(),
'height' => $size->getHeight()
]
);
}
|
[
"public",
"function",
"getSize",
"(",
")",
"{",
"$",
"size",
"=",
"$",
"this",
"->",
"image",
"->",
"getSize",
"(",
")",
";",
"return",
"$",
"this",
"->",
"arr",
"(",
"[",
"'width'",
"=>",
"$",
"size",
"->",
"getWidth",
"(",
")",
",",
"'height'",
"=>",
"$",
"size",
"->",
"getHeight",
"(",
")",
"]",
")",
";",
"}"
] |
Returns the width and height of the image in pixels.
@return ArrayObject
|
[
"Returns",
"the",
"width",
"and",
"height",
"of",
"the",
"image",
"in",
"pixels",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/Imagine/Image.php#L66-L75
|
230,387
|
Webiny/Framework
|
src/Webiny/Component/Image/Bridge/Imagine/Image.php
|
Image.crop
|
public function crop($width, $height, $offestX = 0, $offestY = 0)
{
$pointer = new Point($offestX, $offestY);
$size = new Box($width, $height);
$this->image->crop($pointer, $size);
return $this;
}
|
php
|
public function crop($width, $height, $offestX = 0, $offestY = 0)
{
$pointer = new Point($offestX, $offestY);
$size = new Box($width, $height);
$this->image->crop($pointer, $size);
return $this;
}
|
[
"public",
"function",
"crop",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"offestX",
"=",
"0",
",",
"$",
"offestY",
"=",
"0",
")",
"{",
"$",
"pointer",
"=",
"new",
"Point",
"(",
"$",
"offestX",
",",
"$",
"offestY",
")",
";",
"$",
"size",
"=",
"new",
"Box",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"$",
"this",
"->",
"image",
"->",
"crop",
"(",
"$",
"pointer",
",",
"$",
"size",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Crop the image to the given dimensions.
@param int $width Width on the new image.
@param int $height Height of the new image.
@param int $offestX Crop start position on X axis.
@param int $offestY Crop start position on Y axis.
@return $this
|
[
"Crop",
"the",
"image",
"to",
"the",
"given",
"dimensions",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/Imagine/Image.php#L87-L95
|
230,388
|
Webiny/Framework
|
src/Webiny/Component/Image/Bridge/Imagine/Image.php
|
Image.resize
|
public function resize($width, $height, $preserveAspectRatio = true)
{
if ($preserveAspectRatio) {
$currentSize = $this->getSize();
$currentAspectRatio = round($currentSize->width / $currentSize->height, 3);
$aspectRatio = round($width / $height, 3);
if ($currentAspectRatio <> $aspectRatio) {
if ($width < $height) {
$height = round($width / $currentAspectRatio);
} else {
$width = round($height * $currentAspectRatio);
}
}
}
$size = new Box($width, $height);
$this->image->resize($size);
return $this;
}
|
php
|
public function resize($width, $height, $preserveAspectRatio = true)
{
if ($preserveAspectRatio) {
$currentSize = $this->getSize();
$currentAspectRatio = round($currentSize->width / $currentSize->height, 3);
$aspectRatio = round($width / $height, 3);
if ($currentAspectRatio <> $aspectRatio) {
if ($width < $height) {
$height = round($width / $currentAspectRatio);
} else {
$width = round($height * $currentAspectRatio);
}
}
}
$size = new Box($width, $height);
$this->image->resize($size);
return $this;
}
|
[
"public",
"function",
"resize",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"preserveAspectRatio",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"preserveAspectRatio",
")",
"{",
"$",
"currentSize",
"=",
"$",
"this",
"->",
"getSize",
"(",
")",
";",
"$",
"currentAspectRatio",
"=",
"round",
"(",
"$",
"currentSize",
"->",
"width",
"/",
"$",
"currentSize",
"->",
"height",
",",
"3",
")",
";",
"$",
"aspectRatio",
"=",
"round",
"(",
"$",
"width",
"/",
"$",
"height",
",",
"3",
")",
";",
"if",
"(",
"$",
"currentAspectRatio",
"<>",
"$",
"aspectRatio",
")",
"{",
"if",
"(",
"$",
"width",
"<",
"$",
"height",
")",
"{",
"$",
"height",
"=",
"round",
"(",
"$",
"width",
"/",
"$",
"currentAspectRatio",
")",
";",
"}",
"else",
"{",
"$",
"width",
"=",
"round",
"(",
"$",
"height",
"*",
"$",
"currentAspectRatio",
")",
";",
"}",
"}",
"}",
"$",
"size",
"=",
"new",
"Box",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"$",
"this",
"->",
"image",
"->",
"resize",
"(",
"$",
"size",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Resize the image to given dimensions.
@param int $width Width of the new image.
@param int $height Height of the new image.
@param bool $preserveAspectRatio Do you wish to preserve the aspect ration while resizing. Default is true.
NOTE: If you preserve the aspect ratio, the output image might not match the
defined width and height.
@return $this
|
[
"Resize",
"the",
"image",
"to",
"given",
"dimensions",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/Imagine/Image.php#L108-L130
|
230,389
|
Webiny/Framework
|
src/Webiny/Component/Image/Bridge/Imagine/Image.php
|
Image.thumbnail
|
public function thumbnail($width, $height, $cropOrPad = false, $padColor = null)
{
// get the aspect ratio
$currentSize = $this->getSize();
$ar = round($currentSize['width'] / $currentSize['height'], 3);
$nar = round($width / $height, 3);
$newWidth = $width;
$newHeight = $height;
if ($ar >= 1) {
if ($nar > $ar) {
$newHeight = $width / $ar;
} else {
$newWidth = $height * $ar;
}
} else {
if ($nar > $ar) {
$newHeight = $width / $ar;
} else {
$newWidth = $height * $ar;
}
}
$this->resize($newWidth, $newHeight);
// crop
if ($cropOrPad == self::CROP) {
$this->crop($width, $height);
}
// pad
if ($cropOrPad == self::PAD) {
$padColor = !empty($padColor) ? $padColor : 'ffffff';
$image = ImageLoader::create($width, $height, $padColor);
// re-calculate the size based on aspect ratio
if ($width < $height) {
$newWidth = $width;
$newHeight = round($width / $ar, 0);
} else {
$newWidth = round($height / $ar, 0);
$newHeight = $height;
}
// center the padded image
$offsetX = ($width - $newWidth) / 2;
$offsetY = ($height - $newHeight) / 2;
// resize the current image
$this->resize($newWidth, $newHeight);
$image->paste($this, $offsetX, $offsetY);
$this->image = $image->getInstance();
unset($image);
}
return $this;
}
|
php
|
public function thumbnail($width, $height, $cropOrPad = false, $padColor = null)
{
// get the aspect ratio
$currentSize = $this->getSize();
$ar = round($currentSize['width'] / $currentSize['height'], 3);
$nar = round($width / $height, 3);
$newWidth = $width;
$newHeight = $height;
if ($ar >= 1) {
if ($nar > $ar) {
$newHeight = $width / $ar;
} else {
$newWidth = $height * $ar;
}
} else {
if ($nar > $ar) {
$newHeight = $width / $ar;
} else {
$newWidth = $height * $ar;
}
}
$this->resize($newWidth, $newHeight);
// crop
if ($cropOrPad == self::CROP) {
$this->crop($width, $height);
}
// pad
if ($cropOrPad == self::PAD) {
$padColor = !empty($padColor) ? $padColor : 'ffffff';
$image = ImageLoader::create($width, $height, $padColor);
// re-calculate the size based on aspect ratio
if ($width < $height) {
$newWidth = $width;
$newHeight = round($width / $ar, 0);
} else {
$newWidth = round($height / $ar, 0);
$newHeight = $height;
}
// center the padded image
$offsetX = ($width - $newWidth) / 2;
$offsetY = ($height - $newHeight) / 2;
// resize the current image
$this->resize($newWidth, $newHeight);
$image->paste($this, $offsetX, $offsetY);
$this->image = $image->getInstance();
unset($image);
}
return $this;
}
|
[
"public",
"function",
"thumbnail",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"cropOrPad",
"=",
"false",
",",
"$",
"padColor",
"=",
"null",
")",
"{",
"// get the aspect ratio",
"$",
"currentSize",
"=",
"$",
"this",
"->",
"getSize",
"(",
")",
";",
"$",
"ar",
"=",
"round",
"(",
"$",
"currentSize",
"[",
"'width'",
"]",
"/",
"$",
"currentSize",
"[",
"'height'",
"]",
",",
"3",
")",
";",
"$",
"nar",
"=",
"round",
"(",
"$",
"width",
"/",
"$",
"height",
",",
"3",
")",
";",
"$",
"newWidth",
"=",
"$",
"width",
";",
"$",
"newHeight",
"=",
"$",
"height",
";",
"if",
"(",
"$",
"ar",
">=",
"1",
")",
"{",
"if",
"(",
"$",
"nar",
">",
"$",
"ar",
")",
"{",
"$",
"newHeight",
"=",
"$",
"width",
"/",
"$",
"ar",
";",
"}",
"else",
"{",
"$",
"newWidth",
"=",
"$",
"height",
"*",
"$",
"ar",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"nar",
">",
"$",
"ar",
")",
"{",
"$",
"newHeight",
"=",
"$",
"width",
"/",
"$",
"ar",
";",
"}",
"else",
"{",
"$",
"newWidth",
"=",
"$",
"height",
"*",
"$",
"ar",
";",
"}",
"}",
"$",
"this",
"->",
"resize",
"(",
"$",
"newWidth",
",",
"$",
"newHeight",
")",
";",
"// crop",
"if",
"(",
"$",
"cropOrPad",
"==",
"self",
"::",
"CROP",
")",
"{",
"$",
"this",
"->",
"crop",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"}",
"// pad",
"if",
"(",
"$",
"cropOrPad",
"==",
"self",
"::",
"PAD",
")",
"{",
"$",
"padColor",
"=",
"!",
"empty",
"(",
"$",
"padColor",
")",
"?",
"$",
"padColor",
":",
"'ffffff'",
";",
"$",
"image",
"=",
"ImageLoader",
"::",
"create",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"padColor",
")",
";",
"// re-calculate the size based on aspect ratio",
"if",
"(",
"$",
"width",
"<",
"$",
"height",
")",
"{",
"$",
"newWidth",
"=",
"$",
"width",
";",
"$",
"newHeight",
"=",
"round",
"(",
"$",
"width",
"/",
"$",
"ar",
",",
"0",
")",
";",
"}",
"else",
"{",
"$",
"newWidth",
"=",
"round",
"(",
"$",
"height",
"/",
"$",
"ar",
",",
"0",
")",
";",
"$",
"newHeight",
"=",
"$",
"height",
";",
"}",
"// center the padded image",
"$",
"offsetX",
"=",
"(",
"$",
"width",
"-",
"$",
"newWidth",
")",
"/",
"2",
";",
"$",
"offsetY",
"=",
"(",
"$",
"height",
"-",
"$",
"newHeight",
")",
"/",
"2",
";",
"// resize the current image",
"$",
"this",
"->",
"resize",
"(",
"$",
"newWidth",
",",
"$",
"newHeight",
")",
";",
"$",
"image",
"->",
"paste",
"(",
"$",
"this",
",",
"$",
"offsetX",
",",
"$",
"offsetY",
")",
";",
"$",
"this",
"->",
"image",
"=",
"$",
"image",
"->",
"getInstance",
"(",
")",
";",
"unset",
"(",
"$",
"image",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
This is a method that combines resize, crop and paste methods in order to generate a thumbnail from the given image.
The benefit of using this function is that the function can automatically combine crop and resize methods together
with the pad feature in order to generate the thumb.
@param int $width Thumb width.
@param int $height Thumb height.
@param bool|string $cropOrPad If you set this to 'crop' the method will first resize the image to preserve the
aspect ratio and then it will crop the extra pixels to fit the defined width and height.
If you set this to 'pad' the method will first do the resize and than
it wil create a blank image that has the size of defined width and height and fill it
with $padColor, then it will paste the resized image in the center of the new image.
@param null|string $padColor Parameter that fills the background with the defined color.
Following formats are acceptable
- "fff"
- "ffffff"
- array(255,255,255)
@return $this
|
[
"This",
"is",
"a",
"method",
"that",
"combines",
"resize",
"crop",
"and",
"paste",
"methods",
"in",
"order",
"to",
"generate",
"a",
"thumbnail",
"from",
"the",
"given",
"image",
".",
"The",
"benefit",
"of",
"using",
"this",
"function",
"is",
"that",
"the",
"function",
"can",
"automatically",
"combine",
"crop",
"and",
"resize",
"methods",
"together",
"with",
"the",
"pad",
"feature",
"in",
"order",
"to",
"generate",
"the",
"thumb",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/Imagine/Image.php#L183-L239
|
230,390
|
Webiny/Framework
|
src/Webiny/Component/Image/Bridge/Imagine/Image.php
|
Image.paste
|
public function paste(ImageInterface $image, $offsetX = 0, $offsetY = 0)
{
$point = new Point($offsetX, $offsetY);
$this->image->paste($image->getInstance(), $point);
return $this;
}
|
php
|
public function paste(ImageInterface $image, $offsetX = 0, $offsetY = 0)
{
$point = new Point($offsetX, $offsetY);
$this->image->paste($image->getInstance(), $point);
return $this;
}
|
[
"public",
"function",
"paste",
"(",
"ImageInterface",
"$",
"image",
",",
"$",
"offsetX",
"=",
"0",
",",
"$",
"offsetY",
"=",
"0",
")",
"{",
"$",
"point",
"=",
"new",
"Point",
"(",
"$",
"offsetX",
",",
"$",
"offsetY",
")",
";",
"$",
"this",
"->",
"image",
"->",
"paste",
"(",
"$",
"image",
"->",
"getInstance",
"(",
")",
",",
"$",
"point",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Paste another image into this one a the specified dimension.
@param ImageInterface $image Image to paste.
@param int $offsetX Offset on x axis.
@param int $offsetY Offset on y axis
@return $this
|
[
"Paste",
"another",
"image",
"into",
"this",
"one",
"a",
"the",
"specified",
"dimension",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Image/Bridge/Imagine/Image.php#L250-L257
|
230,391
|
Webiny/Framework
|
src/Webiny/Component/Config/Bridge/Yaml/Yaml.php
|
Yaml.setDriver
|
public static function setDriver($driver)
{
if (!self::isInstanceOf($driver, YamlInterface::class)) {
if (self::isString($driver) || self::isStringObject($driver)) {
$driver = StdObjectWrapper::toString($driver);
$driver = new $driver;
if (self::isInstanceOf($driver, YamlInterface::class)) {
self::$customDriver = $driver;
return;
}
}
throw new YamlException(AbstractException::MSG_INVALID_ARG, ['$driver', YamlInterface::class]);
}
self::$customDriver = $driver;
return;
}
|
php
|
public static function setDriver($driver)
{
if (!self::isInstanceOf($driver, YamlInterface::class)) {
if (self::isString($driver) || self::isStringObject($driver)) {
$driver = StdObjectWrapper::toString($driver);
$driver = new $driver;
if (self::isInstanceOf($driver, YamlInterface::class)) {
self::$customDriver = $driver;
return;
}
}
throw new YamlException(AbstractException::MSG_INVALID_ARG, ['$driver', YamlInterface::class]);
}
self::$customDriver = $driver;
return;
}
|
[
"public",
"static",
"function",
"setDriver",
"(",
"$",
"driver",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isInstanceOf",
"(",
"$",
"driver",
",",
"YamlInterface",
"::",
"class",
")",
")",
"{",
"if",
"(",
"self",
"::",
"isString",
"(",
"$",
"driver",
")",
"||",
"self",
"::",
"isStringObject",
"(",
"$",
"driver",
")",
")",
"{",
"$",
"driver",
"=",
"StdObjectWrapper",
"::",
"toString",
"(",
"$",
"driver",
")",
";",
"$",
"driver",
"=",
"new",
"$",
"driver",
";",
"if",
"(",
"self",
"::",
"isInstanceOf",
"(",
"$",
"driver",
",",
"YamlInterface",
"::",
"class",
")",
")",
"{",
"self",
"::",
"$",
"customDriver",
"=",
"$",
"driver",
";",
"return",
";",
"}",
"}",
"throw",
"new",
"YamlException",
"(",
"AbstractException",
"::",
"MSG_INVALID_ARG",
",",
"[",
"'$driver'",
",",
"YamlInterface",
"::",
"class",
"]",
")",
";",
"}",
"self",
"::",
"$",
"customDriver",
"=",
"$",
"driver",
";",
"return",
";",
"}"
] |
Set Yaml driver to use by Yaml bridge
@param $driver string|YamlInterface
@throws YamlException
|
[
"Set",
"Yaml",
"driver",
"to",
"use",
"by",
"Yaml",
"bridge"
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/Bridge/Yaml/Yaml.php#L48-L66
|
230,392
|
Webiny/Framework
|
src/Webiny/Component/Config/Bridge/Yaml/Yaml.php
|
Yaml.getString
|
public function getString($indent = 2, $wordWrap = false)
{
$res = $this->driverInstance->getString($indent, $wordWrap);
if (!$this->isString($res) && !$this->isStringObject($res)) {
throw new YamlException('YamlInterface method _getString() must return a string or StringObject.');
}
return StdObjectWrapper::toString($res);
}
|
php
|
public function getString($indent = 2, $wordWrap = false)
{
$res = $this->driverInstance->getString($indent, $wordWrap);
if (!$this->isString($res) && !$this->isStringObject($res)) {
throw new YamlException('YamlInterface method _getString() must return a string or StringObject.');
}
return StdObjectWrapper::toString($res);
}
|
[
"public",
"function",
"getString",
"(",
"$",
"indent",
"=",
"2",
",",
"$",
"wordWrap",
"=",
"false",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"driverInstance",
"->",
"getString",
"(",
"$",
"indent",
",",
"$",
"wordWrap",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isString",
"(",
"$",
"res",
")",
"&&",
"!",
"$",
"this",
"->",
"isStringObject",
"(",
"$",
"res",
")",
")",
"{",
"throw",
"new",
"YamlException",
"(",
"'YamlInterface method _getString() must return a string or StringObject.'",
")",
";",
"}",
"return",
"StdObjectWrapper",
"::",
"toString",
"(",
"$",
"res",
")",
";",
"}"
] |
Get current Yaml value as string
@param int $indent
@param bool $wordWrap
@throws YamlException
@return string
|
[
"Get",
"current",
"Yaml",
"value",
"as",
"string"
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/Bridge/Yaml/Yaml.php#L89-L97
|
230,393
|
Webiny/Framework
|
src/Webiny/Component/Config/Bridge/Yaml/Yaml.php
|
Yaml.getArray
|
public function getArray()
{
$res = $this->driverInstance->getArray();
if (!$this->isArray($res) && !$this->isArrayObject($res)) {
throw new YamlException('YamlInterface method getArray() must return an array or ArrayObject.');
}
return StdObjectWrapper::toArray($res);
}
|
php
|
public function getArray()
{
$res = $this->driverInstance->getArray();
if (!$this->isArray($res) && !$this->isArrayObject($res)) {
throw new YamlException('YamlInterface method getArray() must return an array or ArrayObject.');
}
return StdObjectWrapper::toArray($res);
}
|
[
"public",
"function",
"getArray",
"(",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"driverInstance",
"->",
"getArray",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isArray",
"(",
"$",
"res",
")",
"&&",
"!",
"$",
"this",
"->",
"isArrayObject",
"(",
"$",
"res",
")",
")",
"{",
"throw",
"new",
"YamlException",
"(",
"'YamlInterface method getArray() must return an array or ArrayObject.'",
")",
";",
"}",
"return",
"StdObjectWrapper",
"::",
"toArray",
"(",
"$",
"res",
")",
";",
"}"
] |
Get Yaml value as array
@throws YamlException
@return array
|
[
"Get",
"Yaml",
"value",
"as",
"array"
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/Bridge/Yaml/Yaml.php#L105-L113
|
230,394
|
Webiny/Framework
|
src/Webiny/Component/Config/Bridge/Yaml/Yaml.php
|
Yaml.setResource
|
public function setResource($resource)
{
$res = $this->driverInstance->setResource($resource);
if (!$this->isInstanceOf($res, YamlInterface::class)) {
throw new YamlException('YamlInterface method setSource() must return YamlInterface object.');
}
return $this;
}
|
php
|
public function setResource($resource)
{
$res = $this->driverInstance->setResource($resource);
if (!$this->isInstanceOf($res, YamlInterface::class)) {
throw new YamlException('YamlInterface method setSource() must return YamlInterface object.');
}
return $this;
}
|
[
"public",
"function",
"setResource",
"(",
"$",
"resource",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"driverInstance",
"->",
"setResource",
"(",
"$",
"resource",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isInstanceOf",
"(",
"$",
"res",
",",
"YamlInterface",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"YamlException",
"(",
"'YamlInterface method setSource() must return YamlInterface object.'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set driver resource to work on
@param mixed $resource
@throws YamlException
@return $this
|
[
"Set",
"driver",
"resource",
"to",
"work",
"on"
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Config/Bridge/Yaml/Yaml.php#L123-L131
|
230,395
|
Webiny/Framework
|
src/Webiny/Component/Rest/Compiler/CacheDrivers/FilesystemDriver.php
|
FilesystemDriver.getCacheFilename
|
private function getCacheFilename($api, $class, $version)
{
if (!is_numeric(substr($version, 0, 1))) {
$versionFile = $version . '.php';
} else {
$versionFile = 'v' . $version . '.php';
}
// combine the paths and look for the cache file
$cacheFile = $this->getCacheFolder($api, $class) . $versionFile;
return $cacheFile;
}
|
php
|
private function getCacheFilename($api, $class, $version)
{
if (!is_numeric(substr($version, 0, 1))) {
$versionFile = $version . '.php';
} else {
$versionFile = 'v' . $version . '.php';
}
// combine the paths and look for the cache file
$cacheFile = $this->getCacheFolder($api, $class) . $versionFile;
return $cacheFile;
}
|
[
"private",
"function",
"getCacheFilename",
"(",
"$",
"api",
",",
"$",
"class",
",",
"$",
"version",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"substr",
"(",
"$",
"version",
",",
"0",
",",
"1",
")",
")",
")",
"{",
"$",
"versionFile",
"=",
"$",
"version",
".",
"'.php'",
";",
"}",
"else",
"{",
"$",
"versionFile",
"=",
"'v'",
".",
"$",
"version",
".",
"'.php'",
";",
"}",
"// combine the paths and look for the cache file",
"$",
"cacheFile",
"=",
"$",
"this",
"->",
"getCacheFolder",
"(",
"$",
"api",
",",
"$",
"class",
")",
".",
"$",
"versionFile",
";",
"return",
"$",
"cacheFile",
";",
"}"
] |
Returns the name of the cached class file.
@param string $api Name of the api configuration.
@param string $class Class name.
@param string $version Version of the api class.
@return string Full path to the cache filename.
@throws \Webiny\Component\Rest\RestException
|
[
"Returns",
"the",
"name",
"of",
"the",
"cached",
"class",
"file",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Compiler/CacheDrivers/FilesystemDriver.php#L126-L138
|
230,396
|
Webiny/Framework
|
src/Webiny/Component/Rest/Compiler/CacheDrivers/FilesystemDriver.php
|
FilesystemDriver.getCacheFolder
|
private function getCacheFolder($api, $class)
{
// get the api compile folder
$compilePath = Rest::getConfig()->get($api)->CompilePath;
if (empty($compilePath)) {
throw new RestException('You must set CompilePath for "' . $api . '" api.');
}
$apiFolder = $this->str($compilePath)->trimRight('/')->append(DIRECTORY_SEPARATOR . $api);
// get class cache folder
$classCacheFolder = $this->str($class)->trimLeft('\\')->replace('\\', '_')->val();
$apiFolder = $apiFolder . DIRECTORY_SEPARATOR . $classCacheFolder;
if (!is_dir($apiFolder)) {
mkdir($apiFolder, 0755, true);
clearstatcache(true, realpath($apiFolder));
}
return $apiFolder . DIRECTORY_SEPARATOR;
}
|
php
|
private function getCacheFolder($api, $class)
{
// get the api compile folder
$compilePath = Rest::getConfig()->get($api)->CompilePath;
if (empty($compilePath)) {
throw new RestException('You must set CompilePath for "' . $api . '" api.');
}
$apiFolder = $this->str($compilePath)->trimRight('/')->append(DIRECTORY_SEPARATOR . $api);
// get class cache folder
$classCacheFolder = $this->str($class)->trimLeft('\\')->replace('\\', '_')->val();
$apiFolder = $apiFolder . DIRECTORY_SEPARATOR . $classCacheFolder;
if (!is_dir($apiFolder)) {
mkdir($apiFolder, 0755, true);
clearstatcache(true, realpath($apiFolder));
}
return $apiFolder . DIRECTORY_SEPARATOR;
}
|
[
"private",
"function",
"getCacheFolder",
"(",
"$",
"api",
",",
"$",
"class",
")",
"{",
"// get the api compile folder",
"$",
"compilePath",
"=",
"Rest",
"::",
"getConfig",
"(",
")",
"->",
"get",
"(",
"$",
"api",
")",
"->",
"CompilePath",
";",
"if",
"(",
"empty",
"(",
"$",
"compilePath",
")",
")",
"{",
"throw",
"new",
"RestException",
"(",
"'You must set CompilePath for \"'",
".",
"$",
"api",
".",
"'\" api.'",
")",
";",
"}",
"$",
"apiFolder",
"=",
"$",
"this",
"->",
"str",
"(",
"$",
"compilePath",
")",
"->",
"trimRight",
"(",
"'/'",
")",
"->",
"append",
"(",
"DIRECTORY_SEPARATOR",
".",
"$",
"api",
")",
";",
"// get class cache folder",
"$",
"classCacheFolder",
"=",
"$",
"this",
"->",
"str",
"(",
"$",
"class",
")",
"->",
"trimLeft",
"(",
"'\\\\'",
")",
"->",
"replace",
"(",
"'\\\\'",
",",
"'_'",
")",
"->",
"val",
"(",
")",
";",
"$",
"apiFolder",
"=",
"$",
"apiFolder",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"classCacheFolder",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"apiFolder",
")",
")",
"{",
"mkdir",
"(",
"$",
"apiFolder",
",",
"0755",
",",
"true",
")",
";",
"clearstatcache",
"(",
"true",
",",
"realpath",
"(",
"$",
"apiFolder",
")",
")",
";",
"}",
"return",
"$",
"apiFolder",
".",
"DIRECTORY_SEPARATOR",
";",
"}"
] |
Returns the folder where the cache files should be stored.
@param string $api Name of the api configuration.
@param string $class Class name.
@return string
@throws RestException
@throws \Webiny\Component\Rest\RestException
|
[
"Returns",
"the",
"folder",
"where",
"the",
"cache",
"files",
"should",
"be",
"stored",
"."
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Compiler/CacheDrivers/FilesystemDriver.php#L150-L170
|
230,397
|
ZenMagick/ZenCart
|
includes/modules/payment/linkpoint_api.php
|
linkpoint_api._sendRequest
|
function _sendRequest($myorder) {
$myorder["host"] = "secure.linkpt.net";
if (MODULE_PAYMENT_LINKPOINT_API_TRANSACTION_MODE == 'DevelopersTest') {
$myorder["host"] = "staging.linkpt.net";
}
$myorder["port"] = "1129";
$myorder["keyfile"] =(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/linkpoint_api/' . MODULE_PAYMENT_LINKPOINT_API_LOGIN . '.pem');
$myorder["configfile"] = MODULE_PAYMENT_LINKPOINT_API_LOGIN; // This is your store number
// set to ECI and UNSPECIFIED for ecommerce transactions:
$myorder["transactionorigin"] = "ECI";
$myorder["terminaltype"] = "UNSPECIFIED";
// debug - for testing communication only
if (MODULE_PAYMENT_LINKPOINT_API_DEBUG != 'Off') {
}
if (MODULE_PAYMENT_LINKPOINT_API_CODE_DEBUG=='debug') {
$myorder["debugging"] = "true"; // for development only - not intended for production use
$myorder["debug"] = "true"; // for development only - not intended for production use
$myorder["webspace"] = "true"; // for development only - not intended for production use
}
include(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/linkpoint_api/class.linkpoint_api.php');
$mylphp = new lphp;
// Send transaction, using cURL
$result = $mylphp->curl_process($myorder);
// do debug output
$errorMessage = date('M-d-Y h:i:s') . "\n=================================\n\n" . ($mylphp->commError !='' ? $mylphp->commError . "\n\n" : '') . 'Response Code: ' . $result["r_approved"] . ' ' . $result["r_error"] . "\n\n=================================\n\n" . 'Sending to Gateway: ' . "\n" . $mylphp->sendData . "\n\n" . 'Result: ' . substr(print_r($result, true), 5) . "\n\n";
if ($mylphp->commError != '') $errorMessage .= $mylphp->commError . "\n" . 'CURL info: ' . print_r($mylphp->commInfo, true) . "\n";
if (CURL_PROXY_REQUIRED == 'True') $errorMessage .= 'Using CURL Proxy: [' . CURL_PROXY_SERVER_DETAILS . '] with Proxy Tunnel: ' .($proxy_tunnel_flag ? 'On' : 'Off') . "\n";
$failure = (!is_array($result) || $result["r_approved"] != "APPROVED") ? true : false;
// handle logging
if (strstr(MODULE_PAYMENT_LINKPOINT_API_DEBUG, 'Log')) {
$this->_log($errorMessage, $myorder["oid"] . ($failure ? '_FAILED' : ''));
// $this->_log($errorMessage . print_r($myorder, true) . print_r($mylphp->xmlString, true), $myorder["oid"] . ($failure ? '_FAILED' : ''));
}
if (strstr(MODULE_PAYMENT_LINKPOINT_API_DEBUG, 'Email') || ($failure && strstr(MODULE_PAYMENT_LINKPOINT_API_DEBUG, 'Alert'))) {
zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, 'Linkpoint Debug Data' . ($failure ? ' - FAILURE' : ''), $errorMessage, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($errorMessage)), 'debug');
}
//DEBUG ONLY:$this->_log($errorMessage /*. print_r($myorder, true) . print_r($mylphp->xmlString, true)*/, $myorder["oid"]);
if ($myorder['debugging'] == 'true') exit;
return $result;
}
|
php
|
function _sendRequest($myorder) {
$myorder["host"] = "secure.linkpt.net";
if (MODULE_PAYMENT_LINKPOINT_API_TRANSACTION_MODE == 'DevelopersTest') {
$myorder["host"] = "staging.linkpt.net";
}
$myorder["port"] = "1129";
$myorder["keyfile"] =(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/linkpoint_api/' . MODULE_PAYMENT_LINKPOINT_API_LOGIN . '.pem');
$myorder["configfile"] = MODULE_PAYMENT_LINKPOINT_API_LOGIN; // This is your store number
// set to ECI and UNSPECIFIED for ecommerce transactions:
$myorder["transactionorigin"] = "ECI";
$myorder["terminaltype"] = "UNSPECIFIED";
// debug - for testing communication only
if (MODULE_PAYMENT_LINKPOINT_API_DEBUG != 'Off') {
}
if (MODULE_PAYMENT_LINKPOINT_API_CODE_DEBUG=='debug') {
$myorder["debugging"] = "true"; // for development only - not intended for production use
$myorder["debug"] = "true"; // for development only - not intended for production use
$myorder["webspace"] = "true"; // for development only - not intended for production use
}
include(DIR_FS_CATALOG . DIR_WS_MODULES . 'payment/linkpoint_api/class.linkpoint_api.php');
$mylphp = new lphp;
// Send transaction, using cURL
$result = $mylphp->curl_process($myorder);
// do debug output
$errorMessage = date('M-d-Y h:i:s') . "\n=================================\n\n" . ($mylphp->commError !='' ? $mylphp->commError . "\n\n" : '') . 'Response Code: ' . $result["r_approved"] . ' ' . $result["r_error"] . "\n\n=================================\n\n" . 'Sending to Gateway: ' . "\n" . $mylphp->sendData . "\n\n" . 'Result: ' . substr(print_r($result, true), 5) . "\n\n";
if ($mylphp->commError != '') $errorMessage .= $mylphp->commError . "\n" . 'CURL info: ' . print_r($mylphp->commInfo, true) . "\n";
if (CURL_PROXY_REQUIRED == 'True') $errorMessage .= 'Using CURL Proxy: [' . CURL_PROXY_SERVER_DETAILS . '] with Proxy Tunnel: ' .($proxy_tunnel_flag ? 'On' : 'Off') . "\n";
$failure = (!is_array($result) || $result["r_approved"] != "APPROVED") ? true : false;
// handle logging
if (strstr(MODULE_PAYMENT_LINKPOINT_API_DEBUG, 'Log')) {
$this->_log($errorMessage, $myorder["oid"] . ($failure ? '_FAILED' : ''));
// $this->_log($errorMessage . print_r($myorder, true) . print_r($mylphp->xmlString, true), $myorder["oid"] . ($failure ? '_FAILED' : ''));
}
if (strstr(MODULE_PAYMENT_LINKPOINT_API_DEBUG, 'Email') || ($failure && strstr(MODULE_PAYMENT_LINKPOINT_API_DEBUG, 'Alert'))) {
zen_mail(STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, 'Linkpoint Debug Data' . ($failure ? ' - FAILURE' : ''), $errorMessage, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, array('EMAIL_MESSAGE_HTML'=>nl2br($errorMessage)), 'debug');
}
//DEBUG ONLY:$this->_log($errorMessage /*. print_r($myorder, true) . print_r($mylphp->xmlString, true)*/, $myorder["oid"]);
if ($myorder['debugging'] == 'true') exit;
return $result;
}
|
[
"function",
"_sendRequest",
"(",
"$",
"myorder",
")",
"{",
"$",
"myorder",
"[",
"\"host\"",
"]",
"=",
"\"secure.linkpt.net\"",
";",
"if",
"(",
"MODULE_PAYMENT_LINKPOINT_API_TRANSACTION_MODE",
"==",
"'DevelopersTest'",
")",
"{",
"$",
"myorder",
"[",
"\"host\"",
"]",
"=",
"\"staging.linkpt.net\"",
";",
"}",
"$",
"myorder",
"[",
"\"port\"",
"]",
"=",
"\"1129\"",
";",
"$",
"myorder",
"[",
"\"keyfile\"",
"]",
"=",
"(",
"DIR_FS_CATALOG",
".",
"DIR_WS_MODULES",
".",
"'payment/linkpoint_api/'",
".",
"MODULE_PAYMENT_LINKPOINT_API_LOGIN",
".",
"'.pem'",
")",
";",
"$",
"myorder",
"[",
"\"configfile\"",
"]",
"=",
"MODULE_PAYMENT_LINKPOINT_API_LOGIN",
";",
"// This is your store number",
"// set to ECI and UNSPECIFIED for ecommerce transactions:",
"$",
"myorder",
"[",
"\"transactionorigin\"",
"]",
"=",
"\"ECI\"",
";",
"$",
"myorder",
"[",
"\"terminaltype\"",
"]",
"=",
"\"UNSPECIFIED\"",
";",
"// debug - for testing communication only",
"if",
"(",
"MODULE_PAYMENT_LINKPOINT_API_DEBUG",
"!=",
"'Off'",
")",
"{",
"}",
"if",
"(",
"MODULE_PAYMENT_LINKPOINT_API_CODE_DEBUG",
"==",
"'debug'",
")",
"{",
"$",
"myorder",
"[",
"\"debugging\"",
"]",
"=",
"\"true\"",
";",
"// for development only - not intended for production use",
"$",
"myorder",
"[",
"\"debug\"",
"]",
"=",
"\"true\"",
";",
"// for development only - not intended for production use",
"$",
"myorder",
"[",
"\"webspace\"",
"]",
"=",
"\"true\"",
";",
"// for development only - not intended for production use",
"}",
"include",
"(",
"DIR_FS_CATALOG",
".",
"DIR_WS_MODULES",
".",
"'payment/linkpoint_api/class.linkpoint_api.php'",
")",
";",
"$",
"mylphp",
"=",
"new",
"lphp",
";",
"// Send transaction, using cURL",
"$",
"result",
"=",
"$",
"mylphp",
"->",
"curl_process",
"(",
"$",
"myorder",
")",
";",
"// do debug output",
"$",
"errorMessage",
"=",
"date",
"(",
"'M-d-Y h:i:s'",
")",
".",
"\"\\n=================================\\n\\n\"",
".",
"(",
"$",
"mylphp",
"->",
"commError",
"!=",
"''",
"?",
"$",
"mylphp",
"->",
"commError",
".",
"\"\\n\\n\"",
":",
"''",
")",
".",
"'Response Code: '",
".",
"$",
"result",
"[",
"\"r_approved\"",
"]",
".",
"' '",
".",
"$",
"result",
"[",
"\"r_error\"",
"]",
".",
"\"\\n\\n=================================\\n\\n\"",
".",
"'Sending to Gateway: '",
".",
"\"\\n\"",
".",
"$",
"mylphp",
"->",
"sendData",
".",
"\"\\n\\n\"",
".",
"'Result: '",
".",
"substr",
"(",
"print_r",
"(",
"$",
"result",
",",
"true",
")",
",",
"5",
")",
".",
"\"\\n\\n\"",
";",
"if",
"(",
"$",
"mylphp",
"->",
"commError",
"!=",
"''",
")",
"$",
"errorMessage",
".=",
"$",
"mylphp",
"->",
"commError",
".",
"\"\\n\"",
".",
"'CURL info: '",
".",
"print_r",
"(",
"$",
"mylphp",
"->",
"commInfo",
",",
"true",
")",
".",
"\"\\n\"",
";",
"if",
"(",
"CURL_PROXY_REQUIRED",
"==",
"'True'",
")",
"$",
"errorMessage",
".=",
"'Using CURL Proxy: ['",
".",
"CURL_PROXY_SERVER_DETAILS",
".",
"'] with Proxy Tunnel: '",
".",
"(",
"$",
"proxy_tunnel_flag",
"?",
"'On'",
":",
"'Off'",
")",
".",
"\"\\n\"",
";",
"$",
"failure",
"=",
"(",
"!",
"is_array",
"(",
"$",
"result",
")",
"||",
"$",
"result",
"[",
"\"r_approved\"",
"]",
"!=",
"\"APPROVED\"",
")",
"?",
"true",
":",
"false",
";",
"// handle logging",
"if",
"(",
"strstr",
"(",
"MODULE_PAYMENT_LINKPOINT_API_DEBUG",
",",
"'Log'",
")",
")",
"{",
"$",
"this",
"->",
"_log",
"(",
"$",
"errorMessage",
",",
"$",
"myorder",
"[",
"\"oid\"",
"]",
".",
"(",
"$",
"failure",
"?",
"'_FAILED'",
":",
"''",
")",
")",
";",
"// $this->_log($errorMessage . print_r($myorder, true) . print_r($mylphp->xmlString, true), $myorder[\"oid\"] . ($failure ? '_FAILED' : ''));",
"}",
"if",
"(",
"strstr",
"(",
"MODULE_PAYMENT_LINKPOINT_API_DEBUG",
",",
"'Email'",
")",
"||",
"(",
"$",
"failure",
"&&",
"strstr",
"(",
"MODULE_PAYMENT_LINKPOINT_API_DEBUG",
",",
"'Alert'",
")",
")",
")",
"{",
"zen_mail",
"(",
"STORE_NAME",
",",
"STORE_OWNER_EMAIL_ADDRESS",
",",
"'Linkpoint Debug Data'",
".",
"(",
"$",
"failure",
"?",
"' - FAILURE'",
":",
"''",
")",
",",
"$",
"errorMessage",
",",
"STORE_OWNER",
",",
"STORE_OWNER_EMAIL_ADDRESS",
",",
"array",
"(",
"'EMAIL_MESSAGE_HTML'",
"=>",
"nl2br",
"(",
"$",
"errorMessage",
")",
")",
",",
"'debug'",
")",
";",
"}",
"//DEBUG ONLY:$this->_log($errorMessage /*. print_r($myorder, true) . print_r($mylphp->xmlString, true)*/, $myorder[\"oid\"]);",
"if",
"(",
"$",
"myorder",
"[",
"'debugging'",
"]",
"==",
"'true'",
")",
"exit",
";",
"return",
"$",
"result",
";",
"}"
] |
Send transaction to gateway
|
[
"Send",
"transaction",
"to",
"gateway"
] |
00438ebc0faee786489aab4a6d70fc0d0c1461c7
|
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/payment/linkpoint_api.php#L789-L832
|
230,398
|
ZenMagick/ZenCart
|
includes/modules/payment/linkpoint_api.php
|
linkpoint_api._updateOrderStatus
|
function _updateOrderStatus($oID, $new_order_status, $comments) {
global $db;
$sql_data_array= array(array('fieldName'=>'orders_id', 'value' => $oID, 'type'=>'integer'),
array('fieldName'=>'orders_status_id', 'value' => $new_order_status, 'type'=>'integer'),
array('fieldName'=>'date_added', 'value' => 'now()', 'type'=>'noquotestring'),
array('fieldName'=>'comments', 'value' => $comments, 'type'=>'string'),
array('fieldName'=>'customer_notified', 'value' => 0, 'type'=>'integer'));
$db->perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
$db->Execute("update " . TABLE_ORDERS . "
set orders_status = '" . (int)$new_order_status . "'
where orders_id = '" . (int)$oID . "'");
}
|
php
|
function _updateOrderStatus($oID, $new_order_status, $comments) {
global $db;
$sql_data_array= array(array('fieldName'=>'orders_id', 'value' => $oID, 'type'=>'integer'),
array('fieldName'=>'orders_status_id', 'value' => $new_order_status, 'type'=>'integer'),
array('fieldName'=>'date_added', 'value' => 'now()', 'type'=>'noquotestring'),
array('fieldName'=>'comments', 'value' => $comments, 'type'=>'string'),
array('fieldName'=>'customer_notified', 'value' => 0, 'type'=>'integer'));
$db->perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
$db->Execute("update " . TABLE_ORDERS . "
set orders_status = '" . (int)$new_order_status . "'
where orders_id = '" . (int)$oID . "'");
}
|
[
"function",
"_updateOrderStatus",
"(",
"$",
"oID",
",",
"$",
"new_order_status",
",",
"$",
"comments",
")",
"{",
"global",
"$",
"db",
";",
"$",
"sql_data_array",
"=",
"array",
"(",
"array",
"(",
"'fieldName'",
"=>",
"'orders_id'",
",",
"'value'",
"=>",
"$",
"oID",
",",
"'type'",
"=>",
"'integer'",
")",
",",
"array",
"(",
"'fieldName'",
"=>",
"'orders_status_id'",
",",
"'value'",
"=>",
"$",
"new_order_status",
",",
"'type'",
"=>",
"'integer'",
")",
",",
"array",
"(",
"'fieldName'",
"=>",
"'date_added'",
",",
"'value'",
"=>",
"'now()'",
",",
"'type'",
"=>",
"'noquotestring'",
")",
",",
"array",
"(",
"'fieldName'",
"=>",
"'comments'",
",",
"'value'",
"=>",
"$",
"comments",
",",
"'type'",
"=>",
"'string'",
")",
",",
"array",
"(",
"'fieldName'",
"=>",
"'customer_notified'",
",",
"'value'",
"=>",
"0",
",",
"'type'",
"=>",
"'integer'",
")",
")",
";",
"$",
"db",
"->",
"perform",
"(",
"TABLE_ORDERS_STATUS_HISTORY",
",",
"$",
"sql_data_array",
")",
";",
"$",
"db",
"->",
"Execute",
"(",
"\"update \"",
".",
"TABLE_ORDERS",
".",
"\"\n set orders_status = '\"",
".",
"(",
"int",
")",
"$",
"new_order_status",
".",
"\"'\n where orders_id = '\"",
".",
"(",
"int",
")",
"$",
"oID",
".",
"\"'\"",
")",
";",
"}"
] |
Update order status and order status history based on admin changes sent to gateway
|
[
"Update",
"order",
"status",
"and",
"order",
"status",
"history",
"based",
"on",
"admin",
"changes",
"sent",
"to",
"gateway"
] |
00438ebc0faee786489aab4a6d70fc0d0c1461c7
|
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/payment/linkpoint_api.php#L837-L848
|
230,399
|
Webiny/Framework
|
src/Webiny/Component/ServiceManager/ServiceManager.php
|
ServiceManager.getService
|
public function getService($serviceName)
{
$serviceName = ltrim($serviceName, '@');
if (!isset($this->registeredServices[$serviceName])) {
throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]);
}
// Instantiate new service or get existing service instance
if (!isset($this->instantiatedServices[$serviceName])) {
$service = $this->instantiateService($serviceName);
} else {
$service = $this->instantiatedServices[$serviceName];
}
return $service;
}
|
php
|
public function getService($serviceName)
{
$serviceName = ltrim($serviceName, '@');
if (!isset($this->registeredServices[$serviceName])) {
throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]);
}
// Instantiate new service or get existing service instance
if (!isset($this->instantiatedServices[$serviceName])) {
$service = $this->instantiateService($serviceName);
} else {
$service = $this->instantiatedServices[$serviceName];
}
return $service;
}
|
[
"public",
"function",
"getService",
"(",
"$",
"serviceName",
")",
"{",
"$",
"serviceName",
"=",
"ltrim",
"(",
"$",
"serviceName",
",",
"'@'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"registeredServices",
"[",
"$",
"serviceName",
"]",
")",
")",
"{",
"throw",
"new",
"ServiceManagerException",
"(",
"ServiceManagerException",
"::",
"SERVICE_DEFINITION_NOT_FOUND",
",",
"[",
"$",
"serviceName",
"]",
")",
";",
"}",
"// Instantiate new service or get existing service instance",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"instantiatedServices",
"[",
"$",
"serviceName",
"]",
")",
")",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"instantiateService",
"(",
"$",
"serviceName",
")",
";",
"}",
"else",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"instantiatedServices",
"[",
"$",
"serviceName",
"]",
";",
"}",
"return",
"$",
"service",
";",
"}"
] |
Get service instance by given name nad optional arguments
@param string $serviceName Requested service name
@throws ServiceManagerException
@return object
|
[
"Get",
"service",
"instance",
"by",
"given",
"name",
"nad",
"optional",
"arguments"
] |
2ca7fb238999387e54a1eea8c5cb4735de9022a7
|
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ServiceManager.php#L46-L61
|
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.