id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
14,500 | jasny/router | src/Router/Middleware/ErrorPage.php | ErrorPage.getErrorRoute | protected function getErrorRoute(ServerRequestInterface $request, ResponseInterface $response)
{
if (
interface_exists('Jasny\HttpMessage\GlobalEnvironmentInterface') &&
$request instanceof GlobalEnvironmentInterface
) {
$request = $request->withoutGlobalEnvironment();
}
$status = $response->getStatusCode();
$errorUri = $request->getUri()
->withPath($status)
->withQuery(null)
->withFragment(null);
return $this->router->getRoutes()->getRoute($request->withUri($errorUri));
} | php | protected function getErrorRoute(ServerRequestInterface $request, ResponseInterface $response)
{
if (
interface_exists('Jasny\HttpMessage\GlobalEnvironmentInterface') &&
$request instanceof GlobalEnvironmentInterface
) {
$request = $request->withoutGlobalEnvironment();
}
$status = $response->getStatusCode();
$errorUri = $request->getUri()
->withPath($status)
->withQuery(null)
->withFragment(null);
return $this->router->getRoutes()->getRoute($request->withUri($errorUri));
} | [
"protected",
"function",
"getErrorRoute",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"if",
"(",
"interface_exists",
"(",
"'Jasny\\HttpMessage\\GlobalEnvironmentInterface'",
")",
"&&",
"$",
"request",
"instanceof",
"GlobalEnvironmentInterface",
")",
"{",
"$",
"request",
"=",
"$",
"request",
"->",
"withoutGlobalEnvironment",
"(",
")",
";",
"}",
"$",
"status",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"$",
"errorUri",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"withPath",
"(",
"$",
"status",
")",
"->",
"withQuery",
"(",
"null",
")",
"->",
"withFragment",
"(",
"null",
")",
";",
"return",
"$",
"this",
"->",
"router",
"->",
"getRoutes",
"(",
")",
"->",
"getRoute",
"(",
"$",
"request",
"->",
"withUri",
"(",
"$",
"errorUri",
")",
")",
";",
"}"
]
| Get the route to the error page
@param ServerRequestInterface $request
@param ResponseInterface $response
@return Router\Route | [
"Get",
"the",
"route",
"to",
"the",
"error",
"page"
]
| 4c776665ba343150b442c21893946e3d54190896 | https://github.com/jasny/router/blob/4c776665ba343150b442c21893946e3d54190896/src/Router/Middleware/ErrorPage.php#L84-L101 |
14,501 | jasny/router | src/Router/Middleware/ErrorPage.php | ErrorPage.routeToErrorPage | protected function routeToErrorPage(ServerRequestInterface $request, ResponseInterface $response)
{
$errorRoute = $this->getErrorRoute($request, $response);
if (!isset($errorRoute)) {
return $response;
}
$runner = $this->router->getRunner();
return $runner($request->withAttribute('route', $errorRoute), $response);
} | php | protected function routeToErrorPage(ServerRequestInterface $request, ResponseInterface $response)
{
$errorRoute = $this->getErrorRoute($request, $response);
if (!isset($errorRoute)) {
return $response;
}
$runner = $this->router->getRunner();
return $runner($request->withAttribute('route', $errorRoute), $response);
} | [
"protected",
"function",
"routeToErrorPage",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"errorRoute",
"=",
"$",
"this",
"->",
"getErrorRoute",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"errorRoute",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"$",
"runner",
"=",
"$",
"this",
"->",
"router",
"->",
"getRunner",
"(",
")",
";",
"return",
"$",
"runner",
"(",
"$",
"request",
"->",
"withAttribute",
"(",
"'route'",
",",
"$",
"errorRoute",
")",
",",
"$",
"response",
")",
";",
"}"
]
| Route to the error page
@param ServerRequestInterface $request
@param ResponseInterface $response
@return ResponseInterface | [
"Route",
"to",
"the",
"error",
"page"
]
| 4c776665ba343150b442c21893946e3d54190896 | https://github.com/jasny/router/blob/4c776665ba343150b442c21893946e3d54190896/src/Router/Middleware/ErrorPage.php#L110-L121 |
14,502 | paulzi/multicurl | MultiCurlQueue.php | MultiCurlQueue.processNext | protected function processNext()
{
foreach ($this->_status as $i => $status) {
if ($status === false && ($request = array_shift($this->_queue)) !== null) {
$this->_status[$i] = $request;
$this->_retries[$i] = 0;
$this->add($request);
}
}
} | php | protected function processNext()
{
foreach ($this->_status as $i => $status) {
if ($status === false && ($request = array_shift($this->_queue)) !== null) {
$this->_status[$i] = $request;
$this->_retries[$i] = 0;
$this->add($request);
}
}
} | [
"protected",
"function",
"processNext",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_status",
"as",
"$",
"i",
"=>",
"$",
"status",
")",
"{",
"if",
"(",
"$",
"status",
"===",
"false",
"&&",
"(",
"$",
"request",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"_queue",
")",
")",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_status",
"[",
"$",
"i",
"]",
"=",
"$",
"request",
";",
"$",
"this",
"->",
"_retries",
"[",
"$",
"i",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"add",
"(",
"$",
"request",
")",
";",
"}",
"}",
"}"
]
| Execute free threads | [
"Execute",
"free",
"threads"
]
| 2e326d868add238bb2820f3271e235bfed12e5cb | https://github.com/paulzi/multicurl/blob/2e326d868add238bb2820f3271e235bfed12e5cb/MultiCurlQueue.php#L58-L67 |
14,503 | BugBuster1701/banner | classes/DcaBanner.php | DcaBanner.addHeader | public function addHeader($add, $dca)
{
$catId = $add['id'];
unset($add['id']); //delete the helper
$sql = 'SELECT CAST(`banner_published` AS UNSIGNED INTEGER) AS published
,count(id) AS numbers
FROM `tl_banner`
WHERE `pid`=?
GROUP BY 1';
$objNumbers = \Database::getInstance()->prepare($sql)->execute($catId);
if ($objNumbers->numRows == 0)
{
return $add;
}
$published = 0;
$not_published = 0;
while ($objNumbers->next())
{
if ($objNumbers->published == 0)
{
$not_published = $objNumbers->numbers;
}
if ($objNumbers->published == 1)
{
$published = $objNumbers->numbers;
}
}
$add[$GLOBALS['TL_LANG']['tl_banner']['banner_number_of']] = $published." "
. $GLOBALS['TL_LANG']['tl_banner']['banner_active']
. " / "
. $not_published." "
. $GLOBALS['TL_LANG']['tl_banner']['banner_inactive'];
return $add;
} | php | public function addHeader($add, $dca)
{
$catId = $add['id'];
unset($add['id']); //delete the helper
$sql = 'SELECT CAST(`banner_published` AS UNSIGNED INTEGER) AS published
,count(id) AS numbers
FROM `tl_banner`
WHERE `pid`=?
GROUP BY 1';
$objNumbers = \Database::getInstance()->prepare($sql)->execute($catId);
if ($objNumbers->numRows == 0)
{
return $add;
}
$published = 0;
$not_published = 0;
while ($objNumbers->next())
{
if ($objNumbers->published == 0)
{
$not_published = $objNumbers->numbers;
}
if ($objNumbers->published == 1)
{
$published = $objNumbers->numbers;
}
}
$add[$GLOBALS['TL_LANG']['tl_banner']['banner_number_of']] = $published." "
. $GLOBALS['TL_LANG']['tl_banner']['banner_active']
. " / "
. $not_published." "
. $GLOBALS['TL_LANG']['tl_banner']['banner_inactive'];
return $add;
} | [
"public",
"function",
"addHeader",
"(",
"$",
"add",
",",
"$",
"dca",
")",
"{",
"$",
"catId",
"=",
"$",
"add",
"[",
"'id'",
"]",
";",
"unset",
"(",
"$",
"add",
"[",
"'id'",
"]",
")",
";",
"//delete the helper",
"$",
"sql",
"=",
"'SELECT CAST(`banner_published` AS UNSIGNED INTEGER) AS published\n \t,count(id) AS numbers \n FROM `tl_banner` \n WHERE `pid`=?\n GROUP BY 1'",
";",
"$",
"objNumbers",
"=",
"\\",
"Database",
"::",
"getInstance",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
"$",
"catId",
")",
";",
"if",
"(",
"$",
"objNumbers",
"->",
"numRows",
"==",
"0",
")",
"{",
"return",
"$",
"add",
";",
"}",
"$",
"published",
"=",
"0",
";",
"$",
"not_published",
"=",
"0",
";",
"while",
"(",
"$",
"objNumbers",
"->",
"next",
"(",
")",
")",
"{",
"if",
"(",
"$",
"objNumbers",
"->",
"published",
"==",
"0",
")",
"{",
"$",
"not_published",
"=",
"$",
"objNumbers",
"->",
"numbers",
";",
"}",
"if",
"(",
"$",
"objNumbers",
"->",
"published",
"==",
"1",
")",
"{",
"$",
"published",
"=",
"$",
"objNumbers",
"->",
"numbers",
";",
"}",
"}",
"$",
"add",
"[",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'tl_banner'",
"]",
"[",
"'banner_number_of'",
"]",
"]",
"=",
"$",
"published",
".",
"\" \"",
".",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'tl_banner'",
"]",
"[",
"'banner_active'",
"]",
".",
"\" / \"",
".",
"$",
"not_published",
".",
"\" \"",
".",
"$",
"GLOBALS",
"[",
"'TL_LANG'",
"]",
"[",
"'tl_banner'",
"]",
"[",
"'banner_inactive'",
"]",
";",
"return",
"$",
"add",
";",
"}"
]
| Add Header Rows, call from header_callback | [
"Add",
"Header",
"Rows",
"call",
"from",
"header_callback"
]
| 3ffac36837923194ab0ebaf308c0b23a3684b005 | https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/DcaBanner.php#L57-L92 |
14,504 | BugBuster1701/banner | classes/DcaBanner.php | DcaBanner.listBanner | public function listBanner($row)
{
switch ($row['banner_type'])
{
case self::BANNER_TYPE_INTERN :
return $this->listBannerInternal($row);
break;
case self::BANNER_TYPE_EXTERN :
return $this->listBannerExternal($row);
break;
case self::BANNER_TYPE_TEXT :
return $this->listBannerText($row);
break;
default :
return false;
break;
}
} | php | public function listBanner($row)
{
switch ($row['banner_type'])
{
case self::BANNER_TYPE_INTERN :
return $this->listBannerInternal($row);
break;
case self::BANNER_TYPE_EXTERN :
return $this->listBannerExternal($row);
break;
case self::BANNER_TYPE_TEXT :
return $this->listBannerText($row);
break;
default :
return false;
break;
}
} | [
"public",
"function",
"listBanner",
"(",
"$",
"row",
")",
"{",
"switch",
"(",
"$",
"row",
"[",
"'banner_type'",
"]",
")",
"{",
"case",
"self",
"::",
"BANNER_TYPE_INTERN",
":",
"return",
"$",
"this",
"->",
"listBannerInternal",
"(",
"$",
"row",
")",
";",
"break",
";",
"case",
"self",
"::",
"BANNER_TYPE_EXTERN",
":",
"return",
"$",
"this",
"->",
"listBannerExternal",
"(",
"$",
"row",
")",
";",
"break",
";",
"case",
"self",
"::",
"BANNER_TYPE_TEXT",
":",
"return",
"$",
"this",
"->",
"listBannerText",
"(",
"$",
"row",
")",
";",
"break",
";",
"default",
":",
"return",
"false",
";",
"break",
";",
"}",
"}"
]
| List banner record
@param object $row | [
"List",
"banner",
"record"
]
| 3ffac36837923194ab0ebaf308c0b23a3684b005 | https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/DcaBanner.php#L99-L116 |
14,505 | BugBuster1701/banner | classes/DcaBanner.php | DcaBanner.getBannerImageSizes | public function getBannerImageSizes()
{
$sizes = array();
$imageSize = $this->Database
->prepare("SELECT id, name, width, height FROM tl_image_size ORDER BY pid, name")
->execute(\Input::get('id'));
while ($imageSize->next())
{
$sizes[$imageSize->id] = $imageSize->name;
$sizes[$imageSize->id] .= ' (' . $imageSize->width . 'x' . $imageSize->height . ')';
}
return array_merge(array('image_sizes'=>$sizes), $GLOBALS['TL_CROP']);
} | php | public function getBannerImageSizes()
{
$sizes = array();
$imageSize = $this->Database
->prepare("SELECT id, name, width, height FROM tl_image_size ORDER BY pid, name")
->execute(\Input::get('id'));
while ($imageSize->next())
{
$sizes[$imageSize->id] = $imageSize->name;
$sizes[$imageSize->id] .= ' (' . $imageSize->width . 'x' . $imageSize->height . ')';
}
return array_merge(array('image_sizes'=>$sizes), $GLOBALS['TL_CROP']);
} | [
"public",
"function",
"getBannerImageSizes",
"(",
")",
"{",
"$",
"sizes",
"=",
"array",
"(",
")",
";",
"$",
"imageSize",
"=",
"$",
"this",
"->",
"Database",
"->",
"prepare",
"(",
"\"SELECT id, name, width, height FROM tl_image_size ORDER BY pid, name\"",
")",
"->",
"execute",
"(",
"\\",
"Input",
"::",
"get",
"(",
"'id'",
")",
")",
";",
"while",
"(",
"$",
"imageSize",
"->",
"next",
"(",
")",
")",
"{",
"$",
"sizes",
"[",
"$",
"imageSize",
"->",
"id",
"]",
"=",
"$",
"imageSize",
"->",
"name",
";",
"$",
"sizes",
"[",
"$",
"imageSize",
"->",
"id",
"]",
".=",
"' ('",
".",
"$",
"imageSize",
"->",
"width",
".",
"'x'",
".",
"$",
"imageSize",
"->",
"height",
".",
"')'",
";",
"}",
"return",
"array_merge",
"(",
"array",
"(",
"'image_sizes'",
"=>",
"$",
"sizes",
")",
",",
"$",
"GLOBALS",
"[",
"'TL_CROP'",
"]",
")",
";",
"}"
]
| Return all image sizes as array
@return array
@deprecated | [
"Return",
"all",
"image",
"sizes",
"as",
"array"
]
| 3ffac36837923194ab0ebaf308c0b23a3684b005 | https://github.com/BugBuster1701/banner/blob/3ffac36837923194ab0ebaf308c0b23a3684b005/classes/DcaBanner.php#L670-L682 |
14,506 | refinery29/piston | src/Piston.php | Piston.group | public function group($prefix, callable $group)
{
$group = new RouteGroup($prefix, $group, $this);
$this->groups[] = $group;
return $group;
} | php | public function group($prefix, callable $group)
{
$group = new RouteGroup($prefix, $group, $this);
$this->groups[] = $group;
return $group;
} | [
"public",
"function",
"group",
"(",
"$",
"prefix",
",",
"callable",
"$",
"group",
")",
"{",
"$",
"group",
"=",
"new",
"RouteGroup",
"(",
"$",
"prefix",
",",
"$",
"group",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"groups",
"[",
"]",
"=",
"$",
"group",
";",
"return",
"$",
"group",
";",
"}"
]
| Add a group of routes to the collection.
@param string $prefix
@param callable $group
@return RouteGroup | [
"Add",
"a",
"group",
"of",
"routes",
"to",
"the",
"collection",
"."
]
| 75c402e814136577fa9a02479e8803aca664c865 | https://github.com/refinery29/piston/blob/75c402e814136577fa9a02479e8803aca664c865/src/Piston.php#L86-L93 |
14,507 | dpi/ak | src/AvatarServiceDiscovery.php | AvatarServiceDiscovery.discoverClasses | protected function discoverClasses(array $namespaces) : array {
$classes = [];
foreach ($namespaces as $namespace => $namespace_directories) {
$namespace_directories = array_filter($namespace_directories, function ($dir) {
return is_dir($dir);
});
foreach ($namespace_directories as $namespace_directory) {
$finder = $this->createFinder()
->files()
->name('*.php')
->in($namespace_directory)
->path($this->subdir);
foreach ($finder as $file) {
// Remove the namespace directory from the full file path.
$sub_path = substr($file->getPath(), strlen($namespace_directory));
if (!empty($sub_path)) {
$sub_path = substr($sub_path, 1);
$sub_path = str_replace('/', '\\', $sub_path);
$sub_path .= '\\';
$classes[] = $namespace . $sub_path . $file->getBasename('.php');
}
}
}
}
return $classes;
} | php | protected function discoverClasses(array $namespaces) : array {
$classes = [];
foreach ($namespaces as $namespace => $namespace_directories) {
$namespace_directories = array_filter($namespace_directories, function ($dir) {
return is_dir($dir);
});
foreach ($namespace_directories as $namespace_directory) {
$finder = $this->createFinder()
->files()
->name('*.php')
->in($namespace_directory)
->path($this->subdir);
foreach ($finder as $file) {
// Remove the namespace directory from the full file path.
$sub_path = substr($file->getPath(), strlen($namespace_directory));
if (!empty($sub_path)) {
$sub_path = substr($sub_path, 1);
$sub_path = str_replace('/', '\\', $sub_path);
$sub_path .= '\\';
$classes[] = $namespace . $sub_path . $file->getBasename('.php');
}
}
}
}
return $classes;
} | [
"protected",
"function",
"discoverClasses",
"(",
"array",
"$",
"namespaces",
")",
":",
"array",
"{",
"$",
"classes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"namespace",
"=>",
"$",
"namespace_directories",
")",
"{",
"$",
"namespace_directories",
"=",
"array_filter",
"(",
"$",
"namespace_directories",
",",
"function",
"(",
"$",
"dir",
")",
"{",
"return",
"is_dir",
"(",
"$",
"dir",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"namespace_directories",
"as",
"$",
"namespace_directory",
")",
"{",
"$",
"finder",
"=",
"$",
"this",
"->",
"createFinder",
"(",
")",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"'*.php'",
")",
"->",
"in",
"(",
"$",
"namespace_directory",
")",
"->",
"path",
"(",
"$",
"this",
"->",
"subdir",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"// Remove the namespace directory from the full file path.",
"$",
"sub_path",
"=",
"substr",
"(",
"$",
"file",
"->",
"getPath",
"(",
")",
",",
"strlen",
"(",
"$",
"namespace_directory",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sub_path",
")",
")",
"{",
"$",
"sub_path",
"=",
"substr",
"(",
"$",
"sub_path",
",",
"1",
")",
";",
"$",
"sub_path",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"sub_path",
")",
";",
"$",
"sub_path",
".=",
"'\\\\'",
";",
"$",
"classes",
"[",
"]",
"=",
"$",
"namespace",
".",
"$",
"sub_path",
".",
"$",
"file",
"->",
"getBasename",
"(",
"'.php'",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"classes",
";",
"}"
]
| Discover files that look like avatar service classes.
@param array $namespaces
An array of namespaces where keys are namespaces and values are
directories.
@return string[]
An array of classes. | [
"Discover",
"files",
"that",
"look",
"like",
"avatar",
"service",
"classes",
"."
]
| cc61b172a827498cf6284191d51ce04d0f7c0f97 | https://github.com/dpi/ak/blob/cc61b172a827498cf6284191d51ce04d0f7c0f97/src/AvatarServiceDiscovery.php#L86-L113 |
14,508 | dpi/ak | src/AvatarServiceDiscovery.php | AvatarServiceDiscovery.discoverAnnotations | protected function discoverAnnotations(array $classes) : array {
AnnotationRegistry::reset();
AnnotationRegistry::registerLoader('class_exists');
$reader = $this->createReader();
$annotations = [];
foreach ($classes as $class) {
$reflection = new \ReflectionClass($class);
if (!$reflection->isSubclassOf($this->serviceInterface)) {
continue;
}
/** @var \dpi\ak\Annotation\AvatarService $annotation */
$annotation = $reader->getClassAnnotation($reflection, $this->annotationClass);
if ($annotation) {
$annotations[$class] = $annotation;
}
}
AnnotationRegistry::reset();
return $annotations;
} | php | protected function discoverAnnotations(array $classes) : array {
AnnotationRegistry::reset();
AnnotationRegistry::registerLoader('class_exists');
$reader = $this->createReader();
$annotations = [];
foreach ($classes as $class) {
$reflection = new \ReflectionClass($class);
if (!$reflection->isSubclassOf($this->serviceInterface)) {
continue;
}
/** @var \dpi\ak\Annotation\AvatarService $annotation */
$annotation = $reader->getClassAnnotation($reflection, $this->annotationClass);
if ($annotation) {
$annotations[$class] = $annotation;
}
}
AnnotationRegistry::reset();
return $annotations;
} | [
"protected",
"function",
"discoverAnnotations",
"(",
"array",
"$",
"classes",
")",
":",
"array",
"{",
"AnnotationRegistry",
"::",
"reset",
"(",
")",
";",
"AnnotationRegistry",
"::",
"registerLoader",
"(",
"'class_exists'",
")",
";",
"$",
"reader",
"=",
"$",
"this",
"->",
"createReader",
"(",
")",
";",
"$",
"annotations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"isSubclassOf",
"(",
"$",
"this",
"->",
"serviceInterface",
")",
")",
"{",
"continue",
";",
"}",
"/** @var \\dpi\\ak\\Annotation\\AvatarService $annotation */",
"$",
"annotation",
"=",
"$",
"reader",
"->",
"getClassAnnotation",
"(",
"$",
"reflection",
",",
"$",
"this",
"->",
"annotationClass",
")",
";",
"if",
"(",
"$",
"annotation",
")",
"{",
"$",
"annotations",
"[",
"$",
"class",
"]",
"=",
"$",
"annotation",
";",
"}",
"}",
"AnnotationRegistry",
"::",
"reset",
"(",
")",
";",
"return",
"$",
"annotations",
";",
"}"
]
| Discovers and caches annotations.
@param string[] $classes
An array of classes.
@return \dpi\ak\Annotation\AvatarService[]
An array of avatar services keyed by class name. | [
"Discovers",
"and",
"caches",
"annotations",
"."
]
| cc61b172a827498cf6284191d51ce04d0f7c0f97 | https://github.com/dpi/ak/blob/cc61b172a827498cf6284191d51ce04d0f7c0f97/src/AvatarServiceDiscovery.php#L131-L154 |
14,509 | it-blaster/color-picker-type-bundle | DependencyInjection/FenrizbesColorPickerTypeExtension.php | FenrizbesColorPickerTypeExtension.registerResources | protected function registerResources(ContainerBuilder $container)
{
$templatingEngines = $container->getParameter('templating.engines');
if (in_array('twig', $templatingEngines)) {
$container->setParameter('twig.form.resources', array_merge(
array('FenrizbesColorPickerTypeBundle:Form:fields.html.twig'),
$container->getParameter('twig.form.resources')
));
}
} | php | protected function registerResources(ContainerBuilder $container)
{
$templatingEngines = $container->getParameter('templating.engines');
if (in_array('twig', $templatingEngines)) {
$container->setParameter('twig.form.resources', array_merge(
array('FenrizbesColorPickerTypeBundle:Form:fields.html.twig'),
$container->getParameter('twig.form.resources')
));
}
} | [
"protected",
"function",
"registerResources",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"templatingEngines",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'templating.engines'",
")",
";",
"if",
"(",
"in_array",
"(",
"'twig'",
",",
"$",
"templatingEngines",
")",
")",
"{",
"$",
"container",
"->",
"setParameter",
"(",
"'twig.form.resources'",
",",
"array_merge",
"(",
"array",
"(",
"'FenrizbesColorPickerTypeBundle:Form:fields.html.twig'",
")",
",",
"$",
"container",
"->",
"getParameter",
"(",
"'twig.form.resources'",
")",
")",
")",
";",
"}",
"}"
]
| Registers form templates
@param ContainerBuilder $container | [
"Registers",
"form",
"templates"
]
| 507dba21e7ac32174090f08e7192673f3752b311 | https://github.com/it-blaster/color-picker-type-bundle/blob/507dba21e7ac32174090f08e7192673f3752b311/DependencyInjection/FenrizbesColorPickerTypeExtension.php#L36-L46 |
14,510 | leongkui/silex-php-redis | src/SilexPhpRedis/RedisClientProvider.php | RedisClientProvider.getClientInitializer | protected function getClientInitializer(Application $app, $prefix)
{
return $app->protect(function ($args) use ($app, $prefix) {
$extract = function ($bag, $key) use ($app, $prefix) {
$default = "default_$key";
if ($bag instanceof Application) {
$key = "$prefix.$key";
var_dump($key);
}
if (!isset($bag[$key])) {
return $app["$prefix.$default"];
}
if (is_array($bag[$key])) {
return array_merge($app["$prefix.$default"], $bag[$key]);
}
return $bag[$key];
};
if (isset($args['parameters']) && is_string($args['parameters'])) {
$args['parameters'] = $app["$prefix.uri_parser"]($args['parameters']);
}
$parameters = $extract($args, 'parameters');
$options = $extract($args, 'options');
return $app["$prefix.client_constructor"]($parameters, $options);
});
} | php | protected function getClientInitializer(Application $app, $prefix)
{
return $app->protect(function ($args) use ($app, $prefix) {
$extract = function ($bag, $key) use ($app, $prefix) {
$default = "default_$key";
if ($bag instanceof Application) {
$key = "$prefix.$key";
var_dump($key);
}
if (!isset($bag[$key])) {
return $app["$prefix.$default"];
}
if (is_array($bag[$key])) {
return array_merge($app["$prefix.$default"], $bag[$key]);
}
return $bag[$key];
};
if (isset($args['parameters']) && is_string($args['parameters'])) {
$args['parameters'] = $app["$prefix.uri_parser"]($args['parameters']);
}
$parameters = $extract($args, 'parameters');
$options = $extract($args, 'options');
return $app["$prefix.client_constructor"]($parameters, $options);
});
} | [
"protected",
"function",
"getClientInitializer",
"(",
"Application",
"$",
"app",
",",
"$",
"prefix",
")",
"{",
"return",
"$",
"app",
"->",
"protect",
"(",
"function",
"(",
"$",
"args",
")",
"use",
"(",
"$",
"app",
",",
"$",
"prefix",
")",
"{",
"$",
"extract",
"=",
"function",
"(",
"$",
"bag",
",",
"$",
"key",
")",
"use",
"(",
"$",
"app",
",",
"$",
"prefix",
")",
"{",
"$",
"default",
"=",
"\"default_$key\"",
";",
"if",
"(",
"$",
"bag",
"instanceof",
"Application",
")",
"{",
"$",
"key",
"=",
"\"$prefix.$key\"",
";",
"var_dump",
"(",
"$",
"key",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"bag",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"app",
"[",
"\"$prefix.$default\"",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"bag",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"array_merge",
"(",
"$",
"app",
"[",
"\"$prefix.$default\"",
"]",
",",
"$",
"bag",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"$",
"bag",
"[",
"$",
"key",
"]",
";",
"}",
";",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'parameters'",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"'parameters'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'parameters'",
"]",
"=",
"$",
"app",
"[",
"\"$prefix.uri_parser\"",
"]",
"(",
"$",
"args",
"[",
"'parameters'",
"]",
")",
";",
"}",
"$",
"parameters",
"=",
"$",
"extract",
"(",
"$",
"args",
",",
"'parameters'",
")",
";",
"$",
"options",
"=",
"$",
"extract",
"(",
"$",
"args",
",",
"'options'",
")",
";",
"return",
"$",
"app",
"[",
"\"$prefix.client_constructor\"",
"]",
"(",
"$",
"parameters",
",",
"$",
"options",
")",
";",
"}",
")",
";",
"}"
]
| Returns an anonymous function used by the service provider initialize
lazily new instances of Redis\Client.
@param Application $app
@param string $prefix
@return \Closure | [
"Returns",
"an",
"anonymous",
"function",
"used",
"by",
"the",
"service",
"provider",
"initialize",
"lazily",
"new",
"instances",
"of",
"Redis",
"\\",
"Client",
"."
]
| 65fb4f52077fc75a9e134db7888683f07dd3583d | https://github.com/leongkui/silex-php-redis/blob/65fb4f52077fc75a9e134db7888683f07dd3583d/src/SilexPhpRedis/RedisClientProvider.php#L43-L68 |
14,511 | RinkAttendant6/JsonI18n | src/Resource.php | Resource.fromJson | public static function fromJson(string $json): self
{
$input = json_decode($json, true);
$data = reset($input);
$locale = key($input);
return new self($locale, $data);
} | php | public static function fromJson(string $json): self
{
$input = json_decode($json, true);
$data = reset($input);
$locale = key($input);
return new self($locale, $data);
} | [
"public",
"static",
"function",
"fromJson",
"(",
"string",
"$",
"json",
")",
":",
"self",
"{",
"$",
"input",
"=",
"json_decode",
"(",
"$",
"json",
",",
"true",
")",
";",
"$",
"data",
"=",
"reset",
"(",
"$",
"input",
")",
";",
"$",
"locale",
"=",
"key",
"(",
"$",
"input",
")",
";",
"return",
"new",
"self",
"(",
"$",
"locale",
",",
"$",
"data",
")",
";",
"}"
]
| Factory method to create a translation resource from a JSON string
@param string $json
@return \self | [
"Factory",
"method",
"to",
"create",
"a",
"translation",
"resource",
"from",
"a",
"JSON",
"string"
]
| 882cbd43d273f771a384eb09d205d327033aaae3 | https://github.com/RinkAttendant6/JsonI18n/blob/882cbd43d273f771a384eb09d205d327033aaae3/src/Resource.php#L43-L50 |
14,512 | RinkAttendant6/JsonI18n | src/Resource.php | Resource.setLocale | private function setLocale(string $locale)
{
$arr = \Locale::parseLocale($locale);
if ($arr === false) {
throw new \InvalidArgumentException('Invalid locale');
}
$this->locale = $arr;
} | php | private function setLocale(string $locale)
{
$arr = \Locale::parseLocale($locale);
if ($arr === false) {
throw new \InvalidArgumentException('Invalid locale');
}
$this->locale = $arr;
} | [
"private",
"function",
"setLocale",
"(",
"string",
"$",
"locale",
")",
"{",
"$",
"arr",
"=",
"\\",
"Locale",
"::",
"parseLocale",
"(",
"$",
"locale",
")",
";",
"if",
"(",
"$",
"arr",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid locale'",
")",
";",
"}",
"$",
"this",
"->",
"locale",
"=",
"$",
"arr",
";",
"}"
]
| Sets the locale of the resource
@param string $locale The locale
@throws \InvalidArgumentException When provided with an invalid locale | [
"Sets",
"the",
"locale",
"of",
"the",
"resource"
]
| 882cbd43d273f771a384eb09d205d327033aaae3 | https://github.com/RinkAttendant6/JsonI18n/blob/882cbd43d273f771a384eb09d205d327033aaae3/src/Resource.php#L57-L66 |
14,513 | RinkAttendant6/JsonI18n | src/Resource.php | Resource.addData | public function addData(array $data, bool $overwrite = true): void
{
if ($overwrite) {
$this->data = array_merge($this->data, $data);
} else {
$this->data = array_merge($data, $this->data);
}
} | php | public function addData(array $data, bool $overwrite = true): void
{
if ($overwrite) {
$this->data = array_merge($this->data, $data);
} else {
$this->data = array_merge($data, $this->data);
}
} | [
"public",
"function",
"addData",
"(",
"array",
"$",
"data",
",",
"bool",
"$",
"overwrite",
"=",
"true",
")",
":",
"void",
"{",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"=",
"array_merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"data",
")",
";",
"}",
"}"
]
| Adds translation values to the resource
@param array $data Values to add
@param boolean $overwrite Whether the new array should overwrite already existing values | [
"Adds",
"translation",
"values",
"to",
"the",
"resource"
]
| 882cbd43d273f771a384eb09d205d327033aaae3 | https://github.com/RinkAttendant6/JsonI18n/blob/882cbd43d273f771a384eb09d205d327033aaae3/src/Resource.php#L91-L98 |
14,514 | RinkAttendant6/JsonI18n | src/Resource.php | Resource.merge | public function merge(self $resource, bool $overwrite = true): void
{
if ($this->getLocale() !== $resource->getLocale()) {
trigger_error('Attempting to merge resources of different locale', \E_USER_NOTICE);
}
$this->addData($resource->data, (bool) $overwrite);
} | php | public function merge(self $resource, bool $overwrite = true): void
{
if ($this->getLocale() !== $resource->getLocale()) {
trigger_error('Attempting to merge resources of different locale', \E_USER_NOTICE);
}
$this->addData($resource->data, (bool) $overwrite);
} | [
"public",
"function",
"merge",
"(",
"self",
"$",
"resource",
",",
"bool",
"$",
"overwrite",
"=",
"true",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"getLocale",
"(",
")",
"!==",
"$",
"resource",
"->",
"getLocale",
"(",
")",
")",
"{",
"trigger_error",
"(",
"'Attempting to merge resources of different locale'",
",",
"\\",
"E_USER_NOTICE",
")",
";",
"}",
"$",
"this",
"->",
"addData",
"(",
"$",
"resource",
"->",
"data",
",",
"(",
"bool",
")",
"$",
"overwrite",
")",
";",
"}"
]
| Merges a resource into the current resource
@param self $resource
@param boolean $overwrite Whether the new resource should overwrite already existing values | [
"Merges",
"a",
"resource",
"into",
"the",
"current",
"resource"
]
| 882cbd43d273f771a384eb09d205d327033aaae3 | https://github.com/RinkAttendant6/JsonI18n/blob/882cbd43d273f771a384eb09d205d327033aaae3/src/Resource.php#L114-L121 |
14,515 | RinkAttendant6/JsonI18n | src/Resource.php | Resource.jsonSerialize | public function jsonSerialize(): string
{
$output = array($this->getLocale() => $this->data);
return json_encode($output, JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG);
} | php | public function jsonSerialize(): string
{
$output = array($this->getLocale() => $this->data);
return json_encode($output, JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG);
} | [
"public",
"function",
"jsonSerialize",
"(",
")",
":",
"string",
"{",
"$",
"output",
"=",
"array",
"(",
"$",
"this",
"->",
"getLocale",
"(",
")",
"=>",
"$",
"this",
"->",
"data",
")",
";",
"return",
"json_encode",
"(",
"$",
"output",
",",
"JSON_HEX_AMP",
"|",
"JSON_HEX_APOS",
"|",
"JSON_HEX_QUOT",
"|",
"JSON_HEX_TAG",
")",
";",
"}"
]
| Serializes the resource into a JSON object
@return string | [
"Serializes",
"the",
"resource",
"into",
"a",
"JSON",
"object"
]
| 882cbd43d273f771a384eb09d205d327033aaae3 | https://github.com/RinkAttendant6/JsonI18n/blob/882cbd43d273f771a384eb09d205d327033aaae3/src/Resource.php#L165-L169 |
14,516 | comodojo/dispatcher.framework | src/Comodojo/Dispatcher/Cache/RouterCache.php | RouterCache.dump | public function dump($data, $ttl=null) {
return $this->getCache()
->setNamespace(self::CACHE_NAMESPACE)
->set(self::CACHE_NAME, $data, $ttl === null ? self::DEFAULTTTL : intval($ttl));
} | php | public function dump($data, $ttl=null) {
return $this->getCache()
->setNamespace(self::CACHE_NAMESPACE)
->set(self::CACHE_NAME, $data, $ttl === null ? self::DEFAULTTTL : intval($ttl));
} | [
"public",
"function",
"dump",
"(",
"$",
"data",
",",
"$",
"ttl",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"setNamespace",
"(",
"self",
"::",
"CACHE_NAMESPACE",
")",
"->",
"set",
"(",
"self",
"::",
"CACHE_NAME",
",",
"$",
"data",
",",
"$",
"ttl",
"===",
"null",
"?",
"self",
"::",
"DEFAULTTTL",
":",
"intval",
"(",
"$",
"ttl",
")",
")",
";",
"}"
]
| Store the routing table in cache
@return array $data
@return int $ttl
@return bool | [
"Store",
"the",
"routing",
"table",
"in",
"cache"
]
| 5093297dcb7441a8d8f79cbb2429c93232e16d1c | https://github.com/comodojo/dispatcher.framework/blob/5093297dcb7441a8d8f79cbb2429c93232e16d1c/src/Comodojo/Dispatcher/Cache/RouterCache.php#L59-L65 |
14,517 | braincrafted/arrayquery | src/Braincrafted/ArrayQuery/SelectEvaluation.php | SelectEvaluation.evaluate | public function evaluate($value, $filters)
{
if (false === is_array($filters)) {
$filters = [ $filters ];
}
foreach ($filters as $filter) {
$value = $this->evaluateFilter($value, $filter);
}
return $value;
} | php | public function evaluate($value, $filters)
{
if (false === is_array($filters)) {
$filters = [ $filters ];
}
foreach ($filters as $filter) {
$value = $this->evaluateFilter($value, $filter);
}
return $value;
} | [
"public",
"function",
"evaluate",
"(",
"$",
"value",
",",
"$",
"filters",
")",
"{",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"filters",
")",
")",
"{",
"$",
"filters",
"=",
"[",
"$",
"filters",
"]",
";",
"}",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"evaluateFilter",
"(",
"$",
"value",
",",
"$",
"filter",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
]
| Evaluates the given value with the given filters.
@param mixed $value The value.
@param array $filters The list of filters to apply.
@return mixed The evaluated value.
@throws Braincrafted\ArrayQuery\Exception\UnkownFilterException if a filter does not exist. | [
"Evaluates",
"the",
"given",
"value",
"with",
"the",
"given",
"filters",
"."
]
| 8b0c44ee76cea796589422f52e2f7130676b9bd1 | https://github.com/braincrafted/arrayquery/blob/8b0c44ee76cea796589422f52e2f7130676b9bd1/src/Braincrafted/ArrayQuery/SelectEvaluation.php#L53-L64 |
14,518 | codeburnerframework/router | src/Collectors/ControllerCollectorTrait.php | ControllerCollectorTrait.controllers | public function controllers(array $controllers)
{
$group = new Group;
foreach ($controllers as $controller)
$group->set($this->controller($controller));
return $group;
} | php | public function controllers(array $controllers)
{
$group = new Group;
foreach ($controllers as $controller)
$group->set($this->controller($controller));
return $group;
} | [
"public",
"function",
"controllers",
"(",
"array",
"$",
"controllers",
")",
"{",
"$",
"group",
"=",
"new",
"Group",
";",
"foreach",
"(",
"$",
"controllers",
"as",
"$",
"controller",
")",
"$",
"group",
"->",
"set",
"(",
"$",
"this",
"->",
"controller",
"(",
"$",
"controller",
")",
")",
";",
"return",
"$",
"group",
";",
"}"
]
| Maps several controllers at same time.
@param string[] $controllers Controllers name.
@throws \ReflectionException
@return Group | [
"Maps",
"several",
"controllers",
"at",
"same",
"time",
"."
]
| 2b0e8030303dd08d3fadfc4c57aa37b184a408cd | https://github.com/codeburnerframework/router/blob/2b0e8030303dd08d3fadfc4c57aa37b184a408cd/src/Collectors/ControllerCollectorTrait.php#L82-L88 |
14,519 | activecollab/databasestructure | src/Builder/StructureSql.php | StructureSql.appendToStructureSql | public function appendToStructureSql($statement, $comment = '')
{
if ($structure_sql_path = $this->getStructureSqlPath()) {
$current_content = file_get_contents($structure_sql_path);
if ($current_content) {
$current_content .= "\n\n\n\n";
}
if ($comment) {
$current_content .= "# $comment\n";
}
file_put_contents($structure_sql_path, $current_content . $statement);
}
} | php | public function appendToStructureSql($statement, $comment = '')
{
if ($structure_sql_path = $this->getStructureSqlPath()) {
$current_content = file_get_contents($structure_sql_path);
if ($current_content) {
$current_content .= "\n\n\n\n";
}
if ($comment) {
$current_content .= "# $comment\n";
}
file_put_contents($structure_sql_path, $current_content . $statement);
}
} | [
"public",
"function",
"appendToStructureSql",
"(",
"$",
"statement",
",",
"$",
"comment",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"structure_sql_path",
"=",
"$",
"this",
"->",
"getStructureSqlPath",
"(",
")",
")",
"{",
"$",
"current_content",
"=",
"file_get_contents",
"(",
"$",
"structure_sql_path",
")",
";",
"if",
"(",
"$",
"current_content",
")",
"{",
"$",
"current_content",
".=",
"\"\\n\\n\\n\\n\"",
";",
"}",
"if",
"(",
"$",
"comment",
")",
"{",
"$",
"current_content",
".=",
"\"# $comment\\n\"",
";",
"}",
"file_put_contents",
"(",
"$",
"structure_sql_path",
",",
"$",
"current_content",
".",
"$",
"statement",
")",
";",
"}",
"}"
]
| Append statement to SQL file.
@param string $statement
@param string $comment | [
"Append",
"statement",
"to",
"SQL",
"file",
"."
]
| 4b2353c4422186bcfce63b3212da3e70e63eb5df | https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Builder/StructureSql.php#L32-L47 |
14,520 | codeburnerframework/router | src/Collector.php | Collector.match | public function match(array $methods, $pattern, $action)
{
$group = new Group;
foreach ($methods as $method)
$group->set($this->set($method, $pattern, $action));
return $group;
} | php | public function match(array $methods, $pattern, $action)
{
$group = new Group;
foreach ($methods as $method)
$group->set($this->set($method, $pattern, $action));
return $group;
} | [
"public",
"function",
"match",
"(",
"array",
"$",
"methods",
",",
"$",
"pattern",
",",
"$",
"action",
")",
"{",
"$",
"group",
"=",
"new",
"Group",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"$",
"group",
"->",
"set",
"(",
"$",
"this",
"->",
"set",
"(",
"$",
"method",
",",
"$",
"pattern",
",",
"$",
"action",
")",
")",
";",
"return",
"$",
"group",
";",
"}"
]
| Insert a route into several http methods.
@param string[] $methods
@param string $pattern
@param callable $action
@return Group | [
"Insert",
"a",
"route",
"into",
"several",
"http",
"methods",
"."
]
| 2b0e8030303dd08d3fadfc4c57aa37b184a408cd | https://github.com/codeburnerframework/router/blob/2b0e8030303dd08d3fadfc4c57aa37b184a408cd/src/Collector.php#L143-L149 |
14,521 | codeburnerframework/router | src/Collector.php | Collector.any | public function any($pattern, $action)
{
return $this->match(explode(" ", self::HTTP_METHODS), $pattern, $action);
} | php | public function any($pattern, $action)
{
return $this->match(explode(" ", self::HTTP_METHODS), $pattern, $action);
} | [
"public",
"function",
"any",
"(",
"$",
"pattern",
",",
"$",
"action",
")",
"{",
"return",
"$",
"this",
"->",
"match",
"(",
"explode",
"(",
"\" \"",
",",
"self",
"::",
"HTTP_METHODS",
")",
",",
"$",
"pattern",
",",
"$",
"action",
")",
";",
"}"
]
| Insert a route into every http method supported.
@param string $pattern
@param callable $action
@return Group | [
"Insert",
"a",
"route",
"into",
"every",
"http",
"method",
"supported",
"."
]
| 2b0e8030303dd08d3fadfc4c57aa37b184a408cd | https://github.com/codeburnerframework/router/blob/2b0e8030303dd08d3fadfc4c57aa37b184a408cd/src/Collector.php#L160-L163 |
14,522 | codeburnerframework/router | src/Collector.php | Collector.except | public function except($methods, $pattern, $action)
{
return $this->match(array_diff(explode(" ", self::HTTP_METHODS), (array) $methods), $pattern, $action);
} | php | public function except($methods, $pattern, $action)
{
return $this->match(array_diff(explode(" ", self::HTTP_METHODS), (array) $methods), $pattern, $action);
} | [
"public",
"function",
"except",
"(",
"$",
"methods",
",",
"$",
"pattern",
",",
"$",
"action",
")",
"{",
"return",
"$",
"this",
"->",
"match",
"(",
"array_diff",
"(",
"explode",
"(",
"\" \"",
",",
"self",
"::",
"HTTP_METHODS",
")",
",",
"(",
"array",
")",
"$",
"methods",
")",
",",
"$",
"pattern",
",",
"$",
"action",
")",
";",
"}"
]
| Insert a route into every http method supported but the given ones.
@param string $methods
@param string $pattern
@param callable $action
@return Group | [
"Insert",
"a",
"route",
"into",
"every",
"http",
"method",
"supported",
"but",
"the",
"given",
"ones",
"."
]
| 2b0e8030303dd08d3fadfc4c57aa37b184a408cd | https://github.com/codeburnerframework/router/blob/2b0e8030303dd08d3fadfc4c57aa37b184a408cd/src/Collector.php#L175-L178 |
14,523 | codeburnerframework/router | src/Collector.php | Collector.group | public function group(array $routes)
{
$group = new Group;
foreach ($routes as $route)
$group->set($route);
return $group;
} | php | public function group(array $routes)
{
$group = new Group;
foreach ($routes as $route)
$group->set($route);
return $group;
} | [
"public",
"function",
"group",
"(",
"array",
"$",
"routes",
")",
"{",
"$",
"group",
"=",
"new",
"Group",
";",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"route",
")",
"$",
"group",
"->",
"set",
"(",
"$",
"route",
")",
";",
"return",
"$",
"group",
";",
"}"
]
| Group all given routes.
@param Route[] $routes
@return Group | [
"Group",
"all",
"given",
"routes",
"."
]
| 2b0e8030303dd08d3fadfc4c57aa37b184a408cd | https://github.com/codeburnerframework/router/blob/2b0e8030303dd08d3fadfc4c57aa37b184a408cd/src/Collector.php#L187-L193 |
14,524 | codeburnerframework/router | src/Collector.php | Collector.forget | public function forget($method, $pattern)
{
if (strpos($pattern, "{") === false) {
unset($this->statics[$method][$pattern]);
} else unset($this->dynamics[$this->getDynamicIndex($method, $pattern)][$pattern]);
} | php | public function forget($method, $pattern)
{
if (strpos($pattern, "{") === false) {
unset($this->statics[$method][$pattern]);
} else unset($this->dynamics[$this->getDynamicIndex($method, $pattern)][$pattern]);
} | [
"public",
"function",
"forget",
"(",
"$",
"method",
",",
"$",
"pattern",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"pattern",
",",
"\"{\"",
")",
"===",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"statics",
"[",
"$",
"method",
"]",
"[",
"$",
"pattern",
"]",
")",
";",
"}",
"else",
"unset",
"(",
"$",
"this",
"->",
"dynamics",
"[",
"$",
"this",
"->",
"getDynamicIndex",
"(",
"$",
"method",
",",
"$",
"pattern",
")",
"]",
"[",
"$",
"pattern",
"]",
")",
";",
"}"
]
| Remove a route from collector.
@param string $method
@param string $pattern | [
"Remove",
"a",
"route",
"from",
"collector",
"."
]
| 2b0e8030303dd08d3fadfc4c57aa37b184a408cd | https://github.com/codeburnerframework/router/blob/2b0e8030303dd08d3fadfc4c57aa37b184a408cd/src/Collector.php#L202-L207 |
14,525 | codeburnerframework/router | src/Collector.php | Collector.getValidMethod | protected function getValidMethod($method)
{
$method = strtolower($method);
if (strpos(self::HTTP_METHODS, $method) === false) {
throw new MethodNotSupportedException($method);
}
return $method;
} | php | protected function getValidMethod($method)
{
$method = strtolower($method);
if (strpos(self::HTTP_METHODS, $method) === false) {
throw new MethodNotSupportedException($method);
}
return $method;
} | [
"protected",
"function",
"getValidMethod",
"(",
"$",
"method",
")",
"{",
"$",
"method",
"=",
"strtolower",
"(",
"$",
"method",
")",
";",
"if",
"(",
"strpos",
"(",
"self",
"::",
"HTTP_METHODS",
",",
"$",
"method",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"MethodNotSupportedException",
"(",
"$",
"method",
")",
";",
"}",
"return",
"$",
"method",
";",
"}"
]
| Determine if the http method is valid.
@param string $method
@throws MethodNotSupportedException
@return string | [
"Determine",
"if",
"the",
"http",
"method",
"is",
"valid",
"."
]
| 2b0e8030303dd08d3fadfc4c57aa37b184a408cd | https://github.com/codeburnerframework/router/blob/2b0e8030303dd08d3fadfc4c57aa37b184a408cd/src/Collector.php#L270-L279 |
14,526 | axelitus/php-base | src/Traverser.php | Traverser.traverse | final public function traverse(array &$arr)
{
if (!$this->isReady()) {
throw new \RuntimeException("The traverser is not ready, no valid item callback has been set.");
}
return static::run($arr, $this->itemCallback, $this->resultCallback);
} | php | final public function traverse(array &$arr)
{
if (!$this->isReady()) {
throw new \RuntimeException("The traverser is not ready, no valid item callback has been set.");
}
return static::run($arr, $this->itemCallback, $this->resultCallback);
} | [
"final",
"public",
"function",
"traverse",
"(",
"array",
"&",
"$",
"arr",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isReady",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"The traverser is not ready, no valid item callback has been set.\"",
")",
";",
"}",
"return",
"static",
"::",
"run",
"(",
"$",
"arr",
",",
"$",
"this",
"->",
"itemCallback",
",",
"$",
"this",
"->",
"resultCallback",
")",
";",
"}"
]
| Runs the given array through the Traverser's callbacks.
@param array $arr The array to traverse.
@return array Returns the resulting array. | [
"Runs",
"the",
"given",
"array",
"through",
"the",
"Traverser",
"s",
"callbacks",
"."
]
| c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075 | https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Traverser.php#L132-L139 |
14,527 | axelitus/php-base | src/Traverser.php | Traverser.run | public static function run(array &$arr, callable $itemCallback, callable $resultCallback = null)
{
$result = [];
foreach ($arr as $key => &$value) {
// Run the callback and store the result in a variable so that we allow the key to be modified by the
// callback. Also pass the original array if one needs to unset variables from the original array.
$r = $itemCallback($value, $key, $arr);
// Store the item callback's result with the (new) key.
$result[$key] = $r;
}
if (!is_null($resultCallback)) {
// Allow for the original array to be modified with the result array.
return $resultCallback($result, $arr);
}
return $result;
} | php | public static function run(array &$arr, callable $itemCallback, callable $resultCallback = null)
{
$result = [];
foreach ($arr as $key => &$value) {
// Run the callback and store the result in a variable so that we allow the key to be modified by the
// callback. Also pass the original array if one needs to unset variables from the original array.
$r = $itemCallback($value, $key, $arr);
// Store the item callback's result with the (new) key.
$result[$key] = $r;
}
if (!is_null($resultCallback)) {
// Allow for the original array to be modified with the result array.
return $resultCallback($result, $arr);
}
return $result;
} | [
"public",
"static",
"function",
"run",
"(",
"array",
"&",
"$",
"arr",
",",
"callable",
"$",
"itemCallback",
",",
"callable",
"$",
"resultCallback",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"// Run the callback and store the result in a variable so that we allow the key to be modified by the",
"// callback. Also pass the original array if one needs to unset variables from the original array.",
"$",
"r",
"=",
"$",
"itemCallback",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"arr",
")",
";",
"// Store the item callback's result with the (new) key.",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"r",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"resultCallback",
")",
")",
"{",
"// Allow for the original array to be modified with the result array.",
"return",
"$",
"resultCallback",
"(",
"$",
"result",
",",
"$",
"arr",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Runs the traverser across the given array and executes the item callback into every item of the array.
The traverser also has a result callback to allow for 'macro' result processing.
@param array $arr The array to traverse.
@param callable $itemCallback The item callback to operate into every item.
Callback signature used:
- array function($value, $key, $arr) { }
@param callable $resultCallback The result callback to operate into the result array.
Callback signature used:
- mixed function($resultArray, $originalArray) { }
@return array Returns the resulting array. | [
"Runs",
"the",
"traverser",
"across",
"the",
"given",
"array",
"and",
"executes",
"the",
"item",
"callback",
"into",
"every",
"item",
"of",
"the",
"array",
"."
]
| c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075 | https://github.com/axelitus/php-base/blob/c2da680c1f0c3ee93ae6a8be5adaacd0caf7d075/src/Traverser.php#L156-L174 |
14,528 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/CoreBundle/Pricing/ItemPriceCalculator.php | ItemPriceCalculator.getValidProductPriceForItem | private function getValidProductPriceForItem($item, $currency)
{
$product = $item->getCalcProduct();
$specialPriceValue = null;
$bulkPriceValue = null;
//get special price
$specialPrice = $this->priceManager->getSpecialPriceForCurrency($product, $currency);
if ($specialPrice) {
$specialPriceValue = $specialPrice->getPrice();
}
//get bulk price
$bulkPrice = $this->priceManager->getBulkPriceForCurrency($product, $item->getCalcQuantity(), $currency);
if ($bulkPrice) {
$bulkPriceValue = $bulkPrice->getPrice();
}
//take the smallest
if(!empty($specialPriceValue) && !empty($bulkPriceValue)) {
$priceValue = $specialPriceValue;
if ($specialPriceValue > $bulkPriceValue) {
$priceValue = $bulkPriceValue;
}
} elseif (!empty($specialPriceValue)) {
$priceValue = $specialPriceValue;
} else {
$priceValue = $bulkPriceValue;
}
// no price set - return 0
if (empty($priceValue)) {
return 0;
}
return $priceValue;
} | php | private function getValidProductPriceForItem($item, $currency)
{
$product = $item->getCalcProduct();
$specialPriceValue = null;
$bulkPriceValue = null;
//get special price
$specialPrice = $this->priceManager->getSpecialPriceForCurrency($product, $currency);
if ($specialPrice) {
$specialPriceValue = $specialPrice->getPrice();
}
//get bulk price
$bulkPrice = $this->priceManager->getBulkPriceForCurrency($product, $item->getCalcQuantity(), $currency);
if ($bulkPrice) {
$bulkPriceValue = $bulkPrice->getPrice();
}
//take the smallest
if(!empty($specialPriceValue) && !empty($bulkPriceValue)) {
$priceValue = $specialPriceValue;
if ($specialPriceValue > $bulkPriceValue) {
$priceValue = $bulkPriceValue;
}
} elseif (!empty($specialPriceValue)) {
$priceValue = $specialPriceValue;
} else {
$priceValue = $bulkPriceValue;
}
// no price set - return 0
if (empty($priceValue)) {
return 0;
}
return $priceValue;
} | [
"private",
"function",
"getValidProductPriceForItem",
"(",
"$",
"item",
",",
"$",
"currency",
")",
"{",
"$",
"product",
"=",
"$",
"item",
"->",
"getCalcProduct",
"(",
")",
";",
"$",
"specialPriceValue",
"=",
"null",
";",
"$",
"bulkPriceValue",
"=",
"null",
";",
"//get special price",
"$",
"specialPrice",
"=",
"$",
"this",
"->",
"priceManager",
"->",
"getSpecialPriceForCurrency",
"(",
"$",
"product",
",",
"$",
"currency",
")",
";",
"if",
"(",
"$",
"specialPrice",
")",
"{",
"$",
"specialPriceValue",
"=",
"$",
"specialPrice",
"->",
"getPrice",
"(",
")",
";",
"}",
"//get bulk price",
"$",
"bulkPrice",
"=",
"$",
"this",
"->",
"priceManager",
"->",
"getBulkPriceForCurrency",
"(",
"$",
"product",
",",
"$",
"item",
"->",
"getCalcQuantity",
"(",
")",
",",
"$",
"currency",
")",
";",
"if",
"(",
"$",
"bulkPrice",
")",
"{",
"$",
"bulkPriceValue",
"=",
"$",
"bulkPrice",
"->",
"getPrice",
"(",
")",
";",
"}",
"//take the smallest",
"if",
"(",
"!",
"empty",
"(",
"$",
"specialPriceValue",
")",
"&&",
"!",
"empty",
"(",
"$",
"bulkPriceValue",
")",
")",
"{",
"$",
"priceValue",
"=",
"$",
"specialPriceValue",
";",
"if",
"(",
"$",
"specialPriceValue",
">",
"$",
"bulkPriceValue",
")",
"{",
"$",
"priceValue",
"=",
"$",
"bulkPriceValue",
";",
"}",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"specialPriceValue",
")",
")",
"{",
"$",
"priceValue",
"=",
"$",
"specialPriceValue",
";",
"}",
"else",
"{",
"$",
"priceValue",
"=",
"$",
"bulkPriceValue",
";",
"}",
"// no price set - return 0",
"if",
"(",
"empty",
"(",
"$",
"priceValue",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"priceValue",
";",
"}"
]
| Returns the valid product price for item
@param object $item
@param string $currency
@return int | [
"Returns",
"the",
"valid",
"product",
"price",
"for",
"item"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/CoreBundle/Pricing/ItemPriceCalculator.php#L41-L77 |
14,529 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/CoreBundle/Pricing/ItemPriceCalculator.php | ItemPriceCalculator.calculate | public function calculate($item, $currency = null, $useProductsPrice = true)
{
$currency = $this->getCurrency($currency);
// validate item
$this->validateItem($item);
if ($useProductsPrice) {
$priceValue = $this->getValidProductPriceForItem($item, $currency);
} else {
$priceValue = $item->getPrice();
}
$this->validateNotNull('price', $priceValue);
if ($item->getPrice() && $item->getPrice() !== $priceValue) {
$item->setPriceChange($item->getPrice(), $priceValue);
}
$itemPrice = $priceValue * $item->getCalcQuantity();
// calculate items discount
$discount = ($itemPrice / 100) * $item->getCalcDiscount();
// calculate total item price
$totalPrice = $itemPrice - $discount;
return $totalPrice;
} | php | public function calculate($item, $currency = null, $useProductsPrice = true)
{
$currency = $this->getCurrency($currency);
// validate item
$this->validateItem($item);
if ($useProductsPrice) {
$priceValue = $this->getValidProductPriceForItem($item, $currency);
} else {
$priceValue = $item->getPrice();
}
$this->validateNotNull('price', $priceValue);
if ($item->getPrice() && $item->getPrice() !== $priceValue) {
$item->setPriceChange($item->getPrice(), $priceValue);
}
$itemPrice = $priceValue * $item->getCalcQuantity();
// calculate items discount
$discount = ($itemPrice / 100) * $item->getCalcDiscount();
// calculate total item price
$totalPrice = $itemPrice - $discount;
return $totalPrice;
} | [
"public",
"function",
"calculate",
"(",
"$",
"item",
",",
"$",
"currency",
"=",
"null",
",",
"$",
"useProductsPrice",
"=",
"true",
")",
"{",
"$",
"currency",
"=",
"$",
"this",
"->",
"getCurrency",
"(",
"$",
"currency",
")",
";",
"// validate item",
"$",
"this",
"->",
"validateItem",
"(",
"$",
"item",
")",
";",
"if",
"(",
"$",
"useProductsPrice",
")",
"{",
"$",
"priceValue",
"=",
"$",
"this",
"->",
"getValidProductPriceForItem",
"(",
"$",
"item",
",",
"$",
"currency",
")",
";",
"}",
"else",
"{",
"$",
"priceValue",
"=",
"$",
"item",
"->",
"getPrice",
"(",
")",
";",
"}",
"$",
"this",
"->",
"validateNotNull",
"(",
"'price'",
",",
"$",
"priceValue",
")",
";",
"if",
"(",
"$",
"item",
"->",
"getPrice",
"(",
")",
"&&",
"$",
"item",
"->",
"getPrice",
"(",
")",
"!==",
"$",
"priceValue",
")",
"{",
"$",
"item",
"->",
"setPriceChange",
"(",
"$",
"item",
"->",
"getPrice",
"(",
")",
",",
"$",
"priceValue",
")",
";",
"}",
"$",
"itemPrice",
"=",
"$",
"priceValue",
"*",
"$",
"item",
"->",
"getCalcQuantity",
"(",
")",
";",
"// calculate items discount",
"$",
"discount",
"=",
"(",
"$",
"itemPrice",
"/",
"100",
")",
"*",
"$",
"item",
"->",
"getCalcDiscount",
"(",
")",
";",
"// calculate total item price",
"$",
"totalPrice",
"=",
"$",
"itemPrice",
"-",
"$",
"discount",
";",
"return",
"$",
"totalPrice",
";",
"}"
]
| Calculates the overall total price of an item
@param CalculableBulkPriceItemInterface $item
@param string|null $currency
@param bool|null $useProductsPrice
@return int
@throws PriceCalculationException | [
"Calculates",
"the",
"overall",
"total",
"price",
"of",
"an",
"item"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/CoreBundle/Pricing/ItemPriceCalculator.php#L89-L116 |
14,530 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/CoreBundle/Pricing/ItemPriceCalculator.php | ItemPriceCalculator.validateItem | protected function validateItem($item)
{
// validate not null
$this->validateNotNull('quantity', $item->getCalcQuantity());
// validate discount
$discountPercent = $item->getCalcDiscount();
if ($discountPercent < 0 || $discountPercent > 100) {
throw new PriceCalculationException('Discount must be within 0 and 100 percent');
}
} | php | protected function validateItem($item)
{
// validate not null
$this->validateNotNull('quantity', $item->getCalcQuantity());
// validate discount
$discountPercent = $item->getCalcDiscount();
if ($discountPercent < 0 || $discountPercent > 100) {
throw new PriceCalculationException('Discount must be within 0 and 100 percent');
}
} | [
"protected",
"function",
"validateItem",
"(",
"$",
"item",
")",
"{",
"// validate not null",
"$",
"this",
"->",
"validateNotNull",
"(",
"'quantity'",
",",
"$",
"item",
"->",
"getCalcQuantity",
"(",
")",
")",
";",
"// validate discount",
"$",
"discountPercent",
"=",
"$",
"item",
"->",
"getCalcDiscount",
"(",
")",
";",
"if",
"(",
"$",
"discountPercent",
"<",
"0",
"||",
"$",
"discountPercent",
">",
"100",
")",
"{",
"throw",
"new",
"PriceCalculationException",
"(",
"'Discount must be within 0 and 100 percent'",
")",
";",
"}",
"}"
]
| Validate item values
@param $item
@throws PriceCalculationException | [
"Validate",
"item",
"values"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/CoreBundle/Pricing/ItemPriceCalculator.php#L139-L149 |
14,531 | discophp/framework | core/twig/tag/CacheNode.php | CacheNode.duration | private function duration($time){
if(is_numeric($time)){
return $time;
}//if
return (new \DateTime($time))->getTimestamp() - (new \DateTime('now'))->getTimestamp();
} | php | private function duration($time){
if(is_numeric($time)){
return $time;
}//if
return (new \DateTime($time))->getTimestamp() - (new \DateTime('now'))->getTimestamp();
} | [
"private",
"function",
"duration",
"(",
"$",
"time",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"time",
")",
")",
"{",
"return",
"$",
"time",
";",
"}",
"//if",
"return",
"(",
"new",
"\\",
"DateTime",
"(",
"$",
"time",
")",
")",
"->",
"getTimestamp",
"(",
")",
"-",
"(",
"new",
"\\",
"DateTime",
"(",
"'now'",
")",
")",
"->",
"getTimestamp",
"(",
")",
";",
"}"
]
| Convert a potential string date like `+30 days` to seconds.
@param int|string
@return int | [
"Convert",
"a",
"potential",
"string",
"date",
"like",
"+",
"30",
"days",
"to",
"seconds",
"."
]
| 40ff3ea5225810534195494dc6c21083da4d1356 | https://github.com/discophp/framework/blob/40ff3ea5225810534195494dc6c21083da4d1356/core/twig/tag/CacheNode.php#L115-L120 |
14,532 | baleen/cli | src/BaseCommand.php | BaseCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var MessageInterface $message */
$message = $this->getContainer()->get($this->serviceAlias);
if (get_class($message) !== $this->serviceClass) {
throw new InvalidArgumentException(sprintf(
'The specified service alias (%s) and class (%s) do not correspond to each other.',
$this->serviceAlias,
$this->serviceClass
));
}
$message->setCliCommand($this);
$message->setInput($input);
$message->setOutput($output);
$this->getCommandBus()->handle($message);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var MessageInterface $message */
$message = $this->getContainer()->get($this->serviceAlias);
if (get_class($message) !== $this->serviceClass) {
throw new InvalidArgumentException(sprintf(
'The specified service alias (%s) and class (%s) do not correspond to each other.',
$this->serviceAlias,
$this->serviceClass
));
}
$message->setCliCommand($this);
$message->setInput($input);
$message->setOutput($output);
$this->getCommandBus()->handle($message);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"/** @var MessageInterface $message */",
"$",
"message",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"serviceAlias",
")",
";",
"if",
"(",
"get_class",
"(",
"$",
"message",
")",
"!==",
"$",
"this",
"->",
"serviceClass",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The specified service alias (%s) and class (%s) do not correspond to each other.'",
",",
"$",
"this",
"->",
"serviceAlias",
",",
"$",
"this",
"->",
"serviceClass",
")",
")",
";",
"}",
"$",
"message",
"->",
"setCliCommand",
"(",
"$",
"this",
")",
";",
"$",
"message",
"->",
"setInput",
"(",
"$",
"input",
")",
";",
"$",
"message",
"->",
"setOutput",
"(",
"$",
"output",
")",
";",
"$",
"this",
"->",
"getCommandBus",
"(",
")",
"->",
"handle",
"(",
"$",
"message",
")",
";",
"}"
]
| Executes the current command by retrieving its associated Message from the Container, setting the Input and
Output according to what was received as parameters, and finally passing that Message to the CommandBus for
handling.
@param InputInterface $input An InputInterface instance
@param OutputInterface $output An OutputInterface instance
@return int|null null or 0 if everything went fine, or an error code
@throws InvalidArgumentException | [
"Executes",
"the",
"current",
"command",
"by",
"retrieving",
"its",
"associated",
"Message",
"from",
"the",
"Container",
"setting",
"the",
"Input",
"and",
"Output",
"according",
"to",
"what",
"was",
"received",
"as",
"parameters",
"and",
"finally",
"passing",
"that",
"Message",
"to",
"the",
"CommandBus",
"for",
"handling",
"."
]
| 2ecbc7179c5800c9075fd93204ef25da375536ed | https://github.com/baleen/cli/blob/2ecbc7179c5800c9075fd93204ef25da375536ed/src/BaseCommand.php#L124-L141 |
14,533 | TypistTech/wp-option-store | src/OptionStore.php | OptionStore.getBoolean | public function getBoolean(string $optionName): bool
{
return in_array(
$this->get($optionName),
self::TRUE_VALUES,
true
);
} | php | public function getBoolean(string $optionName): bool
{
return in_array(
$this->get($optionName),
self::TRUE_VALUES,
true
);
} | [
"public",
"function",
"getBoolean",
"(",
"string",
"$",
"optionName",
")",
":",
"bool",
"{",
"return",
"in_array",
"(",
"$",
"this",
"->",
"get",
"(",
"$",
"optionName",
")",
",",
"self",
"::",
"TRUE_VALUES",
",",
"true",
")",
";",
"}"
]
| Cast an option value into boolean.
@param string $optionName Name of option to retrieve.
@return bool | [
"Cast",
"an",
"option",
"value",
"into",
"boolean",
"."
]
| 115ff7cb4b5f566c89c1294fe2b68c82d62cccc2 | https://github.com/TypistTech/wp-option-store/blob/115ff7cb4b5f566c89c1294fe2b68c82d62cccc2/src/OptionStore.php#L67-L74 |
14,534 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator.php | Calculator.convert | protected function convert($num)
{
if ($num instanceof NumericTypeInterface) {
return $num;
}
if (is_numeric($num)) {
return $this->calcEngine->convertNumeric($num);
}
$type = (is_object($num) ? get_class($num) : gettype($num));
throw new \BadMethodCallException('No solution for unknown type: ' . $type);
} | php | protected function convert($num)
{
if ($num instanceof NumericTypeInterface) {
return $num;
}
if (is_numeric($num)) {
return $this->calcEngine->convertNumeric($num);
}
$type = (is_object($num) ? get_class($num) : gettype($num));
throw new \BadMethodCallException('No solution for unknown type: ' . $type);
} | [
"protected",
"function",
"convert",
"(",
"$",
"num",
")",
"{",
"if",
"(",
"$",
"num",
"instanceof",
"NumericTypeInterface",
")",
"{",
"return",
"$",
"num",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"num",
")",
")",
"{",
"return",
"$",
"this",
"->",
"calcEngine",
"->",
"convertNumeric",
"(",
"$",
"num",
")",
";",
"}",
"$",
"type",
"=",
"(",
"is_object",
"(",
"$",
"num",
")",
"?",
"get_class",
"(",
"$",
"num",
")",
":",
"gettype",
"(",
"$",
"num",
")",
")",
";",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"'No solution for unknown type: '",
".",
"$",
"type",
")",
";",
"}"
]
| Convert into Strong Numeric Type
@param int|float|NumericTypeInterface $num operand
@return \Chippyash\Type\Number\IntType | [
"Convert",
"into",
"Strong",
"Numeric",
"Type"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator.php#L277-L288 |
14,535 | verschoof/bunq-api | src/Resource/CardResource.php | CardResource.getCard | public function getCard($userId, $cardId)
{
$card = $this->client->get($this->getResourceEndpoint($userId) . '/' . (int)$cardId);
return $card['Response'][0];
} | php | public function getCard($userId, $cardId)
{
$card = $this->client->get($this->getResourceEndpoint($userId) . '/' . (int)$cardId);
return $card['Response'][0];
} | [
"public",
"function",
"getCard",
"(",
"$",
"userId",
",",
"$",
"cardId",
")",
"{",
"$",
"card",
"=",
"$",
"this",
"->",
"client",
"->",
"get",
"(",
"$",
"this",
"->",
"getResourceEndpoint",
"(",
"$",
"userId",
")",
".",
"'/'",
".",
"(",
"int",
")",
"$",
"cardId",
")",
";",
"return",
"$",
"card",
"[",
"'Response'",
"]",
"[",
"0",
"]",
";",
"}"
]
| Gets a user its card information.
@param integer $userId
@param integer $cardId
@return array | [
"Gets",
"a",
"user",
"its",
"card",
"information",
"."
]
| df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd | https://github.com/verschoof/bunq-api/blob/df9aa19f384275f4f0deb26de0cb5e5f8b45ffcd/src/Resource/CardResource.php#L42-L47 |
14,536 | blast-project/CoreBundle | src/Doctrine/ORM/CascadingRelationChecker.php | CascadingRelationChecker.beforeEntityDelete | public function beforeEntityDelete($entity, &$idx)
{
$this->undeleteReasons = [];
$entityMetadata = $this->em->getClassMetadata(get_class($entity));
$associations = $entityMetadata->getAssociationMappings();
foreach ($associations as $association) {
if (in_array('remove', $association['cascade'])) {
continue; // Skip of cascading enabled
}
if (!in_array($association['type'], [ClassMetadata::ONE_TO_MANY])) {
continue; // Handling only _TO_MANY relations
}
$propertyAccessor = new PropertyAccessor();
$associationData = $propertyAccessor->getValue($entity, $association['fieldName']);
if ($associationData instanceof Collection) {
if ($associationData->count() > 0) {
$this->removeFromIdsArray($entityMetadata->getIdentifierValues($entity), $idx, $association);
}
} elseif ($associationData !== null) {
$this->removeFromIdsArray($entityMetadata->getIdentifierValues($entity), $idx, $association);
}
}
return $this->undeleteReasons;
} | php | public function beforeEntityDelete($entity, &$idx)
{
$this->undeleteReasons = [];
$entityMetadata = $this->em->getClassMetadata(get_class($entity));
$associations = $entityMetadata->getAssociationMappings();
foreach ($associations as $association) {
if (in_array('remove', $association['cascade'])) {
continue; // Skip of cascading enabled
}
if (!in_array($association['type'], [ClassMetadata::ONE_TO_MANY])) {
continue; // Handling only _TO_MANY relations
}
$propertyAccessor = new PropertyAccessor();
$associationData = $propertyAccessor->getValue($entity, $association['fieldName']);
if ($associationData instanceof Collection) {
if ($associationData->count() > 0) {
$this->removeFromIdsArray($entityMetadata->getIdentifierValues($entity), $idx, $association);
}
} elseif ($associationData !== null) {
$this->removeFromIdsArray($entityMetadata->getIdentifierValues($entity), $idx, $association);
}
}
return $this->undeleteReasons;
} | [
"public",
"function",
"beforeEntityDelete",
"(",
"$",
"entity",
",",
"&",
"$",
"idx",
")",
"{",
"$",
"this",
"->",
"undeleteReasons",
"=",
"[",
"]",
";",
"$",
"entityMetadata",
"=",
"$",
"this",
"->",
"em",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"entity",
")",
")",
";",
"$",
"associations",
"=",
"$",
"entityMetadata",
"->",
"getAssociationMappings",
"(",
")",
";",
"foreach",
"(",
"$",
"associations",
"as",
"$",
"association",
")",
"{",
"if",
"(",
"in_array",
"(",
"'remove'",
",",
"$",
"association",
"[",
"'cascade'",
"]",
")",
")",
"{",
"continue",
";",
"// Skip of cascading enabled",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"association",
"[",
"'type'",
"]",
",",
"[",
"ClassMetadata",
"::",
"ONE_TO_MANY",
"]",
")",
")",
"{",
"continue",
";",
"// Handling only _TO_MANY relations",
"}",
"$",
"propertyAccessor",
"=",
"new",
"PropertyAccessor",
"(",
")",
";",
"$",
"associationData",
"=",
"$",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"entity",
",",
"$",
"association",
"[",
"'fieldName'",
"]",
")",
";",
"if",
"(",
"$",
"associationData",
"instanceof",
"Collection",
")",
"{",
"if",
"(",
"$",
"associationData",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"removeFromIdsArray",
"(",
"$",
"entityMetadata",
"->",
"getIdentifierValues",
"(",
"$",
"entity",
")",
",",
"$",
"idx",
",",
"$",
"association",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"associationData",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"removeFromIdsArray",
"(",
"$",
"entityMetadata",
"->",
"getIdentifierValues",
"(",
"$",
"entity",
")",
",",
"$",
"idx",
",",
"$",
"association",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"undeleteReasons",
";",
"}"
]
| Hande entity relations before trying to remove it.
@param mixed $entity a Doctrine entity object
@param array $idx list of entity ids to be removed
@return | [
"Hande",
"entity",
"relations",
"before",
"trying",
"to",
"remove",
"it",
"."
]
| 7a0832758ca14e5bc5d65515532c1220df3930ae | https://github.com/blast-project/CoreBundle/blob/7a0832758ca14e5bc5d65515532c1220df3930ae/src/Doctrine/ORM/CascadingRelationChecker.php#L40-L70 |
14,537 | jenky/laravel-api-helper | src/Handler.php | Handler.getSupportedParams | protected function getSupportedParams($method)
{
$columns = [];
if ($this->isEloquentBuilder()) {
$model = $this->getHandler()->getModel();
$columns = in_array(ApiHelper::class, class_uses($model))
? $model->$method()
: $model->getFillable();
}
return $columns;
} | php | protected function getSupportedParams($method)
{
$columns = [];
if ($this->isEloquentBuilder()) {
$model = $this->getHandler()->getModel();
$columns = in_array(ApiHelper::class, class_uses($model))
? $model->$method()
: $model->getFillable();
}
return $columns;
} | [
"protected",
"function",
"getSupportedParams",
"(",
"$",
"method",
")",
"{",
"$",
"columns",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isEloquentBuilder",
"(",
")",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getHandler",
"(",
")",
"->",
"getModel",
"(",
")",
";",
"$",
"columns",
"=",
"in_array",
"(",
"ApiHelper",
"::",
"class",
",",
"class_uses",
"(",
"$",
"model",
")",
")",
"?",
"$",
"model",
"->",
"$",
"method",
"(",
")",
":",
"$",
"model",
"->",
"getFillable",
"(",
")",
";",
"}",
"return",
"$",
"columns",
";",
"}"
]
| Get supported params.
@param string $method
@return array | [
"Get",
"supported",
"params",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L126-L138 |
14,538 | jenky/laravel-api-helper | src/Handler.php | Handler.parse | protected function parse()
{
$this->parseParam('sort');
$this->parseParam('fields');
$this->parseParam('limit');
if ($this->isEloquentBuilder()) {
$this->parseParam('with');
}
$this->parseFilter();
} | php | protected function parse()
{
$this->parseParam('sort');
$this->parseParam('fields');
$this->parseParam('limit');
if ($this->isEloquentBuilder()) {
$this->parseParam('with');
}
$this->parseFilter();
} | [
"protected",
"function",
"parse",
"(",
")",
"{",
"$",
"this",
"->",
"parseParam",
"(",
"'sort'",
")",
";",
"$",
"this",
"->",
"parseParam",
"(",
"'fields'",
")",
";",
"$",
"this",
"->",
"parseParam",
"(",
"'limit'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isEloquentBuilder",
"(",
")",
")",
"{",
"$",
"this",
"->",
"parseParam",
"(",
"'with'",
")",
";",
"}",
"$",
"this",
"->",
"parseFilter",
"(",
")",
";",
"}"
]
| Parse the data from the request.
@return void | [
"Parse",
"the",
"data",
"from",
"the",
"request",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L175-L184 |
14,539 | jenky/laravel-api-helper | src/Handler.php | Handler.parseParam | protected function parseParam($param)
{
$method = 'parse'.ucfirst($param);
if (method_exists($this, $method)) {
if ($params = $this->input($param)) {
return $this->$method($params);
}
}
} | php | protected function parseParam($param)
{
$method = 'parse'.ucfirst($param);
if (method_exists($this, $method)) {
if ($params = $this->input($param)) {
return $this->$method($params);
}
}
} | [
"protected",
"function",
"parseParam",
"(",
"$",
"param",
")",
"{",
"$",
"method",
"=",
"'parse'",
".",
"ucfirst",
"(",
"$",
"param",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"if",
"(",
"$",
"params",
"=",
"$",
"this",
"->",
"input",
"(",
"$",
"param",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"params",
")",
";",
"}",
"}",
"}"
]
| Parse the special param.
@param string $param
@return void | [
"Parse",
"the",
"special",
"param",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L192-L201 |
14,540 | jenky/laravel-api-helper | src/Handler.php | Handler.parseSort | protected function parseSort($params)
{
foreach (explode(',', $params) as $sort) {
// Check if ascending or descending(-) sort
if (preg_match('/^-.+/', $sort)) {
$direction = 'desc';
} else {
$direction = 'asc';
}
$sort = preg_replace('/^-/', '', $sort);
if (! $this->canSort($sort)) {
return;
}
// Only add the sorts that are on the base resource
if (! Str::contains($sort, '.')) {
$this->getHandler()->orderBy($sort, $direction);
} else {
$this->additionalSorts[$sort] = $direction;
}
}
} | php | protected function parseSort($params)
{
foreach (explode(',', $params) as $sort) {
// Check if ascending or descending(-) sort
if (preg_match('/^-.+/', $sort)) {
$direction = 'desc';
} else {
$direction = 'asc';
}
$sort = preg_replace('/^-/', '', $sort);
if (! $this->canSort($sort)) {
return;
}
// Only add the sorts that are on the base resource
if (! Str::contains($sort, '.')) {
$this->getHandler()->orderBy($sort, $direction);
} else {
$this->additionalSorts[$sort] = $direction;
}
}
} | [
"protected",
"function",
"parseSort",
"(",
"$",
"params",
")",
"{",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"params",
")",
"as",
"$",
"sort",
")",
"{",
"// Check if ascending or descending(-) sort",
"if",
"(",
"preg_match",
"(",
"'/^-.+/'",
",",
"$",
"sort",
")",
")",
"{",
"$",
"direction",
"=",
"'desc'",
";",
"}",
"else",
"{",
"$",
"direction",
"=",
"'asc'",
";",
"}",
"$",
"sort",
"=",
"preg_replace",
"(",
"'/^-/'",
",",
"''",
",",
"$",
"sort",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"canSort",
"(",
"$",
"sort",
")",
")",
"{",
"return",
";",
"}",
"// Only add the sorts that are on the base resource",
"if",
"(",
"!",
"Str",
"::",
"contains",
"(",
"$",
"sort",
",",
"'.'",
")",
")",
"{",
"$",
"this",
"->",
"getHandler",
"(",
")",
"->",
"orderBy",
"(",
"$",
"sort",
",",
"$",
"direction",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"additionalSorts",
"[",
"$",
"sort",
"]",
"=",
"$",
"direction",
";",
"}",
"}",
"}"
]
| Parse the sort parameter.
@param string $params
@return void | [
"Parse",
"the",
"sort",
"parameter",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L209-L231 |
14,541 | jenky/laravel-api-helper | src/Handler.php | Handler.parseFields | protected function parseFields($params)
{
foreach (explode(',', $params) as $field) {
// Only add the fields that are on the base resource
if (! Str::contains($field, '.')) {
$this->fields[] = trim($field);
} else {
$this->additionalFields[] = trim($field);
}
}
} | php | protected function parseFields($params)
{
foreach (explode(',', $params) as $field) {
// Only add the fields that are on the base resource
if (! Str::contains($field, '.')) {
$this->fields[] = trim($field);
} else {
$this->additionalFields[] = trim($field);
}
}
} | [
"protected",
"function",
"parseFields",
"(",
"$",
"params",
")",
"{",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"params",
")",
"as",
"$",
"field",
")",
"{",
"// Only add the fields that are on the base resource",
"if",
"(",
"!",
"Str",
"::",
"contains",
"(",
"$",
"field",
",",
"'.'",
")",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"]",
"=",
"trim",
"(",
"$",
"field",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"additionalFields",
"[",
"]",
"=",
"trim",
"(",
"$",
"field",
")",
";",
"}",
"}",
"}"
]
| Parse the fields parameter.
@param string $params
@return void | [
"Parse",
"the",
"fields",
"parameter",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L239-L249 |
14,542 | jenky/laravel-api-helper | src/Handler.php | Handler.parseWith | protected function parseWith($params)
{
$with = explode(',', $params);
$withable = $this->getSupportedParams('getApiWithable');
$with = in_array('*', $withable) ? $with : array_only($with, $withable);
foreach ($this->additionalSorts as $sort => $direction) {
$parts = explode('.', $sort);
$realKey = array_pop($parts);
$relation = implode('.', $parts);
if (in_array($relation, $with)) {
$this->builder->with([$relation => function ($query) use ($realKey, $direction) {
$query->orderBy($realKey, $direction);
}]);
if (($key = array_search($relation, $with)) !== false) {
unset($with[$key]);
}
}
}
if (! empty($with)) {
$this->builder->with($with);
}
$this->with = $this->builder->getEagerLoads();
} | php | protected function parseWith($params)
{
$with = explode(',', $params);
$withable = $this->getSupportedParams('getApiWithable');
$with = in_array('*', $withable) ? $with : array_only($with, $withable);
foreach ($this->additionalSorts as $sort => $direction) {
$parts = explode('.', $sort);
$realKey = array_pop($parts);
$relation = implode('.', $parts);
if (in_array($relation, $with)) {
$this->builder->with([$relation => function ($query) use ($realKey, $direction) {
$query->orderBy($realKey, $direction);
}]);
if (($key = array_search($relation, $with)) !== false) {
unset($with[$key]);
}
}
}
if (! empty($with)) {
$this->builder->with($with);
}
$this->with = $this->builder->getEagerLoads();
} | [
"protected",
"function",
"parseWith",
"(",
"$",
"params",
")",
"{",
"$",
"with",
"=",
"explode",
"(",
"','",
",",
"$",
"params",
")",
";",
"$",
"withable",
"=",
"$",
"this",
"->",
"getSupportedParams",
"(",
"'getApiWithable'",
")",
";",
"$",
"with",
"=",
"in_array",
"(",
"'*'",
",",
"$",
"withable",
")",
"?",
"$",
"with",
":",
"array_only",
"(",
"$",
"with",
",",
"$",
"withable",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"additionalSorts",
"as",
"$",
"sort",
"=>",
"$",
"direction",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"sort",
")",
";",
"$",
"realKey",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"$",
"relation",
"=",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"relation",
",",
"$",
"with",
")",
")",
"{",
"$",
"this",
"->",
"builder",
"->",
"with",
"(",
"[",
"$",
"relation",
"=>",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"realKey",
",",
"$",
"direction",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"$",
"realKey",
",",
"$",
"direction",
")",
";",
"}",
"]",
")",
";",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"relation",
",",
"$",
"with",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"with",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"with",
")",
")",
"{",
"$",
"this",
"->",
"builder",
"->",
"with",
"(",
"$",
"with",
")",
";",
"}",
"$",
"this",
"->",
"with",
"=",
"$",
"this",
"->",
"builder",
"->",
"getEagerLoads",
"(",
")",
";",
"}"
]
| Parse the with parameter.
@param string $params
@return void | [
"Parse",
"the",
"with",
"parameter",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L268-L296 |
14,543 | jenky/laravel-api-helper | src/Handler.php | Handler.parseFilter | protected function parseFilter()
{
if (! $params = $this->getParams()) {
return;
}
foreach ($params as $key => $value) {
if ($this->isEloquentBuilder() && Str::contains($key, '~')) {
$this->filterRelation($key, $value);
} else {
$this->filter($key, $value);
}
}
} | php | protected function parseFilter()
{
if (! $params = $this->getParams()) {
return;
}
foreach ($params as $key => $value) {
if ($this->isEloquentBuilder() && Str::contains($key, '~')) {
$this->filterRelation($key, $value);
} else {
$this->filter($key, $value);
}
}
} | [
"protected",
"function",
"parseFilter",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"params",
"=",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEloquentBuilder",
"(",
")",
"&&",
"Str",
"::",
"contains",
"(",
"$",
"key",
",",
"'~'",
")",
")",
"{",
"$",
"this",
"->",
"filterRelation",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"filter",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
]
| Parse all the paramenters for query builder.
@return void | [
"Parse",
"all",
"the",
"paramenters",
"for",
"query",
"builder",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L303-L316 |
14,544 | jenky/laravel-api-helper | src/Handler.php | Handler.formatParam | protected function formatParam($key, $value)
{
$supportedFixes = [
'lt' => '<',
'gt' => '>',
'lte' => '<=',
'gte' => '>=',
'lk' => 'LIKE',
'not-lk' => 'NOT LIKE',
'in' => 'IN',
'not-in' => 'NOT IN',
'not' => '!=',
];
$prefixes = implode('|', $supportedFixes);
$suffixes = implode('|', array_keys($supportedFixes));
$matches = [];
// Matches every parameter with an optional prefix and/or postfix
// e.g. not-title-lk, title-lk, not-title, title
$regex = '/^(?:('.$prefixes.')-)?(.*?)(?:-('.$suffixes.')|$)/';
preg_match($regex, $key, $matches);
if (! isset($matches[3])) {
if (Str::lower(trim($value)) == 'null') {
$comparator = 'NULL';
} else {
$comparator = '=';
}
} else {
if (Str::lower(trim($value)) == 'null') {
$comparator = 'NOT NULL';
} else {
$comparator = $supportedFixes[$matches[3]];
}
}
$column = isset($matches[2]) ? $matches[2] : null;
return compact('comparator', 'column', 'matches');
} | php | protected function formatParam($key, $value)
{
$supportedFixes = [
'lt' => '<',
'gt' => '>',
'lte' => '<=',
'gte' => '>=',
'lk' => 'LIKE',
'not-lk' => 'NOT LIKE',
'in' => 'IN',
'not-in' => 'NOT IN',
'not' => '!=',
];
$prefixes = implode('|', $supportedFixes);
$suffixes = implode('|', array_keys($supportedFixes));
$matches = [];
// Matches every parameter with an optional prefix and/or postfix
// e.g. not-title-lk, title-lk, not-title, title
$regex = '/^(?:('.$prefixes.')-)?(.*?)(?:-('.$suffixes.')|$)/';
preg_match($regex, $key, $matches);
if (! isset($matches[3])) {
if (Str::lower(trim($value)) == 'null') {
$comparator = 'NULL';
} else {
$comparator = '=';
}
} else {
if (Str::lower(trim($value)) == 'null') {
$comparator = 'NOT NULL';
} else {
$comparator = $supportedFixes[$matches[3]];
}
}
$column = isset($matches[2]) ? $matches[2] : null;
return compact('comparator', 'column', 'matches');
} | [
"protected",
"function",
"formatParam",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"supportedFixes",
"=",
"[",
"'lt'",
"=>",
"'<'",
",",
"'gt'",
"=>",
"'>'",
",",
"'lte'",
"=>",
"'<='",
",",
"'gte'",
"=>",
"'>='",
",",
"'lk'",
"=>",
"'LIKE'",
",",
"'not-lk'",
"=>",
"'NOT LIKE'",
",",
"'in'",
"=>",
"'IN'",
",",
"'not-in'",
"=>",
"'NOT IN'",
",",
"'not'",
"=>",
"'!='",
",",
"]",
";",
"$",
"prefixes",
"=",
"implode",
"(",
"'|'",
",",
"$",
"supportedFixes",
")",
";",
"$",
"suffixes",
"=",
"implode",
"(",
"'|'",
",",
"array_keys",
"(",
"$",
"supportedFixes",
")",
")",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"// Matches every parameter with an optional prefix and/or postfix",
"// e.g. not-title-lk, title-lk, not-title, title",
"$",
"regex",
"=",
"'/^(?:('",
".",
"$",
"prefixes",
".",
"')-)?(.*?)(?:-('",
".",
"$",
"suffixes",
".",
"')|$)/'",
";",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"key",
",",
"$",
"matches",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
")",
"{",
"if",
"(",
"Str",
"::",
"lower",
"(",
"trim",
"(",
"$",
"value",
")",
")",
"==",
"'null'",
")",
"{",
"$",
"comparator",
"=",
"'NULL'",
";",
"}",
"else",
"{",
"$",
"comparator",
"=",
"'='",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"Str",
"::",
"lower",
"(",
"trim",
"(",
"$",
"value",
")",
")",
"==",
"'null'",
")",
"{",
"$",
"comparator",
"=",
"'NOT NULL'",
";",
"}",
"else",
"{",
"$",
"comparator",
"=",
"$",
"supportedFixes",
"[",
"$",
"matches",
"[",
"3",
"]",
"]",
";",
"}",
"}",
"$",
"column",
"=",
"isset",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"?",
"$",
"matches",
"[",
"2",
"]",
":",
"null",
";",
"return",
"compact",
"(",
"'comparator'",
",",
"'column'",
",",
"'matches'",
")",
";",
"}"
]
| Format the paramenter for query builder.
@param string $key
@param string $value
@return array | [
"Format",
"the",
"paramenter",
"for",
"query",
"builder",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L325-L367 |
14,545 | jenky/laravel-api-helper | src/Handler.php | Handler.filter | protected function filter($key, $value)
{
extract($this->formatParam($key, $value));
if (! $this->canFilter($column)) {
return;
}
if ($comparator == 'IN') {
$values = explode(',', $value);
$this->getHandler()->whereIn($column, $values);
} elseif ($comparator == 'NOT IN') {
$values = explode(',', $value);
$this->getHandler()->whereNotIn($column, $values);
} else {
$values = explode('|', $value);
if (count($values) > 1) {
$this->getHandler()->where(function ($query) use ($column, $comparator, $values) {
foreach ($values as $value) {
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\*|\*$)/', '%', $value);
}
// Link the filters with AND of there is a "not" and with OR if there's none
if ($comparator == '!=' || $comparator == 'NOT LIKE') {
$query->where($column, $comparator, $value);
} else {
$query->orWhere($column, $comparator, $value);
}
}
});
} else {
$value = $values[0];
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\*|\*$)/', '%', $value);
}
if ($comparator == 'NULL' || $comparator == 'NOT NULL') {
$this->getHandler()->whereNull($column, 'and', $comparator == 'NOT NULL');
} else {
$this->getHandler()->where($column, $comparator, $value);
}
}
}
} | php | protected function filter($key, $value)
{
extract($this->formatParam($key, $value));
if (! $this->canFilter($column)) {
return;
}
if ($comparator == 'IN') {
$values = explode(',', $value);
$this->getHandler()->whereIn($column, $values);
} elseif ($comparator == 'NOT IN') {
$values = explode(',', $value);
$this->getHandler()->whereNotIn($column, $values);
} else {
$values = explode('|', $value);
if (count($values) > 1) {
$this->getHandler()->where(function ($query) use ($column, $comparator, $values) {
foreach ($values as $value) {
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\*|\*$)/', '%', $value);
}
// Link the filters with AND of there is a "not" and with OR if there's none
if ($comparator == '!=' || $comparator == 'NOT LIKE') {
$query->where($column, $comparator, $value);
} else {
$query->orWhere($column, $comparator, $value);
}
}
});
} else {
$value = $values[0];
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\*|\*$)/', '%', $value);
}
if ($comparator == 'NULL' || $comparator == 'NOT NULL') {
$this->getHandler()->whereNull($column, 'and', $comparator == 'NOT NULL');
} else {
$this->getHandler()->where($column, $comparator, $value);
}
}
}
} | [
"protected",
"function",
"filter",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"extract",
"(",
"$",
"this",
"->",
"formatParam",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"canFilter",
"(",
"$",
"column",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"comparator",
"==",
"'IN'",
")",
"{",
"$",
"values",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"getHandler",
"(",
")",
"->",
"whereIn",
"(",
"$",
"column",
",",
"$",
"values",
")",
";",
"}",
"elseif",
"(",
"$",
"comparator",
"==",
"'NOT IN'",
")",
"{",
"$",
"values",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"getHandler",
"(",
")",
"->",
"whereNotIn",
"(",
"$",
"column",
",",
"$",
"values",
")",
";",
"}",
"else",
"{",
"$",
"values",
"=",
"explode",
"(",
"'|'",
",",
"$",
"value",
")",
";",
"if",
"(",
"count",
"(",
"$",
"values",
")",
">",
"1",
")",
"{",
"$",
"this",
"->",
"getHandler",
"(",
")",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"column",
",",
"$",
"comparator",
",",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"comparator",
"==",
"'LIKE'",
"||",
"$",
"comparator",
"==",
"'NOT LIKE'",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"'/(^\\*|\\*$)/'",
",",
"'%'",
",",
"$",
"value",
")",
";",
"}",
"// Link the filters with AND of there is a \"not\" and with OR if there's none",
"if",
"(",
"$",
"comparator",
"==",
"'!='",
"||",
"$",
"comparator",
"==",
"'NOT LIKE'",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"column",
",",
"$",
"comparator",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"orWhere",
"(",
"$",
"column",
",",
"$",
"comparator",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"values",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"comparator",
"==",
"'LIKE'",
"||",
"$",
"comparator",
"==",
"'NOT LIKE'",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"'/(^\\*|\\*$)/'",
",",
"'%'",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"comparator",
"==",
"'NULL'",
"||",
"$",
"comparator",
"==",
"'NOT NULL'",
")",
"{",
"$",
"this",
"->",
"getHandler",
"(",
")",
"->",
"whereNull",
"(",
"$",
"column",
",",
"'and'",
",",
"$",
"comparator",
"==",
"'NOT NULL'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getHandler",
"(",
")",
"->",
"where",
"(",
"$",
"column",
",",
"$",
"comparator",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}"
]
| Apply the filter to query builder.
@param string $key
@param string $value
@return void | [
"Apply",
"the",
"filter",
"to",
"query",
"builder",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L376-L418 |
14,546 | jenky/laravel-api-helper | src/Handler.php | Handler.filterRelation | protected function filterRelation($key, $value)
{
$key = str_replace('~', '.', $key);
$parts = explode('.', $key);
$realKey = array_pop($parts);
$relation = implode('.', $parts);
if (! in_array($relation, array_keys($this->with))) {
return;
}
extract($this->formatParam($realKey, $value));
if (! $this->canFilter($column)) {
return;
}
$this->builder->whereHas($relation, function ($q) use ($column, $comparator, $value) {
if ($comparator == 'IN') {
$values = explode(',', $value);
$q->whereIn($column, $values);
} elseif ($comparator == 'NOT IN') {
$values = explode(',', $value);
$q->whereNotIn($column, $values);
} else {
$values = explode('|', $value);
if (count($values) > 1) {
$q->where(function ($query) use ($column, $comparator, $values) {
foreach ($values as $value) {
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\*|\*$)/', '%', $value);
}
// Link the filters with AND of there is a "not" and with OR if there's none
if ($comparator == '!=' || $comparator == 'NOT LIKE') {
$query->where($column, $comparator, $value);
} else {
$query->orWhere($column, $comparator, $value);
}
}
});
} else {
$value = $values[0];
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\*|\*$)/', '%', $value);
}
if ($comparator == 'NULL' || $comparator == 'NOT NULL') {
$q->whereNull($column, 'and', $comparator == 'NOT NULL');
} else {
$q->where($column, $comparator, $value);
}
}
}
});
} | php | protected function filterRelation($key, $value)
{
$key = str_replace('~', '.', $key);
$parts = explode('.', $key);
$realKey = array_pop($parts);
$relation = implode('.', $parts);
if (! in_array($relation, array_keys($this->with))) {
return;
}
extract($this->formatParam($realKey, $value));
if (! $this->canFilter($column)) {
return;
}
$this->builder->whereHas($relation, function ($q) use ($column, $comparator, $value) {
if ($comparator == 'IN') {
$values = explode(',', $value);
$q->whereIn($column, $values);
} elseif ($comparator == 'NOT IN') {
$values = explode(',', $value);
$q->whereNotIn($column, $values);
} else {
$values = explode('|', $value);
if (count($values) > 1) {
$q->where(function ($query) use ($column, $comparator, $values) {
foreach ($values as $value) {
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\*|\*$)/', '%', $value);
}
// Link the filters with AND of there is a "not" and with OR if there's none
if ($comparator == '!=' || $comparator == 'NOT LIKE') {
$query->where($column, $comparator, $value);
} else {
$query->orWhere($column, $comparator, $value);
}
}
});
} else {
$value = $values[0];
if ($comparator == 'LIKE' || $comparator == 'NOT LIKE') {
$value = preg_replace('/(^\*|\*$)/', '%', $value);
}
if ($comparator == 'NULL' || $comparator == 'NOT NULL') {
$q->whereNull($column, 'and', $comparator == 'NOT NULL');
} else {
$q->where($column, $comparator, $value);
}
}
}
});
} | [
"protected",
"function",
"filterRelation",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"'~'",
",",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"realKey",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"$",
"relation",
"=",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"array_keys",
"(",
"$",
"this",
"->",
"with",
")",
")",
")",
"{",
"return",
";",
"}",
"extract",
"(",
"$",
"this",
"->",
"formatParam",
"(",
"$",
"realKey",
",",
"$",
"value",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"canFilter",
"(",
"$",
"column",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"builder",
"->",
"whereHas",
"(",
"$",
"relation",
",",
"function",
"(",
"$",
"q",
")",
"use",
"(",
"$",
"column",
",",
"$",
"comparator",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"comparator",
"==",
"'IN'",
")",
"{",
"$",
"values",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"$",
"q",
"->",
"whereIn",
"(",
"$",
"column",
",",
"$",
"values",
")",
";",
"}",
"elseif",
"(",
"$",
"comparator",
"==",
"'NOT IN'",
")",
"{",
"$",
"values",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"$",
"q",
"->",
"whereNotIn",
"(",
"$",
"column",
",",
"$",
"values",
")",
";",
"}",
"else",
"{",
"$",
"values",
"=",
"explode",
"(",
"'|'",
",",
"$",
"value",
")",
";",
"if",
"(",
"count",
"(",
"$",
"values",
")",
">",
"1",
")",
"{",
"$",
"q",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"column",
",",
"$",
"comparator",
",",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"comparator",
"==",
"'LIKE'",
"||",
"$",
"comparator",
"==",
"'NOT LIKE'",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"'/(^\\*|\\*$)/'",
",",
"'%'",
",",
"$",
"value",
")",
";",
"}",
"// Link the filters with AND of there is a \"not\" and with OR if there's none",
"if",
"(",
"$",
"comparator",
"==",
"'!='",
"||",
"$",
"comparator",
"==",
"'NOT LIKE'",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"column",
",",
"$",
"comparator",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"orWhere",
"(",
"$",
"column",
",",
"$",
"comparator",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"values",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"comparator",
"==",
"'LIKE'",
"||",
"$",
"comparator",
"==",
"'NOT LIKE'",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"'/(^\\*|\\*$)/'",
",",
"'%'",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"comparator",
"==",
"'NULL'",
"||",
"$",
"comparator",
"==",
"'NOT NULL'",
")",
"{",
"$",
"q",
"->",
"whereNull",
"(",
"$",
"column",
",",
"'and'",
",",
"$",
"comparator",
"==",
"'NOT NULL'",
")",
";",
"}",
"else",
"{",
"$",
"q",
"->",
"where",
"(",
"$",
"column",
",",
"$",
"comparator",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}",
")",
";",
"}"
]
| Apply the filter to relationship query builder.
@param string $key
@param string $value
@return void | [
"Apply",
"the",
"filter",
"to",
"relationship",
"query",
"builder",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L427-L481 |
14,547 | jenky/laravel-api-helper | src/Handler.php | Handler.getParams | protected function getParams()
{
$reserved = [
$this->config('prefix', '').'sort',
$this->config('prefix', '').'fields',
$this->config('prefix', '').'limit',
$this->config('prefix', '').'with',
$this->config('prefix', '').'page',
];
return $this->params ?: $this->request->except($reserved);
} | php | protected function getParams()
{
$reserved = [
$this->config('prefix', '').'sort',
$this->config('prefix', '').'fields',
$this->config('prefix', '').'limit',
$this->config('prefix', '').'with',
$this->config('prefix', '').'page',
];
return $this->params ?: $this->request->except($reserved);
} | [
"protected",
"function",
"getParams",
"(",
")",
"{",
"$",
"reserved",
"=",
"[",
"$",
"this",
"->",
"config",
"(",
"'prefix'",
",",
"''",
")",
".",
"'sort'",
",",
"$",
"this",
"->",
"config",
"(",
"'prefix'",
",",
"''",
")",
".",
"'fields'",
",",
"$",
"this",
"->",
"config",
"(",
"'prefix'",
",",
"''",
")",
".",
"'limit'",
",",
"$",
"this",
"->",
"config",
"(",
"'prefix'",
",",
"''",
")",
".",
"'with'",
",",
"$",
"this",
"->",
"config",
"(",
"'prefix'",
",",
"''",
")",
".",
"'page'",
",",
"]",
";",
"return",
"$",
"this",
"->",
"params",
"?",
":",
"$",
"this",
"->",
"request",
"->",
"except",
"(",
"$",
"reserved",
")",
";",
"}"
]
| Get the params from the request.
@return array | [
"Get",
"the",
"params",
"from",
"the",
"request",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L530-L541 |
14,548 | jenky/laravel-api-helper | src/Handler.php | Handler.getHandler | protected function getHandler()
{
if ($this->builder) {
return $this->builder;
}
if ($this->query) {
return $this->query;
}
throw new InvalidArgumentException('Missing query builder');
} | php | protected function getHandler()
{
if ($this->builder) {
return $this->builder;
}
if ($this->query) {
return $this->query;
}
throw new InvalidArgumentException('Missing query builder');
} | [
"protected",
"function",
"getHandler",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"builder",
")",
"{",
"return",
"$",
"this",
"->",
"builder",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"query",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Missing query builder'",
")",
";",
"}"
]
| Get the handler.
@throws \InvalidArgumentException
@return \Illuminate\Database\Query\Builder | \Illuminate\Database\Eloquent\Builder | [
"Get",
"the",
"handler",
"."
]
| 9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367 | https://github.com/jenky/laravel-api-helper/blob/9af8f4d99d96ed3ea1bee7eabcdb0472f1bfa367/src/Handler.php#L665-L676 |
14,549 | eloquent/liberator | src/LiberatorClass.php | LiberatorClass.liberatorPropertyReflector | protected function liberatorPropertyReflector($property)
{
$classReflector = $this->liberatorReflector();
while ($classReflector) {
if ($classReflector->hasProperty($property)) {
$propertyReflector = $classReflector->getProperty($property);
$propertyReflector->setAccessible(true);
return $propertyReflector;
}
$classReflector = $classReflector->getParentClass();
}
return null;
} | php | protected function liberatorPropertyReflector($property)
{
$classReflector = $this->liberatorReflector();
while ($classReflector) {
if ($classReflector->hasProperty($property)) {
$propertyReflector = $classReflector->getProperty($property);
$propertyReflector->setAccessible(true);
return $propertyReflector;
}
$classReflector = $classReflector->getParentClass();
}
return null;
} | [
"protected",
"function",
"liberatorPropertyReflector",
"(",
"$",
"property",
")",
"{",
"$",
"classReflector",
"=",
"$",
"this",
"->",
"liberatorReflector",
"(",
")",
";",
"while",
"(",
"$",
"classReflector",
")",
"{",
"if",
"(",
"$",
"classReflector",
"->",
"hasProperty",
"(",
"$",
"property",
")",
")",
"{",
"$",
"propertyReflector",
"=",
"$",
"classReflector",
"->",
"getProperty",
"(",
"$",
"property",
")",
";",
"$",
"propertyReflector",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"propertyReflector",
";",
"}",
"$",
"classReflector",
"=",
"$",
"classReflector",
"->",
"getParentClass",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Get a property reflector.
@param string $property The property name.
@return ReflectionProperty|null The property reflector, or null if no such property exists. | [
"Get",
"a",
"property",
"reflector",
"."
]
| d90c159e0067f7f3e376c8e4b1b72d502f7aa0aa | https://github.com/eloquent/liberator/blob/d90c159e0067f7f3e376c8e4b1b72d502f7aa0aa/src/LiberatorClass.php#L198-L214 |
14,550 | ejsmont-artur/phpProxyBuilder | src/PhpProxyBuilder/Aop/Advice/ExceptionLoggingAdvice.php | ExceptionLoggingAdvice.interceptMethodCall | public function interceptMethodCall(ProceedingJoinPointInterface $jointPoint) {
try {
return $jointPoint->proceed();
} catch (Exception $e) {
$methodName = $jointPoint->getMethodName();
$partialTrace = array();
$trace = $e->getTrace();
$depth = 0;
foreach ($trace as $entry) {
if ($depth > $this->maxTraceDepth) {
$partialTrace[] = "... trace truncated";
break;
}
$file = isset($entry['file']) ? $entry['file'] : "";
$function = isset($entry['function']) ? $entry['function'] : "";
$line = isset($entry['line']) ? $entry['line'] : "";
$partialTrace[] = sprintf("%s:%s:%s", $file, $function, $line);
$depth++;
}
$msg = sprintf("Exception in %s:%s:%s (%d) %s", $e->getFile(), $e->getLine(), $methodName, $e->getCode(), $e->getMessage());
$this->logger->logWarning($msg, implode("\n", $partialTrace));
throw $e;
}
} | php | public function interceptMethodCall(ProceedingJoinPointInterface $jointPoint) {
try {
return $jointPoint->proceed();
} catch (Exception $e) {
$methodName = $jointPoint->getMethodName();
$partialTrace = array();
$trace = $e->getTrace();
$depth = 0;
foreach ($trace as $entry) {
if ($depth > $this->maxTraceDepth) {
$partialTrace[] = "... trace truncated";
break;
}
$file = isset($entry['file']) ? $entry['file'] : "";
$function = isset($entry['function']) ? $entry['function'] : "";
$line = isset($entry['line']) ? $entry['line'] : "";
$partialTrace[] = sprintf("%s:%s:%s", $file, $function, $line);
$depth++;
}
$msg = sprintf("Exception in %s:%s:%s (%d) %s", $e->getFile(), $e->getLine(), $methodName, $e->getCode(), $e->getMessage());
$this->logger->logWarning($msg, implode("\n", $partialTrace));
throw $e;
}
} | [
"public",
"function",
"interceptMethodCall",
"(",
"ProceedingJoinPointInterface",
"$",
"jointPoint",
")",
"{",
"try",
"{",
"return",
"$",
"jointPoint",
"->",
"proceed",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"methodName",
"=",
"$",
"jointPoint",
"->",
"getMethodName",
"(",
")",
";",
"$",
"partialTrace",
"=",
"array",
"(",
")",
";",
"$",
"trace",
"=",
"$",
"e",
"->",
"getTrace",
"(",
")",
";",
"$",
"depth",
"=",
"0",
";",
"foreach",
"(",
"$",
"trace",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"$",
"depth",
">",
"$",
"this",
"->",
"maxTraceDepth",
")",
"{",
"$",
"partialTrace",
"[",
"]",
"=",
"\"... trace truncated\"",
";",
"break",
";",
"}",
"$",
"file",
"=",
"isset",
"(",
"$",
"entry",
"[",
"'file'",
"]",
")",
"?",
"$",
"entry",
"[",
"'file'",
"]",
":",
"\"\"",
";",
"$",
"function",
"=",
"isset",
"(",
"$",
"entry",
"[",
"'function'",
"]",
")",
"?",
"$",
"entry",
"[",
"'function'",
"]",
":",
"\"\"",
";",
"$",
"line",
"=",
"isset",
"(",
"$",
"entry",
"[",
"'line'",
"]",
")",
"?",
"$",
"entry",
"[",
"'line'",
"]",
":",
"\"\"",
";",
"$",
"partialTrace",
"[",
"]",
"=",
"sprintf",
"(",
"\"%s:%s:%s\"",
",",
"$",
"file",
",",
"$",
"function",
",",
"$",
"line",
")",
";",
"$",
"depth",
"++",
";",
"}",
"$",
"msg",
"=",
"sprintf",
"(",
"\"Exception in %s:%s:%s (%d) %s\"",
",",
"$",
"e",
"->",
"getFile",
"(",
")",
",",
"$",
"e",
"->",
"getLine",
"(",
")",
",",
"$",
"methodName",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"logWarning",
"(",
"$",
"msg",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"partialTrace",
")",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}"
]
| In this implementation we log each exception and rethrow.
@param ProceedingJoinPointInterface $jointPoint
@throws \Exception
@return mixed | [
"In",
"this",
"implementation",
"we",
"log",
"each",
"exception",
"and",
"rethrow",
"."
]
| ef7ec14e5d18eeba7a93e3617a0fdb5b146d6480 | https://github.com/ejsmont-artur/phpProxyBuilder/blob/ef7ec14e5d18eeba7a93e3617a0fdb5b146d6480/src/PhpProxyBuilder/Aop/Advice/ExceptionLoggingAdvice.php#L54-L79 |
14,551 | nicoSWD/put.io-api-v2 | src/PutIO/Engines/JSON/JSON.php | Services_JSON.Services_JSON | function Services_JSON($use = 0)
{
$this->use = $use;
$this->_mb_strlen = function_exists('mb_strlen');
$this->_mb_convert_encoding = function_exists('mb_convert_encoding');
$this->_mb_substr = function_exists('mb_substr');
} | php | function Services_JSON($use = 0)
{
$this->use = $use;
$this->_mb_strlen = function_exists('mb_strlen');
$this->_mb_convert_encoding = function_exists('mb_convert_encoding');
$this->_mb_substr = function_exists('mb_substr');
} | [
"function",
"Services_JSON",
"(",
"$",
"use",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"use",
"=",
"$",
"use",
";",
"$",
"this",
"->",
"_mb_strlen",
"=",
"function_exists",
"(",
"'mb_strlen'",
")",
";",
"$",
"this",
"->",
"_mb_convert_encoding",
"=",
"function_exists",
"(",
"'mb_convert_encoding'",
")",
";",
"$",
"this",
"->",
"_mb_substr",
"=",
"function_exists",
"(",
"'mb_substr'",
")",
";",
"}"
]
| constructs a new JSON instance
@param int $use object behavior flags; combine with boolean-OR
possible values:
- SERVICES_JSON_LOOSE_TYPE: loose typing.
"{...}" syntax creates associative arrays
instead of objects in decode().
- SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
Values which can't be encoded (e.g. resources)
appear as NULL instead of throwing errors.
By default, a deeply-nested resource will
bubble up with an error, so all return values
from encode() should be checked with isError()
- SERVICES_JSON_USE_TO_JSON: call toJSON when serializing objects
It serializes the return value from the toJSON call rather
than the object it'self, toJSON can return associative arrays,
strings or numbers, if you return an object, make sure it does
not have a toJSON method, otherwise an error will occur. | [
"constructs",
"a",
"new",
"JSON",
"instance"
]
| d91bedd91ea75793512a921bfd9aa83e86a6f0a7 | https://github.com/nicoSWD/put.io-api-v2/blob/d91bedd91ea75793512a921bfd9aa83e86a6f0a7/src/PutIO/Engines/JSON/JSON.php#L144-L150 |
14,552 | nicoSWD/put.io-api-v2 | src/PutIO/Engines/JSON/JSON.php | Services_JSON.encodeUnsafe | function encodeUnsafe($var)
{
// see bug #16908 - regarding numeric locale printing
$lc = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'C');
$ret = $this->_encode($var);
setlocale(LC_NUMERIC, $lc);
return $ret;
} | php | function encodeUnsafe($var)
{
// see bug #16908 - regarding numeric locale printing
$lc = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, 'C');
$ret = $this->_encode($var);
setlocale(LC_NUMERIC, $lc);
return $ret;
} | [
"function",
"encodeUnsafe",
"(",
"$",
"var",
")",
"{",
"// see bug #16908 - regarding numeric locale printing",
"$",
"lc",
"=",
"setlocale",
"(",
"LC_NUMERIC",
",",
"0",
")",
";",
"setlocale",
"(",
"LC_NUMERIC",
",",
"'C'",
")",
";",
"$",
"ret",
"=",
"$",
"this",
"->",
"_encode",
"(",
"$",
"var",
")",
";",
"setlocale",
"(",
"LC_NUMERIC",
",",
"$",
"lc",
")",
";",
"return",
"$",
"ret",
";",
"}"
]
| encodes an arbitrary variable into JSON format without JSON Header - warning - may allow XSS!!!!)
@param mixed $var any number, boolean, string, array, or object to be encoded.
see argument 1 to Services_JSON() above for array-parsing behavior.
if var is a strng, note that encode() always expects it
to be in ASCII or UTF-8 format!
@return mixed JSON string representation of input var or an error if a problem occurs
@access public | [
"encodes",
"an",
"arbitrary",
"variable",
"into",
"JSON",
"format",
"without",
"JSON",
"Header",
"-",
"warning",
"-",
"may",
"allow",
"XSS!!!!",
")"
]
| d91bedd91ea75793512a921bfd9aa83e86a6f0a7 | https://github.com/nicoSWD/put.io-api-v2/blob/d91bedd91ea75793512a921bfd9aa83e86a6f0a7/src/PutIO/Engines/JSON/JSON.php#L271-L280 |
14,553 | crossjoin/Css | src/Crossjoin/Css/Format/Rule/AtKeyframes/KeyframesRuleSet.php | KeyframesRuleSet.setKeyframes | public function setKeyframes($keyframes)
{
$this->keyframes = [];
if (!is_array($keyframes)) {
$keyframes = [$keyframes];
}
foreach ($keyframes as $keyframe) {
$this->addKeyframe($keyframe);
}
return $this;
} | php | public function setKeyframes($keyframes)
{
$this->keyframes = [];
if (!is_array($keyframes)) {
$keyframes = [$keyframes];
}
foreach ($keyframes as $keyframe) {
$this->addKeyframe($keyframe);
}
return $this;
} | [
"public",
"function",
"setKeyframes",
"(",
"$",
"keyframes",
")",
"{",
"$",
"this",
"->",
"keyframes",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"keyframes",
")",
")",
"{",
"$",
"keyframes",
"=",
"[",
"$",
"keyframes",
"]",
";",
"}",
"foreach",
"(",
"$",
"keyframes",
"as",
"$",
"keyframe",
")",
"{",
"$",
"this",
"->",
"addKeyframe",
"(",
"$",
"keyframe",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Sets the keyframes.
@param KeyframesKeyframe[]|KeyframesKeyframe $keyframes
@return $this | [
"Sets",
"the",
"keyframes",
"."
]
| 7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3 | https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtKeyframes/KeyframesRuleSet.php#L41-L52 |
14,554 | crossjoin/Css | src/Crossjoin/Css/Format/Rule/AtKeyframes/KeyframesRuleSet.php | KeyframesRuleSet.addDeclaration | public function addDeclaration(DeclarationAbstract $declaration)
{
// TODO Selectors (or keyframes in this case) do NOT cascade!
// The last one overwrites previous ones
// @see: https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes#When_a_keyframe_is_defined_multiple_times
if ($declaration instanceof KeyframesDeclaration) {
$this->declarations[] = $declaration;
} else {
throw new \InvalidArgumentException(
"Invalid declaration instance. Instance of 'KeyframesDeclaration' expected."
);
}
return $this;
} | php | public function addDeclaration(DeclarationAbstract $declaration)
{
// TODO Selectors (or keyframes in this case) do NOT cascade!
// The last one overwrites previous ones
// @see: https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes#When_a_keyframe_is_defined_multiple_times
if ($declaration instanceof KeyframesDeclaration) {
$this->declarations[] = $declaration;
} else {
throw new \InvalidArgumentException(
"Invalid declaration instance. Instance of 'KeyframesDeclaration' expected."
);
}
return $this;
} | [
"public",
"function",
"addDeclaration",
"(",
"DeclarationAbstract",
"$",
"declaration",
")",
"{",
"// TODO Selectors (or keyframes in this case) do NOT cascade!",
"// The last one overwrites previous ones",
"// @see: https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes#When_a_keyframe_is_defined_multiple_times",
"if",
"(",
"$",
"declaration",
"instanceof",
"KeyframesDeclaration",
")",
"{",
"$",
"this",
"->",
"declarations",
"[",
"]",
"=",
"$",
"declaration",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid declaration instance. Instance of 'KeyframesDeclaration' expected.\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Adds a keyframes declaration.
@param KeyframesDeclaration $declaration
@return $this | [
"Adds",
"a",
"keyframes",
"declaration",
"."
]
| 7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3 | https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtKeyframes/KeyframesRuleSet.php#L83-L98 |
14,555 | crossjoin/Css | src/Crossjoin/Css/Format/Rule/AtKeyframes/KeyframesRuleSet.php | KeyframesRuleSet.parseKeyframeList | protected function parseKeyframeList($keyframeList)
{
foreach (explode(",", $keyframeList) as $keyframe) {
$keyframe = trim($keyframe, " \r\n\t\f");
$this->addKeyframe(new KeyframesKeyframe($keyframe, $this->getStyleSheet()));
}
} | php | protected function parseKeyframeList($keyframeList)
{
foreach (explode(",", $keyframeList) as $keyframe) {
$keyframe = trim($keyframe, " \r\n\t\f");
$this->addKeyframe(new KeyframesKeyframe($keyframe, $this->getStyleSheet()));
}
} | [
"protected",
"function",
"parseKeyframeList",
"(",
"$",
"keyframeList",
")",
"{",
"foreach",
"(",
"explode",
"(",
"\",\"",
",",
"$",
"keyframeList",
")",
"as",
"$",
"keyframe",
")",
"{",
"$",
"keyframe",
"=",
"trim",
"(",
"$",
"keyframe",
",",
"\" \\r\\n\\t\\f\"",
")",
";",
"$",
"this",
"->",
"addKeyframe",
"(",
"new",
"KeyframesKeyframe",
"(",
"$",
"keyframe",
",",
"$",
"this",
"->",
"getStyleSheet",
"(",
")",
")",
")",
";",
"}",
"}"
]
| Parses a string of keyframes.
@param string $keyframeList | [
"Parses",
"a",
"string",
"of",
"keyframes",
"."
]
| 7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3 | https://github.com/crossjoin/Css/blob/7b50ca94c4bdad60d01cfa327f00b7a600d6f9f3/src/Crossjoin/Css/Format/Rule/AtKeyframes/KeyframesRuleSet.php#L105-L111 |
14,556 | slogsdon/staticwp | includes/staticwp-admin.class.php | Admin.addMenu | public function addMenu()
{
add_submenu_page(
'tools.php',
__('StaticWP', $this->plugin),
__('StaticWP', $this->plugin),
'manage_options',
$this->plugin,
array($this, 'viewPage')
);
} | php | public function addMenu()
{
add_submenu_page(
'tools.php',
__('StaticWP', $this->plugin),
__('StaticWP', $this->plugin),
'manage_options',
$this->plugin,
array($this, 'viewPage')
);
} | [
"public",
"function",
"addMenu",
"(",
")",
"{",
"add_submenu_page",
"(",
"'tools.php'",
",",
"__",
"(",
"'StaticWP'",
",",
"$",
"this",
"->",
"plugin",
")",
",",
"__",
"(",
"'StaticWP'",
",",
"$",
"this",
"->",
"plugin",
")",
",",
"'manage_options'",
",",
"$",
"this",
"->",
"plugin",
",",
"array",
"(",
"$",
"this",
",",
"'viewPage'",
")",
")",
";",
"}"
]
| Creates menu for StaticWP admin pages.
@since 1.3.0
@return void | [
"Creates",
"menu",
"for",
"StaticWP",
"admin",
"pages",
"."
]
| e96811e57c521b0dc28fc600647b89828cdba8c0 | https://github.com/slogsdon/staticwp/blob/e96811e57c521b0dc28fc600647b89828cdba8c0/includes/staticwp-admin.class.php#L90-L100 |
14,557 | slogsdon/staticwp | includes/staticwp-admin.class.php | Admin.deactivate | public function deactivate()
{
$muPluginFile = WP_CONTENT_DIR . '/mu-plugins/' . $this->plugin . '-mu.php';
if (is_file($muPluginFile)) {
unlink($muPluginFile);
}
if (is_dir($this->destination)) {
$this->rrmdir(dirname($this->destination));
}
delete_option($this->plugin . 'version');
delete_option('staticwp_deferred_admin_notices');
} | php | public function deactivate()
{
$muPluginFile = WP_CONTENT_DIR . '/mu-plugins/' . $this->plugin . '-mu.php';
if (is_file($muPluginFile)) {
unlink($muPluginFile);
}
if (is_dir($this->destination)) {
$this->rrmdir(dirname($this->destination));
}
delete_option($this->plugin . 'version');
delete_option('staticwp_deferred_admin_notices');
} | [
"public",
"function",
"deactivate",
"(",
")",
"{",
"$",
"muPluginFile",
"=",
"WP_CONTENT_DIR",
".",
"'/mu-plugins/'",
".",
"$",
"this",
"->",
"plugin",
".",
"'-mu.php'",
";",
"if",
"(",
"is_file",
"(",
"$",
"muPluginFile",
")",
")",
"{",
"unlink",
"(",
"$",
"muPluginFile",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"this",
"->",
"destination",
")",
")",
"{",
"$",
"this",
"->",
"rrmdir",
"(",
"dirname",
"(",
"$",
"this",
"->",
"destination",
")",
")",
";",
"}",
"delete_option",
"(",
"$",
"this",
"->",
"plugin",
".",
"'version'",
")",
";",
"delete_option",
"(",
"'staticwp_deferred_admin_notices'",
")",
";",
"}"
]
| Cleans up after itself on deactivation.
@since 1.1.0
@return void | [
"Cleans",
"up",
"after",
"itself",
"on",
"deactivation",
"."
]
| e96811e57c521b0dc28fc600647b89828cdba8c0 | https://github.com/slogsdon/staticwp/blob/e96811e57c521b0dc28fc600647b89828cdba8c0/includes/staticwp-admin.class.php#L109-L123 |
14,558 | slogsdon/staticwp | includes/staticwp-admin.class.php | Admin.displayNotices | public static function displayNotices()
{
if ($notices = get_option('staticwp_deferred_admin_notices')) {
foreach ($notices as $notice) {
$message = $notice;
$type = 'updated';
if (is_array($notice)) {
$message = isset($notice['message']) ? $notice['message'] : '';
$type = isset($notice['type']) ? $notice['type'] : $type;
}
echo '<div class="' . $type . '"><p>' . $message . '</p></div>';
}
delete_option('staticwp_deferred_admin_notices');
}
} | php | public static function displayNotices()
{
if ($notices = get_option('staticwp_deferred_admin_notices')) {
foreach ($notices as $notice) {
$message = $notice;
$type = 'updated';
if (is_array($notice)) {
$message = isset($notice['message']) ? $notice['message'] : '';
$type = isset($notice['type']) ? $notice['type'] : $type;
}
echo '<div class="' . $type . '"><p>' . $message . '</p></div>';
}
delete_option('staticwp_deferred_admin_notices');
}
} | [
"public",
"static",
"function",
"displayNotices",
"(",
")",
"{",
"if",
"(",
"$",
"notices",
"=",
"get_option",
"(",
"'staticwp_deferred_admin_notices'",
")",
")",
"{",
"foreach",
"(",
"$",
"notices",
"as",
"$",
"notice",
")",
"{",
"$",
"message",
"=",
"$",
"notice",
";",
"$",
"type",
"=",
"'updated'",
";",
"if",
"(",
"is_array",
"(",
"$",
"notice",
")",
")",
"{",
"$",
"message",
"=",
"isset",
"(",
"$",
"notice",
"[",
"'message'",
"]",
")",
"?",
"$",
"notice",
"[",
"'message'",
"]",
":",
"''",
";",
"$",
"type",
"=",
"isset",
"(",
"$",
"notice",
"[",
"'type'",
"]",
")",
"?",
"$",
"notice",
"[",
"'type'",
"]",
":",
"$",
"type",
";",
"}",
"echo",
"'<div class=\"'",
".",
"$",
"type",
".",
"'\"><p>'",
".",
"$",
"message",
".",
"'</p></div>'",
";",
"}",
"delete_option",
"(",
"'staticwp_deferred_admin_notices'",
")",
";",
"}",
"}"
]
| Displays admin notices.
@since 1.3.0
@return void | [
"Displays",
"admin",
"notices",
"."
]
| e96811e57c521b0dc28fc600647b89828cdba8c0 | https://github.com/slogsdon/staticwp/blob/e96811e57c521b0dc28fc600647b89828cdba8c0/includes/staticwp-admin.class.php#L132-L148 |
14,559 | slogsdon/staticwp | includes/staticwp-admin.class.php | Admin.errorToException | public static function errorToException($num, $mes, $file = null, $line = null, $context = null)
{
throw new Exception($mes, $num);
} | php | public static function errorToException($num, $mes, $file = null, $line = null, $context = null)
{
throw new Exception($mes, $num);
} | [
"public",
"static",
"function",
"errorToException",
"(",
"$",
"num",
",",
"$",
"mes",
",",
"$",
"file",
"=",
"null",
",",
"$",
"line",
"=",
"null",
",",
"$",
"context",
"=",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"mes",
",",
"$",
"num",
")",
";",
"}"
]
| Error handler to convert errors to exceptions to make it
easier to catch them.
@param int $num
@param string $mes
@param string $file
@param int $line
@param array $context
@return bool | [
"Error",
"handler",
"to",
"convert",
"errors",
"to",
"exceptions",
"to",
"make",
"it",
"easier",
"to",
"catch",
"them",
"."
]
| e96811e57c521b0dc28fc600647b89828cdba8c0 | https://github.com/slogsdon/staticwp/blob/e96811e57c521b0dc28fc600647b89828cdba8c0/includes/staticwp-admin.class.php#L162-L165 |
14,560 | slogsdon/staticwp | includes/staticwp-admin.class.php | Admin.handlePost | public function handlePost()
{
if (!isset($_POST['staticwp-action'])) {
return;
}
if (!check_admin_referer('staticwp')) {
return;
}
switch ($_POST['staticwp-action']) {
case 'preload':
set_error_handler(array(__CLASS__, 'errorToException'), E_ALL);
try {
$types = apply_filters('staticwp_preload_post_types', array('post', 'page'));
foreach ($types as $type) {
$this->preload($type);
}
$this->addNotice(View::notice('admin/preload-success'));
} catch (Exception $e) {
$this->addNotice(View::notice('admin/preload-error', 'error'));
}
restore_error_handler();
wp_reset_postdata();
wp_safe_redirect(self::url('preload'));
exit();
break;
default:
break;
}
} | php | public function handlePost()
{
if (!isset($_POST['staticwp-action'])) {
return;
}
if (!check_admin_referer('staticwp')) {
return;
}
switch ($_POST['staticwp-action']) {
case 'preload':
set_error_handler(array(__CLASS__, 'errorToException'), E_ALL);
try {
$types = apply_filters('staticwp_preload_post_types', array('post', 'page'));
foreach ($types as $type) {
$this->preload($type);
}
$this->addNotice(View::notice('admin/preload-success'));
} catch (Exception $e) {
$this->addNotice(View::notice('admin/preload-error', 'error'));
}
restore_error_handler();
wp_reset_postdata();
wp_safe_redirect(self::url('preload'));
exit();
break;
default:
break;
}
} | [
"public",
"function",
"handlePost",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"'staticwp-action'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"check_admin_referer",
"(",
"'staticwp'",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"$",
"_POST",
"[",
"'staticwp-action'",
"]",
")",
"{",
"case",
"'preload'",
":",
"set_error_handler",
"(",
"array",
"(",
"__CLASS__",
",",
"'errorToException'",
")",
",",
"E_ALL",
")",
";",
"try",
"{",
"$",
"types",
"=",
"apply_filters",
"(",
"'staticwp_preload_post_types'",
",",
"array",
"(",
"'post'",
",",
"'page'",
")",
")",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"preload",
"(",
"$",
"type",
")",
";",
"}",
"$",
"this",
"->",
"addNotice",
"(",
"View",
"::",
"notice",
"(",
"'admin/preload-success'",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addNotice",
"(",
"View",
"::",
"notice",
"(",
"'admin/preload-error'",
",",
"'error'",
")",
")",
";",
"}",
"restore_error_handler",
"(",
")",
";",
"wp_reset_postdata",
"(",
")",
";",
"wp_safe_redirect",
"(",
"self",
"::",
"url",
"(",
"'preload'",
")",
")",
";",
"exit",
"(",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"}"
]
| Handles form submission on StaticWP admin pages.
@return void | [
"Handles",
"form",
"submission",
"on",
"StaticWP",
"admin",
"pages",
"."
]
| e96811e57c521b0dc28fc600647b89828cdba8c0 | https://github.com/slogsdon/staticwp/blob/e96811e57c521b0dc28fc600647b89828cdba8c0/includes/staticwp-admin.class.php#L172-L202 |
14,561 | slogsdon/staticwp | includes/staticwp-admin.class.php | Admin.update | public function update()
{
$version = get_option($this->plugin . 'version');
if ($version != STATICWP_VERSION) {
update_option($this->plugin . 'version', STATICWP_VERSION);
}
} | php | public function update()
{
$version = get_option($this->plugin . 'version');
if ($version != STATICWP_VERSION) {
update_option($this->plugin . 'version', STATICWP_VERSION);
}
} | [
"public",
"function",
"update",
"(",
")",
"{",
"$",
"version",
"=",
"get_option",
"(",
"$",
"this",
"->",
"plugin",
".",
"'version'",
")",
";",
"if",
"(",
"$",
"version",
"!=",
"STATICWP_VERSION",
")",
"{",
"update_option",
"(",
"$",
"this",
"->",
"plugin",
".",
"'version'",
",",
"STATICWP_VERSION",
")",
";",
"}",
"}"
]
| Handles plugin updates.
@since 1.3.0
@return void | [
"Handles",
"plugin",
"updates",
"."
]
| e96811e57c521b0dc28fc600647b89828cdba8c0 | https://github.com/slogsdon/staticwp/blob/e96811e57c521b0dc28fc600647b89828cdba8c0/includes/staticwp-admin.class.php#L231-L237 |
14,562 | slogsdon/staticwp | includes/staticwp-admin.class.php | Admin.viewPage | public function viewPage()
{
$page = isset($_GET['sub']) ? (string)$_GET['sub'] : self::DEFAULT_SUB_PAGE;
View::page('admin/' . $page);
} | php | public function viewPage()
{
$page = isset($_GET['sub']) ? (string)$_GET['sub'] : self::DEFAULT_SUB_PAGE;
View::page('admin/' . $page);
} | [
"public",
"function",
"viewPage",
"(",
")",
"{",
"$",
"page",
"=",
"isset",
"(",
"$",
"_GET",
"[",
"'sub'",
"]",
")",
"?",
"(",
"string",
")",
"$",
"_GET",
"[",
"'sub'",
"]",
":",
"self",
"::",
"DEFAULT_SUB_PAGE",
";",
"View",
"::",
"page",
"(",
"'admin/'",
".",
"$",
"page",
")",
";",
"}"
]
| Displays a page.
@since 1.4.2
@return void | [
"Displays",
"a",
"page",
"."
]
| e96811e57c521b0dc28fc600647b89828cdba8c0 | https://github.com/slogsdon/staticwp/blob/e96811e57c521b0dc28fc600647b89828cdba8c0/includes/staticwp-admin.class.php#L261-L265 |
14,563 | slogsdon/staticwp | includes/staticwp-admin.class.php | Admin.preload | protected function preload($post_type = 'post')
{
$args = array(
'fields' => 'ids',
'orderby' => 'post_date',
'order' => 'DESC',
'post_status' => 'publish',
'post_type' => $post_type,
'showposts' => -1,
'suppress_filters' => true,
);
$query = new WP_Query($args);
if ($query->have_posts()) {
$posts = apply_filters('staticwp_preload_' . $post_type . '_posts', $query->posts);
foreach ($posts as $post_id) {
$this->updateHtml($post_id);
}
}
} | php | protected function preload($post_type = 'post')
{
$args = array(
'fields' => 'ids',
'orderby' => 'post_date',
'order' => 'DESC',
'post_status' => 'publish',
'post_type' => $post_type,
'showposts' => -1,
'suppress_filters' => true,
);
$query = new WP_Query($args);
if ($query->have_posts()) {
$posts = apply_filters('staticwp_preload_' . $post_type . '_posts', $query->posts);
foreach ($posts as $post_id) {
$this->updateHtml($post_id);
}
}
} | [
"protected",
"function",
"preload",
"(",
"$",
"post_type",
"=",
"'post'",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'fields'",
"=>",
"'ids'",
",",
"'orderby'",
"=>",
"'post_date'",
",",
"'order'",
"=>",
"'DESC'",
",",
"'post_status'",
"=>",
"'publish'",
",",
"'post_type'",
"=>",
"$",
"post_type",
",",
"'showposts'",
"=>",
"-",
"1",
",",
"'suppress_filters'",
"=>",
"true",
",",
")",
";",
"$",
"query",
"=",
"new",
"WP_Query",
"(",
"$",
"args",
")",
";",
"if",
"(",
"$",
"query",
"->",
"have_posts",
"(",
")",
")",
"{",
"$",
"posts",
"=",
"apply_filters",
"(",
"'staticwp_preload_'",
".",
"$",
"post_type",
".",
"'_posts'",
",",
"$",
"query",
"->",
"posts",
")",
";",
"foreach",
"(",
"$",
"posts",
"as",
"$",
"post_id",
")",
"{",
"$",
"this",
"->",
"updateHtml",
"(",
"$",
"post_id",
")",
";",
"}",
"}",
"}"
]
| Loops through posts to compile static HTML for each.
@since 1.3.0
@return void | [
"Loops",
"through",
"posts",
"to",
"compile",
"static",
"HTML",
"for",
"each",
"."
]
| e96811e57c521b0dc28fc600647b89828cdba8c0 | https://github.com/slogsdon/staticwp/blob/e96811e57c521b0dc28fc600647b89828cdba8c0/includes/staticwp-admin.class.php#L288-L307 |
14,564 | jan-dolata/crude-crud | src/Engine/Helpers/CrudeFiles.php | CrudeFiles.upload | public function upload($model, $folderName, $files, $fileAttrName = 'files', $width = null)
{
$updatedFiles = $model->$fileAttrName;
foreach ($files as $file) {
$log = (new FileLog)->create([
'model_id' => $model->id,
'model_name' => $folderName,
'file_original_name' => $file->getClientOriginalName(),
]);
$systemFileName = $this->createSystemFileName($log, $file);
$filePath = $this->createFilePath($folderName, $systemFileName);
$folderPath = $this->createFilePath($folderName);
Storage::put(
$filePath,
file_get_contents($file->path())
);
$log->fill([
'file_path' => $filePath,
'file_system_name' => $systemFileName
])->save();
if ($width)
$this->imageResize($width, $file, $filePath);
$updatedFiles[] = [
'file_log_id' => $log->id,
'path' => asset($log->file_path),
'file_original_name' => $log->file_original_name
];
}
$model->$fileAttrName = $updatedFiles;
return $model;
} | php | public function upload($model, $folderName, $files, $fileAttrName = 'files', $width = null)
{
$updatedFiles = $model->$fileAttrName;
foreach ($files as $file) {
$log = (new FileLog)->create([
'model_id' => $model->id,
'model_name' => $folderName,
'file_original_name' => $file->getClientOriginalName(),
]);
$systemFileName = $this->createSystemFileName($log, $file);
$filePath = $this->createFilePath($folderName, $systemFileName);
$folderPath = $this->createFilePath($folderName);
Storage::put(
$filePath,
file_get_contents($file->path())
);
$log->fill([
'file_path' => $filePath,
'file_system_name' => $systemFileName
])->save();
if ($width)
$this->imageResize($width, $file, $filePath);
$updatedFiles[] = [
'file_log_id' => $log->id,
'path' => asset($log->file_path),
'file_original_name' => $log->file_original_name
];
}
$model->$fileAttrName = $updatedFiles;
return $model;
} | [
"public",
"function",
"upload",
"(",
"$",
"model",
",",
"$",
"folderName",
",",
"$",
"files",
",",
"$",
"fileAttrName",
"=",
"'files'",
",",
"$",
"width",
"=",
"null",
")",
"{",
"$",
"updatedFiles",
"=",
"$",
"model",
"->",
"$",
"fileAttrName",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"log",
"=",
"(",
"new",
"FileLog",
")",
"->",
"create",
"(",
"[",
"'model_id'",
"=>",
"$",
"model",
"->",
"id",
",",
"'model_name'",
"=>",
"$",
"folderName",
",",
"'file_original_name'",
"=>",
"$",
"file",
"->",
"getClientOriginalName",
"(",
")",
",",
"]",
")",
";",
"$",
"systemFileName",
"=",
"$",
"this",
"->",
"createSystemFileName",
"(",
"$",
"log",
",",
"$",
"file",
")",
";",
"$",
"filePath",
"=",
"$",
"this",
"->",
"createFilePath",
"(",
"$",
"folderName",
",",
"$",
"systemFileName",
")",
";",
"$",
"folderPath",
"=",
"$",
"this",
"->",
"createFilePath",
"(",
"$",
"folderName",
")",
";",
"Storage",
"::",
"put",
"(",
"$",
"filePath",
",",
"file_get_contents",
"(",
"$",
"file",
"->",
"path",
"(",
")",
")",
")",
";",
"$",
"log",
"->",
"fill",
"(",
"[",
"'file_path'",
"=>",
"$",
"filePath",
",",
"'file_system_name'",
"=>",
"$",
"systemFileName",
"]",
")",
"->",
"save",
"(",
")",
";",
"if",
"(",
"$",
"width",
")",
"$",
"this",
"->",
"imageResize",
"(",
"$",
"width",
",",
"$",
"file",
",",
"$",
"filePath",
")",
";",
"$",
"updatedFiles",
"[",
"]",
"=",
"[",
"'file_log_id'",
"=>",
"$",
"log",
"->",
"id",
",",
"'path'",
"=>",
"asset",
"(",
"$",
"log",
"->",
"file_path",
")",
",",
"'file_original_name'",
"=>",
"$",
"log",
"->",
"file_original_name",
"]",
";",
"}",
"$",
"model",
"->",
"$",
"fileAttrName",
"=",
"$",
"updatedFiles",
";",
"return",
"$",
"model",
";",
"}"
]
| Upload files for model, without save model
@param Model $model - with 'files' attribute
@param string $folderName
@param Files $files
@return Model | [
"Upload",
"files",
"for",
"model",
"without",
"save",
"model"
]
| 9129ea08278835cf5cecfd46a90369226ae6bdd7 | https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Helpers/CrudeFiles.php#L21-L59 |
14,565 | jan-dolata/crude-crud | src/Engine/Helpers/CrudeFiles.php | CrudeFiles.delete | public function delete($model, $log, $fileAttrName = 'files', $fileLogId = 0)
{
$updatedFiles = [];
if ($log)
$fileLogId = $log->id;
$fileToDelete = [];
foreach ($model->files as $file) {
if ($file['file_log_id'] == $fileLogId)
$fileToDelete = $file;
else
$updatedFiles[] = $file;
}
if ($log)
Storage::delete($log->file_path);
else
Storage::delete($fileToDelete['path']);
if ($log)
$log->delete();
$model->$fileAttrName = $updatedFiles;
return $model;
} | php | public function delete($model, $log, $fileAttrName = 'files', $fileLogId = 0)
{
$updatedFiles = [];
if ($log)
$fileLogId = $log->id;
$fileToDelete = [];
foreach ($model->files as $file) {
if ($file['file_log_id'] == $fileLogId)
$fileToDelete = $file;
else
$updatedFiles[] = $file;
}
if ($log)
Storage::delete($log->file_path);
else
Storage::delete($fileToDelete['path']);
if ($log)
$log->delete();
$model->$fileAttrName = $updatedFiles;
return $model;
} | [
"public",
"function",
"delete",
"(",
"$",
"model",
",",
"$",
"log",
",",
"$",
"fileAttrName",
"=",
"'files'",
",",
"$",
"fileLogId",
"=",
"0",
")",
"{",
"$",
"updatedFiles",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"log",
")",
"$",
"fileLogId",
"=",
"$",
"log",
"->",
"id",
";",
"$",
"fileToDelete",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"model",
"->",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"[",
"'file_log_id'",
"]",
"==",
"$",
"fileLogId",
")",
"$",
"fileToDelete",
"=",
"$",
"file",
";",
"else",
"$",
"updatedFiles",
"[",
"]",
"=",
"$",
"file",
";",
"}",
"if",
"(",
"$",
"log",
")",
"Storage",
"::",
"delete",
"(",
"$",
"log",
"->",
"file_path",
")",
";",
"else",
"Storage",
"::",
"delete",
"(",
"$",
"fileToDelete",
"[",
"'path'",
"]",
")",
";",
"if",
"(",
"$",
"log",
")",
"$",
"log",
"->",
"delete",
"(",
")",
";",
"$",
"model",
"->",
"$",
"fileAttrName",
"=",
"$",
"updatedFiles",
";",
"return",
"$",
"model",
";",
"}"
]
| Delete file for model, without save model
@param Model $model
@param FileLog $log
@param String $fileAttrName = 'files'
@param String $fileLogId = 0 - used when log is missing
@return Model | [
"Delete",
"file",
"for",
"model",
"without",
"save",
"model"
]
| 9129ea08278835cf5cecfd46a90369226ae6bdd7 | https://github.com/jan-dolata/crude-crud/blob/9129ea08278835cf5cecfd46a90369226ae6bdd7/src/Engine/Helpers/CrudeFiles.php#L82-L106 |
14,566 | activecollab/databasestructure | src/Field/Scalar/Traits/SizeInterface/Implementation.php | Implementation.getSupportedSizes | protected function getSupportedSizes()
{
return [FieldInterface::SIZE_TINY, FieldInterface::SIZE_SMALL, FieldInterface::SIZE_MEDIUM, FieldInterface::SIZE_NORMAL, FieldInterface::SIZE_BIG];
} | php | protected function getSupportedSizes()
{
return [FieldInterface::SIZE_TINY, FieldInterface::SIZE_SMALL, FieldInterface::SIZE_MEDIUM, FieldInterface::SIZE_NORMAL, FieldInterface::SIZE_BIG];
} | [
"protected",
"function",
"getSupportedSizes",
"(",
")",
"{",
"return",
"[",
"FieldInterface",
"::",
"SIZE_TINY",
",",
"FieldInterface",
"::",
"SIZE_SMALL",
",",
"FieldInterface",
"::",
"SIZE_MEDIUM",
",",
"FieldInterface",
"::",
"SIZE_NORMAL",
",",
"FieldInterface",
"::",
"SIZE_BIG",
"]",
";",
"}"
]
| Return an array of supported sizes.
@return array | [
"Return",
"an",
"array",
"of",
"supported",
"sizes",
"."
]
| 4b2353c4422186bcfce63b3212da3e70e63eb5df | https://github.com/activecollab/databasestructure/blob/4b2353c4422186bcfce63b3212da3e70e63eb5df/src/Field/Scalar/Traits/SizeInterface/Implementation.php#L54-L57 |
14,567 | okvpn/fixture-bundle | src/Command/LoadDataFixturesCommand.php | LoadDataFixturesCommand.outputFixtures | protected function outputFixtures(InputInterface $input, OutputInterface $output, $fixtures)
{
$output->writeln(
sprintf(
'List of "%s" data fixtures ...',
$this->getTypeOfFixtures($input)
)
);
foreach ($fixtures as $fixture) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', get_class($fixture)));
}
} | php | protected function outputFixtures(InputInterface $input, OutputInterface $output, $fixtures)
{
$output->writeln(
sprintf(
'List of "%s" data fixtures ...',
$this->getTypeOfFixtures($input)
)
);
foreach ($fixtures as $fixture) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', get_class($fixture)));
}
} | [
"protected",
"function",
"outputFixtures",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"$",
"fixtures",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'List of \"%s\" data fixtures ...'",
",",
"$",
"this",
"->",
"getTypeOfFixtures",
"(",
"$",
"input",
")",
")",
")",
";",
"foreach",
"(",
"$",
"fixtures",
"as",
"$",
"fixture",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"' <comment>></comment> <info>%s</info>'",
",",
"get_class",
"(",
"$",
"fixture",
")",
")",
")",
";",
"}",
"}"
]
| Output list of fixtures
@param InputInterface $input
@param OutputInterface $output
@param array $fixtures | [
"Output",
"list",
"of",
"fixtures"
]
| 243b5e4dff9773e97fa447280e929c936a5d66ae | https://github.com/okvpn/fixture-bundle/blob/243b5e4dff9773e97fa447280e929c936a5d66ae/src/Command/LoadDataFixturesCommand.php#L133-L144 |
14,568 | comelyio/comely | src/Comely/IO/Events/EventsHandler.php | EventsHandler.on | public function on(string $tag): Event
{
// Look for existing Event
$event = $this->events[$tag] ?? null;
if ($event) { // Found?
return $event; // Return existing Event
}
// Register and return instance of new Event
return $this->events[$tag] = new Event($this, $tag);
} | php | public function on(string $tag): Event
{
// Look for existing Event
$event = $this->events[$tag] ?? null;
if ($event) { // Found?
return $event; // Return existing Event
}
// Register and return instance of new Event
return $this->events[$tag] = new Event($this, $tag);
} | [
"public",
"function",
"on",
"(",
"string",
"$",
"tag",
")",
":",
"Event",
"{",
"// Look for existing Event",
"$",
"event",
"=",
"$",
"this",
"->",
"events",
"[",
"$",
"tag",
"]",
"??",
"null",
";",
"if",
"(",
"$",
"event",
")",
"{",
"// Found?",
"return",
"$",
"event",
";",
"// Return existing Event",
"}",
"// Register and return instance of new Event",
"return",
"$",
"this",
"->",
"events",
"[",
"$",
"tag",
"]",
"=",
"new",
"Event",
"(",
"$",
"this",
",",
"$",
"tag",
")",
";",
"}"
]
| Returns a registered Event if exists, otherwise creates a new Event
@param string $tag
@return Event | [
"Returns",
"a",
"registered",
"Event",
"if",
"exists",
"otherwise",
"creates",
"a",
"new",
"Event"
]
| 561ea7aef36fea347a1a79d3ee5597d4057ddf82 | https://github.com/comelyio/comely/blob/561ea7aef36fea347a1a79d3ee5597d4057ddf82/src/Comely/IO/Events/EventsHandler.php#L43-L53 |
14,569 | kderyabin/logger | src/Utils/Stringer.php | Stringer.stringify | public static function stringify($value)
{
if (is_string($value)) {
return $value;
}
if ($value === null || is_bool($value)) {
return var_export($value, true);
}
if (is_array($value) || (is_object($value) && !method_exists($value, '__toString'))) {
return json_encode($value, JSON_ERROR_NONE | JSON_UNESCAPED_SLASHES);
}
return (string)$value;
} | php | public static function stringify($value)
{
if (is_string($value)) {
return $value;
}
if ($value === null || is_bool($value)) {
return var_export($value, true);
}
if (is_array($value) || (is_object($value) && !method_exists($value, '__toString'))) {
return json_encode($value, JSON_ERROR_NONE | JSON_UNESCAPED_SLASHES);
}
return (string)$value;
} | [
"public",
"static",
"function",
"stringify",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"return",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"!",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
")",
"{",
"return",
"json_encode",
"(",
"$",
"value",
",",
"JSON_ERROR_NONE",
"|",
"JSON_UNESCAPED_SLASHES",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"value",
";",
"}"
]
| Converts a value into a string.
@param mixed $value
@return string | [
"Converts",
"a",
"value",
"into",
"a",
"string",
"."
]
| 683890192b37fe9d36611972e12c2994669f5b85 | https://github.com/kderyabin/logger/blob/683890192b37fe9d36611972e12c2994669f5b85/src/Utils/Stringer.php#L19-L32 |
14,570 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.intAdd | public function intAdd(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new IntType($a() + $b());
} | php | public function intAdd(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new IntType($a() + $b());
} | [
"public",
"function",
"intAdd",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkIntTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"new",
"IntType",
"(",
"$",
"a",
"(",
")",
"+",
"$",
"b",
"(",
")",
")",
";",
"}"
]
| Integer type addition
@param NI $a first operand
@param NI $b second operand
@return IntType | [
"Integer",
"type",
"addition"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L54-L59 |
14,571 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.intSub | public function intSub(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new IntType($a() - $b());
} | php | public function intSub(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new IntType($a() - $b());
} | [
"public",
"function",
"intSub",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkIntTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"new",
"IntType",
"(",
"$",
"a",
"(",
")",
"-",
"$",
"b",
"(",
")",
")",
";",
"}"
]
| Integer type subtraction
@param NI $a first operand
@param NI $b second operand
@return IntType | [
"Integer",
"type",
"subtraction"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L69-L74 |
14,572 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.intMul | public function intMul(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new IntType($a() * $b());
} | php | public function intMul(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new IntType($a() * $b());
} | [
"public",
"function",
"intMul",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkIntTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"new",
"IntType",
"(",
"$",
"a",
"(",
")",
"*",
"$",
"b",
"(",
")",
")",
";",
"}"
]
| Integer type multiplication
@param NI $a first operand
@param NI $b second operand
@return IntType | [
"Integer",
"type",
"multiplication"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L84-L89 |
14,573 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.intPow | public function intPow(IntType $a, NI $exp)
{
if ($exp instanceof RationalType) {
$b = new RationalType(clone $a, new IntType(1));
return $this->rationalPow($b, $exp);
}
if ($exp instanceof ComplexType) {
return $this->intComplexPow($a(), $exp);
}
//int and float types
$p = pow($a(), $exp());
if (($p - intval($p)) === 0) {
return new IntType($p);
}
return RationalTypeFactory::fromFloat($p);
} | php | public function intPow(IntType $a, NI $exp)
{
if ($exp instanceof RationalType) {
$b = new RationalType(clone $a, new IntType(1));
return $this->rationalPow($b, $exp);
}
if ($exp instanceof ComplexType) {
return $this->intComplexPow($a(), $exp);
}
//int and float types
$p = pow($a(), $exp());
if (($p - intval($p)) === 0) {
return new IntType($p);
}
return RationalTypeFactory::fromFloat($p);
} | [
"public",
"function",
"intPow",
"(",
"IntType",
"$",
"a",
",",
"NI",
"$",
"exp",
")",
"{",
"if",
"(",
"$",
"exp",
"instanceof",
"RationalType",
")",
"{",
"$",
"b",
"=",
"new",
"RationalType",
"(",
"clone",
"$",
"a",
",",
"new",
"IntType",
"(",
"1",
")",
")",
";",
"return",
"$",
"this",
"->",
"rationalPow",
"(",
"$",
"b",
",",
"$",
"exp",
")",
";",
"}",
"if",
"(",
"$",
"exp",
"instanceof",
"ComplexType",
")",
"{",
"return",
"$",
"this",
"->",
"intComplexPow",
"(",
"$",
"a",
"(",
")",
",",
"$",
"exp",
")",
";",
"}",
"//int and float types",
"$",
"p",
"=",
"pow",
"(",
"$",
"a",
"(",
")",
",",
"$",
"exp",
"(",
")",
")",
";",
"if",
"(",
"(",
"$",
"p",
"-",
"intval",
"(",
"$",
"p",
")",
")",
"===",
"0",
")",
"{",
"return",
"new",
"IntType",
"(",
"$",
"p",
")",
";",
"}",
"return",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"p",
")",
";",
"}"
]
| Integer Pow - raise number to the exponent
Will return an IntType, RationalType or ComplexType
@param IntType $a operand
@param NI $exp Exponent
@return NI | [
"Integer",
"Pow",
"-",
"raise",
"number",
"to",
"the",
"exponent",
"Will",
"return",
"an",
"IntType",
"RationalType",
"or",
"ComplexType"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L115-L133 |
14,574 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.intSqrt | public function intSqrt(IntType $a)
{
$res = $this->rationalSqrt(new RationalType($a, new IntType(1)));
if ($res->isInteger()) {
return $res->numerator();
}
return $res;
} | php | public function intSqrt(IntType $a)
{
$res = $this->rationalSqrt(new RationalType($a, new IntType(1)));
if ($res->isInteger()) {
return $res->numerator();
}
return $res;
} | [
"public",
"function",
"intSqrt",
"(",
"IntType",
"$",
"a",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"rationalSqrt",
"(",
"new",
"RationalType",
"(",
"$",
"a",
",",
"new",
"IntType",
"(",
"1",
")",
")",
")",
";",
"if",
"(",
"$",
"res",
"->",
"isInteger",
"(",
")",
")",
"{",
"return",
"$",
"res",
"->",
"numerator",
"(",
")",
";",
"}",
"return",
"$",
"res",
";",
"}"
]
| Integer sqrt
Return IntType for perfect squares, else RationalType
@param IntType $a operand
@return IntType|RationalType result | [
"Integer",
"sqrt",
"Return",
"IntType",
"for",
"perfect",
"squares",
"else",
"RationalType"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L143-L151 |
14,575 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.floatPow | public function floatPow(FloatType $a, NI $exp)
{
if ($exp instanceof RationalType) {
$b = RationalTypeFactory::fromFloat($a());
return $this->rationalPow($b, $exp)->asFloatType();
}
if ($exp instanceof ComplexType) {
return $this->floatComplexPow($a(), $exp);
}
//int and float types
$p = pow($a(), $exp());
return new FloatType($p);
} | php | public function floatPow(FloatType $a, NI $exp)
{
if ($exp instanceof RationalType) {
$b = RationalTypeFactory::fromFloat($a());
return $this->rationalPow($b, $exp)->asFloatType();
}
if ($exp instanceof ComplexType) {
return $this->floatComplexPow($a(), $exp);
}
//int and float types
$p = pow($a(), $exp());
return new FloatType($p);
} | [
"public",
"function",
"floatPow",
"(",
"FloatType",
"$",
"a",
",",
"NI",
"$",
"exp",
")",
"{",
"if",
"(",
"$",
"exp",
"instanceof",
"RationalType",
")",
"{",
"$",
"b",
"=",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"a",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"rationalPow",
"(",
"$",
"b",
",",
"$",
"exp",
")",
"->",
"asFloatType",
"(",
")",
";",
"}",
"if",
"(",
"$",
"exp",
"instanceof",
"ComplexType",
")",
"{",
"return",
"$",
"this",
"->",
"floatComplexPow",
"(",
"$",
"a",
"(",
")",
",",
"$",
"exp",
")",
";",
"}",
"//int and float types",
"$",
"p",
"=",
"pow",
"(",
"$",
"a",
"(",
")",
",",
"$",
"exp",
"(",
")",
")",
";",
"return",
"new",
"FloatType",
"(",
"$",
"p",
")",
";",
"}"
]
| Float Pow - raise number to the exponent
Will return a float type
@param FloatType $a operand
@param NI $exp Exponent
@return FloatType | [
"Float",
"Pow",
"-",
"raise",
"number",
"to",
"the",
"exponent",
"Will",
"return",
"a",
"float",
"type"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L230-L245 |
14,576 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.wholeAdd | public function wholeAdd(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new WholeIntType($a() + $b());
} | php | public function wholeAdd(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new WholeIntType($a() + $b());
} | [
"public",
"function",
"wholeAdd",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkIntTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"new",
"WholeIntType",
"(",
"$",
"a",
"(",
")",
"+",
"$",
"b",
"(",
")",
")",
";",
"}"
]
| Whole number addition
@param NI $a first operand
@param NI $b second operand
@return WholeIntType | [
"Whole",
"number",
"addition"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L267-L271 |
14,577 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.wholeSub | public function wholeSub(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new WholeIntType($a() - $b());
} | php | public function wholeSub(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new WholeIntType($a() - $b());
} | [
"public",
"function",
"wholeSub",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkIntTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"new",
"WholeIntType",
"(",
"$",
"a",
"(",
")",
"-",
"$",
"b",
"(",
")",
")",
";",
"}"
]
| Whole number subtraction
@param NI $a first operand
@param NI $b second operand
@return WholeIntType | [
"Whole",
"number",
"subtraction"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L281-L285 |
14,578 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.wholeMul | public function wholeMul(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new WholeIntType($a() * $b());
} | php | public function wholeMul(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new WholeIntType($a() * $b());
} | [
"public",
"function",
"wholeMul",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkIntTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"new",
"WholeIntType",
"(",
"$",
"a",
"(",
")",
"*",
"$",
"b",
"(",
")",
")",
";",
"}"
]
| Whole number multiplication
@param NI $a first operand
@param NI $b second operand
@return WholeIntType | [
"Whole",
"number",
"multiplication"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L295-L299 |
14,579 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.naturalAdd | public function naturalAdd(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new NaturalIntType($a() + $b());
} | php | public function naturalAdd(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new NaturalIntType($a() + $b());
} | [
"public",
"function",
"naturalAdd",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkIntTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"new",
"NaturalIntType",
"(",
"$",
"a",
"(",
")",
"+",
"$",
"b",
"(",
")",
")",
";",
"}"
]
| Natural number addition
@param NI $a first operand
@param NI $b second operand
@return NaturalIntType | [
"Natural",
"number",
"addition"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L309-L313 |
14,580 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.naturalSub | public function naturalSub(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new NaturalIntType($a() - $b());
} | php | public function naturalSub(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new NaturalIntType($a() - $b());
} | [
"public",
"function",
"naturalSub",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkIntTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"new",
"NaturalIntType",
"(",
"$",
"a",
"(",
")",
"-",
"$",
"b",
"(",
")",
")",
";",
"}"
]
| Natural number subtraction
@param NI $a first operand
@param NI $b second operand
@return NaturalIntType | [
"Natural",
"number",
"subtraction"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L323-L327 |
14,581 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.naturalMul | public function naturalMul(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new NaturalIntType($a() * $b());
} | php | public function naturalMul(NI $a, NI $b)
{
list($a, $b) = $this->checkIntTypes($a, $b);
return new NaturalIntType($a() * $b());
} | [
"public",
"function",
"naturalMul",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkIntTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"new",
"NaturalIntType",
"(",
"$",
"a",
"(",
")",
"*",
"$",
"b",
"(",
")",
")",
";",
"}"
]
| Natural number multiplication
@param NI $a first operand
@param NI $b second operand
@return NaturalIntType | [
"Natural",
"number",
"multiplication"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L337-L341 |
14,582 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.rationalAdd | public function rationalAdd(NI $a, NI $b)
{
if (!$a instanceof RationalType) {
$a = $a->asRational();
}
if (!$b instanceof RationalType) {
$b = $b->asRational();
}
$d = RationalTypeFactory::create($this->lcm($a->denominator()->get(), $b->denominator()->get()));
$nn = $this->rationalDiv($this->rationalMul($a->numerator(), $d), $a->denominator())->get();
$nd = $this->rationalDiv($this->rationalMul($b->numerator(), $d), $b->denominator())->get();
$n = $this->intAdd(new IntType($nn), new IntType($nd));
return RationalTypeFactory::create($n, $d->numerator());
} | php | public function rationalAdd(NI $a, NI $b)
{
if (!$a instanceof RationalType) {
$a = $a->asRational();
}
if (!$b instanceof RationalType) {
$b = $b->asRational();
}
$d = RationalTypeFactory::create($this->lcm($a->denominator()->get(), $b->denominator()->get()));
$nn = $this->rationalDiv($this->rationalMul($a->numerator(), $d), $a->denominator())->get();
$nd = $this->rationalDiv($this->rationalMul($b->numerator(), $d), $b->denominator())->get();
$n = $this->intAdd(new IntType($nn), new IntType($nd));
return RationalTypeFactory::create($n, $d->numerator());
} | [
"public",
"function",
"rationalAdd",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"if",
"(",
"!",
"$",
"a",
"instanceof",
"RationalType",
")",
"{",
"$",
"a",
"=",
"$",
"a",
"->",
"asRational",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"b",
"instanceof",
"RationalType",
")",
"{",
"$",
"b",
"=",
"$",
"b",
"->",
"asRational",
"(",
")",
";",
"}",
"$",
"d",
"=",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"this",
"->",
"lcm",
"(",
"$",
"a",
"->",
"denominator",
"(",
")",
"->",
"get",
"(",
")",
",",
"$",
"b",
"->",
"denominator",
"(",
")",
"->",
"get",
"(",
")",
")",
")",
";",
"$",
"nn",
"=",
"$",
"this",
"->",
"rationalDiv",
"(",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"numerator",
"(",
")",
",",
"$",
"d",
")",
",",
"$",
"a",
"->",
"denominator",
"(",
")",
")",
"->",
"get",
"(",
")",
";",
"$",
"nd",
"=",
"$",
"this",
"->",
"rationalDiv",
"(",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"b",
"->",
"numerator",
"(",
")",
",",
"$",
"d",
")",
",",
"$",
"b",
"->",
"denominator",
"(",
")",
")",
"->",
"get",
"(",
")",
";",
"$",
"n",
"=",
"$",
"this",
"->",
"intAdd",
"(",
"new",
"IntType",
"(",
"$",
"nn",
")",
",",
"new",
"IntType",
"(",
"$",
"nd",
")",
")",
";",
"return",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"n",
",",
"$",
"d",
"->",
"numerator",
"(",
")",
")",
";",
"}"
]
| Rational number addition
@param NI $a first operand
@param NI $b second operand
@return RationalType | [
"Rational",
"number",
"addition"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L351-L366 |
14,583 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.rationalSub | public function rationalSub(NI $a, NI $b)
{
list($a, $b) = $this->checkRationalTypes($a, $b);
$d = RationalTypeFactory::create($this->lcm($a->denominator()->get(), $b->denominator()->get()));
$nn = $this->rationalDiv($this->rationalMul($a->numerator(), $d), $a->denominator())->get();
$nd = $this->rationalDiv($this->rationalMul($b->numerator(), $d), $b->denominator())->get();
$n = $this->intSub(new IntType($nn), new IntType($nd));
return RationalTypeFactory::create($n, $d->numerator());
} | php | public function rationalSub(NI $a, NI $b)
{
list($a, $b) = $this->checkRationalTypes($a, $b);
$d = RationalTypeFactory::create($this->lcm($a->denominator()->get(), $b->denominator()->get()));
$nn = $this->rationalDiv($this->rationalMul($a->numerator(), $d), $a->denominator())->get();
$nd = $this->rationalDiv($this->rationalMul($b->numerator(), $d), $b->denominator())->get();
$n = $this->intSub(new IntType($nn), new IntType($nd));
return RationalTypeFactory::create($n, $d->numerator());
} | [
"public",
"function",
"rationalSub",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkRationalTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"$",
"d",
"=",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"this",
"->",
"lcm",
"(",
"$",
"a",
"->",
"denominator",
"(",
")",
"->",
"get",
"(",
")",
",",
"$",
"b",
"->",
"denominator",
"(",
")",
"->",
"get",
"(",
")",
")",
")",
";",
"$",
"nn",
"=",
"$",
"this",
"->",
"rationalDiv",
"(",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"numerator",
"(",
")",
",",
"$",
"d",
")",
",",
"$",
"a",
"->",
"denominator",
"(",
")",
")",
"->",
"get",
"(",
")",
";",
"$",
"nd",
"=",
"$",
"this",
"->",
"rationalDiv",
"(",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"b",
"->",
"numerator",
"(",
")",
",",
"$",
"d",
")",
",",
"$",
"b",
"->",
"denominator",
"(",
")",
")",
"->",
"get",
"(",
")",
";",
"$",
"n",
"=",
"$",
"this",
"->",
"intSub",
"(",
"new",
"IntType",
"(",
"$",
"nn",
")",
",",
"new",
"IntType",
"(",
"$",
"nd",
")",
")",
";",
"return",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"n",
",",
"$",
"d",
"->",
"numerator",
"(",
")",
")",
";",
"}"
]
| Rational number subtraction
@param NI $a first operand
@param NI $b second operand
@return RationalType | [
"Rational",
"number",
"subtraction"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L376-L385 |
14,584 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.rationalDiv | public function rationalDiv(NI $a, NI $b)
{
list($a, $b) = $this->checkRationalTypes($a, $b);
$n = $this->intMul($a->numerator(), $b->denominator());
$d = $this->intMul($a->denominator(), $b->numerator());
return RationalTypeFactory::create($n, $d);
} | php | public function rationalDiv(NI $a, NI $b)
{
list($a, $b) = $this->checkRationalTypes($a, $b);
$n = $this->intMul($a->numerator(), $b->denominator());
$d = $this->intMul($a->denominator(), $b->numerator());
return RationalTypeFactory::create($n, $d);
} | [
"public",
"function",
"rationalDiv",
"(",
"NI",
"$",
"a",
",",
"NI",
"$",
"b",
")",
"{",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"$",
"this",
"->",
"checkRationalTypes",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"$",
"n",
"=",
"$",
"this",
"->",
"intMul",
"(",
"$",
"a",
"->",
"numerator",
"(",
")",
",",
"$",
"b",
"->",
"denominator",
"(",
")",
")",
";",
"$",
"d",
"=",
"$",
"this",
"->",
"intMul",
"(",
"$",
"a",
"->",
"denominator",
"(",
")",
",",
"$",
"b",
"->",
"numerator",
"(",
")",
")",
";",
"return",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"n",
",",
"$",
"d",
")",
";",
"}"
]
| Rational number division
@param NI $a first operand
@param NI $b second operand
@return RationalType | [
"Rational",
"number",
"division"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L412-L419 |
14,585 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.rationalPow | public function rationalPow(RationalType $a, NI $exp)
{
if ($exp instanceof ComplexType) {
$r = $this->floatComplexPow($a(), $exp);
if ($r instanceof FloatType) {
return RationalTypeFactory::fromFloat($r());
}
return $r;
}
$exp2 = $exp->get();
$numF = pow($a->numerator()->get(), $exp2);
$denF = pow($a->denominator()->get(), $exp2);
$numR = RationalTypeFactory::fromFloat($numF);
$denR = RationalTypeFactory::fromFloat($denF);
return $this->rationalDiv($numR, $denR);
} | php | public function rationalPow(RationalType $a, NI $exp)
{
if ($exp instanceof ComplexType) {
$r = $this->floatComplexPow($a(), $exp);
if ($r instanceof FloatType) {
return RationalTypeFactory::fromFloat($r());
}
return $r;
}
$exp2 = $exp->get();
$numF = pow($a->numerator()->get(), $exp2);
$denF = pow($a->denominator()->get(), $exp2);
$numR = RationalTypeFactory::fromFloat($numF);
$denR = RationalTypeFactory::fromFloat($denF);
return $this->rationalDiv($numR, $denR);
} | [
"public",
"function",
"rationalPow",
"(",
"RationalType",
"$",
"a",
",",
"NI",
"$",
"exp",
")",
"{",
"if",
"(",
"$",
"exp",
"instanceof",
"ComplexType",
")",
"{",
"$",
"r",
"=",
"$",
"this",
"->",
"floatComplexPow",
"(",
"$",
"a",
"(",
")",
",",
"$",
"exp",
")",
";",
"if",
"(",
"$",
"r",
"instanceof",
"FloatType",
")",
"{",
"return",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"r",
"(",
")",
")",
";",
"}",
"return",
"$",
"r",
";",
"}",
"$",
"exp2",
"=",
"$",
"exp",
"->",
"get",
"(",
")",
";",
"$",
"numF",
"=",
"pow",
"(",
"$",
"a",
"->",
"numerator",
"(",
")",
"->",
"get",
"(",
")",
",",
"$",
"exp2",
")",
";",
"$",
"denF",
"=",
"pow",
"(",
"$",
"a",
"->",
"denominator",
"(",
")",
"->",
"get",
"(",
")",
",",
"$",
"exp2",
")",
";",
"$",
"numR",
"=",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"numF",
")",
";",
"$",
"denR",
"=",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"denF",
")",
";",
"return",
"$",
"this",
"->",
"rationalDiv",
"(",
"$",
"numR",
",",
"$",
"denR",
")",
";",
"}"
]
| Rational Pow - raise number to the exponent
Will return a RationalType
@param RationalType $a operand
@param NI $exp exponent
@return NI | [
"Rational",
"Pow",
"-",
"raise",
"number",
"to",
"the",
"exponent",
"Will",
"return",
"a",
"RationalType"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L442-L459 |
14,586 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.complexAdd | public function complexAdd(ComplexType $a, ComplexType $b)
{
$r = $this->rationalAdd($a->r(), $b->r());
$i = $this->rationalAdd($a->i(), $b->i());
return ComplexTypeFactory::create($r, $i);
} | php | public function complexAdd(ComplexType $a, ComplexType $b)
{
$r = $this->rationalAdd($a->r(), $b->r());
$i = $this->rationalAdd($a->i(), $b->i());
return ComplexTypeFactory::create($r, $i);
} | [
"public",
"function",
"complexAdd",
"(",
"ComplexType",
"$",
"a",
",",
"ComplexType",
"$",
"b",
")",
"{",
"$",
"r",
"=",
"$",
"this",
"->",
"rationalAdd",
"(",
"$",
"a",
"->",
"r",
"(",
")",
",",
"$",
"b",
"->",
"r",
"(",
")",
")",
";",
"$",
"i",
"=",
"$",
"this",
"->",
"rationalAdd",
"(",
"$",
"a",
"->",
"i",
"(",
")",
",",
"$",
"b",
"->",
"i",
"(",
")",
")",
";",
"return",
"ComplexTypeFactory",
"::",
"create",
"(",
"$",
"r",
",",
"$",
"i",
")",
";",
"}"
]
| Complex number addition
@param ComplexType $a first operand
@param ComplexType $b second operand
@return ComplexType | [
"Complex",
"number",
"addition"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L487-L492 |
14,587 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.complexSub | public function complexSub(ComplexType $a, ComplexType $b)
{
$r = $this->rationalSub($a->r(), $b->r());
$i = $this->rationalSub($a->i(), $b->i());
return ComplexTypeFactory::create($r, $i);
} | php | public function complexSub(ComplexType $a, ComplexType $b)
{
$r = $this->rationalSub($a->r(), $b->r());
$i = $this->rationalSub($a->i(), $b->i());
return ComplexTypeFactory::create($r, $i);
} | [
"public",
"function",
"complexSub",
"(",
"ComplexType",
"$",
"a",
",",
"ComplexType",
"$",
"b",
")",
"{",
"$",
"r",
"=",
"$",
"this",
"->",
"rationalSub",
"(",
"$",
"a",
"->",
"r",
"(",
")",
",",
"$",
"b",
"->",
"r",
"(",
")",
")",
";",
"$",
"i",
"=",
"$",
"this",
"->",
"rationalSub",
"(",
"$",
"a",
"->",
"i",
"(",
")",
",",
"$",
"b",
"->",
"i",
"(",
")",
")",
";",
"return",
"ComplexTypeFactory",
"::",
"create",
"(",
"$",
"r",
",",
"$",
"i",
")",
";",
"}"
]
| Complex number subtraction
@param ComplexType $a first operand
@param ComplexType $b second operand
@return ComplexType | [
"Complex",
"number",
"subtraction"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L502-L507 |
14,588 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.complexMul | public function complexMul(ComplexType $a, ComplexType $b)
{
$r = $this->rationalSub(
$this->rationalMul($a->r(), $b->r()),
$this->rationalMul($a->i(), $b->i())
);
$i = $this->rationalAdd(
$this->rationalMul($a->i(), $b->r()),
$this->rationalMul($a->r(), $b->i())
);
return ComplexTypeFactory::create($r, $i);
} | php | public function complexMul(ComplexType $a, ComplexType $b)
{
$r = $this->rationalSub(
$this->rationalMul($a->r(), $b->r()),
$this->rationalMul($a->i(), $b->i())
);
$i = $this->rationalAdd(
$this->rationalMul($a->i(), $b->r()),
$this->rationalMul($a->r(), $b->i())
);
return ComplexTypeFactory::create($r, $i);
} | [
"public",
"function",
"complexMul",
"(",
"ComplexType",
"$",
"a",
",",
"ComplexType",
"$",
"b",
")",
"{",
"$",
"r",
"=",
"$",
"this",
"->",
"rationalSub",
"(",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"r",
"(",
")",
",",
"$",
"b",
"->",
"r",
"(",
")",
")",
",",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"i",
"(",
")",
",",
"$",
"b",
"->",
"i",
"(",
")",
")",
")",
";",
"$",
"i",
"=",
"$",
"this",
"->",
"rationalAdd",
"(",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"i",
"(",
")",
",",
"$",
"b",
"->",
"r",
"(",
")",
")",
",",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"r",
"(",
")",
",",
"$",
"b",
"->",
"i",
"(",
")",
")",
")",
";",
"return",
"ComplexTypeFactory",
"::",
"create",
"(",
"$",
"r",
",",
"$",
"i",
")",
";",
"}"
]
| Complex number multiplication
@param ComplexType $a first operand
@param ComplexType $b second operand
@return ComplexType | [
"Complex",
"number",
"multiplication"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L517-L528 |
14,589 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.complexDiv | public function complexDiv(ComplexType $a, ComplexType $b)
{
if ($b->isZero()) {
throw new \BadMethodCallException('Cannot divide complex number by zero complex number');
}
//div = br^2 + bi^2
$div = $this->rationalAdd(
$this->rationalMul($b->r(), $b->r()),
$this->rationalMul($b->i(), $b->i())
);
//r = ((ar * br) + (ai * bi))/div
$r = $this->rationalDiv(
$this->rationalAdd(
$this->rationalMul($a->r(), $b->r()),
$this->rationalMul($a->i(), $b->i())
),
$div
);
//i = ((ai * br) - (ar * bi)) / div
$i = $this->rationalDiv(
$this->rationalSub(
$this->rationalMul($a->i(), $b->r()),
$this->rationalMul($a->r(), $b->i())
),
$div
);
return ComplexTypeFactory::create($r, $i);
} | php | public function complexDiv(ComplexType $a, ComplexType $b)
{
if ($b->isZero()) {
throw new \BadMethodCallException('Cannot divide complex number by zero complex number');
}
//div = br^2 + bi^2
$div = $this->rationalAdd(
$this->rationalMul($b->r(), $b->r()),
$this->rationalMul($b->i(), $b->i())
);
//r = ((ar * br) + (ai * bi))/div
$r = $this->rationalDiv(
$this->rationalAdd(
$this->rationalMul($a->r(), $b->r()),
$this->rationalMul($a->i(), $b->i())
),
$div
);
//i = ((ai * br) - (ar * bi)) / div
$i = $this->rationalDiv(
$this->rationalSub(
$this->rationalMul($a->i(), $b->r()),
$this->rationalMul($a->r(), $b->i())
),
$div
);
return ComplexTypeFactory::create($r, $i);
} | [
"public",
"function",
"complexDiv",
"(",
"ComplexType",
"$",
"a",
",",
"ComplexType",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"b",
"->",
"isZero",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"'Cannot divide complex number by zero complex number'",
")",
";",
"}",
"//div = br^2 + bi^2",
"$",
"div",
"=",
"$",
"this",
"->",
"rationalAdd",
"(",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"b",
"->",
"r",
"(",
")",
",",
"$",
"b",
"->",
"r",
"(",
")",
")",
",",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"b",
"->",
"i",
"(",
")",
",",
"$",
"b",
"->",
"i",
"(",
")",
")",
")",
";",
"//r = ((ar * br) + (ai * bi))/div",
"$",
"r",
"=",
"$",
"this",
"->",
"rationalDiv",
"(",
"$",
"this",
"->",
"rationalAdd",
"(",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"r",
"(",
")",
",",
"$",
"b",
"->",
"r",
"(",
")",
")",
",",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"i",
"(",
")",
",",
"$",
"b",
"->",
"i",
"(",
")",
")",
")",
",",
"$",
"div",
")",
";",
"//i = ((ai * br) - (ar * bi)) / div",
"$",
"i",
"=",
"$",
"this",
"->",
"rationalDiv",
"(",
"$",
"this",
"->",
"rationalSub",
"(",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"i",
"(",
")",
",",
"$",
"b",
"->",
"r",
"(",
")",
")",
",",
"$",
"this",
"->",
"rationalMul",
"(",
"$",
"a",
"->",
"r",
"(",
")",
",",
"$",
"b",
"->",
"i",
"(",
")",
")",
")",
",",
"$",
"div",
")",
";",
"return",
"ComplexTypeFactory",
"::",
"create",
"(",
"$",
"r",
",",
"$",
"i",
")",
";",
"}"
]
| Complex number division
@param ComplexType $a first operand
@param ComplexType $b second operand
@return ComplexType
@throws \BadMethodCallException | [
"Complex",
"number",
"division"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L540-L568 |
14,590 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.complexPow | public function complexPow(ComplexType $a, NI $exp)
{
if ($exp instanceof ComplexType) {
$comp = new Comparator();
$zero = new IntType(0);
$real = 0;
$imaginary = 0;
if (!($comp->eq($a->r(), $zero) && $comp->eq($a->i(), $zero))) {
list($real, $imaginary) = $this->getPowExponentPartsFromPolar($a, $exp);
}
return new ComplexType(
RationalTypeFactory::fromFloat($real),
RationalTypeFactory::fromFloat($imaginary)
);
}
//non complex
//de moivres theorum
//z^n = r^n(cos(n.theta) + sin(n.theta)i)
//where z is a complex number, r is the radius
$n = $exp();
$nTheta = $n * $a->theta()->get();
$pow = pow($a->modulus()->get(), $n);
$real = cos($nTheta) * $pow;
$imaginary = sin($nTheta) * $pow;
return new ComplexType(
RationalTypeFactory::fromFloat($real),
RationalTypeFactory::fromFloat($imaginary)
);
} | php | public function complexPow(ComplexType $a, NI $exp)
{
if ($exp instanceof ComplexType) {
$comp = new Comparator();
$zero = new IntType(0);
$real = 0;
$imaginary = 0;
if (!($comp->eq($a->r(), $zero) && $comp->eq($a->i(), $zero))) {
list($real, $imaginary) = $this->getPowExponentPartsFromPolar($a, $exp);
}
return new ComplexType(
RationalTypeFactory::fromFloat($real),
RationalTypeFactory::fromFloat($imaginary)
);
}
//non complex
//de moivres theorum
//z^n = r^n(cos(n.theta) + sin(n.theta)i)
//where z is a complex number, r is the radius
$n = $exp();
$nTheta = $n * $a->theta()->get();
$pow = pow($a->modulus()->get(), $n);
$real = cos($nTheta) * $pow;
$imaginary = sin($nTheta) * $pow;
return new ComplexType(
RationalTypeFactory::fromFloat($real),
RationalTypeFactory::fromFloat($imaginary)
);
} | [
"public",
"function",
"complexPow",
"(",
"ComplexType",
"$",
"a",
",",
"NI",
"$",
"exp",
")",
"{",
"if",
"(",
"$",
"exp",
"instanceof",
"ComplexType",
")",
"{",
"$",
"comp",
"=",
"new",
"Comparator",
"(",
")",
";",
"$",
"zero",
"=",
"new",
"IntType",
"(",
"0",
")",
";",
"$",
"real",
"=",
"0",
";",
"$",
"imaginary",
"=",
"0",
";",
"if",
"(",
"!",
"(",
"$",
"comp",
"->",
"eq",
"(",
"$",
"a",
"->",
"r",
"(",
")",
",",
"$",
"zero",
")",
"&&",
"$",
"comp",
"->",
"eq",
"(",
"$",
"a",
"->",
"i",
"(",
")",
",",
"$",
"zero",
")",
")",
")",
"{",
"list",
"(",
"$",
"real",
",",
"$",
"imaginary",
")",
"=",
"$",
"this",
"->",
"getPowExponentPartsFromPolar",
"(",
"$",
"a",
",",
"$",
"exp",
")",
";",
"}",
"return",
"new",
"ComplexType",
"(",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"real",
")",
",",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"imaginary",
")",
")",
";",
"}",
"//non complex",
"//de moivres theorum",
"//z^n = r^n(cos(n.theta) + sin(n.theta)i)",
"//where z is a complex number, r is the radius",
"$",
"n",
"=",
"$",
"exp",
"(",
")",
";",
"$",
"nTheta",
"=",
"$",
"n",
"*",
"$",
"a",
"->",
"theta",
"(",
")",
"->",
"get",
"(",
")",
";",
"$",
"pow",
"=",
"pow",
"(",
"$",
"a",
"->",
"modulus",
"(",
")",
"->",
"get",
"(",
")",
",",
"$",
"n",
")",
";",
"$",
"real",
"=",
"cos",
"(",
"$",
"nTheta",
")",
"*",
"$",
"pow",
";",
"$",
"imaginary",
"=",
"sin",
"(",
"$",
"nTheta",
")",
"*",
"$",
"pow",
";",
"return",
"new",
"ComplexType",
"(",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"real",
")",
",",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"imaginary",
")",
")",
";",
"}"
]
| Complex Pow - raise number to the exponent
Will return a ComplexType
Exponent must be non complex
@param ComplexType $a operand
@param NI $exp Exponent
@return ComplexType
@throws \InvalidArgumentException If exponent is complex | [
"Complex",
"Pow",
"-",
"raise",
"number",
"to",
"the",
"exponent",
"Will",
"return",
"a",
"ComplexType",
"Exponent",
"must",
"be",
"non",
"complex"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L606-L636 |
14,591 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.intComplexPow | private function intComplexPow($a, ComplexType $exp)
{
if ($exp->isZero()) {
return new IntType(1);
}
return $this->complexExponent($a, $exp);
} | php | private function intComplexPow($a, ComplexType $exp)
{
if ($exp->isZero()) {
return new IntType(1);
}
return $this->complexExponent($a, $exp);
} | [
"private",
"function",
"intComplexPow",
"(",
"$",
"a",
",",
"ComplexType",
"$",
"exp",
")",
"{",
"if",
"(",
"$",
"exp",
"->",
"isZero",
"(",
")",
")",
"{",
"return",
"new",
"IntType",
"(",
"1",
")",
";",
"}",
"return",
"$",
"this",
"->",
"complexExponent",
"(",
"$",
"a",
",",
"$",
"exp",
")",
";",
"}"
]
| Create Complex power from an integer
@param int $a operand
@param ComplexType $exp exponent
@return NI|ComplexType|IntType | [
"Create",
"Complex",
"power",
"from",
"an",
"integer"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L676-L682 |
14,592 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.floatComplexPow | private function floatComplexPow($a, ComplexType $exp)
{
if ($exp->isZero()) {
return new FloatType(1);
}
return $this->complexExponent($a, $exp);
} | php | private function floatComplexPow($a, ComplexType $exp)
{
if ($exp->isZero()) {
return new FloatType(1);
}
return $this->complexExponent($a, $exp);
} | [
"private",
"function",
"floatComplexPow",
"(",
"$",
"a",
",",
"ComplexType",
"$",
"exp",
")",
"{",
"if",
"(",
"$",
"exp",
"->",
"isZero",
"(",
")",
")",
"{",
"return",
"new",
"FloatType",
"(",
"1",
")",
";",
"}",
"return",
"$",
"this",
"->",
"complexExponent",
"(",
"$",
"a",
",",
"$",
"exp",
")",
";",
"}"
]
| Create complex power from a float
@param float $a operand
@param ComplexType $exp exponent
@return NI|ComplexType|FloatType | [
"Create",
"complex",
"power",
"from",
"a",
"float"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L692-L698 |
14,593 | chippyash/Math-Type-Calculator | src/Chippyash/Math/Type/Calculator/Native.php | Native.complexExponent | private function complexExponent($base, ComplexType $exp)
{
if ($exp->isReal()) {
return $this->rationalPow(
RationalTypeFactory::fromFloat($base),
$exp->r()
);
}
//do the imaginary part
//n^bi = cos(b.lg(n)) + i.sin(b.lg(n))
$b = $exp->i()->get();
$n = log($base);
$r = cos($b * $n);
$i = sin($b * $n);
//no real part
if ($exp->r()->get() == 0) {
return new ComplexType(
RationalTypeFactory::fromFloat($r),
RationalTypeFactory::fromFloat($i)
);
}
//real and imaginary part
//n^a+bi = n^a(cos(b.lg(n)) + i.sin(b.lg(n)))
$na = pow($base, $exp->r()->get());
$rr = $na * $r;
$ii = $na * $i;
return new ComplexType(
RationalTypeFactory::fromFloat($rr),
RationalTypeFactory::fromFloat($ii)
);
} | php | private function complexExponent($base, ComplexType $exp)
{
if ($exp->isReal()) {
return $this->rationalPow(
RationalTypeFactory::fromFloat($base),
$exp->r()
);
}
//do the imaginary part
//n^bi = cos(b.lg(n)) + i.sin(b.lg(n))
$b = $exp->i()->get();
$n = log($base);
$r = cos($b * $n);
$i = sin($b * $n);
//no real part
if ($exp->r()->get() == 0) {
return new ComplexType(
RationalTypeFactory::fromFloat($r),
RationalTypeFactory::fromFloat($i)
);
}
//real and imaginary part
//n^a+bi = n^a(cos(b.lg(n)) + i.sin(b.lg(n)))
$na = pow($base, $exp->r()->get());
$rr = $na * $r;
$ii = $na * $i;
return new ComplexType(
RationalTypeFactory::fromFloat($rr),
RationalTypeFactory::fromFloat($ii)
);
} | [
"private",
"function",
"complexExponent",
"(",
"$",
"base",
",",
"ComplexType",
"$",
"exp",
")",
"{",
"if",
"(",
"$",
"exp",
"->",
"isReal",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"rationalPow",
"(",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"base",
")",
",",
"$",
"exp",
"->",
"r",
"(",
")",
")",
";",
"}",
"//do the imaginary part",
"//n^bi = cos(b.lg(n)) + i.sin(b.lg(n))",
"$",
"b",
"=",
"$",
"exp",
"->",
"i",
"(",
")",
"->",
"get",
"(",
")",
";",
"$",
"n",
"=",
"log",
"(",
"$",
"base",
")",
";",
"$",
"r",
"=",
"cos",
"(",
"$",
"b",
"*",
"$",
"n",
")",
";",
"$",
"i",
"=",
"sin",
"(",
"$",
"b",
"*",
"$",
"n",
")",
";",
"//no real part",
"if",
"(",
"$",
"exp",
"->",
"r",
"(",
")",
"->",
"get",
"(",
")",
"==",
"0",
")",
"{",
"return",
"new",
"ComplexType",
"(",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"r",
")",
",",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"i",
")",
")",
";",
"}",
"//real and imaginary part",
"//n^a+bi = n^a(cos(b.lg(n)) + i.sin(b.lg(n)))",
"$",
"na",
"=",
"pow",
"(",
"$",
"base",
",",
"$",
"exp",
"->",
"r",
"(",
")",
"->",
"get",
"(",
")",
")",
";",
"$",
"rr",
"=",
"$",
"na",
"*",
"$",
"r",
";",
"$",
"ii",
"=",
"$",
"na",
"*",
"$",
"i",
";",
"return",
"new",
"ComplexType",
"(",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"rr",
")",
",",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"ii",
")",
")",
";",
"}"
]
| Create complex power from natural base and complex exponent
@param int|float $base base
@param ComplexType $exp exponent
@return NI|ComplexType | [
"Create",
"complex",
"power",
"from",
"natural",
"base",
"and",
"complex",
"exponent"
]
| 2a2fae0ab4d052772d3dd45745efd5a91f88b9e3 | https://github.com/chippyash/Math-Type-Calculator/blob/2a2fae0ab4d052772d3dd45745efd5a91f88b9e3/src/Chippyash/Math/Type/Calculator/Native.php#L708-L740 |
14,594 | jasny/router | src/Router/Runner/Delegate.php | Delegate.getRunner | public function getRunner(Route $route)
{
if (isset($route->controller)) {
$class = Runner\Controller::class;
} elseif (isset($route->fn)) {
$class = Runner\Callback::class;
} elseif (isset($route->file)) {
$class = Runner\PhpScript::class;
} else {
trigger_error("Route has neither 'controller', 'fn' or 'file' defined", E_USER_NOTICE);
return null;
}
return new $class();
} | php | public function getRunner(Route $route)
{
if (isset($route->controller)) {
$class = Runner\Controller::class;
} elseif (isset($route->fn)) {
$class = Runner\Callback::class;
} elseif (isset($route->file)) {
$class = Runner\PhpScript::class;
} else {
trigger_error("Route has neither 'controller', 'fn' or 'file' defined", E_USER_NOTICE);
return null;
}
return new $class();
} | [
"public",
"function",
"getRunner",
"(",
"Route",
"$",
"route",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"route",
"->",
"controller",
")",
")",
"{",
"$",
"class",
"=",
"Runner",
"\\",
"Controller",
"::",
"class",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"route",
"->",
"fn",
")",
")",
"{",
"$",
"class",
"=",
"Runner",
"\\",
"Callback",
"::",
"class",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"route",
"->",
"file",
")",
")",
"{",
"$",
"class",
"=",
"Runner",
"\\",
"PhpScript",
"::",
"class",
";",
"}",
"else",
"{",
"trigger_error",
"(",
"\"Route has neither 'controller', 'fn' or 'file' defined\"",
",",
"E_USER_NOTICE",
")",
";",
"return",
"null",
";",
"}",
"return",
"new",
"$",
"class",
"(",
")",
";",
"}"
]
| Create Runner instance
@param Route $route
@return Runner | [
"Create",
"Runner",
"instance"
]
| 4c776665ba343150b442c21893946e3d54190896 | https://github.com/jasny/router/blob/4c776665ba343150b442c21893946e3d54190896/src/Router/Runner/Delegate.php#L24-L38 |
14,595 | sulu/SuluSalesShippingBundle | src/Sulu/Bundle/Sales/CoreBundle/Pricing/GroupedItemsPriceCalculator.php | GroupedItemsPriceCalculator.addPriceToPriceGroup | protected function addPriceToPriceGroup($price, $item, &$groupPrices, &$groupedItems)
{
$itemPriceGroup = $item->getCalcPriceGroup();
if ($itemPriceGroup === null) {
$itemPriceGroup = 'undefined';
}
if (!isset($groupPrices[$itemPriceGroup])) {
$groupPrices[$itemPriceGroup] = 0;
}
$groupPrices[$itemPriceGroup] += $price;
// add to grouped items
if (!isset($groupedItems[$itemPriceGroup])) {
$groupedItems[$itemPriceGroup] = array(
'items' => array()
);
if (method_exists($item, 'getCalcPriceGroupContent') &&
$content = $item->getCalcPriceGroupContent()
) {
$groupedItems[$itemPriceGroup] = array_merge($content, $groupedItems[$itemPriceGroup]);
}
}
$groupedItems[$itemPriceGroup]['items'][] = $item;
$groupedItems[$itemPriceGroup]['price'] = $groupPrices[$itemPriceGroup];
$groupedItems[$itemPriceGroup]['priceFormatted'] = $this->itemPriceCalculator->formatPrice(
$groupPrices[$itemPriceGroup],
null
);
} | php | protected function addPriceToPriceGroup($price, $item, &$groupPrices, &$groupedItems)
{
$itemPriceGroup = $item->getCalcPriceGroup();
if ($itemPriceGroup === null) {
$itemPriceGroup = 'undefined';
}
if (!isset($groupPrices[$itemPriceGroup])) {
$groupPrices[$itemPriceGroup] = 0;
}
$groupPrices[$itemPriceGroup] += $price;
// add to grouped items
if (!isset($groupedItems[$itemPriceGroup])) {
$groupedItems[$itemPriceGroup] = array(
'items' => array()
);
if (method_exists($item, 'getCalcPriceGroupContent') &&
$content = $item->getCalcPriceGroupContent()
) {
$groupedItems[$itemPriceGroup] = array_merge($content, $groupedItems[$itemPriceGroup]);
}
}
$groupedItems[$itemPriceGroup]['items'][] = $item;
$groupedItems[$itemPriceGroup]['price'] = $groupPrices[$itemPriceGroup];
$groupedItems[$itemPriceGroup]['priceFormatted'] = $this->itemPriceCalculator->formatPrice(
$groupPrices[$itemPriceGroup],
null
);
} | [
"protected",
"function",
"addPriceToPriceGroup",
"(",
"$",
"price",
",",
"$",
"item",
",",
"&",
"$",
"groupPrices",
",",
"&",
"$",
"groupedItems",
")",
"{",
"$",
"itemPriceGroup",
"=",
"$",
"item",
"->",
"getCalcPriceGroup",
"(",
")",
";",
"if",
"(",
"$",
"itemPriceGroup",
"===",
"null",
")",
"{",
"$",
"itemPriceGroup",
"=",
"'undefined'",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"groupPrices",
"[",
"$",
"itemPriceGroup",
"]",
")",
")",
"{",
"$",
"groupPrices",
"[",
"$",
"itemPriceGroup",
"]",
"=",
"0",
";",
"}",
"$",
"groupPrices",
"[",
"$",
"itemPriceGroup",
"]",
"+=",
"$",
"price",
";",
"// add to grouped items",
"if",
"(",
"!",
"isset",
"(",
"$",
"groupedItems",
"[",
"$",
"itemPriceGroup",
"]",
")",
")",
"{",
"$",
"groupedItems",
"[",
"$",
"itemPriceGroup",
"]",
"=",
"array",
"(",
"'items'",
"=>",
"array",
"(",
")",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"item",
",",
"'getCalcPriceGroupContent'",
")",
"&&",
"$",
"content",
"=",
"$",
"item",
"->",
"getCalcPriceGroupContent",
"(",
")",
")",
"{",
"$",
"groupedItems",
"[",
"$",
"itemPriceGroup",
"]",
"=",
"array_merge",
"(",
"$",
"content",
",",
"$",
"groupedItems",
"[",
"$",
"itemPriceGroup",
"]",
")",
";",
"}",
"}",
"$",
"groupedItems",
"[",
"$",
"itemPriceGroup",
"]",
"[",
"'items'",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"$",
"groupedItems",
"[",
"$",
"itemPriceGroup",
"]",
"[",
"'price'",
"]",
"=",
"$",
"groupPrices",
"[",
"$",
"itemPriceGroup",
"]",
";",
"$",
"groupedItems",
"[",
"$",
"itemPriceGroup",
"]",
"[",
"'priceFormatted'",
"]",
"=",
"$",
"this",
"->",
"itemPriceCalculator",
"->",
"formatPrice",
"(",
"$",
"groupPrices",
"[",
"$",
"itemPriceGroup",
"]",
",",
"null",
")",
";",
"}"
]
| adds price to a price-group
@param $price
@param $item
@param $groupPrices
@param $groupedItems
@internal param $itemPriceGroup | [
"adds",
"price",
"to",
"a",
"price",
"-",
"group"
]
| 0d39de262d58579e5679db99a77dbf717d600b5e | https://github.com/sulu/SuluSalesShippingBundle/blob/0d39de262d58579e5679db99a77dbf717d600b5e/src/Sulu/Bundle/Sales/CoreBundle/Pricing/GroupedItemsPriceCalculator.php#L82-L112 |
14,596 | dragosprotung/stc-core | src/Date/DateTimeZone.php | DateTimeZone.UTCTimeZoneOffset | public function UTCTimeZoneOffset() : int
{
$originDateTime = new \DateTime('now', $this);
$utcTimeZone = new \DateTimeZone('UTC');
$utcDateTime = new \DateTime('now', $utcTimeZone);
return $utcTimeZone->getOffset($utcDateTime) - $this->getOffset($originDateTime);
} | php | public function UTCTimeZoneOffset() : int
{
$originDateTime = new \DateTime('now', $this);
$utcTimeZone = new \DateTimeZone('UTC');
$utcDateTime = new \DateTime('now', $utcTimeZone);
return $utcTimeZone->getOffset($utcDateTime) - $this->getOffset($originDateTime);
} | [
"public",
"function",
"UTCTimeZoneOffset",
"(",
")",
":",
"int",
"{",
"$",
"originDateTime",
"=",
"new",
"\\",
"DateTime",
"(",
"'now'",
",",
"$",
"this",
")",
";",
"$",
"utcTimeZone",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"'UTC'",
")",
";",
"$",
"utcDateTime",
"=",
"new",
"\\",
"DateTime",
"(",
"'now'",
",",
"$",
"utcTimeZone",
")",
";",
"return",
"$",
"utcTimeZone",
"->",
"getOffset",
"(",
"$",
"utcDateTime",
")",
"-",
"$",
"this",
"->",
"getOffset",
"(",
"$",
"originDateTime",
")",
";",
"}"
]
| Get offset between a time zone and UTC time zone in seconds.
@return integer | [
"Get",
"offset",
"between",
"a",
"time",
"zone",
"and",
"UTC",
"time",
"zone",
"in",
"seconds",
"."
]
| 9783e3414294f4ee555a1d538d2807269deeb9e7 | https://github.com/dragosprotung/stc-core/blob/9783e3414294f4ee555a1d538d2807269deeb9e7/src/Date/DateTimeZone.php#L17-L25 |
14,597 | andyvenus/form | src/FormBlueprint.php | FormBlueprint.setFieldOption | public function setFieldOption($field, $option, $value)
{
if (!isset($this->fields[$field])) {
throw new \Exception("Cannot set field option: Field {$field} not found");
}
$this->fields[$field]['options'][$option] = $value;
} | php | public function setFieldOption($field, $option, $value)
{
if (!isset($this->fields[$field])) {
throw new \Exception("Cannot set field option: Field {$field} not found");
}
$this->fields[$field]['options'][$option] = $value;
} | [
"public",
"function",
"setFieldOption",
"(",
"$",
"field",
",",
"$",
"option",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"field",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Cannot set field option: Field {$field} not found\"",
")",
";",
"}",
"$",
"this",
"->",
"fields",
"[",
"$",
"field",
"]",
"[",
"'options'",
"]",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"}"
]
| Override a field option
@param $field
@param $option
@param $value
@return void
@throws \Exception | [
"Override",
"a",
"field",
"option"
]
| fde9d7e1741a707028aec4fd55c3568802df3708 | https://github.com/andyvenus/form/blob/fde9d7e1741a707028aec4fd55c3568802df3708/src/FormBlueprint.php#L230-L237 |
14,598 | hamjoint/mustard-auctions | src/lib/Http/Controllers/InventoryController.php | InventoryController.getBidding | public function getBidding()
{
$items = Item::typeAuction()->active()->whereHas('bids', function ($query) {
return $query->where('user_id', Auth::user()->userId);
});
$items = Item::typeAuction()->active()->leftJoin('bids')->where(
'bids.user_id',
Auth::user()->userId
)->addSelect(
DB::raw('max(`bids`.`amount`) as `max_bid`')
)->addSelect(
DB::raw('count(`bids`.`bid_id`) as `bid_count`')
)->groupBy('items.item_id');
$table = new InventoryBidding($items);
return view('mustard::inventory.bidding', [
'table' => $table,
'items' => $table->paginate(),
]);
} | php | public function getBidding()
{
$items = Item::typeAuction()->active()->whereHas('bids', function ($query) {
return $query->where('user_id', Auth::user()->userId);
});
$items = Item::typeAuction()->active()->leftJoin('bids')->where(
'bids.user_id',
Auth::user()->userId
)->addSelect(
DB::raw('max(`bids`.`amount`) as `max_bid`')
)->addSelect(
DB::raw('count(`bids`.`bid_id`) as `bid_count`')
)->groupBy('items.item_id');
$table = new InventoryBidding($items);
return view('mustard::inventory.bidding', [
'table' => $table,
'items' => $table->paginate(),
]);
} | [
"public",
"function",
"getBidding",
"(",
")",
"{",
"$",
"items",
"=",
"Item",
"::",
"typeAuction",
"(",
")",
"->",
"active",
"(",
")",
"->",
"whereHas",
"(",
"'bids'",
",",
"function",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"'user_id'",
",",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
")",
";",
"}",
")",
";",
"$",
"items",
"=",
"Item",
"::",
"typeAuction",
"(",
")",
"->",
"active",
"(",
")",
"->",
"leftJoin",
"(",
"'bids'",
")",
"->",
"where",
"(",
"'bids.user_id'",
",",
"Auth",
"::",
"user",
"(",
")",
"->",
"userId",
")",
"->",
"addSelect",
"(",
"DB",
"::",
"raw",
"(",
"'max(`bids`.`amount`) as `max_bid`'",
")",
")",
"->",
"addSelect",
"(",
"DB",
"::",
"raw",
"(",
"'count(`bids`.`bid_id`) as `bid_count`'",
")",
")",
"->",
"groupBy",
"(",
"'items.item_id'",
")",
";",
"$",
"table",
"=",
"new",
"InventoryBidding",
"(",
"$",
"items",
")",
";",
"return",
"view",
"(",
"'mustard::inventory.bidding'",
",",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'items'",
"=>",
"$",
"table",
"->",
"paginate",
"(",
")",
",",
"]",
")",
";",
"}"
]
| Return the inventory bidding items view.
@return \Illuminate\View\View | [
"Return",
"the",
"inventory",
"bidding",
"items",
"view",
"."
]
| 66c8723d8681466e280263ad100f3fdc5895480d | https://github.com/hamjoint/mustard-auctions/blob/66c8723d8681466e280263ad100f3fdc5895480d/src/lib/Http/Controllers/InventoryController.php#L37-L58 |
14,599 | codeburnerframework/router | src/Resource.php | Resource.filterByMethod | private function filterByMethod(array $methods, $alt)
{
$methods = array_flip(array_map('strtolower', $methods));
foreach ($this->routes as $route) {
if (isset($methods[$route->getAction()[1]]) === $alt) {
$route->forget();
}
}
} | php | private function filterByMethod(array $methods, $alt)
{
$methods = array_flip(array_map('strtolower', $methods));
foreach ($this->routes as $route) {
if (isset($methods[$route->getAction()[1]]) === $alt) {
$route->forget();
}
}
} | [
"private",
"function",
"filterByMethod",
"(",
"array",
"$",
"methods",
",",
"$",
"alt",
")",
"{",
"$",
"methods",
"=",
"array_flip",
"(",
"array_map",
"(",
"'strtolower'",
",",
"$",
"methods",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"methods",
"[",
"$",
"route",
"->",
"getAction",
"(",
")",
"[",
"1",
"]",
"]",
")",
"===",
"$",
"alt",
")",
"{",
"$",
"route",
"->",
"forget",
"(",
")",
";",
"}",
"}",
"}"
]
| Forget the grouped routes filtering by http methods.
@param string[] $methods
@param bool $alt Should remove? | [
"Forget",
"the",
"grouped",
"routes",
"filtering",
"by",
"http",
"methods",
"."
]
| 2b0e8030303dd08d3fadfc4c57aa37b184a408cd | https://github.com/codeburnerframework/router/blob/2b0e8030303dd08d3fadfc4c57aa37b184a408cd/src/Resource.php#L66-L75 |
Subsets and Splits