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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
232,400
|
youngguns-nl/moneybird_php_api
|
Domainmodel/AbstractModel.php
|
AbstractModel.setDirtyState
|
protected function setDirtyState($isDirty, $attr = null)
{
return $isDirty ? $this->setDirty($attr) : $this->setClean($attr);
}
|
php
|
protected function setDirtyState($isDirty, $attr = null)
{
return $isDirty ? $this->setDirty($attr) : $this->setClean($attr);
}
|
[
"protected",
"function",
"setDirtyState",
"(",
"$",
"isDirty",
",",
"$",
"attr",
"=",
"null",
")",
"{",
"return",
"$",
"isDirty",
"?",
"$",
"this",
"->",
"setDirty",
"(",
"$",
"attr",
")",
":",
"$",
"this",
"->",
"setClean",
"(",
"$",
"attr",
")",
";",
"}"
] |
Set dirty state based on bool
@param bool $isDirty
@param string $attr Name of attribute, if null (default) change state of all attribures
@return self
|
[
"Set",
"dirty",
"state",
"based",
"on",
"bool"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/Domainmodel/AbstractModel.php#L333-L336
|
232,401
|
youngguns-nl/moneybird_php_api
|
Domainmodel/AbstractModel.php
|
AbstractModel.copy
|
protected function copy(Array $filter = array())
{
$filter = array_flip(array_merge($filter, $this->_readonlyAttr));
$copy = new $this();
$attributes = $this->selfToArray();
foreach ($attributes as $key => &$value) {
if (array_key_exists($key, $filter)) {
unset($attributes[$key]);
} elseif ($value instanceof ArrayObject) {
try {
$newElements = $value->copy($filter);
$value = new $value;
foreach ($newElements as $elmCopy) {
$value->append($elmCopy);
}
} catch (ArrayObject\UndefinedMethodException $e) {
// pass
}
} elseif ($value instanceof AbstractModel) {
$value = $value->copy($filter);
}
}
$copy->setData($attributes);
return $copy;
}
|
php
|
protected function copy(Array $filter = array())
{
$filter = array_flip(array_merge($filter, $this->_readonlyAttr));
$copy = new $this();
$attributes = $this->selfToArray();
foreach ($attributes as $key => &$value) {
if (array_key_exists($key, $filter)) {
unset($attributes[$key]);
} elseif ($value instanceof ArrayObject) {
try {
$newElements = $value->copy($filter);
$value = new $value;
foreach ($newElements as $elmCopy) {
$value->append($elmCopy);
}
} catch (ArrayObject\UndefinedMethodException $e) {
// pass
}
} elseif ($value instanceof AbstractModel) {
$value = $value->copy($filter);
}
}
$copy->setData($attributes);
return $copy;
}
|
[
"protected",
"function",
"copy",
"(",
"Array",
"$",
"filter",
"=",
"array",
"(",
")",
")",
"{",
"$",
"filter",
"=",
"array_flip",
"(",
"array_merge",
"(",
"$",
"filter",
",",
"$",
"this",
"->",
"_readonlyAttr",
")",
")",
";",
"$",
"copy",
"=",
"new",
"$",
"this",
"(",
")",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"selfToArray",
"(",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"filter",
")",
")",
"{",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"ArrayObject",
")",
"{",
"try",
"{",
"$",
"newElements",
"=",
"$",
"value",
"->",
"copy",
"(",
"$",
"filter",
")",
";",
"$",
"value",
"=",
"new",
"$",
"value",
";",
"foreach",
"(",
"$",
"newElements",
"as",
"$",
"elmCopy",
")",
"{",
"$",
"value",
"->",
"append",
"(",
"$",
"elmCopy",
")",
";",
"}",
"}",
"catch",
"(",
"ArrayObject",
"\\",
"UndefinedMethodException",
"$",
"e",
")",
"{",
"// pass",
"}",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"AbstractModel",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"copy",
"(",
"$",
"filter",
")",
";",
"}",
"}",
"$",
"copy",
"->",
"setData",
"(",
"$",
"attributes",
")",
";",
"return",
"$",
"copy",
";",
"}"
] |
Copy the object
@param Array $filter Attributes not to copy
@return self
|
[
"Copy",
"the",
"object"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/Domainmodel/AbstractModel.php#L355-L380
|
232,402
|
axypro/sourcemap
|
parsing/Mappings.php
|
Mappings.addPosition
|
public function addPosition(PosMap $position)
{
$generated = $position->generated;
$nl = $generated->line;
if (isset($this->lines[$nl])) {
$this->lines[$nl]->addPosition($position);
} else {
$this->lines[$nl] = new Line($nl, [$generated->column => $position]);
}
$this->sMappings = null;
}
|
php
|
public function addPosition(PosMap $position)
{
$generated = $position->generated;
$nl = $generated->line;
if (isset($this->lines[$nl])) {
$this->lines[$nl]->addPosition($position);
} else {
$this->lines[$nl] = new Line($nl, [$generated->column => $position]);
}
$this->sMappings = null;
}
|
[
"public",
"function",
"addPosition",
"(",
"PosMap",
"$",
"position",
")",
"{",
"$",
"generated",
"=",
"$",
"position",
"->",
"generated",
";",
"$",
"nl",
"=",
"$",
"generated",
"->",
"line",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"lines",
"[",
"$",
"nl",
"]",
")",
")",
"{",
"$",
"this",
"->",
"lines",
"[",
"$",
"nl",
"]",
"->",
"addPosition",
"(",
"$",
"position",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"lines",
"[",
"$",
"nl",
"]",
"=",
"new",
"Line",
"(",
"$",
"nl",
",",
"[",
"$",
"generated",
"->",
"column",
"=>",
"$",
"position",
"]",
")",
";",
"}",
"$",
"this",
"->",
"sMappings",
"=",
"null",
";",
"}"
] |
Adds a position to the mappings
@param \axy\sourcemap\PosMap
|
[
"Adds",
"a",
"position",
"to",
"the",
"mappings"
] |
f5793e5d166bf2a1735e27676007a21c121e20af
|
https://github.com/axypro/sourcemap/blob/f5793e5d166bf2a1735e27676007a21c121e20af/parsing/Mappings.php#L46-L56
|
232,403
|
axypro/sourcemap
|
parsing/Mappings.php
|
Mappings.pack
|
public function pack()
{
$parser = new SegmentParser();
if ($this->sMappings === null) {
$ln = [];
$max = max(array_keys($this->lines));
for ($i = 0; $i <= $max; $i++) {
if (isset($this->lines[$i])) {
$parser->nextLine($i);
$ln[] = $this->lines[$i]->pack($parser);
} else {
$ln[] = '';
}
}
$this->sMappings = implode(';', $ln);
}
return $this->sMappings;
}
|
php
|
public function pack()
{
$parser = new SegmentParser();
if ($this->sMappings === null) {
$ln = [];
$max = max(array_keys($this->lines));
for ($i = 0; $i <= $max; $i++) {
if (isset($this->lines[$i])) {
$parser->nextLine($i);
$ln[] = $this->lines[$i]->pack($parser);
} else {
$ln[] = '';
}
}
$this->sMappings = implode(';', $ln);
}
return $this->sMappings;
}
|
[
"public",
"function",
"pack",
"(",
")",
"{",
"$",
"parser",
"=",
"new",
"SegmentParser",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"sMappings",
"===",
"null",
")",
"{",
"$",
"ln",
"=",
"[",
"]",
";",
"$",
"max",
"=",
"max",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"lines",
")",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"$",
"max",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"lines",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"parser",
"->",
"nextLine",
"(",
"$",
"i",
")",
";",
"$",
"ln",
"[",
"]",
"=",
"$",
"this",
"->",
"lines",
"[",
"$",
"i",
"]",
"->",
"pack",
"(",
"$",
"parser",
")",
";",
"}",
"else",
"{",
"$",
"ln",
"[",
"]",
"=",
"''",
";",
"}",
"}",
"$",
"this",
"->",
"sMappings",
"=",
"implode",
"(",
"';'",
",",
"$",
"ln",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sMappings",
";",
"}"
] |
Packs the mappings
@return string
|
[
"Packs",
"the",
"mappings"
] |
f5793e5d166bf2a1735e27676007a21c121e20af
|
https://github.com/axypro/sourcemap/blob/f5793e5d166bf2a1735e27676007a21c121e20af/parsing/Mappings.php#L176-L193
|
232,404
|
axypro/sourcemap
|
parsing/Mappings.php
|
Mappings.getStat
|
public function getStat()
{
$sources = [];
$names = [];
foreach ($this->lines as $line) {
$line->loadStat($sources, $names);
}
return [
'sources' => $sources,
'names' => $names,
];
}
|
php
|
public function getStat()
{
$sources = [];
$names = [];
foreach ($this->lines as $line) {
$line->loadStat($sources, $names);
}
return [
'sources' => $sources,
'names' => $names,
];
}
|
[
"public",
"function",
"getStat",
"(",
")",
"{",
"$",
"sources",
"=",
"[",
"]",
";",
"$",
"names",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"line",
"->",
"loadStat",
"(",
"$",
"sources",
",",
"$",
"names",
")",
";",
"}",
"return",
"[",
"'sources'",
"=>",
"$",
"sources",
",",
"'names'",
"=>",
"$",
"names",
",",
"]",
";",
"}"
] |
Returns statistic by sources and names
@return array
|
[
"Returns",
"statistic",
"by",
"sources",
"and",
"names"
] |
f5793e5d166bf2a1735e27676007a21c121e20af
|
https://github.com/axypro/sourcemap/blob/f5793e5d166bf2a1735e27676007a21c121e20af/parsing/Mappings.php#L357-L368
|
232,405
|
axypro/sourcemap
|
parsing/Mappings.php
|
Mappings.parse
|
private function parse()
{
$this->lines = [];
$parser = new SegmentParser();
foreach (explode(';', $this->sMappings) as $num => $sLine) {
$sLine = trim($sLine);
if ($sLine !== '') {
$this->lines[$num] = Line::loadFromMappings($num, $sLine, $parser, $this->context);
}
}
}
|
php
|
private function parse()
{
$this->lines = [];
$parser = new SegmentParser();
foreach (explode(';', $this->sMappings) as $num => $sLine) {
$sLine = trim($sLine);
if ($sLine !== '') {
$this->lines[$num] = Line::loadFromMappings($num, $sLine, $parser, $this->context);
}
}
}
|
[
"private",
"function",
"parse",
"(",
")",
"{",
"$",
"this",
"->",
"lines",
"=",
"[",
"]",
";",
"$",
"parser",
"=",
"new",
"SegmentParser",
"(",
")",
";",
"foreach",
"(",
"explode",
"(",
"';'",
",",
"$",
"this",
"->",
"sMappings",
")",
"as",
"$",
"num",
"=>",
"$",
"sLine",
")",
"{",
"$",
"sLine",
"=",
"trim",
"(",
"$",
"sLine",
")",
";",
"if",
"(",
"$",
"sLine",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"lines",
"[",
"$",
"num",
"]",
"=",
"Line",
"::",
"loadFromMappings",
"(",
"$",
"num",
",",
"$",
"sLine",
",",
"$",
"parser",
",",
"$",
"this",
"->",
"context",
")",
";",
"}",
"}",
"}"
] |
Parses the mappings string
|
[
"Parses",
"the",
"mappings",
"string"
] |
f5793e5d166bf2a1735e27676007a21c121e20af
|
https://github.com/axypro/sourcemap/blob/f5793e5d166bf2a1735e27676007a21c121e20af/parsing/Mappings.php#L451-L461
|
232,406
|
usystems/webling-api-php
|
src/Webling/API/Client.php
|
Client.getApiUrl
|
protected function getApiUrl($path) {
// remove extra / at the beginning
$path = ltrim($path, '/');
// prepend protocol if not passed
$protocol = '';
if(strpos($this->domain, 'http://') !== 0 && strpos($this->domain, 'https://') !== 0) {
$protocol = 'https://';
}
// assemble final url
return $protocol . $this->domain . '/api/' . self::API_VERSION . '/' . $path;
}
|
php
|
protected function getApiUrl($path) {
// remove extra / at the beginning
$path = ltrim($path, '/');
// prepend protocol if not passed
$protocol = '';
if(strpos($this->domain, 'http://') !== 0 && strpos($this->domain, 'https://') !== 0) {
$protocol = 'https://';
}
// assemble final url
return $protocol . $this->domain . '/api/' . self::API_VERSION . '/' . $path;
}
|
[
"protected",
"function",
"getApiUrl",
"(",
"$",
"path",
")",
"{",
"// remove extra / at the beginning",
"$",
"path",
"=",
"ltrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"// prepend protocol if not passed",
"$",
"protocol",
"=",
"''",
";",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"domain",
",",
"'http://'",
")",
"!==",
"0",
"&&",
"strpos",
"(",
"$",
"this",
"->",
"domain",
",",
"'https://'",
")",
"!==",
"0",
")",
"{",
"$",
"protocol",
"=",
"'https://'",
";",
"}",
"// assemble final url",
"return",
"$",
"protocol",
".",
"$",
"this",
"->",
"domain",
".",
"'/api/'",
".",
"self",
"::",
"API_VERSION",
".",
"'/'",
".",
"$",
"path",
";",
"}"
] |
Build full URL
@param $path
@return string assembled url
|
[
"Build",
"full",
"URL"
] |
ff3f65f8b944998d116f666af4b0b707a5b4b92d
|
https://github.com/usystems/webling-api-php/blob/ff3f65f8b944998d116f666af4b0b707a5b4b92d/src/Webling/API/Client.php#L139-L151
|
232,407
|
usystems/webling-api-php
|
src/Webling/API/Client.php
|
Client.getCurlObject
|
protected function getCurlObject($url, $method = 'GET') {
$curl = new CurlHttp();
$curl->curl_setopt(CURLOPT_URL, $url);
$curl->curl_setopt(CURLOPT_CUSTOMREQUEST, $method);
$curl->curl_setopt(CURLOPT_RETURNTRANSFER, true);
$curl->curl_setopt(CURLOPT_HTTPHEADER, ['apikey:' . $this->apikey] );
$this->applyOptionsToCurl($curl);
return $curl;
}
|
php
|
protected function getCurlObject($url, $method = 'GET') {
$curl = new CurlHttp();
$curl->curl_setopt(CURLOPT_URL, $url);
$curl->curl_setopt(CURLOPT_CUSTOMREQUEST, $method);
$curl->curl_setopt(CURLOPT_RETURNTRANSFER, true);
$curl->curl_setopt(CURLOPT_HTTPHEADER, ['apikey:' . $this->apikey] );
$this->applyOptionsToCurl($curl);
return $curl;
}
|
[
"protected",
"function",
"getCurlObject",
"(",
"$",
"url",
",",
"$",
"method",
"=",
"'GET'",
")",
"{",
"$",
"curl",
"=",
"new",
"CurlHttp",
"(",
")",
";",
"$",
"curl",
"->",
"curl_setopt",
"(",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"$",
"curl",
"->",
"curl_setopt",
"(",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"method",
")",
";",
"$",
"curl",
"->",
"curl_setopt",
"(",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"$",
"curl",
"->",
"curl_setopt",
"(",
"CURLOPT_HTTPHEADER",
",",
"[",
"'apikey:'",
".",
"$",
"this",
"->",
"apikey",
"]",
")",
";",
"$",
"this",
"->",
"applyOptionsToCurl",
"(",
"$",
"curl",
")",
";",
"return",
"$",
"curl",
";",
"}"
] |
Get a new curl instance, encapsulated to make it mockable
@param string $url - Request url
@param string $method - HTTP method
@return CurlHttp get a new curl object
|
[
"Get",
"a",
"new",
"curl",
"instance",
"encapsulated",
"to",
"make",
"it",
"mockable"
] |
ff3f65f8b944998d116f666af4b0b707a5b4b92d
|
https://github.com/usystems/webling-api-php/blob/ff3f65f8b944998d116f666af4b0b707a5b4b92d/src/Webling/API/Client.php#L171-L179
|
232,408
|
monarkee/bumble
|
Services/S3FileService.php
|
S3FileService.write
|
public function write()
{
// If the local filesystem has the uploaded file
if (file_exists($this->file->getRealPath()))
{
// Read the local uploaded file
$file = file_get_contents($this->file->getRealPath());
// Write it to the S3 location
return $this->remote->write($this->attributes['upload_to'] . '/' . $this->attributes['filename'], $file, ['visibility' => 'public']);
}
throw new Exception('The uploaded file was not found on the filesystem');
}
|
php
|
public function write()
{
// If the local filesystem has the uploaded file
if (file_exists($this->file->getRealPath()))
{
// Read the local uploaded file
$file = file_get_contents($this->file->getRealPath());
// Write it to the S3 location
return $this->remote->write($this->attributes['upload_to'] . '/' . $this->attributes['filename'], $file, ['visibility' => 'public']);
}
throw new Exception('The uploaded file was not found on the filesystem');
}
|
[
"public",
"function",
"write",
"(",
")",
"{",
"// If the local filesystem has the uploaded file",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"file",
"->",
"getRealPath",
"(",
")",
")",
")",
"{",
"// Read the local uploaded file",
"$",
"file",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"file",
"->",
"getRealPath",
"(",
")",
")",
";",
"// Write it to the S3 location",
"return",
"$",
"this",
"->",
"remote",
"->",
"write",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'upload_to'",
"]",
".",
"'/'",
".",
"$",
"this",
"->",
"attributes",
"[",
"'filename'",
"]",
",",
"$",
"file",
",",
"[",
"'visibility'",
"=>",
"'public'",
"]",
")",
";",
"}",
"throw",
"new",
"Exception",
"(",
"'The uploaded file was not found on the filesystem'",
")",
";",
"}"
] |
Write a file to the filesystem
|
[
"Write",
"a",
"file",
"to",
"the",
"filesystem"
] |
6e140e341980d6f9467418594eed48c3859c00f7
|
https://github.com/monarkee/bumble/blob/6e140e341980d6f9467418594eed48c3859c00f7/Services/S3FileService.php#L63-L76
|
232,409
|
jack-theripper/transcoder
|
src/Filter/Rotate.php
|
Rotate.setAngleDegrees
|
public function setAngleDegrees($degree)
{
if ( ! is_numeric($degree))
{
throw new \InvalidArgumentException('Angle degrees must be a numeric.');
}
$this->setAngle($degree * pi() / 180);
return $this;
}
|
php
|
public function setAngleDegrees($degree)
{
if ( ! is_numeric($degree))
{
throw new \InvalidArgumentException('Angle degrees must be a numeric.');
}
$this->setAngle($degree * pi() / 180);
return $this;
}
|
[
"public",
"function",
"setAngleDegrees",
"(",
"$",
"degree",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"degree",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Angle degrees must be a numeric.'",
")",
";",
"}",
"$",
"this",
"->",
"setAngle",
"(",
"$",
"degree",
"*",
"pi",
"(",
")",
"/",
"180",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
The angle value in degrees.
@param int $degree
@return Rotate
@throws \InvalidArgumentException
|
[
"The",
"angle",
"value",
"in",
"degrees",
"."
] |
bd87db4c76ccceafa9fc271b14013ebf12e0b32e
|
https://github.com/jack-theripper/transcoder/blob/bd87db4c76ccceafa9fc271b14013ebf12e0b32e/src/Filter/Rotate.php#L115-L125
|
232,410
|
jack-theripper/transcoder
|
src/Filter/Rotate.php
|
Rotate.setColor
|
public function setColor($color)
{
if ( ! $this->isValidColor($color))
{
throw new \InvalidArgumentException('Invalid color format.');
}
$this->color = (string) $color;
return $this;
}
|
php
|
public function setColor($color)
{
if ( ! $this->isValidColor($color))
{
throw new \InvalidArgumentException('Invalid color format.');
}
$this->color = (string) $color;
return $this;
}
|
[
"public",
"function",
"setColor",
"(",
"$",
"color",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValidColor",
"(",
"$",
"color",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid color format.'",
")",
";",
"}",
"$",
"this",
"->",
"color",
"=",
"(",
"string",
")",
"$",
"color",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the color used to fill the output area not covered by the rotated image.
@param string $color
@return Rotate
|
[
"Set",
"the",
"color",
"used",
"to",
"fill",
"the",
"output",
"area",
"not",
"covered",
"by",
"the",
"rotated",
"image",
"."
] |
bd87db4c76ccceafa9fc271b14013ebf12e0b32e
|
https://github.com/jack-theripper/transcoder/blob/bd87db4c76ccceafa9fc271b14013ebf12e0b32e/src/Filter/Rotate.php#L196-L206
|
232,411
|
jack-theripper/transcoder
|
src/Filter/Rotate.php
|
Rotate.isValidColor
|
protected function isValidColor($color)
{
$regexp = '\(([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\)';
return preg_grep("/{$color}/i", $this->getColors()) || preg_match('/^#(\d|a|b|c|d|e|f){3}$/i', $color)
|| preg_match('/^#(\d|a|b|c|d|e|f){6}$/i', $color) || preg_match('/^(rgb)'.$regexp.'$/i', $color)
|| preg_match('/^(rgba)'.$regexp.'?\W+([01](\.\d+)?)\)$/i', $color);
}
|
php
|
protected function isValidColor($color)
{
$regexp = '\(([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\W+([01]?\d\d?|2[0-4]\d|25[0-5])\)';
return preg_grep("/{$color}/i", $this->getColors()) || preg_match('/^#(\d|a|b|c|d|e|f){3}$/i', $color)
|| preg_match('/^#(\d|a|b|c|d|e|f){6}$/i', $color) || preg_match('/^(rgb)'.$regexp.'$/i', $color)
|| preg_match('/^(rgba)'.$regexp.'?\W+([01](\.\d+)?)\)$/i', $color);
}
|
[
"protected",
"function",
"isValidColor",
"(",
"$",
"color",
")",
"{",
"$",
"regexp",
"=",
"'\\(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\W+([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\W+([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\)'",
";",
"return",
"preg_grep",
"(",
"\"/{$color}/i\"",
",",
"$",
"this",
"->",
"getColors",
"(",
")",
")",
"||",
"preg_match",
"(",
"'/^#(\\d|a|b|c|d|e|f){3}$/i'",
",",
"$",
"color",
")",
"||",
"preg_match",
"(",
"'/^#(\\d|a|b|c|d|e|f){6}$/i'",
",",
"$",
"color",
")",
"||",
"preg_match",
"(",
"'/^(rgb)'",
".",
"$",
"regexp",
".",
"'$/i'",
",",
"$",
"color",
")",
"||",
"preg_match",
"(",
"'/^(rgba)'",
".",
"$",
"regexp",
".",
"'?\\W+([01](\\.\\d+)?)\\)$/i'",
",",
"$",
"color",
")",
";",
"}"
] |
Test on a valid color.
@param string $color
@return bool
|
[
"Test",
"on",
"a",
"valid",
"color",
"."
] |
bd87db4c76ccceafa9fc271b14013ebf12e0b32e
|
https://github.com/jack-theripper/transcoder/blob/bd87db4c76ccceafa9fc271b14013ebf12e0b32e/src/Filter/Rotate.php#L376-L383
|
232,412
|
nineinchnick/yii2-usr
|
controllers/AuthController.php
|
AuthController.actionLogout
|
public function actionLogout($provider = null, $returnUrl = null)
{
/** @var ProfileForm */
$model = $this->module->createFormModel('ProfileForm');
// AuthForm creates an association using lowercase provider
$model->getIdentity()->removeRemoteIdentity(strtolower($provider));
$this->redirect($returnUrl !== null ? $returnUrl : Yii::app()->homeUrl);
}
|
php
|
public function actionLogout($provider = null, $returnUrl = null)
{
/** @var ProfileForm */
$model = $this->module->createFormModel('ProfileForm');
// AuthForm creates an association using lowercase provider
$model->getIdentity()->removeRemoteIdentity(strtolower($provider));
$this->redirect($returnUrl !== null ? $returnUrl : Yii::app()->homeUrl);
}
|
[
"public",
"function",
"actionLogout",
"(",
"$",
"provider",
"=",
"null",
",",
"$",
"returnUrl",
"=",
"null",
")",
"{",
"/** @var ProfileForm */",
"$",
"model",
"=",
"$",
"this",
"->",
"module",
"->",
"createFormModel",
"(",
"'ProfileForm'",
")",
";",
"// AuthForm creates an association using lowercase provider",
"$",
"model",
"->",
"getIdentity",
"(",
")",
"->",
"removeRemoteIdentity",
"(",
"strtolower",
"(",
"$",
"provider",
")",
")",
";",
"$",
"this",
"->",
"redirect",
"(",
"$",
"returnUrl",
"!==",
"null",
"?",
"$",
"returnUrl",
":",
"Yii",
"::",
"app",
"(",
")",
"->",
"homeUrl",
")",
";",
"}"
] |
This action actually removes association with a remote profile instead of logging out.
@param string $provider name of the remote provider
|
[
"This",
"action",
"actually",
"removes",
"association",
"with",
"a",
"remote",
"profile",
"instead",
"of",
"logging",
"out",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/controllers/AuthController.php#L146-L153
|
232,413
|
youngguns-nl/moneybird_php_api
|
HttpClient.php
|
HttpClient.setAuth
|
public function setAuth($username, $password)
{
$this->connectionOptions[CURLOPT_USERPWD] = $username . ':' . $password;
$this->connectionOptions[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
return $this;
}
|
php
|
public function setAuth($username, $password)
{
$this->connectionOptions[CURLOPT_USERPWD] = $username . ':' . $password;
$this->connectionOptions[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
return $this;
}
|
[
"public",
"function",
"setAuth",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"this",
"->",
"connectionOptions",
"[",
"CURLOPT_USERPWD",
"]",
"=",
"$",
"username",
".",
"':'",
".",
"$",
"password",
";",
"$",
"this",
"->",
"connectionOptions",
"[",
"CURLOPT_HTTPAUTH",
"]",
"=",
"CURLAUTH_BASIC",
";",
"return",
"$",
"this",
";",
"}"
] |
Set credentials for the connection
@param string $username Username
@param string $password Password
@access public
@return HttpClient
|
[
"Set",
"credentials",
"for",
"the",
"connection"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/HttpClient.php#L109-L114
|
232,414
|
youngguns-nl/moneybird_php_api
|
HttpClient.php
|
HttpClient.setConnectionOptions
|
protected function setConnectionOptions(Array $options)
{
if (!is_resource($this->connection)) {
throw new ConnectionErrorException('cURL connection has not been set up yet!');
}
if (!curl_setopt_array($this->connection, $options)) {
throw new ConnectionErrorException('Unable to set cURL options' . PHP_EOL . curl_error($this->connection));
}
return $this;
}
|
php
|
protected function setConnectionOptions(Array $options)
{
if (!is_resource($this->connection)) {
throw new ConnectionErrorException('cURL connection has not been set up yet!');
}
if (!curl_setopt_array($this->connection, $options)) {
throw new ConnectionErrorException('Unable to set cURL options' . PHP_EOL . curl_error($this->connection));
}
return $this;
}
|
[
"protected",
"function",
"setConnectionOptions",
"(",
"Array",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"connection",
")",
")",
"{",
"throw",
"new",
"ConnectionErrorException",
"(",
"'cURL connection has not been set up yet!'",
")",
";",
"}",
"if",
"(",
"!",
"curl_setopt_array",
"(",
"$",
"this",
"->",
"connection",
",",
"$",
"options",
")",
")",
"{",
"throw",
"new",
"ConnectionErrorException",
"(",
"'Unable to set cURL options'",
".",
"PHP_EOL",
".",
"curl_error",
"(",
"$",
"this",
"->",
"connection",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set connection options
@param array $options
@throws ConnectionErrorException
@access protected
@return HttpClient
|
[
"Set",
"connection",
"options"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/HttpClient.php#L156-L165
|
232,415
|
youngguns-nl/moneybird_php_api
|
HttpClient.php
|
HttpClient.prePutRequest
|
protected function prePutRequest($data)
{
$this->tmpFile = tmpfile();
fwrite($this->tmpFile, $data);
rewind($this->tmpFile);
$this->setConnectionOptions(array(
CURLOPT_PUT => true,
CURLOPT_INFILE => $this->tmpFile,
CURLOPT_INFILESIZE => strlen($data),
));
return $this;
}
|
php
|
protected function prePutRequest($data)
{
$this->tmpFile = tmpfile();
fwrite($this->tmpFile, $data);
rewind($this->tmpFile);
$this->setConnectionOptions(array(
CURLOPT_PUT => true,
CURLOPT_INFILE => $this->tmpFile,
CURLOPT_INFILESIZE => strlen($data),
));
return $this;
}
|
[
"protected",
"function",
"prePutRequest",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"tmpFile",
"=",
"tmpfile",
"(",
")",
";",
"fwrite",
"(",
"$",
"this",
"->",
"tmpFile",
",",
"$",
"data",
")",
";",
"rewind",
"(",
"$",
"this",
"->",
"tmpFile",
")",
";",
"$",
"this",
"->",
"setConnectionOptions",
"(",
"array",
"(",
"CURLOPT_PUT",
"=>",
"true",
",",
"CURLOPT_INFILE",
"=>",
"$",
"this",
"->",
"tmpFile",
",",
"CURLOPT_INFILESIZE",
"=>",
"strlen",
"(",
"$",
"data",
")",
",",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Prepare PUT request
@return HttpClient
@access protected
|
[
"Prepare",
"PUT",
"request"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/HttpClient.php#L216-L228
|
232,416
|
youngguns-nl/moneybird_php_api
|
HttpClient.php
|
HttpClient.handleError
|
protected function handleError()
{
$okStatus = array(
100, 200, 201,
);
$messages = array(
401 => 'Authorization required',
403 => 'Forbidden request',
404 => 'Not found',
406 => 'Not accepted',
422 => 'Unprocessable entity',
500 => 'Internal server error',
501 => 'Method not implemented',
);
if (isset($messages[$this->httpStatus])) {
throw new HttpStatusException($messages[$this->httpStatus], $this->httpStatus);
}
if (!in_array($this->httpStatus, $okStatus)) {
throw new UnknownHttpStatusException('Unknown http status: ' . $this->httpStatus);
}
}
|
php
|
protected function handleError()
{
$okStatus = array(
100, 200, 201,
);
$messages = array(
401 => 'Authorization required',
403 => 'Forbidden request',
404 => 'Not found',
406 => 'Not accepted',
422 => 'Unprocessable entity',
500 => 'Internal server error',
501 => 'Method not implemented',
);
if (isset($messages[$this->httpStatus])) {
throw new HttpStatusException($messages[$this->httpStatus], $this->httpStatus);
}
if (!in_array($this->httpStatus, $okStatus)) {
throw new UnknownHttpStatusException('Unknown http status: ' . $this->httpStatus);
}
}
|
[
"protected",
"function",
"handleError",
"(",
")",
"{",
"$",
"okStatus",
"=",
"array",
"(",
"100",
",",
"200",
",",
"201",
",",
")",
";",
"$",
"messages",
"=",
"array",
"(",
"401",
"=>",
"'Authorization required'",
",",
"403",
"=>",
"'Forbidden request'",
",",
"404",
"=>",
"'Not found'",
",",
"406",
"=>",
"'Not accepted'",
",",
"422",
"=>",
"'Unprocessable entity'",
",",
"500",
"=>",
"'Internal server error'",
",",
"501",
"=>",
"'Method not implemented'",
",",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"messages",
"[",
"$",
"this",
"->",
"httpStatus",
"]",
")",
")",
"{",
"throw",
"new",
"HttpStatusException",
"(",
"$",
"messages",
"[",
"$",
"this",
"->",
"httpStatus",
"]",
",",
"$",
"this",
"->",
"httpStatus",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"httpStatus",
",",
"$",
"okStatus",
")",
")",
"{",
"throw",
"new",
"UnknownHttpStatusException",
"(",
"'Unknown http status: '",
".",
"$",
"this",
"->",
"httpStatus",
")",
";",
"}",
"}"
] |
Throws exceptions if httpStatus contains error status
@throws HttpStatusException
@throws UnknownHttpStatusException
@access protected
|
[
"Throws",
"exceptions",
"if",
"httpStatus",
"contains",
"error",
"status"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/HttpClient.php#L306-L327
|
232,417
|
youngguns-nl/moneybird_php_api
|
HttpClient.php
|
HttpClient.exec
|
protected function exec()
{
static $loops = 0;
static $maxLoops = 20;
if ($loops++ >= $maxLoops) {
$loops = 0;
throw new ConnectionErrorException('Too many redirects in request');
}
$curl_return = curl_exec($this->connection);
if ($curl_return === false) {
throw new CurlErrorException(curl_error($this->connection));
}
$response = explode("\r\n\r\n", $curl_return, 2);
$this->httpStatus = curl_getinfo($this->connection, CURLINFO_HTTP_CODE);
$header = isset($response[0]) ? $response[0] : '';
$data = isset($response[1]) ? $response[1] : '';
// Ignore Continue header
if ($header == "HTTP/1.1 100 Continue") {
$response = explode("\r\n\r\n", $data, 2);
$header = isset($response[0]) ? $response[0] : '';
$data = isset($response[1]) ? $response[1] : '';
}
$this->lastHeader = $header;
$this->response = $data;
if ($this->httpStatus == 301 || $this->httpStatus == 302) {
$matches = array();
preg_match('/Location:(.*?)\n/', $header, $matches);
$url = @parse_url(trim(array_pop($matches)));
if (!$url) {
//couldn't process the url to redirect to
$loops = 0;
throw new ConnectionErrorException('Invalid redirect');
}
$this->setConnectionOptions(array(
CURLOPT_URL => $url['scheme'] . '://' . $url['host'] . $url['path'] . (!empty($url['query']) ? '?' . $url['query'] : '')
));
$this->exec();
}
$loops = 0;
$this->handleError();
return $this;
}
|
php
|
protected function exec()
{
static $loops = 0;
static $maxLoops = 20;
if ($loops++ >= $maxLoops) {
$loops = 0;
throw new ConnectionErrorException('Too many redirects in request');
}
$curl_return = curl_exec($this->connection);
if ($curl_return === false) {
throw new CurlErrorException(curl_error($this->connection));
}
$response = explode("\r\n\r\n", $curl_return, 2);
$this->httpStatus = curl_getinfo($this->connection, CURLINFO_HTTP_CODE);
$header = isset($response[0]) ? $response[0] : '';
$data = isset($response[1]) ? $response[1] : '';
// Ignore Continue header
if ($header == "HTTP/1.1 100 Continue") {
$response = explode("\r\n\r\n", $data, 2);
$header = isset($response[0]) ? $response[0] : '';
$data = isset($response[1]) ? $response[1] : '';
}
$this->lastHeader = $header;
$this->response = $data;
if ($this->httpStatus == 301 || $this->httpStatus == 302) {
$matches = array();
preg_match('/Location:(.*?)\n/', $header, $matches);
$url = @parse_url(trim(array_pop($matches)));
if (!$url) {
//couldn't process the url to redirect to
$loops = 0;
throw new ConnectionErrorException('Invalid redirect');
}
$this->setConnectionOptions(array(
CURLOPT_URL => $url['scheme'] . '://' . $url['host'] . $url['path'] . (!empty($url['query']) ? '?' . $url['query'] : '')
));
$this->exec();
}
$loops = 0;
$this->handleError();
return $this;
}
|
[
"protected",
"function",
"exec",
"(",
")",
"{",
"static",
"$",
"loops",
"=",
"0",
";",
"static",
"$",
"maxLoops",
"=",
"20",
";",
"if",
"(",
"$",
"loops",
"++",
">=",
"$",
"maxLoops",
")",
"{",
"$",
"loops",
"=",
"0",
";",
"throw",
"new",
"ConnectionErrorException",
"(",
"'Too many redirects in request'",
")",
";",
"}",
"$",
"curl_return",
"=",
"curl_exec",
"(",
"$",
"this",
"->",
"connection",
")",
";",
"if",
"(",
"$",
"curl_return",
"===",
"false",
")",
"{",
"throw",
"new",
"CurlErrorException",
"(",
"curl_error",
"(",
"$",
"this",
"->",
"connection",
")",
")",
";",
"}",
"$",
"response",
"=",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"$",
"curl_return",
",",
"2",
")",
";",
"$",
"this",
"->",
"httpStatus",
"=",
"curl_getinfo",
"(",
"$",
"this",
"->",
"connection",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"$",
"header",
"=",
"isset",
"(",
"$",
"response",
"[",
"0",
"]",
")",
"?",
"$",
"response",
"[",
"0",
"]",
":",
"''",
";",
"$",
"data",
"=",
"isset",
"(",
"$",
"response",
"[",
"1",
"]",
")",
"?",
"$",
"response",
"[",
"1",
"]",
":",
"''",
";",
"// Ignore Continue header",
"if",
"(",
"$",
"header",
"==",
"\"HTTP/1.1 100 Continue\"",
")",
"{",
"$",
"response",
"=",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"$",
"data",
",",
"2",
")",
";",
"$",
"header",
"=",
"isset",
"(",
"$",
"response",
"[",
"0",
"]",
")",
"?",
"$",
"response",
"[",
"0",
"]",
":",
"''",
";",
"$",
"data",
"=",
"isset",
"(",
"$",
"response",
"[",
"1",
"]",
")",
"?",
"$",
"response",
"[",
"1",
"]",
":",
"''",
";",
"}",
"$",
"this",
"->",
"lastHeader",
"=",
"$",
"header",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"data",
";",
"if",
"(",
"$",
"this",
"->",
"httpStatus",
"==",
"301",
"||",
"$",
"this",
"->",
"httpStatus",
"==",
"302",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"preg_match",
"(",
"'/Location:(.*?)\\n/'",
",",
"$",
"header",
",",
"$",
"matches",
")",
";",
"$",
"url",
"=",
"@",
"parse_url",
"(",
"trim",
"(",
"array_pop",
"(",
"$",
"matches",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"//couldn't process the url to redirect to",
"$",
"loops",
"=",
"0",
";",
"throw",
"new",
"ConnectionErrorException",
"(",
"'Invalid redirect'",
")",
";",
"}",
"$",
"this",
"->",
"setConnectionOptions",
"(",
"array",
"(",
"CURLOPT_URL",
"=>",
"$",
"url",
"[",
"'scheme'",
"]",
".",
"'://'",
".",
"$",
"url",
"[",
"'host'",
"]",
".",
"$",
"url",
"[",
"'path'",
"]",
".",
"(",
"!",
"empty",
"(",
"$",
"url",
"[",
"'query'",
"]",
")",
"?",
"'?'",
".",
"$",
"url",
"[",
"'query'",
"]",
":",
"''",
")",
")",
")",
";",
"$",
"this",
"->",
"exec",
"(",
")",
";",
"}",
"$",
"loops",
"=",
"0",
";",
"$",
"this",
"->",
"handleError",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Execute request
Redirects via cURL option CURLOPT_FOLLOWLOCATION won't work if safe mode
or open basedir is active
@access protected
@return HttpClient
@throws HttpStatusException
@throws UnknownHttpStatusException
@throws ConnectionErrorException
|
[
"Execute",
"request",
"Redirects",
"via",
"cURL",
"option",
"CURLOPT_FOLLOWLOCATION",
"won",
"t",
"work",
"if",
"safe",
"mode",
"or",
"open",
"basedir",
"is",
"active"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/HttpClient.php#L340-L393
|
232,418
|
jack-theripper/transcoder
|
src/Point.php
|
Point.setX
|
protected function setX($x)
{
if ( ! is_numeric($x) || $x < 0)
{
throw new \InvalidArgumentException('The value of x must be a positive numeric.');
}
$this->x = (int) $x;
return $this;
}
|
php
|
protected function setX($x)
{
if ( ! is_numeric($x) || $x < 0)
{
throw new \InvalidArgumentException('The value of x must be a positive numeric.');
}
$this->x = (int) $x;
return $this;
}
|
[
"protected",
"function",
"setX",
"(",
"$",
"x",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"x",
")",
"||",
"$",
"x",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The value of x must be a positive numeric.'",
")",
";",
"}",
"$",
"this",
"->",
"x",
"=",
"(",
"int",
")",
"$",
"x",
";",
"return",
"$",
"this",
";",
"}"
] |
Set X value.
@param int $x
@return Point
@throws \InvalidArgumentException
|
[
"Set",
"X",
"value",
"."
] |
bd87db4c76ccceafa9fc271b14013ebf12e0b32e
|
https://github.com/jack-theripper/transcoder/blob/bd87db4c76ccceafa9fc271b14013ebf12e0b32e/src/Point.php#L88-L98
|
232,419
|
jack-theripper/transcoder
|
src/Point.php
|
Point.setY
|
protected function setY($y)
{
if ( ! is_numeric($y) || $y < 0)
{
throw new \InvalidArgumentException('The value of y must be a positive numeric.');
}
$this->y = (int) $y;
return $this;
}
|
php
|
protected function setY($y)
{
if ( ! is_numeric($y) || $y < 0)
{
throw new \InvalidArgumentException('The value of y must be a positive numeric.');
}
$this->y = (int) $y;
return $this;
}
|
[
"protected",
"function",
"setY",
"(",
"$",
"y",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"y",
")",
"||",
"$",
"y",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The value of y must be a positive numeric.'",
")",
";",
"}",
"$",
"this",
"->",
"y",
"=",
"(",
"int",
")",
"$",
"y",
";",
"return",
"$",
"this",
";",
"}"
] |
Set Y value.
@param int $y
@return Point
@throws \InvalidArgumentException
|
[
"Set",
"Y",
"value",
"."
] |
bd87db4c76ccceafa9fc271b14013ebf12e0b32e
|
https://github.com/jack-theripper/transcoder/blob/bd87db4c76ccceafa9fc271b14013ebf12e0b32e/src/Point.php#L108-L118
|
232,420
|
jack-theripper/transcoder
|
src/Filter/Graph.php
|
Graph.insert
|
public function insert($filter, $priority)
{
if ( ! $filter instanceof FilterInterface)
{
throw new \InvalidArgumentException('The filter must be an instance of FilterInterface.');
}
if ($filter instanceof FilterChainInterface)
{
parent::insert($filter, [-$priority, $this->serial--]);
}
else
{
if ($this->isEmpty())
{
parent::insert(new FilterChain(), [0, $this->serial--]);
}
$this->top()->addFilter($filter, $priority);
}
return $this;
}
|
php
|
public function insert($filter, $priority)
{
if ( ! $filter instanceof FilterInterface)
{
throw new \InvalidArgumentException('The filter must be an instance of FilterInterface.');
}
if ($filter instanceof FilterChainInterface)
{
parent::insert($filter, [-$priority, $this->serial--]);
}
else
{
if ($this->isEmpty())
{
parent::insert(new FilterChain(), [0, $this->serial--]);
}
$this->top()->addFilter($filter, $priority);
}
return $this;
}
|
[
"public",
"function",
"insert",
"(",
"$",
"filter",
",",
"$",
"priority",
")",
"{",
"if",
"(",
"!",
"$",
"filter",
"instanceof",
"FilterInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The filter must be an instance of FilterInterface.'",
")",
";",
"}",
"if",
"(",
"$",
"filter",
"instanceof",
"FilterChainInterface",
")",
"{",
"parent",
"::",
"insert",
"(",
"$",
"filter",
",",
"[",
"-",
"$",
"priority",
",",
"$",
"this",
"->",
"serial",
"--",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"parent",
"::",
"insert",
"(",
"new",
"FilterChain",
"(",
")",
",",
"[",
"0",
",",
"$",
"this",
"->",
"serial",
"--",
"]",
")",
";",
"}",
"$",
"this",
"->",
"top",
"(",
")",
"->",
"addFilter",
"(",
"$",
"filter",
",",
"$",
"priority",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Inserts an element in the queue by sifting it up.
@param FilterInterface $filter
@param mixed $priority The associated priority.
@return Graph
@throws \Arhitector\Transcoder\Exception\InvalidFilterException
@throws \InvalidArgumentException
|
[
"Inserts",
"an",
"element",
"in",
"the",
"queue",
"by",
"sifting",
"it",
"up",
"."
] |
bd87db4c76ccceafa9fc271b14013ebf12e0b32e
|
https://github.com/jack-theripper/transcoder/blob/bd87db4c76ccceafa9fc271b14013ebf12e0b32e/src/Filter/Graph.php#L48-L70
|
232,421
|
shawm11/hawk-auth-php
|
RoboFile.php
|
RoboFile.releasePatch
|
public function releasePatch()
{
$execution = $this->taskExecStack()
->stopOnFail()
->exec(
'"./vendor/bin/robo" git:stash "release-patch-'
. (new \DateTime)->format(\DateTime::ISO8601) . '"'
)
->exec('"./vendor/bin/robo" lint')
->exec('"./vendor/bin/robo" test')
->exec('"./vendor/bin/robo" git:stash-pop')
->exec('"./vendor/bin/robo" bump:patch')
->exec('"./vendor/bin/robo" bump:commit')
->exec('"./vendor/bin/robo" git:push-master')
->run();
if (!$execution->wasSuccessful()) {
$this->io()->error('PATCH RELEASE FAILED!');
$this->_exec('"./vendor/bin/robo" git:stash-pop');
}
return $execution;
}
|
php
|
public function releasePatch()
{
$execution = $this->taskExecStack()
->stopOnFail()
->exec(
'"./vendor/bin/robo" git:stash "release-patch-'
. (new \DateTime)->format(\DateTime::ISO8601) . '"'
)
->exec('"./vendor/bin/robo" lint')
->exec('"./vendor/bin/robo" test')
->exec('"./vendor/bin/robo" git:stash-pop')
->exec('"./vendor/bin/robo" bump:patch')
->exec('"./vendor/bin/robo" bump:commit')
->exec('"./vendor/bin/robo" git:push-master')
->run();
if (!$execution->wasSuccessful()) {
$this->io()->error('PATCH RELEASE FAILED!');
$this->_exec('"./vendor/bin/robo" git:stash-pop');
}
return $execution;
}
|
[
"public",
"function",
"releasePatch",
"(",
")",
"{",
"$",
"execution",
"=",
"$",
"this",
"->",
"taskExecStack",
"(",
")",
"->",
"stopOnFail",
"(",
")",
"->",
"exec",
"(",
"'\"./vendor/bin/robo\" git:stash \"release-patch-'",
".",
"(",
"new",
"\\",
"DateTime",
")",
"->",
"format",
"(",
"\\",
"DateTime",
"::",
"ISO8601",
")",
".",
"'\"'",
")",
"->",
"exec",
"(",
"'\"./vendor/bin/robo\" lint'",
")",
"->",
"exec",
"(",
"'\"./vendor/bin/robo\" test'",
")",
"->",
"exec",
"(",
"'\"./vendor/bin/robo\" git:stash-pop'",
")",
"->",
"exec",
"(",
"'\"./vendor/bin/robo\" bump:patch'",
")",
"->",
"exec",
"(",
"'\"./vendor/bin/robo\" bump:commit'",
")",
"->",
"exec",
"(",
"'\"./vendor/bin/robo\" git:push-master'",
")",
"->",
"run",
"(",
")",
";",
"if",
"(",
"!",
"$",
"execution",
"->",
"wasSuccessful",
"(",
")",
")",
"{",
"$",
"this",
"->",
"io",
"(",
")",
"->",
"error",
"(",
"'PATCH RELEASE FAILED!'",
")",
";",
"$",
"this",
"->",
"_exec",
"(",
"'\"./vendor/bin/robo\" git:stash-pop'",
")",
";",
"}",
"return",
"$",
"execution",
";",
"}"
] |
Bump the PATCH version and release to the remote repository master branch
|
[
"Bump",
"the",
"PATCH",
"version",
"and",
"release",
"to",
"the",
"remote",
"repository",
"master",
"branch"
] |
c3629078a86a65745f8f8ce47a962184da3492bb
|
https://github.com/shawm11/hawk-auth-php/blob/c3629078a86a65745f8f8ce47a962184da3492bb/RoboFile.php#L185-L207
|
232,422
|
shawm11/hawk-auth-php
|
RoboFile.php
|
RoboFile.setComposerVersion
|
private function setComposerVersion($semver)
{
$this->composerJson['version'] = $semver->getVersion();
file_put_contents(
'composer.json',
json_encode($this->composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
|
php
|
private function setComposerVersion($semver)
{
$this->composerJson['version'] = $semver->getVersion();
file_put_contents(
'composer.json',
json_encode($this->composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
|
[
"private",
"function",
"setComposerVersion",
"(",
"$",
"semver",
")",
"{",
"$",
"this",
"->",
"composerJson",
"[",
"'version'",
"]",
"=",
"$",
"semver",
"->",
"getVersion",
"(",
")",
";",
"file_put_contents",
"(",
"'composer.json'",
",",
"json_encode",
"(",
"$",
"this",
"->",
"composerJson",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_SLASHES",
")",
")",
";",
"}"
] |
Set the project's version number stored in the composer.json file
@param \vierbergenlars\SemVer\version $semver
|
[
"Set",
"the",
"project",
"s",
"version",
"number",
"stored",
"in",
"the",
"composer",
".",
"json",
"file"
] |
c3629078a86a65745f8f8ce47a962184da3492bb
|
https://github.com/shawm11/hawk-auth-php/blob/c3629078a86a65745f8f8ce47a962184da3492bb/RoboFile.php#L234-L241
|
232,423
|
mmanos/laravel-api
|
src/Mmanos/Api/Exceptions/HttpException.php
|
HttpException.body
|
public function body()
{
$msg = $this->getMessage();
if (422 == $this->getCode() && !empty($msg)) {
$this->extra['errors'] = json_decode($msg, true);
$msg = null;
}
if (empty($msg)) {
switch ($this->getCode()) {
case 404:
$msg = 'Not Found';
break;
case 405:
$msg = 'Method Not Allowed';
break;
case 400:
$msg = 'Bad Request';
break;
case 401:
$msg = 'Unauthorized';
break;
case 402:
$msg = 'Payment Required';
break;
case 403:
$msg = 'Forbidden';
break;
case 422:
$msg = 'Unprocessable Entity';
break;
case 410:
$msg = 'Resource Deleted';
break;
case 500:
$msg = 'Server Error';
break;
default:
$msg = 'Error';
}
}
$output = array(
'status' => $this->getCode(),
'message' => $msg,
);
if (!empty($this->getExtra())) {
$output = array_merge($output, $this->getExtra());
}
return $output;
}
|
php
|
public function body()
{
$msg = $this->getMessage();
if (422 == $this->getCode() && !empty($msg)) {
$this->extra['errors'] = json_decode($msg, true);
$msg = null;
}
if (empty($msg)) {
switch ($this->getCode()) {
case 404:
$msg = 'Not Found';
break;
case 405:
$msg = 'Method Not Allowed';
break;
case 400:
$msg = 'Bad Request';
break;
case 401:
$msg = 'Unauthorized';
break;
case 402:
$msg = 'Payment Required';
break;
case 403:
$msg = 'Forbidden';
break;
case 422:
$msg = 'Unprocessable Entity';
break;
case 410:
$msg = 'Resource Deleted';
break;
case 500:
$msg = 'Server Error';
break;
default:
$msg = 'Error';
}
}
$output = array(
'status' => $this->getCode(),
'message' => $msg,
);
if (!empty($this->getExtra())) {
$output = array_merge($output, $this->getExtra());
}
return $output;
}
|
[
"public",
"function",
"body",
"(",
")",
"{",
"$",
"msg",
"=",
"$",
"this",
"->",
"getMessage",
"(",
")",
";",
"if",
"(",
"422",
"==",
"$",
"this",
"->",
"getCode",
"(",
")",
"&&",
"!",
"empty",
"(",
"$",
"msg",
")",
")",
"{",
"$",
"this",
"->",
"extra",
"[",
"'errors'",
"]",
"=",
"json_decode",
"(",
"$",
"msg",
",",
"true",
")",
";",
"$",
"msg",
"=",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"msg",
")",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getCode",
"(",
")",
")",
"{",
"case",
"404",
":",
"$",
"msg",
"=",
"'Not Found'",
";",
"break",
";",
"case",
"405",
":",
"$",
"msg",
"=",
"'Method Not Allowed'",
";",
"break",
";",
"case",
"400",
":",
"$",
"msg",
"=",
"'Bad Request'",
";",
"break",
";",
"case",
"401",
":",
"$",
"msg",
"=",
"'Unauthorized'",
";",
"break",
";",
"case",
"402",
":",
"$",
"msg",
"=",
"'Payment Required'",
";",
"break",
";",
"case",
"403",
":",
"$",
"msg",
"=",
"'Forbidden'",
";",
"break",
";",
"case",
"422",
":",
"$",
"msg",
"=",
"'Unprocessable Entity'",
";",
"break",
";",
"case",
"410",
":",
"$",
"msg",
"=",
"'Resource Deleted'",
";",
"break",
";",
"case",
"500",
":",
"$",
"msg",
"=",
"'Server Error'",
";",
"break",
";",
"default",
":",
"$",
"msg",
"=",
"'Error'",
";",
"}",
"}",
"$",
"output",
"=",
"array",
"(",
"'status'",
"=>",
"$",
"this",
"->",
"getCode",
"(",
")",
",",
"'message'",
"=>",
"$",
"msg",
",",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"getExtra",
"(",
")",
")",
")",
"{",
"$",
"output",
"=",
"array_merge",
"(",
"$",
"output",
",",
"$",
"this",
"->",
"getExtra",
"(",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Return the response body array.
@return array
|
[
"Return",
"the",
"response",
"body",
"array",
"."
] |
8fac248d91c797f4a8f960e7cd7466df5a814975
|
https://github.com/mmanos/laravel-api/blob/8fac248d91c797f4a8f960e7cd7466df5a814975/src/Mmanos/Api/Exceptions/HttpException.php#L45-L98
|
232,424
|
jr-cologne/db-class
|
src/QueryBuilder.php
|
QueryBuilder.resetProperties
|
public function resetProperties() {
$this->mode = $this->columns = $this->where = $this->values = $this->data = null;
}
|
php
|
public function resetProperties() {
$this->mode = $this->columns = $this->where = $this->values = $this->data = null;
}
|
[
"public",
"function",
"resetProperties",
"(",
")",
"{",
"$",
"this",
"->",
"mode",
"=",
"$",
"this",
"->",
"columns",
"=",
"$",
"this",
"->",
"where",
"=",
"$",
"this",
"->",
"values",
"=",
"$",
"this",
"->",
"data",
"=",
"null",
";",
"}"
] |
Resets the properties for the query.
|
[
"Resets",
"the",
"properties",
"for",
"the",
"query",
"."
] |
6578f51b5fb8ffe96687bcf1b8e490c2c848a396
|
https://github.com/jr-cologne/db-class/blob/6578f51b5fb8ffe96687bcf1b8e490c2c848a396/src/QueryBuilder.php#L92-L94
|
232,425
|
jr-cologne/db-class
|
src/QueryBuilder.php
|
QueryBuilder.formatColumns
|
protected function formatColumns($columns) : string {
if (is_string($columns)) {
if ($columns === '*') {
return $columns;
}
$columns = explode(',', $columns);
$columns = array_map(function ($column) {
return '`' . trim($column) . '`';
}, $columns);
return implode(', ', $columns);
}
if (is_array($columns)) {
return '`' . implode('`, `', $columns) . '`';
}
}
|
php
|
protected function formatColumns($columns) : string {
if (is_string($columns)) {
if ($columns === '*') {
return $columns;
}
$columns = explode(',', $columns);
$columns = array_map(function ($column) {
return '`' . trim($column) . '`';
}, $columns);
return implode(', ', $columns);
}
if (is_array($columns)) {
return '`' . implode('`, `', $columns) . '`';
}
}
|
[
"protected",
"function",
"formatColumns",
"(",
"$",
"columns",
")",
":",
"string",
"{",
"if",
"(",
"is_string",
"(",
"$",
"columns",
")",
")",
"{",
"if",
"(",
"$",
"columns",
"===",
"'*'",
")",
"{",
"return",
"$",
"columns",
";",
"}",
"$",
"columns",
"=",
"explode",
"(",
"','",
",",
"$",
"columns",
")",
";",
"$",
"columns",
"=",
"array_map",
"(",
"function",
"(",
"$",
"column",
")",
"{",
"return",
"'`'",
".",
"trim",
"(",
"$",
"column",
")",
".",
"'`'",
";",
"}",
",",
"$",
"columns",
")",
";",
"return",
"implode",
"(",
"', '",
",",
"$",
"columns",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"columns",
")",
")",
"{",
"return",
"'`'",
".",
"implode",
"(",
"'`, `'",
",",
"$",
"columns",
")",
".",
"'`'",
";",
"}",
"}"
] |
Formats the columns for the query.
@param mixed $columns
@return string
|
[
"Formats",
"the",
"columns",
"for",
"the",
"query",
"."
] |
6578f51b5fb8ffe96687bcf1b8e490c2c848a396
|
https://github.com/jr-cologne/db-class/blob/6578f51b5fb8ffe96687bcf1b8e490c2c848a396/src/QueryBuilder.php#L156-L174
|
232,426
|
jr-cologne/db-class
|
src/QueryBuilder.php
|
QueryBuilder.formatWhere
|
protected function formatWhere(array $where) : string {
$where_clause = '';
foreach ($where as $column => $value) {
$logical_operator = null;
if (is_numeric($column) && is_array($value)) {
$where_clause .= "`{$value[0]}` {$value[1]} :where_{$value[0]}";
} else if (is_numeric($column) && is_string($value)) {
$logical_operator = $value;
} else {
$where_clause .= "`{$column}` = :where_{$column}";
}
$next_value = next($where);
$next_key = key($where);
if ( $next_value !== false && !is_null($next_key) && (!is_numeric($next_key) || !is_string($next_value)) ) {
$logical_operator = $logical_operator ?? '&&';
$where_clause .= " {$logical_operator} ";
}
}
return $where_clause;
}
|
php
|
protected function formatWhere(array $where) : string {
$where_clause = '';
foreach ($where as $column => $value) {
$logical_operator = null;
if (is_numeric($column) && is_array($value)) {
$where_clause .= "`{$value[0]}` {$value[1]} :where_{$value[0]}";
} else if (is_numeric($column) && is_string($value)) {
$logical_operator = $value;
} else {
$where_clause .= "`{$column}` = :where_{$column}";
}
$next_value = next($where);
$next_key = key($where);
if ( $next_value !== false && !is_null($next_key) && (!is_numeric($next_key) || !is_string($next_value)) ) {
$logical_operator = $logical_operator ?? '&&';
$where_clause .= " {$logical_operator} ";
}
}
return $where_clause;
}
|
[
"protected",
"function",
"formatWhere",
"(",
"array",
"$",
"where",
")",
":",
"string",
"{",
"$",
"where_clause",
"=",
"''",
";",
"foreach",
"(",
"$",
"where",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"logical_operator",
"=",
"null",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"column",
")",
"&&",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"where_clause",
".=",
"\"`{$value[0]}` {$value[1]} :where_{$value[0]}\"",
";",
"}",
"else",
"if",
"(",
"is_numeric",
"(",
"$",
"column",
")",
"&&",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"logical_operator",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"where_clause",
".=",
"\"`{$column}` = :where_{$column}\"",
";",
"}",
"$",
"next_value",
"=",
"next",
"(",
"$",
"where",
")",
";",
"$",
"next_key",
"=",
"key",
"(",
"$",
"where",
")",
";",
"if",
"(",
"$",
"next_value",
"!==",
"false",
"&&",
"!",
"is_null",
"(",
"$",
"next_key",
")",
"&&",
"(",
"!",
"is_numeric",
"(",
"$",
"next_key",
")",
"||",
"!",
"is_string",
"(",
"$",
"next_value",
")",
")",
")",
"{",
"$",
"logical_operator",
"=",
"$",
"logical_operator",
"??",
"'&&'",
";",
"$",
"where_clause",
".=",
"\" {$logical_operator} \"",
";",
"}",
"}",
"return",
"$",
"where_clause",
";",
"}"
] |
Formats the where clause for the query.
@param array $where
@return string
|
[
"Formats",
"the",
"where",
"clause",
"for",
"the",
"query",
"."
] |
6578f51b5fb8ffe96687bcf1b8e490c2c848a396
|
https://github.com/jr-cologne/db-class/blob/6578f51b5fb8ffe96687bcf1b8e490c2c848a396/src/QueryBuilder.php#L182-L207
|
232,427
|
jr-cologne/db-class
|
src/QueryBuilder.php
|
QueryBuilder.formatValues
|
protected function formatValues($values) : string {
if (is_array($values)) {
return ':' . implode(', :', $values);
}
if (is_string($values)) {
$values = explode(',', $values);
$values = array_map(function($value) {
return ':' . trim($value);
}, $values);
return implode(', ', $values);
}
}
|
php
|
protected function formatValues($values) : string {
if (is_array($values)) {
return ':' . implode(', :', $values);
}
if (is_string($values)) {
$values = explode(',', $values);
$values = array_map(function($value) {
return ':' . trim($value);
}, $values);
return implode(', ', $values);
}
}
|
[
"protected",
"function",
"formatValues",
"(",
"$",
"values",
")",
":",
"string",
"{",
"if",
"(",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"return",
"':'",
".",
"implode",
"(",
"', :'",
",",
"$",
"values",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"explode",
"(",
"','",
",",
"$",
"values",
")",
";",
"$",
"values",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"':'",
".",
"trim",
"(",
"$",
"value",
")",
";",
"}",
",",
"$",
"values",
")",
";",
"return",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
";",
"}",
"}"
] |
Formats the values for the insert query.
@param mixed $values
@return string
|
[
"Formats",
"the",
"values",
"for",
"the",
"insert",
"query",
"."
] |
6578f51b5fb8ffe96687bcf1b8e490c2c848a396
|
https://github.com/jr-cologne/db-class/blob/6578f51b5fb8ffe96687bcf1b8e490c2c848a396/src/QueryBuilder.php#L215-L229
|
232,428
|
jr-cologne/db-class
|
src/QueryBuilder.php
|
QueryBuilder.formatData
|
protected function formatData(array $data) : string {
$data_string = '';
foreach ($data as $column => $value) {
$data_string .= "`{$column}` = :{$column}";
if (next($data) !== false) {
$data_string .= ', ';
}
}
return $data_string;
}
|
php
|
protected function formatData(array $data) : string {
$data_string = '';
foreach ($data as $column => $value) {
$data_string .= "`{$column}` = :{$column}";
if (next($data) !== false) {
$data_string .= ', ';
}
}
return $data_string;
}
|
[
"protected",
"function",
"formatData",
"(",
"array",
"$",
"data",
")",
":",
"string",
"{",
"$",
"data_string",
"=",
"''",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"data_string",
".=",
"\"`{$column}` = :{$column}\"",
";",
"if",
"(",
"next",
"(",
"$",
"data",
")",
"!==",
"false",
")",
"{",
"$",
"data_string",
".=",
"', '",
";",
"}",
"}",
"return",
"$",
"data_string",
";",
"}"
] |
Formats the data for the update query.
@param array $data
@return string
|
[
"Formats",
"the",
"data",
"for",
"the",
"update",
"query",
"."
] |
6578f51b5fb8ffe96687bcf1b8e490c2c848a396
|
https://github.com/jr-cologne/db-class/blob/6578f51b5fb8ffe96687bcf1b8e490c2c848a396/src/QueryBuilder.php#L237-L249
|
232,429
|
youngguns-nl/moneybird_php_api
|
Payment/AbstractPayment.php
|
AbstractPayment.setPaymentMethodAttr
|
protected function setPaymentMethodAttr($value, $isDirty = true)
{
if ($value !== null && $value !== '' && !in_array($value, $this->_paymentMethods)) {
throw new InvalidMethodException('Invalid payment method: ' . $value);
}
$this->paymentMethod = $value;
$this->setDirtyState($isDirty, 'paymentMethod');
}
|
php
|
protected function setPaymentMethodAttr($value, $isDirty = true)
{
if ($value !== null && $value !== '' && !in_array($value, $this->_paymentMethods)) {
throw new InvalidMethodException('Invalid payment method: ' . $value);
}
$this->paymentMethod = $value;
$this->setDirtyState($isDirty, 'paymentMethod');
}
|
[
"protected",
"function",
"setPaymentMethodAttr",
"(",
"$",
"value",
",",
"$",
"isDirty",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
"&&",
"$",
"value",
"!==",
"''",
"&&",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"_paymentMethods",
")",
")",
"{",
"throw",
"new",
"InvalidMethodException",
"(",
"'Invalid payment method: '",
".",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"paymentMethod",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"setDirtyState",
"(",
"$",
"isDirty",
",",
"'paymentMethod'",
")",
";",
"}"
] |
Set payment method
@param string $value
@param bool $isDirty new value is dirty, defaults to true
@throws InvalidMethodException
|
[
"Set",
"payment",
"method"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/Payment/AbstractPayment.php#L56-L64
|
232,430
|
youngguns-nl/moneybird_php_api
|
Contact/Service.php
|
Service.saveNote
|
public function saveNote(Note $note, Contact $contact)
{
return $this->connector->save($note, $contact);
}
|
php
|
public function saveNote(Note $note, Contact $contact)
{
return $this->connector->save($note, $contact);
}
|
[
"public",
"function",
"saveNote",
"(",
"Note",
"$",
"note",
",",
"Contact",
"$",
"contact",
")",
"{",
"return",
"$",
"this",
"->",
"connector",
"->",
"save",
"(",
"$",
"note",
",",
"$",
"contact",
")",
";",
"}"
] |
Inserts contact note
@param Note $note
@param Contact $contact
@return Note
|
[
"Inserts",
"contact",
"note"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/Contact/Service.php#L110-L113
|
232,431
|
youngguns-nl/moneybird_php_api
|
Contact/Service.php
|
Service.deleteNote
|
public function deleteNote(Note $note, Contact $contact)
{
$this->connector->delete($note, $contact);
return $this;
}
|
php
|
public function deleteNote(Note $note, Contact $contact)
{
$this->connector->delete($note, $contact);
return $this;
}
|
[
"public",
"function",
"deleteNote",
"(",
"Note",
"$",
"note",
",",
"Contact",
"$",
"contact",
")",
"{",
"$",
"this",
"->",
"connector",
"->",
"delete",
"(",
"$",
"note",
",",
"$",
"contact",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Delete contact note
@param Note $note
@param Contact $contact
@return self
|
[
"Delete",
"contact",
"note"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/Contact/Service.php#L121-L125
|
232,432
|
mmanos/laravel-api
|
src/Mmanos/Api/ApiServiceProvider.php
|
ApiServiceProvider.bootFilters
|
protected function bootFilters()
{
if (config('api.cors_enabled', true)) {
$this->app['router']->before(function ($request) {
if (Request::header('Origin') && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
$response = Response::make(null, 204);
Cors::attachHeaders($response);
Cors::attachOriginHeader($response, Request::header('Origin'));
return $response;
}
});
$this->app['router']->after(function ($request, $response) {
if (Request::header('Origin')) {
Cors::attachHeaders($response);
Cors::attachOriginHeader($response, Request::header('Origin'));
}
});
}
$this->app['router']->filter('protect', function ($route, $request) {
Api::protect();
});
$this->app['router']->filter('checkscope', function ($route, $request, $scope = '') {
// B/c Laravel uses : as a special character already.
$scope = str_replace('.', ':', $scope);
Api::checkScope($scope);
});
}
|
php
|
protected function bootFilters()
{
if (config('api.cors_enabled', true)) {
$this->app['router']->before(function ($request) {
if (Request::header('Origin') && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
$response = Response::make(null, 204);
Cors::attachHeaders($response);
Cors::attachOriginHeader($response, Request::header('Origin'));
return $response;
}
});
$this->app['router']->after(function ($request, $response) {
if (Request::header('Origin')) {
Cors::attachHeaders($response);
Cors::attachOriginHeader($response, Request::header('Origin'));
}
});
}
$this->app['router']->filter('protect', function ($route, $request) {
Api::protect();
});
$this->app['router']->filter('checkscope', function ($route, $request, $scope = '') {
// B/c Laravel uses : as a special character already.
$scope = str_replace('.', ':', $scope);
Api::checkScope($scope);
});
}
|
[
"protected",
"function",
"bootFilters",
"(",
")",
"{",
"if",
"(",
"config",
"(",
"'api.cors_enabled'",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'router'",
"]",
"->",
"before",
"(",
"function",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"Request",
"::",
"header",
"(",
"'Origin'",
")",
"&&",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"===",
"'OPTIONS'",
")",
"{",
"$",
"response",
"=",
"Response",
"::",
"make",
"(",
"null",
",",
"204",
")",
";",
"Cors",
"::",
"attachHeaders",
"(",
"$",
"response",
")",
";",
"Cors",
"::",
"attachOriginHeader",
"(",
"$",
"response",
",",
"Request",
"::",
"header",
"(",
"'Origin'",
")",
")",
";",
"return",
"$",
"response",
";",
"}",
"}",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'router'",
"]",
"->",
"after",
"(",
"function",
"(",
"$",
"request",
",",
"$",
"response",
")",
"{",
"if",
"(",
"Request",
"::",
"header",
"(",
"'Origin'",
")",
")",
"{",
"Cors",
"::",
"attachHeaders",
"(",
"$",
"response",
")",
";",
"Cors",
"::",
"attachOriginHeader",
"(",
"$",
"response",
",",
"Request",
"::",
"header",
"(",
"'Origin'",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"$",
"this",
"->",
"app",
"[",
"'router'",
"]",
"->",
"filter",
"(",
"'protect'",
",",
"function",
"(",
"$",
"route",
",",
"$",
"request",
")",
"{",
"Api",
"::",
"protect",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'router'",
"]",
"->",
"filter",
"(",
"'checkscope'",
",",
"function",
"(",
"$",
"route",
",",
"$",
"request",
",",
"$",
"scope",
"=",
"''",
")",
"{",
"// B/c Laravel uses : as a special character already.",
"$",
"scope",
"=",
"str_replace",
"(",
"'.'",
",",
"':'",
",",
"$",
"scope",
")",
";",
"Api",
"::",
"checkScope",
"(",
"$",
"scope",
")",
";",
"}",
")",
";",
"}"
] |
Add route filters.
@return void
|
[
"Add",
"route",
"filters",
"."
] |
8fac248d91c797f4a8f960e7cd7466df5a814975
|
https://github.com/mmanos/laravel-api/blob/8fac248d91c797f4a8f960e7cd7466df5a814975/src/Mmanos/Api/ApiServiceProvider.php#L86-L116
|
232,433
|
chippyash/Builder-Pattern
|
src/Chippyash/BuilderPattern/Renderer/XmlRenderer.php
|
XmlRenderer.arrayToDomNode
|
protected function arrayToDomNode(\DOMDocument $dom, \DOMElement $node, array $arr)
{
foreach ($arr as $key => $item) {
$ref = null;
if (is_numeric($key) || empty($key)) {
if (is_numeric($key)) {
$ref = $key;
}
$key = 'item';
}
if (is_array($item)) {
$newNode = $dom->createElement($key);
if (!is_null($ref)) {
$attr = $dom->createAttribute('ref');
$attr->value = $ref;
$newNode->appendChild($attr);
}
$this->arrayToDomNode($dom, $newNode, $item);
$node->appendChild($newNode);
} elseif (is_object($item)) {
$this->encodeObject($key, $item, $dom, $node);
} else {
$node->appendChild($dom->createElement($key, $item));
}
}
}
|
php
|
protected function arrayToDomNode(\DOMDocument $dom, \DOMElement $node, array $arr)
{
foreach ($arr as $key => $item) {
$ref = null;
if (is_numeric($key) || empty($key)) {
if (is_numeric($key)) {
$ref = $key;
}
$key = 'item';
}
if (is_array($item)) {
$newNode = $dom->createElement($key);
if (!is_null($ref)) {
$attr = $dom->createAttribute('ref');
$attr->value = $ref;
$newNode->appendChild($attr);
}
$this->arrayToDomNode($dom, $newNode, $item);
$node->appendChild($newNode);
} elseif (is_object($item)) {
$this->encodeObject($key, $item, $dom, $node);
} else {
$node->appendChild($dom->createElement($key, $item));
}
}
}
|
[
"protected",
"function",
"arrayToDomNode",
"(",
"\\",
"DOMDocument",
"$",
"dom",
",",
"\\",
"DOMElement",
"$",
"node",
",",
"array",
"$",
"arr",
")",
"{",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"ref",
"=",
"null",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
"||",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"ref",
"=",
"$",
"key",
";",
"}",
"$",
"key",
"=",
"'item'",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"item",
")",
")",
"{",
"$",
"newNode",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"ref",
")",
")",
"{",
"$",
"attr",
"=",
"$",
"dom",
"->",
"createAttribute",
"(",
"'ref'",
")",
";",
"$",
"attr",
"->",
"value",
"=",
"$",
"ref",
";",
"$",
"newNode",
"->",
"appendChild",
"(",
"$",
"attr",
")",
";",
"}",
"$",
"this",
"->",
"arrayToDomNode",
"(",
"$",
"dom",
",",
"$",
"newNode",
",",
"$",
"item",
")",
";",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"newNode",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"item",
")",
")",
"{",
"$",
"this",
"->",
"encodeObject",
"(",
"$",
"key",
",",
"$",
"item",
",",
"$",
"dom",
",",
"$",
"node",
")",
";",
"}",
"else",
"{",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"dom",
"->",
"createElement",
"(",
"$",
"key",
",",
"$",
"item",
")",
")",
";",
"}",
"}",
"}"
] |
Recursive iteration through array to be converted to DOM
@param \DOMDocument $dom
@param \DOMElement $node
@param array $arr
|
[
"Recursive",
"iteration",
"through",
"array",
"to",
"be",
"converted",
"to",
"DOM"
] |
00be4830438542abe494ac9be0bbd27723a0c984
|
https://github.com/chippyash/Builder-Pattern/blob/00be4830438542abe494ac9be0bbd27723a0c984/src/Chippyash/BuilderPattern/Renderer/XmlRenderer.php#L60-L85
|
232,434
|
hussainweb/drupal-api-client
|
src/Entity/Collection/EntityCollection.php
|
EntityCollection.getRelLink
|
protected function getRelLink($link_name)
{
if (!isset($this->rawData->$link_name)) {
return false;
}
$uri = new Uri($this->rawData->$link_name);
$uri = $uri->withPath($uri->getPath() . '.json');
return $uri;
}
|
php
|
protected function getRelLink($link_name)
{
if (!isset($this->rawData->$link_name)) {
return false;
}
$uri = new Uri($this->rawData->$link_name);
$uri = $uri->withPath($uri->getPath() . '.json');
return $uri;
}
|
[
"protected",
"function",
"getRelLink",
"(",
"$",
"link_name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"rawData",
"->",
"$",
"link_name",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"uri",
"=",
"new",
"Uri",
"(",
"$",
"this",
"->",
"rawData",
"->",
"$",
"link_name",
")",
";",
"$",
"uri",
"=",
"$",
"uri",
"->",
"withPath",
"(",
"$",
"uri",
"->",
"getPath",
"(",
")",
".",
"'.json'",
")",
";",
"return",
"$",
"uri",
";",
"}"
] |
Get the related link.
@param string $link_name
The name of the related link to retrieve.
@return bool|\Psr\Http\Message\UriInterface
The related URL or FALSE if not present.
|
[
"Get",
"the",
"related",
"link",
"."
] |
d15de9591a3d5181b4d44c2e50235fb98b3d3448
|
https://github.com/hussainweb/drupal-api-client/blob/d15de9591a3d5181b4d44c2e50235fb98b3d3448/src/Entity/Collection/EntityCollection.php#L71-L80
|
232,435
|
endorphin-studio/browser-detector
|
src/Detector.php
|
Detector.analyse
|
public function analyse(string $ua = 'ua'): Result
{
$request = Request::createFromGlobals();
$this->ua = $ua === 'ua' ? $request->server->get('HTTP_USER_AGENT') : $ua;
$this->resultObject = new Result($this->ua);
foreach ($this->detectors as $detectionType => $detector) {
$detector->detect();
}
return $this->resultObject;
}
|
php
|
public function analyse(string $ua = 'ua'): Result
{
$request = Request::createFromGlobals();
$this->ua = $ua === 'ua' ? $request->server->get('HTTP_USER_AGENT') : $ua;
$this->resultObject = new Result($this->ua);
foreach ($this->detectors as $detectionType => $detector) {
$detector->detect();
}
return $this->resultObject;
}
|
[
"public",
"function",
"analyse",
"(",
"string",
"$",
"ua",
"=",
"'ua'",
")",
":",
"Result",
"{",
"$",
"request",
"=",
"Request",
"::",
"createFromGlobals",
"(",
")",
";",
"$",
"this",
"->",
"ua",
"=",
"$",
"ua",
"===",
"'ua'",
"?",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'HTTP_USER_AGENT'",
")",
":",
"$",
"ua",
";",
"$",
"this",
"->",
"resultObject",
"=",
"new",
"Result",
"(",
"$",
"this",
"->",
"ua",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"detectors",
"as",
"$",
"detectionType",
"=>",
"$",
"detector",
")",
"{",
"$",
"detector",
"->",
"detect",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resultObject",
";",
"}"
] |
Analyse User Agent String
@param string $ua
@return Result
|
[
"Analyse",
"User",
"Agent",
"String"
] |
bb5e2d34917e98fd4a1214e146bb2ec64390bc13
|
https://github.com/endorphin-studio/browser-detector/blob/bb5e2d34917e98fd4a1214e146bb2ec64390bc13/src/Detector.php#L106-L115
|
232,436
|
iwyg/jitimage
|
src/Thapp/JitImage/Filter/AbstractFilter.php
|
AbstractFilter.getOption
|
public function getOption($option, $default = null)
{
if (array_key_exists($option, $this->options)) {
return $this->options[$option];
}
return $default;
}
|
php
|
public function getOption($option, $default = null)
{
if (array_key_exists($option, $this->options)) {
return $this->options[$option];
}
return $default;
}
|
[
"public",
"function",
"getOption",
"(",
"$",
"option",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"option",
",",
"$",
"this",
"->",
"options",
")",
")",
"{",
"return",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Get a filter option.
@param string $option option name
@param mixed $default the default value to return
@access public
@return mixed
|
[
"Get",
"a",
"filter",
"option",
"."
] |
25300cc5bb17835634ec60d71f5ac2ba870abbe4
|
https://github.com/iwyg/jitimage/blob/25300cc5bb17835634ec60d71f5ac2ba870abbe4/src/Thapp/JitImage/Filter/AbstractFilter.php#L102-L108
|
232,437
|
nineinchnick/yii2-usr
|
models/OneTimePasswordForm.php
|
OneTimePasswordForm.validOneTimePassword
|
public function validOneTimePassword($attribute, $params)
{
if ($this->_mode === OneTimePasswordFormBehavior::OTP_TIME) {
$valid = $this->_authenticator->checkCode($this->_secret, $this->$attribute);
} elseif ($this->_mode === OneTimePasswordFormBehavior::OTP_COUNTER) {
$valid = $this->_authenticator->getCode($this->_secret, $this->getPreviousCounter()) == $this->$attribute;
} else {
$valid = false;
}
if (!$valid) {
$this->addError($attribute, Yii::t('usr', 'Entered code is invalid.'));
return false;
}
if ($this->$attribute == $this->getPreviousCode()) {
if ($this->_mode === OneTimePasswordFormBehavior::OTP_TIME) {
$message = Yii::t('usr', 'Please wait until next code will be generated.');
} elseif ($this->_mode === OneTimePasswordFormBehavior::OTP_COUNTER) {
$message = Yii::t('usr', 'Please log in again to request a new code.');
}
$this->addError($attribute, Yii::t('usr', 'Entered code has already been used.').' '.$message);
$this->scenario = 'verifyOTP';
return false;
}
return true;
}
|
php
|
public function validOneTimePassword($attribute, $params)
{
if ($this->_mode === OneTimePasswordFormBehavior::OTP_TIME) {
$valid = $this->_authenticator->checkCode($this->_secret, $this->$attribute);
} elseif ($this->_mode === OneTimePasswordFormBehavior::OTP_COUNTER) {
$valid = $this->_authenticator->getCode($this->_secret, $this->getPreviousCounter()) == $this->$attribute;
} else {
$valid = false;
}
if (!$valid) {
$this->addError($attribute, Yii::t('usr', 'Entered code is invalid.'));
return false;
}
if ($this->$attribute == $this->getPreviousCode()) {
if ($this->_mode === OneTimePasswordFormBehavior::OTP_TIME) {
$message = Yii::t('usr', 'Please wait until next code will be generated.');
} elseif ($this->_mode === OneTimePasswordFormBehavior::OTP_COUNTER) {
$message = Yii::t('usr', 'Please log in again to request a new code.');
}
$this->addError($attribute, Yii::t('usr', 'Entered code has already been used.').' '.$message);
$this->scenario = 'verifyOTP';
return false;
}
return true;
}
|
[
"public",
"function",
"validOneTimePassword",
"(",
"$",
"attribute",
",",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_mode",
"===",
"OneTimePasswordFormBehavior",
"::",
"OTP_TIME",
")",
"{",
"$",
"valid",
"=",
"$",
"this",
"->",
"_authenticator",
"->",
"checkCode",
"(",
"$",
"this",
"->",
"_secret",
",",
"$",
"this",
"->",
"$",
"attribute",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_mode",
"===",
"OneTimePasswordFormBehavior",
"::",
"OTP_COUNTER",
")",
"{",
"$",
"valid",
"=",
"$",
"this",
"->",
"_authenticator",
"->",
"getCode",
"(",
"$",
"this",
"->",
"_secret",
",",
"$",
"this",
"->",
"getPreviousCounter",
"(",
")",
")",
"==",
"$",
"this",
"->",
"$",
"attribute",
";",
"}",
"else",
"{",
"$",
"valid",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"valid",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"attribute",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Entered code is invalid.'",
")",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"$",
"attribute",
"==",
"$",
"this",
"->",
"getPreviousCode",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_mode",
"===",
"OneTimePasswordFormBehavior",
"::",
"OTP_TIME",
")",
"{",
"$",
"message",
"=",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Please wait until next code will be generated.'",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_mode",
"===",
"OneTimePasswordFormBehavior",
"::",
"OTP_COUNTER",
")",
"{",
"$",
"message",
"=",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Please log in again to request a new code.'",
")",
";",
"}",
"$",
"this",
"->",
"addError",
"(",
"$",
"attribute",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Entered code has already been used.'",
")",
".",
"' '",
".",
"$",
"message",
")",
";",
"$",
"this",
"->",
"scenario",
"=",
"'verifyOTP'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Inline validator that checkes if enteres one time password is valid and hasn't been already used.
@param string $attribute
@param array $params
@return boolean
|
[
"Inline",
"validator",
"that",
"checkes",
"if",
"enteres",
"one",
"time",
"password",
"is",
"valid",
"and",
"hasn",
"t",
"been",
"already",
"used",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/models/OneTimePasswordForm.php#L124-L151
|
232,438
|
Speicher210/Reflection
|
src/ReflectionMethod.php
|
ReflectionMethod.getBody
|
public function getBody()
{
if ($this->isAbstract() === true) {
throw new RuntimeException('Can not get body of an abstract method');
}
$fileName = $this->getDeclaringClass()->getFileName();
if ($fileName === false) {
throw new RuntimeException('Can not get body of a method belonging to an internal class.');
}
$lines = file($fileName, FILE_IGNORE_NEW_LINES);
$lines = array_slice($lines, $this->getStartLine() - 1, ($this->getEndLine() - $this->getStartLine() + 1),
true);
$lines = implode("\n", $lines);
$firstBracketPos = strpos($lines, '{');
$lastBracketPost = strrpos($lines, '}');
$body = substr($lines, $firstBracketPos + 1, $lastBracketPost - $firstBracketPos - 1);
return trim(rtrim($body), "\n\r");
}
|
php
|
public function getBody()
{
if ($this->isAbstract() === true) {
throw new RuntimeException('Can not get body of an abstract method');
}
$fileName = $this->getDeclaringClass()->getFileName();
if ($fileName === false) {
throw new RuntimeException('Can not get body of a method belonging to an internal class.');
}
$lines = file($fileName, FILE_IGNORE_NEW_LINES);
$lines = array_slice($lines, $this->getStartLine() - 1, ($this->getEndLine() - $this->getStartLine() + 1),
true);
$lines = implode("\n", $lines);
$firstBracketPos = strpos($lines, '{');
$lastBracketPost = strrpos($lines, '}');
$body = substr($lines, $firstBracketPos + 1, $lastBracketPost - $firstBracketPos - 1);
return trim(rtrim($body), "\n\r");
}
|
[
"public",
"function",
"getBody",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAbstract",
"(",
")",
"===",
"true",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Can not get body of an abstract method'",
")",
";",
"}",
"$",
"fileName",
"=",
"$",
"this",
"->",
"getDeclaringClass",
"(",
")",
"->",
"getFileName",
"(",
")",
";",
"if",
"(",
"$",
"fileName",
"===",
"false",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Can not get body of a method belonging to an internal class.'",
")",
";",
"}",
"$",
"lines",
"=",
"file",
"(",
"$",
"fileName",
",",
"FILE_IGNORE_NEW_LINES",
")",
";",
"$",
"lines",
"=",
"array_slice",
"(",
"$",
"lines",
",",
"$",
"this",
"->",
"getStartLine",
"(",
")",
"-",
"1",
",",
"(",
"$",
"this",
"->",
"getEndLine",
"(",
")",
"-",
"$",
"this",
"->",
"getStartLine",
"(",
")",
"+",
"1",
")",
",",
"true",
")",
";",
"$",
"lines",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"$",
"firstBracketPos",
"=",
"strpos",
"(",
"$",
"lines",
",",
"'{'",
")",
";",
"$",
"lastBracketPost",
"=",
"strrpos",
"(",
"$",
"lines",
",",
"'}'",
")",
";",
"$",
"body",
"=",
"substr",
"(",
"$",
"lines",
",",
"$",
"firstBracketPos",
"+",
"1",
",",
"$",
"lastBracketPost",
"-",
"$",
"firstBracketPos",
"-",
"1",
")",
";",
"return",
"trim",
"(",
"rtrim",
"(",
"$",
"body",
")",
",",
"\"\\n\\r\"",
")",
";",
"}"
] |
Get the body of the method.
@return string
@throws \Wingu\OctopusCore\Reflection\Exceptions\RuntimeException If the method belongs to an internal class or is abstract.
|
[
"Get",
"the",
"body",
"of",
"the",
"method",
"."
] |
3d0f5033077b6a3f47cebbeded6538caeb0a1909
|
https://github.com/Speicher210/Reflection/blob/3d0f5033077b6a3f47cebbeded6538caeb0a1909/src/ReflectionMethod.php#L43-L64
|
232,439
|
Speicher210/Reflection
|
src/ReflectionMethod.php
|
ReflectionMethod.getParameters
|
public function getParameters()
{
$function = array($this->getDeclaringClass()->getName(), $this->getName());
$res = parent::getParameters();
foreach ($res as $key => $val) {
$res[$key] = new ReflectionParameter($function, $val->getName());
}
return $res;
}
|
php
|
public function getParameters()
{
$function = array($this->getDeclaringClass()->getName(), $this->getName());
$res = parent::getParameters();
foreach ($res as $key => $val) {
$res[$key] = new ReflectionParameter($function, $val->getName());
}
return $res;
}
|
[
"public",
"function",
"getParameters",
"(",
")",
"{",
"$",
"function",
"=",
"array",
"(",
"$",
"this",
"->",
"getDeclaringClass",
"(",
")",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"$",
"res",
"=",
"parent",
"::",
"getParameters",
"(",
")",
";",
"foreach",
"(",
"$",
"res",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"res",
"[",
"$",
"key",
"]",
"=",
"new",
"ReflectionParameter",
"(",
"$",
"function",
",",
"$",
"val",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"$",
"res",
";",
"}"
] |
Gets parameters.
@return \Wingu\OctopusCore\Reflection\ReflectionParameter[]
|
[
"Gets",
"parameters",
"."
] |
3d0f5033077b6a3f47cebbeded6538caeb0a1909
|
https://github.com/Speicher210/Reflection/blob/3d0f5033077b6a3f47cebbeded6538caeb0a1909/src/ReflectionMethod.php#L71-L81
|
232,440
|
icicleio/http
|
src/Message/BasicUri.php
|
BasicUri.filterValue
|
protected function filterValue($values): array
{
if (!is_array($values)) {
$values = [$values];
}
$lines = [];
foreach ($values as $value) {
if (is_numeric($value) || is_null($value) || (is_object($value) && method_exists($value, '__toString'))) {
$value = (string) $value;
} elseif (!is_string($value)) {
throw new InvalidValueException('Query values must be strings or an array of strings.');
}
$lines[] = decode($value);
}
return $lines;
}
|
php
|
protected function filterValue($values): array
{
if (!is_array($values)) {
$values = [$values];
}
$lines = [];
foreach ($values as $value) {
if (is_numeric($value) || is_null($value) || (is_object($value) && method_exists($value, '__toString'))) {
$value = (string) $value;
} elseif (!is_string($value)) {
throw new InvalidValueException('Query values must be strings or an array of strings.');
}
$lines[] = decode($value);
}
return $lines;
}
|
[
"protected",
"function",
"filterValue",
"(",
"$",
"values",
")",
":",
"array",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"[",
"$",
"values",
"]",
";",
"}",
"$",
"lines",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"||",
"is_null",
"(",
"$",
"value",
")",
"||",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"elseif",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidValueException",
"(",
"'Query values must be strings or an array of strings.'",
")",
";",
"}",
"$",
"lines",
"[",
"]",
"=",
"decode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"lines",
";",
"}"
] |
Converts a given query value to an integer-indexed array of strings.
@param mixed|mixed[] $values
@return string[]
@throws \Icicle\Http\Exception\InvalidValueException If the given value cannot be converted to a string and
is not an array of values that can be converted to strings.
|
[
"Converts",
"a",
"given",
"query",
"value",
"to",
"an",
"integer",
"-",
"indexed",
"array",
"of",
"strings",
"."
] |
13c5b45cbffd186b61dd3f8d1161f170ed686296
|
https://github.com/icicleio/http/blob/13c5b45cbffd186b61dd3f8d1161f170ed686296/src/Message/BasicUri.php#L472-L491
|
232,441
|
linkorb/buckaroo
|
src/LinkORB/Buckaroo/SignatureComposer/Sha1Composer.php
|
Sha1Composer.sign
|
protected function sign(array $parameters)
{
//turn into string and add the secret key to the end
$signatureString = '';
foreach ($parameters as $key => $value) {
$signatureString .= $key . '=' . $value;
}
$signatureString .= $this->secret;
return sha1($signatureString);
}
|
php
|
protected function sign(array $parameters)
{
//turn into string and add the secret key to the end
$signatureString = '';
foreach ($parameters as $key => $value) {
$signatureString .= $key . '=' . $value;
}
$signatureString .= $this->secret;
return sha1($signatureString);
}
|
[
"protected",
"function",
"sign",
"(",
"array",
"$",
"parameters",
")",
"{",
"//turn into string and add the secret key to the end",
"$",
"signatureString",
"=",
"''",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"signatureString",
".=",
"$",
"key",
".",
"'='",
".",
"$",
"value",
";",
"}",
"$",
"signatureString",
".=",
"$",
"this",
"->",
"secret",
";",
"return",
"sha1",
"(",
"$",
"signatureString",
")",
";",
"}"
] |
Calculate the sha1 for the parameter array.
@param array $parameters
@return string
|
[
"Calculate",
"the",
"sha1",
"for",
"the",
"parameter",
"array",
"."
] |
bbc66743c55c7d5b6eb5d7ad981ac08de5b5d08a
|
https://github.com/linkorb/buckaroo/blob/bbc66743c55c7d5b6eb5d7ad981ac08de5b5d08a/src/LinkORB/Buckaroo/SignatureComposer/Sha1Composer.php#L35-L47
|
232,442
|
linkorb/buckaroo
|
src/LinkORB/Buckaroo/SignatureComposer/Sha1Composer.php
|
Sha1Composer.sort
|
protected function sort(array $parameters)
{
uksort(
$parameters,
function ($key1, $key2) {
return strtolower($key1) > strtolower($key2) ? 1 : -1;
}
);
return $parameters;
}
|
php
|
protected function sort(array $parameters)
{
uksort(
$parameters,
function ($key1, $key2) {
return strtolower($key1) > strtolower($key2) ? 1 : -1;
}
);
return $parameters;
}
|
[
"protected",
"function",
"sort",
"(",
"array",
"$",
"parameters",
")",
"{",
"uksort",
"(",
"$",
"parameters",
",",
"function",
"(",
"$",
"key1",
",",
"$",
"key2",
")",
"{",
"return",
"strtolower",
"(",
"$",
"key1",
")",
">",
"strtolower",
"(",
"$",
"key2",
")",
"?",
"1",
":",
"-",
"1",
";",
"}",
")",
";",
"return",
"$",
"parameters",
";",
"}"
] |
Sort array alphabetically on key.
@param array $parameters
@return array
|
[
"Sort",
"array",
"alphabetically",
"on",
"key",
"."
] |
bbc66743c55c7d5b6eb5d7ad981ac08de5b5d08a
|
https://github.com/linkorb/buckaroo/blob/bbc66743c55c7d5b6eb5d7ad981ac08de5b5d08a/src/LinkORB/Buckaroo/SignatureComposer/Sha1Composer.php#L54-L64
|
232,443
|
chippyash/Monad
|
src/chippyash/Monad/FTry.php
|
FTry.create
|
public static function create($value)
{
if ($value instanceof \Exception) {
return new Failure($value);
}
try {
if ($value instanceof \Closure) {
//test to ensure function doesn't throw exception or is an Exception
$potentialException = $value();
if ($potentialException instanceof \Exception) {
return new Failure($potentialException);
}
} elseif ($value instanceof Monadic) {
return static::create($value->flatten());
}
return new Success($value);
} catch (\Exception $e) {
return new Failure($e);
}
}
|
php
|
public static function create($value)
{
if ($value instanceof \Exception) {
return new Failure($value);
}
try {
if ($value instanceof \Closure) {
//test to ensure function doesn't throw exception or is an Exception
$potentialException = $value();
if ($potentialException instanceof \Exception) {
return new Failure($potentialException);
}
} elseif ($value instanceof Monadic) {
return static::create($value->flatten());
}
return new Success($value);
} catch (\Exception $e) {
return new Failure($e);
}
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"Exception",
")",
"{",
"return",
"new",
"Failure",
"(",
"$",
"value",
")",
";",
"}",
"try",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"{",
"//test to ensure function doesn't throw exception or is an Exception",
"$",
"potentialException",
"=",
"$",
"value",
"(",
")",
";",
"if",
"(",
"$",
"potentialException",
"instanceof",
"\\",
"Exception",
")",
"{",
"return",
"new",
"Failure",
"(",
"$",
"potentialException",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"Monadic",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"$",
"value",
"->",
"flatten",
"(",
")",
")",
";",
"}",
"return",
"new",
"Success",
"(",
"$",
"value",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"new",
"Failure",
"(",
"$",
"e",
")",
";",
"}",
"}"
] |
Create a concrete FTry. If value results in an exception being thrown then Failure else Success
@param mixed $value Value
@return Failure|Success
|
[
"Create",
"a",
"concrete",
"FTry",
".",
"If",
"value",
"results",
"in",
"an",
"exception",
"being",
"thrown",
"then",
"Failure",
"else",
"Success"
] |
56b0d0177880932448e41b07c1d8e4ba16f8804f
|
https://github.com/chippyash/Monad/blob/56b0d0177880932448e41b07c1d8e4ba16f8804f/src/chippyash/Monad/FTry.php#L27-L48
|
232,444
|
monarkee/bumble
|
Controllers/LoginController.php
|
LoginController.postLogin
|
public function postLogin()
{
$input = Input::all();
// Get the columns we will authenticate against
$columns = config('bumble.auth_columns');
$creds = [];
foreach ($columns as $column)
{
$creds[$column] = $input[$column];
}
// Log the user in
if (Auth::attempt($creds))
{
return Redirect::route('bumble.dashboard');
}
return Redirect::back()->with('login_error', 'There was something wrong with your credentials')->withInput();
}
|
php
|
public function postLogin()
{
$input = Input::all();
// Get the columns we will authenticate against
$columns = config('bumble.auth_columns');
$creds = [];
foreach ($columns as $column)
{
$creds[$column] = $input[$column];
}
// Log the user in
if (Auth::attempt($creds))
{
return Redirect::route('bumble.dashboard');
}
return Redirect::back()->with('login_error', 'There was something wrong with your credentials')->withInput();
}
|
[
"public",
"function",
"postLogin",
"(",
")",
"{",
"$",
"input",
"=",
"Input",
"::",
"all",
"(",
")",
";",
"// Get the columns we will authenticate against",
"$",
"columns",
"=",
"config",
"(",
"'bumble.auth_columns'",
")",
";",
"$",
"creds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"$",
"creds",
"[",
"$",
"column",
"]",
"=",
"$",
"input",
"[",
"$",
"column",
"]",
";",
"}",
"// Log the user in",
"if",
"(",
"Auth",
"::",
"attempt",
"(",
"$",
"creds",
")",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'bumble.dashboard'",
")",
";",
"}",
"return",
"Redirect",
"::",
"back",
"(",
")",
"->",
"with",
"(",
"'login_error'",
",",
"'There was something wrong with your credentials'",
")",
"->",
"withInput",
"(",
")",
";",
"}"
] |
Process the Login
@return Response
|
[
"Process",
"the",
"Login"
] |
6e140e341980d6f9467418594eed48c3859c00f7
|
https://github.com/monarkee/bumble/blob/6e140e341980d6f9467418594eed48c3859c00f7/Controllers/LoginController.php#L45-L66
|
232,445
|
iwyg/jitimage
|
src/Thapp/JitImage/Response/AbstractFileResponse.php
|
AbstractFileResponse.make
|
final public function make(ImageInterface $image)
{
$this->response = new Response(null, 200);
$this->response->setPublic();
$lastMod = (new \DateTime)->setTimestamp($modDate = $image->getLastModTime());
$mod = strtotime($this->request->headers->get('if-modified-since', time()));
if (($image instanceof CachedImage || !$image->isProcessed()) && $mod === $modDate) {
$this->setHeadersIfNotProcessed($this->response, $lastMod);
} else {
$this->setHeaders($this->response, $image, $lastMod);
}
}
|
php
|
final public function make(ImageInterface $image)
{
$this->response = new Response(null, 200);
$this->response->setPublic();
$lastMod = (new \DateTime)->setTimestamp($modDate = $image->getLastModTime());
$mod = strtotime($this->request->headers->get('if-modified-since', time()));
if (($image instanceof CachedImage || !$image->isProcessed()) && $mod === $modDate) {
$this->setHeadersIfNotProcessed($this->response, $lastMod);
} else {
$this->setHeaders($this->response, $image, $lastMod);
}
}
|
[
"final",
"public",
"function",
"make",
"(",
"ImageInterface",
"$",
"image",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"new",
"Response",
"(",
"null",
",",
"200",
")",
";",
"$",
"this",
"->",
"response",
"->",
"setPublic",
"(",
")",
";",
"$",
"lastMod",
"=",
"(",
"new",
"\\",
"DateTime",
")",
"->",
"setTimestamp",
"(",
"$",
"modDate",
"=",
"$",
"image",
"->",
"getLastModTime",
"(",
")",
")",
";",
"$",
"mod",
"=",
"strtotime",
"(",
"$",
"this",
"->",
"request",
"->",
"headers",
"->",
"get",
"(",
"'if-modified-since'",
",",
"time",
"(",
")",
")",
")",
";",
"if",
"(",
"(",
"$",
"image",
"instanceof",
"CachedImage",
"||",
"!",
"$",
"image",
"->",
"isProcessed",
"(",
")",
")",
"&&",
"$",
"mod",
"===",
"$",
"modDate",
")",
"{",
"$",
"this",
"->",
"setHeadersIfNotProcessed",
"(",
"$",
"this",
"->",
"response",
",",
"$",
"lastMod",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setHeaders",
"(",
"$",
"this",
"->",
"response",
",",
"$",
"image",
",",
"$",
"lastMod",
")",
";",
"}",
"}"
] |
Creates a new response.
@param Image $image
@access public
@final
@return void
|
[
"Creates",
"a",
"new",
"response",
"."
] |
25300cc5bb17835634ec60d71f5ac2ba870abbe4
|
https://github.com/iwyg/jitimage/blob/25300cc5bb17835634ec60d71f5ac2ba870abbe4/src/Thapp/JitImage/Response/AbstractFileResponse.php#L72-L85
|
232,446
|
funivan/PhpTokenizer
|
src/QuerySequence/QuerySequence.php
|
QuerySequence.strict
|
public function strict($condition) {
$query = $this->buildStrategyCondition($condition, Strict::create());
return $this->process($query);
}
|
php
|
public function strict($condition) {
$query = $this->buildStrategyCondition($condition, Strict::create());
return $this->process($query);
}
|
[
"public",
"function",
"strict",
"(",
"$",
"condition",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"buildStrategyCondition",
"(",
"$",
"condition",
",",
"Strict",
"::",
"create",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"process",
"(",
"$",
"query",
")",
";",
"}"
] |
Strict validation of condition
@param int|string|Strict $condition
@return Token
|
[
"Strict",
"validation",
"of",
"condition"
] |
f31ec8f1440708518c2a785b3f129f130621e966
|
https://github.com/funivan/PhpTokenizer/blob/f31ec8f1440708518c2a785b3f129f130621e966/src/QuerySequence/QuerySequence.php#L84-L87
|
232,447
|
funivan/PhpTokenizer
|
src/QuerySequence/QuerySequence.php
|
QuerySequence.possible
|
public function possible($condition) {
$query = $this->buildStrategyCondition($condition, Possible::create());
return $this->process($query);
}
|
php
|
public function possible($condition) {
$query = $this->buildStrategyCondition($condition, Possible::create());
return $this->process($query);
}
|
[
"public",
"function",
"possible",
"(",
"$",
"condition",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"buildStrategyCondition",
"(",
"$",
"condition",
",",
"Possible",
"::",
"create",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"process",
"(",
"$",
"query",
")",
";",
"}"
] |
Check if token possible valid for our condition
@param int|string|Possible $condition
@return Token
|
[
"Check",
"if",
"token",
"possible",
"valid",
"for",
"our",
"condition"
] |
f31ec8f1440708518c2a785b3f129f130621e966
|
https://github.com/funivan/PhpTokenizer/blob/f31ec8f1440708518c2a785b3f129f130621e966/src/QuerySequence/QuerySequence.php#L96-L99
|
232,448
|
funivan/PhpTokenizer
|
src/QuerySequence/QuerySequence.php
|
QuerySequence.search
|
public function search($condition, $direction = null) {
$strategy = Search::create();
if ($direction !== null) {
$strategy->setDirection($direction);
}
$query = $this->buildStrategyCondition($condition, $strategy);
return $this->process($query);
}
|
php
|
public function search($condition, $direction = null) {
$strategy = Search::create();
if ($direction !== null) {
$strategy->setDirection($direction);
}
$query = $this->buildStrategyCondition($condition, $strategy);
return $this->process($query);
}
|
[
"public",
"function",
"search",
"(",
"$",
"condition",
",",
"$",
"direction",
"=",
"null",
")",
"{",
"$",
"strategy",
"=",
"Search",
"::",
"create",
"(",
")",
";",
"if",
"(",
"$",
"direction",
"!==",
"null",
")",
"{",
"$",
"strategy",
"->",
"setDirection",
"(",
"$",
"direction",
")",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"buildStrategyCondition",
"(",
"$",
"condition",
",",
"$",
"strategy",
")",
";",
"return",
"$",
"this",
"->",
"process",
"(",
"$",
"query",
")",
";",
"}"
] |
By default we search forward
@param int|string|Search $condition
@param null $direction
@return Token
|
[
"By",
"default",
"we",
"search",
"forward"
] |
f31ec8f1440708518c2a785b3f129f130621e966
|
https://github.com/funivan/PhpTokenizer/blob/f31ec8f1440708518c2a785b3f129f130621e966/src/QuerySequence/QuerySequence.php#L135-L142
|
232,449
|
funivan/PhpTokenizer
|
src/QuerySequence/QuerySequence.php
|
QuerySequence.moveToToken
|
public function moveToToken(Token $token) {
if (!$token->isValid()) {
$this->setValid(false);
return new Token();
}
$tokenIndex = $token->getIndex();
foreach ($this->collection as $index => $collectionToken) {
if ($collectionToken->getIndex() === $tokenIndex) {
$this->setPosition($index);
return $collectionToken;
}
}
$this->setValid(false);
return new Token();
}
|
php
|
public function moveToToken(Token $token) {
if (!$token->isValid()) {
$this->setValid(false);
return new Token();
}
$tokenIndex = $token->getIndex();
foreach ($this->collection as $index => $collectionToken) {
if ($collectionToken->getIndex() === $tokenIndex) {
$this->setPosition($index);
return $collectionToken;
}
}
$this->setValid(false);
return new Token();
}
|
[
"public",
"function",
"moveToToken",
"(",
"Token",
"$",
"token",
")",
"{",
"if",
"(",
"!",
"$",
"token",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setValid",
"(",
"false",
")",
";",
"return",
"new",
"Token",
"(",
")",
";",
"}",
"$",
"tokenIndex",
"=",
"$",
"token",
"->",
"getIndex",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"collection",
"as",
"$",
"index",
"=>",
"$",
"collectionToken",
")",
"{",
"if",
"(",
"$",
"collectionToken",
"->",
"getIndex",
"(",
")",
"===",
"$",
"tokenIndex",
")",
"{",
"$",
"this",
"->",
"setPosition",
"(",
"$",
"index",
")",
";",
"return",
"$",
"collectionToken",
";",
"}",
"}",
"$",
"this",
"->",
"setValid",
"(",
"false",
")",
";",
"return",
"new",
"Token",
"(",
")",
";",
"}"
] |
Move to specific position
@param Token $token
@return Token|null
|
[
"Move",
"to",
"specific",
"position"
] |
f31ec8f1440708518c2a785b3f129f130621e966
|
https://github.com/funivan/PhpTokenizer/blob/f31ec8f1440708518c2a785b3f129f130621e966/src/QuerySequence/QuerySequence.php#L164-L183
|
232,450
|
funivan/PhpTokenizer
|
src/QuerySequence/QuerySequence.php
|
QuerySequence.sequence
|
public function sequence(array $conditions) {
$range = new Collection();
foreach ($conditions as $value) {
$range[] = $this->checkFromSequence($value);
}
return $range;
}
|
php
|
public function sequence(array $conditions) {
$range = new Collection();
foreach ($conditions as $value) {
$range[] = $this->checkFromSequence($value);
}
return $range;
}
|
[
"public",
"function",
"sequence",
"(",
"array",
"$",
"conditions",
")",
"{",
"$",
"range",
"=",
"new",
"Collection",
"(",
")",
";",
"foreach",
"(",
"$",
"conditions",
"as",
"$",
"value",
")",
"{",
"$",
"range",
"[",
"]",
"=",
"$",
"this",
"->",
"checkFromSequence",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"range",
";",
"}"
] |
Array may contain Int, String or any StrategyInterface object
@param array $conditions
@return Collection
|
[
"Array",
"may",
"contain",
"Int",
"String",
"or",
"any",
"StrategyInterface",
"object"
] |
f31ec8f1440708518c2a785b3f129f130621e966
|
https://github.com/funivan/PhpTokenizer/blob/f31ec8f1440708518c2a785b3f129f130621e966/src/QuerySequence/QuerySequence.php#L192-L199
|
232,451
|
code-orange/redis-counting-semaphore
|
src/Semaphore.php
|
Semaphore.acquire
|
public function acquire($sleep = null, $retries = null) {
if ($this->identifier) {
// We already have it
return true;
}
if ($sleep == null || $retries == null) {
$acquired = $this->acquire_fair_with_lock();
return $acquired;
}
while ($sleep > 0 && $retries > 0) {
$acquired = $this->acquire_fair_with_lock();
if ($acquired) {
return true;
}
$retries -= 1;
sleep($sleep);
}
return false;
}
|
php
|
public function acquire($sleep = null, $retries = null) {
if ($this->identifier) {
// We already have it
return true;
}
if ($sleep == null || $retries == null) {
$acquired = $this->acquire_fair_with_lock();
return $acquired;
}
while ($sleep > 0 && $retries > 0) {
$acquired = $this->acquire_fair_with_lock();
if ($acquired) {
return true;
}
$retries -= 1;
sleep($sleep);
}
return false;
}
|
[
"public",
"function",
"acquire",
"(",
"$",
"sleep",
"=",
"null",
",",
"$",
"retries",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"identifier",
")",
"{",
"// We already have it",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"sleep",
"==",
"null",
"||",
"$",
"retries",
"==",
"null",
")",
"{",
"$",
"acquired",
"=",
"$",
"this",
"->",
"acquire_fair_with_lock",
"(",
")",
";",
"return",
"$",
"acquired",
";",
"}",
"while",
"(",
"$",
"sleep",
">",
"0",
"&&",
"$",
"retries",
">",
"0",
")",
"{",
"$",
"acquired",
"=",
"$",
"this",
"->",
"acquire_fair_with_lock",
"(",
")",
";",
"if",
"(",
"$",
"acquired",
")",
"{",
"return",
"true",
";",
"}",
"$",
"retries",
"-=",
"1",
";",
"sleep",
"(",
"$",
"sleep",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Try to acquire a semaphore
@param float $sleep Number of seconds to sleep between retries. If null, this function will not retry but return immediately.
@param int $retries Number of times to retry before giving up
@return bool Whether or not the semaphore was acquired correctly
|
[
"Try",
"to",
"acquire",
"a",
"semaphore"
] |
88125ea1c217e67c4d5b4e4f13482f3d868ff7a9
|
https://github.com/code-orange/redis-counting-semaphore/blob/88125ea1c217e67c4d5b4e4f13482f3d868ff7a9/src/Semaphore.php#L47-L69
|
232,452
|
code-orange/redis-counting-semaphore
|
src/Semaphore.php
|
Semaphore.acquire_lock
|
private function acquire_lock($acquire_timeout = 10) {
$identifier = (string)Uuid::uuid4();
$end = time() + $acquire_timeout;
while (time() < $end) {
$res = $this->client->setnx('lock:' . $this->name, $identifier);
if ($res) {
return $identifier;
}
sleep(0.001);
}
return false;
}
|
php
|
private function acquire_lock($acquire_timeout = 10) {
$identifier = (string)Uuid::uuid4();
$end = time() + $acquire_timeout;
while (time() < $end) {
$res = $this->client->setnx('lock:' . $this->name, $identifier);
if ($res) {
return $identifier;
}
sleep(0.001);
}
return false;
}
|
[
"private",
"function",
"acquire_lock",
"(",
"$",
"acquire_timeout",
"=",
"10",
")",
"{",
"$",
"identifier",
"=",
"(",
"string",
")",
"Uuid",
"::",
"uuid4",
"(",
")",
";",
"$",
"end",
"=",
"time",
"(",
")",
"+",
"$",
"acquire_timeout",
";",
"while",
"(",
"time",
"(",
")",
"<",
"$",
"end",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"client",
"->",
"setnx",
"(",
"'lock:'",
".",
"$",
"this",
"->",
"name",
",",
"$",
"identifier",
")",
";",
"if",
"(",
"$",
"res",
")",
"{",
"return",
"$",
"identifier",
";",
"}",
"sleep",
"(",
"0.001",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
From section 6.2 of the book
|
[
"From",
"section",
"6",
".",
"2",
"of",
"the",
"book"
] |
88125ea1c217e67c4d5b4e4f13482f3d868ff7a9
|
https://github.com/code-orange/redis-counting-semaphore/blob/88125ea1c217e67c4d5b4e4f13482f3d868ff7a9/src/Semaphore.php#L197-L209
|
232,453
|
nineinchnick/yii2-usr
|
controllers/UsrController.php
|
UsrController.sendEmail
|
public function sendEmail(\yii\base\Model $model, $mode)
{
$params = [
'siteUrl' => \yii\helpers\Url::toRoute(['/'], true),
];
switch ($mode) {
default:
return false;
case 'recovery':
case 'verify':
$subject = $mode == 'recovery'
? Yii::t('usr', 'Password recovery')
: Yii::t('usr', 'Email address verification');
$params['actionUrl'] = \yii\helpers\Url::toRoute([
$this->module->id . '/default/' . $mode,
'activationKey' => $model->getIdentity()->getActivationKey(),
'username' => $model->getIdentity()->username,
], true);
break;
case 'oneTimePassword':
$subject = Yii::t('usr', 'One Time Password');
$params['code'] = $model->getNewCode();
break;
}
$message = Yii::$app->mailer->compose($mode, $params);
$message->setTo([$model->getIdentity()->getEmail() => $model->getIdentity()->username]);
$message->setSubject($subject);
return $message->send();
}
|
php
|
public function sendEmail(\yii\base\Model $model, $mode)
{
$params = [
'siteUrl' => \yii\helpers\Url::toRoute(['/'], true),
];
switch ($mode) {
default:
return false;
case 'recovery':
case 'verify':
$subject = $mode == 'recovery'
? Yii::t('usr', 'Password recovery')
: Yii::t('usr', 'Email address verification');
$params['actionUrl'] = \yii\helpers\Url::toRoute([
$this->module->id . '/default/' . $mode,
'activationKey' => $model->getIdentity()->getActivationKey(),
'username' => $model->getIdentity()->username,
], true);
break;
case 'oneTimePassword':
$subject = Yii::t('usr', 'One Time Password');
$params['code'] = $model->getNewCode();
break;
}
$message = Yii::$app->mailer->compose($mode, $params);
$message->setTo([$model->getIdentity()->getEmail() => $model->getIdentity()->username]);
$message->setSubject($subject);
return $message->send();
}
|
[
"public",
"function",
"sendEmail",
"(",
"\\",
"yii",
"\\",
"base",
"\\",
"Model",
"$",
"model",
",",
"$",
"mode",
")",
"{",
"$",
"params",
"=",
"[",
"'siteUrl'",
"=>",
"\\",
"yii",
"\\",
"helpers",
"\\",
"Url",
"::",
"toRoute",
"(",
"[",
"'/'",
"]",
",",
"true",
")",
",",
"]",
";",
"switch",
"(",
"$",
"mode",
")",
"{",
"default",
":",
"return",
"false",
";",
"case",
"'recovery'",
":",
"case",
"'verify'",
":",
"$",
"subject",
"=",
"$",
"mode",
"==",
"'recovery'",
"?",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Password recovery'",
")",
":",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Email address verification'",
")",
";",
"$",
"params",
"[",
"'actionUrl'",
"]",
"=",
"\\",
"yii",
"\\",
"helpers",
"\\",
"Url",
"::",
"toRoute",
"(",
"[",
"$",
"this",
"->",
"module",
"->",
"id",
".",
"'/default/'",
".",
"$",
"mode",
",",
"'activationKey'",
"=>",
"$",
"model",
"->",
"getIdentity",
"(",
")",
"->",
"getActivationKey",
"(",
")",
",",
"'username'",
"=>",
"$",
"model",
"->",
"getIdentity",
"(",
")",
"->",
"username",
",",
"]",
",",
"true",
")",
";",
"break",
";",
"case",
"'oneTimePassword'",
":",
"$",
"subject",
"=",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'One Time Password'",
")",
";",
"$",
"params",
"[",
"'code'",
"]",
"=",
"$",
"model",
"->",
"getNewCode",
"(",
")",
";",
"break",
";",
"}",
"$",
"message",
"=",
"Yii",
"::",
"$",
"app",
"->",
"mailer",
"->",
"compose",
"(",
"$",
"mode",
",",
"$",
"params",
")",
";",
"$",
"message",
"->",
"setTo",
"(",
"[",
"$",
"model",
"->",
"getIdentity",
"(",
")",
"->",
"getEmail",
"(",
")",
"=>",
"$",
"model",
"->",
"getIdentity",
"(",
")",
"->",
"username",
"]",
")",
";",
"$",
"message",
"->",
"setSubject",
"(",
"$",
"subject",
")",
";",
"return",
"$",
"message",
"->",
"send",
"(",
")",
";",
"}"
] |
Sends out an email containing instructions and link to the email verification
or password recovery page, containing an activation key.
@param \yii\base\Model $model it must have a getIdentity() method
@param string $mode 'recovery', 'verify' or 'oneTimePassword'
@return boolean if sending the email succeeded
|
[
"Sends",
"out",
"an",
"email",
"containing",
"instructions",
"and",
"link",
"to",
"the",
"email",
"verification",
"or",
"password",
"recovery",
"page",
"containing",
"an",
"activation",
"key",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/controllers/UsrController.php#L16-L45
|
232,454
|
nineinchnick/yii2-usr
|
controllers/UsrController.php
|
UsrController.getScenarioView
|
public function getScenarioView($scenario, $default)
{
if (empty($scenario) || $scenario === \yii\base\Model::SCENARIO_DEFAULT) {
$scenario = $default;
}
if (!isset($this->module->scenarioViews[$scenario])) {
return [$scenario, []];
}
// config, scenario, default
$config = $this->module->scenarioViews[$scenario];
if (isset($config['view'])) {
$view = $config['view'];
unset($config['view']);
} else {
$view = $scenario;
}
return [$view, $config];
}
|
php
|
public function getScenarioView($scenario, $default)
{
if (empty($scenario) || $scenario === \yii\base\Model::SCENARIO_DEFAULT) {
$scenario = $default;
}
if (!isset($this->module->scenarioViews[$scenario])) {
return [$scenario, []];
}
// config, scenario, default
$config = $this->module->scenarioViews[$scenario];
if (isset($config['view'])) {
$view = $config['view'];
unset($config['view']);
} else {
$view = $scenario;
}
return [$view, $config];
}
|
[
"public",
"function",
"getScenarioView",
"(",
"$",
"scenario",
",",
"$",
"default",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"scenario",
")",
"||",
"$",
"scenario",
"===",
"\\",
"yii",
"\\",
"base",
"\\",
"Model",
"::",
"SCENARIO_DEFAULT",
")",
"{",
"$",
"scenario",
"=",
"$",
"default",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"module",
"->",
"scenarioViews",
"[",
"$",
"scenario",
"]",
")",
")",
"{",
"return",
"[",
"$",
"scenario",
",",
"[",
"]",
"]",
";",
"}",
"// config, scenario, default",
"$",
"config",
"=",
"$",
"this",
"->",
"module",
"->",
"scenarioViews",
"[",
"$",
"scenario",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'view'",
"]",
")",
")",
"{",
"$",
"view",
"=",
"$",
"config",
"[",
"'view'",
"]",
";",
"unset",
"(",
"$",
"config",
"[",
"'view'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"$",
"scenario",
";",
"}",
"return",
"[",
"$",
"view",
",",
"$",
"config",
"]",
";",
"}"
] |
Retreive view name and params based on scenario name and module configuration.
@param string $scenario
@param string $default default view name if scenario is null
@return array two values, view name (string) and view params (array)
|
[
"Retreive",
"view",
"name",
"and",
"params",
"based",
"on",
"scenario",
"name",
"and",
"module",
"configuration",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/controllers/UsrController.php#L54-L72
|
232,455
|
nineinchnick/yii2-usr
|
controllers/UsrController.php
|
UsrController.afterLogin
|
public function afterLogin()
{
$returnUrl = Yii::$app->user->returnUrl;
$returnUrlParts = explode('/', is_array($returnUrl) ? reset($returnUrl) : $returnUrl);
$url = end($returnUrlParts) == 'index.php' ? '/' : Yii::$app->user->returnUrl;
return $this->redirect($url);
}
|
php
|
public function afterLogin()
{
$returnUrl = Yii::$app->user->returnUrl;
$returnUrlParts = explode('/', is_array($returnUrl) ? reset($returnUrl) : $returnUrl);
$url = end($returnUrlParts) == 'index.php' ? '/' : Yii::$app->user->returnUrl;
return $this->redirect($url);
}
|
[
"public",
"function",
"afterLogin",
"(",
")",
"{",
"$",
"returnUrl",
"=",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"returnUrl",
";",
"$",
"returnUrlParts",
"=",
"explode",
"(",
"'/'",
",",
"is_array",
"(",
"$",
"returnUrl",
")",
"?",
"reset",
"(",
"$",
"returnUrl",
")",
":",
"$",
"returnUrl",
")",
";",
"$",
"url",
"=",
"end",
"(",
"$",
"returnUrlParts",
")",
"==",
"'index.php'",
"?",
"'/'",
":",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"returnUrl",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"url",
")",
";",
"}"
] |
Redirects user either to returnUrl or main page.
|
[
"Redirects",
"user",
"either",
"to",
"returnUrl",
"or",
"main",
"page",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/controllers/UsrController.php#L77-L84
|
232,456
|
monarkee/bumble
|
Providers/BumbleServiceProvider.php
|
BumbleServiceProvider.registerBindings
|
protected function registerBindings()
{
$this->app->singleton('assetLoader', 'Monarkee\Bumble\Repositories\FieldAssetRepository');
$this->app->singleton('bumblestr', function ()
{
return $this->app->make('Monarkee\Bumble\Support\BumbleStr');
});
$this->app->singleton('bumble-gravatar', function ()
{
return $this->app->make('Monarkee\Bumble\Support\Gravatar');
});
$this->app->bind('Monarkee\Bumble\Repositories\ModelRepository', 'Monarkee\Bumble\Repositories\ArrayConfigModelRepository');
}
|
php
|
protected function registerBindings()
{
$this->app->singleton('assetLoader', 'Monarkee\Bumble\Repositories\FieldAssetRepository');
$this->app->singleton('bumblestr', function ()
{
return $this->app->make('Monarkee\Bumble\Support\BumbleStr');
});
$this->app->singleton('bumble-gravatar', function ()
{
return $this->app->make('Monarkee\Bumble\Support\Gravatar');
});
$this->app->bind('Monarkee\Bumble\Repositories\ModelRepository', 'Monarkee\Bumble\Repositories\ArrayConfigModelRepository');
}
|
[
"protected",
"function",
"registerBindings",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'assetLoader'",
",",
"'Monarkee\\Bumble\\Repositories\\FieldAssetRepository'",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'bumblestr'",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'Monarkee\\Bumble\\Support\\BumbleStr'",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'bumble-gravatar'",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'Monarkee\\Bumble\\Support\\Gravatar'",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'Monarkee\\Bumble\\Repositories\\ModelRepository'",
",",
"'Monarkee\\Bumble\\Repositories\\ArrayConfigModelRepository'",
")",
";",
"}"
] |
Register the IoC Bindings
@return void
|
[
"Register",
"the",
"IoC",
"Bindings"
] |
6e140e341980d6f9467418594eed48c3859c00f7
|
https://github.com/monarkee/bumble/blob/6e140e341980d6f9467418594eed48c3859c00f7/Providers/BumbleServiceProvider.php#L72-L87
|
232,457
|
monarkee/bumble
|
Providers/BumbleServiceProvider.php
|
BumbleServiceProvider.createAliases
|
protected function createAliases()
{
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('BumbleStr', 'Monarkee\Bumble\Support\Facades\BumbleStr');
$loader->alias('BumbleGravatar', 'Monarkee\Bumble\Support\Facades\Gravatar');
$loader->alias('BumbleForm', 'Collective\Html\FormFacade');
$loader->alias('BumbleHtml', 'Collective\Html\HtmlFacade');
}
|
php
|
protected function createAliases()
{
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('BumbleStr', 'Monarkee\Bumble\Support\Facades\BumbleStr');
$loader->alias('BumbleGravatar', 'Monarkee\Bumble\Support\Facades\Gravatar');
$loader->alias('BumbleForm', 'Collective\Html\FormFacade');
$loader->alias('BumbleHtml', 'Collective\Html\HtmlFacade');
}
|
[
"protected",
"function",
"createAliases",
"(",
")",
"{",
"$",
"loader",
"=",
"\\",
"Illuminate",
"\\",
"Foundation",
"\\",
"AliasLoader",
"::",
"getInstance",
"(",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'BumbleStr'",
",",
"'Monarkee\\Bumble\\Support\\Facades\\BumbleStr'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'BumbleGravatar'",
",",
"'Monarkee\\Bumble\\Support\\Facades\\Gravatar'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'BumbleForm'",
",",
"'Collective\\Html\\FormFacade'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'BumbleHtml'",
",",
"'Collective\\Html\\HtmlFacade'",
")",
";",
"}"
] |
Create aliases for the dependency.
@return void
|
[
"Create",
"aliases",
"for",
"the",
"dependency",
"."
] |
6e140e341980d6f9467418594eed48c3859c00f7
|
https://github.com/monarkee/bumble/blob/6e140e341980d6f9467418594eed48c3859c00f7/Providers/BumbleServiceProvider.php#L93-L101
|
232,458
|
youngguns-nl/moneybird_php_api
|
Invoice/Service.php
|
Service.send
|
public function send(Invoice $invoice, $method = 'email', $email = null, $message = null)
{
return $this->connector->send($invoice, $this->buildEnvelope($method, $email, $message));
}
|
php
|
public function send(Invoice $invoice, $method = 'email', $email = null, $message = null)
{
return $this->connector->send($invoice, $this->buildEnvelope($method, $email, $message));
}
|
[
"public",
"function",
"send",
"(",
"Invoice",
"$",
"invoice",
",",
"$",
"method",
"=",
"'email'",
",",
"$",
"email",
"=",
"null",
",",
"$",
"message",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"connector",
"->",
"send",
"(",
"$",
"invoice",
",",
"$",
"this",
"->",
"buildEnvelope",
"(",
"$",
"method",
",",
"$",
"email",
",",
"$",
"message",
")",
")",
";",
"}"
] |
Send the invoice. Returns the updated invoice
@param Invoice $invoice
@param string $method Send method (email|hand|post); default: email
@param type $email Address to send to; default: contact e-mail
@param type $message
@return Invoice
|
[
"Send",
"the",
"invoice",
".",
"Returns",
"the",
"updated",
"invoice"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/Invoice/Service.php#L118-L121
|
232,459
|
youngguns-nl/moneybird_php_api
|
Invoice/Service.php
|
Service.buildEnvelope
|
protected function buildEnvelope($method = 'email', $email = null, $message = null)
{
return new Envelope(
array(
'sendMethod' => $method,
'email' => $email,
'invoiceEmail' => $message,
)
);
}
|
php
|
protected function buildEnvelope($method = 'email', $email = null, $message = null)
{
return new Envelope(
array(
'sendMethod' => $method,
'email' => $email,
'invoiceEmail' => $message,
)
);
}
|
[
"protected",
"function",
"buildEnvelope",
"(",
"$",
"method",
"=",
"'email'",
",",
"$",
"email",
"=",
"null",
",",
"$",
"message",
"=",
"null",
")",
"{",
"return",
"new",
"Envelope",
"(",
"array",
"(",
"'sendMethod'",
"=>",
"$",
"method",
",",
"'email'",
"=>",
"$",
"email",
",",
"'invoiceEmail'",
"=>",
"$",
"message",
",",
")",
")",
";",
"}"
] |
Build an envelope to send the invoice or reminder with
@param string $method Send method (email|hand|post); default: email
@param type $email Address to send to; default: contact e-mail
@param type $message
@return Envelope
@access protected
|
[
"Build",
"an",
"envelope",
"to",
"send",
"the",
"invoice",
"or",
"reminder",
"with"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/Invoice/Service.php#L144-L153
|
232,460
|
blast-project/DoctrinePgsqlBundle
|
src/DoctrineExtensions/BlastWalker.php
|
BlastWalker.walkSelectClause
|
public function walkSelectClause($selectClause)
{
$sql = parent::walkSelectClause($selectClause);
if ($this->getQuery()->getHint('blastWalker.noIlike') === false) {
$sql = str_replace(' LIKE ', ' ILIKE ', $sql);
}
return $sql;
}
|
php
|
public function walkSelectClause($selectClause)
{
$sql = parent::walkSelectClause($selectClause);
if ($this->getQuery()->getHint('blastWalker.noIlike') === false) {
$sql = str_replace(' LIKE ', ' ILIKE ', $sql);
}
return $sql;
}
|
[
"public",
"function",
"walkSelectClause",
"(",
"$",
"selectClause",
")",
"{",
"$",
"sql",
"=",
"parent",
"::",
"walkSelectClause",
"(",
"$",
"selectClause",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"getHint",
"(",
"'blastWalker.noIlike'",
")",
"===",
"false",
")",
"{",
"$",
"sql",
"=",
"str_replace",
"(",
"' LIKE '",
",",
"' ILIKE '",
",",
"$",
"sql",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] |
Walks down a SelectClause AST node, thereby generating the appropriate SQL.
@param $selectClause
@return string the SQL
|
[
"Walks",
"down",
"a",
"SelectClause",
"AST",
"node",
"thereby",
"generating",
"the",
"appropriate",
"SQL",
"."
] |
edc4dce259771390dcf9cd452dc54ec03b0b545c
|
https://github.com/blast-project/DoctrinePgsqlBundle/blob/edc4dce259771390dcf9cd452dc54ec03b0b545c/src/DoctrineExtensions/BlastWalker.php#L26-L35
|
232,461
|
blast-project/DoctrinePgsqlBundle
|
src/DoctrineExtensions/BlastWalker.php
|
BlastWalker.walkWhereClause
|
public function walkWhereClause($whereClause)
{
$sql = parent::walkWhereClause($whereClause);
if ($this->getQuery()->getHint('blastWalker.noIlike') === false) {
$sql = str_replace(' LIKE ', ' ILIKE ', $sql);
}
return $sql;
}
|
php
|
public function walkWhereClause($whereClause)
{
$sql = parent::walkWhereClause($whereClause);
if ($this->getQuery()->getHint('blastWalker.noIlike') === false) {
$sql = str_replace(' LIKE ', ' ILIKE ', $sql);
}
return $sql;
}
|
[
"public",
"function",
"walkWhereClause",
"(",
"$",
"whereClause",
")",
"{",
"$",
"sql",
"=",
"parent",
"::",
"walkWhereClause",
"(",
"$",
"whereClause",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"getHint",
"(",
"'blastWalker.noIlike'",
")",
"===",
"false",
")",
"{",
"$",
"sql",
"=",
"str_replace",
"(",
"' LIKE '",
",",
"' ILIKE '",
",",
"$",
"sql",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] |
Walks down a WhereClause AST node, thereby generating the appropriate SQL.
@param $whereClause
@return string the SQL
|
[
"Walks",
"down",
"a",
"WhereClause",
"AST",
"node",
"thereby",
"generating",
"the",
"appropriate",
"SQL",
"."
] |
edc4dce259771390dcf9cd452dc54ec03b0b545c
|
https://github.com/blast-project/DoctrinePgsqlBundle/blob/edc4dce259771390dcf9cd452dc54ec03b0b545c/src/DoctrineExtensions/BlastWalker.php#L44-L53
|
232,462
|
axypro/sourcemap
|
helpers/PosBuilder.php
|
PosBuilder.build
|
public static function build($p)
{
if (is_object($p)) {
if ($p instanceof PosMap) {
return $p;
}
$generated = isset($p->generated) ? $p->generated : null;
$source = isset($p->source) ? $p->source : null;
} elseif (is_array($p)) {
$generated = isset($p['generated']) ? $p['generated'] : null;
$source = isset($p['source']) ? $p['source'] : null;
} else {
$generated = null;
$source = null;
}
return new PosMap($generated, $source);
}
|
php
|
public static function build($p)
{
if (is_object($p)) {
if ($p instanceof PosMap) {
return $p;
}
$generated = isset($p->generated) ? $p->generated : null;
$source = isset($p->source) ? $p->source : null;
} elseif (is_array($p)) {
$generated = isset($p['generated']) ? $p['generated'] : null;
$source = isset($p['source']) ? $p['source'] : null;
} else {
$generated = null;
$source = null;
}
return new PosMap($generated, $source);
}
|
[
"public",
"static",
"function",
"build",
"(",
"$",
"p",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"p",
")",
")",
"{",
"if",
"(",
"$",
"p",
"instanceof",
"PosMap",
")",
"{",
"return",
"$",
"p",
";",
"}",
"$",
"generated",
"=",
"isset",
"(",
"$",
"p",
"->",
"generated",
")",
"?",
"$",
"p",
"->",
"generated",
":",
"null",
";",
"$",
"source",
"=",
"isset",
"(",
"$",
"p",
"->",
"source",
")",
"?",
"$",
"p",
"->",
"source",
":",
"null",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"p",
")",
")",
"{",
"$",
"generated",
"=",
"isset",
"(",
"$",
"p",
"[",
"'generated'",
"]",
")",
"?",
"$",
"p",
"[",
"'generated'",
"]",
":",
"null",
";",
"$",
"source",
"=",
"isset",
"(",
"$",
"p",
"[",
"'source'",
"]",
")",
"?",
"$",
"p",
"[",
"'source'",
"]",
":",
"null",
";",
"}",
"else",
"{",
"$",
"generated",
"=",
"null",
";",
"$",
"source",
"=",
"null",
";",
"}",
"return",
"new",
"PosMap",
"(",
"$",
"generated",
",",
"$",
"source",
")",
";",
"}"
] |
Builds a position map
@param \axy\sourcemap\PosMap|array|object $p
@return \axy\sourcemap\PosMap
|
[
"Builds",
"a",
"position",
"map"
] |
f5793e5d166bf2a1735e27676007a21c121e20af
|
https://github.com/axypro/sourcemap/blob/f5793e5d166bf2a1735e27676007a21c121e20af/helpers/PosBuilder.php#L22-L38
|
232,463
|
cawaphp/cawa
|
src/Events/TimerEvent.php
|
TimerEvent.onEmit
|
public function onEmit()
{
if (!$this->duration) {
$time = microtime(true);
$this->duration = round($time - $this->start, 6);
}
}
|
php
|
public function onEmit()
{
if (!$this->duration) {
$time = microtime(true);
$this->duration = round($time - $this->start, 6);
}
}
|
[
"public",
"function",
"onEmit",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"duration",
")",
"{",
"$",
"time",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"duration",
"=",
"round",
"(",
"$",
"time",
"-",
"$",
"this",
"->",
"start",
",",
"6",
")",
";",
"}",
"}"
] |
Save duration of this events.
|
[
"Save",
"duration",
"of",
"this",
"events",
"."
] |
bd250532200121e7aa1da44e547c04c4c148fb37
|
https://github.com/cawaphp/cawa/blob/bd250532200121e7aa1da44e547c04c4c148fb37/src/Events/TimerEvent.php#L61-L67
|
232,464
|
cawaphp/cawa
|
src/Router/Router.php
|
Router.routeRegexpTranslatedText
|
private function routeRegexpTranslatedText(Route $route, string $value = null, array $data = null) : string
{
if (!$value) {
throw new \InvalidArgumentException(
sprintf("Missing router var on route '%s'", $route->getName())
);
}
$variable = null;
$trans = [];
if (strpos($value, '<') !== false && strpos($value, '>')) {
$variable = substr($value, 1, strpos($value, '>') - 1);
$keys = explode('|', substr($value, strpos($value, '>') + 1));
} else {
$keys = [$value];
}
foreach ($keys as $key) {
if (!isset($this->uris[$key])) {
throw new \InvalidArgumentException(
sprintf("Missing translations for var '%s' on route '%s'", $key, $route->getName())
);
}
foreach ($this->uris[$key] as $locale => $current) {
$trans[$locale][$key] = $current;
$trans['*'][] = $current;
}
}
if (!is_null($data) && sizeof($keys) > 1 && !isset($data[$variable])) {
throw new \InvalidArgumentException(
sprintf("Missing datas '%s' on route '%s'", $value, $route->getName())
);
}
if (!is_null($data) && sizeof($keys) == 1) {
$dest = $trans[self::locale()][$value];
} elseif (!is_null($data) && sizeof($keys) > 1) {
$dest = $data[$variable];
} else {
$dest = ($variable ? '(?<' . $variable . '>' : '(?:') . implode('|', $trans['*']) . ')';
}
return $dest;
}
|
php
|
private function routeRegexpTranslatedText(Route $route, string $value = null, array $data = null) : string
{
if (!$value) {
throw new \InvalidArgumentException(
sprintf("Missing router var on route '%s'", $route->getName())
);
}
$variable = null;
$trans = [];
if (strpos($value, '<') !== false && strpos($value, '>')) {
$variable = substr($value, 1, strpos($value, '>') - 1);
$keys = explode('|', substr($value, strpos($value, '>') + 1));
} else {
$keys = [$value];
}
foreach ($keys as $key) {
if (!isset($this->uris[$key])) {
throw new \InvalidArgumentException(
sprintf("Missing translations for var '%s' on route '%s'", $key, $route->getName())
);
}
foreach ($this->uris[$key] as $locale => $current) {
$trans[$locale][$key] = $current;
$trans['*'][] = $current;
}
}
if (!is_null($data) && sizeof($keys) > 1 && !isset($data[$variable])) {
throw new \InvalidArgumentException(
sprintf("Missing datas '%s' on route '%s'", $value, $route->getName())
);
}
if (!is_null($data) && sizeof($keys) == 1) {
$dest = $trans[self::locale()][$value];
} elseif (!is_null($data) && sizeof($keys) > 1) {
$dest = $data[$variable];
} else {
$dest = ($variable ? '(?<' . $variable . '>' : '(?:') . implode('|', $trans['*']) . ')';
}
return $dest;
}
|
[
"private",
"function",
"routeRegexpTranslatedText",
"(",
"Route",
"$",
"route",
",",
"string",
"$",
"value",
"=",
"null",
",",
"array",
"$",
"data",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Missing router var on route '%s'\"",
",",
"$",
"route",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"$",
"variable",
"=",
"null",
";",
"$",
"trans",
"=",
"[",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"'<'",
")",
"!==",
"false",
"&&",
"strpos",
"(",
"$",
"value",
",",
"'>'",
")",
")",
"{",
"$",
"variable",
"=",
"substr",
"(",
"$",
"value",
",",
"1",
",",
"strpos",
"(",
"$",
"value",
",",
"'>'",
")",
"-",
"1",
")",
";",
"$",
"keys",
"=",
"explode",
"(",
"'|'",
",",
"substr",
"(",
"$",
"value",
",",
"strpos",
"(",
"$",
"value",
",",
"'>'",
")",
"+",
"1",
")",
")",
";",
"}",
"else",
"{",
"$",
"keys",
"=",
"[",
"$",
"value",
"]",
";",
"}",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"uris",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Missing translations for var '%s' on route '%s'\"",
",",
"$",
"key",
",",
"$",
"route",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"uris",
"[",
"$",
"key",
"]",
"as",
"$",
"locale",
"=>",
"$",
"current",
")",
"{",
"$",
"trans",
"[",
"$",
"locale",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"current",
";",
"$",
"trans",
"[",
"'*'",
"]",
"[",
"]",
"=",
"$",
"current",
";",
"}",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"data",
")",
"&&",
"sizeof",
"(",
"$",
"keys",
")",
">",
"1",
"&&",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"variable",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Missing datas '%s' on route '%s'\"",
",",
"$",
"value",
",",
"$",
"route",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"data",
")",
"&&",
"sizeof",
"(",
"$",
"keys",
")",
"==",
"1",
")",
"{",
"$",
"dest",
"=",
"$",
"trans",
"[",
"self",
"::",
"locale",
"(",
")",
"]",
"[",
"$",
"value",
"]",
";",
"}",
"elseif",
"(",
"!",
"is_null",
"(",
"$",
"data",
")",
"&&",
"sizeof",
"(",
"$",
"keys",
")",
">",
"1",
")",
"{",
"$",
"dest",
"=",
"$",
"data",
"[",
"$",
"variable",
"]",
";",
"}",
"else",
"{",
"$",
"dest",
"=",
"(",
"$",
"variable",
"?",
"'(?<'",
".",
"$",
"variable",
".",
"'>'",
":",
"'(?:'",
")",
".",
"implode",
"(",
"'|'",
",",
"$",
"trans",
"[",
"'*'",
"]",
")",
".",
"')'",
";",
"}",
"return",
"$",
"dest",
";",
"}"
] |
Translate text => accueil|home.
@param Route $route
@param string|null $value
@param array|null $data
@return string
|
[
"Translate",
"text",
"=",
">",
"accueil|home",
"."
] |
bd250532200121e7aa1da44e547c04c4c148fb37
|
https://github.com/cawaphp/cawa/blob/bd250532200121e7aa1da44e547c04c4c148fb37/src/Router/Router.php#L496-L542
|
232,465
|
cawaphp/cawa
|
src/Router/Router.php
|
Router.routeRegexpLocales
|
private function routeRegexpLocales(array $data = null) : string
{
if (!is_null($data)) {
$dest = self::locale();
} else {
$dest = '(?:' . implode('|', self::translator()->getLocales()) . ')';
}
return $dest;
}
|
php
|
private function routeRegexpLocales(array $data = null) : string
{
if (!is_null($data)) {
$dest = self::locale();
} else {
$dest = '(?:' . implode('|', self::translator()->getLocales()) . ')';
}
return $dest;
}
|
[
"private",
"function",
"routeRegexpLocales",
"(",
"array",
"$",
"data",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"$",
"dest",
"=",
"self",
"::",
"locale",
"(",
")",
";",
"}",
"else",
"{",
"$",
"dest",
"=",
"'(?:'",
".",
"implode",
"(",
"'|'",
",",
"self",
"::",
"translator",
"(",
")",
"->",
"getLocales",
"(",
")",
")",
".",
"')'",
";",
"}",
"return",
"$",
"dest",
";",
"}"
] |
Locales avaialble => fr|en.
@param array|null $data
@return string
|
[
"Locales",
"avaialble",
"=",
">",
"fr|en",
"."
] |
bd250532200121e7aa1da44e547c04c4c148fb37
|
https://github.com/cawaphp/cawa/blob/bd250532200121e7aa1da44e547c04c4c148fb37/src/Router/Router.php#L551-L560
|
232,466
|
monarkee/bumble
|
Fields/ImageField.php
|
ImageField.getPublicUrl
|
public function getPublicUrl($path = '')
{
if (isset($this->options['public_url'])) return $this->options['public_url'];
return url() . '/' . $this->addSlashes(self::DEFAULT_PUBLIC_PATH) . $path;
}
|
php
|
public function getPublicUrl($path = '')
{
if (isset($this->options['public_url'])) return $this->options['public_url'];
return url() . '/' . $this->addSlashes(self::DEFAULT_PUBLIC_PATH) . $path;
}
|
[
"public",
"function",
"getPublicUrl",
"(",
"$",
"path",
"=",
"''",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'public_url'",
"]",
")",
")",
"return",
"$",
"this",
"->",
"options",
"[",
"'public_url'",
"]",
";",
"return",
"url",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"addSlashes",
"(",
"self",
"::",
"DEFAULT_PUBLIC_PATH",
")",
".",
"$",
"path",
";",
"}"
] |
Get the public path to the image
@param string $path
@return string
|
[
"Get",
"the",
"public",
"path",
"to",
"the",
"image"
] |
6e140e341980d6f9467418594eed48c3859c00f7
|
https://github.com/monarkee/bumble/blob/6e140e341980d6f9467418594eed48c3859c00f7/Fields/ImageField.php#L19-L24
|
232,467
|
youngguns-nl/moneybird_php_api
|
Contact/Note.php
|
Note.delete
|
public function delete(ServiceInterface $service, Contact $contact = null)
{
if ($contact === null) {
throw new Exception('$contact must be instance of Contact');
}
$service->deleteNote($this, $contact);
}
|
php
|
public function delete(ServiceInterface $service, Contact $contact = null)
{
if ($contact === null) {
throw new Exception('$contact must be instance of Contact');
}
$service->deleteNote($this, $contact);
}
|
[
"public",
"function",
"delete",
"(",
"ServiceInterface",
"$",
"service",
",",
"Contact",
"$",
"contact",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"contact",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'$contact must be instance of Contact'",
")",
";",
"}",
"$",
"service",
"->",
"deleteNote",
"(",
"$",
"this",
",",
"$",
"contact",
")",
";",
"}"
] |
Deletes a contact note
@param Service $service
@param Contact $contact
|
[
"Deletes",
"a",
"contact",
"note"
] |
bb5035dd60cf087c7a055458d207be418355ab74
|
https://github.com/youngguns-nl/moneybird_php_api/blob/bb5035dd60cf087c7a055458d207be418355ab74/Contact/Note.php#L60-L66
|
232,468
|
icicleio/http
|
src/Message/BasicRequest.php
|
BasicRequest.setHostFromUri
|
private function setHostFromUri()
{
$this->hostFromUri = true;
$host = $this->uri->getHost();
if (!empty($host)) { // Do not set Host header if URI has no host.
$port = $this->uri->getPort();
if (null !== $port) {
$host = sprintf('%s:%d', $host, $port);
}
parent::setHeader('Host', $host);
}
}
|
php
|
private function setHostFromUri()
{
$this->hostFromUri = true;
$host = $this->uri->getHost();
if (!empty($host)) { // Do not set Host header if URI has no host.
$port = $this->uri->getPort();
if (null !== $port) {
$host = sprintf('%s:%d', $host, $port);
}
parent::setHeader('Host', $host);
}
}
|
[
"private",
"function",
"setHostFromUri",
"(",
")",
"{",
"$",
"this",
"->",
"hostFromUri",
"=",
"true",
";",
"$",
"host",
"=",
"$",
"this",
"->",
"uri",
"->",
"getHost",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"host",
")",
")",
"{",
"// Do not set Host header if URI has no host.",
"$",
"port",
"=",
"$",
"this",
"->",
"uri",
"->",
"getPort",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"port",
")",
"{",
"$",
"host",
"=",
"sprintf",
"(",
"'%s:%d'",
",",
"$",
"host",
",",
"$",
"port",
")",
";",
"}",
"parent",
"::",
"setHeader",
"(",
"'Host'",
",",
"$",
"host",
")",
";",
"}",
"}"
] |
Sets the host based on the current URI.
|
[
"Sets",
"the",
"host",
"based",
"on",
"the",
"current",
"URI",
"."
] |
13c5b45cbffd186b61dd3f8d1161f170ed686296
|
https://github.com/icicleio/http/blob/13c5b45cbffd186b61dd3f8d1161f170ed686296/src/Message/BasicRequest.php#L285-L299
|
232,469
|
monarkee/bumble
|
Fields/BooleanField.php
|
BooleanField.process
|
public function process($model, $input)
{
$column = $this->getColumn();
$model->{$this->getColumn()} = isset($input[$column]) ?: false;
return $model;
}
|
php
|
public function process($model, $input)
{
$column = $this->getColumn();
$model->{$this->getColumn()} = isset($input[$column]) ?: false;
return $model;
}
|
[
"public",
"function",
"process",
"(",
"$",
"model",
",",
"$",
"input",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"getColumn",
"(",
")",
";",
"$",
"model",
"->",
"{",
"$",
"this",
"->",
"getColumn",
"(",
")",
"}",
"=",
"isset",
"(",
"$",
"input",
"[",
"$",
"column",
"]",
")",
"?",
":",
"false",
";",
"return",
"$",
"model",
";",
"}"
] |
Process the model, assign its input and return the model to the user
@param $model
@param $input
@return mixed
|
[
"Process",
"the",
"model",
"assign",
"its",
"input",
"and",
"return",
"the",
"model",
"to",
"the",
"user"
] |
6e140e341980d6f9467418594eed48c3859c00f7
|
https://github.com/monarkee/bumble/blob/6e140e341980d6f9467418594eed48c3859c00f7/Fields/BooleanField.php#L15-L22
|
232,470
|
iwyg/jitimage
|
src/Thapp/JitImage/JitImageServiceProvider.php
|
JitImageServiceProvider.registerDriver
|
protected function registerDriver()
{
$app = $this->app;
$config = $app['config'];
$storage = $config->get('jitimage::cache.path');
$driver = sprintf(
'\Thapp\JitImage\Driver\%sDriver',
$driverName = ucfirst($config->get('jitimage::driver', 'gd'))
);
$app->bind(
'Thapp\JitImage\Cache\CacheInterface',
function () use ($storage) {
$cache = new \Thapp\JitImage\Cache\ImageCache(
new CachedImage,
//$this->app['Thapp\JitImage\ImageInterface'],
new Filesystem,
$storage . '/jit'
);
return $cache;
}
);
$app->bind('Thapp\JitImage\Driver\SourceLoaderInterface', 'Thapp\JitImage\Driver\ImageSourceLoader');
$app->bind('Thapp\JitImage\Driver\BinLocatorInterface', function () use ($config) {
$locator = new \Thapp\JitImage\Driver\ImBinLocator;
extract($config->get('jitimage::imagemagick', ['path' => '/usr/local/bin', 'bin' => 'convert']));
$locator->setConverterPath(
sprintf('%s%s%s', rtrim($path, DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, $bin)
);
return $locator;
});
$this->app->bind('Thapp\JitImage\Driver\DriverInterface', function () use ($driver) {
return $this->app->make($driver);
});
$this->app->bind('Thapp\JitImage\ImageInterface', function () use ($app) {
return new ProxyImage(function () use ($app) {
$image = new Image($app->make('Thapp\JitImage\Driver\DriverInterface'));
$image->setQuality($app['config']->get('jitimage::quality', 80));
return $image;
});
});
//$this->app->extend(
// 'Thapp\JitImage\ImageInterface',
// function ($image) {
// $image->setQuality($this->app['config']->get('jitimage::quality', 80));
// return $image;
// }
//);
$this->app['jitimage'] = $this->app->share(
function () use ($app) {
$resolver = $app->make('Thapp\JitImage\ResolverInterface');
$image = new JitImage($resolver, \URL::to('/'));
return $image;
}
);
$this->app['jitimage.cache'] = $this->app->share(
function () {
return $this->app->make('Thapp\JitImage\Cache\CacheInterface');
}
);
$this->registerFilter($driverName, $this->getFilters());
}
|
php
|
protected function registerDriver()
{
$app = $this->app;
$config = $app['config'];
$storage = $config->get('jitimage::cache.path');
$driver = sprintf(
'\Thapp\JitImage\Driver\%sDriver',
$driverName = ucfirst($config->get('jitimage::driver', 'gd'))
);
$app->bind(
'Thapp\JitImage\Cache\CacheInterface',
function () use ($storage) {
$cache = new \Thapp\JitImage\Cache\ImageCache(
new CachedImage,
//$this->app['Thapp\JitImage\ImageInterface'],
new Filesystem,
$storage . '/jit'
);
return $cache;
}
);
$app->bind('Thapp\JitImage\Driver\SourceLoaderInterface', 'Thapp\JitImage\Driver\ImageSourceLoader');
$app->bind('Thapp\JitImage\Driver\BinLocatorInterface', function () use ($config) {
$locator = new \Thapp\JitImage\Driver\ImBinLocator;
extract($config->get('jitimage::imagemagick', ['path' => '/usr/local/bin', 'bin' => 'convert']));
$locator->setConverterPath(
sprintf('%s%s%s', rtrim($path, DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, $bin)
);
return $locator;
});
$this->app->bind('Thapp\JitImage\Driver\DriverInterface', function () use ($driver) {
return $this->app->make($driver);
});
$this->app->bind('Thapp\JitImage\ImageInterface', function () use ($app) {
return new ProxyImage(function () use ($app) {
$image = new Image($app->make('Thapp\JitImage\Driver\DriverInterface'));
$image->setQuality($app['config']->get('jitimage::quality', 80));
return $image;
});
});
//$this->app->extend(
// 'Thapp\JitImage\ImageInterface',
// function ($image) {
// $image->setQuality($this->app['config']->get('jitimage::quality', 80));
// return $image;
// }
//);
$this->app['jitimage'] = $this->app->share(
function () use ($app) {
$resolver = $app->make('Thapp\JitImage\ResolverInterface');
$image = new JitImage($resolver, \URL::to('/'));
return $image;
}
);
$this->app['jitimage.cache'] = $this->app->share(
function () {
return $this->app->make('Thapp\JitImage\Cache\CacheInterface');
}
);
$this->registerFilter($driverName, $this->getFilters());
}
|
[
"protected",
"function",
"registerDriver",
"(",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"$",
"config",
"=",
"$",
"app",
"[",
"'config'",
"]",
";",
"$",
"storage",
"=",
"$",
"config",
"->",
"get",
"(",
"'jitimage::cache.path'",
")",
";",
"$",
"driver",
"=",
"sprintf",
"(",
"'\\Thapp\\JitImage\\Driver\\%sDriver'",
",",
"$",
"driverName",
"=",
"ucfirst",
"(",
"$",
"config",
"->",
"get",
"(",
"'jitimage::driver'",
",",
"'gd'",
")",
")",
")",
";",
"$",
"app",
"->",
"bind",
"(",
"'Thapp\\JitImage\\Cache\\CacheInterface'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"storage",
")",
"{",
"$",
"cache",
"=",
"new",
"\\",
"Thapp",
"\\",
"JitImage",
"\\",
"Cache",
"\\",
"ImageCache",
"(",
"new",
"CachedImage",
",",
"//$this->app['Thapp\\JitImage\\ImageInterface'],",
"new",
"Filesystem",
",",
"$",
"storage",
".",
"'/jit'",
")",
";",
"return",
"$",
"cache",
";",
"}",
")",
";",
"$",
"app",
"->",
"bind",
"(",
"'Thapp\\JitImage\\Driver\\SourceLoaderInterface'",
",",
"'Thapp\\JitImage\\Driver\\ImageSourceLoader'",
")",
";",
"$",
"app",
"->",
"bind",
"(",
"'Thapp\\JitImage\\Driver\\BinLocatorInterface'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"$",
"locator",
"=",
"new",
"\\",
"Thapp",
"\\",
"JitImage",
"\\",
"Driver",
"\\",
"ImBinLocator",
";",
"extract",
"(",
"$",
"config",
"->",
"get",
"(",
"'jitimage::imagemagick'",
",",
"[",
"'path'",
"=>",
"'/usr/local/bin'",
",",
"'bin'",
"=>",
"'convert'",
"]",
")",
")",
";",
"$",
"locator",
"->",
"setConverterPath",
"(",
"sprintf",
"(",
"'%s%s%s'",
",",
"rtrim",
"(",
"$",
"path",
",",
"DIRECTORY_SEPARATOR",
")",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"bin",
")",
")",
";",
"return",
"$",
"locator",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'Thapp\\JitImage\\Driver\\DriverInterface'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"driver",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"$",
"driver",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'Thapp\\JitImage\\ImageInterface'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"ProxyImage",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"$",
"image",
"=",
"new",
"Image",
"(",
"$",
"app",
"->",
"make",
"(",
"'Thapp\\JitImage\\Driver\\DriverInterface'",
")",
")",
";",
"$",
"image",
"->",
"setQuality",
"(",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'jitimage::quality'",
",",
"80",
")",
")",
";",
"return",
"$",
"image",
";",
"}",
")",
";",
"}",
")",
";",
"//$this->app->extend(",
"// 'Thapp\\JitImage\\ImageInterface',",
"// function ($image) {",
"// $image->setQuality($this->app['config']->get('jitimage::quality', 80));",
"// return $image;",
"// }",
"//);",
"$",
"this",
"->",
"app",
"[",
"'jitimage'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"$",
"resolver",
"=",
"$",
"app",
"->",
"make",
"(",
"'Thapp\\JitImage\\ResolverInterface'",
")",
";",
"$",
"image",
"=",
"new",
"JitImage",
"(",
"$",
"resolver",
",",
"\\",
"URL",
"::",
"to",
"(",
"'/'",
")",
")",
";",
"return",
"$",
"image",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'jitimage.cache'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'Thapp\\JitImage\\Cache\\CacheInterface'",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"registerFilter",
"(",
"$",
"driverName",
",",
"$",
"this",
"->",
"getFilters",
"(",
")",
")",
";",
"}"
] |
Register the image process driver.
@access protected
@return void
|
[
"Register",
"the",
"image",
"process",
"driver",
"."
] |
25300cc5bb17835634ec60d71f5ac2ba870abbe4
|
https://github.com/iwyg/jitimage/blob/25300cc5bb17835634ec60d71f5ac2ba870abbe4/src/Thapp/JitImage/JitImageServiceProvider.php#L77-L153
|
232,471
|
iwyg/jitimage
|
src/Thapp/JitImage/JitImageServiceProvider.php
|
JitImageServiceProvider.registerResolver
|
protected function registerResolver()
{
$config = $this->app['config'];
$this->app->singleton('Thapp\JitImage\ResolverInterface', 'Thapp\JitImage\JitImageResolver');
$this->app->bind(
'Thapp\JitImage\ResolverConfigInterface',
function () use ($config) {
$conf = [
'trusted_sites' => $config->get('jitimage::trusted-sites', []),
'cache_prefix' => $config->get('jitimage::cache.prefix', 'jit_'),
'base_route' => $config->get('jitimage::route', 'images'),
'cache_route' => $config->get('jitimage::cache.route', 'jit/storage'),
'base' => $config->get('jitimage::base', public_path()),
'cache' => in_array(
$config->getEnvironment(),
$config->get('jitimage::cache.environments', [])
),
'format_filter' => $config->get('jitimage::filter.Convert', 'conv')
];
return new \Thapp\JitImage\JitResolveConfiguration($conf);
}
);
}
|
php
|
protected function registerResolver()
{
$config = $this->app['config'];
$this->app->singleton('Thapp\JitImage\ResolverInterface', 'Thapp\JitImage\JitImageResolver');
$this->app->bind(
'Thapp\JitImage\ResolverConfigInterface',
function () use ($config) {
$conf = [
'trusted_sites' => $config->get('jitimage::trusted-sites', []),
'cache_prefix' => $config->get('jitimage::cache.prefix', 'jit_'),
'base_route' => $config->get('jitimage::route', 'images'),
'cache_route' => $config->get('jitimage::cache.route', 'jit/storage'),
'base' => $config->get('jitimage::base', public_path()),
'cache' => in_array(
$config->getEnvironment(),
$config->get('jitimage::cache.environments', [])
),
'format_filter' => $config->get('jitimage::filter.Convert', 'conv')
];
return new \Thapp\JitImage\JitResolveConfiguration($conf);
}
);
}
|
[
"protected",
"function",
"registerResolver",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Thapp\\JitImage\\ResolverInterface'",
",",
"'Thapp\\JitImage\\JitImageResolver'",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'Thapp\\JitImage\\ResolverConfigInterface'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"$",
"conf",
"=",
"[",
"'trusted_sites'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'jitimage::trusted-sites'",
",",
"[",
"]",
")",
",",
"'cache_prefix'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'jitimage::cache.prefix'",
",",
"'jit_'",
")",
",",
"'base_route'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'jitimage::route'",
",",
"'images'",
")",
",",
"'cache_route'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'jitimage::cache.route'",
",",
"'jit/storage'",
")",
",",
"'base'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'jitimage::base'",
",",
"public_path",
"(",
")",
")",
",",
"'cache'",
"=>",
"in_array",
"(",
"$",
"config",
"->",
"getEnvironment",
"(",
")",
",",
"$",
"config",
"->",
"get",
"(",
"'jitimage::cache.environments'",
",",
"[",
"]",
")",
")",
",",
"'format_filter'",
"=>",
"$",
"config",
"->",
"get",
"(",
"'jitimage::filter.Convert'",
",",
"'conv'",
")",
"]",
";",
"return",
"new",
"\\",
"Thapp",
"\\",
"JitImage",
"\\",
"JitResolveConfiguration",
"(",
"$",
"conf",
")",
";",
"}",
")",
";",
"}"
] |
Register the ResolverInterface on its implementation.
@access protected
@return void
|
[
"Register",
"the",
"ResolverInterface",
"on",
"its",
"implementation",
"."
] |
25300cc5bb17835634ec60d71f5ac2ba870abbe4
|
https://github.com/iwyg/jitimage/blob/25300cc5bb17835634ec60d71f5ac2ba870abbe4/src/Thapp/JitImage/JitImageServiceProvider.php#L161-L186
|
232,472
|
iwyg/jitimage
|
src/Thapp/JitImage/JitImageServiceProvider.php
|
JitImageServiceProvider.registerResponse
|
protected function registerResponse()
{
$app = $this->app;
$type = $this->app['config']->get('jitimage::response-type', 'generic');
$response = sprintf('Thapp\JitImage\Response\%sFileResponse', ucfirst($type));
$this->app->bind(
'Thapp\JitImage\Response\FileResponseInterface',
function () use ($response, $app) {
return new $response($app['request']);
}
);
}
|
php
|
protected function registerResponse()
{
$app = $this->app;
$type = $this->app['config']->get('jitimage::response-type', 'generic');
$response = sprintf('Thapp\JitImage\Response\%sFileResponse', ucfirst($type));
$this->app->bind(
'Thapp\JitImage\Response\FileResponseInterface',
function () use ($response, $app) {
return new $response($app['request']);
}
);
}
|
[
"protected",
"function",
"registerResponse",
"(",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'jitimage::response-type'",
",",
"'generic'",
")",
";",
"$",
"response",
"=",
"sprintf",
"(",
"'Thapp\\JitImage\\Response\\%sFileResponse'",
",",
"ucfirst",
"(",
"$",
"type",
")",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'Thapp\\JitImage\\Response\\FileResponseInterface'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"response",
",",
"$",
"app",
")",
"{",
"return",
"new",
"$",
"response",
"(",
"$",
"app",
"[",
"'request'",
"]",
")",
";",
"}",
")",
";",
"}"
] |
Register the response class on the ioc container.
@access protected
@return void
|
[
"Register",
"the",
"response",
"class",
"on",
"the",
"ioc",
"container",
"."
] |
25300cc5bb17835634ec60d71f5ac2ba870abbe4
|
https://github.com/iwyg/jitimage/blob/25300cc5bb17835634ec60d71f5ac2ba870abbe4/src/Thapp/JitImage/JitImageServiceProvider.php#L194-L206
|
232,473
|
iwyg/jitimage
|
src/Thapp/JitImage/JitImageServiceProvider.php
|
JitImageServiceProvider.registerController
|
protected function registerController()
{
$config = $this->app['config'];
$recipes = $config->get('jitimage::recipes', []);
$route = $config->get('jitimage::route', 'image');
$cacheroute = $config->get('jitimage::cache.route', 'jit/storage');
$this->registerCacheRoute($cacheroute);
if (false === $this->registerStaticRoutes($recipes, $route)) {
$this->registerDynanmicRoute($route);
}
}
|
php
|
protected function registerController()
{
$config = $this->app['config'];
$recipes = $config->get('jitimage::recipes', []);
$route = $config->get('jitimage::route', 'image');
$cacheroute = $config->get('jitimage::cache.route', 'jit/storage');
$this->registerCacheRoute($cacheroute);
if (false === $this->registerStaticRoutes($recipes, $route)) {
$this->registerDynanmicRoute($route);
}
}
|
[
"protected",
"function",
"registerController",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
";",
"$",
"recipes",
"=",
"$",
"config",
"->",
"get",
"(",
"'jitimage::recipes'",
",",
"[",
"]",
")",
";",
"$",
"route",
"=",
"$",
"config",
"->",
"get",
"(",
"'jitimage::route'",
",",
"'image'",
")",
";",
"$",
"cacheroute",
"=",
"$",
"config",
"->",
"get",
"(",
"'jitimage::cache.route'",
",",
"'jit/storage'",
")",
";",
"$",
"this",
"->",
"registerCacheRoute",
"(",
"$",
"cacheroute",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"registerStaticRoutes",
"(",
"$",
"recipes",
",",
"$",
"route",
")",
")",
"{",
"$",
"this",
"->",
"registerDynanmicRoute",
"(",
"$",
"route",
")",
";",
"}",
"}"
] |
Register the image controller
@access protected
@return void;
|
[
"Register",
"the",
"image",
"controller"
] |
25300cc5bb17835634ec60d71f5ac2ba870abbe4
|
https://github.com/iwyg/jitimage/blob/25300cc5bb17835634ec60d71f5ac2ba870abbe4/src/Thapp/JitImage/JitImageServiceProvider.php#L214-L227
|
232,474
|
iwyg/jitimage
|
src/Thapp/JitImage/JitImageServiceProvider.php
|
JitImageServiceProvider.registerStaticRoutes
|
protected function registerStaticRoutes(array $recipes = [], $route = null)
{
if (empty($recipes)) {
return false;
}
$ctrl = 'Thapp\JitImage\Controller\JitController';
foreach ($recipes as $aliasRoute => $formular) {
$param = str_replace('/', '_', $aliasRoute);
$this->app['router']
->get(
$route . '/{' . $param . '}/{source}',
['uses' => $ctrl . '@getResource']
)
->where($param, $aliasRoute)
->where('source', '(.*)');
}
//$this->app->bind($ctrl);
//$this->app->extend($ctrl, function ($controller) use ($recipes) {
// $controller->setRecieps(new \Thapp\JitImage\RecipeResolver($recipes));
// return $controller;
//});
$this->app->bind($ctrl, function () use ($ctrl, $recipes) {
$controller = new $ctrl(
$this->app->make('Thapp\JitImage\ResolverInterface'),
$this->app->make('Thapp\JitImage\Response\FileResponseInterface')
);
$controller->setRecieps(new \Thapp\JitImage\RecipeResolver($recipes));
return $controller;
});
}
|
php
|
protected function registerStaticRoutes(array $recipes = [], $route = null)
{
if (empty($recipes)) {
return false;
}
$ctrl = 'Thapp\JitImage\Controller\JitController';
foreach ($recipes as $aliasRoute => $formular) {
$param = str_replace('/', '_', $aliasRoute);
$this->app['router']
->get(
$route . '/{' . $param . '}/{source}',
['uses' => $ctrl . '@getResource']
)
->where($param, $aliasRoute)
->where('source', '(.*)');
}
//$this->app->bind($ctrl);
//$this->app->extend($ctrl, function ($controller) use ($recipes) {
// $controller->setRecieps(new \Thapp\JitImage\RecipeResolver($recipes));
// return $controller;
//});
$this->app->bind($ctrl, function () use ($ctrl, $recipes) {
$controller = new $ctrl(
$this->app->make('Thapp\JitImage\ResolverInterface'),
$this->app->make('Thapp\JitImage\Response\FileResponseInterface')
);
$controller->setRecieps(new \Thapp\JitImage\RecipeResolver($recipes));
return $controller;
});
}
|
[
"protected",
"function",
"registerStaticRoutes",
"(",
"array",
"$",
"recipes",
"=",
"[",
"]",
",",
"$",
"route",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"recipes",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"ctrl",
"=",
"'Thapp\\JitImage\\Controller\\JitController'",
";",
"foreach",
"(",
"$",
"recipes",
"as",
"$",
"aliasRoute",
"=>",
"$",
"formular",
")",
"{",
"$",
"param",
"=",
"str_replace",
"(",
"'/'",
",",
"'_'",
",",
"$",
"aliasRoute",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'router'",
"]",
"->",
"get",
"(",
"$",
"route",
".",
"'/{'",
".",
"$",
"param",
".",
"'}/{source}'",
",",
"[",
"'uses'",
"=>",
"$",
"ctrl",
".",
"'@getResource'",
"]",
")",
"->",
"where",
"(",
"$",
"param",
",",
"$",
"aliasRoute",
")",
"->",
"where",
"(",
"'source'",
",",
"'(.*)'",
")",
";",
"}",
"//$this->app->bind($ctrl);",
"//$this->app->extend($ctrl, function ($controller) use ($recipes) {",
"// $controller->setRecieps(new \\Thapp\\JitImage\\RecipeResolver($recipes));",
"// return $controller;",
"//});",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"$",
"ctrl",
",",
"function",
"(",
")",
"use",
"(",
"$",
"ctrl",
",",
"$",
"recipes",
")",
"{",
"$",
"controller",
"=",
"new",
"$",
"ctrl",
"(",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'Thapp\\JitImage\\ResolverInterface'",
")",
",",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'Thapp\\JitImage\\Response\\FileResponseInterface'",
")",
")",
";",
"$",
"controller",
"->",
"setRecieps",
"(",
"new",
"\\",
"Thapp",
"\\",
"JitImage",
"\\",
"RecipeResolver",
"(",
"$",
"recipes",
")",
")",
";",
"return",
"$",
"controller",
";",
"}",
")",
";",
"}"
] |
Register static routes.
@param array $recipes array of prefined processing instructions
@param string $route baseroute name
@access protected
@return void|boolean false
|
[
"Register",
"static",
"routes",
"."
] |
25300cc5bb17835634ec60d71f5ac2ba870abbe4
|
https://github.com/iwyg/jitimage/blob/25300cc5bb17835634ec60d71f5ac2ba870abbe4/src/Thapp/JitImage/JitImageServiceProvider.php#L252-L287
|
232,475
|
mmanos/laravel-social
|
src/controllers/SocialController.php
|
SocialController.getComplete
|
public function getComplete()
{
$user_data = Session::get('mmanos.social.pending');
if (empty($user_data) || !is_array($user_data)) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (10).'
);
}
$failed_fields = Session::get('mmanos.social.failed_fields');
if (empty($failed_fields) || !is_array($failed_fields)) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (11).'
);
}
return View::make('laravel-social::social.complete', array(
'failed_fields' => $failed_fields,
'info' => array_get($user_data, 'user_info'),
));
}
|
php
|
public function getComplete()
{
$user_data = Session::get('mmanos.social.pending');
if (empty($user_data) || !is_array($user_data)) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (10).'
);
}
$failed_fields = Session::get('mmanos.social.failed_fields');
if (empty($failed_fields) || !is_array($failed_fields)) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (11).'
);
}
return View::make('laravel-social::social.complete', array(
'failed_fields' => $failed_fields,
'info' => array_get($user_data, 'user_info'),
));
}
|
[
"public",
"function",
"getComplete",
"(",
")",
"{",
"$",
"user_data",
"=",
"Session",
"::",
"get",
"(",
"'mmanos.social.pending'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"user_data",
")",
"||",
"!",
"is_array",
"(",
"$",
"user_data",
")",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem logging in to your account (10).'",
")",
";",
"}",
"$",
"failed_fields",
"=",
"Session",
"::",
"get",
"(",
"'mmanos.social.failed_fields'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"failed_fields",
")",
"||",
"!",
"is_array",
"(",
"$",
"failed_fields",
")",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem logging in to your account (11).'",
")",
";",
"}",
"return",
"View",
"::",
"make",
"(",
"'laravel-social::social.complete'",
",",
"array",
"(",
"'failed_fields'",
"=>",
"$",
"failed_fields",
",",
"'info'",
"=>",
"array_get",
"(",
"$",
"user_data",
",",
"'user_info'",
")",
",",
")",
")",
";",
"}"
] |
Complete login action.
@return View
|
[
"Complete",
"login",
"action",
"."
] |
f3ec7165509825d16cb9d06759a77580a291cb83
|
https://github.com/mmanos/laravel-social/blob/f3ec7165509825d16cb9d06759a77580a291cb83/src/controllers/SocialController.php#L272-L296
|
232,476
|
mmanos/laravel-social
|
src/controllers/SocialController.php
|
SocialController.postComplete
|
public function postComplete()
{
$user_data = Session::get('mmanos.social.pending');
if (empty($user_data) || !is_array($user_data)) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (12).'
);
}
$user_info = array_merge(array_get($user_data, 'user_info'), Input::all());
$user_validation = Config::get('laravel-social::user_validation');
if ($user_validation instanceof Closure) {
$validator = $user_validation($user_info);
}
else {
$validator = Validator::make($user_info, (array) $user_validation);
}
if ($validator->fails()) {
return Redirect::action('Mmanos\Social\SocialController@getComplete')
->withInput()
->withErrors($validator);
}
$create_user_callback = Config::get('laravel-social::create_user');
if (empty($create_user_callback) || !$create_user_callback instanceof Closure) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (13).'
);
}
$user_id = $create_user_callback($user_info);
if (!$user_id || !is_numeric($user_id) || $user_id <= 0) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (14).'
);
}
$provider = array_get($user_data, 'provider');
$provider_id = array_get($user_data, 'provider_id');
$access_token = array_get($user_data, 'access_token');
$this->linkProvider($user_id, $provider, $provider_id, $access_token);
Session::forget('mmanos.social.pending');
Session::forget('mmanos.social.failed_fields');
Auth::loginUsingId($user_id);
return Redirect::to(Session::pull('mmanos.social.onsuccess', '/'));
}
|
php
|
public function postComplete()
{
$user_data = Session::get('mmanos.social.pending');
if (empty($user_data) || !is_array($user_data)) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (12).'
);
}
$user_info = array_merge(array_get($user_data, 'user_info'), Input::all());
$user_validation = Config::get('laravel-social::user_validation');
if ($user_validation instanceof Closure) {
$validator = $user_validation($user_info);
}
else {
$validator = Validator::make($user_info, (array) $user_validation);
}
if ($validator->fails()) {
return Redirect::action('Mmanos\Social\SocialController@getComplete')
->withInput()
->withErrors($validator);
}
$create_user_callback = Config::get('laravel-social::create_user');
if (empty($create_user_callback) || !$create_user_callback instanceof Closure) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (13).'
);
}
$user_id = $create_user_callback($user_info);
if (!$user_id || !is_numeric($user_id) || $user_id <= 0) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem logging in to your account (14).'
);
}
$provider = array_get($user_data, 'provider');
$provider_id = array_get($user_data, 'provider_id');
$access_token = array_get($user_data, 'access_token');
$this->linkProvider($user_id, $provider, $provider_id, $access_token);
Session::forget('mmanos.social.pending');
Session::forget('mmanos.social.failed_fields');
Auth::loginUsingId($user_id);
return Redirect::to(Session::pull('mmanos.social.onsuccess', '/'));
}
|
[
"public",
"function",
"postComplete",
"(",
")",
"{",
"$",
"user_data",
"=",
"Session",
"::",
"get",
"(",
"'mmanos.social.pending'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"user_data",
")",
"||",
"!",
"is_array",
"(",
"$",
"user_data",
")",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem logging in to your account (12).'",
")",
";",
"}",
"$",
"user_info",
"=",
"array_merge",
"(",
"array_get",
"(",
"$",
"user_data",
",",
"'user_info'",
")",
",",
"Input",
"::",
"all",
"(",
")",
")",
";",
"$",
"user_validation",
"=",
"Config",
"::",
"get",
"(",
"'laravel-social::user_validation'",
")",
";",
"if",
"(",
"$",
"user_validation",
"instanceof",
"Closure",
")",
"{",
"$",
"validator",
"=",
"$",
"user_validation",
"(",
"$",
"user_info",
")",
";",
"}",
"else",
"{",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"user_info",
",",
"(",
"array",
")",
"$",
"user_validation",
")",
";",
"}",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"Redirect",
"::",
"action",
"(",
"'Mmanos\\Social\\SocialController@getComplete'",
")",
"->",
"withInput",
"(",
")",
"->",
"withErrors",
"(",
"$",
"validator",
")",
";",
"}",
"$",
"create_user_callback",
"=",
"Config",
"::",
"get",
"(",
"'laravel-social::create_user'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"create_user_callback",
")",
"||",
"!",
"$",
"create_user_callback",
"instanceof",
"Closure",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem logging in to your account (13).'",
")",
";",
"}",
"$",
"user_id",
"=",
"$",
"create_user_callback",
"(",
"$",
"user_info",
")",
";",
"if",
"(",
"!",
"$",
"user_id",
"||",
"!",
"is_numeric",
"(",
"$",
"user_id",
")",
"||",
"$",
"user_id",
"<=",
"0",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem logging in to your account (14).'",
")",
";",
"}",
"$",
"provider",
"=",
"array_get",
"(",
"$",
"user_data",
",",
"'provider'",
")",
";",
"$",
"provider_id",
"=",
"array_get",
"(",
"$",
"user_data",
",",
"'provider_id'",
")",
";",
"$",
"access_token",
"=",
"array_get",
"(",
"$",
"user_data",
",",
"'access_token'",
")",
";",
"$",
"this",
"->",
"linkProvider",
"(",
"$",
"user_id",
",",
"$",
"provider",
",",
"$",
"provider_id",
",",
"$",
"access_token",
")",
";",
"Session",
"::",
"forget",
"(",
"'mmanos.social.pending'",
")",
";",
"Session",
"::",
"forget",
"(",
"'mmanos.social.failed_fields'",
")",
";",
"Auth",
"::",
"loginUsingId",
"(",
"$",
"user_id",
")",
";",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onsuccess'",
",",
"'/'",
")",
")",
";",
"}"
] |
Handle the complete login form submission.
@return Redirect
|
[
"Handle",
"the",
"complete",
"login",
"form",
"submission",
"."
] |
f3ec7165509825d16cb9d06759a77580a291cb83
|
https://github.com/mmanos/laravel-social/blob/f3ec7165509825d16cb9d06759a77580a291cb83/src/controllers/SocialController.php#L303-L359
|
232,477
|
mmanos/laravel-social
|
src/controllers/SocialController.php
|
SocialController.getConnect
|
public function getConnect($provider = null)
{
if (empty($provider)) {
App::abort(404);
}
$referer = Request::header('referer', '/');
$referer_parts = parse_url($referer);
$onboth = array_get($referer_parts, 'path');
if (array_get($referer_parts, 'query')) {
$onboth .= '?' . array_get($referer_parts, 'query');
}
if (!Input::get('code') && !Input::get('oauth_token')) {
Session::put('mmanos.social.onsuccess', Input::get('onsuccess', $onboth));
Session::put('mmanos.social.onerror', Input::get('onerror', $onboth));
}
if (!Auth::check()) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (1).'
);
}
if (Input::get('denied') || Input::get('error')) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (2).'
);
}
$provider = ucfirst($provider);
try {
$service = Social::service($provider);
if (Config::get('laravel-social::providers.' . strtolower($provider) . '.offline')) {
$service->setAccessType('offline');
}
} catch (Exception $e) {
App::abort(404);
}
if (2 === Social::oauthSpec($provider)) {
return $this->oauth2Connect($provider, $service);
}
else {
return $this->oauth1Connect($provider, $service);
}
}
|
php
|
public function getConnect($provider = null)
{
if (empty($provider)) {
App::abort(404);
}
$referer = Request::header('referer', '/');
$referer_parts = parse_url($referer);
$onboth = array_get($referer_parts, 'path');
if (array_get($referer_parts, 'query')) {
$onboth .= '?' . array_get($referer_parts, 'query');
}
if (!Input::get('code') && !Input::get('oauth_token')) {
Session::put('mmanos.social.onsuccess', Input::get('onsuccess', $onboth));
Session::put('mmanos.social.onerror', Input::get('onerror', $onboth));
}
if (!Auth::check()) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (1).'
);
}
if (Input::get('denied') || Input::get('error')) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (2).'
);
}
$provider = ucfirst($provider);
try {
$service = Social::service($provider);
if (Config::get('laravel-social::providers.' . strtolower($provider) . '.offline')) {
$service->setAccessType('offline');
}
} catch (Exception $e) {
App::abort(404);
}
if (2 === Social::oauthSpec($provider)) {
return $this->oauth2Connect($provider, $service);
}
else {
return $this->oauth1Connect($provider, $service);
}
}
|
[
"public",
"function",
"getConnect",
"(",
"$",
"provider",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"provider",
")",
")",
"{",
"App",
"::",
"abort",
"(",
"404",
")",
";",
"}",
"$",
"referer",
"=",
"Request",
"::",
"header",
"(",
"'referer'",
",",
"'/'",
")",
";",
"$",
"referer_parts",
"=",
"parse_url",
"(",
"$",
"referer",
")",
";",
"$",
"onboth",
"=",
"array_get",
"(",
"$",
"referer_parts",
",",
"'path'",
")",
";",
"if",
"(",
"array_get",
"(",
"$",
"referer_parts",
",",
"'query'",
")",
")",
"{",
"$",
"onboth",
".=",
"'?'",
".",
"array_get",
"(",
"$",
"referer_parts",
",",
"'query'",
")",
";",
"}",
"if",
"(",
"!",
"Input",
"::",
"get",
"(",
"'code'",
")",
"&&",
"!",
"Input",
"::",
"get",
"(",
"'oauth_token'",
")",
")",
"{",
"Session",
"::",
"put",
"(",
"'mmanos.social.onsuccess'",
",",
"Input",
"::",
"get",
"(",
"'onsuccess'",
",",
"$",
"onboth",
")",
")",
";",
"Session",
"::",
"put",
"(",
"'mmanos.social.onerror'",
",",
"Input",
"::",
"get",
"(",
"'onerror'",
",",
"$",
"onboth",
")",
")",
";",
"}",
"if",
"(",
"!",
"Auth",
"::",
"check",
"(",
")",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem connecting your account (1).'",
")",
";",
"}",
"if",
"(",
"Input",
"::",
"get",
"(",
"'denied'",
")",
"||",
"Input",
"::",
"get",
"(",
"'error'",
")",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem connecting your account (2).'",
")",
";",
"}",
"$",
"provider",
"=",
"ucfirst",
"(",
"$",
"provider",
")",
";",
"try",
"{",
"$",
"service",
"=",
"Social",
"::",
"service",
"(",
"$",
"provider",
")",
";",
"if",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::providers.'",
".",
"strtolower",
"(",
"$",
"provider",
")",
".",
"'.offline'",
")",
")",
"{",
"$",
"service",
"->",
"setAccessType",
"(",
"'offline'",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"App",
"::",
"abort",
"(",
"404",
")",
";",
"}",
"if",
"(",
"2",
"===",
"Social",
"::",
"oauthSpec",
"(",
"$",
"provider",
")",
")",
"{",
"return",
"$",
"this",
"->",
"oauth2Connect",
"(",
"$",
"provider",
",",
"$",
"service",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"oauth1Connect",
"(",
"$",
"provider",
",",
"$",
"service",
")",
";",
"}",
"}"
] |
Connect action.
@param string $provider
@return mixed
|
[
"Connect",
"action",
"."
] |
f3ec7165509825d16cb9d06759a77580a291cb83
|
https://github.com/mmanos/laravel-social/blob/f3ec7165509825d16cb9d06759a77580a291cb83/src/controllers/SocialController.php#L368-L420
|
232,478
|
mmanos/laravel-social
|
src/controllers/SocialController.php
|
SocialController.processConnect
|
protected function processConnect($provider, $service, $access_token)
{
$user_info_callback = Config::get(
'laravel-social::providers.' . strtolower($provider) . '.fetch_user_info'
);
if (empty($user_info_callback) || !$user_info_callback instanceof Closure) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (6).'
);
}
try {
$user_info = $user_info_callback($service);
} catch (Exception $e) {}
if (empty($user_info) || !is_array($user_info)) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (7).'
);
}
if (empty($user_info['id'])) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (8).'
);
}
$provider_id = array_get($user_info, 'id');
$user_provider = Provider::where('provider', strtolower($provider))
->where('provider_id', $provider_id)
->first();
if ($user_provider) {
if ($user_provider->user_id != Auth::id()) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (9).'
);
}
$user_provider->access_token = $access_token;
$user_provider->save();
}
else {
$this->linkProvider(Auth::id(), $provider, $provider_id, $access_token);
}
return Redirect::to(Session::pull('mmanos.social.onsuccess', '/'))
->with(
Config::get('laravel-social::success_flash_var'),
'You have successfully connected your account.'
);
}
|
php
|
protected function processConnect($provider, $service, $access_token)
{
$user_info_callback = Config::get(
'laravel-social::providers.' . strtolower($provider) . '.fetch_user_info'
);
if (empty($user_info_callback) || !$user_info_callback instanceof Closure) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (6).'
);
}
try {
$user_info = $user_info_callback($service);
} catch (Exception $e) {}
if (empty($user_info) || !is_array($user_info)) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (7).'
);
}
if (empty($user_info['id'])) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (8).'
);
}
$provider_id = array_get($user_info, 'id');
$user_provider = Provider::where('provider', strtolower($provider))
->where('provider_id', $provider_id)
->first();
if ($user_provider) {
if ($user_provider->user_id != Auth::id()) {
return Redirect::to(Session::pull('mmanos.social.onerror', '/'))
->with(
Config::get('laravel-social::error_flash_var'),
'There was a problem connecting your account (9).'
);
}
$user_provider->access_token = $access_token;
$user_provider->save();
}
else {
$this->linkProvider(Auth::id(), $provider, $provider_id, $access_token);
}
return Redirect::to(Session::pull('mmanos.social.onsuccess', '/'))
->with(
Config::get('laravel-social::success_flash_var'),
'You have successfully connected your account.'
);
}
|
[
"protected",
"function",
"processConnect",
"(",
"$",
"provider",
",",
"$",
"service",
",",
"$",
"access_token",
")",
"{",
"$",
"user_info_callback",
"=",
"Config",
"::",
"get",
"(",
"'laravel-social::providers.'",
".",
"strtolower",
"(",
"$",
"provider",
")",
".",
"'.fetch_user_info'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"user_info_callback",
")",
"||",
"!",
"$",
"user_info_callback",
"instanceof",
"Closure",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem connecting your account (6).'",
")",
";",
"}",
"try",
"{",
"$",
"user_info",
"=",
"$",
"user_info_callback",
"(",
"$",
"service",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"}",
"if",
"(",
"empty",
"(",
"$",
"user_info",
")",
"||",
"!",
"is_array",
"(",
"$",
"user_info",
")",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem connecting your account (7).'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"user_info",
"[",
"'id'",
"]",
")",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem connecting your account (8).'",
")",
";",
"}",
"$",
"provider_id",
"=",
"array_get",
"(",
"$",
"user_info",
",",
"'id'",
")",
";",
"$",
"user_provider",
"=",
"Provider",
"::",
"where",
"(",
"'provider'",
",",
"strtolower",
"(",
"$",
"provider",
")",
")",
"->",
"where",
"(",
"'provider_id'",
",",
"$",
"provider_id",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"user_provider",
")",
"{",
"if",
"(",
"$",
"user_provider",
"->",
"user_id",
"!=",
"Auth",
"::",
"id",
"(",
")",
")",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onerror'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::error_flash_var'",
")",
",",
"'There was a problem connecting your account (9).'",
")",
";",
"}",
"$",
"user_provider",
"->",
"access_token",
"=",
"$",
"access_token",
";",
"$",
"user_provider",
"->",
"save",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"linkProvider",
"(",
"Auth",
"::",
"id",
"(",
")",
",",
"$",
"provider",
",",
"$",
"provider_id",
",",
"$",
"access_token",
")",
";",
"}",
"return",
"Redirect",
"::",
"to",
"(",
"Session",
"::",
"pull",
"(",
"'mmanos.social.onsuccess'",
",",
"'/'",
")",
")",
"->",
"with",
"(",
"Config",
"::",
"get",
"(",
"'laravel-social::success_flash_var'",
")",
",",
"'You have successfully connected your account.'",
")",
";",
"}"
] |
Process the response from a provider connect attempt.
@param string $provider
@param \OAuth\Common\Service\AbstractService $service
@param array $access_token
@return Redirect
|
[
"Process",
"the",
"response",
"from",
"a",
"provider",
"connect",
"attempt",
"."
] |
f3ec7165509825d16cb9d06759a77580a291cb83
|
https://github.com/mmanos/laravel-social/blob/f3ec7165509825d16cb9d06759a77580a291cb83/src/controllers/SocialController.php#L507-L568
|
232,479
|
mmanos/laravel-social
|
src/controllers/SocialController.php
|
SocialController.linkProvider
|
protected function linkProvider($user_id, $provider, $provider_id, $access_token)
{
$user_provider = new Provider;
$user_provider->user_id = $user_id;
$user_provider->provider = strtolower($provider);
$user_provider->provider_id = $provider_id;
$user_provider->access_token = $access_token;
$user_provider->save();
return $user_provider;
}
|
php
|
protected function linkProvider($user_id, $provider, $provider_id, $access_token)
{
$user_provider = new Provider;
$user_provider->user_id = $user_id;
$user_provider->provider = strtolower($provider);
$user_provider->provider_id = $provider_id;
$user_provider->access_token = $access_token;
$user_provider->save();
return $user_provider;
}
|
[
"protected",
"function",
"linkProvider",
"(",
"$",
"user_id",
",",
"$",
"provider",
",",
"$",
"provider_id",
",",
"$",
"access_token",
")",
"{",
"$",
"user_provider",
"=",
"new",
"Provider",
";",
"$",
"user_provider",
"->",
"user_id",
"=",
"$",
"user_id",
";",
"$",
"user_provider",
"->",
"provider",
"=",
"strtolower",
"(",
"$",
"provider",
")",
";",
"$",
"user_provider",
"->",
"provider_id",
"=",
"$",
"provider_id",
";",
"$",
"user_provider",
"->",
"access_token",
"=",
"$",
"access_token",
";",
"$",
"user_provider",
"->",
"save",
"(",
")",
";",
"return",
"$",
"user_provider",
";",
"}"
] |
Link the give user to the given provider.
@param integer $user_id
@param string $provider
@param integer $provider_id
@param array $access_token
@return Provider
|
[
"Link",
"the",
"give",
"user",
"to",
"the",
"given",
"provider",
"."
] |
f3ec7165509825d16cb9d06759a77580a291cb83
|
https://github.com/mmanos/laravel-social/blob/f3ec7165509825d16cb9d06759a77580a291cb83/src/controllers/SocialController.php#L580-L590
|
232,480
|
thephpleague/flysystem-eventable-filesystem
|
src/Event/After.php
|
After.getArgument
|
public function getArgument($key)
{
if (! array_key_exists($key, $this->arguments)) {
throw new ErrorException('Undefined index: '.$key);
}
return $this->arguments[$key];
}
|
php
|
public function getArgument($key)
{
if (! array_key_exists($key, $this->arguments)) {
throw new ErrorException('Undefined index: '.$key);
}
return $this->arguments[$key];
}
|
[
"public",
"function",
"getArgument",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"arguments",
")",
")",
"{",
"throw",
"new",
"ErrorException",
"(",
"'Undefined index: '",
".",
"$",
"key",
")",
";",
"}",
"return",
"$",
"this",
"->",
"arguments",
"[",
"$",
"key",
"]",
";",
"}"
] |
Get an argument by key.
@param string $key argument key
@throws ErrorException
@return mixed
|
[
"Get",
"an",
"argument",
"by",
"key",
"."
] |
784ddbf1a1c0144c04686b439548286279f0f920
|
https://github.com/thephpleague/flysystem-eventable-filesystem/blob/784ddbf1a1c0144c04686b439548286279f0f920/src/Event/After.php#L120-L127
|
232,481
|
koala-framework/sourcemaps
|
Kwf/SourceMaps/SourceMap.php
|
Kwf_SourceMaps_SourceMap.createFromInline
|
public static function createFromInline($fileContents)
{
// '//# sourceMappingURL=data:application/json;charset:utf-8;base64,
// '//# sourceMappingURL=data:application/json;base64,'
$pos = strrpos($fileContents, "\n//# sourceMappingURL=");
$isCss = false;
if ($pos === false) {
$pos = strrpos($fileContents, "\n/*# sourceMappingURL=");
if ($pos === false) {
throw new Exception("No sourceMappingURL found");
}
$isCss = true;
}
$url = substr($fileContents, $pos + 22);
$url = rtrim($url);
if ($isCss) {
if (substr($url, -2) != '*/') {
throw new Exception("sourceMappingURL isn't wrapped with closing */");
}
$url = substr($url, 0, -2); //remove "*/"
$url = rtrim($url);
}
if (substr($url, 0, 29) == 'data:application/json;base64,') {
$map = substr($url, 29);
} else if (substr($url, 0, 29 + 14) == 'data:application/json;charset:utf-8;base64,') {
$map = substr($url, 29 + 14);
} else if (substr($url, 0, 29 + 14) == 'data:application/json;charset=utf-8;base64,') {
$map = substr($url, 29 + 14);
} else {
throw new Exception("Unsupported sourceMappingURL");
}
$map = base64_decode($map);
$map = json_decode($map);
$fileContents = substr($fileContents, 0, $pos);
$ret = new self($map, $fileContents);
$ret->setMimeType($isCss ? 'text/css' : 'text/javascript');
return $ret;
}
|
php
|
public static function createFromInline($fileContents)
{
// '//# sourceMappingURL=data:application/json;charset:utf-8;base64,
// '//# sourceMappingURL=data:application/json;base64,'
$pos = strrpos($fileContents, "\n//# sourceMappingURL=");
$isCss = false;
if ($pos === false) {
$pos = strrpos($fileContents, "\n/*# sourceMappingURL=");
if ($pos === false) {
throw new Exception("No sourceMappingURL found");
}
$isCss = true;
}
$url = substr($fileContents, $pos + 22);
$url = rtrim($url);
if ($isCss) {
if (substr($url, -2) != '*/') {
throw new Exception("sourceMappingURL isn't wrapped with closing */");
}
$url = substr($url, 0, -2); //remove "*/"
$url = rtrim($url);
}
if (substr($url, 0, 29) == 'data:application/json;base64,') {
$map = substr($url, 29);
} else if (substr($url, 0, 29 + 14) == 'data:application/json;charset:utf-8;base64,') {
$map = substr($url, 29 + 14);
} else if (substr($url, 0, 29 + 14) == 'data:application/json;charset=utf-8;base64,') {
$map = substr($url, 29 + 14);
} else {
throw new Exception("Unsupported sourceMappingURL");
}
$map = base64_decode($map);
$map = json_decode($map);
$fileContents = substr($fileContents, 0, $pos);
$ret = new self($map, $fileContents);
$ret->setMimeType($isCss ? 'text/css' : 'text/javascript');
return $ret;
}
|
[
"public",
"static",
"function",
"createFromInline",
"(",
"$",
"fileContents",
")",
"{",
"// '//# sourceMappingURL=data:application/json;charset:utf-8;base64,",
"// '//# sourceMappingURL=data:application/json;base64,'",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"fileContents",
",",
"\"\\n//# sourceMappingURL=\"",
")",
";",
"$",
"isCss",
"=",
"false",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"fileContents",
",",
"\"\\n/*# sourceMappingURL=\"",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"No sourceMappingURL found\"",
")",
";",
"}",
"$",
"isCss",
"=",
"true",
";",
"}",
"$",
"url",
"=",
"substr",
"(",
"$",
"fileContents",
",",
"$",
"pos",
"+",
"22",
")",
";",
"$",
"url",
"=",
"rtrim",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"isCss",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"-",
"2",
")",
"!=",
"'*/'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"sourceMappingURL isn't wrapped with closing */\"",
")",
";",
"}",
"$",
"url",
"=",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"-",
"2",
")",
";",
"//remove \"*/\"",
"$",
"url",
"=",
"rtrim",
"(",
"$",
"url",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"29",
")",
"==",
"'data:application/json;base64,'",
")",
"{",
"$",
"map",
"=",
"substr",
"(",
"$",
"url",
",",
"29",
")",
";",
"}",
"else",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"29",
"+",
"14",
")",
"==",
"'data:application/json;charset:utf-8;base64,'",
")",
"{",
"$",
"map",
"=",
"substr",
"(",
"$",
"url",
",",
"29",
"+",
"14",
")",
";",
"}",
"else",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"29",
"+",
"14",
")",
"==",
"'data:application/json;charset=utf-8;base64,'",
")",
"{",
"$",
"map",
"=",
"substr",
"(",
"$",
"url",
",",
"29",
"+",
"14",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unsupported sourceMappingURL\"",
")",
";",
"}",
"$",
"map",
"=",
"base64_decode",
"(",
"$",
"map",
")",
";",
"$",
"map",
"=",
"json_decode",
"(",
"$",
"map",
")",
";",
"$",
"fileContents",
"=",
"substr",
"(",
"$",
"fileContents",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"ret",
"=",
"new",
"self",
"(",
"$",
"map",
",",
"$",
"fileContents",
")",
";",
"$",
"ret",
"->",
"setMimeType",
"(",
"$",
"isCss",
"?",
"'text/css'",
":",
"'text/javascript'",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
Create a new sourcemap based on sourceMappingURL with inline base64 encoded data
Example:
//# sourceMappingURL=data:application/json;base64,....
@param string contents of the minified file including sourceMappingURL
|
[
"Create",
"a",
"new",
"sourcemap",
"based",
"on",
"sourceMappingURL",
"with",
"inline",
"base64",
"encoded",
"data"
] |
d6e573412a693978fda6bd97dbbe40d335adae7e
|
https://github.com/koala-framework/sourcemaps/blob/d6e573412a693978fda6bd97dbbe40d335adae7e/Kwf/SourceMaps/SourceMap.php#L107-L145
|
232,482
|
koala-framework/sourcemaps
|
Kwf/SourceMaps/SourceMap.php
|
Kwf_SourceMaps_SourceMap.stringReplace
|
public function stringReplace($string, $replace)
{
if ($this->_mappingsChanged) {
$this->_generateMappings();
}
if (strpos("\n", $string)) {
throw new Exception('string must not contain \n');
}
if ($replace != "" && strpos("\n", $replace)) {
throw new Exception('replace must not contain \n');
}
$adjustOffsets = array();
$pos = 0;
$str = $this->_fileContents;
$offset = 0;
$lineOffset = 0;
while (($pos = strpos($str, $string, $pos)) !== false) {
$line = substr_count(substr($str, 0, $pos), "\n") + 1;
if (!isset($adjustOffsets[$line])) {
//first in line
$lineOffset = 0;
}
$this->_fileContents = substr($this->_fileContents, 0, $pos + $offset).$replace.substr($this->_fileContents, $pos + $offset + strlen($string));
$offset += strlen($replace) - strlen($string);
$lineOffset += strlen($replace) - strlen($string);
$column = $pos - strrpos(substr($str, 0, $pos), "\n") + 1; //strrpos can return false for first line which will subtract 0 (=false)
$adjustOffsets[$line][] = array(
'column' => $column,
'absoluteOffset' => $offset,
'lineOffset' => $lineOffset,
'offset' => strlen($replace) - strlen($string),
'replacedLength' => strlen($string)
);
$pos = $pos + strlen($string);
}
$mappings = $this->getMappings();
$this->_mappingsChanged = true;
$this->_mappings = array();
foreach ($mappings as $mappingIndex=>$mapping) {
if (isset($adjustOffsets[$mapping['generatedLine']])) {
foreach (array_reverse($adjustOffsets[$mapping['generatedLine']], true) as $offsIndex=>$offs) {
if ($mapping['generatedColumn'] > $offs['column']) {
if ($mapping['generatedColumn'] < $offs['column']-1+$offs['replacedLength']) {
//mapping inside replaced test, remove
continue 2;
} else {
$mapping['generatedColumn'] += $offs['lineOffset'];
break;
}
}
}
}
$this->_mappings[] = $mapping;
}
}
|
php
|
public function stringReplace($string, $replace)
{
if ($this->_mappingsChanged) {
$this->_generateMappings();
}
if (strpos("\n", $string)) {
throw new Exception('string must not contain \n');
}
if ($replace != "" && strpos("\n", $replace)) {
throw new Exception('replace must not contain \n');
}
$adjustOffsets = array();
$pos = 0;
$str = $this->_fileContents;
$offset = 0;
$lineOffset = 0;
while (($pos = strpos($str, $string, $pos)) !== false) {
$line = substr_count(substr($str, 0, $pos), "\n") + 1;
if (!isset($adjustOffsets[$line])) {
//first in line
$lineOffset = 0;
}
$this->_fileContents = substr($this->_fileContents, 0, $pos + $offset).$replace.substr($this->_fileContents, $pos + $offset + strlen($string));
$offset += strlen($replace) - strlen($string);
$lineOffset += strlen($replace) - strlen($string);
$column = $pos - strrpos(substr($str, 0, $pos), "\n") + 1; //strrpos can return false for first line which will subtract 0 (=false)
$adjustOffsets[$line][] = array(
'column' => $column,
'absoluteOffset' => $offset,
'lineOffset' => $lineOffset,
'offset' => strlen($replace) - strlen($string),
'replacedLength' => strlen($string)
);
$pos = $pos + strlen($string);
}
$mappings = $this->getMappings();
$this->_mappingsChanged = true;
$this->_mappings = array();
foreach ($mappings as $mappingIndex=>$mapping) {
if (isset($adjustOffsets[$mapping['generatedLine']])) {
foreach (array_reverse($adjustOffsets[$mapping['generatedLine']], true) as $offsIndex=>$offs) {
if ($mapping['generatedColumn'] > $offs['column']) {
if ($mapping['generatedColumn'] < $offs['column']-1+$offs['replacedLength']) {
//mapping inside replaced test, remove
continue 2;
} else {
$mapping['generatedColumn'] += $offs['lineOffset'];
break;
}
}
}
}
$this->_mappings[] = $mapping;
}
}
|
[
"public",
"function",
"stringReplace",
"(",
"$",
"string",
",",
"$",
"replace",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_mappingsChanged",
")",
"{",
"$",
"this",
"->",
"_generateMappings",
"(",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"\"\\n\"",
",",
"$",
"string",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'string must not contain \\n'",
")",
";",
"}",
"if",
"(",
"$",
"replace",
"!=",
"\"\"",
"&&",
"strpos",
"(",
"\"\\n\"",
",",
"$",
"replace",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'replace must not contain \\n'",
")",
";",
"}",
"$",
"adjustOffsets",
"=",
"array",
"(",
")",
";",
"$",
"pos",
"=",
"0",
";",
"$",
"str",
"=",
"$",
"this",
"->",
"_fileContents",
";",
"$",
"offset",
"=",
"0",
";",
"$",
"lineOffset",
"=",
"0",
";",
"while",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"str",
",",
"$",
"string",
",",
"$",
"pos",
")",
")",
"!==",
"false",
")",
"{",
"$",
"line",
"=",
"substr_count",
"(",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"$",
"pos",
")",
",",
"\"\\n\"",
")",
"+",
"1",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"adjustOffsets",
"[",
"$",
"line",
"]",
")",
")",
"{",
"//first in line",
"$",
"lineOffset",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"_fileContents",
"=",
"substr",
"(",
"$",
"this",
"->",
"_fileContents",
",",
"0",
",",
"$",
"pos",
"+",
"$",
"offset",
")",
".",
"$",
"replace",
".",
"substr",
"(",
"$",
"this",
"->",
"_fileContents",
",",
"$",
"pos",
"+",
"$",
"offset",
"+",
"strlen",
"(",
"$",
"string",
")",
")",
";",
"$",
"offset",
"+=",
"strlen",
"(",
"$",
"replace",
")",
"-",
"strlen",
"(",
"$",
"string",
")",
";",
"$",
"lineOffset",
"+=",
"strlen",
"(",
"$",
"replace",
")",
"-",
"strlen",
"(",
"$",
"string",
")",
";",
"$",
"column",
"=",
"$",
"pos",
"-",
"strrpos",
"(",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"$",
"pos",
")",
",",
"\"\\n\"",
")",
"+",
"1",
";",
"//strrpos can return false for first line which will subtract 0 (=false)",
"$",
"adjustOffsets",
"[",
"$",
"line",
"]",
"[",
"]",
"=",
"array",
"(",
"'column'",
"=>",
"$",
"column",
",",
"'absoluteOffset'",
"=>",
"$",
"offset",
",",
"'lineOffset'",
"=>",
"$",
"lineOffset",
",",
"'offset'",
"=>",
"strlen",
"(",
"$",
"replace",
")",
"-",
"strlen",
"(",
"$",
"string",
")",
",",
"'replacedLength'",
"=>",
"strlen",
"(",
"$",
"string",
")",
")",
";",
"$",
"pos",
"=",
"$",
"pos",
"+",
"strlen",
"(",
"$",
"string",
")",
";",
"}",
"$",
"mappings",
"=",
"$",
"this",
"->",
"getMappings",
"(",
")",
";",
"$",
"this",
"->",
"_mappingsChanged",
"=",
"true",
";",
"$",
"this",
"->",
"_mappings",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"mappings",
"as",
"$",
"mappingIndex",
"=>",
"$",
"mapping",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"adjustOffsets",
"[",
"$",
"mapping",
"[",
"'generatedLine'",
"]",
"]",
")",
")",
"{",
"foreach",
"(",
"array_reverse",
"(",
"$",
"adjustOffsets",
"[",
"$",
"mapping",
"[",
"'generatedLine'",
"]",
"]",
",",
"true",
")",
"as",
"$",
"offsIndex",
"=>",
"$",
"offs",
")",
"{",
"if",
"(",
"$",
"mapping",
"[",
"'generatedColumn'",
"]",
">",
"$",
"offs",
"[",
"'column'",
"]",
")",
"{",
"if",
"(",
"$",
"mapping",
"[",
"'generatedColumn'",
"]",
"<",
"$",
"offs",
"[",
"'column'",
"]",
"-",
"1",
"+",
"$",
"offs",
"[",
"'replacedLength'",
"]",
")",
"{",
"//mapping inside replaced test, remove",
"continue",
"2",
";",
"}",
"else",
"{",
"$",
"mapping",
"[",
"'generatedColumn'",
"]",
"+=",
"$",
"offs",
"[",
"'lineOffset'",
"]",
";",
"break",
";",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"_mappings",
"[",
"]",
"=",
"$",
"mapping",
";",
"}",
"}"
] |
Performant Source Map aware string replace
@param string
@param string
|
[
"Performant",
"Source",
"Map",
"aware",
"string",
"replace"
] |
d6e573412a693978fda6bd97dbbe40d335adae7e
|
https://github.com/koala-framework/sourcemaps/blob/d6e573412a693978fda6bd97dbbe40d335adae7e/Kwf/SourceMaps/SourceMap.php#L272-L329
|
232,483
|
koala-framework/sourcemaps
|
Kwf/SourceMaps/SourceMap.php
|
Kwf_SourceMaps_SourceMap.getMapContents
|
public function getMapContents($includeLastExtension = true)
{
if ($this->_mappingsChanged) {
$this->_generateMappings();
}
if ($includeLastExtension && !isset($this->_map->{'_x_org_koala-framework_last'})) {
$this->_addLastExtension();
}
return json_encode($this->_map);
}
|
php
|
public function getMapContents($includeLastExtension = true)
{
if ($this->_mappingsChanged) {
$this->_generateMappings();
}
if ($includeLastExtension && !isset($this->_map->{'_x_org_koala-framework_last'})) {
$this->_addLastExtension();
}
return json_encode($this->_map);
}
|
[
"public",
"function",
"getMapContents",
"(",
"$",
"includeLastExtension",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_mappingsChanged",
")",
"{",
"$",
"this",
"->",
"_generateMappings",
"(",
")",
";",
"}",
"if",
"(",
"$",
"includeLastExtension",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"_map",
"->",
"{",
"'_x_org_koala-framework_last'",
"}",
")",
")",
"{",
"$",
"this",
"->",
"_addLastExtension",
"(",
")",
";",
"}",
"return",
"json_encode",
"(",
"$",
"this",
"->",
"_map",
")",
";",
"}"
] |
Returns the contents of the source map as string
@return string
|
[
"Returns",
"the",
"contents",
"of",
"the",
"source",
"map",
"as",
"string"
] |
d6e573412a693978fda6bd97dbbe40d335adae7e
|
https://github.com/koala-framework/sourcemaps/blob/d6e573412a693978fda6bd97dbbe40d335adae7e/Kwf/SourceMaps/SourceMap.php#L675-L684
|
232,484
|
koala-framework/sourcemaps
|
Kwf/SourceMaps/SourceMap.php
|
Kwf_SourceMaps_SourceMap.save
|
public function save($mapFileName, $fileFileName = null)
{
if ($fileFileName !== null) {
file_put_contents($fileFileName, $this->_fileContents);
}
file_put_contents($mapFileName, $this->getMapContents());
}
|
php
|
public function save($mapFileName, $fileFileName = null)
{
if ($fileFileName !== null) {
file_put_contents($fileFileName, $this->_fileContents);
}
file_put_contents($mapFileName, $this->getMapContents());
}
|
[
"public",
"function",
"save",
"(",
"$",
"mapFileName",
",",
"$",
"fileFileName",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"fileFileName",
"!==",
"null",
")",
"{",
"file_put_contents",
"(",
"$",
"fileFileName",
",",
"$",
"this",
"->",
"_fileContents",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"mapFileName",
",",
"$",
"this",
"->",
"getMapContents",
"(",
")",
")",
";",
"}"
] |
Save the source map to a file
@param string file name the source map should be saved to
@param string optional file name the minified file should be saved to
|
[
"Save",
"the",
"source",
"map",
"to",
"a",
"file"
] |
d6e573412a693978fda6bd97dbbe40d335adae7e
|
https://github.com/koala-framework/sourcemaps/blob/d6e573412a693978fda6bd97dbbe40d335adae7e/Kwf/SourceMaps/SourceMap.php#L708-L714
|
232,485
|
koala-framework/sourcemaps
|
Kwf/SourceMaps/SourceMap.php
|
Kwf_SourceMaps_SourceMap.getFileContentsInlineMap
|
public function getFileContentsInlineMap($includeLastExtension = true)
{
$ret = $this->_fileContents;
if ($this->_mimeType == 'text/css') {
$ret .= "\n/*# sourceMappingURL=data:application/json;base64,".base64_encode($this->getMapContents($includeLastExtension))." */\n";
} else {
$ret .= "\n//# sourceMappingURL=data:application/json;base64,".base64_encode($this->getMapContents($includeLastExtension))."\n";
}
return $ret;
}
|
php
|
public function getFileContentsInlineMap($includeLastExtension = true)
{
$ret = $this->_fileContents;
if ($this->_mimeType == 'text/css') {
$ret .= "\n/*# sourceMappingURL=data:application/json;base64,".base64_encode($this->getMapContents($includeLastExtension))." */\n";
} else {
$ret .= "\n//# sourceMappingURL=data:application/json;base64,".base64_encode($this->getMapContents($includeLastExtension))."\n";
}
return $ret;
}
|
[
"public",
"function",
"getFileContentsInlineMap",
"(",
"$",
"includeLastExtension",
"=",
"true",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"_fileContents",
";",
"if",
"(",
"$",
"this",
"->",
"_mimeType",
"==",
"'text/css'",
")",
"{",
"$",
"ret",
".=",
"\"\\n/*# sourceMappingURL=data:application/json;base64,\"",
".",
"base64_encode",
"(",
"$",
"this",
"->",
"getMapContents",
"(",
"$",
"includeLastExtension",
")",
")",
".",
"\" */\\n\"",
";",
"}",
"else",
"{",
"$",
"ret",
".=",
"\"\\n//# sourceMappingURL=data:application/json;base64,\"",
".",
"base64_encode",
"(",
"$",
"this",
"->",
"getMapContents",
"(",
"$",
"includeLastExtension",
")",
")",
".",
"\"\\n\"",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Returns the contents of the minimied file with source map data appended inline as data url
@return string
|
[
"Returns",
"the",
"contents",
"of",
"the",
"minimied",
"file",
"with",
"source",
"map",
"data",
"appended",
"inline",
"as",
"data",
"url"
] |
d6e573412a693978fda6bd97dbbe40d335adae7e
|
https://github.com/koala-framework/sourcemaps/blob/d6e573412a693978fda6bd97dbbe40d335adae7e/Kwf/SourceMaps/SourceMap.php#L721-L730
|
232,486
|
mmanos/laravel-api
|
src/Mmanos/Api/Authentication.php
|
Authentication.clientId
|
public function clientId()
{
if (isset($this->client_id)) {
return $this->client_id ? $this->client_id : null;
}
if (!$this->check()) {
return null;
}
if (Request::input('client_id')) {
$this->client_id = Request::input('client_id');
}
else if ($id = Authorizer::getClientId()) {
$this->client_id = $id;
}
else {
$this->client_id = false;
}
return $this->client_id ? $this->client_id : null;
}
|
php
|
public function clientId()
{
if (isset($this->client_id)) {
return $this->client_id ? $this->client_id : null;
}
if (!$this->check()) {
return null;
}
if (Request::input('client_id')) {
$this->client_id = Request::input('client_id');
}
else if ($id = Authorizer::getClientId()) {
$this->client_id = $id;
}
else {
$this->client_id = false;
}
return $this->client_id ? $this->client_id : null;
}
|
[
"public",
"function",
"clientId",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"client_id",
")",
")",
"{",
"return",
"$",
"this",
"->",
"client_id",
"?",
"$",
"this",
"->",
"client_id",
":",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"Request",
"::",
"input",
"(",
"'client_id'",
")",
")",
"{",
"$",
"this",
"->",
"client_id",
"=",
"Request",
"::",
"input",
"(",
"'client_id'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"id",
"=",
"Authorizer",
"::",
"getClientId",
"(",
")",
")",
"{",
"$",
"this",
"->",
"client_id",
"=",
"$",
"id",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"client_id",
"=",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"client_id",
"?",
"$",
"this",
"->",
"client_id",
":",
"null",
";",
"}"
] |
Return the current oauth client.
@return string
|
[
"Return",
"the",
"current",
"oauth",
"client",
"."
] |
8fac248d91c797f4a8f960e7cd7466df5a814975
|
https://github.com/mmanos/laravel-api/blob/8fac248d91c797f4a8f960e7cd7466df5a814975/src/Mmanos/Api/Authentication.php#L37-L58
|
232,487
|
mmanos/laravel-api
|
src/Mmanos/Api/Authentication.php
|
Authentication.client
|
public function client()
{
if (isset($this->client)) {
return $this->client ? $this->client : null;
}
$client_id = $this->clientId();
if (!$client_id) {
$this->client = false;
return null;
}
$client = $this->fetchClient($client_id);
if ($client) {
$this->client = $client;
}
else {
$this->client = false;
}
return $this->client ? $this->client : null;
}
|
php
|
public function client()
{
if (isset($this->client)) {
return $this->client ? $this->client : null;
}
$client_id = $this->clientId();
if (!$client_id) {
$this->client = false;
return null;
}
$client = $this->fetchClient($client_id);
if ($client) {
$this->client = $client;
}
else {
$this->client = false;
}
return $this->client ? $this->client : null;
}
|
[
"public",
"function",
"client",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"client",
")",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"?",
"$",
"this",
"->",
"client",
":",
"null",
";",
"}",
"$",
"client_id",
"=",
"$",
"this",
"->",
"clientId",
"(",
")",
";",
"if",
"(",
"!",
"$",
"client_id",
")",
"{",
"$",
"this",
"->",
"client",
"=",
"false",
";",
"return",
"null",
";",
"}",
"$",
"client",
"=",
"$",
"this",
"->",
"fetchClient",
"(",
"$",
"client_id",
")",
";",
"if",
"(",
"$",
"client",
")",
"{",
"$",
"this",
"->",
"client",
"=",
"$",
"client",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"client",
"=",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"client",
"?",
"$",
"this",
"->",
"client",
":",
"null",
";",
"}"
] |
Return an array of details for the current client.
@return array
|
[
"Return",
"an",
"array",
"of",
"details",
"for",
"the",
"current",
"client",
"."
] |
8fac248d91c797f4a8f960e7cd7466df5a814975
|
https://github.com/mmanos/laravel-api/blob/8fac248d91c797f4a8f960e7cd7466df5a814975/src/Mmanos/Api/Authentication.php#L65-L86
|
232,488
|
mmanos/laravel-api
|
src/Mmanos/Api/Authentication.php
|
Authentication.check
|
public function check()
{
if (isset($this->check)) {
return $this->check;
}
try {
Authorizer::validateAccessToken();
$this->type = 'user';
return $this->check = true;
} catch (Exception $e) {}
$client_id = Request::input('client_id');
$client_secret = Request::input('client_secret');
if (!$client_id || !$client_secret) {
return $this->check = false;
}
$client = $this->fetchClient($client_id, $client_secret);
if (!$client) {
return $this->check = false;
}
if (!in_array('client_id_secret', $client->grants())) {
return $this->check = false;
}
$this->client = $client;
$this->type = 'client';
return $this->check = true;
}
|
php
|
public function check()
{
if (isset($this->check)) {
return $this->check;
}
try {
Authorizer::validateAccessToken();
$this->type = 'user';
return $this->check = true;
} catch (Exception $e) {}
$client_id = Request::input('client_id');
$client_secret = Request::input('client_secret');
if (!$client_id || !$client_secret) {
return $this->check = false;
}
$client = $this->fetchClient($client_id, $client_secret);
if (!$client) {
return $this->check = false;
}
if (!in_array('client_id_secret', $client->grants())) {
return $this->check = false;
}
$this->client = $client;
$this->type = 'client';
return $this->check = true;
}
|
[
"public",
"function",
"check",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"check",
")",
")",
"{",
"return",
"$",
"this",
"->",
"check",
";",
"}",
"try",
"{",
"Authorizer",
"::",
"validateAccessToken",
"(",
")",
";",
"$",
"this",
"->",
"type",
"=",
"'user'",
";",
"return",
"$",
"this",
"->",
"check",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"}",
"$",
"client_id",
"=",
"Request",
"::",
"input",
"(",
"'client_id'",
")",
";",
"$",
"client_secret",
"=",
"Request",
"::",
"input",
"(",
"'client_secret'",
")",
";",
"if",
"(",
"!",
"$",
"client_id",
"||",
"!",
"$",
"client_secret",
")",
"{",
"return",
"$",
"this",
"->",
"check",
"=",
"false",
";",
"}",
"$",
"client",
"=",
"$",
"this",
"->",
"fetchClient",
"(",
"$",
"client_id",
",",
"$",
"client_secret",
")",
";",
"if",
"(",
"!",
"$",
"client",
")",
"{",
"return",
"$",
"this",
"->",
"check",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"'client_id_secret'",
",",
"$",
"client",
"->",
"grants",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"check",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"client",
"=",
"$",
"client",
";",
"$",
"this",
"->",
"type",
"=",
"'client'",
";",
"return",
"$",
"this",
"->",
"check",
"=",
"true",
";",
"}"
] |
Validate authorization for the current request.
@return bool
|
[
"Validate",
"authorization",
"for",
"the",
"current",
"request",
"."
] |
8fac248d91c797f4a8f960e7cd7466df5a814975
|
https://github.com/mmanos/laravel-api/blob/8fac248d91c797f4a8f960e7cd7466df5a814975/src/Mmanos/Api/Authentication.php#L127-L157
|
232,489
|
mmanos/laravel-api
|
src/Mmanos/Api/Authentication.php
|
Authentication.checkScope
|
public function checkScope($scope)
{
if (isset($this->scopes[$scope])) {
return $this->scopes[$scope];
}
if (!empty($this->scopes['*'])) {
return true;
}
if (!$this->check()) {
return false;
}
if ('user' == $this->type) {
$this->scopes[$scope] = Authorizer::hasScope($scope);
}
else {
$client = $this->client();
$this->scopes[$scope] = in_array($scope, $client->scopes());
}
if (!$this->scopes[$scope] && '*' != $scope) {
$this->scopes[$scope] = $this->checkScope('*');
}
return $this->scopes[$scope];
}
|
php
|
public function checkScope($scope)
{
if (isset($this->scopes[$scope])) {
return $this->scopes[$scope];
}
if (!empty($this->scopes['*'])) {
return true;
}
if (!$this->check()) {
return false;
}
if ('user' == $this->type) {
$this->scopes[$scope] = Authorizer::hasScope($scope);
}
else {
$client = $this->client();
$this->scopes[$scope] = in_array($scope, $client->scopes());
}
if (!$this->scopes[$scope] && '*' != $scope) {
$this->scopes[$scope] = $this->checkScope('*');
}
return $this->scopes[$scope];
}
|
[
"public",
"function",
"checkScope",
"(",
"$",
"scope",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"scopes",
"[",
"$",
"scope",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"scopes",
"[",
"$",
"scope",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"scopes",
"[",
"'*'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"'user'",
"==",
"$",
"this",
"->",
"type",
")",
"{",
"$",
"this",
"->",
"scopes",
"[",
"$",
"scope",
"]",
"=",
"Authorizer",
"::",
"hasScope",
"(",
"$",
"scope",
")",
";",
"}",
"else",
"{",
"$",
"client",
"=",
"$",
"this",
"->",
"client",
"(",
")",
";",
"$",
"this",
"->",
"scopes",
"[",
"$",
"scope",
"]",
"=",
"in_array",
"(",
"$",
"scope",
",",
"$",
"client",
"->",
"scopes",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"scopes",
"[",
"$",
"scope",
"]",
"&&",
"'*'",
"!=",
"$",
"scope",
")",
"{",
"$",
"this",
"->",
"scopes",
"[",
"$",
"scope",
"]",
"=",
"$",
"this",
"->",
"checkScope",
"(",
"'*'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"scopes",
"[",
"$",
"scope",
"]",
";",
"}"
] |
Ensure the current authentication has access to the requested scope.
@param string $scope
@return bool
|
[
"Ensure",
"the",
"current",
"authentication",
"has",
"access",
"to",
"the",
"requested",
"scope",
"."
] |
8fac248d91c797f4a8f960e7cd7466df5a814975
|
https://github.com/mmanos/laravel-api/blob/8fac248d91c797f4a8f960e7cd7466df5a814975/src/Mmanos/Api/Authentication.php#L166-L193
|
232,490
|
mmanos/laravel-api
|
src/Mmanos/Api/Authentication.php
|
Authentication.fetchClient
|
public static function fetchClient($client_id, $client_secret = null)
{
$query = DB::table('oauth_clients')->where('id', $client_id);
if (null !== $client_secret) {
$query->where('secret', $client_secret);
}
$client = $query->first();
if (!$client) {
return null;
}
return new Authentication\Client($client_id, (array) $client);
}
|
php
|
public static function fetchClient($client_id, $client_secret = null)
{
$query = DB::table('oauth_clients')->where('id', $client_id);
if (null !== $client_secret) {
$query->where('secret', $client_secret);
}
$client = $query->first();
if (!$client) {
return null;
}
return new Authentication\Client($client_id, (array) $client);
}
|
[
"public",
"static",
"function",
"fetchClient",
"(",
"$",
"client_id",
",",
"$",
"client_secret",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"DB",
"::",
"table",
"(",
"'oauth_clients'",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"client_id",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"client_secret",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'secret'",
",",
"$",
"client_secret",
")",
";",
"}",
"$",
"client",
"=",
"$",
"query",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"$",
"client",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"Authentication",
"\\",
"Client",
"(",
"$",
"client_id",
",",
"(",
"array",
")",
"$",
"client",
")",
";",
"}"
] |
Fetch a Authentication\Client instance for the requested client id.
@param string $client_id
@param string $client_secret
@return Authentication\Client
|
[
"Fetch",
"a",
"Authentication",
"\\",
"Client",
"instance",
"for",
"the",
"requested",
"client",
"id",
"."
] |
8fac248d91c797f4a8f960e7cd7466df5a814975
|
https://github.com/mmanos/laravel-api/blob/8fac248d91c797f4a8f960e7cd7466df5a814975/src/Mmanos/Api/Authentication.php#L203-L216
|
232,491
|
nineinchnick/yii2-usr
|
controllers/DefaultController.php
|
DefaultController.beforeAction
|
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
switch ($action->id) {
case 'index':
case 'profile':
case 'profilePicture':
if (Yii::$app->user->isGuest) {
$this->redirect(['login']);
return false;
}
break;
case 'login':
case 'recovery':
if ($action->id === 'recovery' && !$this->module->recoveryEnabled) {
throw new AccessDeniedHttpException(Yii::t('usr', 'Password recovery has not been enabled.'));
}
if (!Yii::$app->user->isGuest) {
$this->goBack();
return false;
}
break;
case 'register':
if (!$this->module->registrationEnabled) {
throw new AccessDeniedHttpException(Yii::t('usr', 'Registration has not been enabled.'));
}
if (!Yii::$app->user->isGuest) {
$this->redirect(['profile']);
return false;
}
break;
case 'verify':
if (!isset($_GET['activationKey'])) {
throw new BadRequestHttpException(Yii::t('usr', 'Activation key is missing.'));
}
break;
}
return true;
}
|
php
|
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
switch ($action->id) {
case 'index':
case 'profile':
case 'profilePicture':
if (Yii::$app->user->isGuest) {
$this->redirect(['login']);
return false;
}
break;
case 'login':
case 'recovery':
if ($action->id === 'recovery' && !$this->module->recoveryEnabled) {
throw new AccessDeniedHttpException(Yii::t('usr', 'Password recovery has not been enabled.'));
}
if (!Yii::$app->user->isGuest) {
$this->goBack();
return false;
}
break;
case 'register':
if (!$this->module->registrationEnabled) {
throw new AccessDeniedHttpException(Yii::t('usr', 'Registration has not been enabled.'));
}
if (!Yii::$app->user->isGuest) {
$this->redirect(['profile']);
return false;
}
break;
case 'verify':
if (!isset($_GET['activationKey'])) {
throw new BadRequestHttpException(Yii::t('usr', 'Activation key is missing.'));
}
break;
}
return true;
}
|
[
"public",
"function",
"beforeAction",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"!",
"parent",
"::",
"beforeAction",
"(",
"$",
"action",
")",
")",
"{",
"return",
"false",
";",
"}",
"switch",
"(",
"$",
"action",
"->",
"id",
")",
"{",
"case",
"'index'",
":",
"case",
"'profile'",
":",
"case",
"'profilePicture'",
":",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'login'",
"]",
")",
";",
"return",
"false",
";",
"}",
"break",
";",
"case",
"'login'",
":",
"case",
"'recovery'",
":",
"if",
"(",
"$",
"action",
"->",
"id",
"===",
"'recovery'",
"&&",
"!",
"$",
"this",
"->",
"module",
"->",
"recoveryEnabled",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Password recovery has not been enabled.'",
")",
")",
";",
"}",
"if",
"(",
"!",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"this",
"->",
"goBack",
"(",
")",
";",
"return",
"false",
";",
"}",
"break",
";",
"case",
"'register'",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"module",
"->",
"registrationEnabled",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Registration has not been enabled.'",
")",
")",
";",
"}",
"if",
"(",
"!",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'profile'",
"]",
")",
";",
"return",
"false",
";",
"}",
"break",
";",
"case",
"'verify'",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"_GET",
"[",
"'activationKey'",
"]",
")",
")",
"{",
"throw",
"new",
"BadRequestHttpException",
"(",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Activation key is missing.'",
")",
")",
";",
"}",
"break",
";",
"}",
"return",
"true",
";",
"}"
] |
Redirect user depending on whether is he logged in or not.
Performs additional authorization checks.
@param Action $action the action to be executed.
@return boolean whether the action should continue to be executed.
|
[
"Redirect",
"user",
"depending",
"on",
"whether",
"is",
"he",
"logged",
"in",
"or",
"not",
".",
"Performs",
"additional",
"authorization",
"checks",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/controllers/DefaultController.php#L65-L109
|
232,492
|
nineinchnick/yii2-usr
|
controllers/DefaultController.php
|
DefaultController.actionLogin
|
public function actionLogin($scenario = null)
{
/** @var LoginForm */
$model = $this->module->createFormModel('LoginForm');
$scenarios = $model->scenarios();
if ($scenario !== null && in_array($scenario, array_keys($scenarios))) {
$model->scenario = $scenario;
}
if ($model->load($_POST)) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return \yii\widgets\ActiveForm::validate($model);
}
if ($model->validate()) {
if (($model->scenario !== 'reset' || $model->resetPassword($model->newPassword)) && $model->login($this->module->rememberMeDuration)) {
return $this->afterLogin();
} else {
Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to change password or log in using new password.'));
}
}
}
list($view, $params) = $this->getScenarioView($model->scenario, 'login');
return $this->render($view, array_merge(['model' => $model], $params));
}
|
php
|
public function actionLogin($scenario = null)
{
/** @var LoginForm */
$model = $this->module->createFormModel('LoginForm');
$scenarios = $model->scenarios();
if ($scenario !== null && in_array($scenario, array_keys($scenarios))) {
$model->scenario = $scenario;
}
if ($model->load($_POST)) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return \yii\widgets\ActiveForm::validate($model);
}
if ($model->validate()) {
if (($model->scenario !== 'reset' || $model->resetPassword($model->newPassword)) && $model->login($this->module->rememberMeDuration)) {
return $this->afterLogin();
} else {
Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to change password or log in using new password.'));
}
}
}
list($view, $params) = $this->getScenarioView($model->scenario, 'login');
return $this->render($view, array_merge(['model' => $model], $params));
}
|
[
"public",
"function",
"actionLogin",
"(",
"$",
"scenario",
"=",
"null",
")",
"{",
"/** @var LoginForm */",
"$",
"model",
"=",
"$",
"this",
"->",
"module",
"->",
"createFormModel",
"(",
"'LoginForm'",
")",
";",
"$",
"scenarios",
"=",
"$",
"model",
"->",
"scenarios",
"(",
")",
";",
"if",
"(",
"$",
"scenario",
"!==",
"null",
"&&",
"in_array",
"(",
"$",
"scenario",
",",
"array_keys",
"(",
"$",
"scenarios",
")",
")",
")",
"{",
"$",
"model",
"->",
"scenario",
"=",
"$",
"scenario",
";",
"}",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"$",
"_POST",
")",
")",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"isAjax",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"response",
"->",
"format",
"=",
"\\",
"yii",
"\\",
"web",
"\\",
"Response",
"::",
"FORMAT_JSON",
";",
"return",
"\\",
"yii",
"\\",
"widgets",
"\\",
"ActiveForm",
"::",
"validate",
"(",
"$",
"model",
")",
";",
"}",
"if",
"(",
"$",
"model",
"->",
"validate",
"(",
")",
")",
"{",
"if",
"(",
"(",
"$",
"model",
"->",
"scenario",
"!==",
"'reset'",
"||",
"$",
"model",
"->",
"resetPassword",
"(",
"$",
"model",
"->",
"newPassword",
")",
")",
"&&",
"$",
"model",
"->",
"login",
"(",
"$",
"this",
"->",
"module",
"->",
"rememberMeDuration",
")",
")",
"{",
"return",
"$",
"this",
"->",
"afterLogin",
"(",
")",
";",
"}",
"else",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'error'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Failed to change password or log in using new password.'",
")",
")",
";",
"}",
"}",
"}",
"list",
"(",
"$",
"view",
",",
"$",
"params",
")",
"=",
"$",
"this",
"->",
"getScenarioView",
"(",
"$",
"model",
"->",
"scenario",
",",
"'login'",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"view",
",",
"array_merge",
"(",
"[",
"'model'",
"=>",
"$",
"model",
"]",
",",
"$",
"params",
")",
")",
";",
"}"
] |
Performs user login, expired password reset or one time password verification.
@param string $scenario
@return string
|
[
"Performs",
"user",
"login",
"expired",
"password",
"reset",
"or",
"one",
"time",
"password",
"verification",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/controllers/DefaultController.php#L124-L150
|
232,493
|
nineinchnick/yii2-usr
|
controllers/DefaultController.php
|
DefaultController.actionRecovery
|
public function actionRecovery()
{
/** @var RecoveryForm */
$model = $this->module->createFormModel('RecoveryForm');
if (isset($_GET['activationKey'])) {
$model->scenario = 'reset';
$model->setAttributes($_GET);
}
if ($model->load($_POST)) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return \yii\widgets\ActiveForm::validate($model);
}
/**
* If the activation key is missing that means the user is requesting a recovery email.
*/
if ($model->activationKey !== null) {
$model->scenario = 'reset';
}
if ($model->validate()) {
if ($model->scenario !== 'reset') {
/**
* Send email appropriate to the activation status. If verification is required, that must happen
* before password recovery. Also allows re-sending of verification emails.
*/
if ($this->sendEmail($model, $model->identity->isActive() ? 'recovery' : 'verify')) {
Yii::$app->session->setFlash('success', Yii::t('usr', 'An email containing further instructions has been sent to email associated with specified user account.'));
} else {
Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to send an email.').' '.Yii::t('usr', 'Try again or contact the site administrator.'));
}
} else {
// a valid recovery form means the user confirmed his email address
$model->getIdentity()->verifyEmail($this->module->requireVerifiedEmail);
// regenerate the activation key to prevent reply attack
$model->getIdentity()->getActivationKey();
if ($model->resetPassword() && $model->login()) {
return $this->afterLogin();
} else {
Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to change password or log in using new password.'));
}
}
return $this->redirect(['recovery']);
}
}
return $this->render('recovery', ['model' => $model]);
}
|
php
|
public function actionRecovery()
{
/** @var RecoveryForm */
$model = $this->module->createFormModel('RecoveryForm');
if (isset($_GET['activationKey'])) {
$model->scenario = 'reset';
$model->setAttributes($_GET);
}
if ($model->load($_POST)) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return \yii\widgets\ActiveForm::validate($model);
}
/**
* If the activation key is missing that means the user is requesting a recovery email.
*/
if ($model->activationKey !== null) {
$model->scenario = 'reset';
}
if ($model->validate()) {
if ($model->scenario !== 'reset') {
/**
* Send email appropriate to the activation status. If verification is required, that must happen
* before password recovery. Also allows re-sending of verification emails.
*/
if ($this->sendEmail($model, $model->identity->isActive() ? 'recovery' : 'verify')) {
Yii::$app->session->setFlash('success', Yii::t('usr', 'An email containing further instructions has been sent to email associated with specified user account.'));
} else {
Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to send an email.').' '.Yii::t('usr', 'Try again or contact the site administrator.'));
}
} else {
// a valid recovery form means the user confirmed his email address
$model->getIdentity()->verifyEmail($this->module->requireVerifiedEmail);
// regenerate the activation key to prevent reply attack
$model->getIdentity()->getActivationKey();
if ($model->resetPassword() && $model->login()) {
return $this->afterLogin();
} else {
Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to change password or log in using new password.'));
}
}
return $this->redirect(['recovery']);
}
}
return $this->render('recovery', ['model' => $model]);
}
|
[
"public",
"function",
"actionRecovery",
"(",
")",
"{",
"/** @var RecoveryForm */",
"$",
"model",
"=",
"$",
"this",
"->",
"module",
"->",
"createFormModel",
"(",
"'RecoveryForm'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'activationKey'",
"]",
")",
")",
"{",
"$",
"model",
"->",
"scenario",
"=",
"'reset'",
";",
"$",
"model",
"->",
"setAttributes",
"(",
"$",
"_GET",
")",
";",
"}",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"$",
"_POST",
")",
")",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"isAjax",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"response",
"->",
"format",
"=",
"\\",
"yii",
"\\",
"web",
"\\",
"Response",
"::",
"FORMAT_JSON",
";",
"return",
"\\",
"yii",
"\\",
"widgets",
"\\",
"ActiveForm",
"::",
"validate",
"(",
"$",
"model",
")",
";",
"}",
"/**\n * If the activation key is missing that means the user is requesting a recovery email.\n */",
"if",
"(",
"$",
"model",
"->",
"activationKey",
"!==",
"null",
")",
"{",
"$",
"model",
"->",
"scenario",
"=",
"'reset'",
";",
"}",
"if",
"(",
"$",
"model",
"->",
"validate",
"(",
")",
")",
"{",
"if",
"(",
"$",
"model",
"->",
"scenario",
"!==",
"'reset'",
")",
"{",
"/**\n * Send email appropriate to the activation status. If verification is required, that must happen\n * before password recovery. Also allows re-sending of verification emails.\n */",
"if",
"(",
"$",
"this",
"->",
"sendEmail",
"(",
"$",
"model",
",",
"$",
"model",
"->",
"identity",
"->",
"isActive",
"(",
")",
"?",
"'recovery'",
":",
"'verify'",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'success'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'An email containing further instructions has been sent to email associated with specified user account.'",
")",
")",
";",
"}",
"else",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'error'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Failed to send an email.'",
")",
".",
"' '",
".",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Try again or contact the site administrator.'",
")",
")",
";",
"}",
"}",
"else",
"{",
"// a valid recovery form means the user confirmed his email address",
"$",
"model",
"->",
"getIdentity",
"(",
")",
"->",
"verifyEmail",
"(",
"$",
"this",
"->",
"module",
"->",
"requireVerifiedEmail",
")",
";",
"// regenerate the activation key to prevent reply attack",
"$",
"model",
"->",
"getIdentity",
"(",
")",
"->",
"getActivationKey",
"(",
")",
";",
"if",
"(",
"$",
"model",
"->",
"resetPassword",
"(",
")",
"&&",
"$",
"model",
"->",
"login",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"afterLogin",
"(",
")",
";",
"}",
"else",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'error'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Failed to change password or log in using new password.'",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'recovery'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'recovery'",
",",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
";",
"}"
] |
Processes a request for password recovery email or resetting the password.
@return string
|
[
"Processes",
"a",
"request",
"for",
"password",
"recovery",
"email",
"or",
"resetting",
"the",
"password",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/controllers/DefaultController.php#L168-L216
|
232,494
|
nineinchnick/yii2-usr
|
controllers/DefaultController.php
|
DefaultController.actionVerify
|
public function actionVerify()
{
/** @var RecoveryForm */
$model = $this->module->createFormModel('RecoveryForm', 'verify');
$model->setAttributes($_GET);
if ($model->validate() && $model->getIdentity()->verifyEmail($this->module->requireVerifiedEmail)) {
// regenerate the activation key to prevent reply attack
$model->getIdentity()->getActivationKey();
Yii::$app->session->setFlash('success', Yii::t('usr', 'Your email address has been successfully verified.'));
} else {
Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to verify your email address.'));
}
return $this->redirect([Yii::$app->user->isGuest ? 'login' : 'profile']);
}
|
php
|
public function actionVerify()
{
/** @var RecoveryForm */
$model = $this->module->createFormModel('RecoveryForm', 'verify');
$model->setAttributes($_GET);
if ($model->validate() && $model->getIdentity()->verifyEmail($this->module->requireVerifiedEmail)) {
// regenerate the activation key to prevent reply attack
$model->getIdentity()->getActivationKey();
Yii::$app->session->setFlash('success', Yii::t('usr', 'Your email address has been successfully verified.'));
} else {
Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to verify your email address.'));
}
return $this->redirect([Yii::$app->user->isGuest ? 'login' : 'profile']);
}
|
[
"public",
"function",
"actionVerify",
"(",
")",
"{",
"/** @var RecoveryForm */",
"$",
"model",
"=",
"$",
"this",
"->",
"module",
"->",
"createFormModel",
"(",
"'RecoveryForm'",
",",
"'verify'",
")",
";",
"$",
"model",
"->",
"setAttributes",
"(",
"$",
"_GET",
")",
";",
"if",
"(",
"$",
"model",
"->",
"validate",
"(",
")",
"&&",
"$",
"model",
"->",
"getIdentity",
"(",
")",
"->",
"verifyEmail",
"(",
"$",
"this",
"->",
"module",
"->",
"requireVerifiedEmail",
")",
")",
"{",
"// regenerate the activation key to prevent reply attack",
"$",
"model",
"->",
"getIdentity",
"(",
")",
"->",
"getActivationKey",
"(",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'success'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Your email address has been successfully verified.'",
")",
")",
";",
"}",
"else",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'error'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Failed to verify your email address.'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
"?",
"'login'",
":",
"'profile'",
"]",
")",
";",
"}"
] |
Processes email verification.
@return string
|
[
"Processes",
"email",
"verification",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/controllers/DefaultController.php#L222-L236
|
232,495
|
nineinchnick/yii2-usr
|
controllers/DefaultController.php
|
DefaultController.actionProfilePicture
|
public function actionProfilePicture($id)
{
/** @var ProfileForm */
$model = $this->module->createFormModel('ProfileForm');
if (!(($identity = $model->getIdentity()) instanceof PictureIdentityInterface)) {
throw new ForbiddenException(Yii::t('usr', 'The {class} class must implement the {interface} interface.', [
'class' => get_class($identity),
'interface' => 'PictureIdentityInterface',
]));
}
$picture = $identity->getPicture($id);
if ($picture === null) {
throw new NotFoundHttpException(Yii::t('usr', 'Picture with id {id} is not found.', ['id' => $id]));
}
header('Content-Type:'.$picture['mimetype']);
echo $picture['picture'];
}
|
php
|
public function actionProfilePicture($id)
{
/** @var ProfileForm */
$model = $this->module->createFormModel('ProfileForm');
if (!(($identity = $model->getIdentity()) instanceof PictureIdentityInterface)) {
throw new ForbiddenException(Yii::t('usr', 'The {class} class must implement the {interface} interface.', [
'class' => get_class($identity),
'interface' => 'PictureIdentityInterface',
]));
}
$picture = $identity->getPicture($id);
if ($picture === null) {
throw new NotFoundHttpException(Yii::t('usr', 'Picture with id {id} is not found.', ['id' => $id]));
}
header('Content-Type:'.$picture['mimetype']);
echo $picture['picture'];
}
|
[
"public",
"function",
"actionProfilePicture",
"(",
"$",
"id",
")",
"{",
"/** @var ProfileForm */",
"$",
"model",
"=",
"$",
"this",
"->",
"module",
"->",
"createFormModel",
"(",
"'ProfileForm'",
")",
";",
"if",
"(",
"!",
"(",
"(",
"$",
"identity",
"=",
"$",
"model",
"->",
"getIdentity",
"(",
")",
")",
"instanceof",
"PictureIdentityInterface",
")",
")",
"{",
"throw",
"new",
"ForbiddenException",
"(",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'The {class} class must implement the {interface} interface.'",
",",
"[",
"'class'",
"=>",
"get_class",
"(",
"$",
"identity",
")",
",",
"'interface'",
"=>",
"'PictureIdentityInterface'",
",",
"]",
")",
")",
";",
"}",
"$",
"picture",
"=",
"$",
"identity",
"->",
"getPicture",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"picture",
"===",
"null",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Picture with id {id} is not found.'",
",",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
")",
";",
"}",
"header",
"(",
"'Content-Type:'",
".",
"$",
"picture",
"[",
"'mimetype'",
"]",
")",
";",
"echo",
"$",
"picture",
"[",
"'picture'",
"]",
";",
"}"
] |
Allows users to view their profile picture.
@param integer $id
@return string
|
[
"Allows",
"users",
"to",
"view",
"their",
"profile",
"picture",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/controllers/DefaultController.php#L381-L397
|
232,496
|
nineinchnick/yii2-usr
|
models/RecoveryForm.php
|
RecoveryForm.existingIdentity
|
public function existingIdentity($attribute, $params)
{
if ($this->hasErrors()) {
return false;
}
$identity = $this->getIdentity();
if ($identity === null) {
if ($this->username !== null) {
$this->addError('username', Yii::t('usr', 'No user found matching this username.'));
} elseif ($this->email !== null) {
$this->addError('email', Yii::t('usr', 'No user found matching this email address.'));
} else {
$this->addError('username', Yii::t('usr', 'Please specify username or email.'));
}
return false;
} elseif ($identity->isDisabled()) {
$this->addError('username', Yii::t('usr', 'User account has been disabled.'));
return false;
}
return true;
}
|
php
|
public function existingIdentity($attribute, $params)
{
if ($this->hasErrors()) {
return false;
}
$identity = $this->getIdentity();
if ($identity === null) {
if ($this->username !== null) {
$this->addError('username', Yii::t('usr', 'No user found matching this username.'));
} elseif ($this->email !== null) {
$this->addError('email', Yii::t('usr', 'No user found matching this email address.'));
} else {
$this->addError('username', Yii::t('usr', 'Please specify username or email.'));
}
return false;
} elseif ($identity->isDisabled()) {
$this->addError('username', Yii::t('usr', 'User account has been disabled.'));
return false;
}
return true;
}
|
[
"public",
"function",
"existingIdentity",
"(",
"$",
"attribute",
",",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"identity",
"=",
"$",
"this",
"->",
"getIdentity",
"(",
")",
";",
"if",
"(",
"$",
"identity",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"username",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"'username'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'No user found matching this username.'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"email",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"'email'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'No user found matching this email address.'",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addError",
"(",
"'username'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Please specify username or email.'",
")",
")",
";",
"}",
"return",
"false",
";",
"}",
"elseif",
"(",
"$",
"identity",
"->",
"isDisabled",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"'username'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'User account has been disabled.'",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Inline validator that checks if an identity exists matching provided username or password.
@param string $attribute
@param array $params
@return boolean
|
[
"Inline",
"validator",
"that",
"checks",
"if",
"an",
"identity",
"exists",
"matching",
"provided",
"username",
"or",
"password",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/models/RecoveryForm.php#L90-L113
|
232,497
|
nineinchnick/yii2-usr
|
models/RecoveryForm.php
|
RecoveryForm.validActivationKey
|
public function validActivationKey($attribute, $params)
{
if ($this->hasErrors()) {
return false;
}
if (($identity = $this->getIdentity()) === null) {
return false;
}
$errorCode = $identity->verifyActivationKey($this->activationKey);
switch ($errorCode) {
default:
case $identity::ERROR_AKEY_INVALID:
$this->addError('activationKey', Yii::t('usr', 'Activation key is invalid.'));
return false;
case $identity::ERROR_AKEY_TOO_OLD:
$this->addError('activationKey', Yii::t('usr', 'Activation key is too old.'));
return false;
case $identity::ERROR_AKEY_NONE:
return true;
}
return true;
}
|
php
|
public function validActivationKey($attribute, $params)
{
if ($this->hasErrors()) {
return false;
}
if (($identity = $this->getIdentity()) === null) {
return false;
}
$errorCode = $identity->verifyActivationKey($this->activationKey);
switch ($errorCode) {
default:
case $identity::ERROR_AKEY_INVALID:
$this->addError('activationKey', Yii::t('usr', 'Activation key is invalid.'));
return false;
case $identity::ERROR_AKEY_TOO_OLD:
$this->addError('activationKey', Yii::t('usr', 'Activation key is too old.'));
return false;
case $identity::ERROR_AKEY_NONE:
return true;
}
return true;
}
|
[
"public",
"function",
"validActivationKey",
"(",
"$",
"attribute",
",",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"(",
"$",
"identity",
"=",
"$",
"this",
"->",
"getIdentity",
"(",
")",
")",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"errorCode",
"=",
"$",
"identity",
"->",
"verifyActivationKey",
"(",
"$",
"this",
"->",
"activationKey",
")",
";",
"switch",
"(",
"$",
"errorCode",
")",
"{",
"default",
":",
"case",
"$",
"identity",
"::",
"ERROR_AKEY_INVALID",
":",
"$",
"this",
"->",
"addError",
"(",
"'activationKey'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Activation key is invalid.'",
")",
")",
";",
"return",
"false",
";",
"case",
"$",
"identity",
"::",
"ERROR_AKEY_TOO_OLD",
":",
"$",
"this",
"->",
"addError",
"(",
"'activationKey'",
",",
"Yii",
"::",
"t",
"(",
"'usr'",
",",
"'Activation key is too old.'",
")",
")",
";",
"return",
"false",
";",
"case",
"$",
"identity",
"::",
"ERROR_AKEY_NONE",
":",
"return",
"true",
";",
"}",
"return",
"true",
";",
"}"
] |
Validates the activation key.
|
[
"Validates",
"the",
"activation",
"key",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/models/RecoveryForm.php#L118-L143
|
232,498
|
nineinchnick/yii2-usr
|
models/RecoveryForm.php
|
RecoveryForm.login
|
public function login()
{
$identity = $this->getIdentity();
if ($identity->authenticate($this->newPassword)) {
return $this->webUser->login($identity, 0);
}
return false;
}
|
php
|
public function login()
{
$identity = $this->getIdentity();
if ($identity->authenticate($this->newPassword)) {
return $this->webUser->login($identity, 0);
}
return false;
}
|
[
"public",
"function",
"login",
"(",
")",
"{",
"$",
"identity",
"=",
"$",
"this",
"->",
"getIdentity",
"(",
")",
";",
"if",
"(",
"$",
"identity",
"->",
"authenticate",
"(",
"$",
"this",
"->",
"newPassword",
")",
")",
"{",
"return",
"$",
"this",
"->",
"webUser",
"->",
"login",
"(",
"$",
"identity",
",",
"0",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Logs in the user using the given username and new password.
@return boolean whether login is successful
|
[
"Logs",
"in",
"the",
"user",
"using",
"the",
"given",
"username",
"and",
"new",
"password",
"."
] |
d51fbe95eeba0068cc4543efa3bca7baa30ed5e6
|
https://github.com/nineinchnick/yii2-usr/blob/d51fbe95eeba0068cc4543efa3bca7baa30ed5e6/models/RecoveryForm.php#L165-L174
|
232,499
|
jack-theripper/transcoder
|
src/Codec.php
|
Codec.setCode
|
protected function setCode($codec)
{
if (empty($codec) || ! is_string($codec))
{
throw new \InvalidArgumentException('The codec value must be a string type.');
}
$this->codec = $codec;
return $this;
}
|
php
|
protected function setCode($codec)
{
if (empty($codec) || ! is_string($codec))
{
throw new \InvalidArgumentException('The codec value must be a string type.');
}
$this->codec = $codec;
return $this;
}
|
[
"protected",
"function",
"setCode",
"(",
"$",
"codec",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"codec",
")",
"||",
"!",
"is_string",
"(",
"$",
"codec",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The codec value must be a string type.'",
")",
";",
"}",
"$",
"this",
"->",
"codec",
"=",
"$",
"codec",
";",
"return",
"$",
"this",
";",
"}"
] |
Set codec code value.
@param string $codec
@return Codec
@throws \InvalidArgumentException
|
[
"Set",
"codec",
"code",
"value",
"."
] |
bd87db4c76ccceafa9fc271b14013ebf12e0b32e
|
https://github.com/jack-theripper/transcoder/blob/bd87db4c76ccceafa9fc271b14013ebf12e0b32e/src/Codec.php#L89-L99
|
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.