repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
maniaplanet/matchmaking-lobby | MatchMakingLobby/Lobby/MatchMakers/AbstractDistance.php | AbstractDistance.computeDistances | private function computeDistances($object, $followers, $distanceComputeCallback)
{
$distances = array();
foreach($followers as $follower)
{
if($follower == $object)
continue;
$distances[$follower->id] = call_user_func($distanceComputeCallback, $object->data, $follower->data);
}
return $distances;
} | php | private function computeDistances($object, $followers, $distanceComputeCallback)
{
$distances = array();
foreach($followers as $follower)
{
if($follower == $object)
continue;
$distances[$follower->id] = call_user_func($distanceComputeCallback, $object->data, $follower->data);
}
return $distances;
} | [
"private",
"function",
"computeDistances",
"(",
"$",
"object",
",",
"$",
"followers",
",",
"$",
"distanceComputeCallback",
")",
"{",
"$",
"distances",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"followers",
"as",
"$",
"follower",
")",
"{",
"if",
"(",
"$",
"follower",
"==",
"$",
"object",
")",
"continue",
";",
"$",
"distances",
"[",
"$",
"follower",
"->",
"id",
"]",
"=",
"call_user_func",
"(",
"$",
"distanceComputeCallback",
",",
"$",
"object",
"->",
"data",
",",
"$",
"follower",
"->",
"data",
")",
";",
"}",
"return",
"$",
"distances",
";",
"}"
]
| Compute distance for a player with all his followers
@param string $player
@param string[] $followers
@return float[string] | [
"Compute",
"distance",
"for",
"a",
"player",
"with",
"all",
"his",
"followers"
]
| train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Lobby/MatchMakers/AbstractDistance.php#L207-L217 |
webforge-labs/psc-cms | lib/Psc/UI/jQuery.php | jQuery.widget | public static function widget(Tag $tag, $name, $options = array()) {
//$tag->addClass('\Psc\jquery-widget');
$js = sprintf("%s(%s)",
$name, JSHelper::convertHashMap((object) $options)
);
$tag->chain(new Code($js));
return $tag;
} | php | public static function widget(Tag $tag, $name, $options = array()) {
//$tag->addClass('\Psc\jquery-widget');
$js = sprintf("%s(%s)",
$name, JSHelper::convertHashMap((object) $options)
);
$tag->chain(new Code($js));
return $tag;
} | [
"public",
"static",
"function",
"widget",
"(",
"Tag",
"$",
"tag",
",",
"$",
"name",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"//$tag->addClass('\\Psc\\jquery-widget');",
"$",
"js",
"=",
"sprintf",
"(",
"\"%s(%s)\"",
",",
"$",
"name",
",",
"JSHelper",
"::",
"convertHashMap",
"(",
"(",
"object",
")",
"$",
"options",
")",
")",
";",
"$",
"tag",
"->",
"chain",
"(",
"new",
"Code",
"(",
"$",
"js",
")",
")",
";",
"return",
"$",
"tag",
";",
"}"
]
| Fügt dem Tag den Initialisierer für ein JQueryUI-Widget hinzu
z. B. so:
<span id="element"></span>
<script type="text/javascript">$('#element').droppable({..})</script> | [
"Fügt",
"dem",
"Tag",
"den",
"Initialisierer",
"für",
"ein",
"JQueryUI",
"-",
"Widget",
"hinzu"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/UI/jQuery.php#L20-L30 |
webforge-labs/psc-cms | lib/Psc/UI/jQuery.php | jQuery.data | public static function data(Tag $tag, $name, $data) {
$js = sprintf("data(%s, %s)",
JSHelper::convertString($name), JSHelper::convertValue($data)
);
$tag->chain(new Code($js));
return $tag;
} | php | public static function data(Tag $tag, $name, $data) {
$js = sprintf("data(%s, %s)",
JSHelper::convertString($name), JSHelper::convertValue($data)
);
$tag->chain(new Code($js));
return $tag;
} | [
"public",
"static",
"function",
"data",
"(",
"Tag",
"$",
"tag",
",",
"$",
"name",
",",
"$",
"data",
")",
"{",
"$",
"js",
"=",
"sprintf",
"(",
"\"data(%s, %s)\"",
",",
"JSHelper",
"::",
"convertString",
"(",
"$",
"name",
")",
",",
"JSHelper",
"::",
"convertValue",
"(",
"$",
"data",
")",
")",
";",
"$",
"tag",
"->",
"chain",
"(",
"new",
"Code",
"(",
"$",
"js",
")",
")",
";",
"return",
"$",
"tag",
";",
"}"
]
| Fügt dem Tag jquery Data hinzu | [
"Fügt",
"dem",
"Tag",
"jquery",
"Data",
"hinzu"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/UI/jQuery.php#L35-L43 |
ppetermann/king23 | src/Http/Middleware/BasePathStripper.php | BasePathStripper.process | public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface
{
$path = $request->getUri()->getPath();
if (!empty($this->basePath) && 0 === strpos($path, $this->basePath)) {
$cleanPath = substr($path, strlen($this->basePath));
if ($cleanPath === false) {
$cleanPath = '';
}
$request = $request->withUri($request->getUri()->withPath($cleanPath));
}
return $next->handle($request);
} | php | public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface
{
$path = $request->getUri()->getPath();
if (!empty($this->basePath) && 0 === strpos($path, $this->basePath)) {
$cleanPath = substr($path, strlen($this->basePath));
if ($cleanPath === false) {
$cleanPath = '';
}
$request = $request->withUri($request->getUri()->withPath($cleanPath));
}
return $next->handle($request);
} | [
"public",
"function",
"process",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"RequestHandlerInterface",
"$",
"next",
")",
":",
"ResponseInterface",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"basePath",
")",
"&&",
"0",
"===",
"strpos",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"basePath",
")",
")",
"{",
"$",
"cleanPath",
"=",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"this",
"->",
"basePath",
")",
")",
";",
"if",
"(",
"$",
"cleanPath",
"===",
"false",
")",
"{",
"$",
"cleanPath",
"=",
"''",
";",
"}",
"$",
"request",
"=",
"$",
"request",
"->",
"withUri",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"withPath",
"(",
"$",
"cleanPath",
")",
")",
";",
"}",
"return",
"$",
"next",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"}"
]
| strip away the basePath
@param ServerRequestInterface $request
@param RequestHandlerInterface $next
@return ResponseInterface | [
"strip",
"away",
"the",
"basePath"
]
| train | https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Middleware/BasePathStripper.php#L67-L80 |
Double-Opt-in/php-client-api | src/Guzzle/Plugin/OAuth2Plugin.php | OAuth2Plugin.setCache | public function setCache($file)
{
if ( ! empty($file)) {
$this->cache = new AccessTokenCache($file);
$this->setAccessToken($this->cache->get());
}
} | php | public function setCache($file)
{
if ( ! empty($file)) {
$this->cache = new AccessTokenCache($file);
$this->setAccessToken($this->cache->get());
}
} | [
"public",
"function",
"setCache",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"=",
"new",
"AccessTokenCache",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"setAccessToken",
"(",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
")",
")",
";",
"}",
"}"
]
| sets the cache file when possible
@param string $file | [
"sets",
"the",
"cache",
"file",
"when",
"possible"
]
| train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Guzzle/Plugin/OAuth2Plugin.php#L24-L31 |
Double-Opt-in/php-client-api | src/Guzzle/Plugin/OAuth2Plugin.php | OAuth2Plugin.acquireAccessToken | protected function acquireAccessToken()
{
$accessToken = parent::acquireAccessToken();
if ($this->cache !== null)
$this->cache->put($this->accessToken);
return $accessToken;
} | php | protected function acquireAccessToken()
{
$accessToken = parent::acquireAccessToken();
if ($this->cache !== null)
$this->cache->put($this->accessToken);
return $accessToken;
} | [
"protected",
"function",
"acquireAccessToken",
"(",
")",
"{",
"$",
"accessToken",
"=",
"parent",
"::",
"acquireAccessToken",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"cache",
"!==",
"null",
")",
"$",
"this",
"->",
"cache",
"->",
"put",
"(",
"$",
"this",
"->",
"accessToken",
")",
";",
"return",
"$",
"accessToken",
";",
"}"
]
| Acquire a new access token from the server.
@return array|null | [
"Acquire",
"a",
"new",
"access",
"token",
"from",
"the",
"server",
"."
]
| train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Guzzle/Plugin/OAuth2Plugin.php#L38-L46 |
kherge-abandoned/php-wise | src/lib/Herrera/Wise/Processor/DelegatingProcessor.php | DelegatingProcessor.supports | public function supports($resource, $type = null)
{
$this->last = $this->getResolver()->resolve($resource, $type) ?: null;
return (null !== $this->last);
} | php | public function supports($resource, $type = null)
{
$this->last = $this->getResolver()->resolve($resource, $type) ?: null;
return (null !== $this->last);
} | [
"public",
"function",
"supports",
"(",
"$",
"resource",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"last",
"=",
"$",
"this",
"->",
"getResolver",
"(",
")",
"->",
"resolve",
"(",
"$",
"resource",
",",
"$",
"type",
")",
"?",
":",
"null",
";",
"return",
"(",
"null",
"!==",
"$",
"this",
"->",
"last",
")",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/kherge-abandoned/php-wise/blob/7621e0be7dbb2a015d68197d290fe8469f539a4d/src/lib/Herrera/Wise/Processor/DelegatingProcessor.php#L50-L55 |
ondrakoupil/tools | src/Files.php | Files.extension | static function extension($in,$case=false) {
$name=self::filename($in);
if (preg_match('~\.(\w{1,10})\s*$~',$name,$parts)) {
if (!$case) return $parts[1];
if (strtoupper($case)==self::LOWERCASE) return Strings::lower($parts[1]);
if (strtoupper($case)==self::UPPERCASE) return Strings::upper($parts[1]);
return $parts[1];
}
return "";
} | php | static function extension($in,$case=false) {
$name=self::filename($in);
if (preg_match('~\.(\w{1,10})\s*$~',$name,$parts)) {
if (!$case) return $parts[1];
if (strtoupper($case)==self::LOWERCASE) return Strings::lower($parts[1]);
if (strtoupper($case)==self::UPPERCASE) return Strings::upper($parts[1]);
return $parts[1];
}
return "";
} | [
"static",
"function",
"extension",
"(",
"$",
"in",
",",
"$",
"case",
"=",
"false",
")",
"{",
"$",
"name",
"=",
"self",
"::",
"filename",
"(",
"$",
"in",
")",
";",
"if",
"(",
"preg_match",
"(",
"'~\\.(\\w{1,10})\\s*$~'",
",",
"$",
"name",
",",
"$",
"parts",
")",
")",
"{",
"if",
"(",
"!",
"$",
"case",
")",
"return",
"$",
"parts",
"[",
"1",
"]",
";",
"if",
"(",
"strtoupper",
"(",
"$",
"case",
")",
"==",
"self",
"::",
"LOWERCASE",
")",
"return",
"Strings",
"::",
"lower",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"if",
"(",
"strtoupper",
"(",
"$",
"case",
")",
"==",
"self",
"::",
"UPPERCASE",
")",
"return",
"Strings",
"::",
"upper",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"return",
"$",
"parts",
"[",
"1",
"]",
";",
"}",
"return",
"\"\"",
";",
"}"
]
| Přípona souboru
`/var/www/vhosts/somefile.txt` => `txt`
@param string $in
@param string $case self::LOWERCASE nebo self::UPPERCASE. Cokoliv jiného = neměnit velikost přípony.
@return string | [
"Přípona",
"souboru"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L36-L47 |
ondrakoupil/tools | src/Files.php | Files.filenameWithoutExtension | static function filenameWithoutExtension($filename) {
$filename=self::filename($filename);
if (preg_match('~(.*)\.(\w{1,10})$~',$filename,$parts)) {
return $parts[1];
}
return $filename;
} | php | static function filenameWithoutExtension($filename) {
$filename=self::filename($filename);
if (preg_match('~(.*)\.(\w{1,10})$~',$filename,$parts)) {
return $parts[1];
}
return $filename;
} | [
"static",
"function",
"filenameWithoutExtension",
"(",
"$",
"filename",
")",
"{",
"$",
"filename",
"=",
"self",
"::",
"filename",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"preg_match",
"(",
"'~(.*)\\.(\\w{1,10})$~'",
",",
"$",
"filename",
",",
"$",
"parts",
")",
")",
"{",
"return",
"$",
"parts",
"[",
"1",
"]",
";",
"}",
"return",
"$",
"filename",
";",
"}"
]
| Jméno souboru, ale bez přípony.
`/var/www/vhosts/somefile.txt` => `somefile`
@param string $filename
@return string | [
"Jméno",
"souboru",
"ale",
"bez",
"přípony",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L56-L62 |
ondrakoupil/tools | src/Files.php | Files.dir | static function dir($in,$real=false) {
if ($real) {
$in=realpath($in);
if ($in and is_dir($in)) $in.="/file";
}
return dirname($in);
} | php | static function dir($in,$real=false) {
if ($real) {
$in=realpath($in);
if ($in and is_dir($in)) $in.="/file";
}
return dirname($in);
} | [
"static",
"function",
"dir",
"(",
"$",
"in",
",",
"$",
"real",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"real",
")",
"{",
"$",
"in",
"=",
"realpath",
"(",
"$",
"in",
")",
";",
"if",
"(",
"$",
"in",
"and",
"is_dir",
"(",
"$",
"in",
")",
")",
"$",
"in",
".=",
"\"/file\"",
";",
"}",
"return",
"dirname",
"(",
"$",
"in",
")",
";",
"}"
]
| Jen cesta k adresáři.
`/var/www/vhosts/somefile.txt` => `/var/www/vhosts`
@param string $in
@param bool $real True = použít realpath()
@return string Pokud je $real==true a $in neexistuje, vrací empty string | [
"Jen",
"cesta",
"k",
"adresáři",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L86-L92 |
ondrakoupil/tools | src/Files.php | Files.addBeforeExtension | static function addBeforeExtension($filename,$addedString,$withPath=true) {
if ($withPath) {
$dir=self::dir($filename)."/";
} else {
$dir="";
}
if (!$dir or $dir=="./") $dir="";
$filenameWithoutExtension=self::filenameWithoutExtension($filename);
$extension=self::extension($filename);
if ($extension) $addExtension=".".$extension;
else $addExtension="";
return $dir.$filenameWithoutExtension.$addedString.$addExtension;
} | php | static function addBeforeExtension($filename,$addedString,$withPath=true) {
if ($withPath) {
$dir=self::dir($filename)."/";
} else {
$dir="";
}
if (!$dir or $dir=="./") $dir="";
$filenameWithoutExtension=self::filenameWithoutExtension($filename);
$extension=self::extension($filename);
if ($extension) $addExtension=".".$extension;
else $addExtension="";
return $dir.$filenameWithoutExtension.$addedString.$addExtension;
} | [
"static",
"function",
"addBeforeExtension",
"(",
"$",
"filename",
",",
"$",
"addedString",
",",
"$",
"withPath",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"withPath",
")",
"{",
"$",
"dir",
"=",
"self",
"::",
"dir",
"(",
"$",
"filename",
")",
".",
"\"/\"",
";",
"}",
"else",
"{",
"$",
"dir",
"=",
"\"\"",
";",
"}",
"if",
"(",
"!",
"$",
"dir",
"or",
"$",
"dir",
"==",
"\"./\"",
")",
"$",
"dir",
"=",
"\"\"",
";",
"$",
"filenameWithoutExtension",
"=",
"self",
"::",
"filenameWithoutExtension",
"(",
"$",
"filename",
")",
";",
"$",
"extension",
"=",
"self",
"::",
"extension",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"$",
"extension",
")",
"$",
"addExtension",
"=",
"\".\"",
".",
"$",
"extension",
";",
"else",
"$",
"addExtension",
"=",
"\"\"",
";",
"return",
"$",
"dir",
".",
"$",
"filenameWithoutExtension",
".",
"$",
"addedString",
".",
"$",
"addExtension",
";",
"}"
]
| Přidá do jména souboru něco na konec, před příponu.
`/var/www/vhosts/somefile.txt` => `/var/www/vhosts/somefile-affix.txt`
@param string $filename
@param string $addedString
@param bool $withPath Vracet i s cestou? Anebo jen jméno souboru?
@return string | [
"Přidá",
"do",
"jména",
"souboru",
"něco",
"na",
"konec",
"před",
"příponu",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L104-L116 |
ondrakoupil/tools | src/Files.php | Files.perms | static function perms($filename) {
if (!file_exists($filename)) {
throw new FileException("Missing: $filename");
}
if (!is_writeable($filename)) {
throw new FileException("Not writable: $filename");
}
if (is_dir($filename)) {
$ok=chmod($filename,0777);
} else {
$ok=chmod($filename,0666);
}
if (!$ok) {
throw new FileAccessException("Could not chmod $filename");
}
return $ok;
} | php | static function perms($filename) {
if (!file_exists($filename)) {
throw new FileException("Missing: $filename");
}
if (!is_writeable($filename)) {
throw new FileException("Not writable: $filename");
}
if (is_dir($filename)) {
$ok=chmod($filename,0777);
} else {
$ok=chmod($filename,0666);
}
if (!$ok) {
throw new FileAccessException("Could not chmod $filename");
}
return $ok;
} | [
"static",
"function",
"perms",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"FileException",
"(",
"\"Missing: $filename\"",
")",
";",
"}",
"if",
"(",
"!",
"is_writeable",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"FileException",
"(",
"\"Not writable: $filename\"",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"ok",
"=",
"chmod",
"(",
"$",
"filename",
",",
"0777",
")",
";",
"}",
"else",
"{",
"$",
"ok",
"=",
"chmod",
"(",
"$",
"filename",
",",
"0666",
")",
";",
"}",
"if",
"(",
"!",
"$",
"ok",
")",
"{",
"throw",
"new",
"FileAccessException",
"(",
"\"Could not chmod $filename\"",
")",
";",
"}",
"return",
"$",
"ok",
";",
"}"
]
| Nastaví práva, aby $filename bylo zapisovatelné, ať už je to soubor nebo adresář
@param string $filename
@return bool Dle úspěchu
@throws Exceptions\FileException Pokud zadaná cesta není
@throws Exceptions\FileAccessException Pokud změna selže | [
"Nastaví",
"práva",
"aby",
"$filename",
"bylo",
"zapisovatelné",
"ať",
"už",
"je",
"to",
"soubor",
"nebo",
"adresář"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L125-L145 |
ondrakoupil/tools | src/Files.php | Files.rebaseFile | static function rebaseFile($file, $from, $to, $copy=false) {
if (!file_exists($file)) {
throw new FileException("Not found: $file");
}
if (!Strings::startsWith($file, $from)) {
throw new \InvalidArgumentException("File $file is not in directory $from");
}
$newPath=$to."/".Strings::substring($file, Strings::length($from));
$newDir=self::dir($newPath);
self::createDirectories($newDir);
if ($copy) {
$ok=copy($file,$newPath);
} else {
$ok=rename($file, $newPath);
}
if (!$ok) {
throw new FileException("Failed copying to $newPath");
}
self::perms($newPath);
return $newPath;
} | php | static function rebaseFile($file, $from, $to, $copy=false) {
if (!file_exists($file)) {
throw new FileException("Not found: $file");
}
if (!Strings::startsWith($file, $from)) {
throw new \InvalidArgumentException("File $file is not in directory $from");
}
$newPath=$to."/".Strings::substring($file, Strings::length($from));
$newDir=self::dir($newPath);
self::createDirectories($newDir);
if ($copy) {
$ok=copy($file,$newPath);
} else {
$ok=rename($file, $newPath);
}
if (!$ok) {
throw new FileException("Failed copying to $newPath");
}
self::perms($newPath);
return $newPath;
} | [
"static",
"function",
"rebaseFile",
"(",
"$",
"file",
",",
"$",
"from",
",",
"$",
"to",
",",
"$",
"copy",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"FileException",
"(",
"\"Not found: $file\"",
")",
";",
"}",
"if",
"(",
"!",
"Strings",
"::",
"startsWith",
"(",
"$",
"file",
",",
"$",
"from",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"File $file is not in directory $from\"",
")",
";",
"}",
"$",
"newPath",
"=",
"$",
"to",
".",
"\"/\"",
".",
"Strings",
"::",
"substring",
"(",
"$",
"file",
",",
"Strings",
"::",
"length",
"(",
"$",
"from",
")",
")",
";",
"$",
"newDir",
"=",
"self",
"::",
"dir",
"(",
"$",
"newPath",
")",
";",
"self",
"::",
"createDirectories",
"(",
"$",
"newDir",
")",
";",
"if",
"(",
"$",
"copy",
")",
"{",
"$",
"ok",
"=",
"copy",
"(",
"$",
"file",
",",
"$",
"newPath",
")",
";",
"}",
"else",
"{",
"$",
"ok",
"=",
"rename",
"(",
"$",
"file",
",",
"$",
"newPath",
")",
";",
"}",
"if",
"(",
"!",
"$",
"ok",
")",
"{",
"throw",
"new",
"FileException",
"(",
"\"Failed copying to $newPath\"",
")",
";",
"}",
"self",
"::",
"perms",
"(",
"$",
"newPath",
")",
";",
"return",
"$",
"newPath",
";",
"}"
]
| Přesune soubor i s adresářovou strukturou zpod jednoho do jiného.
@param string $file Cílový soubor
@param string $from Adresář, který brát jako základ
@param string $to Clový adresář
@param bool $copy True (default) = kopírovat, false = přesunout
@return string Cesta k novému souboru
@throws FileException Když $file není nalezeno nebo když selže kopírování
@throws \InvalidArgumentException Když $file není umístěno v $from | [
"Přesune",
"soubor",
"i",
"s",
"adresářovou",
"strukturou",
"zpod",
"jednoho",
"do",
"jiného",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L157-L177 |
ondrakoupil/tools | src/Files.php | Files.rebasedFilename | static function rebasedFilename($file,$from,$to) {
if (!Strings::startsWith($file, $from)) {
throw new \InvalidArgumentException("File $file is not in directory $from");
}
$secondPart=Strings::substring($file, Strings::length($from));
if ($secondPart[0]=="/") $secondPart=substr($secondPart,1);
$newPath=$to."/".$secondPart;
return $newPath;
} | php | static function rebasedFilename($file,$from,$to) {
if (!Strings::startsWith($file, $from)) {
throw new \InvalidArgumentException("File $file is not in directory $from");
}
$secondPart=Strings::substring($file, Strings::length($from));
if ($secondPart[0]=="/") $secondPart=substr($secondPart,1);
$newPath=$to."/".$secondPart;
return $newPath;
} | [
"static",
"function",
"rebasedFilename",
"(",
"$",
"file",
",",
"$",
"from",
",",
"$",
"to",
")",
"{",
"if",
"(",
"!",
"Strings",
"::",
"startsWith",
"(",
"$",
"file",
",",
"$",
"from",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"File $file is not in directory $from\"",
")",
";",
"}",
"$",
"secondPart",
"=",
"Strings",
"::",
"substring",
"(",
"$",
"file",
",",
"Strings",
"::",
"length",
"(",
"$",
"from",
")",
")",
";",
"if",
"(",
"$",
"secondPart",
"[",
"0",
"]",
"==",
"\"/\"",
")",
"$",
"secondPart",
"=",
"substr",
"(",
"$",
"secondPart",
",",
"1",
")",
";",
"$",
"newPath",
"=",
"$",
"to",
".",
"\"/\"",
".",
"$",
"secondPart",
";",
"return",
"$",
"newPath",
";",
"}"
]
| Vrátí cestu k souboru, jako kdyby byl umístěn do jiného adresáře i s cestou k sobě.
@param string $file Jméno souboru
@param string $from Cesta k němu
@param string $to Adresář, kam ho chceš přesunout
@return string
@throws \InvalidArgumentException | [
"Vrátí",
"cestu",
"k",
"souboru",
"jako",
"kdyby",
"byl",
"umístěn",
"do",
"jiného",
"adresáře",
"i",
"s",
"cestou",
"k",
"sobě",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L187-L195 |
ondrakoupil/tools | src/Files.php | Files.isFileInDir | static function isFileInDir($file,$dir) {
if (!Strings::endsWith($dir, "/")) $dir.="/";
return Strings::startsWith($file, $dir);
} | php | static function isFileInDir($file,$dir) {
if (!Strings::endsWith($dir, "/")) $dir.="/";
return Strings::startsWith($file, $dir);
} | [
"static",
"function",
"isFileInDir",
"(",
"$",
"file",
",",
"$",
"dir",
")",
"{",
"if",
"(",
"!",
"Strings",
"::",
"endsWith",
"(",
"$",
"dir",
",",
"\"/\"",
")",
")",
"$",
"dir",
".=",
"\"/\"",
";",
"return",
"Strings",
"::",
"startsWith",
"(",
"$",
"file",
",",
"$",
"dir",
")",
";",
"}"
]
| Ověří, zda soubor je v zadaném adresáři.
@param string $file
@param string $dir
@return bool | [
"Ověří",
"zda",
"soubor",
"je",
"v",
"zadaném",
"adresáři",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L203-L206 |
ondrakoupil/tools | src/Files.php | Files.safeName | static function safeName($filename,$unsafeExtensions=null,$safeExtension="txt") {
if ($unsafeExtensions===null) $unsafeExtensions=array("php","phtml","inc","php3","php4","php5");
if ($filename[0] == '.') {
$filename = substr($filename, 1);
}
$filename = str_replace(DIRECTORY_SEPARATOR, '-', $filename);
$extension=self::extension($filename, "l");
if (in_array($extension, $unsafeExtensions)) {
$extension=$safeExtension;
}
$name=self::filenameWithoutExtension($filename);
$name=Strings::safe($name, false);
if (preg_match('~^(.*)[-_]+$~',$name,$partsName)) {
$name=$partsName[1];
}
if (preg_match('~^[-_]+(.*)$~',$name,$partsName)) {
$name=$partsName[1];
}
$ret=$name;
if ($extension) $ret.=".".$extension;
return $ret;
} | php | static function safeName($filename,$unsafeExtensions=null,$safeExtension="txt") {
if ($unsafeExtensions===null) $unsafeExtensions=array("php","phtml","inc","php3","php4","php5");
if ($filename[0] == '.') {
$filename = substr($filename, 1);
}
$filename = str_replace(DIRECTORY_SEPARATOR, '-', $filename);
$extension=self::extension($filename, "l");
if (in_array($extension, $unsafeExtensions)) {
$extension=$safeExtension;
}
$name=self::filenameWithoutExtension($filename);
$name=Strings::safe($name, false);
if (preg_match('~^(.*)[-_]+$~',$name,$partsName)) {
$name=$partsName[1];
}
if (preg_match('~^[-_]+(.*)$~',$name,$partsName)) {
$name=$partsName[1];
}
$ret=$name;
if ($extension) $ret.=".".$extension;
return $ret;
} | [
"static",
"function",
"safeName",
"(",
"$",
"filename",
",",
"$",
"unsafeExtensions",
"=",
"null",
",",
"$",
"safeExtension",
"=",
"\"txt\"",
")",
"{",
"if",
"(",
"$",
"unsafeExtensions",
"===",
"null",
")",
"$",
"unsafeExtensions",
"=",
"array",
"(",
"\"php\"",
",",
"\"phtml\"",
",",
"\"inc\"",
",",
"\"php3\"",
",",
"\"php4\"",
",",
"\"php5\"",
")",
";",
"if",
"(",
"$",
"filename",
"[",
"0",
"]",
"==",
"'.'",
")",
"{",
"$",
"filename",
"=",
"substr",
"(",
"$",
"filename",
",",
"1",
")",
";",
"}",
"$",
"filename",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'-'",
",",
"$",
"filename",
")",
";",
"$",
"extension",
"=",
"self",
"::",
"extension",
"(",
"$",
"filename",
",",
"\"l\"",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"extension",
",",
"$",
"unsafeExtensions",
")",
")",
"{",
"$",
"extension",
"=",
"$",
"safeExtension",
";",
"}",
"$",
"name",
"=",
"self",
"::",
"filenameWithoutExtension",
"(",
"$",
"filename",
")",
";",
"$",
"name",
"=",
"Strings",
"::",
"safe",
"(",
"$",
"name",
",",
"false",
")",
";",
"if",
"(",
"preg_match",
"(",
"'~^(.*)[-_]+$~'",
",",
"$",
"name",
",",
"$",
"partsName",
")",
")",
"{",
"$",
"name",
"=",
"$",
"partsName",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'~^[-_]+(.*)$~'",
",",
"$",
"name",
",",
"$",
"partsName",
")",
")",
"{",
"$",
"name",
"=",
"$",
"partsName",
"[",
"1",
"]",
";",
"}",
"$",
"ret",
"=",
"$",
"name",
";",
"if",
"(",
"$",
"extension",
")",
"$",
"ret",
".=",
"\".\"",
".",
"$",
"extension",
";",
"return",
"$",
"ret",
";",
"}"
]
| Vytvoří bezpečné jméno pro soubor
@param string $filename
@param array $unsafeExtensions
@param string $safeExtension
@return string | [
"Vytvoří",
"bezpečné",
"jméno",
"pro",
"soubor"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L215-L236 |
ondrakoupil/tools | src/Files.php | Files.create | static function create($filename, $createDirectoriesIfNeeded=true, $content="") {
if (!$filename) {
throw new \InvalidArgumentException("Completely missing argument!");
}
if (file_exists($filename) and is_dir($filename)) {
throw new FileException("$filename is directory!");
}
if (file_exists($filename)) {
self::perms($filename);
return $filename;
}
if ($createDirectoriesIfNeeded) self::createDirectories(self::dir($filename, false));
$ok=@touch($filename);
if (!$ok) {
throw new FileAccessException("Could not create file $filename");
}
self::perms($filename);
if ($content) {
file_put_contents($filename, $content);
}
return $filename;
} | php | static function create($filename, $createDirectoriesIfNeeded=true, $content="") {
if (!$filename) {
throw new \InvalidArgumentException("Completely missing argument!");
}
if (file_exists($filename) and is_dir($filename)) {
throw new FileException("$filename is directory!");
}
if (file_exists($filename)) {
self::perms($filename);
return $filename;
}
if ($createDirectoriesIfNeeded) self::createDirectories(self::dir($filename, false));
$ok=@touch($filename);
if (!$ok) {
throw new FileAccessException("Could not create file $filename");
}
self::perms($filename);
if ($content) {
file_put_contents($filename, $content);
}
return $filename;
} | [
"static",
"function",
"create",
"(",
"$",
"filename",
",",
"$",
"createDirectoriesIfNeeded",
"=",
"true",
",",
"$",
"content",
"=",
"\"\"",
")",
"{",
"if",
"(",
"!",
"$",
"filename",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Completely missing argument!\"",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
"and",
"is_dir",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"FileException",
"(",
"\"$filename is directory!\"",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"self",
"::",
"perms",
"(",
"$",
"filename",
")",
";",
"return",
"$",
"filename",
";",
"}",
"if",
"(",
"$",
"createDirectoriesIfNeeded",
")",
"self",
"::",
"createDirectories",
"(",
"self",
"::",
"dir",
"(",
"$",
"filename",
",",
"false",
")",
")",
";",
"$",
"ok",
"=",
"@",
"touch",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"$",
"ok",
")",
"{",
"throw",
"new",
"FileAccessException",
"(",
"\"Could not create file $filename\"",
")",
";",
"}",
"self",
"::",
"perms",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"$",
"content",
")",
"{",
"file_put_contents",
"(",
"$",
"filename",
",",
"$",
"content",
")",
";",
"}",
"return",
"$",
"filename",
";",
"}"
]
| Vytvoří soubor, pokud neexistuje, a udělá ho zapisovatelným
@param string $filename
@param bool $createDirectoriesIfNeeded
@param string $content Pokud se má vytvořit nový soubor, naplní se tímto obsahem
@return string Jméno vytvořného souboru (cesta k němu)
@throws \InvalidArgumentException
@throws FileException
@throws FileAccessException | [
"Vytvoří",
"soubor",
"pokud",
"neexistuje",
"a",
"udělá",
"ho",
"zapisovatelným"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L248-L269 |
ondrakoupil/tools | src/Files.php | Files.createDirectories | static function createDirectories($path) {
if (!$path) throw new \InvalidArgumentException("\$path can not be empty.");
/*
$parts=explode("/",$path);
$pathPart="";
foreach($parts as $i=>$p) {
if ($i) $pathPart.="/";
$pathPart.=$p;
if ($pathPart) {
if (@file_exists($pathPart) and !is_dir($pathPart)) {
throw new FileException("\"$pathPart\" is a regular file!");
}
if (!(@file_exists($pathPart))) {
self::mkdir($pathPart,false);
}
}
}
return $pathPart;
*
*/
if (file_exists($path)) {
if (is_dir($path)) {
return $path;
}
throw new FileException("\"$path\" is a regular file!");
}
$ret = @mkdir($path, 0777, true);
if (!$ret) {
throw new FileException("Directory \"$path\ could not be created.");
}
return $path;
} | php | static function createDirectories($path) {
if (!$path) throw new \InvalidArgumentException("\$path can not be empty.");
/*
$parts=explode("/",$path);
$pathPart="";
foreach($parts as $i=>$p) {
if ($i) $pathPart.="/";
$pathPart.=$p;
if ($pathPart) {
if (@file_exists($pathPart) and !is_dir($pathPart)) {
throw new FileException("\"$pathPart\" is a regular file!");
}
if (!(@file_exists($pathPart))) {
self::mkdir($pathPart,false);
}
}
}
return $pathPart;
*
*/
if (file_exists($path)) {
if (is_dir($path)) {
return $path;
}
throw new FileException("\"$path\" is a regular file!");
}
$ret = @mkdir($path, 0777, true);
if (!$ret) {
throw new FileException("Directory \"$path\ could not be created.");
}
return $path;
} | [
"static",
"function",
"createDirectories",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"path",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"\\$path can not be empty.\"",
")",
";",
"/*\n\t\t$parts=explode(\"/\",$path);\n\t\t$pathPart=\"\";\n\t\tforeach($parts as $i=>$p) {\n\t\t\tif ($i) $pathPart.=\"/\";\n\t\t\t$pathPart.=$p;\n\t\t\tif ($pathPart) {\n\t\t\t\tif (@file_exists($pathPart) and !is_dir($pathPart)) {\n\t\t\t\t\tthrow new FileException(\"\\\"$pathPart\\\" is a regular file!\");\n\t\t\t\t}\n\t\t\t\tif (!(@file_exists($pathPart))) {\n\t\t\t\t\tself::mkdir($pathPart,false);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn $pathPart;\n\t\t *\n\t\t */",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"path",
";",
"}",
"throw",
"new",
"FileException",
"(",
"\"\\\"$path\\\" is a regular file!\"",
")",
";",
"}",
"$",
"ret",
"=",
"@",
"mkdir",
"(",
"$",
"path",
",",
"0777",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"ret",
")",
"{",
"throw",
"new",
"FileException",
"(",
"\"Directory \\\"$path\\ could not be created.\"",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
]
| Pokusí se vytvořit strukturu adresářů v zadané cestě.
@param string $path
@return string Vytvořená cesta
@throws FileException Když už takto pojmenovaný soubor existuje a jde o obyčejný soubor nebo když vytváření selže. | [
"Pokusí",
"se",
"vytvořit",
"strukturu",
"adresářů",
"v",
"zadané",
"cestě",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L291-L327 |
ondrakoupil/tools | src/Files.php | Files.mkdir | static function mkdir($filename, $createDirectoriesIfNeeded=true) {
if (!$filename) {
throw new \InvalidArgumentException("Completely missing argument!");
}
if (file_exists($filename) and !is_dir($filename)) {
throw new FileException("$filename is not a directory!");
}
if (file_exists($filename)) {
self::perms($filename);
return $filename;
}
if ($createDirectoriesIfNeeded) {
self::createDirectories($filename);
} else {
$ok=@mkdir($filename);
if (!$ok) {
throw new FileAccessException("Could not create directory $filename");
}
}
self::perms($filename);
return $filename;
} | php | static function mkdir($filename, $createDirectoriesIfNeeded=true) {
if (!$filename) {
throw new \InvalidArgumentException("Completely missing argument!");
}
if (file_exists($filename) and !is_dir($filename)) {
throw new FileException("$filename is not a directory!");
}
if (file_exists($filename)) {
self::perms($filename);
return $filename;
}
if ($createDirectoriesIfNeeded) {
self::createDirectories($filename);
} else {
$ok=@mkdir($filename);
if (!$ok) {
throw new FileAccessException("Could not create directory $filename");
}
}
self::perms($filename);
return $filename;
} | [
"static",
"function",
"mkdir",
"(",
"$",
"filename",
",",
"$",
"createDirectoriesIfNeeded",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"filename",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Completely missing argument!\"",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
"and",
"!",
"is_dir",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"FileException",
"(",
"\"$filename is not a directory!\"",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"self",
"::",
"perms",
"(",
"$",
"filename",
")",
";",
"return",
"$",
"filename",
";",
"}",
"if",
"(",
"$",
"createDirectoriesIfNeeded",
")",
"{",
"self",
"::",
"createDirectories",
"(",
"$",
"filename",
")",
";",
"}",
"else",
"{",
"$",
"ok",
"=",
"@",
"mkdir",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"$",
"ok",
")",
"{",
"throw",
"new",
"FileAccessException",
"(",
"\"Could not create directory $filename\"",
")",
";",
"}",
"}",
"self",
"::",
"perms",
"(",
"$",
"filename",
")",
";",
"return",
"$",
"filename",
";",
"}"
]
| Vytvoří adresář, pokud neexistuje, a udělá ho obecně zapisovatelným
@param string $filename
@param bool $createDirectoriesIfNeeded
@return string Jméno vytvořneého adresáře
@throws \InvalidArgumentException
@throws FileException
@throws FileAccessException | [
"Vytvoří",
"adresář",
"pokud",
"neexistuje",
"a",
"udělá",
"ho",
"obecně",
"zapisovatelným"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L338-L359 |
ondrakoupil/tools | src/Files.php | Files.freeFilename | static function freeFilename($path,$filename) {
if (!file_exists($path) or !is_dir($path) or !is_writable($path)) {
throw new FileAccessException("Directory $path is missing or not writeble.");
}
if (!file_exists($path."/".$filename)) {
return $filename;
}
$maxTries=99;
$filenamePart=self::filenameWithoutExtension($filename);
$extension=self::extension($filename);
$addExtension=$extension?".$extension":"";
for ( $addedIndex=2 ; $addedIndex<$maxTries ; $addedIndex++ ) {
if (!file_exists($path."/".$filenamePart."-".$addedIndex.$addExtension)) {
break;
}
}
if ($addedIndex==$maxTries) {
return $filenamePart."-".uniqid("").$addExtension;
}
return $filenamePart."-".$addedIndex.$addExtension;
} | php | static function freeFilename($path,$filename) {
if (!file_exists($path) or !is_dir($path) or !is_writable($path)) {
throw new FileAccessException("Directory $path is missing or not writeble.");
}
if (!file_exists($path."/".$filename)) {
return $filename;
}
$maxTries=99;
$filenamePart=self::filenameWithoutExtension($filename);
$extension=self::extension($filename);
$addExtension=$extension?".$extension":"";
for ( $addedIndex=2 ; $addedIndex<$maxTries ; $addedIndex++ ) {
if (!file_exists($path."/".$filenamePart."-".$addedIndex.$addExtension)) {
break;
}
}
if ($addedIndex==$maxTries) {
return $filenamePart."-".uniqid("").$addExtension;
}
return $filenamePart."-".$addedIndex.$addExtension;
} | [
"static",
"function",
"freeFilename",
"(",
"$",
"path",
",",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
"or",
"!",
"is_dir",
"(",
"$",
"path",
")",
"or",
"!",
"is_writable",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"FileAccessException",
"(",
"\"Directory $path is missing or not writeble.\"",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
".",
"\"/\"",
".",
"$",
"filename",
")",
")",
"{",
"return",
"$",
"filename",
";",
"}",
"$",
"maxTries",
"=",
"99",
";",
"$",
"filenamePart",
"=",
"self",
"::",
"filenameWithoutExtension",
"(",
"$",
"filename",
")",
";",
"$",
"extension",
"=",
"self",
"::",
"extension",
"(",
"$",
"filename",
")",
";",
"$",
"addExtension",
"=",
"$",
"extension",
"?",
"\".$extension\"",
":",
"\"\"",
";",
"for",
"(",
"$",
"addedIndex",
"=",
"2",
";",
"$",
"addedIndex",
"<",
"$",
"maxTries",
";",
"$",
"addedIndex",
"++",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
".",
"\"/\"",
".",
"$",
"filenamePart",
".",
"\"-\"",
".",
"$",
"addedIndex",
".",
"$",
"addExtension",
")",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"addedIndex",
"==",
"$",
"maxTries",
")",
"{",
"return",
"$",
"filenamePart",
".",
"\"-\"",
".",
"uniqid",
"(",
"\"\"",
")",
".",
"$",
"addExtension",
";",
"}",
"return",
"$",
"filenamePart",
".",
"\"-\"",
".",
"$",
"addedIndex",
".",
"$",
"addExtension",
";",
"}"
]
| Najde volné pojmenování pro soubor v určitém adresáři tak, aby bylo jméno volné.
<br />Pokus je obsazené, pokouší se přidávat pomlčku a čísla až do 99, pak přejde na uniqid():
<br />freeFilename("/files/somewhere","abc.txt");
<br />Bude zkoušet: abc.txt, abc-2.txt, abc-3.txt atd.
@param string $path Adresář
@param string $filename Požadované jméno souboru
@return string Jméno souboru (ne celá cesta, jen jméno souboru)
@throws AccessException | [
"Najde",
"volné",
"pojmenování",
"pro",
"soubor",
"v",
"určitém",
"adresáři",
"tak",
"aby",
"bylo",
"jméno",
"volné",
".",
"<br",
"/",
">",
"Pokus",
"je",
"obsazené",
"pokouší",
"se",
"přidávat",
"pomlčku",
"a",
"čísla",
"až",
"do",
"99",
"pak",
"přejde",
"na",
"uniqid",
"()",
":",
"<br",
"/",
">",
"freeFilename",
"(",
"/",
"files",
"/",
"somewhere",
"abc",
".",
"txt",
")",
";",
"<br",
"/",
">",
"Bude",
"zkoušet",
":",
"abc",
".",
"txt",
"abc",
"-",
"2",
".",
"txt",
"abc",
"-",
"3",
".",
"txt",
"atd",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L372-L392 |
ondrakoupil/tools | src/Files.php | Files.purgeDir | static function purgeDir($dir) {
if (!is_dir($dir)) {
throw new \InvalidArgumentException("$dir is not directory.");
}
$content=glob($dir."/*");
if ($content) {
foreach($content as $sub) {
if ($sub=="." or $sub=="..") continue;
self::remove($sub);
}
}
return true;
} | php | static function purgeDir($dir) {
if (!is_dir($dir)) {
throw new \InvalidArgumentException("$dir is not directory.");
}
$content=glob($dir."/*");
if ($content) {
foreach($content as $sub) {
if ($sub=="." or $sub=="..") continue;
self::remove($sub);
}
}
return true;
} | [
"static",
"function",
"purgeDir",
"(",
"$",
"dir",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"$dir is not directory.\"",
")",
";",
"}",
"$",
"content",
"=",
"glob",
"(",
"$",
"dir",
".",
"\"/*\"",
")",
";",
"if",
"(",
"$",
"content",
")",
"{",
"foreach",
"(",
"$",
"content",
"as",
"$",
"sub",
")",
"{",
"if",
"(",
"$",
"sub",
"==",
"\".\"",
"or",
"$",
"sub",
"==",
"\"..\"",
")",
"continue",
";",
"self",
"::",
"remove",
"(",
"$",
"sub",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Vymaže obsah adresáře
@param string $dir
@return boolean Dle úspěchu
@throws \InvalidArgumentException | [
"Vymaže",
"obsah",
"adresáře"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L400-L412 |
ondrakoupil/tools | src/Files.php | Files.removeDir | static function removeDir($dir,$depthLock=0) {
if ($depthLock > 15) {
throw new \RuntimeException("Recursion too deep at $dir");
}
if (!file_exists($dir)) {
return true;
}
if (!is_dir($dir)) {
throw new \InvalidArgumentException("$dir is not directory.");
}
$content=glob($dir."/*");
if ($content) {
foreach($content as $sub) {
if ($sub=="." or $sub=="..") continue;
if (is_dir($sub)) {
self::removeDir($sub,$depthLock+1);
} else {
if (is_writable($sub)) {
unlink($sub);
} else {
throw new FileAccessException("Could not delete file $sub");
}
}
}
}
$ok=rmdir($dir);
if (!$ok) {
throw new FileAccessException("Could not remove dir $dir");
}
return true;
} | php | static function removeDir($dir,$depthLock=0) {
if ($depthLock > 15) {
throw new \RuntimeException("Recursion too deep at $dir");
}
if (!file_exists($dir)) {
return true;
}
if (!is_dir($dir)) {
throw new \InvalidArgumentException("$dir is not directory.");
}
$content=glob($dir."/*");
if ($content) {
foreach($content as $sub) {
if ($sub=="." or $sub=="..") continue;
if (is_dir($sub)) {
self::removeDir($sub,$depthLock+1);
} else {
if (is_writable($sub)) {
unlink($sub);
} else {
throw new FileAccessException("Could not delete file $sub");
}
}
}
}
$ok=rmdir($dir);
if (!$ok) {
throw new FileAccessException("Could not remove dir $dir");
}
return true;
} | [
"static",
"function",
"removeDir",
"(",
"$",
"dir",
",",
"$",
"depthLock",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"depthLock",
">",
"15",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Recursion too deep at $dir\"",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"$dir is not directory.\"",
")",
";",
"}",
"$",
"content",
"=",
"glob",
"(",
"$",
"dir",
".",
"\"/*\"",
")",
";",
"if",
"(",
"$",
"content",
")",
"{",
"foreach",
"(",
"$",
"content",
"as",
"$",
"sub",
")",
"{",
"if",
"(",
"$",
"sub",
"==",
"\".\"",
"or",
"$",
"sub",
"==",
"\"..\"",
")",
"continue",
";",
"if",
"(",
"is_dir",
"(",
"$",
"sub",
")",
")",
"{",
"self",
"::",
"removeDir",
"(",
"$",
"sub",
",",
"$",
"depthLock",
"+",
"1",
")",
";",
"}",
"else",
"{",
"if",
"(",
"is_writable",
"(",
"$",
"sub",
")",
")",
"{",
"unlink",
"(",
"$",
"sub",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"FileAccessException",
"(",
"\"Could not delete file $sub\"",
")",
";",
"}",
"}",
"}",
"}",
"$",
"ok",
"=",
"rmdir",
"(",
"$",
"dir",
")",
";",
"if",
"(",
"!",
"$",
"ok",
")",
"{",
"throw",
"new",
"FileAccessException",
"(",
"\"Could not remove dir $dir\"",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Smaže adresář a rekurzivně i jeho obsah
@param string $dir
@param int $depthLock Interní, ochrana proti nekonečné rekurzi
@return boolean Dle úspěchu
@throws \RuntimeException
@throws \InvalidArgumentException
@throws FileAccessException | [
"Smaže",
"adresář",
"a",
"rekurzivně",
"i",
"jeho",
"obsah"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L423-L455 |
ondrakoupil/tools | src/Files.php | Files.remove | static function remove($path, $onlyFiles=false) {
if (!file_exists($path)) {
return true;
}
if (is_dir($path)) {
if ($onlyFiles) throw new FileException("$path is a directory!");
return self::removeDir($path);
}
else {
$ok=unlink($path);
if (!$ok) throw new FileAccessException("Could not delete file $path");
}
return true;
} | php | static function remove($path, $onlyFiles=false) {
if (!file_exists($path)) {
return true;
}
if (is_dir($path)) {
if ($onlyFiles) throw new FileException("$path is a directory!");
return self::removeDir($path);
}
else {
$ok=unlink($path);
if (!$ok) throw new FileAccessException("Could not delete file $path");
}
return true;
} | [
"static",
"function",
"remove",
"(",
"$",
"path",
",",
"$",
"onlyFiles",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"$",
"onlyFiles",
")",
"throw",
"new",
"FileException",
"(",
"\"$path is a directory!\"",
")",
";",
"return",
"self",
"::",
"removeDir",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"$",
"ok",
"=",
"unlink",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"ok",
")",
"throw",
"new",
"FileAccessException",
"(",
"\"Could not delete file $path\"",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Smaže $path, ať již je to adresář nebo soubor
@param string $path
@param bool $onlyFiles Zakáže mazání adresářů
@return boolean Dle úspěchu
@throws FileAccessException
@throws FileException | [
"Smaže",
"$path",
"ať",
"již",
"je",
"to",
"adresář",
"nebo",
"soubor"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L465-L478 |
ondrakoupil/tools | src/Files.php | Files.downloadFile | public static function downloadFile($url, $path, $stream = TRUE) {
$curl = curl_init($url);
if(!$stream) {
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
file_put_contents($path, curl_exec($curl));
}
else {
$fp = fopen($path, 'w');
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_exec($curl);
fclose($fp);
}
curl_close($curl);
} | php | public static function downloadFile($url, $path, $stream = TRUE) {
$curl = curl_init($url);
if(!$stream) {
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
file_put_contents($path, curl_exec($curl));
}
else {
$fp = fopen($path, 'w');
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_exec($curl);
fclose($fp);
}
curl_close($curl);
} | [
"public",
"static",
"function",
"downloadFile",
"(",
"$",
"url",
",",
"$",
"path",
",",
"$",
"stream",
"=",
"TRUE",
")",
"{",
"$",
"curl",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"if",
"(",
"!",
"$",
"stream",
")",
"{",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_RETURNTRANSFER",
",",
"TRUE",
")",
";",
"file_put_contents",
"(",
"$",
"path",
",",
"curl_exec",
"(",
"$",
"curl",
")",
")",
";",
"}",
"else",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"path",
",",
"'w'",
")",
";",
"curl_setopt",
"(",
"$",
"curl",
",",
"CURLOPT_FILE",
",",
"$",
"fp",
")",
";",
"curl_exec",
"(",
"$",
"curl",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"}",
"curl_close",
"(",
"$",
"curl",
")",
";",
"}"
]
| Stažení vzdáleného souboru pomocí cURL
@param $url URL vzdáleného souboru
@param $path Kam stažený soubor uložit?
@param bool $stream | [
"Stažení",
"vzdáleného",
"souboru",
"pomocí",
"cURL"
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L486-L505 |
ondrakoupil/tools | src/Files.php | Files.maxUploadFileSize | static function maxUploadFileSize() {
$file_max = Strings::parsePhpNumber(ini_get("post_max_size"));
$post_max = Strings::parsePhpNumber(ini_get("upload_max_filesize"));
$php_max = min($file_max,$post_max);
return $php_max;
} | php | static function maxUploadFileSize() {
$file_max = Strings::parsePhpNumber(ini_get("post_max_size"));
$post_max = Strings::parsePhpNumber(ini_get("upload_max_filesize"));
$php_max = min($file_max,$post_max);
return $php_max;
} | [
"static",
"function",
"maxUploadFileSize",
"(",
")",
"{",
"$",
"file_max",
"=",
"Strings",
"::",
"parsePhpNumber",
"(",
"ini_get",
"(",
"\"post_max_size\"",
")",
")",
";",
"$",
"post_max",
"=",
"Strings",
"::",
"parsePhpNumber",
"(",
"ini_get",
"(",
"\"upload_max_filesize\"",
")",
")",
";",
"$",
"php_max",
"=",
"min",
"(",
"$",
"file_max",
",",
"$",
"post_max",
")",
";",
"return",
"$",
"php_max",
";",
"}"
]
| Vrací maximální nahratelnou velikost souboru.
Bere menší z hodnot post_max_size a upload_max_filesize a převede je na obyčejné číslo.
@return int Bytes | [
"Vrací",
"maximální",
"nahratelnou",
"velikost",
"souboru",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Files.php#L513-L518 |
slashworks/control-bundle | src/Slashworks/AppBundle/Form/Type/CustomerType.php | CustomerType.buildForm | public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
$builder->add('street');
$builder->add('zip');
$builder->add('city');
$builder->add('country', 'model', array(
'class' => 'Slashworks\AppBundle\Model\Country',
'property' => $this->getOption("language")
));
$builder->add('phone');
$builder->add('fax');
$builder->add('email');
$builder->add('legalform');
$builder->add('logo','file',array('data_class'=>null,'required' => false));
$builder->add('created');
$builder->add('notes');
} | php | public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
$builder->add('street');
$builder->add('zip');
$builder->add('city');
$builder->add('country', 'model', array(
'class' => 'Slashworks\AppBundle\Model\Country',
'property' => $this->getOption("language")
));
$builder->add('phone');
$builder->add('fax');
$builder->add('email');
$builder->add('legalform');
$builder->add('logo','file',array('data_class'=>null,'required' => false));
$builder->add('created');
$builder->add('notes');
} | [
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"builder",
"->",
"add",
"(",
"'name'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'street'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'zip'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'city'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'country'",
",",
"'model'",
",",
"array",
"(",
"'class'",
"=>",
"'Slashworks\\AppBundle\\Model\\Country'",
",",
"'property'",
"=>",
"$",
"this",
"->",
"getOption",
"(",
"\"language\"",
")",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'phone'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'fax'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'email'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'legalform'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'logo'",
",",
"'file'",
",",
"array",
"(",
"'data_class'",
"=>",
"null",
",",
"'required'",
"=>",
"false",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'created'",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'notes'",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Form/Type/CustomerType.php#L48-L66 |
jfusion/org.jfusion.framework | src/Api/Base.php | Base.readPayload | protected function readPayload($encrypt)
{
if (!$encrypt && isset($_GET['jfpayload'])) {
ob_start();
$payload = json_decode(trim(base64_decode($_GET['jfpayload'])));
ob_end_clean();
} else if ($encrypt && isset($_POST['jfpayload'])) {
$payload = Api::decrypt($this->key , $_POST['jfpayload']);
}
if (isset($payload) && is_array($payload)) {
$this->payload = $payload;
return true;
}
return false;
} | php | protected function readPayload($encrypt)
{
if (!$encrypt && isset($_GET['jfpayload'])) {
ob_start();
$payload = json_decode(trim(base64_decode($_GET['jfpayload'])));
ob_end_clean();
} else if ($encrypt && isset($_POST['jfpayload'])) {
$payload = Api::decrypt($this->key , $_POST['jfpayload']);
}
if (isset($payload) && is_array($payload)) {
$this->payload = $payload;
return true;
}
return false;
} | [
"protected",
"function",
"readPayload",
"(",
"$",
"encrypt",
")",
"{",
"if",
"(",
"!",
"$",
"encrypt",
"&&",
"isset",
"(",
"$",
"_GET",
"[",
"'jfpayload'",
"]",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"payload",
"=",
"json_decode",
"(",
"trim",
"(",
"base64_decode",
"(",
"$",
"_GET",
"[",
"'jfpayload'",
"]",
")",
")",
")",
";",
"ob_end_clean",
"(",
")",
";",
"}",
"else",
"if",
"(",
"$",
"encrypt",
"&&",
"isset",
"(",
"$",
"_POST",
"[",
"'jfpayload'",
"]",
")",
")",
"{",
"$",
"payload",
"=",
"Api",
"::",
"decrypt",
"(",
"$",
"this",
"->",
"key",
",",
"$",
"_POST",
"[",
"'jfpayload'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"payload",
")",
"&&",
"is_array",
"(",
"$",
"payload",
")",
")",
"{",
"$",
"this",
"->",
"payload",
"=",
"$",
"payload",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| @param $encrypt
@return bool | [
"@param",
"$encrypt"
]
| train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Api/Base.php#L28-L42 |
jfusion/org.jfusion.framework | src/Api/Base.php | Base.doExit | protected function doExit($url = null) {
if ($url && isset($_GET['jfreturn'])) {
$url .= '&jfreturn=' . $_GET['jfreturn'];
} else if (isset($_GET['jfreturn'])) {
$url = base64_decode($_GET['jfreturn']);
}
if ($url) {
Framework::redirect($url);
}
exit();
} | php | protected function doExit($url = null) {
if ($url && isset($_GET['jfreturn'])) {
$url .= '&jfreturn=' . $_GET['jfreturn'];
} else if (isset($_GET['jfreturn'])) {
$url = base64_decode($_GET['jfreturn']);
}
if ($url) {
Framework::redirect($url);
}
exit();
} | [
"protected",
"function",
"doExit",
"(",
"$",
"url",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"url",
"&&",
"isset",
"(",
"$",
"_GET",
"[",
"'jfreturn'",
"]",
")",
")",
"{",
"$",
"url",
".=",
"'&jfreturn='",
".",
"$",
"_GET",
"[",
"'jfreturn'",
"]",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'jfreturn'",
"]",
")",
")",
"{",
"$",
"url",
"=",
"base64_decode",
"(",
"$",
"_GET",
"[",
"'jfreturn'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"url",
")",
"{",
"Framework",
"::",
"redirect",
"(",
"$",
"url",
")",
";",
"}",
"exit",
"(",
")",
";",
"}"
]
| @param string|null $url Url of where to redirect to
@return void | [
"@param",
"string|null",
"$url",
"Url",
"of",
"where",
"to",
"redirect",
"to"
]
| train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Api/Base.php#L59-L70 |
arsengoian/viper-framework | src/Viper/Support/Libs/Location.php | Location.distance | public static function distance(Location $a, Location $b): float {
$f1 = deg2rad($a -> latitude);
$f2 = deg2rad($b -> latitude);
$df = deg2rad($b -> latitude - $a -> latitude);
$dl = deg2rad($b -> longitude - $a -> longitude);
$a = sin($df/2) * sin($df/2) +
cos($f1) * cos($f2) *
sin($dl/2) * sin($dl/2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return self::EARTH_RADIUS * $c;
} | php | public static function distance(Location $a, Location $b): float {
$f1 = deg2rad($a -> latitude);
$f2 = deg2rad($b -> latitude);
$df = deg2rad($b -> latitude - $a -> latitude);
$dl = deg2rad($b -> longitude - $a -> longitude);
$a = sin($df/2) * sin($df/2) +
cos($f1) * cos($f2) *
sin($dl/2) * sin($dl/2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return self::EARTH_RADIUS * $c;
} | [
"public",
"static",
"function",
"distance",
"(",
"Location",
"$",
"a",
",",
"Location",
"$",
"b",
")",
":",
"float",
"{",
"$",
"f1",
"=",
"deg2rad",
"(",
"$",
"a",
"->",
"latitude",
")",
";",
"$",
"f2",
"=",
"deg2rad",
"(",
"$",
"b",
"->",
"latitude",
")",
";",
"$",
"df",
"=",
"deg2rad",
"(",
"$",
"b",
"->",
"latitude",
"-",
"$",
"a",
"->",
"latitude",
")",
";",
"$",
"dl",
"=",
"deg2rad",
"(",
"$",
"b",
"->",
"longitude",
"-",
"$",
"a",
"->",
"longitude",
")",
";",
"$",
"a",
"=",
"sin",
"(",
"$",
"df",
"/",
"2",
")",
"*",
"sin",
"(",
"$",
"df",
"/",
"2",
")",
"+",
"cos",
"(",
"$",
"f1",
")",
"*",
"cos",
"(",
"$",
"f2",
")",
"*",
"sin",
"(",
"$",
"dl",
"/",
"2",
")",
"*",
"sin",
"(",
"$",
"dl",
"/",
"2",
")",
";",
"$",
"c",
"=",
"2",
"*",
"atan2",
"(",
"sqrt",
"(",
"$",
"a",
")",
",",
"sqrt",
"(",
"1",
"-",
"$",
"a",
")",
")",
";",
"return",
"self",
"::",
"EARTH_RADIUS",
"*",
"$",
"c",
";",
"}"
]
| Get distance in km (approximate)
@param Location $a
@param Location $b
@return float | [
"Get",
"distance",
"in",
"km",
"(",
"approximate",
")"
]
| train | https://github.com/arsengoian/viper-framework/blob/22796c5cc219cae3ca0b4af370a347ba2acab0f2/src/Viper/Support/Libs/Location.php#L56-L68 |
gries/rcon | src/Messenger.php | Messenger.send | public function send($messageText, callable $callable = null)
{
$message = new Message($messageText);
$response = $this->connection
->sendMessage($message)
->getBody()
;
if ($callable) {
$response = call_user_func($callable, $response);
}
return $response;
} | php | public function send($messageText, callable $callable = null)
{
$message = new Message($messageText);
$response = $this->connection
->sendMessage($message)
->getBody()
;
if ($callable) {
$response = call_user_func($callable, $response);
}
return $response;
} | [
"public",
"function",
"send",
"(",
"$",
"messageText",
",",
"callable",
"$",
"callable",
"=",
"null",
")",
"{",
"$",
"message",
"=",
"new",
"Message",
"(",
"$",
"messageText",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"connection",
"->",
"sendMessage",
"(",
"$",
"message",
")",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"$",
"callable",
")",
"{",
"$",
"response",
"=",
"call_user_func",
"(",
"$",
"callable",
",",
"$",
"response",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Send text to the server.
@param $messageText
@param callable $callable
@return string | [
"Send",
"text",
"to",
"the",
"server",
"."
]
| train | https://github.com/gries/rcon/blob/7fada05b329d89542692af00ab80db02ad59d45d/src/Messenger.php#L29-L43 |
AydinHassan/cli-md-renderer | src/Renderer/HorizontalRuleRenderer.php | HorizontalRuleRenderer.render | public function render(AbstractBlock $block, CliRenderer $renderer)
{
if (!($block instanceof ThematicBreak)) {
throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
}
return $renderer->style(str_repeat('-', $this->width), 'dark_gray');
} | php | public function render(AbstractBlock $block, CliRenderer $renderer)
{
if (!($block instanceof ThematicBreak)) {
throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
}
return $renderer->style(str_repeat('-', $this->width), 'dark_gray');
} | [
"public",
"function",
"render",
"(",
"AbstractBlock",
"$",
"block",
",",
"CliRenderer",
"$",
"renderer",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"block",
"instanceof",
"ThematicBreak",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Incompatible block type: \"%s\"'",
",",
"get_class",
"(",
"$",
"block",
")",
")",
")",
";",
"}",
"return",
"$",
"renderer",
"->",
"style",
"(",
"str_repeat",
"(",
"'-'",
",",
"$",
"this",
"->",
"width",
")",
",",
"'dark_gray'",
")",
";",
"}"
]
| @param AbstractBlock $block
@param CliRenderer $renderer
@return string | [
"@param",
"AbstractBlock",
"$block",
"@param",
"CliRenderer",
"$renderer"
]
| train | https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/Renderer/HorizontalRuleRenderer.php#L45-L52 |
ClanCats/Core | src/bundles/Mail/Transporter/PHPMailer.php | Transporter_PHPMailer.send | public function send( CCMail $mail )
{
// create new phpmailer instance
$driver = new PHPMailer\PHPMailer();
// set the charset
$driver->CharSet = 'utf-8';
// set the xmailer tag
$driver->XMailer = "ClanCatsFramework 2.0 Mail / PHPMailer ".$driver->Version;
// get the mail data as array
$mail_data = $mail->export_data();
// from address and name
list( $from_email, $from_name ) = $mail_data['from'];
$driver->From = $from_email;
if ( !is_null( $from_name ) )
{
$driver->FromName = $from_name;
}
// set the recipients
foreach( $mail_data['to'] as $email => $name )
{
$driver->AddAddress( $email, $name );
}
// set bcc
foreach( $mail_data['bcc'] as $email => $name )
{
$driver->addBCC( $email, $name );
}
// set cc
foreach( $mail_data['cc'] as $email => $name )
{
$driver->addCC( $email, $name );
}
// add attachments
foreach( $mail_data['attachments'] as $path => $name )
{
$driver->addAttachment( $path, $name );
}
// set the subject
$driver->Subject = $mail_data['subject'];
// set the message
$driver->Body = $mail_data['message'];
$driver->AltBody = $mail_data['plaintext'];
$driver->IsHTML( !$mail_data['is_plaintext'] );
// setup the driver
$this->setup_driver( $driver );
if( !$driver->Send() )
{
throw new Exception( "Mail failure: ". $driver->ErrorInfo );
}
} | php | public function send( CCMail $mail )
{
// create new phpmailer instance
$driver = new PHPMailer\PHPMailer();
// set the charset
$driver->CharSet = 'utf-8';
// set the xmailer tag
$driver->XMailer = "ClanCatsFramework 2.0 Mail / PHPMailer ".$driver->Version;
// get the mail data as array
$mail_data = $mail->export_data();
// from address and name
list( $from_email, $from_name ) = $mail_data['from'];
$driver->From = $from_email;
if ( !is_null( $from_name ) )
{
$driver->FromName = $from_name;
}
// set the recipients
foreach( $mail_data['to'] as $email => $name )
{
$driver->AddAddress( $email, $name );
}
// set bcc
foreach( $mail_data['bcc'] as $email => $name )
{
$driver->addBCC( $email, $name );
}
// set cc
foreach( $mail_data['cc'] as $email => $name )
{
$driver->addCC( $email, $name );
}
// add attachments
foreach( $mail_data['attachments'] as $path => $name )
{
$driver->addAttachment( $path, $name );
}
// set the subject
$driver->Subject = $mail_data['subject'];
// set the message
$driver->Body = $mail_data['message'];
$driver->AltBody = $mail_data['plaintext'];
$driver->IsHTML( !$mail_data['is_plaintext'] );
// setup the driver
$this->setup_driver( $driver );
if( !$driver->Send() )
{
throw new Exception( "Mail failure: ". $driver->ErrorInfo );
}
} | [
"public",
"function",
"send",
"(",
"CCMail",
"$",
"mail",
")",
"{",
"// create new phpmailer instance",
"$",
"driver",
"=",
"new",
"PHPMailer",
"\\",
"PHPMailer",
"(",
")",
";",
"// set the charset",
"$",
"driver",
"->",
"CharSet",
"=",
"'utf-8'",
";",
"// set the xmailer tag",
"$",
"driver",
"->",
"XMailer",
"=",
"\"ClanCatsFramework 2.0 Mail / PHPMailer \"",
".",
"$",
"driver",
"->",
"Version",
";",
"// get the mail data as array",
"$",
"mail_data",
"=",
"$",
"mail",
"->",
"export_data",
"(",
")",
";",
"// from address and name",
"list",
"(",
"$",
"from_email",
",",
"$",
"from_name",
")",
"=",
"$",
"mail_data",
"[",
"'from'",
"]",
";",
"$",
"driver",
"->",
"From",
"=",
"$",
"from_email",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"from_name",
")",
")",
"{",
"$",
"driver",
"->",
"FromName",
"=",
"$",
"from_name",
";",
"}",
"// set the recipients",
"foreach",
"(",
"$",
"mail_data",
"[",
"'to'",
"]",
"as",
"$",
"email",
"=>",
"$",
"name",
")",
"{",
"$",
"driver",
"->",
"AddAddress",
"(",
"$",
"email",
",",
"$",
"name",
")",
";",
"}",
"// set bcc",
"foreach",
"(",
"$",
"mail_data",
"[",
"'bcc'",
"]",
"as",
"$",
"email",
"=>",
"$",
"name",
")",
"{",
"$",
"driver",
"->",
"addBCC",
"(",
"$",
"email",
",",
"$",
"name",
")",
";",
"}",
"// set cc",
"foreach",
"(",
"$",
"mail_data",
"[",
"'cc'",
"]",
"as",
"$",
"email",
"=>",
"$",
"name",
")",
"{",
"$",
"driver",
"->",
"addCC",
"(",
"$",
"email",
",",
"$",
"name",
")",
";",
"}",
"// add attachments",
"foreach",
"(",
"$",
"mail_data",
"[",
"'attachments'",
"]",
"as",
"$",
"path",
"=>",
"$",
"name",
")",
"{",
"$",
"driver",
"->",
"addAttachment",
"(",
"$",
"path",
",",
"$",
"name",
")",
";",
"}",
"// set the subject",
"$",
"driver",
"->",
"Subject",
"=",
"$",
"mail_data",
"[",
"'subject'",
"]",
";",
"// set the message",
"$",
"driver",
"->",
"Body",
"=",
"$",
"mail_data",
"[",
"'message'",
"]",
";",
"$",
"driver",
"->",
"AltBody",
"=",
"$",
"mail_data",
"[",
"'plaintext'",
"]",
";",
"$",
"driver",
"->",
"IsHTML",
"(",
"!",
"$",
"mail_data",
"[",
"'is_plaintext'",
"]",
")",
";",
"// setup the driver",
"$",
"this",
"->",
"setup_driver",
"(",
"$",
"driver",
")",
";",
"if",
"(",
"!",
"$",
"driver",
"->",
"Send",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Mail failure: \"",
".",
"$",
"driver",
"->",
"ErrorInfo",
")",
";",
"}",
"}"
]
| Send the mail
@param CCMail $mail The mail object.
@return void
@throws Mail\Exception | [
"Send",
"the",
"mail"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/Transporter/PHPMailer.php#L37-L99 |
uthando-cms/uthando-dompdf | src/UthandoDomPdf/View/Renderer/PdfRenderer.php | PdfRenderer.render | public function render($nameOrModel, $values = null)
{
$pdfOptions = $nameOrModel->getPdfOptions();
$paperSize = explode(',', $pdfOptions->getPaperSize());
$paperOrientation = $pdfOptions->getPaperOrientation();
$basePath = $pdfOptions->getBasePath();
$paperSize = (count($paperSize) === 1) ? $paperSize[0] : $paperSize;
$pdf = $this->getEngine();
$pdf->setPaper($paperSize, $paperOrientation);
$pdf->setBasePath($basePath);
$html = $this->getHtmlRenderer()->render($nameOrModel, $values);
$pdf->loadHtml($html);
$pdf->render();
$pdf = $this->processHeader($pdf, $pdfOptions);
$pdf = $this->processFooter($pdf, $pdfOptions);
return $pdf->output();
} | php | public function render($nameOrModel, $values = null)
{
$pdfOptions = $nameOrModel->getPdfOptions();
$paperSize = explode(',', $pdfOptions->getPaperSize());
$paperOrientation = $pdfOptions->getPaperOrientation();
$basePath = $pdfOptions->getBasePath();
$paperSize = (count($paperSize) === 1) ? $paperSize[0] : $paperSize;
$pdf = $this->getEngine();
$pdf->setPaper($paperSize, $paperOrientation);
$pdf->setBasePath($basePath);
$html = $this->getHtmlRenderer()->render($nameOrModel, $values);
$pdf->loadHtml($html);
$pdf->render();
$pdf = $this->processHeader($pdf, $pdfOptions);
$pdf = $this->processFooter($pdf, $pdfOptions);
return $pdf->output();
} | [
"public",
"function",
"render",
"(",
"$",
"nameOrModel",
",",
"$",
"values",
"=",
"null",
")",
"{",
"$",
"pdfOptions",
"=",
"$",
"nameOrModel",
"->",
"getPdfOptions",
"(",
")",
";",
"$",
"paperSize",
"=",
"explode",
"(",
"','",
",",
"$",
"pdfOptions",
"->",
"getPaperSize",
"(",
")",
")",
";",
"$",
"paperOrientation",
"=",
"$",
"pdfOptions",
"->",
"getPaperOrientation",
"(",
")",
";",
"$",
"basePath",
"=",
"$",
"pdfOptions",
"->",
"getBasePath",
"(",
")",
";",
"$",
"paperSize",
"=",
"(",
"count",
"(",
"$",
"paperSize",
")",
"===",
"1",
")",
"?",
"$",
"paperSize",
"[",
"0",
"]",
":",
"$",
"paperSize",
";",
"$",
"pdf",
"=",
"$",
"this",
"->",
"getEngine",
"(",
")",
";",
"$",
"pdf",
"->",
"setPaper",
"(",
"$",
"paperSize",
",",
"$",
"paperOrientation",
")",
";",
"$",
"pdf",
"->",
"setBasePath",
"(",
"$",
"basePath",
")",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"getHtmlRenderer",
"(",
")",
"->",
"render",
"(",
"$",
"nameOrModel",
",",
"$",
"values",
")",
";",
"$",
"pdf",
"->",
"loadHtml",
"(",
"$",
"html",
")",
";",
"$",
"pdf",
"->",
"render",
"(",
")",
";",
"$",
"pdf",
"=",
"$",
"this",
"->",
"processHeader",
"(",
"$",
"pdf",
",",
"$",
"pdfOptions",
")",
";",
"$",
"pdf",
"=",
"$",
"this",
"->",
"processFooter",
"(",
"$",
"pdf",
",",
"$",
"pdfOptions",
")",
";",
"return",
"$",
"pdf",
"->",
"output",
"(",
")",
";",
"}"
]
| Renders values as a PDF
@param string|ModelInterface|PdfModel $nameOrModel
@param null|array|\ArrayAccess Values to use during rendering
@return string The script output. | [
"Renders",
"values",
"as",
"a",
"PDF"
]
| train | https://github.com/uthando-cms/uthando-dompdf/blob/60a750058c2db9ed167476192b20c7f544c32007/src/UthandoDomPdf/View/Renderer/PdfRenderer.php#L85-L107 |
iocaste/microservice-foundation | src/Feature/Client/HttpClient.php | HttpClient.getResponse | public function getResponse($toJson = false, $toAssociative = false)
{
return $toJson ? json_decode($this->response, $toAssociative) : $this->response;
} | php | public function getResponse($toJson = false, $toAssociative = false)
{
return $toJson ? json_decode($this->response, $toAssociative) : $this->response;
} | [
"public",
"function",
"getResponse",
"(",
"$",
"toJson",
"=",
"false",
",",
"$",
"toAssociative",
"=",
"false",
")",
"{",
"return",
"$",
"toJson",
"?",
"json_decode",
"(",
"$",
"this",
"->",
"response",
",",
"$",
"toAssociative",
")",
":",
"$",
"this",
"->",
"response",
";",
"}"
]
| @param bool $toJson
@param bool $toAssociative
@return mixed | [
"@param",
"bool",
"$toJson",
"@param",
"bool",
"$toAssociative"
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Feature/Client/HttpClient.php#L52-L55 |
iocaste/microservice-foundation | src/Feature/Client/HttpClient.php | HttpClient.json | public function json($method, $uri, array $data = [], array $headers = [], $async = false)
{
$content = json_encode($data);
$headers = array_merge([
'CONTENT_LENGTH' => mb_strlen($content, '8bit'),
'CONTENT_TYPE' => 'application/json',
'Accept' => 'application/json',
], $headers);
$this->call($method, $uri, $data, [], [], $this->transformHeadersToServerVars($headers), $content, $async);
return $this;
} | php | public function json($method, $uri, array $data = [], array $headers = [], $async = false)
{
$content = json_encode($data);
$headers = array_merge([
'CONTENT_LENGTH' => mb_strlen($content, '8bit'),
'CONTENT_TYPE' => 'application/json',
'Accept' => 'application/json',
], $headers);
$this->call($method, $uri, $data, [], [], $this->transformHeadersToServerVars($headers), $content, $async);
return $this;
} | [
"public",
"function",
"json",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"async",
"=",
"false",
")",
"{",
"$",
"content",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"$",
"headers",
"=",
"array_merge",
"(",
"[",
"'CONTENT_LENGTH'",
"=>",
"mb_strlen",
"(",
"$",
"content",
",",
"'8bit'",
")",
",",
"'CONTENT_TYPE'",
"=>",
"'application/json'",
",",
"'Accept'",
"=>",
"'application/json'",
",",
"]",
",",
"$",
"headers",
")",
";",
"$",
"this",
"->",
"call",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"data",
",",
"[",
"]",
",",
"[",
"]",
",",
"$",
"this",
"->",
"transformHeadersToServerVars",
"(",
"$",
"headers",
")",
",",
"$",
"content",
",",
"$",
"async",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Visit the given URI with a JSON request.
@param $method
@param $uri
@param array $data
@param array $headers
@param bool $async
@return $this | [
"Visit",
"the",
"given",
"URI",
"with",
"a",
"JSON",
"request",
"."
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Feature/Client/HttpClient.php#L68-L81 |
iocaste/microservice-foundation | src/Feature/Client/HttpClient.php | HttpClient.send | public function send(Request $request, $async = false): \Psr\Http\Message\StreamInterface
{
$this->currentUri = $request->fullUrl();
$options = [];
if ($request->method() === 'POST' || $request->method() === 'PUT') {
$options['json'] = $request->request->all();
}
$client = new Client();
$requestType = $async ? 'requestAsync' : 'request';
$response = $client->{$requestType}($request->method(), $this->currentUri, $options);
return $response->getBody();
} | php | public function send(Request $request, $async = false): \Psr\Http\Message\StreamInterface
{
$this->currentUri = $request->fullUrl();
$options = [];
if ($request->method() === 'POST' || $request->method() === 'PUT') {
$options['json'] = $request->request->all();
}
$client = new Client();
$requestType = $async ? 'requestAsync' : 'request';
$response = $client->{$requestType}($request->method(), $this->currentUri, $options);
return $response->getBody();
} | [
"public",
"function",
"send",
"(",
"Request",
"$",
"request",
",",
"$",
"async",
"=",
"false",
")",
":",
"\\",
"Psr",
"\\",
"Http",
"\\",
"Message",
"\\",
"StreamInterface",
"{",
"$",
"this",
"->",
"currentUri",
"=",
"$",
"request",
"->",
"fullUrl",
"(",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"request",
"->",
"method",
"(",
")",
"===",
"'POST'",
"||",
"$",
"request",
"->",
"method",
"(",
")",
"===",
"'PUT'",
")",
"{",
"$",
"options",
"[",
"'json'",
"]",
"=",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"}",
"$",
"client",
"=",
"new",
"Client",
"(",
")",
";",
"$",
"requestType",
"=",
"$",
"async",
"?",
"'requestAsync'",
":",
"'request'",
";",
"$",
"response",
"=",
"$",
"client",
"->",
"{",
"$",
"requestType",
"}",
"(",
"$",
"request",
"->",
"method",
"(",
")",
",",
"$",
"this",
"->",
"currentUri",
",",
"$",
"options",
")",
";",
"return",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}"
]
| Send the given request through the application.
This method allows you to fully customize the entire Request object.
@param Request $request
@param bool $async
@return \Psr\Http\Message\StreamInterface | [
"Send",
"the",
"given",
"request",
"through",
"the",
"application",
".",
"This",
"method",
"allows",
"you",
"to",
"fully",
"customize",
"the",
"entire",
"Request",
"object",
"."
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Feature/Client/HttpClient.php#L177-L192 |
iocaste/microservice-foundation | src/Feature/Client/HttpClient.php | HttpClient.call | public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null, $async = false)
{
$this->currentUri = $this->prepareUrlForRequest($uri);
$symfonyRequest = SymfonyRequest::create(
$this->currentUri,
$method,
$parameters,
$cookies,
$files,
$server,
$content
);
return $this->response = $this->send(
Request::createFromBase($symfonyRequest),
$async
);
} | php | public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null, $async = false)
{
$this->currentUri = $this->prepareUrlForRequest($uri);
$symfonyRequest = SymfonyRequest::create(
$this->currentUri,
$method,
$parameters,
$cookies,
$files,
$server,
$content
);
return $this->response = $this->send(
Request::createFromBase($symfonyRequest),
$async
);
} | [
"public",
"function",
"call",
"(",
"$",
"method",
",",
"$",
"uri",
",",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"cookies",
"=",
"[",
"]",
",",
"$",
"files",
"=",
"[",
"]",
",",
"$",
"server",
"=",
"[",
"]",
",",
"$",
"content",
"=",
"null",
",",
"$",
"async",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"currentUri",
"=",
"$",
"this",
"->",
"prepareUrlForRequest",
"(",
"$",
"uri",
")",
";",
"$",
"symfonyRequest",
"=",
"SymfonyRequest",
"::",
"create",
"(",
"$",
"this",
"->",
"currentUri",
",",
"$",
"method",
",",
"$",
"parameters",
",",
"$",
"cookies",
",",
"$",
"files",
",",
"$",
"server",
",",
"$",
"content",
")",
";",
"return",
"$",
"this",
"->",
"response",
"=",
"$",
"this",
"->",
"send",
"(",
"Request",
"::",
"createFromBase",
"(",
"$",
"symfonyRequest",
")",
",",
"$",
"async",
")",
";",
"}"
]
| Call the given URI and return the Response.
@param string $method
@param string $uri
@param array $parameters
@param array $cookies
@param array $files
@param array $server
@param string $content
@param bool $async
@return mixed | [
"Call",
"the",
"given",
"URI",
"and",
"return",
"the",
"Response",
"."
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Feature/Client/HttpClient.php#L208-L226 |
iocaste/microservice-foundation | src/Feature/Client/HttpClient.php | HttpClient.transformHeadersToServerVars | protected function transformHeadersToServerVars(array $headers): array
{
$server = [];
$prefix = 'HTTP_';
foreach ($headers as $name => $value) {
$name = str_replace(strtoupper($name), '-', '_');
if ($name !== 'CONTENT_TYPE' && ! starts_with($name, $prefix)) {
$name = $prefix.$name;
}
$server[$name] = $value;
}
return $server;
} | php | protected function transformHeadersToServerVars(array $headers): array
{
$server = [];
$prefix = 'HTTP_';
foreach ($headers as $name => $value) {
$name = str_replace(strtoupper($name), '-', '_');
if ($name !== 'CONTENT_TYPE' && ! starts_with($name, $prefix)) {
$name = $prefix.$name;
}
$server[$name] = $value;
}
return $server;
} | [
"protected",
"function",
"transformHeadersToServerVars",
"(",
"array",
"$",
"headers",
")",
":",
"array",
"{",
"$",
"server",
"=",
"[",
"]",
";",
"$",
"prefix",
"=",
"'HTTP_'",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"strtoupper",
"(",
"$",
"name",
")",
",",
"'-'",
",",
"'_'",
")",
";",
"if",
"(",
"$",
"name",
"!==",
"'CONTENT_TYPE'",
"&&",
"!",
"starts_with",
"(",
"$",
"name",
",",
"$",
"prefix",
")",
")",
"{",
"$",
"name",
"=",
"$",
"prefix",
".",
"$",
"name",
";",
"}",
"$",
"server",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"server",
";",
"}"
]
| Transform headers array to array of $_SERVER vars with HTTP_* format.
@param array $headers
@return array | [
"Transform",
"headers",
"array",
"to",
"array",
"of",
"$_SERVER",
"vars",
"with",
"HTTP_",
"*",
"format",
"."
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Feature/Client/HttpClient.php#L253-L269 |
PeekAndPoke/psi | src/Operation/Terminal/AverageOperation.php | AverageOperation.apply | public function apply(\Iterator $set)
{
$data = iterator_to_array($set);
if (count($data) === 0) {
return 0;
}
return array_sum($data) / count($data);
} | php | public function apply(\Iterator $set)
{
$data = iterator_to_array($set);
if (count($data) === 0) {
return 0;
}
return array_sum($data) / count($data);
} | [
"public",
"function",
"apply",
"(",
"\\",
"Iterator",
"$",
"set",
")",
"{",
"$",
"data",
"=",
"iterator_to_array",
"(",
"$",
"set",
")",
";",
"if",
"(",
"count",
"(",
"$",
"data",
")",
"===",
"0",
")",
"{",
"return",
"0",
";",
"}",
"return",
"array_sum",
"(",
"$",
"data",
")",
"/",
"count",
"(",
"$",
"data",
")",
";",
"}"
]
| {@inheritdoc}
@return float | [
"{",
"@inheritdoc",
"}"
]
| train | https://github.com/PeekAndPoke/psi/blob/cfd45d995d3a2c2ea6ba5b1ce7b5fcc71179456f/src/Operation/Terminal/AverageOperation.php#L24-L33 |
adammbalogh/key-value-store-memory | src/Adapter/MemoryAdapter/KeyTrait.php | KeyTrait.delete | public function delete($key)
{
try {
$this->get($key);
} catch (KeyNotFoundException $e) {
return false;
}
unset($this->store[$key]);
return true;
} | php | public function delete($key)
{
try {
$this->get($key);
} catch (KeyNotFoundException $e) {
return false;
}
unset($this->store[$key]);
return true;
} | [
"public",
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"catch",
"(",
"KeyNotFoundException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"store",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}"
]
| Removes a key.
@param string $key
@return bool True if the deletion was successful, false if the deletion was unsuccessful. | [
"Removes",
"a",
"key",
"."
]
| train | https://github.com/adammbalogh/key-value-store-memory/blob/6bafb9037d61911f76343a7aa7270866b1a11995/src/Adapter/MemoryAdapter/KeyTrait.php#L18-L29 |
adammbalogh/key-value-store-memory | src/Adapter/MemoryAdapter/KeyTrait.php | KeyTrait.getTtl | public function getTtl($key)
{
if (!array_key_exists($key, $this->store)) {
throw new KeyNotFoundException();
}
$getResult = $this->store[$key];
$unserialized = @unserialize($getResult);
if (!Util::hasInternalExpireTime($unserialized)) {
throw new \Exception('Cannot retrieve ttl');
}
return $this->handleTtl($key, $unserialized['ts'], $unserialized['s']);
} | php | public function getTtl($key)
{
if (!array_key_exists($key, $this->store)) {
throw new KeyNotFoundException();
}
$getResult = $this->store[$key];
$unserialized = @unserialize($getResult);
if (!Util::hasInternalExpireTime($unserialized)) {
throw new \Exception('Cannot retrieve ttl');
}
return $this->handleTtl($key, $unserialized['ts'], $unserialized['s']);
} | [
"public",
"function",
"getTtl",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"store",
")",
")",
"{",
"throw",
"new",
"KeyNotFoundException",
"(",
")",
";",
"}",
"$",
"getResult",
"=",
"$",
"this",
"->",
"store",
"[",
"$",
"key",
"]",
";",
"$",
"unserialized",
"=",
"@",
"unserialize",
"(",
"$",
"getResult",
")",
";",
"if",
"(",
"!",
"Util",
"::",
"hasInternalExpireTime",
"(",
"$",
"unserialized",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Cannot retrieve ttl'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleTtl",
"(",
"$",
"key",
",",
"$",
"unserialized",
"[",
"'ts'",
"]",
",",
"$",
"unserialized",
"[",
"'s'",
"]",
")",
";",
"}"
]
| Returns the remaining time to live of a key that has a timeout.
@param string $key
@return int Ttl in seconds.
@throws KeyNotFoundException
@throws \Exception | [
"Returns",
"the",
"remaining",
"time",
"to",
"live",
"of",
"a",
"key",
"that",
"has",
"a",
"timeout",
"."
]
| train | https://github.com/adammbalogh/key-value-store-memory/blob/6bafb9037d61911f76343a7aa7270866b1a11995/src/Adapter/MemoryAdapter/KeyTrait.php#L60-L74 |
adammbalogh/key-value-store-memory | src/Adapter/MemoryAdapter/KeyTrait.php | KeyTrait.persist | public function persist($key)
{
if (!array_key_exists($key, $this->store)) {
return false;
}
$getResult = $this->store[$key];
$unserialized = @unserialize($getResult);
if (!Util::hasInternalExpireTime($unserialized)) {
return false;
}
try {
$this->handleTtl($key, $unserialized['ts'], $unserialized['s']);
} catch (KeyNotFoundException $e) {
return false;
}
return $this->set($key, $unserialized['v']);
} | php | public function persist($key)
{
if (!array_key_exists($key, $this->store)) {
return false;
}
$getResult = $this->store[$key];
$unserialized = @unserialize($getResult);
if (!Util::hasInternalExpireTime($unserialized)) {
return false;
}
try {
$this->handleTtl($key, $unserialized['ts'], $unserialized['s']);
} catch (KeyNotFoundException $e) {
return false;
}
return $this->set($key, $unserialized['v']);
} | [
"public",
"function",
"persist",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"store",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"getResult",
"=",
"$",
"this",
"->",
"store",
"[",
"$",
"key",
"]",
";",
"$",
"unserialized",
"=",
"@",
"unserialize",
"(",
"$",
"getResult",
")",
";",
"if",
"(",
"!",
"Util",
"::",
"hasInternalExpireTime",
"(",
"$",
"unserialized",
")",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"handleTtl",
"(",
"$",
"key",
",",
"$",
"unserialized",
"[",
"'ts'",
"]",
",",
"$",
"unserialized",
"[",
"'s'",
"]",
")",
";",
"}",
"catch",
"(",
"KeyNotFoundException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"unserialized",
"[",
"'v'",
"]",
")",
";",
"}"
]
| Removes the existing timeout on key, turning the key from volatile (a key with an expire set)
to persistent (a key that will never expire as no timeout is associated).
@param string $key
@return bool True if the persist was success, false if the persis was unsuccessful.
@throws \Exception | [
"Removes",
"the",
"existing",
"timeout",
"on",
"key",
"turning",
"the",
"key",
"from",
"volatile",
"(",
"a",
"key",
"with",
"an",
"expire",
"set",
")",
"to",
"persistent",
"(",
"a",
"key",
"that",
"will",
"never",
"expire",
"as",
"no",
"timeout",
"is",
"associated",
")",
"."
]
| train | https://github.com/adammbalogh/key-value-store-memory/blob/6bafb9037d61911f76343a7aa7270866b1a11995/src/Adapter/MemoryAdapter/KeyTrait.php#L104-L124 |
Nozemi/SlickBoard-Library | lib/SBLib/Users/User.php | User.setPassword | public function setPassword($p1, $p2 = null, $login = false) {
$this->password = $this->integration->setPassword($p1, $p2, $login, $this);
return $this;
} | php | public function setPassword($p1, $p2 = null, $login = false) {
$this->password = $this->integration->setPassword($p1, $p2, $login, $this);
return $this;
} | [
"public",
"function",
"setPassword",
"(",
"$",
"p1",
",",
"$",
"p2",
"=",
"null",
",",
"$",
"login",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"password",
"=",
"$",
"this",
"->",
"integration",
"->",
"setPassword",
"(",
"$",
"p1",
",",
"$",
"p2",
",",
"$",
"login",
",",
"$",
"this",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the password if the passwords match. | [
"Set",
"the",
"password",
"if",
"the",
"passwords",
"match",
"."
]
| train | https://github.com/Nozemi/SlickBoard-Library/blob/c9f0a26a30f8127c997f75d7232eac170972418d/lib/SBLib/Users/User.php#L110-L113 |
comodojo/cookies | src/Comodojo/Cookies/CookieTools.php | CookieTools.setCookieProperties | public static function setCookieProperties(CookieInterface $cookie, array $properties, $serialize) {
try {
foreach ( $properties as $property => $value ) {
switch ( $property ) {
case 'value':
$cookie->setValue($value, $serialize);
break;
case 'expire':
$cookie->setExpire($value);
break;
case 'path':
$cookie->setPath($value);
break;
case 'domain':
$cookie->setDomain($value);
break;
case 'secure':
$cookie->setSecure($value);
break;
case 'httponly':
$cookie->setHttponly($value);
break;
}
}
} catch (Exception $e) {
throw $e;
}
return $cookie;
} | php | public static function setCookieProperties(CookieInterface $cookie, array $properties, $serialize) {
try {
foreach ( $properties as $property => $value ) {
switch ( $property ) {
case 'value':
$cookie->setValue($value, $serialize);
break;
case 'expire':
$cookie->setExpire($value);
break;
case 'path':
$cookie->setPath($value);
break;
case 'domain':
$cookie->setDomain($value);
break;
case 'secure':
$cookie->setSecure($value);
break;
case 'httponly':
$cookie->setHttponly($value);
break;
}
}
} catch (Exception $e) {
throw $e;
}
return $cookie;
} | [
"public",
"static",
"function",
"setCookieProperties",
"(",
"CookieInterface",
"$",
"cookie",
",",
"array",
"$",
"properties",
",",
"$",
"serialize",
")",
"{",
"try",
"{",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"property",
")",
"{",
"case",
"'value'",
":",
"$",
"cookie",
"->",
"setValue",
"(",
"$",
"value",
",",
"$",
"serialize",
")",
";",
"break",
";",
"case",
"'expire'",
":",
"$",
"cookie",
"->",
"setExpire",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'path'",
":",
"$",
"cookie",
"->",
"setPath",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'domain'",
":",
"$",
"cookie",
"->",
"setDomain",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'secure'",
":",
"$",
"cookie",
"->",
"setSecure",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'httponly'",
":",
"$",
"cookie",
"->",
"setHttponly",
"(",
"$",
"value",
")",
";",
"break",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"cookie",
";",
"}"
]
| Set content of $cookie from array $properties
@param CookieInterface $cookie
@param array $properties
Array of properties cookie should have in the format
[
'value' => '',
'expire' => '',
'path' => '',
'domain' => '',
'secure' => '',
'httponly' => ''
]
@param boolean $serialize
@return CookieInterface
@throws Exception | [
"Set",
"content",
"of",
"$cookie",
"from",
"array",
"$properties"
]
| train | https://github.com/comodojo/cookies/blob/a81c7dff37d52c1a75462c0ad30db75d0c3b0081/src/Comodojo/Cookies/CookieTools.php#L46-L100 |
comodojo/cookies | src/Comodojo/Cookies/CookieTools.php | CookieTools.checkDomain | public static function checkDomain($domain_name) {
if ( $domain_name[0] == '.' ) $domain_name = substr($domain_name, 1);
return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check
&& preg_match("/^.{1,253}$/", $domain_name) //overall length check
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)); //length of each label
} | php | public static function checkDomain($domain_name) {
if ( $domain_name[0] == '.' ) $domain_name = substr($domain_name, 1);
return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check
&& preg_match("/^.{1,253}$/", $domain_name) //overall length check
&& preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)); //length of each label
} | [
"public",
"static",
"function",
"checkDomain",
"(",
"$",
"domain_name",
")",
"{",
"if",
"(",
"$",
"domain_name",
"[",
"0",
"]",
"==",
"'.'",
")",
"$",
"domain_name",
"=",
"substr",
"(",
"$",
"domain_name",
",",
"1",
")",
";",
"return",
"(",
"preg_match",
"(",
"\"/^([a-z\\d](-*[a-z\\d])*)(\\.([a-z\\d](-*[a-z\\d])*))*$/i\"",
",",
"$",
"domain_name",
")",
"//valid chars check\r",
"&&",
"preg_match",
"(",
"\"/^.{1,253}$/\"",
",",
"$",
"domain_name",
")",
"//overall length check\r",
"&&",
"preg_match",
"(",
"\"/^[^\\.]{1,63}(\\.[^\\.]{1,63})*$/\"",
",",
"$",
"domain_name",
")",
")",
";",
"//length of each label\r",
"}"
]
| Check if domain is valid
Main code from: http://stackoverflow.com/questions/1755144/how-to-validate-domain-name-in-php
@param string $domain_name
The domain name to check
@return bool | [
"Check",
"if",
"domain",
"is",
"valid"
]
| train | https://github.com/comodojo/cookies/blob/a81c7dff37d52c1a75462c0ad30db75d0c3b0081/src/Comodojo/Cookies/CookieTools.php#L112-L120 |
geekwright/Po | src/PoHeader.php | PoHeader.buildStructuredHeaders | protected function buildStructuredHeaders(): void
{
$this->structuredHeaders = array();
$headers = $this->entry[PoTokens::TRANSLATED];
$headers = ($headers === null) ? array() : $headers;
$full = implode('', $headers);
$headers = explode("\n", $full);
// split on ':'
$pattern = '/([a-z0-9\-]+):\s*(.*)/i';
foreach ($headers as $h) {
if (preg_match($pattern, trim($h), $matches)) {
$this->structuredHeaders[strtolower($matches[1])] = array(
'key' => $matches[1],
'value' => $matches[2],
);
}
}
} | php | protected function buildStructuredHeaders(): void
{
$this->structuredHeaders = array();
$headers = $this->entry[PoTokens::TRANSLATED];
$headers = ($headers === null) ? array() : $headers;
$full = implode('', $headers);
$headers = explode("\n", $full);
// split on ':'
$pattern = '/([a-z0-9\-]+):\s*(.*)/i';
foreach ($headers as $h) {
if (preg_match($pattern, trim($h), $matches)) {
$this->structuredHeaders[strtolower($matches[1])] = array(
'key' => $matches[1],
'value' => $matches[2],
);
}
}
} | [
"protected",
"function",
"buildStructuredHeaders",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"structuredHeaders",
"=",
"array",
"(",
")",
";",
"$",
"headers",
"=",
"$",
"this",
"->",
"entry",
"[",
"PoTokens",
"::",
"TRANSLATED",
"]",
";",
"$",
"headers",
"=",
"(",
"$",
"headers",
"===",
"null",
")",
"?",
"array",
"(",
")",
":",
"$",
"headers",
";",
"$",
"full",
"=",
"implode",
"(",
"''",
",",
"$",
"headers",
")",
";",
"$",
"headers",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"full",
")",
";",
"// split on ':'",
"$",
"pattern",
"=",
"'/([a-z0-9\\-]+):\\s*(.*)/i'",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"h",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"trim",
"(",
"$",
"h",
")",
",",
"$",
"matches",
")",
")",
"{",
"$",
"this",
"->",
"structuredHeaders",
"[",
"strtolower",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"]",
"=",
"array",
"(",
"'key'",
"=>",
"$",
"matches",
"[",
"1",
"]",
",",
"'value'",
"=>",
"$",
"matches",
"[",
"2",
"]",
",",
")",
";",
"}",
"}",
"}"
]
| Populate the internal structuredHeaders property with contents
of this entry's "msgstr" value.
@return void | [
"Populate",
"the",
"internal",
"structuredHeaders",
"property",
"with",
"contents",
"of",
"this",
"entry",
"s",
"msgstr",
"value",
"."
]
| train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoHeader.php#L38-L55 |
geekwright/Po | src/PoHeader.php | PoHeader.storeStructuredHeader | protected function storeStructuredHeader(): bool
{
if (is_null($this->structuredHeaders)) {
return false;
}
$headers = array("");
foreach ($this->structuredHeaders as $h) {
$headers[] = $h['key'] . ': ' . $h['value'] . "\n";
}
$this->entry[PoTokens::TRANSLATED] = $headers;
return true;
} | php | protected function storeStructuredHeader(): bool
{
if (is_null($this->structuredHeaders)) {
return false;
}
$headers = array("");
foreach ($this->structuredHeaders as $h) {
$headers[] = $h['key'] . ': ' . $h['value'] . "\n";
}
$this->entry[PoTokens::TRANSLATED] = $headers;
return true;
} | [
"protected",
"function",
"storeStructuredHeader",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"structuredHeaders",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"headers",
"=",
"array",
"(",
"\"\"",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"structuredHeaders",
"as",
"$",
"h",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"$",
"h",
"[",
"'key'",
"]",
".",
"': '",
".",
"$",
"h",
"[",
"'value'",
"]",
".",
"\"\\n\"",
";",
"}",
"$",
"this",
"->",
"entry",
"[",
"PoTokens",
"::",
"TRANSLATED",
"]",
"=",
"$",
"headers",
";",
"return",
"true",
";",
"}"
]
| Rebuild the this entry's "msgstr" value using contents of the internal
structuredHeaders property.
@return boolean true if rebuilt, false if not | [
"Rebuild",
"the",
"this",
"entry",
"s",
"msgstr",
"value",
"using",
"contents",
"of",
"the",
"internal",
"structuredHeaders",
"property",
"."
]
| train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoHeader.php#L63-L75 |
geekwright/Po | src/PoHeader.php | PoHeader.getHeader | public function getHeader(string $key): ?string
{
$this->buildStructuredHeaders();
$lkey = strtolower($key);
$header = null;
if (isset($this->structuredHeaders[$lkey]['value'])) {
$header = $this->structuredHeaders[$lkey]['value'];
}
return $header;
} | php | public function getHeader(string $key): ?string
{
$this->buildStructuredHeaders();
$lkey = strtolower($key);
$header = null;
if (isset($this->structuredHeaders[$lkey]['value'])) {
$header = $this->structuredHeaders[$lkey]['value'];
}
return $header;
} | [
"public",
"function",
"getHeader",
"(",
"string",
"$",
"key",
")",
":",
"?",
"string",
"{",
"$",
"this",
"->",
"buildStructuredHeaders",
"(",
")",
";",
"$",
"lkey",
"=",
"strtolower",
"(",
"$",
"key",
")",
";",
"$",
"header",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"structuredHeaders",
"[",
"$",
"lkey",
"]",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"header",
"=",
"$",
"this",
"->",
"structuredHeaders",
"[",
"$",
"lkey",
"]",
"[",
"'value'",
"]",
";",
"}",
"return",
"$",
"header",
";",
"}"
]
| Get a header value string by key
@param string $key case insensitive name of header to return
@return string|null header string for key or false if not set | [
"Get",
"a",
"header",
"value",
"string",
"by",
"key"
]
| train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoHeader.php#L84-L93 |
geekwright/Po | src/PoHeader.php | PoHeader.setHeader | public function setHeader(string $key, string $value): void
{
$this->buildStructuredHeaders();
$lkey = strtolower($key);
if (isset($this->structuredHeaders[$lkey])) {
$this->structuredHeaders[$lkey]['value'] = $value;
} else {
$newHeader = array('key' => $key, 'value' => $value);
$this->structuredHeaders[$lkey] = $newHeader;
}
$this->storeStructuredHeader();
} | php | public function setHeader(string $key, string $value): void
{
$this->buildStructuredHeaders();
$lkey = strtolower($key);
if (isset($this->structuredHeaders[$lkey])) {
$this->structuredHeaders[$lkey]['value'] = $value;
} else {
$newHeader = array('key' => $key, 'value' => $value);
$this->structuredHeaders[$lkey] = $newHeader;
}
$this->storeStructuredHeader();
} | [
"public",
"function",
"setHeader",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"value",
")",
":",
"void",
"{",
"$",
"this",
"->",
"buildStructuredHeaders",
"(",
")",
";",
"$",
"lkey",
"=",
"strtolower",
"(",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"structuredHeaders",
"[",
"$",
"lkey",
"]",
")",
")",
"{",
"$",
"this",
"->",
"structuredHeaders",
"[",
"$",
"lkey",
"]",
"[",
"'value'",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"newHeader",
"=",
"array",
"(",
"'key'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"value",
")",
";",
"$",
"this",
"->",
"structuredHeaders",
"[",
"$",
"lkey",
"]",
"=",
"$",
"newHeader",
";",
"}",
"$",
"this",
"->",
"storeStructuredHeader",
"(",
")",
";",
"}"
]
| Set the value of a header string for a key.
@param string $key name of header to set. If the header exists, the name is
case insensitive. If it is new the given case will be used
@param string $value value to set
@return void | [
"Set",
"the",
"value",
"of",
"a",
"header",
"string",
"for",
"a",
"key",
"."
]
| train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoHeader.php#L104-L115 |
geekwright/Po | src/PoHeader.php | PoHeader.setCreateDate | public function setCreateDate(?int $time = null): void
{
$this->setHeader('POT-Creation-Date', $this->formatTimestamp($time));
} | php | public function setCreateDate(?int $time = null): void
{
$this->setHeader('POT-Creation-Date', $this->formatTimestamp($time));
} | [
"public",
"function",
"setCreateDate",
"(",
"?",
"int",
"$",
"time",
"=",
"null",
")",
":",
"void",
"{",
"$",
"this",
"->",
"setHeader",
"(",
"'POT-Creation-Date'",
",",
"$",
"this",
"->",
"formatTimestamp",
"(",
"$",
"time",
")",
")",
";",
"}"
]
| Set the POT-Creation-Date header
@param integer|null $time unix timestamp, null to use current
@return void | [
"Set",
"the",
"POT",
"-",
"Creation",
"-",
"Date",
"header"
]
| train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoHeader.php#L124-L127 |
geekwright/Po | src/PoHeader.php | PoHeader.setRevisionDate | public function setRevisionDate(?int $time = null): void
{
$this->setHeader('PO-Revision-Date', $this->formatTimestamp($time));
} | php | public function setRevisionDate(?int $time = null): void
{
$this->setHeader('PO-Revision-Date', $this->formatTimestamp($time));
} | [
"public",
"function",
"setRevisionDate",
"(",
"?",
"int",
"$",
"time",
"=",
"null",
")",
":",
"void",
"{",
"$",
"this",
"->",
"setHeader",
"(",
"'PO-Revision-Date'",
",",
"$",
"this",
"->",
"formatTimestamp",
"(",
"$",
"time",
")",
")",
";",
"}"
]
| Set the PO-Revision-Date header
@param integer|null $time unix timestamp, null to use current
@return void | [
"Set",
"the",
"PO",
"-",
"Revision",
"-",
"Date",
"header"
]
| train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoHeader.php#L136-L139 |
geekwright/Po | src/PoHeader.php | PoHeader.formatTimestamp | protected function formatTimestamp(?int $time = null): string
{
if (empty($time)) {
$time = time();
}
return gmdate('Y-m-d H:iO', $time);
} | php | protected function formatTimestamp(?int $time = null): string
{
if (empty($time)) {
$time = time();
}
return gmdate('Y-m-d H:iO', $time);
} | [
"protected",
"function",
"formatTimestamp",
"(",
"?",
"int",
"$",
"time",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"time",
")",
")",
"{",
"$",
"time",
"=",
"time",
"(",
")",
";",
"}",
"return",
"gmdate",
"(",
"'Y-m-d H:iO'",
",",
"$",
"time",
")",
";",
"}"
]
| Format a timestamp following PO file conventions
@param integer|null $time unix timestamp, null to use current
@return string formatted timestamp | [
"Format",
"a",
"timestamp",
"following",
"PO",
"file",
"conventions"
]
| train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoHeader.php#L148-L154 |
geekwright/Po | src/PoHeader.php | PoHeader.buildDefaultHeader | public function buildDefaultHeader(): void
{
$this->set(PoTokens::MESSAGE, "");
$this->set(PoTokens::TRANSLATOR_COMMENTS, 'SOME DESCRIPTIVE TITLE');
$this->add(PoTokens::TRANSLATOR_COMMENTS, 'Copyright (C) YEAR HOLDER');
$this->add(PoTokens::TRANSLATOR_COMMENTS, 'LICENSE');
$this->add(PoTokens::TRANSLATOR_COMMENTS, 'FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.');
$this->add(PoTokens::TRANSLATOR_COMMENTS, '');
$this->set(PoTokens::FLAG, 'fuzzy');
$this->setHeader('Project-Id-Version', 'PACKAGE VERSION');
$this->setHeader('Report-Msgid-Bugs-To', 'FULL NAME <EMAIL@ADDRESS>');
$this->setCreateDate();
$this->setHeader('PO-Revision-Date', 'YEAR-MO-DA HO:MI+ZONE');
$this->setHeader('Last-Translator', 'FULL NAME <EMAIL@ADDRESS>');
$this->setHeader('Language-Team', 'LANGUAGE <EMAIL@ADDRESS>');
$this->setHeader('MIME-Version', '1.0');
$this->setHeader('Content-Type', 'text/plain; charset=UTF-8');
$this->setHeader('Content-Transfer-Encoding', '8bit');
$this->setHeader('Plural-Forms', 'nplurals=INTEGER; plural=EXPRESSION;');
$this->setHeader('X-Generator', 'geekwright/po');
} | php | public function buildDefaultHeader(): void
{
$this->set(PoTokens::MESSAGE, "");
$this->set(PoTokens::TRANSLATOR_COMMENTS, 'SOME DESCRIPTIVE TITLE');
$this->add(PoTokens::TRANSLATOR_COMMENTS, 'Copyright (C) YEAR HOLDER');
$this->add(PoTokens::TRANSLATOR_COMMENTS, 'LICENSE');
$this->add(PoTokens::TRANSLATOR_COMMENTS, 'FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.');
$this->add(PoTokens::TRANSLATOR_COMMENTS, '');
$this->set(PoTokens::FLAG, 'fuzzy');
$this->setHeader('Project-Id-Version', 'PACKAGE VERSION');
$this->setHeader('Report-Msgid-Bugs-To', 'FULL NAME <EMAIL@ADDRESS>');
$this->setCreateDate();
$this->setHeader('PO-Revision-Date', 'YEAR-MO-DA HO:MI+ZONE');
$this->setHeader('Last-Translator', 'FULL NAME <EMAIL@ADDRESS>');
$this->setHeader('Language-Team', 'LANGUAGE <EMAIL@ADDRESS>');
$this->setHeader('MIME-Version', '1.0');
$this->setHeader('Content-Type', 'text/plain; charset=UTF-8');
$this->setHeader('Content-Transfer-Encoding', '8bit');
$this->setHeader('Plural-Forms', 'nplurals=INTEGER; plural=EXPRESSION;');
$this->setHeader('X-Generator', 'geekwright/po');
} | [
"public",
"function",
"buildDefaultHeader",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"set",
"(",
"PoTokens",
"::",
"MESSAGE",
",",
"\"\"",
")",
";",
"$",
"this",
"->",
"set",
"(",
"PoTokens",
"::",
"TRANSLATOR_COMMENTS",
",",
"'SOME DESCRIPTIVE TITLE'",
")",
";",
"$",
"this",
"->",
"add",
"(",
"PoTokens",
"::",
"TRANSLATOR_COMMENTS",
",",
"'Copyright (C) YEAR HOLDER'",
")",
";",
"$",
"this",
"->",
"add",
"(",
"PoTokens",
"::",
"TRANSLATOR_COMMENTS",
",",
"'LICENSE'",
")",
";",
"$",
"this",
"->",
"add",
"(",
"PoTokens",
"::",
"TRANSLATOR_COMMENTS",
",",
"'FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.'",
")",
";",
"$",
"this",
"->",
"add",
"(",
"PoTokens",
"::",
"TRANSLATOR_COMMENTS",
",",
"''",
")",
";",
"$",
"this",
"->",
"set",
"(",
"PoTokens",
"::",
"FLAG",
",",
"'fuzzy'",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Project-Id-Version'",
",",
"'PACKAGE VERSION'",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Report-Msgid-Bugs-To'",
",",
"'FULL NAME <EMAIL@ADDRESS>'",
")",
";",
"$",
"this",
"->",
"setCreateDate",
"(",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'PO-Revision-Date'",
",",
"'YEAR-MO-DA HO:MI+ZONE'",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Last-Translator'",
",",
"'FULL NAME <EMAIL@ADDRESS>'",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Language-Team'",
",",
"'LANGUAGE <EMAIL@ADDRESS>'",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'MIME-Version'",
",",
"'1.0'",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"'text/plain; charset=UTF-8'",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Content-Transfer-Encoding'",
",",
"'8bit'",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Plural-Forms'",
",",
"'nplurals=INTEGER; plural=EXPRESSION;'",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'X-Generator'",
",",
"'geekwright/po'",
")",
";",
"}"
]
| Create a default header entry
@return void | [
"Create",
"a",
"default",
"header",
"entry"
]
| train | https://github.com/geekwright/Po/blob/9474d059a83b64e6242cc41e5c5b7a08bc57e4e2/src/PoHeader.php#L161-L181 |
webforge-labs/psc-cms | lib/Psc/Object.php | Object.factory | public static function factory() {
$args = func_get_args();
$className = array_shift($args); // className entfernen
if (isset($args[1]) && $args[1] == self::REPLACE_ARGS) {
$args = $args[0];
}
if (!class_exists($className)) {
throw new \Psc\Exception($className. ' kann nicht geladen werden');
}
/* funky switch da wir performance wollen */
switch (count($args)) {
case 0:
return new $className;
case 1:
return new $className($args[0]);
case 2:
return new $className($args[0],$args[1]);
case 3:
return new $className($args[0],$args[1],$args[2]);
case 4:
return new $className($args[0],$args[1],$args[2],$args[3]);
case 5:
return new $className($args[0],$args[1],$args[2],$args[3],$args[4]);
case 6:
return new $className($args[0],$args[1],$args[2],$args[3],$args[4],$args[5]);
case 7:
return new $className($args[0],$args[1],$args[2],$args[3],$args[4],$args[5],$args[6]);
case 8:
return new $className($args[0],$args[1],$args[2],$args[3],$args[4],$args[5],$args[6],$args[7]);
default:
$rfc = new \ReflectionClass($className);
// use Reflection to create a new instance, using the $args
return $rfc->newInstanceArgs($args);
}
} | php | public static function factory() {
$args = func_get_args();
$className = array_shift($args); // className entfernen
if (isset($args[1]) && $args[1] == self::REPLACE_ARGS) {
$args = $args[0];
}
if (!class_exists($className)) {
throw new \Psc\Exception($className. ' kann nicht geladen werden');
}
/* funky switch da wir performance wollen */
switch (count($args)) {
case 0:
return new $className;
case 1:
return new $className($args[0]);
case 2:
return new $className($args[0],$args[1]);
case 3:
return new $className($args[0],$args[1],$args[2]);
case 4:
return new $className($args[0],$args[1],$args[2],$args[3]);
case 5:
return new $className($args[0],$args[1],$args[2],$args[3],$args[4]);
case 6:
return new $className($args[0],$args[1],$args[2],$args[3],$args[4],$args[5]);
case 7:
return new $className($args[0],$args[1],$args[2],$args[3],$args[4],$args[5],$args[6]);
case 8:
return new $className($args[0],$args[1],$args[2],$args[3],$args[4],$args[5],$args[6],$args[7]);
default:
$rfc = new \ReflectionClass($className);
// use Reflection to create a new instance, using the $args
return $rfc->newInstanceArgs($args);
}
} | [
"public",
"static",
"function",
"factory",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"className",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"// className entfernen",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"&&",
"$",
"args",
"[",
"1",
"]",
"==",
"self",
"::",
"REPLACE_ARGS",
")",
"{",
"$",
"args",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"\\",
"Psc",
"\\",
"Exception",
"(",
"$",
"className",
".",
"' kann nicht geladen werden'",
")",
";",
"}",
"/* funky switch da wir performance wollen */",
"switch",
"(",
"count",
"(",
"$",
"args",
")",
")",
"{",
"case",
"0",
":",
"return",
"new",
"$",
"className",
";",
"case",
"1",
":",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"case",
"2",
":",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
")",
";",
"case",
"3",
":",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
")",
";",
"case",
"4",
":",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
")",
";",
"case",
"5",
":",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
")",
";",
"case",
"6",
":",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
")",
";",
"case",
"7",
":",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
",",
"$",
"args",
"[",
"6",
"]",
")",
";",
"case",
"8",
":",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
",",
"$",
"args",
"[",
"6",
"]",
",",
"$",
"args",
"[",
"7",
"]",
")",
";",
"default",
":",
"$",
"rfc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"// use Reflection to create a new instance, using the $args",
"return",
"$",
"rfc",
"->",
"newInstanceArgs",
"(",
"$",
"args",
")",
";",
"}",
"}"
]
| Erstellt ein neues Objekt und gibt dieses zurück
Die Argument für den Konstruktor können ganz normal übergeben werden
Der Dritte Parameter kan self::REPLACE_ARGS sein, dann wird der zweite Parameter als Parameters interpretiert
@param string $className der Name der Klasse
@param mixed $arg,...
@return Object | [
"Erstellt",
"ein",
"neues",
"Objekt",
"und",
"gibt",
"dieses",
"zurück"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Object.php#L79-L126 |
webforge-labs/psc-cms | lib/Psc/Object.php | Object.callObjectMethod | public static function callObjectMethod($object, $name, Array $args = NULL) {
$args = (array) $args;
/* funky switch da wir performance wollen */
switch (count($args)) {
case 0:
return $object->$name();
case 1:
return $object->$name($args[0]);
case 2:
return $object->$name($args[0],$args[1]);
case 3:
return $object->$name($args[0],$args[1],$args[2]);
case 4:
return $object->$name($args[0],$args[1],$args[2],$args[3]);
case 5:
return $object->$name($args[0],$args[1],$args[2],$args[3],$args[4]);
case 6:
return $object->$name($args[0],$args[1],$args[2],$args[3],$args[4],$args[5]);
case 7:
return $object->$name($args[0],$args[1],$args[2],$args[3],$args[4],$args[5],$args[6]);
case 8:
return $object->$name($args[0],$args[1],$args[2],$args[3],$args[4],$args[5],$args[6],$args[7]);
default:
// use call_user_func_array evil
return call_user_func_array(array($object,$name),$args);
}
} | php | public static function callObjectMethod($object, $name, Array $args = NULL) {
$args = (array) $args;
/* funky switch da wir performance wollen */
switch (count($args)) {
case 0:
return $object->$name();
case 1:
return $object->$name($args[0]);
case 2:
return $object->$name($args[0],$args[1]);
case 3:
return $object->$name($args[0],$args[1],$args[2]);
case 4:
return $object->$name($args[0],$args[1],$args[2],$args[3]);
case 5:
return $object->$name($args[0],$args[1],$args[2],$args[3],$args[4]);
case 6:
return $object->$name($args[0],$args[1],$args[2],$args[3],$args[4],$args[5]);
case 7:
return $object->$name($args[0],$args[1],$args[2],$args[3],$args[4],$args[5],$args[6]);
case 8:
return $object->$name($args[0],$args[1],$args[2],$args[3],$args[4],$args[5],$args[6],$args[7]);
default:
// use call_user_func_array evil
return call_user_func_array(array($object,$name),$args);
}
} | [
"public",
"static",
"function",
"callObjectMethod",
"(",
"$",
"object",
",",
"$",
"name",
",",
"Array",
"$",
"args",
"=",
"NULL",
")",
"{",
"$",
"args",
"=",
"(",
"array",
")",
"$",
"args",
";",
"/* funky switch da wir performance wollen */",
"switch",
"(",
"count",
"(",
"$",
"args",
")",
")",
"{",
"case",
"0",
":",
"return",
"$",
"object",
"->",
"$",
"name",
"(",
")",
";",
"case",
"1",
":",
"return",
"$",
"object",
"->",
"$",
"name",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"case",
"2",
":",
"return",
"$",
"object",
"->",
"$",
"name",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
")",
";",
"case",
"3",
":",
"return",
"$",
"object",
"->",
"$",
"name",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
")",
";",
"case",
"4",
":",
"return",
"$",
"object",
"->",
"$",
"name",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
")",
";",
"case",
"5",
":",
"return",
"$",
"object",
"->",
"$",
"name",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
")",
";",
"case",
"6",
":",
"return",
"$",
"object",
"->",
"$",
"name",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
")",
";",
"case",
"7",
":",
"return",
"$",
"object",
"->",
"$",
"name",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
",",
"$",
"args",
"[",
"6",
"]",
")",
";",
"case",
"8",
":",
"return",
"$",
"object",
"->",
"$",
"name",
"(",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"args",
"[",
"1",
"]",
",",
"$",
"args",
"[",
"2",
"]",
",",
"$",
"args",
"[",
"3",
"]",
",",
"$",
"args",
"[",
"4",
"]",
",",
"$",
"args",
"[",
"5",
"]",
",",
"$",
"args",
"[",
"6",
"]",
",",
"$",
"args",
"[",
"7",
"]",
")",
";",
"default",
":",
"// use call_user_func_array evil",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"object",
",",
"$",
"name",
")",
",",
"$",
"args",
")",
";",
"}",
"}"
]
| Ruft eine Methode auf einem Objekt auf
@param object $object
@param string $name der Name der Methode die aufgerufen werden soll
@param array $arg
@return Object | [
"Ruft",
"eine",
"Methode",
"auf",
"einem",
"Objekt",
"auf"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Object.php#L138-L174 |
nodes-php/database | src/Eloquent/Model.php | Model.save | public function save(array $options = [])
{
try {
// Save model to database
$result = parent::save($options);
// If save has been aborted from an event/observer
// or simply returned an empty response, we'll treat
// it as a failed save and throw an exception.
if (! $result) {
throw new SaveFailedException(sprintf('Could not save model [%s]. Reason: Save returned false.', get_class($this)));
}
} catch (Exception $e) {
// Catch exceptions and re-throw
// as our Nodes "save failed" exceptions
throw (new SaveFailedException(sprintf('Could not save model [%s]. Reason: %s', get_class($this), $e->getMessage())))->setPreviousException($e);
} catch (Throwable $e) {
// Add support for PHP 7 throwable interface.
// Re-throw as our Nodes "save failed" exceptions.
throw (new SaveFailedException(sprintf('Could not save model [%s]. Reason: %s', get_class($this), $e->getMessage())))->setPreviousException($e);
}
return $result;
} | php | public function save(array $options = [])
{
try {
// Save model to database
$result = parent::save($options);
// If save has been aborted from an event/observer
// or simply returned an empty response, we'll treat
// it as a failed save and throw an exception.
if (! $result) {
throw new SaveFailedException(sprintf('Could not save model [%s]. Reason: Save returned false.', get_class($this)));
}
} catch (Exception $e) {
// Catch exceptions and re-throw
// as our Nodes "save failed" exceptions
throw (new SaveFailedException(sprintf('Could not save model [%s]. Reason: %s', get_class($this), $e->getMessage())))->setPreviousException($e);
} catch (Throwable $e) {
// Add support for PHP 7 throwable interface.
// Re-throw as our Nodes "save failed" exceptions.
throw (new SaveFailedException(sprintf('Could not save model [%s]. Reason: %s', get_class($this), $e->getMessage())))->setPreviousException($e);
}
return $result;
} | [
"public",
"function",
"save",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"// Save model to database",
"$",
"result",
"=",
"parent",
"::",
"save",
"(",
"$",
"options",
")",
";",
"// If save has been aborted from an event/observer",
"// or simply returned an empty response, we'll treat",
"// it as a failed save and throw an exception.",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"SaveFailedException",
"(",
"sprintf",
"(",
"'Could not save model [%s]. Reason: Save returned false.'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// Catch exceptions and re-throw",
"// as our Nodes \"save failed\" exceptions",
"throw",
"(",
"new",
"SaveFailedException",
"(",
"sprintf",
"(",
"'Could not save model [%s]. Reason: %s'",
",",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
")",
"->",
"setPreviousException",
"(",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"// Add support for PHP 7 throwable interface.",
"// Re-throw as our Nodes \"save failed\" exceptions.",
"throw",
"(",
"new",
"SaveFailedException",
"(",
"sprintf",
"(",
"'Could not save model [%s]. Reason: %s'",
",",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
")",
"->",
"setPreviousException",
"(",
"$",
"e",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Save the model to the database.
@author Morten Rugaard <[email protected]>
@param array $options
@return bool
@throws \Nodes\Database\Exceptions\SaveFailedException | [
"Save",
"the",
"model",
"to",
"the",
"database",
"."
]
| train | https://github.com/nodes-php/database/blob/ec58a01a2b966f89efeac58ac9ac633919c04a52/src/Eloquent/Model.php#L24-L47 |
yuncms/framework | src/user/models/LoginForm.php | LoginForm.confirmationValidate | public function confirmationValidate($attribute)
{
if (!$this->hasErrors()) {
if ($this->user !== null) {
$confirmationRequired = Yii::$app->settings->get('enableConfirmation', 'user') && !Yii::$app->settings->get('enableUnconfirmedLogin', 'user');
if ($confirmationRequired && !$this->user->isEmailConfirmed) {
$this->addError($attribute, Yii::t('yuncms', 'You need to confirm your email address.'));
}
if ($this->user->isBlocked) {
$this->addError($attribute, Yii::t('yuncms', 'Your account has been blocked.'));
}
}
}
} | php | public function confirmationValidate($attribute)
{
if (!$this->hasErrors()) {
if ($this->user !== null) {
$confirmationRequired = Yii::$app->settings->get('enableConfirmation', 'user') && !Yii::$app->settings->get('enableUnconfirmedLogin', 'user');
if ($confirmationRequired && !$this->user->isEmailConfirmed) {
$this->addError($attribute, Yii::t('yuncms', 'You need to confirm your email address.'));
}
if ($this->user->isBlocked) {
$this->addError($attribute, Yii::t('yuncms', 'Your account has been blocked.'));
}
}
}
} | [
"public",
"function",
"confirmationValidate",
"(",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"!==",
"null",
")",
"{",
"$",
"confirmationRequired",
"=",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"get",
"(",
"'enableConfirmation'",
",",
"'user'",
")",
"&&",
"!",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"get",
"(",
"'enableUnconfirmedLogin'",
",",
"'user'",
")",
";",
"if",
"(",
"$",
"confirmationRequired",
"&&",
"!",
"$",
"this",
"->",
"user",
"->",
"isEmailConfirmed",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"attribute",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'You need to confirm your email address.'",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"user",
"->",
"isBlocked",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"attribute",
",",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Your account has been blocked.'",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Validates the confirmation.
This method serves as the inline validation for password.
@param string $attribute the attribute currently being validated | [
"Validates",
"the",
"confirmation",
".",
"This",
"method",
"serves",
"as",
"the",
"inline",
"validation",
"for",
"password",
"."
]
| train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/LoginForm.php#L102-L115 |
yuncms/framework | src/user/models/LoginForm.php | LoginForm.login | public function login()
{
if ($this->validate()) {
UserLoginHistory::createAsync(['user_id' => $this->user->getId(), 'ip' => Yii::$app->request->userIP]);
return Yii::$app->user->login($this->user, $this->rememberMe ? Yii::$app->settings->get('rememberFor', 'user') : 0);
} else {
return false;
}
} | php | public function login()
{
if ($this->validate()) {
UserLoginHistory::createAsync(['user_id' => $this->user->getId(), 'ip' => Yii::$app->request->userIP]);
return Yii::$app->user->login($this->user, $this->rememberMe ? Yii::$app->settings->get('rememberFor', 'user') : 0);
} else {
return false;
}
} | [
"public",
"function",
"login",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"UserLoginHistory",
"::",
"createAsync",
"(",
"[",
"'user_id'",
"=>",
"$",
"this",
"->",
"user",
"->",
"getId",
"(",
")",
",",
"'ip'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"userIP",
"]",
")",
";",
"return",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"login",
"(",
"$",
"this",
"->",
"user",
",",
"$",
"this",
"->",
"rememberMe",
"?",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"get",
"(",
"'rememberFor'",
",",
"'user'",
")",
":",
"0",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Validates form and logs the user in.
@return boolean whether the user is logged in successfully | [
"Validates",
"form",
"and",
"logs",
"the",
"user",
"in",
"."
]
| train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/LoginForm.php#L122-L130 |
miisieq/InfaktClient | src/Infakt/Mapper/ClientMapper.php | ClientMapper.map | public function map($data)
{
return (new Client())
->setId((int) $data['id'])
->setCompanyName($data['company_name'])
->setStreet($data['street'])
->setCity($data['city'])
->setCountry($data['country'])
->setPostalCode($data['postal_code'])
->setNip($data['nip'])
->setPhoneNumber($data['phone_number'])
->setWebsite($data['web_site'])
->setEmail($data['email'])
->setNote($data['note'])
->setReceiver($data['receiver'])
->setMailingCompanyName($data['mailing_company_name'])
->setMailingStreet($data['mailing_street'])
->setMailingCity($data['mailing_city'])
->setMailingPostalCode($data['mailing_postal_code'])
->setDaysToPayment($data['days_to_payment'] ?: null)
->setPaymentMethod($data['payment_method'])
->setInvoiceNote($data['invoice_note'])
->setSameForwardAddress((bool) $data['same_forward_address']);
} | php | public function map($data)
{
return (new Client())
->setId((int) $data['id'])
->setCompanyName($data['company_name'])
->setStreet($data['street'])
->setCity($data['city'])
->setCountry($data['country'])
->setPostalCode($data['postal_code'])
->setNip($data['nip'])
->setPhoneNumber($data['phone_number'])
->setWebsite($data['web_site'])
->setEmail($data['email'])
->setNote($data['note'])
->setReceiver($data['receiver'])
->setMailingCompanyName($data['mailing_company_name'])
->setMailingStreet($data['mailing_street'])
->setMailingCity($data['mailing_city'])
->setMailingPostalCode($data['mailing_postal_code'])
->setDaysToPayment($data['days_to_payment'] ?: null)
->setPaymentMethod($data['payment_method'])
->setInvoiceNote($data['invoice_note'])
->setSameForwardAddress((bool) $data['same_forward_address']);
} | [
"public",
"function",
"map",
"(",
"$",
"data",
")",
"{",
"return",
"(",
"new",
"Client",
"(",
")",
")",
"->",
"setId",
"(",
"(",
"int",
")",
"$",
"data",
"[",
"'id'",
"]",
")",
"->",
"setCompanyName",
"(",
"$",
"data",
"[",
"'company_name'",
"]",
")",
"->",
"setStreet",
"(",
"$",
"data",
"[",
"'street'",
"]",
")",
"->",
"setCity",
"(",
"$",
"data",
"[",
"'city'",
"]",
")",
"->",
"setCountry",
"(",
"$",
"data",
"[",
"'country'",
"]",
")",
"->",
"setPostalCode",
"(",
"$",
"data",
"[",
"'postal_code'",
"]",
")",
"->",
"setNip",
"(",
"$",
"data",
"[",
"'nip'",
"]",
")",
"->",
"setPhoneNumber",
"(",
"$",
"data",
"[",
"'phone_number'",
"]",
")",
"->",
"setWebsite",
"(",
"$",
"data",
"[",
"'web_site'",
"]",
")",
"->",
"setEmail",
"(",
"$",
"data",
"[",
"'email'",
"]",
")",
"->",
"setNote",
"(",
"$",
"data",
"[",
"'note'",
"]",
")",
"->",
"setReceiver",
"(",
"$",
"data",
"[",
"'receiver'",
"]",
")",
"->",
"setMailingCompanyName",
"(",
"$",
"data",
"[",
"'mailing_company_name'",
"]",
")",
"->",
"setMailingStreet",
"(",
"$",
"data",
"[",
"'mailing_street'",
"]",
")",
"->",
"setMailingCity",
"(",
"$",
"data",
"[",
"'mailing_city'",
"]",
")",
"->",
"setMailingPostalCode",
"(",
"$",
"data",
"[",
"'mailing_postal_code'",
"]",
")",
"->",
"setDaysToPayment",
"(",
"$",
"data",
"[",
"'days_to_payment'",
"]",
"?",
":",
"null",
")",
"->",
"setPaymentMethod",
"(",
"$",
"data",
"[",
"'payment_method'",
"]",
")",
"->",
"setInvoiceNote",
"(",
"$",
"data",
"[",
"'invoice_note'",
"]",
")",
"->",
"setSameForwardAddress",
"(",
"(",
"bool",
")",
"$",
"data",
"[",
"'same_forward_address'",
"]",
")",
";",
"}"
]
| {@inheritdoc}
@param $data
@return Client | [
"{",
"@inheritdoc",
"}"
]
| train | https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Mapper/ClientMapper.php#L18-L41 |
lode/fem | src/exception.php | exception.setUserAction | public function setUserAction($link, $label=null) {
if ($label) {
$this->userAction = [
'link' => $link,
'label' => $label,
];
}
else {
$this->userAction = $link;
}
} | php | public function setUserAction($link, $label=null) {
if ($label) {
$this->userAction = [
'link' => $link,
'label' => $label,
];
}
else {
$this->userAction = $link;
}
} | [
"public",
"function",
"setUserAction",
"(",
"$",
"link",
",",
"$",
"label",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"label",
")",
"{",
"$",
"this",
"->",
"userAction",
"=",
"[",
"'link'",
"=>",
"$",
"link",
",",
"'label'",
"=>",
"$",
"label",
",",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"userAction",
"=",
"$",
"link",
";",
"}",
"}"
]
| set a user facing link as continue action
@param string $link
@param string $label optional | [
"set",
"a",
"user",
"facing",
"link",
"as",
"continue",
"action"
]
| train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/exception.php#L69-L79 |
lode/fem | src/exception.php | exception.clean_paths | public static function clean_paths($string) {
$string = str_replace(ROOT_DIR, '', $string);
$string = str_replace('.php', '', $string);
return $string;
} | php | public static function clean_paths($string) {
$string = str_replace(ROOT_DIR, '', $string);
$string = str_replace('.php', '', $string);
return $string;
} | [
"public",
"static",
"function",
"clean_paths",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"ROOT_DIR",
",",
"''",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"'.php'",
",",
"''",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
]
| cleans file paths from redundant information
i.e. ROOT_DIR and '.php' is removed
@param string $string
@return string | [
"cleans",
"file",
"paths",
"from",
"redundant",
"information",
"i",
".",
"e",
".",
"ROOT_DIR",
"and",
".",
"php",
"is",
"removed"
]
| train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/exception.php#L101-L106 |
simple-php-mvc/simple-php-mvc | src/MVC/Server/Router.php | Router._compile_regex | protected function _compile_regex($route)
{
$pattern = '`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`';
if ( preg_match_all($pattern, $route, $matches, PREG_SET_ORDER) ) {
$match_types = array(
'i' => '[0-9]++',
'a' => '[0-9A-Za-z]++',
'h' => '[0-9A-Fa-f]++',
'*' => '.+?',
'' => '[^/]++'
);
foreach ( $matches as $match ) {
list($block, $pre, $type, $param, $optional) = $match;
if ( isset($match_types[$type]) ) {
$type = $match_types[$type];
}
if ( $param ) {
$param = "?<{$param}>";
}
if ( $optional ) {
$optional = '?';
}
$replaced = "(?:{$pre}({$param}{$type})){$optional}";
$route = str_replace($block, $replaced, $route);
}
}
if ( substr($route, strlen($route) - 1) != '/' ) {
$route .= '/?';
}
return "`^{$route}$`";
} | php | protected function _compile_regex($route)
{
$pattern = '`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`';
if ( preg_match_all($pattern, $route, $matches, PREG_SET_ORDER) ) {
$match_types = array(
'i' => '[0-9]++',
'a' => '[0-9A-Za-z]++',
'h' => '[0-9A-Fa-f]++',
'*' => '.+?',
'' => '[^/]++'
);
foreach ( $matches as $match ) {
list($block, $pre, $type, $param, $optional) = $match;
if ( isset($match_types[$type]) ) {
$type = $match_types[$type];
}
if ( $param ) {
$param = "?<{$param}>";
}
if ( $optional ) {
$optional = '?';
}
$replaced = "(?:{$pre}({$param}{$type})){$optional}";
$route = str_replace($block, $replaced, $route);
}
}
if ( substr($route, strlen($route) - 1) != '/' ) {
$route .= '/?';
}
return "`^{$route}$`";
} | [
"protected",
"function",
"_compile_regex",
"(",
"$",
"route",
")",
"{",
"$",
"pattern",
"=",
"'`(/|\\.|)\\[([^:\\]]*+)(?::([^:\\]]*+))?\\](\\?|)`'",
";",
"if",
"(",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"route",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
")",
"{",
"$",
"match_types",
"=",
"array",
"(",
"'i'",
"=>",
"'[0-9]++'",
",",
"'a'",
"=>",
"'[0-9A-Za-z]++'",
",",
"'h'",
"=>",
"'[0-9A-Fa-f]++'",
",",
"'*'",
"=>",
"'.+?'",
",",
"''",
"=>",
"'[^/]++'",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"list",
"(",
"$",
"block",
",",
"$",
"pre",
",",
"$",
"type",
",",
"$",
"param",
",",
"$",
"optional",
")",
"=",
"$",
"match",
";",
"if",
"(",
"isset",
"(",
"$",
"match_types",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"match_types",
"[",
"$",
"type",
"]",
";",
"}",
"if",
"(",
"$",
"param",
")",
"{",
"$",
"param",
"=",
"\"?<{$param}>\"",
";",
"}",
"if",
"(",
"$",
"optional",
")",
"{",
"$",
"optional",
"=",
"'?'",
";",
"}",
"$",
"replaced",
"=",
"\"(?:{$pre}({$param}{$type})){$optional}\"",
";",
"$",
"route",
"=",
"str_replace",
"(",
"$",
"block",
",",
"$",
"replaced",
",",
"$",
"route",
")",
";",
"}",
"}",
"if",
"(",
"substr",
"(",
"$",
"route",
",",
"strlen",
"(",
"$",
"route",
")",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"route",
".=",
"'/?'",
";",
"}",
"return",
"\"`^{$route}$`\"",
";",
"}"
]
| Compiles the regex necessary to capture all match types within a route.
@access protected
@param string $route The route.
@return string | [
"Compiles",
"the",
"regex",
"necessary",
"to",
"capture",
"all",
"match",
"types",
"within",
"a",
"route",
"."
]
| train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Server/Router.php#L20-L53 |
simple-php-mvc/simple-php-mvc | src/MVC/Server/Router.php | Router.parse | public function parse(HttpRequest $request, $routes)
{
foreach ( $routes as $route ) {
if (!$route instanceof Route) {
throw new \LogicException(sprintf('The route given don\'t is instance of Route. Type given "%s".', gettype($route)));
}
list($methods, $patternUri, $action) = array($route->getMethods(), $route->getPatternUri(), $route->getAction());
if ( is_array($methods) ) {
$found = false;
foreach ( $methods as $method ) {
if ( strcasecmp($request->getMethod(), $method) == 0 ) {
$found = true;
break;
} elseif (($method === strtolower('ajax') || $method === strtolower('xhr')) && $request->isAjax()) {
$found = true;
break;
}
}
if ( !$found ) {
continue;
}
} elseif ( strcasecmp($request->getMethod(), $methods) != 0 ) {
continue;
} elseif (($methods === strtolower('ajax') || $methods === strtolower('xhr')) && $request->isAjax()) {
continue;
}
if ( is_null($patternUri) || $patternUri == '*' ) {
$found = false;
$params = array();
return compact('action', 'found', 'params');
}
$found = true;
$routeToMatch = '';
$len = strlen($patternUri);
$requestUri = $request->url;
for ( $i = 0; $i < $len; $i++ ) {
$char = $patternUri[$i];
$is_regex = (
$char == '[' || $char == '(' || $char == '.'
|| $char == '?' || $char == '+' || $char == '{'
);
if ( $is_regex ) {
$routeToMatch = $patternUri;
break;
} elseif (
!isset($requestUri[$i]) || $char != $requestUri[$i]
) {
continue 2;
}
$routeToMatch .= $char;
}
$params = array();
$regex = $this->_compile_regex($routeToMatch);
if ( preg_match($regex, $requestUri, $paramsMatched) ) {
foreach ( $paramsMatched as $key => $arg ) {
if ( is_numeric($key) ) {
unset($paramsMatched[$key]);
} else {
$params[$key] = $arg;
}
}
return compact('action', 'found', 'params');
}
}
return array(
'found' => false,
'params' => null,
'action' => null
);
} | php | public function parse(HttpRequest $request, $routes)
{
foreach ( $routes as $route ) {
if (!$route instanceof Route) {
throw new \LogicException(sprintf('The route given don\'t is instance of Route. Type given "%s".', gettype($route)));
}
list($methods, $patternUri, $action) = array($route->getMethods(), $route->getPatternUri(), $route->getAction());
if ( is_array($methods) ) {
$found = false;
foreach ( $methods as $method ) {
if ( strcasecmp($request->getMethod(), $method) == 0 ) {
$found = true;
break;
} elseif (($method === strtolower('ajax') || $method === strtolower('xhr')) && $request->isAjax()) {
$found = true;
break;
}
}
if ( !$found ) {
continue;
}
} elseif ( strcasecmp($request->getMethod(), $methods) != 0 ) {
continue;
} elseif (($methods === strtolower('ajax') || $methods === strtolower('xhr')) && $request->isAjax()) {
continue;
}
if ( is_null($patternUri) || $patternUri == '*' ) {
$found = false;
$params = array();
return compact('action', 'found', 'params');
}
$found = true;
$routeToMatch = '';
$len = strlen($patternUri);
$requestUri = $request->url;
for ( $i = 0; $i < $len; $i++ ) {
$char = $patternUri[$i];
$is_regex = (
$char == '[' || $char == '(' || $char == '.'
|| $char == '?' || $char == '+' || $char == '{'
);
if ( $is_regex ) {
$routeToMatch = $patternUri;
break;
} elseif (
!isset($requestUri[$i]) || $char != $requestUri[$i]
) {
continue 2;
}
$routeToMatch .= $char;
}
$params = array();
$regex = $this->_compile_regex($routeToMatch);
if ( preg_match($regex, $requestUri, $paramsMatched) ) {
foreach ( $paramsMatched as $key => $arg ) {
if ( is_numeric($key) ) {
unset($paramsMatched[$key]);
} else {
$params[$key] = $arg;
}
}
return compact('action', 'found', 'params');
}
}
return array(
'found' => false,
'params' => null,
'action' => null
);
} | [
"public",
"function",
"parse",
"(",
"HttpRequest",
"$",
"request",
",",
"$",
"routes",
")",
"{",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"!",
"$",
"route",
"instanceof",
"Route",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'The route given don\\'t is instance of Route. Type given \"%s\".'",
",",
"gettype",
"(",
"$",
"route",
")",
")",
")",
";",
"}",
"list",
"(",
"$",
"methods",
",",
"$",
"patternUri",
",",
"$",
"action",
")",
"=",
"array",
"(",
"$",
"route",
"->",
"getMethods",
"(",
")",
",",
"$",
"route",
"->",
"getPatternUri",
"(",
")",
",",
"$",
"route",
"->",
"getAction",
"(",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"methods",
")",
")",
"{",
"$",
"found",
"=",
"false",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"method",
")",
"==",
"0",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"elseif",
"(",
"(",
"$",
"method",
"===",
"strtolower",
"(",
"'ajax'",
")",
"||",
"$",
"method",
"===",
"strtolower",
"(",
"'xhr'",
")",
")",
"&&",
"$",
"request",
"->",
"isAjax",
"(",
")",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"continue",
";",
"}",
"}",
"elseif",
"(",
"strcasecmp",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"methods",
")",
"!=",
"0",
")",
"{",
"continue",
";",
"}",
"elseif",
"(",
"(",
"$",
"methods",
"===",
"strtolower",
"(",
"'ajax'",
")",
"||",
"$",
"methods",
"===",
"strtolower",
"(",
"'xhr'",
")",
")",
"&&",
"$",
"request",
"->",
"isAjax",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"patternUri",
")",
"||",
"$",
"patternUri",
"==",
"'*'",
")",
"{",
"$",
"found",
"=",
"false",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"return",
"compact",
"(",
"'action'",
",",
"'found'",
",",
"'params'",
")",
";",
"}",
"$",
"found",
"=",
"true",
";",
"$",
"routeToMatch",
"=",
"''",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"patternUri",
")",
";",
"$",
"requestUri",
"=",
"$",
"request",
"->",
"url",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"$",
"char",
"=",
"$",
"patternUri",
"[",
"$",
"i",
"]",
";",
"$",
"is_regex",
"=",
"(",
"$",
"char",
"==",
"'['",
"||",
"$",
"char",
"==",
"'('",
"||",
"$",
"char",
"==",
"'.'",
"||",
"$",
"char",
"==",
"'?'",
"||",
"$",
"char",
"==",
"'+'",
"||",
"$",
"char",
"==",
"'{'",
")",
";",
"if",
"(",
"$",
"is_regex",
")",
"{",
"$",
"routeToMatch",
"=",
"$",
"patternUri",
";",
"break",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"requestUri",
"[",
"$",
"i",
"]",
")",
"||",
"$",
"char",
"!=",
"$",
"requestUri",
"[",
"$",
"i",
"]",
")",
"{",
"continue",
"2",
";",
"}",
"$",
"routeToMatch",
".=",
"$",
"char",
";",
"}",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"regex",
"=",
"$",
"this",
"->",
"_compile_regex",
"(",
"$",
"routeToMatch",
")",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"requestUri",
",",
"$",
"paramsMatched",
")",
")",
"{",
"foreach",
"(",
"$",
"paramsMatched",
"as",
"$",
"key",
"=>",
"$",
"arg",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"unset",
"(",
"$",
"paramsMatched",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"$",
"params",
"[",
"$",
"key",
"]",
"=",
"$",
"arg",
";",
"}",
"}",
"return",
"compact",
"(",
"'action'",
",",
"'found'",
",",
"'params'",
")",
";",
"}",
"}",
"return",
"array",
"(",
"'found'",
"=>",
"false",
",",
"'params'",
"=>",
"null",
",",
"'action'",
"=>",
"null",
")",
";",
"}"
]
| Parses the supplied request uri based on the supplied routes and
the request method.
Routes should be of the following format:
<code>
$routes = array(
array(
mixed $request_method, string $request_uri, callable $callback
),
...
);
</code>
where:
<code>
$request_method can be a string ('GET', 'POST', 'PUT', 'DELETE'),
or an array (e.g., array('GET, 'POST')). Note that $request_method
is case-insensitive.
</code>
<code>
$request_uri is a string, with optional match types. Valid match types
are as follows:
[i] - integer
[a] - alphanumeric
[h] - hexadecimal
[*] - anything
Match types can be combined with parameter names, which will be
captured:
[i:id] - will match an integer, storing it within the returned 'params'
array under the 'id' key
[a:name] - will match an alphanumeric value, storing it within the
returned 'params' array under the 'name' key
Here are some examples to help illustrate:
/post/[i:id] - will match on /post/32 (with the returned 'params' array
containing an 'id' key with a value of 32), but will not match on
/post/today
/find/[h:serial] - will match on /find/ae32 (with the returned 'params'
array containing a 'serial' key will a value of 'ae32'), but will not
match on /find/john
</code>
<code>
$callback is a valid callback function.
</code>
Returns an array containing the following keys:
* 'params' - The parameters collected from the matched uri
* 'callback' - The callback function pulled from the matched route
@access public
@param string $requestUri The request uri.
@param string $requestMethod The request method.
@param Route[] $routes The routes.
@return array | [
"Parses",
"the",
"supplied",
"request",
"uri",
"based",
"on",
"the",
"supplied",
"routes",
"and",
"the",
"request",
"method",
"."
]
| train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Server/Router.php#L121-L197 |
rayrutjes/domain-foundation | src/UnitOfWork/DefaultUnitOfWork.php | DefaultUnitOfWork.registerAggregate | public function registerAggregate(
AggregateRoot $aggregate,
EventBus $eventBus,
SaveAggregateCallback $saveAggregateCallback
) {
return $this->registeredAggregates->add($aggregate, $eventBus, $saveAggregateCallback);
} | php | public function registerAggregate(
AggregateRoot $aggregate,
EventBus $eventBus,
SaveAggregateCallback $saveAggregateCallback
) {
return $this->registeredAggregates->add($aggregate, $eventBus, $saveAggregateCallback);
} | [
"public",
"function",
"registerAggregate",
"(",
"AggregateRoot",
"$",
"aggregate",
",",
"EventBus",
"$",
"eventBus",
",",
"SaveAggregateCallback",
"$",
"saveAggregateCallback",
")",
"{",
"return",
"$",
"this",
"->",
"registeredAggregates",
"->",
"add",
"(",
"$",
"aggregate",
",",
"$",
"eventBus",
",",
"$",
"saveAggregateCallback",
")",
";",
"}"
]
| @param AggregateRoot $aggregate
@param EventBus $eventBus
@param SaveAggregateCallback $saveAggregateCallback
@return AggregateRoot | [
"@param",
"AggregateRoot",
"$aggregate",
"@param",
"EventBus",
"$eventBus",
"@param",
"SaveAggregateCallback",
"$saveAggregateCallback"
]
| train | https://github.com/rayrutjes/domain-foundation/blob/2bce7cd6a6612f718e70e3176589c1abf39d1a3e/src/UnitOfWork/DefaultUnitOfWork.php#L121-L127 |
mongrate/mongrate | src/Mongrate/Model/Name.php | Name.validate | private function validate($name)
{
if (!is_string($name)) {
throw new InvalidNameException('Migration name must be a string, got ' . gettype($name));
}
if (strlen($name) === 0) {
throw new InvalidNameException('Migration name must not be empty');
}
$validCharsRegex = '/^[' . self::NAME_VALID_CHARS_REGEX . ']+$/';
if (preg_match($validCharsRegex, $name) === 0) {
$invalidChars = preg_replace('/[' . self::NAME_VALID_CHARS_REGEX . ']/', '', $name);
throw new InvalidNameException('Migration name contains invalid characters: ' . $invalidChars);
}
if (strlen($name) > self::MAX_NAME_LENGTH) {
throw new InvalidNameException(sprintf(
'Migration name cannot exceed %d characters, is %d: %s',
self::MAX_NAME_LENGTH,
strlen($name),
$name
));
}
} | php | private function validate($name)
{
if (!is_string($name)) {
throw new InvalidNameException('Migration name must be a string, got ' . gettype($name));
}
if (strlen($name) === 0) {
throw new InvalidNameException('Migration name must not be empty');
}
$validCharsRegex = '/^[' . self::NAME_VALID_CHARS_REGEX . ']+$/';
if (preg_match($validCharsRegex, $name) === 0) {
$invalidChars = preg_replace('/[' . self::NAME_VALID_CHARS_REGEX . ']/', '', $name);
throw new InvalidNameException('Migration name contains invalid characters: ' . $invalidChars);
}
if (strlen($name) > self::MAX_NAME_LENGTH) {
throw new InvalidNameException(sprintf(
'Migration name cannot exceed %d characters, is %d: %s',
self::MAX_NAME_LENGTH,
strlen($name),
$name
));
}
} | [
"private",
"function",
"validate",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidNameException",
"(",
"'Migration name must be a string, got '",
".",
"gettype",
"(",
"$",
"name",
")",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"name",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"InvalidNameException",
"(",
"'Migration name must not be empty'",
")",
";",
"}",
"$",
"validCharsRegex",
"=",
"'/^['",
".",
"self",
"::",
"NAME_VALID_CHARS_REGEX",
".",
"']+$/'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"validCharsRegex",
",",
"$",
"name",
")",
"===",
"0",
")",
"{",
"$",
"invalidChars",
"=",
"preg_replace",
"(",
"'/['",
".",
"self",
"::",
"NAME_VALID_CHARS_REGEX",
".",
"']/'",
",",
"''",
",",
"$",
"name",
")",
";",
"throw",
"new",
"InvalidNameException",
"(",
"'Migration name contains invalid characters: '",
".",
"$",
"invalidChars",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"name",
")",
">",
"self",
"::",
"MAX_NAME_LENGTH",
")",
"{",
"throw",
"new",
"InvalidNameException",
"(",
"sprintf",
"(",
"'Migration name cannot exceed %d characters, is %d: %s'",
",",
"self",
"::",
"MAX_NAME_LENGTH",
",",
"strlen",
"(",
"$",
"name",
")",
",",
"$",
"name",
")",
")",
";",
"}",
"}"
]
| Ensure the migration name is acceptable.
@throws InvalidNameException if the name given is invalid. | [
"Ensure",
"the",
"migration",
"name",
"is",
"acceptable",
"."
]
| train | https://github.com/mongrate/mongrate/blob/d76455a58a4ee5e6f8198e033c07bce40e2f7c7b/src/Mongrate/Model/Name.php#L47-L71 |
fyuze/framework | src/Fyuze/Kernel/Fyuze.php | Fyuze.init | protected function init()
{
$this->setupContainer();
$this->configure();
$this->errorHandling();
$this->registerServices();
$this->initialized = true;
} | php | protected function init()
{
$this->setupContainer();
$this->configure();
$this->errorHandling();
$this->registerServices();
$this->initialized = true;
} | [
"protected",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"setupContainer",
"(",
")",
";",
"$",
"this",
"->",
"configure",
"(",
")",
";",
"$",
"this",
"->",
"errorHandling",
"(",
")",
";",
"$",
"this",
"->",
"registerServices",
"(",
")",
";",
"$",
"this",
"->",
"initialized",
"=",
"true",
";",
"}"
]
| Initialize services
return @void | [
"Initialize",
"services"
]
| train | https://github.com/fyuze/framework/blob/89b3984f7225e24bfcdafb090ee197275b3222c9/src/Fyuze/Kernel/Fyuze.php#L112-L120 |
fyuze/framework | src/Fyuze/Kernel/Fyuze.php | Fyuze.setupContainer | protected function setupContainer()
{
$container = Registry::init();
$container->add('app', $this);
$container->add('registry', $container);
$container->add('config', function () {
return new Config($this->getConfigPath(), 'prod');
});
$this->config = $container->make('config');
$container->add('routes', function () {
return new Collection();
});
$this->container = $container;
} | php | protected function setupContainer()
{
$container = Registry::init();
$container->add('app', $this);
$container->add('registry', $container);
$container->add('config', function () {
return new Config($this->getConfigPath(), 'prod');
});
$this->config = $container->make('config');
$container->add('routes', function () {
return new Collection();
});
$this->container = $container;
} | [
"protected",
"function",
"setupContainer",
"(",
")",
"{",
"$",
"container",
"=",
"Registry",
"::",
"init",
"(",
")",
";",
"$",
"container",
"->",
"add",
"(",
"'app'",
",",
"$",
"this",
")",
";",
"$",
"container",
"->",
"add",
"(",
"'registry'",
",",
"$",
"container",
")",
";",
"$",
"container",
"->",
"add",
"(",
"'config'",
",",
"function",
"(",
")",
"{",
"return",
"new",
"Config",
"(",
"$",
"this",
"->",
"getConfigPath",
"(",
")",
",",
"'prod'",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"config",
"=",
"$",
"container",
"->",
"make",
"(",
"'config'",
")",
";",
"$",
"container",
"->",
"add",
"(",
"'routes'",
",",
"function",
"(",
")",
"{",
"return",
"new",
"Collection",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"container",
"=",
"$",
"container",
";",
"}"
]
| Registers container and some classes
@return void | [
"Registers",
"container",
"and",
"some",
"classes"
]
| train | https://github.com/fyuze/framework/blob/89b3984f7225e24bfcdafb090ee197275b3222c9/src/Fyuze/Kernel/Fyuze.php#L127-L144 |
fyuze/framework | src/Fyuze/Kernel/Fyuze.php | Fyuze.configure | protected function configure()
{
$config = $this->config->get('app');
$this->charset = $config['charset'];
mb_internal_encoding($this->charset);
date_default_timezone_set($config['timezone']);
} | php | protected function configure()
{
$config = $this->config->get('app');
$this->charset = $config['charset'];
mb_internal_encoding($this->charset);
date_default_timezone_set($config['timezone']);
} | [
"protected",
"function",
"configure",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'app'",
")",
";",
"$",
"this",
"->",
"charset",
"=",
"$",
"config",
"[",
"'charset'",
"]",
";",
"mb_internal_encoding",
"(",
"$",
"this",
"->",
"charset",
")",
";",
"date_default_timezone_set",
"(",
"$",
"config",
"[",
"'timezone'",
"]",
")",
";",
"}"
]
| Sets up basic application configurations
@return void | [
"Sets",
"up",
"basic",
"application",
"configurations"
]
| train | https://github.com/fyuze/framework/blob/89b3984f7225e24bfcdafb090ee197275b3222c9/src/Fyuze/Kernel/Fyuze.php#L151-L159 |
fyuze/framework | src/Fyuze/Kernel/Fyuze.php | Fyuze.registerServices | protected function registerServices()
{
$services = array_filter($this->config->get('app.services'), function ($service) {
return class_exists($service);
});
foreach ($services as $service) {
/** @var \Fyuze\Kernel\Service $obj */
$obj = new $service($this->container);
$obj->services();
$this->services[] = $obj;
}
} | php | protected function registerServices()
{
$services = array_filter($this->config->get('app.services'), function ($service) {
return class_exists($service);
});
foreach ($services as $service) {
/** @var \Fyuze\Kernel\Service $obj */
$obj = new $service($this->container);
$obj->services();
$this->services[] = $obj;
}
} | [
"protected",
"function",
"registerServices",
"(",
")",
"{",
"$",
"services",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'app.services'",
")",
",",
"function",
"(",
"$",
"service",
")",
"{",
"return",
"class_exists",
"(",
"$",
"service",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"services",
"as",
"$",
"service",
")",
"{",
"/** @var \\Fyuze\\Kernel\\Service $obj */",
"$",
"obj",
"=",
"new",
"$",
"service",
"(",
"$",
"this",
"->",
"container",
")",
";",
"$",
"obj",
"->",
"services",
"(",
")",
";",
"$",
"this",
"->",
"services",
"[",
"]",
"=",
"$",
"obj",
";",
"}",
"}"
]
| Registers all defined services
@return void | [
"Registers",
"all",
"defined",
"services"
]
| train | https://github.com/fyuze/framework/blob/89b3984f7225e24bfcdafb090ee197275b3222c9/src/Fyuze/Kernel/Fyuze.php#L166-L179 |
vorbind/influx-analytics | src/Adapter/MysqlDatabaseAdapter.php | MysqlDatabaseAdapter.getDatabaseAdapter | public function getDatabaseAdapter() {
try {
if (isset($this->db)) {
return $this->db;
}
$config = $this->reader->getDbsConfig();
if (!isset($config['mysql'])
|| !isset($config['mysql']["username"])
|| !isset($config['mysql']["password"])
|| !isset($config['mysql']["host"])
|| !isset($config['mysql']["database"]) ) {
throw new Exception("Mysql config is not valid!");
}
$username = $config['mysql']["username"];
$password = $config['mysql']["password"];
$host = $config['mysql']["host"];
$dbname = $config['mysql']["database"];
$this->db = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $this->db;
} catch (Exception $ex) {
print("ERROR:>>>>>>>" . $ex->getMessage());
throw new Exception("Faild to connect mysql db!");
}
} | php | public function getDatabaseAdapter() {
try {
if (isset($this->db)) {
return $this->db;
}
$config = $this->reader->getDbsConfig();
if (!isset($config['mysql'])
|| !isset($config['mysql']["username"])
|| !isset($config['mysql']["password"])
|| !isset($config['mysql']["host"])
|| !isset($config['mysql']["database"]) ) {
throw new Exception("Mysql config is not valid!");
}
$username = $config['mysql']["username"];
$password = $config['mysql']["password"];
$host = $config['mysql']["host"];
$dbname = $config['mysql']["database"];
$this->db = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $this->db;
} catch (Exception $ex) {
print("ERROR:>>>>>>>" . $ex->getMessage());
throw new Exception("Faild to connect mysql db!");
}
} | [
"public",
"function",
"getDatabaseAdapter",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"db",
")",
")",
"{",
"return",
"$",
"this",
"->",
"db",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"reader",
"->",
"getDbsConfig",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'mysql'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"config",
"[",
"'mysql'",
"]",
"[",
"\"username\"",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"config",
"[",
"'mysql'",
"]",
"[",
"\"password\"",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"config",
"[",
"'mysql'",
"]",
"[",
"\"host\"",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"config",
"[",
"'mysql'",
"]",
"[",
"\"database\"",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Mysql config is not valid!\"",
")",
";",
"}",
"$",
"username",
"=",
"$",
"config",
"[",
"'mysql'",
"]",
"[",
"\"username\"",
"]",
";",
"$",
"password",
"=",
"$",
"config",
"[",
"'mysql'",
"]",
"[",
"\"password\"",
"]",
";",
"$",
"host",
"=",
"$",
"config",
"[",
"'mysql'",
"]",
"[",
"\"host\"",
"]",
";",
"$",
"dbname",
"=",
"$",
"config",
"[",
"'mysql'",
"]",
"[",
"\"database\"",
"]",
";",
"$",
"this",
"->",
"db",
"=",
"new",
"PDO",
"(",
"\"mysql:host=$host;dbname=$dbname;charset=utf8\"",
",",
"$",
"username",
",",
"$",
"password",
")",
";",
"$",
"this",
"->",
"db",
"->",
"setAttribute",
"(",
"PDO",
"::",
"ATTR_ERRMODE",
",",
"PDO",
"::",
"ERRMODE_EXCEPTION",
")",
";",
"return",
"$",
"this",
"->",
"db",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"print",
"(",
"\"ERROR:>>>>>>>\"",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Faild to connect mysql db!\"",
")",
";",
"}",
"}"
]
| Get db adapter
@return PDO
@throws Exception | [
"Get",
"db",
"adapter"
]
| train | https://github.com/vorbind/influx-analytics/blob/8c0c150351f045ccd3d57063f2b3b50a2c926e3e/src/Adapter/MysqlDatabaseAdapter.php#L53-L80 |
madmis/exchange-api | src/ExchangeApi/Endpoint/EndpointFactory.php | EndpointFactory.getEndpoint | public function getEndpoint(string $type, ClientInterface $client, array $options = []): EndpointInterface
{
if (!array_key_exists($type, $this->endpointList)) {
if (class_exists($type)) {
$this->endpointList[$type] = new $type($client, $options);
} else {
$className = sprintf('%s\%sEndpoint', __NAMESPACE__, ucfirst($type));
if (!class_exists($className)) {
throw new \InvalidArgumentException("{$className} is not valid endpoint");
}
$this->endpointList[$type] = new $className($client);
}
}
return $this->endpointList[$type];
} | php | public function getEndpoint(string $type, ClientInterface $client, array $options = []): EndpointInterface
{
if (!array_key_exists($type, $this->endpointList)) {
if (class_exists($type)) {
$this->endpointList[$type] = new $type($client, $options);
} else {
$className = sprintf('%s\%sEndpoint', __NAMESPACE__, ucfirst($type));
if (!class_exists($className)) {
throw new \InvalidArgumentException("{$className} is not valid endpoint");
}
$this->endpointList[$type] = new $className($client);
}
}
return $this->endpointList[$type];
} | [
"public",
"function",
"getEndpoint",
"(",
"string",
"$",
"type",
",",
"ClientInterface",
"$",
"client",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"EndpointInterface",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"endpointList",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"endpointList",
"[",
"$",
"type",
"]",
"=",
"new",
"$",
"type",
"(",
"$",
"client",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"$",
"className",
"=",
"sprintf",
"(",
"'%s\\%sEndpoint'",
",",
"__NAMESPACE__",
",",
"ucfirst",
"(",
"$",
"type",
")",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"{$className} is not valid endpoint\"",
")",
";",
"}",
"$",
"this",
"->",
"endpointList",
"[",
"$",
"type",
"]",
"=",
"new",
"$",
"className",
"(",
"$",
"client",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"endpointList",
"[",
"$",
"type",
"]",
";",
"}"
]
| @param string $type endpoint type or class
@param ClientInterface $client
@param array $options additional endpoint options
@return EndpointInterface
@throws \InvalidArgumentException | [
"@param",
"string",
"$type",
"endpoint",
"type",
"or",
"class",
"@param",
"ClientInterface",
"$client",
"@param",
"array",
"$options",
"additional",
"endpoint",
"options"
]
| train | https://github.com/madmis/exchange-api/blob/a65121f6846c2cf4effe9e27a0e60f6b28c888c6/src/ExchangeApi/Endpoint/EndpointFactory.php#L27-L43 |
qcubed/orm | src/Database/PostgreSql/Row.php | Row.getColumn | public function getColumn($strColumnName, $strColumnType = null)
{
if (!isset($this->strColumnArray[$strColumnName])) {
return null;
}
$strColumnValue = $this->strColumnArray[$strColumnName];
switch ($strColumnType) {
case FieldType::BIT:
// PostgreSQL returns 't' or 'f' for boolean fields
if ($strColumnValue == 'f') {
return false;
} else {
return ($strColumnValue) ? true : false;
}
case FieldType::BLOB:
case FieldType::CHAR:
case FieldType::VAR_CHAR:
case FieldType::JSON: // JSON is basically String
return Type::cast($strColumnValue, Type::STRING);
case FieldType::DATE:
case FieldType::DATE_TIME:
case FieldType::TIME:
return new QDateTime($strColumnValue);
case FieldType::FLOAT:
return Type::cast($strColumnValue, Type::FLOAT);
case FieldType::INTEGER:
return Type::cast($strColumnValue, Type::INTEGER);
default:
return $strColumnValue;
}
} | php | public function getColumn($strColumnName, $strColumnType = null)
{
if (!isset($this->strColumnArray[$strColumnName])) {
return null;
}
$strColumnValue = $this->strColumnArray[$strColumnName];
switch ($strColumnType) {
case FieldType::BIT:
// PostgreSQL returns 't' or 'f' for boolean fields
if ($strColumnValue == 'f') {
return false;
} else {
return ($strColumnValue) ? true : false;
}
case FieldType::BLOB:
case FieldType::CHAR:
case FieldType::VAR_CHAR:
case FieldType::JSON: // JSON is basically String
return Type::cast($strColumnValue, Type::STRING);
case FieldType::DATE:
case FieldType::DATE_TIME:
case FieldType::TIME:
return new QDateTime($strColumnValue);
case FieldType::FLOAT:
return Type::cast($strColumnValue, Type::FLOAT);
case FieldType::INTEGER:
return Type::cast($strColumnValue, Type::INTEGER);
default:
return $strColumnValue;
}
} | [
"public",
"function",
"getColumn",
"(",
"$",
"strColumnName",
",",
"$",
"strColumnType",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"strColumnArray",
"[",
"$",
"strColumnName",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"strColumnValue",
"=",
"$",
"this",
"->",
"strColumnArray",
"[",
"$",
"strColumnName",
"]",
";",
"switch",
"(",
"$",
"strColumnType",
")",
"{",
"case",
"FieldType",
"::",
"BIT",
":",
"// PostgreSQL returns 't' or 'f' for boolean fields",
"if",
"(",
"$",
"strColumnValue",
"==",
"'f'",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"(",
"$",
"strColumnValue",
")",
"?",
"true",
":",
"false",
";",
"}",
"case",
"FieldType",
"::",
"BLOB",
":",
"case",
"FieldType",
"::",
"CHAR",
":",
"case",
"FieldType",
"::",
"VAR_CHAR",
":",
"case",
"FieldType",
"::",
"JSON",
":",
"// JSON is basically String",
"return",
"Type",
"::",
"cast",
"(",
"$",
"strColumnValue",
",",
"Type",
"::",
"STRING",
")",
";",
"case",
"FieldType",
"::",
"DATE",
":",
"case",
"FieldType",
"::",
"DATE_TIME",
":",
"case",
"FieldType",
"::",
"TIME",
":",
"return",
"new",
"QDateTime",
"(",
"$",
"strColumnValue",
")",
";",
"case",
"FieldType",
"::",
"FLOAT",
":",
"return",
"Type",
"::",
"cast",
"(",
"$",
"strColumnValue",
",",
"Type",
"::",
"FLOAT",
")",
";",
"case",
"FieldType",
"::",
"INTEGER",
":",
"return",
"Type",
"::",
"cast",
"(",
"$",
"strColumnValue",
",",
"Type",
"::",
"INTEGER",
")",
";",
"default",
":",
"return",
"$",
"strColumnValue",
";",
"}",
"}"
]
| Gets the value of a column from a result row returned by the database
@param string $strColumnName Name of the column
@param null|string $strColumnType Data type
@return mixed | [
"Gets",
"the",
"value",
"of",
"a",
"column",
"from",
"a",
"result",
"row",
"returned",
"by",
"the",
"database"
]
| train | https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Database/PostgreSql/Row.php#L45-L79 |
phpmob/changmin | src/PhpMob/CmsBundle/Form/Type/TemplateType.php | TemplateType.buildForm | public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', ChoiceType::class, [
'label' => 'phpmob.form.template.type',
'required' => true,
'choices' => array_flip([
TemplateInterface::TYPE_NORMAL => 'phpmob.form.template.type_normal',
TemplateInterface::TYPE_ABSTRACT => 'phpmob.form.template.type_abstract',
]),
])
->add('name', TextType::class, [
'label' => 'phpmob.form.template.name',
'required' => true,
])
->add('content', TextareaType::class, [
'label' => 'phpmob.form.template.content',
'required' => true,
])
->add('options', YamlType::class, [
'label' => 'phpmob.form.template.options',
'required' => false,
])
->add('definedTranslations', YamlType::class, [
'label' => 'phpmob.form.template.defined_translations',
'required' => false,
])
;
} | php | public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', ChoiceType::class, [
'label' => 'phpmob.form.template.type',
'required' => true,
'choices' => array_flip([
TemplateInterface::TYPE_NORMAL => 'phpmob.form.template.type_normal',
TemplateInterface::TYPE_ABSTRACT => 'phpmob.form.template.type_abstract',
]),
])
->add('name', TextType::class, [
'label' => 'phpmob.form.template.name',
'required' => true,
])
->add('content', TextareaType::class, [
'label' => 'phpmob.form.template.content',
'required' => true,
])
->add('options', YamlType::class, [
'label' => 'phpmob.form.template.options',
'required' => false,
])
->add('definedTranslations', YamlType::class, [
'label' => 'phpmob.form.template.defined_translations',
'required' => false,
])
;
} | [
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"builder",
"->",
"add",
"(",
"'type'",
",",
"ChoiceType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.template.type'",
",",
"'required'",
"=>",
"true",
",",
"'choices'",
"=>",
"array_flip",
"(",
"[",
"TemplateInterface",
"::",
"TYPE_NORMAL",
"=>",
"'phpmob.form.template.type_normal'",
",",
"TemplateInterface",
"::",
"TYPE_ABSTRACT",
"=>",
"'phpmob.form.template.type_abstract'",
",",
"]",
")",
",",
"]",
")",
"->",
"add",
"(",
"'name'",
",",
"TextType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.template.name'",
",",
"'required'",
"=>",
"true",
",",
"]",
")",
"->",
"add",
"(",
"'content'",
",",
"TextareaType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.template.content'",
",",
"'required'",
"=>",
"true",
",",
"]",
")",
"->",
"add",
"(",
"'options'",
",",
"YamlType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.template.options'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
"->",
"add",
"(",
"'definedTranslations'",
",",
"YamlType",
"::",
"class",
",",
"[",
"'label'",
"=>",
"'phpmob.form.template.defined_translations'",
",",
"'required'",
"=>",
"false",
",",
"]",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CmsBundle/Form/Type/TemplateType.php#L29-L57 |
christianblos/markdown2html | src/Filesystem.php | Filesystem.getFilesOfDir | public function getFilesOfDir($dir)
{
$iterator = new DirectoryIterator($dir);
$iterator = new CallbackFilterIterator(
$iterator,
function (SplFileInfo $current, $key, DirectoryIterator $iterator) {
return !$iterator->isDot();
}
);
return $iterator;
} | php | public function getFilesOfDir($dir)
{
$iterator = new DirectoryIterator($dir);
$iterator = new CallbackFilterIterator(
$iterator,
function (SplFileInfo $current, $key, DirectoryIterator $iterator) {
return !$iterator->isDot();
}
);
return $iterator;
} | [
"public",
"function",
"getFilesOfDir",
"(",
"$",
"dir",
")",
"{",
"$",
"iterator",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"dir",
")",
";",
"$",
"iterator",
"=",
"new",
"CallbackFilterIterator",
"(",
"$",
"iterator",
",",
"function",
"(",
"SplFileInfo",
"$",
"current",
",",
"$",
"key",
",",
"DirectoryIterator",
"$",
"iterator",
")",
"{",
"return",
"!",
"$",
"iterator",
"->",
"isDot",
"(",
")",
";",
"}",
")",
";",
"return",
"$",
"iterator",
";",
"}"
]
| @param string $dir
@return SplFileInfo[]|\Iterator | [
"@param",
"string",
"$dir"
]
| train | https://github.com/christianblos/markdown2html/blob/2ae1177d71fe313c802962dbb9226b5a90bbc65a/src/Filesystem.php#L16-L28 |
discordier/justtextwidgets | src/Widgets/JustAText.php | JustAText.generate | public function generate()
{
return sprintf(
'<input type="hidden" id="ctrl_%s" name="%s" value="%s" /><span>%s</span>',
$this->strId,
$this->strName,
StringUtil::specialchars($this->varValue),
$this->label
);
} | php | public function generate()
{
return sprintf(
'<input type="hidden" id="ctrl_%s" name="%s" value="%s" /><span>%s</span>',
$this->strId,
$this->strName,
StringUtil::specialchars($this->varValue),
$this->label
);
} | [
"public",
"function",
"generate",
"(",
")",
"{",
"return",
"sprintf",
"(",
"'<input type=\"hidden\" id=\"ctrl_%s\" name=\"%s\" value=\"%s\" /><span>%s</span>'",
",",
"$",
"this",
"->",
"strId",
",",
"$",
"this",
"->",
"strName",
",",
"StringUtil",
"::",
"specialchars",
"(",
"$",
"this",
"->",
"varValue",
")",
",",
"$",
"this",
"->",
"label",
")",
";",
"}"
]
| Generate the widget and return it as string.
@return string | [
"Generate",
"the",
"widget",
"and",
"return",
"it",
"as",
"string",
"."
]
| train | https://github.com/discordier/justtextwidgets/blob/585f20eec05d592bb13281ca8ef0972e956d3f06/src/Widgets/JustAText.php#L44-L53 |
miisieq/InfaktClient | src/Infakt/Repository/AbstractObjectRepository.php | AbstractObjectRepository.get | public function get(int $entityId)
{
$response = $this->infakt->get($this->getServiceName().'/'.$entityId.'.json');
if (2 != substr((string) $response->getStatusCode(), 0, 1)) {
return null;
}
return $this->getMapper()->map(\GuzzleHttp\json_decode($response->getBody()->getContents(), true));
} | php | public function get(int $entityId)
{
$response = $this->infakt->get($this->getServiceName().'/'.$entityId.'.json');
if (2 != substr((string) $response->getStatusCode(), 0, 1)) {
return null;
}
return $this->getMapper()->map(\GuzzleHttp\json_decode($response->getBody()->getContents(), true));
} | [
"public",
"function",
"get",
"(",
"int",
"$",
"entityId",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"infakt",
"->",
"get",
"(",
"$",
"this",
"->",
"getServiceName",
"(",
")",
".",
"'/'",
".",
"$",
"entityId",
".",
"'.json'",
")",
";",
"if",
"(",
"2",
"!=",
"substr",
"(",
"(",
"string",
")",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
",",
"0",
",",
"1",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"getMapper",
"(",
")",
"->",
"map",
"(",
"\\",
"GuzzleHttp",
"\\",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
",",
"true",
")",
")",
";",
"}"
]
| Get entity by ID.
@param $entityId
@return null|EntityInterface | [
"Get",
"entity",
"by",
"ID",
"."
]
| train | https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Repository/AbstractObjectRepository.php#L56-L65 |
miisieq/InfaktClient | src/Infakt/Repository/AbstractObjectRepository.php | AbstractObjectRepository.getAll | public function getAll(int $page = 1, int $limit = 25)
{
return $this->match(new Criteria([], [], ($page - 1) * $limit, $limit));
} | php | public function getAll(int $page = 1, int $limit = 25)
{
return $this->match(new Criteria([], [], ($page - 1) * $limit, $limit));
} | [
"public",
"function",
"getAll",
"(",
"int",
"$",
"page",
"=",
"1",
",",
"int",
"$",
"limit",
"=",
"25",
")",
"{",
"return",
"$",
"this",
"->",
"match",
"(",
"new",
"Criteria",
"(",
"[",
"]",
",",
"[",
"]",
",",
"(",
"$",
"page",
"-",
"1",
")",
"*",
"$",
"limit",
",",
"$",
"limit",
")",
")",
";",
"}"
]
| @param int $page
@param int $limit
@return CollectionResult | [
"@param",
"int",
"$page",
"@param",
"int",
"$limit"
]
| train | https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Repository/AbstractObjectRepository.php#L73-L76 |
miisieq/InfaktClient | src/Infakt/Repository/AbstractObjectRepository.php | AbstractObjectRepository.delete | public function delete(EntityInterface $entity)
{
return $this->infakt->delete($this->getServiceName().'/'.$entity->getId().'.json');
} | php | public function delete(EntityInterface $entity)
{
return $this->infakt->delete($this->getServiceName().'/'.$entity->getId().'.json');
} | [
"public",
"function",
"delete",
"(",
"EntityInterface",
"$",
"entity",
")",
"{",
"return",
"$",
"this",
"->",
"infakt",
"->",
"delete",
"(",
"$",
"this",
"->",
"getServiceName",
"(",
")",
".",
"'/'",
".",
"$",
"entity",
"->",
"getId",
"(",
")",
".",
"'.json'",
")",
";",
"}"
]
| Delete an entity.
@param EntityInterface $entity
@return \Psr\Http\Message\ResponseInterface | [
"Delete",
"an",
"entity",
"."
]
| train | https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Repository/AbstractObjectRepository.php#L100-L103 |
miisieq/InfaktClient | src/Infakt/Repository/AbstractObjectRepository.php | AbstractObjectRepository.match | protected function match(Criteria $criteria)
{
$response = $this->infakt->get($this->buildQuery($criteria));
$data = \GuzzleHttp\json_decode($response->getBody()->getContents(), true);
if (!(array_key_exists('metainfo', $data)
&& array_key_exists('total_count', $data['metainfo'])
&& array_key_exists('entities', $data))
) {
throw new ApiException('Response does not contain required fields.');
}
$mapper = $this->getMapper();
$collection = new CollectionResult();
$collection->setTotalCount($data['metainfo']['total_count']);
foreach ($data['entities'] as $entity) {
$collection->addItemToCollection($mapper->map($entity));
}
return $collection;
} | php | protected function match(Criteria $criteria)
{
$response = $this->infakt->get($this->buildQuery($criteria));
$data = \GuzzleHttp\json_decode($response->getBody()->getContents(), true);
if (!(array_key_exists('metainfo', $data)
&& array_key_exists('total_count', $data['metainfo'])
&& array_key_exists('entities', $data))
) {
throw new ApiException('Response does not contain required fields.');
}
$mapper = $this->getMapper();
$collection = new CollectionResult();
$collection->setTotalCount($data['metainfo']['total_count']);
foreach ($data['entities'] as $entity) {
$collection->addItemToCollection($mapper->map($entity));
}
return $collection;
} | [
"protected",
"function",
"match",
"(",
"Criteria",
"$",
"criteria",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"infakt",
"->",
"get",
"(",
"$",
"this",
"->",
"buildQuery",
"(",
"$",
"criteria",
")",
")",
";",
"$",
"data",
"=",
"\\",
"GuzzleHttp",
"\\",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"(",
"array_key_exists",
"(",
"'metainfo'",
",",
"$",
"data",
")",
"&&",
"array_key_exists",
"(",
"'total_count'",
",",
"$",
"data",
"[",
"'metainfo'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'entities'",
",",
"$",
"data",
")",
")",
")",
"{",
"throw",
"new",
"ApiException",
"(",
"'Response does not contain required fields.'",
")",
";",
"}",
"$",
"mapper",
"=",
"$",
"this",
"->",
"getMapper",
"(",
")",
";",
"$",
"collection",
"=",
"new",
"CollectionResult",
"(",
")",
";",
"$",
"collection",
"->",
"setTotalCount",
"(",
"$",
"data",
"[",
"'metainfo'",
"]",
"[",
"'total_count'",
"]",
")",
";",
"foreach",
"(",
"$",
"data",
"[",
"'entities'",
"]",
"as",
"$",
"entity",
")",
"{",
"$",
"collection",
"->",
"addItemToCollection",
"(",
"$",
"mapper",
"->",
"map",
"(",
"$",
"entity",
")",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
]
| @param Criteria $criteria
@throws ApiException
@return CollectionResult | [
"@param",
"Criteria",
"$criteria"
]
| train | https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Repository/AbstractObjectRepository.php#L158-L180 |
miisieq/InfaktClient | src/Infakt/Repository/AbstractObjectRepository.php | AbstractObjectRepository.getServiceName | protected function getServiceName(): string
{
return Inflector::pluralize(Inflector::tableize(substr($this->modelClass, strrpos($this->modelClass, '\\') + 1)));
} | php | protected function getServiceName(): string
{
return Inflector::pluralize(Inflector::tableize(substr($this->modelClass, strrpos($this->modelClass, '\\') + 1)));
} | [
"protected",
"function",
"getServiceName",
"(",
")",
":",
"string",
"{",
"return",
"Inflector",
"::",
"pluralize",
"(",
"Inflector",
"::",
"tableize",
"(",
"substr",
"(",
"$",
"this",
"->",
"modelClass",
",",
"strrpos",
"(",
"$",
"this",
"->",
"modelClass",
",",
"'\\\\'",
")",
"+",
"1",
")",
")",
")",
";",
"}"
]
| Gets API service name, for example: "clients" or "bank_accounts".
@return string | [
"Gets",
"API",
"service",
"name",
"for",
"example",
":",
"clients",
"or",
"bank_accounts",
"."
]
| train | https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Repository/AbstractObjectRepository.php#L187-L190 |
miisieq/InfaktClient | src/Infakt/Repository/AbstractObjectRepository.php | AbstractObjectRepository.getModelClass | protected function getModelClass(): string
{
$class = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
$class = substr($class, 0, strlen($class) - strlen('Repository'));
return 'Infakt\\Model\\'.$class;
} | php | protected function getModelClass(): string
{
$class = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
$class = substr($class, 0, strlen($class) - strlen('Repository'));
return 'Infakt\\Model\\'.$class;
} | [
"protected",
"function",
"getModelClass",
"(",
")",
":",
"string",
"{",
"$",
"class",
"=",
"substr",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"strrpos",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"'\\\\'",
")",
"+",
"1",
")",
";",
"$",
"class",
"=",
"substr",
"(",
"$",
"class",
",",
"0",
",",
"strlen",
"(",
"$",
"class",
")",
"-",
"strlen",
"(",
"'Repository'",
")",
")",
";",
"return",
"'Infakt\\\\Model\\\\'",
".",
"$",
"class",
";",
"}"
]
| Get fully-qualified class name of a model.
@return string | [
"Get",
"fully",
"-",
"qualified",
"class",
"name",
"of",
"a",
"model",
"."
]
| train | https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Repository/AbstractObjectRepository.php#L207-L213 |
miisieq/InfaktClient | src/Infakt/Repository/AbstractObjectRepository.php | AbstractObjectRepository.getMapperClass | protected function getMapperClass(): string
{
$class = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
$class = substr($class, 0, strlen($class) - strlen('Repository'));
return 'Infakt\\Mapper\\'.$class.'Mapper';
} | php | protected function getMapperClass(): string
{
$class = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
$class = substr($class, 0, strlen($class) - strlen('Repository'));
return 'Infakt\\Mapper\\'.$class.'Mapper';
} | [
"protected",
"function",
"getMapperClass",
"(",
")",
":",
"string",
"{",
"$",
"class",
"=",
"substr",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"strrpos",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"'\\\\'",
")",
"+",
"1",
")",
";",
"$",
"class",
"=",
"substr",
"(",
"$",
"class",
",",
"0",
",",
"strlen",
"(",
"$",
"class",
")",
"-",
"strlen",
"(",
"'Repository'",
")",
")",
";",
"return",
"'Infakt\\\\Mapper\\\\'",
".",
"$",
"class",
".",
"'Mapper'",
";",
"}"
]
| Get fully-qualified class name of a mapper.
@return string | [
"Get",
"fully",
"-",
"qualified",
"class",
"name",
"of",
"a",
"mapper",
"."
]
| train | https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Repository/AbstractObjectRepository.php#L220-L226 |
shiftio/safestream-php-sdk | src/Video/Video.php | Video.withTag | public function withTag($tag) {
if (is_null($this->tags)) {
$this->tags = [];
}
array_push($this->tags, $tag);
return $this;
} | php | public function withTag($tag) {
if (is_null($this->tags)) {
$this->tags = [];
}
array_push($this->tags, $tag);
return $this;
} | [
"public",
"function",
"withTag",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"tags",
")",
")",
"{",
"$",
"this",
"->",
"tags",
"=",
"[",
"]",
";",
"}",
"array_push",
"(",
"$",
"this",
"->",
"tags",
",",
"$",
"tag",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Fluent setter for the property tags
@param $tag
@return $this | [
"Fluent",
"setter",
"for",
"the",
"property",
"tags"
]
| train | https://github.com/shiftio/safestream-php-sdk/blob/1957cd5574725b24da1bbff9059aa30a9ca123c2/src/Video/Video.php#L143-L150 |
shiftio/safestream-php-sdk | src/Video/Video.php | Video.withTags | public function withTags($tags) {
if (is_null($this->tags)) {
$this->tags = [];
}
foreach ($tags as $tag) {
array_push($this->tags, $tags);
}
return $this;
} | php | public function withTags($tags) {
if (is_null($this->tags)) {
$this->tags = [];
}
foreach ($tags as $tag) {
array_push($this->tags, $tags);
}
return $this;
} | [
"public",
"function",
"withTags",
"(",
"$",
"tags",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"tags",
")",
")",
"{",
"$",
"this",
"->",
"tags",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"tags",
"as",
"$",
"tag",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"tags",
",",
"$",
"tags",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Fluent setter for the property tags
@param $tags
@return $this | [
"Fluent",
"setter",
"for",
"the",
"property",
"tags"
]
| train | https://github.com/shiftio/safestream-php-sdk/blob/1957cd5574725b24da1bbff9059aa30a9ca123c2/src/Video/Video.php#L158-L168 |
shiftio/safestream-php-sdk | src/Video/Video.php | Video.withExistingProxy | public function withExistingProxy(HlsProxy $hlsProxy) {
if(is_null($this->proxies)) {
$this->proxies = [];
}
array_push($this->proxies, $hlsProxy);
return $this;
} | php | public function withExistingProxy(HlsProxy $hlsProxy) {
if(is_null($this->proxies)) {
$this->proxies = [];
}
array_push($this->proxies, $hlsProxy);
return $this;
} | [
"public",
"function",
"withExistingProxy",
"(",
"HlsProxy",
"$",
"hlsProxy",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"proxies",
")",
")",
"{",
"$",
"this",
"->",
"proxies",
"=",
"[",
"]",
";",
"}",
"array_push",
"(",
"$",
"this",
"->",
"proxies",
",",
"$",
"hlsProxy",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Fluent setter for the property proxies
@param HlsProxy $hlsProxy
@return $this | [
"Fluent",
"setter",
"for",
"the",
"property",
"proxies"
]
| train | https://github.com/shiftio/safestream-php-sdk/blob/1957cd5574725b24da1bbff9059aa30a9ca123c2/src/Video/Video.php#L216-L224 |
FuriosoJack/LaraException | src/Exceptions/ExceptionProyect.php | ExceptionProyect.toArray | public function toArray()
{
return [
'message' => $this->getMessageException(),
'errors' => $this->getErrors(),
'debugCode' => $this->getDebugCode(),
'details' => $this->getDetails(),
'routeBack' => redirect()->back()->getTargetUrl()
];
} | php | public function toArray()
{
return [
'message' => $this->getMessageException(),
'errors' => $this->getErrors(),
'debugCode' => $this->getDebugCode(),
'details' => $this->getDetails(),
'routeBack' => redirect()->back()->getTargetUrl()
];
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"[",
"'message'",
"=>",
"$",
"this",
"->",
"getMessageException",
"(",
")",
",",
"'errors'",
"=>",
"$",
"this",
"->",
"getErrors",
"(",
")",
",",
"'debugCode'",
"=>",
"$",
"this",
"->",
"getDebugCode",
"(",
")",
",",
"'details'",
"=>",
"$",
"this",
"->",
"getDetails",
"(",
")",
",",
"'routeBack'",
"=>",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"getTargetUrl",
"(",
")",
"]",
";",
"}"
]
| convierte el Objeto en un array
@return array | [
"convierte",
"el",
"Objeto",
"en",
"un",
"array"
]
| train | https://github.com/FuriosoJack/LaraException/blob/b30ec2ed3331d99fca4d0ae47c8710a522bd0c19/src/Exceptions/ExceptionProyect.php#L101-L110 |
chubbyphp/chubbyphp-mock | src/MockByCallsTrait.php | MockByCallsTrait.getMockByCalls | private function getMockByCalls($class, array $calls = []): MockObject
{
$mock = $this->prepareMock($class);
$mockName = (new \ReflectionObject($mock))->getShortName();
$className = $this->getMockClassAsString($class);
$options = JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
$callIndex = -1;
$mock->expects(self::exactly(count($calls)))->method(self::anything())->willReturnCallback(
function () use ($className, $mock, $mockName, &$callIndex, &$calls, $options) {
++$callIndex;
$call = array_shift($calls);
$method = $call->getMethod();
$mocketMethod = $this->getMockedMethod($mockName);
if ($mocketMethod !== $method) {
self::fail(
sprintf(
'Call at index %d on class "%s" expected method "%s", "%s" given',
$callIndex,
$className,
$method,
$mocketMethod
)
.PHP_EOL
.json_encode($this->getStackTrace($mock), $options)
);
}
return $this->getMockCallback($className, $callIndex, $call, $mock)(...func_get_args());
}
);
return $mock;
} | php | private function getMockByCalls($class, array $calls = []): MockObject
{
$mock = $this->prepareMock($class);
$mockName = (new \ReflectionObject($mock))->getShortName();
$className = $this->getMockClassAsString($class);
$options = JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
$callIndex = -1;
$mock->expects(self::exactly(count($calls)))->method(self::anything())->willReturnCallback(
function () use ($className, $mock, $mockName, &$callIndex, &$calls, $options) {
++$callIndex;
$call = array_shift($calls);
$method = $call->getMethod();
$mocketMethod = $this->getMockedMethod($mockName);
if ($mocketMethod !== $method) {
self::fail(
sprintf(
'Call at index %d on class "%s" expected method "%s", "%s" given',
$callIndex,
$className,
$method,
$mocketMethod
)
.PHP_EOL
.json_encode($this->getStackTrace($mock), $options)
);
}
return $this->getMockCallback($className, $callIndex, $call, $mock)(...func_get_args());
}
);
return $mock;
} | [
"private",
"function",
"getMockByCalls",
"(",
"$",
"class",
",",
"array",
"$",
"calls",
"=",
"[",
"]",
")",
":",
"MockObject",
"{",
"$",
"mock",
"=",
"$",
"this",
"->",
"prepareMock",
"(",
"$",
"class",
")",
";",
"$",
"mockName",
"=",
"(",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"mock",
")",
")",
"->",
"getShortName",
"(",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"getMockClassAsString",
"(",
"$",
"class",
")",
";",
"$",
"options",
"=",
"JSON_PRETTY_PRINT",
"|",
"JSON_PRESERVE_ZERO_FRACTION",
"|",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_UNESCAPED_SLASHES",
";",
"$",
"callIndex",
"=",
"-",
"1",
";",
"$",
"mock",
"->",
"expects",
"(",
"self",
"::",
"exactly",
"(",
"count",
"(",
"$",
"calls",
")",
")",
")",
"->",
"method",
"(",
"self",
"::",
"anything",
"(",
")",
")",
"->",
"willReturnCallback",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"className",
",",
"$",
"mock",
",",
"$",
"mockName",
",",
"&",
"$",
"callIndex",
",",
"&",
"$",
"calls",
",",
"$",
"options",
")",
"{",
"++",
"$",
"callIndex",
";",
"$",
"call",
"=",
"array_shift",
"(",
"$",
"calls",
")",
";",
"$",
"method",
"=",
"$",
"call",
"->",
"getMethod",
"(",
")",
";",
"$",
"mocketMethod",
"=",
"$",
"this",
"->",
"getMockedMethod",
"(",
"$",
"mockName",
")",
";",
"if",
"(",
"$",
"mocketMethod",
"!==",
"$",
"method",
")",
"{",
"self",
"::",
"fail",
"(",
"sprintf",
"(",
"'Call at index %d on class \"%s\" expected method \"%s\", \"%s\" given'",
",",
"$",
"callIndex",
",",
"$",
"className",
",",
"$",
"method",
",",
"$",
"mocketMethod",
")",
".",
"PHP_EOL",
".",
"json_encode",
"(",
"$",
"this",
"->",
"getStackTrace",
"(",
"$",
"mock",
")",
",",
"$",
"options",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getMockCallback",
"(",
"$",
"className",
",",
"$",
"callIndex",
",",
"$",
"call",
",",
"$",
"mock",
")",
"(",
"...",
"func_get_args",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"mock",
";",
"}"
]
| @param string[]|string $class
@param Call[] $calls
@return MockObject | [
"@param",
"string",
"[]",
"|string",
"$class",
"@param",
"Call",
"[]",
"$calls"
]
| train | https://github.com/chubbyphp/chubbyphp-mock/blob/4c58095b26eba579a2d707cf15cdab275e679041/src/MockByCallsTrait.php#L18-L58 |
chubbyphp/chubbyphp-mock | src/MockByCallsTrait.php | MockByCallsTrait.getMockedMethod | private function getMockedMethod(string $mockName): string
{
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $trace) {
if ($mockName === $trace['class']) {
return $trace['function'];
}
}
} | php | private function getMockedMethod(string $mockName): string
{
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $trace) {
if ($mockName === $trace['class']) {
return $trace['function'];
}
}
} | [
"private",
"function",
"getMockedMethod",
"(",
"string",
"$",
"mockName",
")",
":",
"string",
"{",
"foreach",
"(",
"debug_backtrace",
"(",
"DEBUG_BACKTRACE_IGNORE_ARGS",
")",
"as",
"$",
"trace",
")",
"{",
"if",
"(",
"$",
"mockName",
"===",
"$",
"trace",
"[",
"'class'",
"]",
")",
"{",
"return",
"$",
"trace",
"[",
"'function'",
"]",
";",
"}",
"}",
"}"
]
| @param string $mockName
@return string | [
"@param",
"string",
"$mockName"
]
| train | https://github.com/chubbyphp/chubbyphp-mock/blob/4c58095b26eba579a2d707cf15cdab275e679041/src/MockByCallsTrait.php#L93-L100 |
chubbyphp/chubbyphp-mock | src/MockByCallsTrait.php | MockByCallsTrait.getMockCallback | private function getMockCallback(
string $class,
int $callIndex,
Call $call,
MockObject $mock
): \Closure {
return function () use ($class, $callIndex, $call, $mock) {
if ($call->hasWith()) {
$this->compareArguments($class, $call->getMethod(), $callIndex, $call->getWith(), func_get_args());
}
if (null !== $exception = $call->getException()) {
throw $exception;
}
if ($call->hasReturnSelf()) {
return $mock;
}
if ($call->hasReturn()) {
return $call->getReturn();
}
if ($call->hasReturnCallback()) {
$callback = $call->getReturnCallback();
return $callback(...func_get_args());
}
};
} | php | private function getMockCallback(
string $class,
int $callIndex,
Call $call,
MockObject $mock
): \Closure {
return function () use ($class, $callIndex, $call, $mock) {
if ($call->hasWith()) {
$this->compareArguments($class, $call->getMethod(), $callIndex, $call->getWith(), func_get_args());
}
if (null !== $exception = $call->getException()) {
throw $exception;
}
if ($call->hasReturnSelf()) {
return $mock;
}
if ($call->hasReturn()) {
return $call->getReturn();
}
if ($call->hasReturnCallback()) {
$callback = $call->getReturnCallback();
return $callback(...func_get_args());
}
};
} | [
"private",
"function",
"getMockCallback",
"(",
"string",
"$",
"class",
",",
"int",
"$",
"callIndex",
",",
"Call",
"$",
"call",
",",
"MockObject",
"$",
"mock",
")",
":",
"\\",
"Closure",
"{",
"return",
"function",
"(",
")",
"use",
"(",
"$",
"class",
",",
"$",
"callIndex",
",",
"$",
"call",
",",
"$",
"mock",
")",
"{",
"if",
"(",
"$",
"call",
"->",
"hasWith",
"(",
")",
")",
"{",
"$",
"this",
"->",
"compareArguments",
"(",
"$",
"class",
",",
"$",
"call",
"->",
"getMethod",
"(",
")",
",",
"$",
"callIndex",
",",
"$",
"call",
"->",
"getWith",
"(",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"exception",
"=",
"$",
"call",
"->",
"getException",
"(",
")",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"if",
"(",
"$",
"call",
"->",
"hasReturnSelf",
"(",
")",
")",
"{",
"return",
"$",
"mock",
";",
"}",
"if",
"(",
"$",
"call",
"->",
"hasReturn",
"(",
")",
")",
"{",
"return",
"$",
"call",
"->",
"getReturn",
"(",
")",
";",
"}",
"if",
"(",
"$",
"call",
"->",
"hasReturnCallback",
"(",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"call",
"->",
"getReturnCallback",
"(",
")",
";",
"return",
"$",
"callback",
"(",
"...",
"func_get_args",
"(",
")",
")",
";",
"}",
"}",
";",
"}"
]
| @param string $class
@param int $callIndex
@param Call $call
@param MockObject $mock
@return \Closure | [
"@param",
"string",
"$class",
"@param",
"int",
"$callIndex",
"@param",
"Call",
"$call",
"@param",
"MockObject",
"$mock"
]
| train | https://github.com/chubbyphp/chubbyphp-mock/blob/4c58095b26eba579a2d707cf15cdab275e679041/src/MockByCallsTrait.php#L110-L139 |
chubbyphp/chubbyphp-mock | src/MockByCallsTrait.php | MockByCallsTrait.getStackTrace | private function getStackTrace(MockObject $mock): array
{
$mockName = (new \ReflectionObject($mock))->getShortName();
$trace = [];
$enableTrace = false;
foreach (debug_backtrace() as $i => $row) {
if (isset($row['class']) && $mockName === $row['class']) {
$enableTrace = true;
}
if ($enableTrace) {
$traceRow = '';
if (isset($row['class'])) {
$traceRow .= $row['class'];
}
if (isset($row['type'])) {
$traceRow .= $row['type'];
}
if (isset($row['function'])) {
$traceRow .= $row['function'];
}
if (isset($row['file'])) {
$traceRow .= sprintf(' (%s:%d)', $row['file'], $row['line']);
}
$trace[] = $traceRow;
}
}
krsort($trace);
return array_values($trace);
} | php | private function getStackTrace(MockObject $mock): array
{
$mockName = (new \ReflectionObject($mock))->getShortName();
$trace = [];
$enableTrace = false;
foreach (debug_backtrace() as $i => $row) {
if (isset($row['class']) && $mockName === $row['class']) {
$enableTrace = true;
}
if ($enableTrace) {
$traceRow = '';
if (isset($row['class'])) {
$traceRow .= $row['class'];
}
if (isset($row['type'])) {
$traceRow .= $row['type'];
}
if (isset($row['function'])) {
$traceRow .= $row['function'];
}
if (isset($row['file'])) {
$traceRow .= sprintf(' (%s:%d)', $row['file'], $row['line']);
}
$trace[] = $traceRow;
}
}
krsort($trace);
return array_values($trace);
} | [
"private",
"function",
"getStackTrace",
"(",
"MockObject",
"$",
"mock",
")",
":",
"array",
"{",
"$",
"mockName",
"=",
"(",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"mock",
")",
")",
"->",
"getShortName",
"(",
")",
";",
"$",
"trace",
"=",
"[",
"]",
";",
"$",
"enableTrace",
"=",
"false",
";",
"foreach",
"(",
"debug_backtrace",
"(",
")",
"as",
"$",
"i",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'class'",
"]",
")",
"&&",
"$",
"mockName",
"===",
"$",
"row",
"[",
"'class'",
"]",
")",
"{",
"$",
"enableTrace",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"enableTrace",
")",
"{",
"$",
"traceRow",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"traceRow",
".=",
"$",
"row",
"[",
"'class'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"traceRow",
".=",
"$",
"row",
"[",
"'type'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'function'",
"]",
")",
")",
"{",
"$",
"traceRow",
".=",
"$",
"row",
"[",
"'function'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"'file'",
"]",
")",
")",
"{",
"$",
"traceRow",
".=",
"sprintf",
"(",
"' (%s:%d)'",
",",
"$",
"row",
"[",
"'file'",
"]",
",",
"$",
"row",
"[",
"'line'",
"]",
")",
";",
"}",
"$",
"trace",
"[",
"]",
"=",
"$",
"traceRow",
";",
"}",
"}",
"krsort",
"(",
"$",
"trace",
")",
";",
"return",
"array_values",
"(",
"$",
"trace",
")",
";",
"}"
]
| @param MockObject $mock
@return array | [
"@param",
"MockObject",
"$mock"
]
| train | https://github.com/chubbyphp/chubbyphp-mock/blob/4c58095b26eba579a2d707cf15cdab275e679041/src/MockByCallsTrait.php#L200-L237 |
spiral-modules/auth | source/Auth/TokenManager.php | TokenManager.createToken | public function createToken(UserInterface $user, string $operator = null): TokenInterface
{
return $this->getOperator($operator ?? $this->config->defaultOperator())->createToken($user);
} | php | public function createToken(UserInterface $user, string $operator = null): TokenInterface
{
return $this->getOperator($operator ?? $this->config->defaultOperator())->createToken($user);
} | [
"public",
"function",
"createToken",
"(",
"UserInterface",
"$",
"user",
",",
"string",
"$",
"operator",
"=",
"null",
")",
":",
"TokenInterface",
"{",
"return",
"$",
"this",
"->",
"getOperator",
"(",
"$",
"operator",
"??",
"$",
"this",
"->",
"config",
"->",
"defaultOperator",
"(",
")",
")",
"->",
"createToken",
"(",
"$",
"user",
")",
";",
"}"
]
| @param UserInterface $user
@param string $operator Default operator to be used when value is null.
@return TokenInterface | [
"@param",
"UserInterface",
"$user",
"@param",
"string",
"$operator",
"Default",
"operator",
"to",
"be",
"used",
"when",
"value",
"is",
"null",
"."
]
| train | https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/TokenManager.php#L53-L56 |
spiral-modules/auth | source/Auth/TokenManager.php | TokenManager.fetchToken | public function fetchToken(Request $request)
{
foreach ($this->config->getOperators() as $name) {
$operator = $this->getOperator($name);
if ($operator->hasToken($request)) {
return $operator->fetchToken($request);
}
}
return null;
} | php | public function fetchToken(Request $request)
{
foreach ($this->config->getOperators() as $name) {
$operator = $this->getOperator($name);
if ($operator->hasToken($request)) {
return $operator->fetchToken($request);
}
}
return null;
} | [
"public",
"function",
"fetchToken",
"(",
"Request",
"$",
"request",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"config",
"->",
"getOperators",
"(",
")",
"as",
"$",
"name",
")",
"{",
"$",
"operator",
"=",
"$",
"this",
"->",
"getOperator",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"operator",
"->",
"hasToken",
"(",
"$",
"request",
")",
")",
"{",
"return",
"$",
"operator",
"->",
"fetchToken",
"(",
"$",
"request",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Fetch authorization token from request if any.
@param Request $request
@return TokenInterface|null | [
"Fetch",
"authorization",
"token",
"from",
"request",
"if",
"any",
"."
]
| train | https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/TokenManager.php#L65-L76 |
spiral-modules/auth | source/Auth/TokenManager.php | TokenManager.getOperator | protected function getOperator(string $name): TokenOperatorInterface
{
if (isset($this->operators[$name])) {
return $this->operators[$name];
}
if (!$this->config->hasOperator($name)) {
throw new AuthException("Undefined token operator '{$name}'");
}
return $this->operators[$name] = $this->factory->make(
$this->config->operatorClass($name),
$this->config->operatorOptions($name)
);
} | php | protected function getOperator(string $name): TokenOperatorInterface
{
if (isset($this->operators[$name])) {
return $this->operators[$name];
}
if (!$this->config->hasOperator($name)) {
throw new AuthException("Undefined token operator '{$name}'");
}
return $this->operators[$name] = $this->factory->make(
$this->config->operatorClass($name),
$this->config->operatorOptions($name)
);
} | [
"protected",
"function",
"getOperator",
"(",
"string",
"$",
"name",
")",
":",
"TokenOperatorInterface",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"operators",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"operators",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
"->",
"hasOperator",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"AuthException",
"(",
"\"Undefined token operator '{$name}'\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"operators",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"factory",
"->",
"make",
"(",
"$",
"this",
"->",
"config",
"->",
"operatorClass",
"(",
"$",
"name",
")",
",",
"$",
"this",
"->",
"config",
"->",
"operatorOptions",
"(",
"$",
"name",
")",
")",
";",
"}"
]
| @param string $name
@return TokenOperatorInterface | [
"@param",
"string",
"$name"
]
| train | https://github.com/spiral-modules/auth/blob/24e2070028f7257e8192914556963a4794428a99/source/Auth/TokenManager.php#L83-L97 |
aedart/laravel-helpers | src/Traits/Routing/ResponseTrait.php | ResponseTrait.getResponse | public function getResponse(): ?ResponseFactory
{
if (!$this->hasResponse()) {
$this->setResponse($this->getDefaultResponse());
}
return $this->response;
} | php | public function getResponse(): ?ResponseFactory
{
if (!$this->hasResponse()) {
$this->setResponse($this->getDefaultResponse());
}
return $this->response;
} | [
"public",
"function",
"getResponse",
"(",
")",
":",
"?",
"ResponseFactory",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasResponse",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setResponse",
"(",
"$",
"this",
"->",
"getDefaultResponse",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"response",
";",
"}"
]
| Get response
If no response has been set, this method will
set and return a default response, if any such
value is available
@see getDefaultResponse()
@return ResponseFactory|null response or null if none response has been set | [
"Get",
"response"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Routing/ResponseTrait.php#L53-L59 |
tomphp/patch-builder | src/TomPHP/PatchBuilder/Buffer/Exception/RangePastEndOfBufferException.php | RangePastEndOfBufferException.fromRange | public static function fromRange(LineRangeInterface $range, $bufferLength)
{
return new self(sprintf(
'Range %d-%d goes beyond buffer with %d lines.',
$range->getStart()->getNumber(),
$range->getEnd()->getNumber(),
$bufferLength
));
} | php | public static function fromRange(LineRangeInterface $range, $bufferLength)
{
return new self(sprintf(
'Range %d-%d goes beyond buffer with %d lines.',
$range->getStart()->getNumber(),
$range->getEnd()->getNumber(),
$bufferLength
));
} | [
"public",
"static",
"function",
"fromRange",
"(",
"LineRangeInterface",
"$",
"range",
",",
"$",
"bufferLength",
")",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'Range %d-%d goes beyond buffer with %d lines.'",
",",
"$",
"range",
"->",
"getStart",
"(",
")",
"->",
"getNumber",
"(",
")",
",",
"$",
"range",
"->",
"getEnd",
"(",
")",
"->",
"getNumber",
"(",
")",
",",
"$",
"bufferLength",
")",
")",
";",
"}"
]
| @param int $bufferLength
@return RangePastEndOfBufferException | [
"@param",
"int",
"$bufferLength"
]
| train | https://github.com/tomphp/patch-builder/blob/4419eaad23016c7db1deffc6cce3f539096c11ce/src/TomPHP/PatchBuilder/Buffer/Exception/RangePastEndOfBufferException.php#L14-L22 |
mongrate/mongrate | src/Mongrate/Service/MigrationService.php | MigrationService.isMigrationApplied | public function isMigrationApplied(Name $name)
{
$this->ensureMigrationExists($name);
$collection = $this->getAppliedCollection();
$criteria = ['className' => (string) $name];
$record = $collection->find($criteria)->getSingleResult();
if ($record === null) {
return false;
} else {
return (bool) $record['isApplied'];
}
} | php | public function isMigrationApplied(Name $name)
{
$this->ensureMigrationExists($name);
$collection = $this->getAppliedCollection();
$criteria = ['className' => (string) $name];
$record = $collection->find($criteria)->getSingleResult();
if ($record === null) {
return false;
} else {
return (bool) $record['isApplied'];
}
} | [
"public",
"function",
"isMigrationApplied",
"(",
"Name",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"ensureMigrationExists",
"(",
"$",
"name",
")",
";",
"$",
"collection",
"=",
"$",
"this",
"->",
"getAppliedCollection",
"(",
")",
";",
"$",
"criteria",
"=",
"[",
"'className'",
"=>",
"(",
"string",
")",
"$",
"name",
"]",
";",
"$",
"record",
"=",
"$",
"collection",
"->",
"find",
"(",
"$",
"criteria",
")",
"->",
"getSingleResult",
"(",
")",
";",
"if",
"(",
"$",
"record",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"(",
"bool",
")",
"$",
"record",
"[",
"'isApplied'",
"]",
";",
"}",
"}"
]
| Check if a migration has been applied.
@param Name $name name of the migration.
@return bool | [
"Check",
"if",
"a",
"migration",
"has",
"been",
"applied",
"."
]
| train | https://github.com/mongrate/mongrate/blob/d76455a58a4ee5e6f8198e033c07bce40e2f7c7b/src/Mongrate/Service/MigrationService.php#L151-L164 |
mongrate/mongrate | src/Mongrate/Service/MigrationService.php | MigrationService.migrate | public function migrate(Name $name, Direction $direction, OutputInterface $output)
{
$migration = $this->createMigrationInstance($name, $output);
$output->writeln('<info>Migrating ' . $direction . '...</info> <comment>' . $name . '</comment>');
if ($direction->isUp()) {
$migration->up($this->getDatabase());
$this->setMigrationApplied($name, true);
} else {
$migration->down($this->getDatabase());
$this->setMigrationApplied($name, false);
}
$output->writeln('<info>Migrated ' . $direction . '</info>');
} | php | public function migrate(Name $name, Direction $direction, OutputInterface $output)
{
$migration = $this->createMigrationInstance($name, $output);
$output->writeln('<info>Migrating ' . $direction . '...</info> <comment>' . $name . '</comment>');
if ($direction->isUp()) {
$migration->up($this->getDatabase());
$this->setMigrationApplied($name, true);
} else {
$migration->down($this->getDatabase());
$this->setMigrationApplied($name, false);
}
$output->writeln('<info>Migrated ' . $direction . '</info>');
} | [
"public",
"function",
"migrate",
"(",
"Name",
"$",
"name",
",",
"Direction",
"$",
"direction",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"migration",
"=",
"$",
"this",
"->",
"createMigrationInstance",
"(",
"$",
"name",
",",
"$",
"output",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"'<info>Migrating '",
".",
"$",
"direction",
".",
"'...</info> <comment>'",
".",
"$",
"name",
".",
"'</comment>'",
")",
";",
"if",
"(",
"$",
"direction",
"->",
"isUp",
"(",
")",
")",
"{",
"$",
"migration",
"->",
"up",
"(",
"$",
"this",
"->",
"getDatabase",
"(",
")",
")",
";",
"$",
"this",
"->",
"setMigrationApplied",
"(",
"$",
"name",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"migration",
"->",
"down",
"(",
"$",
"this",
"->",
"getDatabase",
"(",
")",
")",
";",
"$",
"this",
"->",
"setMigrationApplied",
"(",
"$",
"name",
",",
"false",
")",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"'<info>Migrated '",
".",
"$",
"direction",
".",
"'</info>'",
")",
";",
"}"
]
| Migrate up or down.
@param Direction $direction | [
"Migrate",
"up",
"or",
"down",
"."
]
| train | https://github.com/mongrate/mongrate/blob/d76455a58a4ee5e6f8198e033c07bce40e2f7c7b/src/Mongrate/Service/MigrationService.php#L186-L201 |
mongrate/mongrate | src/Mongrate/Service/MigrationService.php | MigrationService.getAllMigrations | public function getAllMigrations()
{
$iterator = new \DirectoryIterator($this->configuration->getMigrationsDirectory());
$migrations = [];
foreach ($iterator as $file) {
$fileName = (string) $file;
if ($fileName === '.'|| $fileName === '..') {
continue;
}
if (!is_dir($file->getPathname())) {
// Ignore files that might be in the migrations directory, like documentation or
// a .gitignore or .gitkeep file.
continue;
}
$name = new Name($fileName);
$isApplied = $this->isMigrationApplied($name);
$migrations[] = new Migration($name, $isApplied);
}
usort($migrations, function (Migration $a, Migration $b) {
return strcmp($a->getName(), $b->getName());
});
return $migrations;
} | php | public function getAllMigrations()
{
$iterator = new \DirectoryIterator($this->configuration->getMigrationsDirectory());
$migrations = [];
foreach ($iterator as $file) {
$fileName = (string) $file;
if ($fileName === '.'|| $fileName === '..') {
continue;
}
if (!is_dir($file->getPathname())) {
// Ignore files that might be in the migrations directory, like documentation or
// a .gitignore or .gitkeep file.
continue;
}
$name = new Name($fileName);
$isApplied = $this->isMigrationApplied($name);
$migrations[] = new Migration($name, $isApplied);
}
usort($migrations, function (Migration $a, Migration $b) {
return strcmp($a->getName(), $b->getName());
});
return $migrations;
} | [
"public",
"function",
"getAllMigrations",
"(",
")",
"{",
"$",
"iterator",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getMigrationsDirectory",
"(",
")",
")",
";",
"$",
"migrations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"file",
")",
"{",
"$",
"fileName",
"=",
"(",
"string",
")",
"$",
"file",
";",
"if",
"(",
"$",
"fileName",
"===",
"'.'",
"||",
"$",
"fileName",
"===",
"'..'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
")",
"{",
"// Ignore files that might be in the migrations directory, like documentation or",
"// a .gitignore or .gitkeep file.",
"continue",
";",
"}",
"$",
"name",
"=",
"new",
"Name",
"(",
"$",
"fileName",
")",
";",
"$",
"isApplied",
"=",
"$",
"this",
"->",
"isMigrationApplied",
"(",
"$",
"name",
")",
";",
"$",
"migrations",
"[",
"]",
"=",
"new",
"Migration",
"(",
"$",
"name",
",",
"$",
"isApplied",
")",
";",
"}",
"usort",
"(",
"$",
"migrations",
",",
"function",
"(",
"Migration",
"$",
"a",
",",
"Migration",
"$",
"b",
")",
"{",
"return",
"strcmp",
"(",
"$",
"a",
"->",
"getName",
"(",
")",
",",
"$",
"b",
"->",
"getName",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"migrations",
";",
"}"
]
| Get a list of all migrations, sorted alphabetically.
@return Migration[] | [
"Get",
"a",
"list",
"of",
"all",
"migrations",
"sorted",
"alphabetically",
"."
]
| train | https://github.com/mongrate/mongrate/blob/d76455a58a4ee5e6f8198e033c07bce40e2f7c7b/src/Mongrate/Service/MigrationService.php#L208-L237 |
mongrate/mongrate | src/Mongrate/Service/MigrationService.php | MigrationService.getMigrationsNotApplied | public function getMigrationsNotApplied()
{
$migrationsNotApplied = [];
$migrations = $this->getAllMigrations();
foreach ($migrations as $migration) {
if (!$migration->isApplied()) {
$migrationsNotApplied[] = $migration;
}
}
return $migrationsNotApplied;
} | php | public function getMigrationsNotApplied()
{
$migrationsNotApplied = [];
$migrations = $this->getAllMigrations();
foreach ($migrations as $migration) {
if (!$migration->isApplied()) {
$migrationsNotApplied[] = $migration;
}
}
return $migrationsNotApplied;
} | [
"public",
"function",
"getMigrationsNotApplied",
"(",
")",
"{",
"$",
"migrationsNotApplied",
"=",
"[",
"]",
";",
"$",
"migrations",
"=",
"$",
"this",
"->",
"getAllMigrations",
"(",
")",
";",
"foreach",
"(",
"$",
"migrations",
"as",
"$",
"migration",
")",
"{",
"if",
"(",
"!",
"$",
"migration",
"->",
"isApplied",
"(",
")",
")",
"{",
"$",
"migrationsNotApplied",
"[",
"]",
"=",
"$",
"migration",
";",
"}",
"}",
"return",
"$",
"migrationsNotApplied",
";",
"}"
]
| Return array with all migrations that were note applied.
@return Migration[] | [
"Return",
"array",
"with",
"all",
"migrations",
"that",
"were",
"note",
"applied",
"."
]
| train | https://github.com/mongrate/mongrate/blob/d76455a58a4ee5e6f8198e033c07bce40e2f7c7b/src/Mongrate/Service/MigrationService.php#L244-L256 |
mongrate/mongrate | src/Mongrate/Service/MigrationService.php | MigrationService.setMigrationApplied | private function setMigrationApplied(Name $name, $isApplied)
{
$collection = $this->getAppliedCollection();
$criteria = ['className' => (string) $name];
$newObj = ['$set' => ['className' => (string) $name, 'isApplied' => $isApplied]];
$collection->upsert($criteria, $newObj);
} | php | private function setMigrationApplied(Name $name, $isApplied)
{
$collection = $this->getAppliedCollection();
$criteria = ['className' => (string) $name];
$newObj = ['$set' => ['className' => (string) $name, 'isApplied' => $isApplied]];
$collection->upsert($criteria, $newObj);
} | [
"private",
"function",
"setMigrationApplied",
"(",
"Name",
"$",
"name",
",",
"$",
"isApplied",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"getAppliedCollection",
"(",
")",
";",
"$",
"criteria",
"=",
"[",
"'className'",
"=>",
"(",
"string",
")",
"$",
"name",
"]",
";",
"$",
"newObj",
"=",
"[",
"'$set'",
"=>",
"[",
"'className'",
"=>",
"(",
"string",
")",
"$",
"name",
",",
"'isApplied'",
"=>",
"$",
"isApplied",
"]",
"]",
";",
"$",
"collection",
"->",
"upsert",
"(",
"$",
"criteria",
",",
"$",
"newObj",
")",
";",
"}"
]
| Update the database to record whether or not the migration has been applied.
@param boolean $isApplied | [
"Update",
"the",
"database",
"to",
"record",
"whether",
"or",
"not",
"the",
"migration",
"has",
"been",
"applied",
"."
]
| train | https://github.com/mongrate/mongrate/blob/d76455a58a4ee5e6f8198e033c07bce40e2f7c7b/src/Mongrate/Service/MigrationService.php#L298-L304 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.