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 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
larapulse/support | src/Handlers/Str.php | Str.shift | public static function shift(string &$str, string $encoding = null)
{
$encoding = $encoding ?: mb_internal_encoding();
$first = mb_substr($str, 0, 1, $encoding);
$str = mb_substr($str, 1, null, $encoding);
return $first;
} | php | public static function shift(string &$str, string $encoding = null)
{
$encoding = $encoding ?: mb_internal_encoding();
$first = mb_substr($str, 0, 1, $encoding);
$str = mb_substr($str, 1, null, $encoding);
return $first;
} | [
"public",
"static",
"function",
"shift",
"(",
"string",
"&",
"$",
"str",
",",
"string",
"$",
"encoding",
"=",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"encoding",
"?",
":",
"mb_internal_encoding",
"(",
")",
";",
"$",
"first",
"=",
"mb_substr",
"(",
"$",
"str",
",",
"0",
",",
"1",
",",
"$",
"encoding",
")",
";",
"$",
"str",
"=",
"mb_substr",
"(",
"$",
"str",
",",
"1",
",",
"null",
",",
"$",
"encoding",
")",
";",
"return",
"$",
"first",
";",
"}"
] | Shift a character off the beginning of string
@param string $str
@param string $encoding
@return bool|string | [
"Shift",
"a",
"character",
"off",
"the",
"beginning",
"of",
"string"
] | 601ee3fd6967be669afe081322340c82c7edf32d | https://github.com/larapulse/support/blob/601ee3fd6967be669afe081322340c82c7edf32d/src/Handlers/Str.php#L35-L43 | train |
larapulse/support | src/Handlers/Str.php | Str.cutStart | public static function cutStart(
string $str,
string $subString = ' ',
bool $repeat = false,
bool $caseSensitive = true
) : string {
$prepared = RegEx::prepare($subString, '/');
$regex = sprintf(
'/^%s/%s',
($subString
? ($repeat ? RegexHelper::quantifyGroup($prepared, 0) : $prepared)
: ''
),
(!$caseSensitive ? 'i' : '')
);
return preg_replace($regex, '', $str);
} | php | public static function cutStart(
string $str,
string $subString = ' ',
bool $repeat = false,
bool $caseSensitive = true
) : string {
$prepared = RegEx::prepare($subString, '/');
$regex = sprintf(
'/^%s/%s',
($subString
? ($repeat ? RegexHelper::quantifyGroup($prepared, 0) : $prepared)
: ''
),
(!$caseSensitive ? 'i' : '')
);
return preg_replace($regex, '', $str);
} | [
"public",
"static",
"function",
"cutStart",
"(",
"string",
"$",
"str",
",",
"string",
"$",
"subString",
"=",
"' '",
",",
"bool",
"$",
"repeat",
"=",
"false",
",",
"bool",
"$",
"caseSensitive",
"=",
"true",
")",
":",
"string",
"{",
"$",
"prepared",
"=",
"RegEx",
"::",
"prepare",
"(",
"$",
"subString",
",",
"'/'",
")",
";",
"$",
"regex",
"=",
"sprintf",
"(",
"'/^%s/%s'",
",",
"(",
"$",
"subString",
"?",
"(",
"$",
"repeat",
"?",
"RegexHelper",
"::",
"quantifyGroup",
"(",
"$",
"prepared",
",",
"0",
")",
":",
"$",
"prepared",
")",
":",
"''",
")",
",",
"(",
"!",
"$",
"caseSensitive",
"?",
"'i'",
":",
"''",
")",
")",
";",
"return",
"preg_replace",
"(",
"$",
"regex",
",",
"''",
",",
"$",
"str",
")",
";",
"}"
] | Cut substring from the beginning of string
@param string $str
@param string $subString
@param bool $repeat
@param bool $caseSensitive Not working with multi-byte characters
@return string | [
"Cut",
"substring",
"from",
"the",
"beginning",
"of",
"string"
] | 601ee3fd6967be669afe081322340c82c7edf32d | https://github.com/larapulse/support/blob/601ee3fd6967be669afe081322340c82c7edf32d/src/Handlers/Str.php#L55-L72 | train |
Becklyn/Gluggi | src/Model/DownloadModel.php | DownloadModel.getAllDownloads | public function getAllDownloads ()
{
try
{
$directoryIterator = new \DirectoryIterator($this->downloadDir);
$downloads = [];
foreach ($directoryIterator as $file)
{
if (!$file->isFile())
{
continue;
}
// skip hidden files
if ("." === $file->getBasename()[0])
{
continue;
}
$downloads[$file->getFilename()] = new Download($file, self::RELATIVE_DOWNLOAD_DIR);
}
ksort($downloads);
return $downloads;
}
catch (\UnexpectedValueException $e)
{
return [];
}
} | php | public function getAllDownloads ()
{
try
{
$directoryIterator = new \DirectoryIterator($this->downloadDir);
$downloads = [];
foreach ($directoryIterator as $file)
{
if (!$file->isFile())
{
continue;
}
// skip hidden files
if ("." === $file->getBasename()[0])
{
continue;
}
$downloads[$file->getFilename()] = new Download($file, self::RELATIVE_DOWNLOAD_DIR);
}
ksort($downloads);
return $downloads;
}
catch (\UnexpectedValueException $e)
{
return [];
}
} | [
"public",
"function",
"getAllDownloads",
"(",
")",
"{",
"try",
"{",
"$",
"directoryIterator",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"this",
"->",
"downloadDir",
")",
";",
"$",
"downloads",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"directoryIterator",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"$",
"file",
"->",
"isFile",
"(",
")",
")",
"{",
"continue",
";",
"}",
"// skip hidden files",
"if",
"(",
"\".\"",
"===",
"$",
"file",
"->",
"getBasename",
"(",
")",
"[",
"0",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"downloads",
"[",
"$",
"file",
"->",
"getFilename",
"(",
")",
"]",
"=",
"new",
"Download",
"(",
"$",
"file",
",",
"self",
"::",
"RELATIVE_DOWNLOAD_DIR",
")",
";",
"}",
"ksort",
"(",
"$",
"downloads",
")",
";",
"return",
"$",
"downloads",
";",
"}",
"catch",
"(",
"\\",
"UnexpectedValueException",
"$",
"e",
")",
"{",
"return",
"[",
"]",
";",
"}",
"}"
] | Returns a list of all downloads
@return Download[] | [
"Returns",
"a",
"list",
"of",
"all",
"downloads"
] | 837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786 | https://github.com/Becklyn/Gluggi/blob/837e7ee8d34f5b16a7f1ef53ca64b1ea8722b786/src/Model/DownloadModel.php#L41-L71 | train |
net-tools/core | src/Helpers/ImagingHelper.php | ImagingHelper.imageAdjustOrientation | static function imageAdjustOrientation($path)
{
// read image
$image = new \imagick();
if ( !$image->readImage($path) )
return FALSE;
// read exif orientation
$orientation = $image->getImageOrientation();
$rotated = false;
switch($orientation)
{
case \imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateimage("#000", 180); // rotate 180 degrees
$rotated = true;
break;
case \imagick::ORIENTATION_RIGHTTOP:
$image->rotateimage("#000", 90); // rotate 90 degrees CW
$rotated = true;
break;
case \imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateimage("#000", -90); // rotate 90 degrees CCW
$rotated = true;
break;
}
// Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
$image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT);
if ( $rotated )
{
$image->setImageCompressionQuality(90);
$image->writeImage($path);
}
return TRUE;
} | php | static function imageAdjustOrientation($path)
{
// read image
$image = new \imagick();
if ( !$image->readImage($path) )
return FALSE;
// read exif orientation
$orientation = $image->getImageOrientation();
$rotated = false;
switch($orientation)
{
case \imagick::ORIENTATION_BOTTOMRIGHT:
$image->rotateimage("#000", 180); // rotate 180 degrees
$rotated = true;
break;
case \imagick::ORIENTATION_RIGHTTOP:
$image->rotateimage("#000", 90); // rotate 90 degrees CW
$rotated = true;
break;
case \imagick::ORIENTATION_LEFTBOTTOM:
$image->rotateimage("#000", -90); // rotate 90 degrees CCW
$rotated = true;
break;
}
// Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
$image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT);
if ( $rotated )
{
$image->setImageCompressionQuality(90);
$image->writeImage($path);
}
return TRUE;
} | [
"static",
"function",
"imageAdjustOrientation",
"(",
"$",
"path",
")",
"{",
"// read image",
"$",
"image",
"=",
"new",
"\\",
"imagick",
"(",
")",
";",
"if",
"(",
"!",
"$",
"image",
"->",
"readImage",
"(",
"$",
"path",
")",
")",
"return",
"FALSE",
";",
"// read exif orientation",
"$",
"orientation",
"=",
"$",
"image",
"->",
"getImageOrientation",
"(",
")",
";",
"$",
"rotated",
"=",
"false",
";",
"switch",
"(",
"$",
"orientation",
")",
"{",
"case",
"\\",
"imagick",
"::",
"ORIENTATION_BOTTOMRIGHT",
":",
"$",
"image",
"->",
"rotateimage",
"(",
"\"#000\"",
",",
"180",
")",
";",
"// rotate 180 degrees ",
"$",
"rotated",
"=",
"true",
";",
"break",
";",
"case",
"\\",
"imagick",
"::",
"ORIENTATION_RIGHTTOP",
":",
"$",
"image",
"->",
"rotateimage",
"(",
"\"#000\"",
",",
"90",
")",
";",
"// rotate 90 degrees CW ",
"$",
"rotated",
"=",
"true",
";",
"break",
";",
"case",
"\\",
"imagick",
"::",
"ORIENTATION_LEFTBOTTOM",
":",
"$",
"image",
"->",
"rotateimage",
"(",
"\"#000\"",
",",
"-",
"90",
")",
";",
"// rotate 90 degrees CCW ",
"$",
"rotated",
"=",
"true",
";",
"break",
";",
"}",
"// Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image! ",
"$",
"image",
"->",
"setImageOrientation",
"(",
"\\",
"imagick",
"::",
"ORIENTATION_TOPLEFT",
")",
";",
"if",
"(",
"$",
"rotated",
")",
"{",
"$",
"image",
"->",
"setImageCompressionQuality",
"(",
"90",
")",
";",
"$",
"image",
"->",
"writeImage",
"(",
"$",
"path",
")",
";",
"}",
"return",
"TRUE",
";",
"}"
] | If exif data indicates a rotated image, we apply the transformation to the image and set back orientation to normal
@param string $path Path to image
@return bool | [
"If",
"exif",
"data",
"indicates",
"a",
"rotated",
"image",
"we",
"apply",
"the",
"transformation",
"to",
"the",
"image",
"and",
"set",
"back",
"orientation",
"to",
"normal"
] | 51446641cee22c0cf53d2b409c76cc8bd1a187e7 | https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Helpers/ImagingHelper.php#L27-L69 | train |
bkstg/schedule-bundle | Controller/InvitationController.php | InvitationController.indexAction | public function indexAction(
Request $request,
PaginatorInterface $paginator,
TokenStorageInterface $token_storage
): Response {
// Get the invitations repo and a list of pending invites for this user.
$repo = $this->em->getRepository(Invitation::class);
$query = $repo->findPendingInvitationsQuery($token_storage->getToken()->getUser());
// Paginate and render the invitations.
$invitations = $paginator->paginate($query, $request->query->getInt('page', 1));
return new Response($this->templating->render(
'@BkstgSchedule/Invitation/index.html.twig',
['invitations' => $invitations]
));
} | php | public function indexAction(
Request $request,
PaginatorInterface $paginator,
TokenStorageInterface $token_storage
): Response {
// Get the invitations repo and a list of pending invites for this user.
$repo = $this->em->getRepository(Invitation::class);
$query = $repo->findPendingInvitationsQuery($token_storage->getToken()->getUser());
// Paginate and render the invitations.
$invitations = $paginator->paginate($query, $request->query->getInt('page', 1));
return new Response($this->templating->render(
'@BkstgSchedule/Invitation/index.html.twig',
['invitations' => $invitations]
));
} | [
"public",
"function",
"indexAction",
"(",
"Request",
"$",
"request",
",",
"PaginatorInterface",
"$",
"paginator",
",",
"TokenStorageInterface",
"$",
"token_storage",
")",
":",
"Response",
"{",
"// Get the invitations repo and a list of pending invites for this user.",
"$",
"repo",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"Invitation",
"::",
"class",
")",
";",
"$",
"query",
"=",
"$",
"repo",
"->",
"findPendingInvitationsQuery",
"(",
"$",
"token_storage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
")",
";",
"// Paginate and render the invitations.",
"$",
"invitations",
"=",
"$",
"paginator",
"->",
"paginate",
"(",
"$",
"query",
",",
"$",
"request",
"->",
"query",
"->",
"getInt",
"(",
"'page'",
",",
"1",
")",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"templating",
"->",
"render",
"(",
"'@BkstgSchedule/Invitation/index.html.twig'",
",",
"[",
"'invitations'",
"=>",
"$",
"invitations",
"]",
")",
")",
";",
"}"
] | Show a list of pending invitations for the current user.
@param Request $request The incoming request.
@param PaginatorInterface $paginator The paginator service.
@param TokenStorageInterface $token_storage The token storage service.
@return Response | [
"Show",
"a",
"list",
"of",
"pending",
"invitations",
"for",
"the",
"current",
"user",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Controller/InvitationController.php#L36-L52 | train |
bkstg/schedule-bundle | Controller/InvitationController.php | InvitationController.respondAction | public function respondAction(
int $id,
string $response,
AuthorizationCheckerInterface $auth
): Response {
// Get the repo and lookup the invitation.
$repo = $this->em->getRepository(Invitation::class);
if (null === $invitation = $repo->findOneBy(['id' => $id])) {
throw new NotFoundHttpException();
}
// Check that this user is allowed to respond.
if (!$auth->isGranted('respond', $invitation)) {
throw new AccessDeniedException();
}
// Record response.
switch ($response) {
case 'accept':
$invitation->setResponse(Invitation::RESPONSE_ACCEPT);
break;
case 'maybe':
$invitation->setResponse(Invitation::RESPONSE_MAYBE);
break;
case 'decline':
$invitation->setResponse(Invitation::RESPONSE_DECLINE);
break;
}
$this->em->flush();
// Return empty json response (code 200).
return new JsonResponse();
} | php | public function respondAction(
int $id,
string $response,
AuthorizationCheckerInterface $auth
): Response {
// Get the repo and lookup the invitation.
$repo = $this->em->getRepository(Invitation::class);
if (null === $invitation = $repo->findOneBy(['id' => $id])) {
throw new NotFoundHttpException();
}
// Check that this user is allowed to respond.
if (!$auth->isGranted('respond', $invitation)) {
throw new AccessDeniedException();
}
// Record response.
switch ($response) {
case 'accept':
$invitation->setResponse(Invitation::RESPONSE_ACCEPT);
break;
case 'maybe':
$invitation->setResponse(Invitation::RESPONSE_MAYBE);
break;
case 'decline':
$invitation->setResponse(Invitation::RESPONSE_DECLINE);
break;
}
$this->em->flush();
// Return empty json response (code 200).
return new JsonResponse();
} | [
"public",
"function",
"respondAction",
"(",
"int",
"$",
"id",
",",
"string",
"$",
"response",
",",
"AuthorizationCheckerInterface",
"$",
"auth",
")",
":",
"Response",
"{",
"// Get the repo and lookup the invitation.",
"$",
"repo",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"Invitation",
"::",
"class",
")",
";",
"if",
"(",
"null",
"===",
"$",
"invitation",
"=",
"$",
"repo",
"->",
"findOneBy",
"(",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"// Check that this user is allowed to respond.",
"if",
"(",
"!",
"$",
"auth",
"->",
"isGranted",
"(",
"'respond'",
",",
"$",
"invitation",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}",
"// Record response.",
"switch",
"(",
"$",
"response",
")",
"{",
"case",
"'accept'",
":",
"$",
"invitation",
"->",
"setResponse",
"(",
"Invitation",
"::",
"RESPONSE_ACCEPT",
")",
";",
"break",
";",
"case",
"'maybe'",
":",
"$",
"invitation",
"->",
"setResponse",
"(",
"Invitation",
"::",
"RESPONSE_MAYBE",
")",
";",
"break",
";",
"case",
"'decline'",
":",
"$",
"invitation",
"->",
"setResponse",
"(",
"Invitation",
"::",
"RESPONSE_DECLINE",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"em",
"->",
"flush",
"(",
")",
";",
"// Return empty json response (code 200).",
"return",
"new",
"JsonResponse",
"(",
")",
";",
"}"
] | Respond to an individual invitation.
@param int $id The id of the invitation.
@param string $response The response to the invitation.
@param AuthorizationCheckerInterface $auth The authorization checker service.
@throws NotFoundHttpException When the invitation does not exist.
@throws AccessDeniedException When the user has no access to respond.
@return Response | [
"Respond",
"to",
"an",
"individual",
"invitation",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Controller/InvitationController.php#L93-L125 | train |
pluf/tenant | src/Tenant/Monitor.php | Tenant_Monitor.permission | public static function permission ($request = null, $match = null)
{
// Check user
if (!$request->user || $request->user->isAnonymous()) {
return false;
}
// Get permission
$per = new User_Role();
$sql = new Pluf_SQL('code_name=%s',
array(
$match['metricName']
));
$items = $per->getList(
array(
'filter' => $sql->gen()
));
if ($items->count() == 0) {
return false;
}
// Check permission
return $request->user->hasPerm($items[0].'');
} | php | public static function permission ($request = null, $match = null)
{
// Check user
if (!$request->user || $request->user->isAnonymous()) {
return false;
}
// Get permission
$per = new User_Role();
$sql = new Pluf_SQL('code_name=%s',
array(
$match['metricName']
));
$items = $per->getList(
array(
'filter' => $sql->gen()
));
if ($items->count() == 0) {
return false;
}
// Check permission
return $request->user->hasPerm($items[0].'');
} | [
"public",
"static",
"function",
"permission",
"(",
"$",
"request",
"=",
"null",
",",
"$",
"match",
"=",
"null",
")",
"{",
"// Check user",
"if",
"(",
"!",
"$",
"request",
"->",
"user",
"||",
"$",
"request",
"->",
"user",
"->",
"isAnonymous",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Get permission",
"$",
"per",
"=",
"new",
"User_Role",
"(",
")",
";",
"$",
"sql",
"=",
"new",
"Pluf_SQL",
"(",
"'code_name=%s'",
",",
"array",
"(",
"$",
"match",
"[",
"'metricName'",
"]",
")",
")",
";",
"$",
"items",
"=",
"$",
"per",
"->",
"getList",
"(",
"array",
"(",
"'filter'",
"=>",
"$",
"sql",
"->",
"gen",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"items",
"->",
"count",
"(",
")",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"// Check permission",
"return",
"$",
"request",
"->",
"user",
"->",
"hasPerm",
"(",
"$",
"items",
"[",
"0",
"]",
".",
"''",
")",
";",
"}"
] | Retruns permision status
@param Pluf_HTTP_Request $request
@param array $match | [
"Retruns",
"permision",
"status"
] | a06359c52b9a257b5a0a186264e8770acfc54b73 | https://github.com/pluf/tenant/blob/a06359c52b9a257b5a0a186264e8770acfc54b73/src/Tenant/Monitor.php#L39-L63 | train |
Waryway/PhpTraitsLibrary | src/Generator.php | Generator.fileLineGenerator | private function fileLineGenerator(string $fileName, callable $formatter = null)
{
$f = fopen($fileName, 'r');
try {
while ($line = fgets($f)) {
if(!is_null($formatter)){
yield call_user_func($formatter, $line);
}
else {
yield $line;
}
}
} finally {
fclose($f);
}
} | php | private function fileLineGenerator(string $fileName, callable $formatter = null)
{
$f = fopen($fileName, 'r');
try {
while ($line = fgets($f)) {
if(!is_null($formatter)){
yield call_user_func($formatter, $line);
}
else {
yield $line;
}
}
} finally {
fclose($f);
}
} | [
"private",
"function",
"fileLineGenerator",
"(",
"string",
"$",
"fileName",
",",
"callable",
"$",
"formatter",
"=",
"null",
")",
"{",
"$",
"f",
"=",
"fopen",
"(",
"$",
"fileName",
",",
"'r'",
")",
";",
"try",
"{",
"while",
"(",
"$",
"line",
"=",
"fgets",
"(",
"$",
"f",
")",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"formatter",
")",
")",
"{",
"yield",
"call_user_func",
"(",
"$",
"formatter",
",",
"$",
"line",
")",
";",
"}",
"else",
"{",
"yield",
"$",
"line",
";",
"}",
"}",
"}",
"finally",
"{",
"fclose",
"(",
"$",
"f",
")",
";",
"}",
"}"
] | Read from a file one line at a time.
@test
@param $fileName
@param callable|null $formatter - the default is a string.
@return \Generator|string|object | [
"Read",
"from",
"a",
"file",
"one",
"line",
"at",
"a",
"time",
"."
] | 90c02e09b92e94664669b020b47a20a1590c4a4a | https://github.com/Waryway/PhpTraitsLibrary/blob/90c02e09b92e94664669b020b47a20a1590c4a4a/src/Generator.php#L14-L29 | train |
ezra-obiwale/dSCore | src/Stdlib/WordFigure.php | WordFigure.toWords | public function toWords($todo = null) {
$this->toWords = true;
if ($todo !== null)
$this->todo = $todo;
if ($this->todo !== null)
return $this->doQuadrillion();
} | php | public function toWords($todo = null) {
$this->toWords = true;
if ($todo !== null)
$this->todo = $todo;
if ($this->todo !== null)
return $this->doQuadrillion();
} | [
"public",
"function",
"toWords",
"(",
"$",
"todo",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"toWords",
"=",
"true",
";",
"if",
"(",
"$",
"todo",
"!==",
"null",
")",
"$",
"this",
"->",
"todo",
"=",
"$",
"todo",
";",
"if",
"(",
"$",
"this",
"->",
"todo",
"!==",
"null",
")",
"return",
"$",
"this",
"->",
"doQuadrillion",
"(",
")",
";",
"}"
] | Converts the figure todo value to words
@param string|int|float $todo The value to work on | [
"Converts",
"the",
"figure",
"todo",
"value",
"to",
"words"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/WordFigure.php#L36-L44 | train |
ezra-obiwale/dSCore | src/Stdlib/WordFigure.php | WordFigure.toFigure | public function toFigure($todo = null) {
$this->toWords = false;
if ($todo !== null)
$this->todo = $todo;
if ($this->todo !== null)
return $this->doQuadrillion();
} | php | public function toFigure($todo = null) {
$this->toWords = false;
if ($todo !== null)
$this->todo = $todo;
if ($this->todo !== null)
return $this->doQuadrillion();
} | [
"public",
"function",
"toFigure",
"(",
"$",
"todo",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"toWords",
"=",
"false",
";",
"if",
"(",
"$",
"todo",
"!==",
"null",
")",
"$",
"this",
"->",
"todo",
"=",
"$",
"todo",
";",
"if",
"(",
"$",
"this",
"->",
"todo",
"!==",
"null",
")",
"return",
"$",
"this",
"->",
"doQuadrillion",
"(",
")",
";",
"}"
] | Converts the word todo value to figure
@param string|int|float $todo The value to work on | [
"Converts",
"the",
"word",
"todo",
"value",
"to",
"figure"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/WordFigure.php#L50-L58 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Query/Grammars/Grammar.php | Grammar.compileNestedJoinConstraint | protected function compileNestedJoinConstraint(array $clause)
{
$clauses = [];
foreach ($clause['join']->clauses as $nestedClause) {
$clauses[] = $this->compileJoinConstraint($nestedClause);
}
$clauses[0] = $this->removeLeadingBoolean($clauses[0]);
$clauses = implode(' ', $clauses);
return "{$clause['boolean']} ({$clauses})";
} | php | protected function compileNestedJoinConstraint(array $clause)
{
$clauses = [];
foreach ($clause['join']->clauses as $nestedClause) {
$clauses[] = $this->compileJoinConstraint($nestedClause);
}
$clauses[0] = $this->removeLeadingBoolean($clauses[0]);
$clauses = implode(' ', $clauses);
return "{$clause['boolean']} ({$clauses})";
} | [
"protected",
"function",
"compileNestedJoinConstraint",
"(",
"array",
"$",
"clause",
")",
"{",
"$",
"clauses",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"clause",
"[",
"'join'",
"]",
"->",
"clauses",
"as",
"$",
"nestedClause",
")",
"{",
"$",
"clauses",
"[",
"]",
"=",
"$",
"this",
"->",
"compileJoinConstraint",
"(",
"$",
"nestedClause",
")",
";",
"}",
"$",
"clauses",
"[",
"0",
"]",
"=",
"$",
"this",
"->",
"removeLeadingBoolean",
"(",
"$",
"clauses",
"[",
"0",
"]",
")",
";",
"$",
"clauses",
"=",
"implode",
"(",
"' '",
",",
"$",
"clauses",
")",
";",
"return",
"\"{$clause['boolean']} ({$clauses})\"",
";",
"}"
] | Create a nested join clause constraint segment.
@param array $clause
@return string | [
"Create",
"a",
"nested",
"join",
"clause",
"constraint",
"segment",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Query/Grammars/Grammar.php#L217-L230 | train |
OUTRAGElib/objectlist | lib/ObjectListRetrievalTrait.php | ObjectListRetrievalTrait.toArray | public function toArray()
{
$output = iterator_to_array($this);
foreach($output as $index => $value)
{
# it's safe to presume this will be a thing
if($value instanceof self)
$output[$index] = $value->toArray();
}
return $output;
} | php | public function toArray()
{
$output = iterator_to_array($this);
foreach($output as $index => $value)
{
# it's safe to presume this will be a thing
if($value instanceof self)
$output[$index] = $value->toArray();
}
return $output;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"output",
"=",
"iterator_to_array",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"output",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"# it's safe to presume this will be a thing",
"if",
"(",
"$",
"value",
"instanceof",
"self",
")",
"$",
"output",
"[",
"$",
"index",
"]",
"=",
"$",
"value",
"->",
"toArray",
"(",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | toArray will return turn itself into arrays | [
"toArray",
"will",
"return",
"turn",
"itself",
"into",
"arrays"
] | 8ac3f9fd99992c58a3f537325e02ba2337f9ee55 | https://github.com/OUTRAGElib/objectlist/blob/8ac3f9fd99992c58a3f537325e02ba2337f9ee55/lib/ObjectListRetrievalTrait.php#L12-L24 | train |
ezra-obiwale/dSCore | src/Stdlib/Session.php | Session.getLifetime | public function getLifetime() {
if (!self::$lifetime) {
$sessionExpirationHours = engineGet('Config', 'sessionExpirationHours', false);
if (!$sessionExpirationHours)
$sessionExpirationHours = 2;
self::$lifetime = 60 * 60 * $sessionExpirationHours;
}
return self::$lifetime;
} | php | public function getLifetime() {
if (!self::$lifetime) {
$sessionExpirationHours = engineGet('Config', 'sessionExpirationHours', false);
if (!$sessionExpirationHours)
$sessionExpirationHours = 2;
self::$lifetime = 60 * 60 * $sessionExpirationHours;
}
return self::$lifetime;
} | [
"public",
"function",
"getLifetime",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"lifetime",
")",
"{",
"$",
"sessionExpirationHours",
"=",
"engineGet",
"(",
"'Config'",
",",
"'sessionExpirationHours'",
",",
"false",
")",
";",
"if",
"(",
"!",
"$",
"sessionExpirationHours",
")",
"$",
"sessionExpirationHours",
"=",
"2",
";",
"self",
"::",
"$",
"lifetime",
"=",
"60",
"*",
"60",
"*",
"$",
"sessionExpirationHours",
";",
"}",
"return",
"self",
"::",
"$",
"lifetime",
";",
"}"
] | Fetch the life time for the session
@return int | [
"Fetch",
"the",
"life",
"time",
"for",
"the",
"session"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Session.php#L38-L47 | train |
ezra-obiwale/dSCore | src/Stdlib/Session.php | Session.save | public static function save($key, $value, $duration = null) {
self::setLifetime($duration);
static::init();
$_SESSION[self::$prepend . $key] = $value;
} | php | public static function save($key, $value, $duration = null) {
self::setLifetime($duration);
static::init();
$_SESSION[self::$prepend . $key] = $value;
} | [
"public",
"static",
"function",
"save",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"duration",
"=",
"null",
")",
"{",
"self",
"::",
"setLifetime",
"(",
"$",
"duration",
")",
";",
"static",
"::",
"init",
"(",
")",
";",
"$",
"_SESSION",
"[",
"self",
"::",
"$",
"prepend",
".",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | Saves to session
@param string $key
@param mixed $value
@param int $duration Duration for which the identity should be valid | [
"Saves",
"to",
"session"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Session.php#L55-L59 | train |
ezra-obiwale/dSCore | src/Stdlib/Session.php | Session.fetch | public static function fetch($key) {
static::init();
if (isset($_SESSION[self::$prepend . $key]))
return $_SESSION[self::$prepend . $key];
} | php | public static function fetch($key) {
static::init();
if (isset($_SESSION[self::$prepend . $key]))
return $_SESSION[self::$prepend . $key];
} | [
"public",
"static",
"function",
"fetch",
"(",
"$",
"key",
")",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"$",
"prepend",
".",
"$",
"key",
"]",
")",
")",
"return",
"$",
"_SESSION",
"[",
"self",
"::",
"$",
"prepend",
".",
"$",
"key",
"]",
";",
"}"
] | Fetches from session
@param string $key
@return mixed | [
"Fetches",
"from",
"session"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Session.php#L66-L70 | train |
ezra-obiwale/dSCore | src/Stdlib/Session.php | Session.remove | public static function remove($key) {
static::init();
if (isset($_SESSION[self::$prepend . $key]))
unset($_SESSION[self::$prepend . $key]);
} | php | public static function remove($key) {
static::init();
if (isset($_SESSION[self::$prepend . $key]))
unset($_SESSION[self::$prepend . $key]);
} | [
"public",
"static",
"function",
"remove",
"(",
"$",
"key",
")",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"$",
"prepend",
".",
"$",
"key",
"]",
")",
")",
"unset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"$",
"prepend",
".",
"$",
"key",
"]",
")",
";",
"}"
] | Removes from session
@param string $key | [
"Removes",
"from",
"session"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Session.php#L76-L80 | train |
sndsgd/sndsgd-task | src/task/Runner.php | Runner.run | public function run($data)
{
$this->task->addValues($data);
if ($this->task->validate() === true) {
return $this->task->run();
}
$errors = $this->task->getErrors();
Env::error($this->formatErrors($errors));
} | php | public function run($data)
{
$this->task->addValues($data);
if ($this->task->validate() === true) {
return $this->task->run();
}
$errors = $this->task->getErrors();
Env::error($this->formatErrors($errors));
} | [
"public",
"function",
"run",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"task",
"->",
"addValues",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"this",
"->",
"task",
"->",
"validate",
"(",
")",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"task",
"->",
"run",
"(",
")",
";",
"}",
"$",
"errors",
"=",
"$",
"this",
"->",
"task",
"->",
"getErrors",
"(",
")",
";",
"Env",
"::",
"error",
"(",
"$",
"this",
"->",
"formatErrors",
"(",
"$",
"errors",
")",
")",
";",
"}"
] | Run a task
@param mixed $data | [
"Run",
"a",
"task"
] | 53185a58fe739e5c4b9e0c96290adaca0cf015d5 | https://github.com/sndsgd/sndsgd-task/blob/53185a58fe739e5c4b9e0c96290adaca0cf015d5/src/task/Runner.php#L67-L76 | train |
squareproton/Bond | src/Bond/Entity/Types/Json.php | Json.makeFromObject | public static function makeFromObject( $object )
{
// inistante object without going via constructer to allow us to
$refl = new \ReflectionClass( __CLASS__ );
$obj = $refl->newInstanceWithoutConstructor();
$obj->isValid = true;
$obj->decoded = $object;
return $obj;
} | php | public static function makeFromObject( $object )
{
// inistante object without going via constructer to allow us to
$refl = new \ReflectionClass( __CLASS__ );
$obj = $refl->newInstanceWithoutConstructor();
$obj->isValid = true;
$obj->decoded = $object;
return $obj;
} | [
"public",
"static",
"function",
"makeFromObject",
"(",
"$",
"object",
")",
"{",
"// inistante object without going via constructer to allow us to",
"$",
"refl",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"__CLASS__",
")",
";",
"$",
"obj",
"=",
"$",
"refl",
"->",
"newInstanceWithoutConstructor",
"(",
")",
";",
"$",
"obj",
"->",
"isValid",
"=",
"true",
";",
"$",
"obj",
"->",
"decoded",
"=",
"$",
"object",
";",
"return",
"$",
"obj",
";",
"}"
] | Static entry point to generate a json_object from something that can be json_serialized
We don't need to validate or calc the json representation as this can be calculated lazily
@return Bond\Entity\Type\Json | [
"Static",
"entry",
"point",
"to",
"generate",
"a",
"json_object",
"from",
"something",
"that",
"can",
"be",
"json_serialized",
"We",
"don",
"t",
"need",
"to",
"validate",
"or",
"calc",
"the",
"json",
"representation",
"as",
"this",
"can",
"be",
"calculated",
"lazily"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/Json.php#L94-L102 | train |
squareproton/Bond | src/Bond/Entity/Types/Json.php | Json.isValid | public function isValid( &$exception = null )
{
$exception = null;
// have we validated this before?
if( $this->isValid === null ) {
$this->decoded = @json_decode( $this->json, true );
// have error?
if( null === $this->decoded and JSON_ERROR_NONE !== $lastError = json_last_error() ) {
// yep
$this->isValid = new BadJsonException( $this->json, $lastError );
$exception = $this->isValid;
} else {
// nope
$this->isValid = true;
}
// is the isValid propety a exception
} elseif ( $this->isValid !== true ) {
$exception = $this->isValid;
}
return $this->isValid === true;
} | php | public function isValid( &$exception = null )
{
$exception = null;
// have we validated this before?
if( $this->isValid === null ) {
$this->decoded = @json_decode( $this->json, true );
// have error?
if( null === $this->decoded and JSON_ERROR_NONE !== $lastError = json_last_error() ) {
// yep
$this->isValid = new BadJsonException( $this->json, $lastError );
$exception = $this->isValid;
} else {
// nope
$this->isValid = true;
}
// is the isValid propety a exception
} elseif ( $this->isValid !== true ) {
$exception = $this->isValid;
}
return $this->isValid === true;
} | [
"public",
"function",
"isValid",
"(",
"&",
"$",
"exception",
"=",
"null",
")",
"{",
"$",
"exception",
"=",
"null",
";",
"// have we validated this before?",
"if",
"(",
"$",
"this",
"->",
"isValid",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"decoded",
"=",
"@",
"json_decode",
"(",
"$",
"this",
"->",
"json",
",",
"true",
")",
";",
"// have error?",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"decoded",
"and",
"JSON_ERROR_NONE",
"!==",
"$",
"lastError",
"=",
"json_last_error",
"(",
")",
")",
"{",
"// yep",
"$",
"this",
"->",
"isValid",
"=",
"new",
"BadJsonException",
"(",
"$",
"this",
"->",
"json",
",",
"$",
"lastError",
")",
";",
"$",
"exception",
"=",
"$",
"this",
"->",
"isValid",
";",
"}",
"else",
"{",
"// nope",
"$",
"this",
"->",
"isValid",
"=",
"true",
";",
"}",
"// is the isValid propety a exception",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isValid",
"!==",
"true",
")",
"{",
"$",
"exception",
"=",
"$",
"this",
"->",
"isValid",
";",
"}",
"return",
"$",
"this",
"->",
"isValid",
"===",
"true",
";",
"}"
] | Does or json object contain valid json
@return bool | [
"Does",
"or",
"json",
"object",
"contain",
"valid",
"json"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/Json.php#L108-L129 | train |
WyriHaximus/TickingPromise | src/TickingFuturePromise.php | TickingFuturePromise.create | public static function create(LoopInterface $loop, callable $check, $value = null, $iterations = 1)
{
return (new self($loop, $check, $value, $iterations))->run();
} | php | public static function create(LoopInterface $loop, callable $check, $value = null, $iterations = 1)
{
return (new self($loop, $check, $value, $iterations))->run();
} | [
"public",
"static",
"function",
"create",
"(",
"LoopInterface",
"$",
"loop",
",",
"callable",
"$",
"check",
",",
"$",
"value",
"=",
"null",
",",
"$",
"iterations",
"=",
"1",
")",
"{",
"return",
"(",
"new",
"self",
"(",
"$",
"loop",
",",
"$",
"check",
",",
"$",
"value",
",",
"$",
"iterations",
")",
")",
"->",
"run",
"(",
")",
";",
"}"
] | Factory used by tickingFuturePromise, see there for more details.
@param LoopInterface $loop ReactPHP event loop.
@param callable $check Callable to run at the future tick.
@param mixed $value Value to pass into $check on tick.
@param int $iterations Number of iterations to call $check in one tick.
@return mixed | [
"Factory",
"used",
"by",
"tickingFuturePromise",
"see",
"there",
"for",
"more",
"details",
"."
] | efdb162d596052455c9ba98aec42e08009c6629b | https://github.com/WyriHaximus/TickingPromise/blob/efdb162d596052455c9ba98aec42e08009c6629b/src/TickingFuturePromise.php#L78-L81 | train |
WyriHaximus/TickingPromise | src/TickingFuturePromise.php | TickingFuturePromise.run | protected function run()
{
futurePromise($this->loop)->then(function (): void {
$this->check();
});
return $this->deferred->promise();
} | php | protected function run()
{
futurePromise($this->loop)->then(function (): void {
$this->check();
});
return $this->deferred->promise();
} | [
"protected",
"function",
"run",
"(",
")",
"{",
"futurePromise",
"(",
"$",
"this",
"->",
"loop",
")",
"->",
"then",
"(",
"function",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"check",
"(",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"deferred",
"->",
"promise",
"(",
")",
";",
"}"
] | Run the ticking future promise.
@return \React\Promise\Promise | [
"Run",
"the",
"ticking",
"future",
"promise",
"."
] | efdb162d596052455c9ba98aec42e08009c6629b | https://github.com/WyriHaximus/TickingPromise/blob/efdb162d596052455c9ba98aec42e08009c6629b/src/TickingFuturePromise.php#L88-L95 | train |
shrink0r/php-schema | src/Property/IntProperty.php | IntProperty.validate | public function validate($value)
{
return is_int($value) ? Ok::unit() : Error::unit([ Error::NON_INT ]);
} | php | public function validate($value)
{
return is_int($value) ? Ok::unit() : Error::unit([ Error::NON_INT ]);
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"return",
"is_int",
"(",
"$",
"value",
")",
"?",
"Ok",
"::",
"unit",
"(",
")",
":",
"Error",
"::",
"unit",
"(",
"[",
"Error",
"::",
"NON_INT",
"]",
")",
";",
"}"
] | Tells if a given value is a valid int.
@param mixed $value
@return ResultInterface Returns Ok if the value is valid, otherwise an Error is returned. | [
"Tells",
"if",
"a",
"given",
"value",
"is",
"a",
"valid",
"int",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/IntProperty.php#L18-L21 | train |
net-tools/core | src/ExceptionHandlers/Formatters/Formatter.php | Formatter.format | public function format(\Throwable $e, $h1)
{
// get body content with stack trace content (stack formatted with strategy passed as constructor parameter)
return $this->body($e, $h1, $this->_stackTraceFormatter->format(new StackTrace($e)));
} | php | public function format(\Throwable $e, $h1)
{
// get body content with stack trace content (stack formatted with strategy passed as constructor parameter)
return $this->body($e, $h1, $this->_stackTraceFormatter->format(new StackTrace($e)));
} | [
"public",
"function",
"format",
"(",
"\\",
"Throwable",
"$",
"e",
",",
"$",
"h1",
")",
"{",
"// get body content with stack trace content (stack formatted with strategy passed as constructor parameter)",
"return",
"$",
"this",
"->",
"body",
"(",
"$",
"e",
",",
"$",
"h1",
",",
"$",
"this",
"->",
"_stackTraceFormatter",
"->",
"format",
"(",
"new",
"StackTrace",
"(",
"$",
"e",
")",
")",
")",
";",
"}"
] | Format an exception as a string with suitable format
@param \Throwable $e Exception to format
@param string $h1 Title of error page (such as "an error has occured")
@return string | [
"Format",
"an",
"exception",
"as",
"a",
"string",
"with",
"suitable",
"format"
] | 51446641cee22c0cf53d2b409c76cc8bd1a187e7 | https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/ExceptionHandlers/Formatters/Formatter.php#L53-L57 | train |
Kris-Kuiper/sFire-Framework | src/Utils/StringToArray.php | StringToArray.execute | public function execute($key = null, $default = null, $data = null) {
//Matching type array
if(is_array($key)) {
foreach($key as $index) {
if(!isset($data[$index])) {
return $default;
}
$data = $data[$index];
}
return $data;
}
//Matching type string
if($key && isset($data[$key])) {
return $data[$key];
}
//Matching type string array
$names = explode('[', $key);
foreach($names as $index => $name) {
$name = rtrim($name, ']');
if(!isset($data[$name])) {
return null;
}
$data = $data[$name];
if($index == count($names) - 1) {
$default = $data;
}
}
return $default;
} | php | public function execute($key = null, $default = null, $data = null) {
//Matching type array
if(is_array($key)) {
foreach($key as $index) {
if(!isset($data[$index])) {
return $default;
}
$data = $data[$index];
}
return $data;
}
//Matching type string
if($key && isset($data[$key])) {
return $data[$key];
}
//Matching type string array
$names = explode('[', $key);
foreach($names as $index => $name) {
$name = rtrim($name, ']');
if(!isset($data[$name])) {
return null;
}
$data = $data[$name];
if($index == count($names) - 1) {
$default = $data;
}
}
return $default;
} | [
"public",
"function",
"execute",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
",",
"$",
"data",
"=",
"null",
")",
"{",
"//Matching type array\r",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"foreach",
"(",
"$",
"key",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"$",
"data",
"=",
"$",
"data",
"[",
"$",
"index",
"]",
";",
"}",
"return",
"$",
"data",
";",
"}",
"//Matching type string\r",
"if",
"(",
"$",
"key",
"&&",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"$",
"key",
"]",
";",
"}",
"//Matching type string array\r",
"$",
"names",
"=",
"explode",
"(",
"'['",
",",
"$",
"key",
")",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"index",
"=>",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"rtrim",
"(",
"$",
"name",
",",
"']'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"data",
"=",
"$",
"data",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"$",
"index",
"==",
"count",
"(",
"$",
"names",
")",
"-",
"1",
")",
"{",
"$",
"default",
"=",
"$",
"data",
";",
"}",
"}",
"return",
"$",
"default",
";",
"}"
] | Get value from array string
@param mixed $key
@param mixed $default
@param mixed $data
@return mixed | [
"Get",
"value",
"from",
"array",
"string"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Utils/StringToArray.php#L21-L62 | train |
modulusphp/utility | Validate.php | Validate.make | public static function make(array $data, array $rules, $unknown = null, $custom = [])
{
$factory = new ValidatorFactory();
if (is_array($unknown) && count($unknown) > 0) {
$custom = $unknown;
}
$response = $factory->make($data, $rules, $custom);
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtoupper($_SERVER['HTTP_X_REQUESTED_WITH']) === 'XMLHTTPREQUEST' &&
$response->fails()) {
return Rest::response()
->json($response->errors()->toArray(), 422);
die();
}
return $response;
} | php | public static function make(array $data, array $rules, $unknown = null, $custom = [])
{
$factory = new ValidatorFactory();
if (is_array($unknown) && count($unknown) > 0) {
$custom = $unknown;
}
$response = $factory->make($data, $rules, $custom);
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtoupper($_SERVER['HTTP_X_REQUESTED_WITH']) === 'XMLHTTPREQUEST' &&
$response->fails()) {
return Rest::response()
->json($response->errors()->toArray(), 422);
die();
}
return $response;
} | [
"public",
"static",
"function",
"make",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"rules",
",",
"$",
"unknown",
"=",
"null",
",",
"$",
"custom",
"=",
"[",
"]",
")",
"{",
"$",
"factory",
"=",
"new",
"ValidatorFactory",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"unknown",
")",
"&&",
"count",
"(",
"$",
"unknown",
")",
">",
"0",
")",
"{",
"$",
"custom",
"=",
"$",
"unknown",
";",
"}",
"$",
"response",
"=",
"$",
"factory",
"->",
"make",
"(",
"$",
"data",
",",
"$",
"rules",
",",
"$",
"custom",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_REQUESTED_WITH'",
"]",
")",
"&&",
"strtoupper",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_REQUESTED_WITH'",
"]",
")",
"===",
"'XMLHTTPREQUEST'",
"&&",
"$",
"response",
"->",
"fails",
"(",
")",
")",
"{",
"return",
"Rest",
"::",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"response",
"->",
"errors",
"(",
")",
"->",
"toArray",
"(",
")",
",",
"422",
")",
";",
"die",
"(",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Make a new validator
@param array $data
@param array $rules
@param mixed $unknown
@param mixed $custom
@return mixed | [
"Make",
"a",
"new",
"validator"
] | c1e127539b13d3ec8381e41c64b881e0701807f5 | https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/Validate.php#L19-L39 | train |
bseddon/XPath20 | Iterator/NodeIterator.php | NodeIterator.NextItem | protected function NextItem()
{
if ( $this->used ) $this->iterator->next();
$this->used = true;
return $this->iterator->current(); // getCurrent();
} | php | protected function NextItem()
{
if ( $this->used ) $this->iterator->next();
$this->used = true;
return $this->iterator->current(); // getCurrent();
} | [
"protected",
"function",
"NextItem",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"used",
")",
"$",
"this",
"->",
"iterator",
"->",
"next",
"(",
")",
";",
"$",
"this",
"->",
"used",
"=",
"true",
";",
"return",
"$",
"this",
"->",
"iterator",
"->",
"current",
"(",
")",
";",
"// getCurrent();\r",
"}"
] | NextItem This function is used if the caller uses 'MoveNext' on the iterator
@return XPathItem | [
"NextItem",
"This",
"function",
"is",
"used",
"if",
"the",
"caller",
"uses",
"MoveNext",
"on",
"the",
"iterator"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Iterator/NodeIterator.php#L99-L104 | train |
MatiasNAmendola/slimpower-auth-core | src/Abstracts/TokenAuthMiddleware.php | TokenAuthMiddleware.fetchData | public function fetchData() {
/* If using PHP in CGI mode and non standard environment */
if (isset($_SERVER[$this->options["environment"]])) {
$message = "Using token from environent";
$header = $_SERVER[$this->options["environment"]];
} else {
$message = "Using token from request header";
$header = $this->app->request->headers("Authorization");
}
$matches = null;
if (preg_match("/Bearer\s+(.*)$/i", $header, $matches)) {
$this->log(LogLevel::DEBUG, $message);
return array(self::KEY_TOKEN => $matches[1]);
}
/* Bearer not found, try a cookie. */
if ($this->app->getCookie($this->options["cookie"])) {
$this->log(LogLevel::DEBUG, "Using token from cookie");
$token = $this->app->getCookie($this->options["cookie"]);
return array(self::KEY_TOKEN => $token);
}
/* If everything fails log and return false. */
$message = "Token not found";
$this->error = new \SlimPower\Authentication\Error();
$this->error->setDescription($message);
$this->log(LogLevel::WARNING, $message);
return false;
} | php | public function fetchData() {
/* If using PHP in CGI mode and non standard environment */
if (isset($_SERVER[$this->options["environment"]])) {
$message = "Using token from environent";
$header = $_SERVER[$this->options["environment"]];
} else {
$message = "Using token from request header";
$header = $this->app->request->headers("Authorization");
}
$matches = null;
if (preg_match("/Bearer\s+(.*)$/i", $header, $matches)) {
$this->log(LogLevel::DEBUG, $message);
return array(self::KEY_TOKEN => $matches[1]);
}
/* Bearer not found, try a cookie. */
if ($this->app->getCookie($this->options["cookie"])) {
$this->log(LogLevel::DEBUG, "Using token from cookie");
$token = $this->app->getCookie($this->options["cookie"]);
return array(self::KEY_TOKEN => $token);
}
/* If everything fails log and return false. */
$message = "Token not found";
$this->error = new \SlimPower\Authentication\Error();
$this->error->setDescription($message);
$this->log(LogLevel::WARNING, $message);
return false;
} | [
"public",
"function",
"fetchData",
"(",
")",
"{",
"/* If using PHP in CGI mode and non standard environment */",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"$",
"this",
"->",
"options",
"[",
"\"environment\"",
"]",
"]",
")",
")",
"{",
"$",
"message",
"=",
"\"Using token from environent\"",
";",
"$",
"header",
"=",
"$",
"_SERVER",
"[",
"$",
"this",
"->",
"options",
"[",
"\"environment\"",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"\"Using token from request header\"",
";",
"$",
"header",
"=",
"$",
"this",
"->",
"app",
"->",
"request",
"->",
"headers",
"(",
"\"Authorization\"",
")",
";",
"}",
"$",
"matches",
"=",
"null",
";",
"if",
"(",
"preg_match",
"(",
"\"/Bearer\\s+(.*)$/i\"",
",",
"$",
"header",
",",
"$",
"matches",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"$",
"message",
")",
";",
"return",
"array",
"(",
"self",
"::",
"KEY_TOKEN",
"=>",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"/* Bearer not found, try a cookie. */",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"getCookie",
"(",
"$",
"this",
"->",
"options",
"[",
"\"cookie\"",
"]",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"Using token from cookie\"",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"app",
"->",
"getCookie",
"(",
"$",
"this",
"->",
"options",
"[",
"\"cookie\"",
"]",
")",
";",
"return",
"array",
"(",
"self",
"::",
"KEY_TOKEN",
"=>",
"$",
"token",
")",
";",
"}",
"/* If everything fails log and return false. */",
"$",
"message",
"=",
"\"Token not found\"",
";",
"$",
"this",
"->",
"error",
"=",
"new",
"\\",
"SlimPower",
"\\",
"Authentication",
"\\",
"Error",
"(",
")",
";",
"$",
"this",
"->",
"error",
"->",
"setDescription",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"WARNING",
",",
"$",
"message",
")",
";",
"return",
"false",
";",
"}"
] | Fetch the access token
@return string|false Base64 encoded JSON Web Token or false if not found. | [
"Fetch",
"the",
"access",
"token"
] | 550ab85d871de8451cb242eaa17f4041ff320b7c | https://github.com/MatiasNAmendola/slimpower-auth-core/blob/550ab85d871de8451cb242eaa17f4041ff320b7c/src/Abstracts/TokenAuthMiddleware.php#L102-L134 | train |
danielgp/common-lib | source/DomPaginationByDanielGP.php | DomPaginationByDanielGP.setArrayToStringForUrl | protected function setArrayToStringForUrl($sSeparator, $aElements, $aExceptedElements = [''])
{
$outArray = $this->normalizeArrayForUrl($aElements);
if (count($outArray) < 1) {
return '';
}
$xptArray = $this->normalizeArrayForUrl($aExceptedElements);
$finalArray = array_diff_key($outArray, $xptArray);
return http_build_query($finalArray, '', $sSeparator);
} | php | protected function setArrayToStringForUrl($sSeparator, $aElements, $aExceptedElements = [''])
{
$outArray = $this->normalizeArrayForUrl($aElements);
if (count($outArray) < 1) {
return '';
}
$xptArray = $this->normalizeArrayForUrl($aExceptedElements);
$finalArray = array_diff_key($outArray, $xptArray);
return http_build_query($finalArray, '', $sSeparator);
} | [
"protected",
"function",
"setArrayToStringForUrl",
"(",
"$",
"sSeparator",
",",
"$",
"aElements",
",",
"$",
"aExceptedElements",
"=",
"[",
"''",
"]",
")",
"{",
"$",
"outArray",
"=",
"$",
"this",
"->",
"normalizeArrayForUrl",
"(",
"$",
"aElements",
")",
";",
"if",
"(",
"count",
"(",
"$",
"outArray",
")",
"<",
"1",
")",
"{",
"return",
"''",
";",
"}",
"$",
"xptArray",
"=",
"$",
"this",
"->",
"normalizeArrayForUrl",
"(",
"$",
"aExceptedElements",
")",
";",
"$",
"finalArray",
"=",
"array_diff_key",
"(",
"$",
"outArray",
",",
"$",
"xptArray",
")",
";",
"return",
"http_build_query",
"(",
"$",
"finalArray",
",",
"''",
",",
"$",
"sSeparator",
")",
";",
"}"
] | Converts an array to string
@param string $sSeparator
@param array $aElements
@return string | [
"Converts",
"an",
"array",
"to",
"string"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomPaginationByDanielGP.php#L100-L109 | train |
danielgp/common-lib | source/DomPaginationByDanielGP.php | DomPaginationByDanielGP.setStartingPageRecord | private function setStartingPageRecord($sDefaultPageNo, $iRecordsPerPage, $iAllRecords, $bKeepFullPage = true)
{
if (is_null($this->tCmnSuperGlobals->get('page'))) {
switch ($sDefaultPageNo) {
case 'last':
$iStartingPageRecord = $iAllRecords - $iRecordsPerPage;
break;
case 'first':
default:
$iStartingPageRecord = 0;
break;
}
} else {
$iStartingPageRecord = ($this->tCmnSuperGlobals->get('page') - 1 ) * $iRecordsPerPage;
}
if (($bKeepFullPage ) && (($iStartingPageRecord + $iRecordsPerPage ) > $iAllRecords)) {
$iStartingPageRecord = $iAllRecords - $iRecordsPerPage;
}
return max(0, $iStartingPageRecord);
} | php | private function setStartingPageRecord($sDefaultPageNo, $iRecordsPerPage, $iAllRecords, $bKeepFullPage = true)
{
if (is_null($this->tCmnSuperGlobals->get('page'))) {
switch ($sDefaultPageNo) {
case 'last':
$iStartingPageRecord = $iAllRecords - $iRecordsPerPage;
break;
case 'first':
default:
$iStartingPageRecord = 0;
break;
}
} else {
$iStartingPageRecord = ($this->tCmnSuperGlobals->get('page') - 1 ) * $iRecordsPerPage;
}
if (($bKeepFullPage ) && (($iStartingPageRecord + $iRecordsPerPage ) > $iAllRecords)) {
$iStartingPageRecord = $iAllRecords - $iRecordsPerPage;
}
return max(0, $iStartingPageRecord);
} | [
"private",
"function",
"setStartingPageRecord",
"(",
"$",
"sDefaultPageNo",
",",
"$",
"iRecordsPerPage",
",",
"$",
"iAllRecords",
",",
"$",
"bKeepFullPage",
"=",
"true",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"tCmnSuperGlobals",
"->",
"get",
"(",
"'page'",
")",
")",
")",
"{",
"switch",
"(",
"$",
"sDefaultPageNo",
")",
"{",
"case",
"'last'",
":",
"$",
"iStartingPageRecord",
"=",
"$",
"iAllRecords",
"-",
"$",
"iRecordsPerPage",
";",
"break",
";",
"case",
"'first'",
":",
"default",
":",
"$",
"iStartingPageRecord",
"=",
"0",
";",
"break",
";",
"}",
"}",
"else",
"{",
"$",
"iStartingPageRecord",
"=",
"(",
"$",
"this",
"->",
"tCmnSuperGlobals",
"->",
"get",
"(",
"'page'",
")",
"-",
"1",
")",
"*",
"$",
"iRecordsPerPage",
";",
"}",
"if",
"(",
"(",
"$",
"bKeepFullPage",
")",
"&&",
"(",
"(",
"$",
"iStartingPageRecord",
"+",
"$",
"iRecordsPerPage",
")",
">",
"$",
"iAllRecords",
")",
")",
"{",
"$",
"iStartingPageRecord",
"=",
"$",
"iAllRecords",
"-",
"$",
"iRecordsPerPage",
";",
"}",
"return",
"max",
"(",
"0",
",",
"$",
"iStartingPageRecord",
")",
";",
"}"
] | Returns starting records for LIMIT clause on SQL interrogation
@version 20080521
@param string $sDefaultPageNo
@param int $iRecordsPerPage
@param int $iAllRecords
@param boolean $bKeepFullPage
@return int | [
"Returns",
"starting",
"records",
"for",
"LIMIT",
"clause",
"on",
"SQL",
"interrogation"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomPaginationByDanielGP.php#L218-L237 | train |
mrstroz/yii2-wavecms-page | models/Page.php | Page.validateUniqueLink | public function validateUniqueLink($attribute)
{
$params = Yii::$app->request->get();
$query = PageLang::find()->joinWith('page')->andWhere([PageLang::tableName() . '.language' => Yii::$app->wavecms->editedLanguage, PageLang::tableName() . '.link' => $this->link]);
if (isset($params['id'])) {
$query->andWhere(['!=', Page::tableName() . '.id', $params['id']]);
}
if ($query->count() !== '0') {
$this->addError($attribute, Yii::t('app', Yii::t('wavecms_page/main', 'Link should be unique.')));
}
} | php | public function validateUniqueLink($attribute)
{
$params = Yii::$app->request->get();
$query = PageLang::find()->joinWith('page')->andWhere([PageLang::tableName() . '.language' => Yii::$app->wavecms->editedLanguage, PageLang::tableName() . '.link' => $this->link]);
if (isset($params['id'])) {
$query->andWhere(['!=', Page::tableName() . '.id', $params['id']]);
}
if ($query->count() !== '0') {
$this->addError($attribute, Yii::t('app', Yii::t('wavecms_page/main', 'Link should be unique.')));
}
} | [
"public",
"function",
"validateUniqueLink",
"(",
"$",
"attribute",
")",
"{",
"$",
"params",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"get",
"(",
")",
";",
"$",
"query",
"=",
"PageLang",
"::",
"find",
"(",
")",
"->",
"joinWith",
"(",
"'page'",
")",
"->",
"andWhere",
"(",
"[",
"PageLang",
"::",
"tableName",
"(",
")",
".",
"'.language'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"wavecms",
"->",
"editedLanguage",
",",
"PageLang",
"::",
"tableName",
"(",
")",
".",
"'.link'",
"=>",
"$",
"this",
"->",
"link",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"query",
"->",
"andWhere",
"(",
"[",
"'!='",
",",
"Page",
"::",
"tableName",
"(",
")",
".",
"'.id'",
",",
"$",
"params",
"[",
"'id'",
"]",
"]",
")",
";",
"}",
"if",
"(",
"$",
"query",
"->",
"count",
"(",
")",
"!==",
"'0'",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"attribute",
",",
"Yii",
"::",
"t",
"(",
"'app'",
",",
"Yii",
"::",
"t",
"(",
"'wavecms_page/main'",
",",
"'Link should be unique.'",
")",
")",
")",
";",
"}",
"}"
] | Validator for unique link per language
@param $attribute
@return void | [
"Validator",
"for",
"unique",
"link",
"per",
"language"
] | c7f867ffc5abd86814230c360aec9b30b6d2e819 | https://github.com/mrstroz/yii2-wavecms-page/blob/c7f867ffc5abd86814230c360aec9b30b6d2e819/models/Page.php#L237-L250 | train |
frodosghost/PublishBundle | EventListener/ObjectPersistSubscriber.php | ObjectPersistSubscriber.getSecurityToken | private function getSecurityToken()
{
if ($this->container->get('security.context')->getToken() instanceof TokenInterface) {
return $this->container->get('security.context')->getToken();
}
return null;
} | php | private function getSecurityToken()
{
if ($this->container->get('security.context')->getToken() instanceof TokenInterface) {
return $this->container->get('security.context')->getToken();
}
return null;
} | [
"private",
"function",
"getSecurityToken",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"instanceof",
"TokenInterface",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Lazy Loading of security context.
Returns TokenInterface
@link(Circular Reference when injecting Security Context, http://stackoverflow.com/a/8713339/174148)
@return TokenInterface | [
"Lazy",
"Loading",
"of",
"security",
"context",
".",
"Returns",
"TokenInterface"
] | 7aaf7d7567a14e57e87b8d7474fbdd064f7b09bc | https://github.com/frodosghost/PublishBundle/blob/7aaf7d7567a14e57e87b8d7474fbdd064f7b09bc/EventListener/ObjectPersistSubscriber.php#L97-L104 | train |
phpgears/event | src/AbstractEvent.php | AbstractEvent.occurred | final protected static function occurred(array $payload, ?TimeProvider $timeProvider = null)
{
$timeProvider = $timeProvider ?? new SystemTimeProvider();
return new static($payload, $timeProvider->getCurrentTime());
} | php | final protected static function occurred(array $payload, ?TimeProvider $timeProvider = null)
{
$timeProvider = $timeProvider ?? new SystemTimeProvider();
return new static($payload, $timeProvider->getCurrentTime());
} | [
"final",
"protected",
"static",
"function",
"occurred",
"(",
"array",
"$",
"payload",
",",
"?",
"TimeProvider",
"$",
"timeProvider",
"=",
"null",
")",
"{",
"$",
"timeProvider",
"=",
"$",
"timeProvider",
"??",
"new",
"SystemTimeProvider",
"(",
")",
";",
"return",
"new",
"static",
"(",
"$",
"payload",
",",
"$",
"timeProvider",
"->",
"getCurrentTime",
"(",
")",
")",
";",
"}"
] | Instantiate new event.
@param array<string, mixed> $payload
@param TimeProvider $timeProvider
@return mixed|self | [
"Instantiate",
"new",
"event",
"."
] | 9b25301837748a67b3b48cc46ad837c859c4522d | https://github.com/phpgears/event/blob/9b25301837748a67b3b48cc46ad837c859c4522d/src/AbstractEvent.php#L58-L63 | train |
nails/module-blog | src/Model/Skin.php | Skin.init | public function init($iBlogId)
{
$this->iActiveBlogId = $iBlogId;
$this->aAvailable[$iBlogId] = array();
$this->aEnabled[$iBlogId] = array();
// Get available skins
$this->aAvailable[$iBlogId] = Components::skins('nails/module-blog');
if (empty($this->aAvailable[$iBlogId])) {
throw new SkinException(
'No skins are available.'
);
}
// Get the skin
$sSkinSlug = appSetting('skin', 'blog-' . $iBlogId) ?: self::DEFAULT_SKIN;
$this->aEnabled[$iBlogId] = $this->get($sSkinSlug);
if (empty($this->aEnabled[$iBlogId])) {
throw new SkinException(
'Skin "' . $sSkinSlug . '" does not exist.'
);
}
} | php | public function init($iBlogId)
{
$this->iActiveBlogId = $iBlogId;
$this->aAvailable[$iBlogId] = array();
$this->aEnabled[$iBlogId] = array();
// Get available skins
$this->aAvailable[$iBlogId] = Components::skins('nails/module-blog');
if (empty($this->aAvailable[$iBlogId])) {
throw new SkinException(
'No skins are available.'
);
}
// Get the skin
$sSkinSlug = appSetting('skin', 'blog-' . $iBlogId) ?: self::DEFAULT_SKIN;
$this->aEnabled[$iBlogId] = $this->get($sSkinSlug);
if (empty($this->aEnabled[$iBlogId])) {
throw new SkinException(
'Skin "' . $sSkinSlug . '" does not exist.'
);
}
} | [
"public",
"function",
"init",
"(",
"$",
"iBlogId",
")",
"{",
"$",
"this",
"->",
"iActiveBlogId",
"=",
"$",
"iBlogId",
";",
"$",
"this",
"->",
"aAvailable",
"[",
"$",
"iBlogId",
"]",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"aEnabled",
"[",
"$",
"iBlogId",
"]",
"=",
"array",
"(",
")",
";",
"// Get available skins",
"$",
"this",
"->",
"aAvailable",
"[",
"$",
"iBlogId",
"]",
"=",
"Components",
"::",
"skins",
"(",
"'nails/module-blog'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"aAvailable",
"[",
"$",
"iBlogId",
"]",
")",
")",
"{",
"throw",
"new",
"SkinException",
"(",
"'No skins are available.'",
")",
";",
"}",
"// Get the skin",
"$",
"sSkinSlug",
"=",
"appSetting",
"(",
"'skin'",
",",
"'blog-'",
".",
"$",
"iBlogId",
")",
"?",
":",
"self",
"::",
"DEFAULT_SKIN",
";",
"$",
"this",
"->",
"aEnabled",
"[",
"$",
"iBlogId",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"sSkinSlug",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"aEnabled",
"[",
"$",
"iBlogId",
"]",
")",
")",
"{",
"throw",
"new",
"SkinException",
"(",
"'Skin \"'",
".",
"$",
"sSkinSlug",
".",
"'\" does not exist.'",
")",
";",
"}",
"}"
] | Setup the model for use with a particular skin | [
"Setup",
"the",
"model",
"for",
"use",
"with",
"a",
"particular",
"skin"
] | 7b369c5209f4343fff7c7e2a22c237d5a95c8c24 | https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/src/Model/Skin.php#L45-L68 | train |
nails/module-blog | src/Model/Skin.php | Skin.get | public function get($sSlug)
{
$aSkins = $this->getAll();
foreach ($aSkins as $oSkin) {
if ($oSkin->slug == $sSlug) {
return $oSkin;
}
}
return false;
} | php | public function get($sSlug)
{
$aSkins = $this->getAll();
foreach ($aSkins as $oSkin) {
if ($oSkin->slug == $sSlug) {
return $oSkin;
}
}
return false;
} | [
"public",
"function",
"get",
"(",
"$",
"sSlug",
")",
"{",
"$",
"aSkins",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"foreach",
"(",
"$",
"aSkins",
"as",
"$",
"oSkin",
")",
"{",
"if",
"(",
"$",
"oSkin",
"->",
"slug",
"==",
"$",
"sSlug",
")",
"{",
"return",
"$",
"oSkin",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Gets a single skin
@param string $sSlug The skin's slug
@return stdClass | [
"Gets",
"a",
"single",
"skin"
] | 7b369c5209f4343fff7c7e2a22c237d5a95c8c24 | https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/src/Model/Skin.php#L111-L122 | train |
zodream/helpers | src/Str.php | Str.multiExplode | public static function multiExplode(array $delimiters, $string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
return explode($delimiters[0], $ready);
} | php | public static function multiExplode(array $delimiters, $string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
return explode($delimiters[0], $ready);
} | [
"public",
"static",
"function",
"multiExplode",
"(",
"array",
"$",
"delimiters",
",",
"$",
"string",
")",
"{",
"$",
"ready",
"=",
"str_replace",
"(",
"$",
"delimiters",
",",
"$",
"delimiters",
"[",
"0",
"]",
",",
"$",
"string",
")",
";",
"return",
"explode",
"(",
"$",
"delimiters",
"[",
"0",
"]",
",",
"$",
"ready",
")",
";",
"}"
] | EXPLODE STRING BY ARRAY
@param array $delimiters
@param $string
@return array | [
"EXPLODE",
"STRING",
"BY",
"ARRAY"
] | 98c533a0a50547bd8e3c97ab750d2d15f8e58b49 | https://github.com/zodream/helpers/blob/98c533a0a50547bd8e3c97ab750d2d15f8e58b49/src/Str.php#L281-L284 | train |
Retentio/Boomgo | src/Boomgo/Builder/Map.php | Map.addDefinition | public function addDefinition(Definition $definition)
{
$attribute = $definition->getAttribute();
$key = $definition->getKey();
$this->mongoIndex[$key] = $attribute;
$this->definitions[$attribute] = $definition;
} | php | public function addDefinition(Definition $definition)
{
$attribute = $definition->getAttribute();
$key = $definition->getKey();
$this->mongoIndex[$key] = $attribute;
$this->definitions[$attribute] = $definition;
} | [
"public",
"function",
"addDefinition",
"(",
"Definition",
"$",
"definition",
")",
"{",
"$",
"attribute",
"=",
"$",
"definition",
"->",
"getAttribute",
"(",
")",
";",
"$",
"key",
"=",
"$",
"definition",
"->",
"getKey",
"(",
")",
";",
"$",
"this",
"->",
"mongoIndex",
"[",
"$",
"key",
"]",
"=",
"$",
"attribute",
";",
"$",
"this",
"->",
"definitions",
"[",
"$",
"attribute",
"]",
"=",
"$",
"definition",
";",
"}"
] | Add a definition
@param Definition $definition | [
"Add",
"a",
"definition"
] | 95cc53777425dd76cd0034046fa4f9e72c04d73a | https://github.com/Retentio/Boomgo/blob/95cc53777425dd76cd0034046fa4f9e72c04d73a/src/Boomgo/Builder/Map.php#L116-L124 | train |
Retentio/Boomgo | src/Boomgo/Builder/Map.php | Map.hasDefinition | public function hasDefinition($identifier)
{
return isset($this->definitions[$identifier]) || isset($this->mongoIndex[$identifier]);
} | php | public function hasDefinition($identifier)
{
return isset($this->definitions[$identifier]) || isset($this->mongoIndex[$identifier]);
} | [
"public",
"function",
"hasDefinition",
"(",
"$",
"identifier",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"definitions",
"[",
"$",
"identifier",
"]",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"mongoIndex",
"[",
"$",
"identifier",
"]",
")",
";",
"}"
] | Check whether a definition exists
@param string $identifier Php attribute name or Document key name
@return boolean | [
"Check",
"whether",
"a",
"definition",
"exists"
] | 95cc53777425dd76cd0034046fa4f9e72c04d73a | https://github.com/Retentio/Boomgo/blob/95cc53777425dd76cd0034046fa4f9e72c04d73a/src/Boomgo/Builder/Map.php#L133-L136 | train |
Retentio/Boomgo | src/Boomgo/Builder/Map.php | Map.getDefinition | public function getDefinition($identifier)
{
// Identifier is a php attribute
if (isset($this->definitions[$identifier])) {
return $this->definitions[$identifier];
}
// Identifier is a MongoDB Key
if (isset($this->mongoIndex[$identifier])) {
return $this->definitions[$this->mongoIndex[$identifier]];
}
return null;
} | php | public function getDefinition($identifier)
{
// Identifier is a php attribute
if (isset($this->definitions[$identifier])) {
return $this->definitions[$identifier];
}
// Identifier is a MongoDB Key
if (isset($this->mongoIndex[$identifier])) {
return $this->definitions[$this->mongoIndex[$identifier]];
}
return null;
} | [
"public",
"function",
"getDefinition",
"(",
"$",
"identifier",
")",
"{",
"// Identifier is a php attribute",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"definitions",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"definitions",
"[",
"$",
"identifier",
"]",
";",
"}",
"// Identifier is a MongoDB Key",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"mongoIndex",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"definitions",
"[",
"$",
"this",
"->",
"mongoIndex",
"[",
"$",
"identifier",
"]",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Return a definition
@param string $identifier Php attribute name or Document key name
@return mixed null|Definition | [
"Return",
"a",
"definition"
] | 95cc53777425dd76cd0034046fa4f9e72c04d73a | https://github.com/Retentio/Boomgo/blob/95cc53777425dd76cd0034046fa4f9e72c04d73a/src/Boomgo/Builder/Map.php#L145-L158 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/AbstractSystemXMLDAO.php | AbstractSystemXMLDAO.delete | public function delete($slug)
{
if(is_object($slug) && $slug instanceof ModelObject)
$slug = $slug->Slug;
$this->Events->trigger(get_class($this).'.delete.pre', $this, $slug);
$this->Events->trigger('AbstractSystemXMLDAO.delete.pre', $this, $slug);
$this->loadSource();
if(isset($this->objectsBySlug[$slug]))
{
$obj = $this->objectsBySlug[$slug];
unset($this->objectsBySlug[$slug]);
unset($this->slugsByID[$obj->AspectID]);
$pKey = array_search($slug, $this->slugsByPluginID[$obj->PluginID]);
unset($this->slugsByPluginID[$pKey]);
}
$this->persistSource();
$this->Events->trigger(get_class($this).'.delete.post', $this, $slug);
$this->Events->trigger('AbstractSystemXMLDAO.delete.post', $this, $slug);
return true;
} | php | public function delete($slug)
{
if(is_object($slug) && $slug instanceof ModelObject)
$slug = $slug->Slug;
$this->Events->trigger(get_class($this).'.delete.pre', $this, $slug);
$this->Events->trigger('AbstractSystemXMLDAO.delete.pre', $this, $slug);
$this->loadSource();
if(isset($this->objectsBySlug[$slug]))
{
$obj = $this->objectsBySlug[$slug];
unset($this->objectsBySlug[$slug]);
unset($this->slugsByID[$obj->AspectID]);
$pKey = array_search($slug, $this->slugsByPluginID[$obj->PluginID]);
unset($this->slugsByPluginID[$pKey]);
}
$this->persistSource();
$this->Events->trigger(get_class($this).'.delete.post', $this, $slug);
$this->Events->trigger('AbstractSystemXMLDAO.delete.post', $this, $slug);
return true;
} | [
"public",
"function",
"delete",
"(",
"$",
"slug",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"slug",
")",
"&&",
"$",
"slug",
"instanceof",
"ModelObject",
")",
"$",
"slug",
"=",
"$",
"slug",
"->",
"Slug",
";",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"get_class",
"(",
"$",
"this",
")",
".",
"'.delete.pre'",
",",
"$",
"this",
",",
"$",
"slug",
")",
";",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"'AbstractSystemXMLDAO.delete.pre'",
",",
"$",
"this",
",",
"$",
"slug",
")",
";",
"$",
"this",
"->",
"loadSource",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"objectsBySlug",
"[",
"$",
"slug",
"]",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"objectsBySlug",
"[",
"$",
"slug",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"objectsBySlug",
"[",
"$",
"slug",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"slugsByID",
"[",
"$",
"obj",
"->",
"AspectID",
"]",
")",
";",
"$",
"pKey",
"=",
"array_search",
"(",
"$",
"slug",
",",
"$",
"this",
"->",
"slugsByPluginID",
"[",
"$",
"obj",
"->",
"PluginID",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"slugsByPluginID",
"[",
"$",
"pKey",
"]",
")",
";",
"}",
"$",
"this",
"->",
"persistSource",
"(",
")",
";",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"get_class",
"(",
"$",
"this",
")",
".",
"'.delete.post'",
",",
"$",
"this",
",",
"$",
"slug",
")",
";",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"'AbstractSystemXMLDAO.delete.post'",
",",
"$",
"this",
",",
"$",
"slug",
")",
";",
"return",
"true",
";",
"}"
] | Removes the aspect and all the aspect relations
@param string $slug The slug of the aspect to remove
@return void | [
"Removes",
"the",
"aspect",
"and",
"all",
"the",
"aspect",
"relations"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/AbstractSystemXMLDAO.php#L231-L259 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/AbstractSystemXMLDAO.php | AbstractSystemXMLDAO.getByID | public function getByID($id)
{
if(array_key_exists($id, $this->idToSlugCache))
$slug = $this->idToSlugCache[$id];
else
$slug = $this->SystemCache->get($this->getModel()->getTableName().':id:'.$id);
if (!empty($slug)) {
return $this->getBySlug($slug);
}
$this->loadSource();
if(!isset($this->slugsByID[$id]))
return null;
$slug = $this->slugsByID[$id];
return $this->getBySlug($slug);
} | php | public function getByID($id)
{
if(array_key_exists($id, $this->idToSlugCache))
$slug = $this->idToSlugCache[$id];
else
$slug = $this->SystemCache->get($this->getModel()->getTableName().':id:'.$id);
if (!empty($slug)) {
return $this->getBySlug($slug);
}
$this->loadSource();
if(!isset($this->slugsByID[$id]))
return null;
$slug = $this->slugsByID[$id];
return $this->getBySlug($slug);
} | [
"public",
"function",
"getByID",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"idToSlugCache",
")",
")",
"$",
"slug",
"=",
"$",
"this",
"->",
"idToSlugCache",
"[",
"$",
"id",
"]",
";",
"else",
"$",
"slug",
"=",
"$",
"this",
"->",
"SystemCache",
"->",
"get",
"(",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"getTableName",
"(",
")",
".",
"':id:'",
".",
"$",
"id",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"slug",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getBySlug",
"(",
"$",
"slug",
")",
";",
"}",
"$",
"this",
"->",
"loadSource",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"slugsByID",
"[",
"$",
"id",
"]",
")",
")",
"return",
"null",
";",
"$",
"slug",
"=",
"$",
"this",
"->",
"slugsByID",
"[",
"$",
"id",
"]",
";",
"return",
"$",
"this",
"->",
"getBySlug",
"(",
"$",
"slug",
")",
";",
"}"
] | Returns the ModelObject containing the specified ID
@param integer $id The ID of the ModelObject to locate
@return ModelObject
@throws Exception if the Object doesn't exist | [
"Returns",
"the",
"ModelObject",
"containing",
"the",
"specified",
"ID"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/AbstractSystemXMLDAO.php#L296-L315 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/AbstractSystemXMLDAO.php | AbstractSystemXMLDAO.findAll | public function findAll(DTO $dto)
{
$sd = get_class($this).(string)serialize($dto);
$slugs = $this->SystemCache->get($sd);
if ($slugs === false) {
$this->loadSource();
$slugs = array();
$sort_array = array();
$dir = 'ASC';
$orderbys = $dto->getOrderBys();
if(!empty($orderbys))
foreach($orderbys as $col => $dir) {}
else
$col = 'Slug';
foreach($this->objectsBySlug as $slug => $obj)
{
if(($val = $dto->getParameter('Slug')) != null)
{
if($obj->Slug != $val)
continue;
}
if(($val = $dto->getParameter('PluginID')) != null)
{
if($obj->PluginID != $val)
continue;
}
$slugs[] = $slug;
$sort_array[] = $obj[$col];
}
array_multisort($sort_array, strtolower($dir)=='asc'?SORT_ASC:SORT_DESC, SORT_REGULAR, $slugs);
$this->SystemCache->put($sd, $slugs, 0);
}
// retrieve objects
$rows = $this->multiGetBySlug($slugs);
$results = array();
foreach ($slugs as $slug) {
if(isset($rows[$slug]))
$results[] = $rows[$slug];
}
return $dto->setResults($results);
} | php | public function findAll(DTO $dto)
{
$sd = get_class($this).(string)serialize($dto);
$slugs = $this->SystemCache->get($sd);
if ($slugs === false) {
$this->loadSource();
$slugs = array();
$sort_array = array();
$dir = 'ASC';
$orderbys = $dto->getOrderBys();
if(!empty($orderbys))
foreach($orderbys as $col => $dir) {}
else
$col = 'Slug';
foreach($this->objectsBySlug as $slug => $obj)
{
if(($val = $dto->getParameter('Slug')) != null)
{
if($obj->Slug != $val)
continue;
}
if(($val = $dto->getParameter('PluginID')) != null)
{
if($obj->PluginID != $val)
continue;
}
$slugs[] = $slug;
$sort_array[] = $obj[$col];
}
array_multisort($sort_array, strtolower($dir)=='asc'?SORT_ASC:SORT_DESC, SORT_REGULAR, $slugs);
$this->SystemCache->put($sd, $slugs, 0);
}
// retrieve objects
$rows = $this->multiGetBySlug($slugs);
$results = array();
foreach ($slugs as $slug) {
if(isset($rows[$slug]))
$results[] = $rows[$slug];
}
return $dto->setResults($results);
} | [
"public",
"function",
"findAll",
"(",
"DTO",
"$",
"dto",
")",
"{",
"$",
"sd",
"=",
"get_class",
"(",
"$",
"this",
")",
".",
"(",
"string",
")",
"serialize",
"(",
"$",
"dto",
")",
";",
"$",
"slugs",
"=",
"$",
"this",
"->",
"SystemCache",
"->",
"get",
"(",
"$",
"sd",
")",
";",
"if",
"(",
"$",
"slugs",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"loadSource",
"(",
")",
";",
"$",
"slugs",
"=",
"array",
"(",
")",
";",
"$",
"sort_array",
"=",
"array",
"(",
")",
";",
"$",
"dir",
"=",
"'ASC'",
";",
"$",
"orderbys",
"=",
"$",
"dto",
"->",
"getOrderBys",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"orderbys",
")",
")",
"foreach",
"(",
"$",
"orderbys",
"as",
"$",
"col",
"=>",
"$",
"dir",
")",
"{",
"}",
"else",
"$",
"col",
"=",
"'Slug'",
";",
"foreach",
"(",
"$",
"this",
"->",
"objectsBySlug",
"as",
"$",
"slug",
"=>",
"$",
"obj",
")",
"{",
"if",
"(",
"(",
"$",
"val",
"=",
"$",
"dto",
"->",
"getParameter",
"(",
"'Slug'",
")",
")",
"!=",
"null",
")",
"{",
"if",
"(",
"$",
"obj",
"->",
"Slug",
"!=",
"$",
"val",
")",
"continue",
";",
"}",
"if",
"(",
"(",
"$",
"val",
"=",
"$",
"dto",
"->",
"getParameter",
"(",
"'PluginID'",
")",
")",
"!=",
"null",
")",
"{",
"if",
"(",
"$",
"obj",
"->",
"PluginID",
"!=",
"$",
"val",
")",
"continue",
";",
"}",
"$",
"slugs",
"[",
"]",
"=",
"$",
"slug",
";",
"$",
"sort_array",
"[",
"]",
"=",
"$",
"obj",
"[",
"$",
"col",
"]",
";",
"}",
"array_multisort",
"(",
"$",
"sort_array",
",",
"strtolower",
"(",
"$",
"dir",
")",
"==",
"'asc'",
"?",
"SORT_ASC",
":",
"SORT_DESC",
",",
"SORT_REGULAR",
",",
"$",
"slugs",
")",
";",
"$",
"this",
"->",
"SystemCache",
"->",
"put",
"(",
"$",
"sd",
",",
"$",
"slugs",
",",
"0",
")",
";",
"}",
"// retrieve objects",
"$",
"rows",
"=",
"$",
"this",
"->",
"multiGetBySlug",
"(",
"$",
"slugs",
")",
";",
"$",
"results",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"slugs",
"as",
"$",
"slug",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"rows",
"[",
"$",
"slug",
"]",
")",
")",
"$",
"results",
"[",
"]",
"=",
"$",
"rows",
"[",
"$",
"slug",
"]",
";",
"}",
"return",
"$",
"dto",
"->",
"setResults",
"(",
"$",
"results",
")",
";",
"}"
] | Finds Aspects.
@param DTO $dto DTO with supported parameters:
<PrimaryKey>
Slug
PluginID
StartDate string ModifiedDate is greater than this value
EndDate string ModifiedDate is less than this value
Search string Matches part of Name, Slug, or Description
@return DTO A filled DTO | [
"Finds",
"Aspects",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/AbstractSystemXMLDAO.php#L417-L472 | train |
rabbitcms/forms | src/Control.php | Control.make | public static function make($name, array $options = []): self
{
$class = new ReflectionClass($options['class'] ?? static::class);
/* @var static $instance */
$instance = $class->newInstanceWithoutConstructor();
$instance->setName($name);
$instance->setOptions($options);
return $instance;
} | php | public static function make($name, array $options = []): self
{
$class = new ReflectionClass($options['class'] ?? static::class);
/* @var static $instance */
$instance = $class->newInstanceWithoutConstructor();
$instance->setName($name);
$instance->setOptions($options);
return $instance;
} | [
"public",
"static",
"function",
"make",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"self",
"{",
"$",
"class",
"=",
"new",
"ReflectionClass",
"(",
"$",
"options",
"[",
"'class'",
"]",
"??",
"static",
"::",
"class",
")",
";",
"/* @var static $instance */",
"$",
"instance",
"=",
"$",
"class",
"->",
"newInstanceWithoutConstructor",
"(",
")",
";",
"$",
"instance",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"instance",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"return",
"$",
"instance",
";",
"}"
] | Make control.
@param string $name
@param array $options
@return Control
@throws \ReflectionException | [
"Make",
"control",
"."
] | 4dd657d1c8caeb0b87f25239fabf5fa064db29cd | https://github.com/rabbitcms/forms/blob/4dd657d1c8caeb0b87f25239fabf5fa064db29cd/src/Control.php#L103-L113 | train |
flexibuild/component | ComponentTrait.php | ComponentTrait.getBehavior | public function getBehavior($name)
{
$this->ensureBehaviors();
return isset($this->__behaviors__[$name]) ? $this->__behaviors__[$name] : null;
} | php | public function getBehavior($name)
{
$this->ensureBehaviors();
return isset($this->__behaviors__[$name]) ? $this->__behaviors__[$name] : null;
} | [
"public",
"function",
"getBehavior",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"ensureBehaviors",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"__behaviors__",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"__behaviors__",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | Returns the named behavior object.
@param string $name the behavior name
@return Behavior the behavior object, or null if the behavior does not exist | [
"Returns",
"the",
"named",
"behavior",
"object",
"."
] | 1817af23e5a51564075785d5591421b86f275d71 | https://github.com/flexibuild/component/blob/1817af23e5a51564075785d5591421b86f275d71/ComponentTrait.php#L457-L461 | train |
flexibuild/component | ComponentTrait.php | ComponentTrait.detachBehaviors | public function detachBehaviors()
{
$this->ensureBehaviors();
foreach ($this->__behaviors__ as $name => $behavior) {
$this->detachBehavior($name);
}
} | php | public function detachBehaviors()
{
$this->ensureBehaviors();
foreach ($this->__behaviors__ as $name => $behavior) {
$this->detachBehavior($name);
}
} | [
"public",
"function",
"detachBehaviors",
"(",
")",
"{",
"$",
"this",
"->",
"ensureBehaviors",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"__behaviors__",
"as",
"$",
"name",
"=>",
"$",
"behavior",
")",
"{",
"$",
"this",
"->",
"detachBehavior",
"(",
"$",
"name",
")",
";",
"}",
"}"
] | Detaches all behaviors from the component. | [
"Detaches",
"all",
"behaviors",
"from",
"the",
"component",
"."
] | 1817af23e5a51564075785d5591421b86f275d71 | https://github.com/flexibuild/component/blob/1817af23e5a51564075785d5591421b86f275d71/ComponentTrait.php#L531-L537 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Comparator/SchemaComparator.php | SchemaComparator.compare | public function compare(Schema $oldSchema, Schema $newSchema)
{
$createdTables = $this->getCreatedTables($oldSchema, $newSchema);
$alteredTables = $this->getAlteredTables($oldSchema, $newSchema);
$droppedTables = $this->getDroppedTables($oldSchema, $newSchema);
$this->detectRenamedTables($createdTables, $droppedTables, $alteredTables);
return new SchemaDiff(
$oldSchema,
$newSchema,
$createdTables,
$alteredTables,
$droppedTables,
$this->getCreatedSequences($oldSchema, $newSchema),
$this->getDroppedSequences($oldSchema, $newSchema),
$this->getCreatedViews($oldSchema, $newSchema),
$this->getDroppedViews($oldSchema, $newSchema)
);
} | php | public function compare(Schema $oldSchema, Schema $newSchema)
{
$createdTables = $this->getCreatedTables($oldSchema, $newSchema);
$alteredTables = $this->getAlteredTables($oldSchema, $newSchema);
$droppedTables = $this->getDroppedTables($oldSchema, $newSchema);
$this->detectRenamedTables($createdTables, $droppedTables, $alteredTables);
return new SchemaDiff(
$oldSchema,
$newSchema,
$createdTables,
$alteredTables,
$droppedTables,
$this->getCreatedSequences($oldSchema, $newSchema),
$this->getDroppedSequences($oldSchema, $newSchema),
$this->getCreatedViews($oldSchema, $newSchema),
$this->getDroppedViews($oldSchema, $newSchema)
);
} | [
"public",
"function",
"compare",
"(",
"Schema",
"$",
"oldSchema",
",",
"Schema",
"$",
"newSchema",
")",
"{",
"$",
"createdTables",
"=",
"$",
"this",
"->",
"getCreatedTables",
"(",
"$",
"oldSchema",
",",
"$",
"newSchema",
")",
";",
"$",
"alteredTables",
"=",
"$",
"this",
"->",
"getAlteredTables",
"(",
"$",
"oldSchema",
",",
"$",
"newSchema",
")",
";",
"$",
"droppedTables",
"=",
"$",
"this",
"->",
"getDroppedTables",
"(",
"$",
"oldSchema",
",",
"$",
"newSchema",
")",
";",
"$",
"this",
"->",
"detectRenamedTables",
"(",
"$",
"createdTables",
",",
"$",
"droppedTables",
",",
"$",
"alteredTables",
")",
";",
"return",
"new",
"SchemaDiff",
"(",
"$",
"oldSchema",
",",
"$",
"newSchema",
",",
"$",
"createdTables",
",",
"$",
"alteredTables",
",",
"$",
"droppedTables",
",",
"$",
"this",
"->",
"getCreatedSequences",
"(",
"$",
"oldSchema",
",",
"$",
"newSchema",
")",
",",
"$",
"this",
"->",
"getDroppedSequences",
"(",
"$",
"oldSchema",
",",
"$",
"newSchema",
")",
",",
"$",
"this",
"->",
"getCreatedViews",
"(",
"$",
"oldSchema",
",",
"$",
"newSchema",
")",
",",
"$",
"this",
"->",
"getDroppedViews",
"(",
"$",
"oldSchema",
",",
"$",
"newSchema",
")",
")",
";",
"}"
] | Compares two schemas.
@param \Fridge\DBAL\Schema\Schema $oldSchema The old schema.
@param \Fridge\DBAL\Schema\Schema $newSchema The new schema.
@return \Fridge\DBAL\Schema\Diff\SchemaDiff The difference between the two schemas. | [
"Compares",
"two",
"schemas",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Comparator/SchemaComparator.php#L45-L64 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Comparator/SchemaComparator.php | SchemaComparator.compareSequences | public function compareSequences(Sequence $oldSequence, Sequence $newSequence)
{
return ($oldSequence->getName() !== $newSequence->getName())
|| ($oldSequence->getInitialValue() !== $newSequence->getInitialValue())
|| ($oldSequence->getIncrementSize() !== $newSequence->getIncrementSize());
} | php | public function compareSequences(Sequence $oldSequence, Sequence $newSequence)
{
return ($oldSequence->getName() !== $newSequence->getName())
|| ($oldSequence->getInitialValue() !== $newSequence->getInitialValue())
|| ($oldSequence->getIncrementSize() !== $newSequence->getIncrementSize());
} | [
"public",
"function",
"compareSequences",
"(",
"Sequence",
"$",
"oldSequence",
",",
"Sequence",
"$",
"newSequence",
")",
"{",
"return",
"(",
"$",
"oldSequence",
"->",
"getName",
"(",
")",
"!==",
"$",
"newSequence",
"->",
"getName",
"(",
")",
")",
"||",
"(",
"$",
"oldSequence",
"->",
"getInitialValue",
"(",
")",
"!==",
"$",
"newSequence",
"->",
"getInitialValue",
"(",
")",
")",
"||",
"(",
"$",
"oldSequence",
"->",
"getIncrementSize",
"(",
")",
"!==",
"$",
"newSequence",
"->",
"getIncrementSize",
"(",
")",
")",
";",
"}"
] | Compares two sequences.
@param \Fridge\DBAL\Schema\Sequence $oldSequence The old sequence.
@param \Fridge\DBAL\Schema\Sequence $newSequence The new sequence.
@return boolean TRUE if sequences are different else FALSE. | [
"Compares",
"two",
"sequences",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Comparator/SchemaComparator.php#L74-L79 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Comparator/SchemaComparator.php | SchemaComparator.compareViews | public function compareViews(View $oldView, View $newView)
{
return ($oldView->getName() !== $newView->getName()) || ($oldView->getSQL() !== $newView->getSQL());
} | php | public function compareViews(View $oldView, View $newView)
{
return ($oldView->getName() !== $newView->getName()) || ($oldView->getSQL() !== $newView->getSQL());
} | [
"public",
"function",
"compareViews",
"(",
"View",
"$",
"oldView",
",",
"View",
"$",
"newView",
")",
"{",
"return",
"(",
"$",
"oldView",
"->",
"getName",
"(",
")",
"!==",
"$",
"newView",
"->",
"getName",
"(",
")",
")",
"||",
"(",
"$",
"oldView",
"->",
"getSQL",
"(",
")",
"!==",
"$",
"newView",
"->",
"getSQL",
"(",
")",
")",
";",
"}"
] | Compares two views.
@param \Fridge\DBAL\Schema\View $oldView The old view.
@param \Fridge\DBAL\Schema\View $newView The new view.
@return boolean TRUE if views are different else FALSE. | [
"Compares",
"two",
"views",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Comparator/SchemaComparator.php#L89-L92 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Comparator/SchemaComparator.php | SchemaComparator.detectRenamedTables | private function detectRenamedTables(array &$createdTables, array &$droppedTables, array &$alteredTables)
{
foreach ($createdTables as $createdIndex => $createdTable) {
foreach ($droppedTables as $droppedIndex => $droppedTable) {
$tableDiff = $this->tableComparator->compare($droppedTable, $createdTable);
if ($tableDiff->hasNameDifferenceOnly()) {
$alteredTables[] = $tableDiff;
unset($createdTables[$createdIndex]);
unset($droppedTables[$droppedIndex]);
break;
}
}
}
} | php | private function detectRenamedTables(array &$createdTables, array &$droppedTables, array &$alteredTables)
{
foreach ($createdTables as $createdIndex => $createdTable) {
foreach ($droppedTables as $droppedIndex => $droppedTable) {
$tableDiff = $this->tableComparator->compare($droppedTable, $createdTable);
if ($tableDiff->hasNameDifferenceOnly()) {
$alteredTables[] = $tableDiff;
unset($createdTables[$createdIndex]);
unset($droppedTables[$droppedIndex]);
break;
}
}
}
} | [
"private",
"function",
"detectRenamedTables",
"(",
"array",
"&",
"$",
"createdTables",
",",
"array",
"&",
"$",
"droppedTables",
",",
"array",
"&",
"$",
"alteredTables",
")",
"{",
"foreach",
"(",
"$",
"createdTables",
"as",
"$",
"createdIndex",
"=>",
"$",
"createdTable",
")",
"{",
"foreach",
"(",
"$",
"droppedTables",
"as",
"$",
"droppedIndex",
"=>",
"$",
"droppedTable",
")",
"{",
"$",
"tableDiff",
"=",
"$",
"this",
"->",
"tableComparator",
"->",
"compare",
"(",
"$",
"droppedTable",
",",
"$",
"createdTable",
")",
";",
"if",
"(",
"$",
"tableDiff",
"->",
"hasNameDifferenceOnly",
"(",
")",
")",
"{",
"$",
"alteredTables",
"[",
"]",
"=",
"$",
"tableDiff",
";",
"unset",
"(",
"$",
"createdTables",
"[",
"$",
"createdIndex",
"]",
")",
";",
"unset",
"(",
"$",
"droppedTables",
"[",
"$",
"droppedIndex",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"}"
] | Detects and rewrites renamed tables.
@param array &$createdTables The create tables.
@param array &$droppedTables The dropped tables.
@param array &$alteredTables The altered tables. | [
"Detects",
"and",
"rewrites",
"renamed",
"tables",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Comparator/SchemaComparator.php#L168-L184 | train |
rutger-speksnijder/restphp | src/RestPHP/Response/Types/XML.php | XML.transformToXml | private function transformToXml($data = [], $hypertextRoutes = [], $depth = 0)
{
// Set the xml string
$xml = '';
// Starting depth, so add the xml starting lines
if ($depth === 0) {
$xml = "<?xml version=\"1.0\"?>\n";
$xml .= "<response>\n";
}
// Check if data is an array. If not, return a response with data to string.
if (!is_array($data)) {
return "<?xml version=\"1.0\"?>\n<response>{$data}{$this->getHypertextXml($hypertextRoutes)}</response>";
}
// Loop through the data
foreach ($data as $k => $v) {
// Add tabs
for ($i = 0; $i < $depth; $i++) {
$xml .= "\t";
}
// Check if key is a number.
// - XML doesn't allow <number></number> tags.
$key = $k;
if (is_int($k) || (int)$k > 0) {
$key = "key_{$k}";
}
// Check if the value is an array. If so, generate xml for it.
if (is_array($v)) {
$xml .= "<{$key}>\n{$this->transformToXml($v, [], $depth+1)}\n</{$key}>\n";
} else {
$xml .= "<{$key}>{$v}</{$key}>\n";
}
}
// Add the closing tag if this is depth 0
if ($depth === 0) {
$xml .= $this->getHypertextXml($hypertextRoutes);
$xml .= "</response>\n";
}
// Return the xml string
return $xml;
} | php | private function transformToXml($data = [], $hypertextRoutes = [], $depth = 0)
{
// Set the xml string
$xml = '';
// Starting depth, so add the xml starting lines
if ($depth === 0) {
$xml = "<?xml version=\"1.0\"?>\n";
$xml .= "<response>\n";
}
// Check if data is an array. If not, return a response with data to string.
if (!is_array($data)) {
return "<?xml version=\"1.0\"?>\n<response>{$data}{$this->getHypertextXml($hypertextRoutes)}</response>";
}
// Loop through the data
foreach ($data as $k => $v) {
// Add tabs
for ($i = 0; $i < $depth; $i++) {
$xml .= "\t";
}
// Check if key is a number.
// - XML doesn't allow <number></number> tags.
$key = $k;
if (is_int($k) || (int)$k > 0) {
$key = "key_{$k}";
}
// Check if the value is an array. If so, generate xml for it.
if (is_array($v)) {
$xml .= "<{$key}>\n{$this->transformToXml($v, [], $depth+1)}\n</{$key}>\n";
} else {
$xml .= "<{$key}>{$v}</{$key}>\n";
}
}
// Add the closing tag if this is depth 0
if ($depth === 0) {
$xml .= $this->getHypertextXml($hypertextRoutes);
$xml .= "</response>\n";
}
// Return the xml string
return $xml;
} | [
"private",
"function",
"transformToXml",
"(",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"hypertextRoutes",
"=",
"[",
"]",
",",
"$",
"depth",
"=",
"0",
")",
"{",
"// Set the xml string",
"$",
"xml",
"=",
"''",
";",
"// Starting depth, so add the xml starting lines",
"if",
"(",
"$",
"depth",
"===",
"0",
")",
"{",
"$",
"xml",
"=",
"\"<?xml version=\\\"1.0\\\"?>\\n\"",
";",
"$",
"xml",
".=",
"\"<response>\\n\"",
";",
"}",
"// Check if data is an array. If not, return a response with data to string.",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"\"<?xml version=\\\"1.0\\\"?>\\n<response>{$data}{$this->getHypertextXml($hypertextRoutes)}</response>\"",
";",
"}",
"// Loop through the data",
"foreach",
"(",
"$",
"data",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"// Add tabs",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"depth",
";",
"$",
"i",
"++",
")",
"{",
"$",
"xml",
".=",
"\"\\t\"",
";",
"}",
"// Check if key is a number.",
"// - XML doesn't allow <number></number> tags.",
"$",
"key",
"=",
"$",
"k",
";",
"if",
"(",
"is_int",
"(",
"$",
"k",
")",
"||",
"(",
"int",
")",
"$",
"k",
">",
"0",
")",
"{",
"$",
"key",
"=",
"\"key_{$k}\"",
";",
"}",
"// Check if the value is an array. If so, generate xml for it.",
"if",
"(",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"$",
"xml",
".=",
"\"<{$key}>\\n{$this->transformToXml($v, [], $depth+1)}\\n</{$key}>\\n\"",
";",
"}",
"else",
"{",
"$",
"xml",
".=",
"\"<{$key}>{$v}</{$key}>\\n\"",
";",
"}",
"}",
"// Add the closing tag if this is depth 0",
"if",
"(",
"$",
"depth",
"===",
"0",
")",
"{",
"$",
"xml",
".=",
"$",
"this",
"->",
"getHypertextXml",
"(",
"$",
"hypertextRoutes",
")",
";",
"$",
"xml",
".=",
"\"</response>\\n\"",
";",
"}",
"// Return the xml string",
"return",
"$",
"xml",
";",
"}"
] | Recursively converts the response into an xml string.
@param mixed $data The data to transform.
@param optional array $hypertextRoutes An array with hypertext routes.
@return string The response as an xml string. | [
"Recursively",
"converts",
"the",
"response",
"into",
"an",
"xml",
"string",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/Response/Types/XML.php#L48-L94 | train |
rutger-speksnijder/restphp | src/RestPHP/Response/Types/XML.php | XML.getHypertextXml | private function getHypertextXml($routes = [])
{
// Check if we have routes
if (!$routes) {
return '';
}
// Loop through the routes and add them as links to the xml
$xml = '';
foreach ($routes as $name => $route) {
$xml .= "<link rel=\"{$name}\" href=\"{$route}\"/>\n";
}
return $xml;
} | php | private function getHypertextXml($routes = [])
{
// Check if we have routes
if (!$routes) {
return '';
}
// Loop through the routes and add them as links to the xml
$xml = '';
foreach ($routes as $name => $route) {
$xml .= "<link rel=\"{$name}\" href=\"{$route}\"/>\n";
}
return $xml;
} | [
"private",
"function",
"getHypertextXml",
"(",
"$",
"routes",
"=",
"[",
"]",
")",
"{",
"// Check if we have routes",
"if",
"(",
"!",
"$",
"routes",
")",
"{",
"return",
"''",
";",
"}",
"// Loop through the routes and add them as links to the xml",
"$",
"xml",
"=",
"''",
";",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"name",
"=>",
"$",
"route",
")",
"{",
"$",
"xml",
".=",
"\"<link rel=\\\"{$name}\\\" href=\\\"{$route}\\\"/>\\n\"",
";",
"}",
"return",
"$",
"xml",
";",
"}"
] | Generates the xml for the hypertext routes.
@param optional array $routes The hypertext routes.
@return string The hypertext routes xml string. | [
"Generates",
"the",
"xml",
"for",
"the",
"hypertext",
"routes",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/Response/Types/XML.php#L103-L116 | train |
modulusphp/http | Route.php | Route.url | public static function url(string $name, ?array $parameters = [])
{
$url = null;
foreach (Swish::$routes as $route) {
if ($route['name'] == $name) {
$url = $route['pattern'];
if ($route['required'] > 0 && ($route['required'] == count($parameters))) {
foreach ($parameters as $name => $parameter) {
$url = str_replace('{' . $name . '}', $parameter, $url);
}
}
}
}
if (str_contains($url, ['{', '}'])) $url = null;
return $url;
} | php | public static function url(string $name, ?array $parameters = [])
{
$url = null;
foreach (Swish::$routes as $route) {
if ($route['name'] == $name) {
$url = $route['pattern'];
if ($route['required'] > 0 && ($route['required'] == count($parameters))) {
foreach ($parameters as $name => $parameter) {
$url = str_replace('{' . $name . '}', $parameter, $url);
}
}
}
}
if (str_contains($url, ['{', '}'])) $url = null;
return $url;
} | [
"public",
"static",
"function",
"url",
"(",
"string",
"$",
"name",
",",
"?",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"null",
";",
"foreach",
"(",
"Swish",
"::",
"$",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"[",
"'name'",
"]",
"==",
"$",
"name",
")",
"{",
"$",
"url",
"=",
"$",
"route",
"[",
"'pattern'",
"]",
";",
"if",
"(",
"$",
"route",
"[",
"'required'",
"]",
">",
"0",
"&&",
"(",
"$",
"route",
"[",
"'required'",
"]",
"==",
"count",
"(",
"$",
"parameters",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"name",
"=>",
"$",
"parameter",
")",
"{",
"$",
"url",
"=",
"str_replace",
"(",
"'{'",
".",
"$",
"name",
".",
"'}'",
",",
"$",
"parameter",
",",
"$",
"url",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"str_contains",
"(",
"$",
"url",
",",
"[",
"'{'",
",",
"'}'",
"]",
")",
")",
"$",
"url",
"=",
"null",
";",
"return",
"$",
"url",
";",
"}"
] | Generate url from route
@param string $name
@param null|array $parameters
@return string $url | [
"Generate",
"url",
"from",
"route"
] | fc5c0f2b582a04de1685578d3fb790686a0a240c | https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Route.php#L130-L149 | train |
OUTRAGElib/fs-temp | lib/TemporaryFilesystemStreamWrapper.php | TemporaryFilesystemStreamWrapper.stream_open | public function stream_open($path, $mode, $options, &$opened_path)
{
$this->path = $path;
$this->resource = fopen($this->getLocalFilesystemPath($path), $mode);
return is_resource($this->resource);
} | php | public function stream_open($path, $mode, $options, &$opened_path)
{
$this->path = $path;
$this->resource = fopen($this->getLocalFilesystemPath($path), $mode);
return is_resource($this->resource);
} | [
"public",
"function",
"stream_open",
"(",
"$",
"path",
",",
"$",
"mode",
",",
"$",
"options",
",",
"&",
"$",
"opened_path",
")",
"{",
"$",
"this",
"->",
"path",
"=",
"$",
"path",
";",
"$",
"this",
"->",
"resource",
"=",
"fopen",
"(",
"$",
"this",
"->",
"getLocalFilesystemPath",
"(",
"$",
"path",
")",
",",
"$",
"mode",
")",
";",
"return",
"is_resource",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"}"
] | Let's create a stream. No file writing necessary here | [
"Let",
"s",
"create",
"a",
"stream",
".",
"No",
"file",
"writing",
"necessary",
"here"
] | 1eb71fd2cab4a379d055b07d868272ea02123dce | https://github.com/OUTRAGElib/fs-temp/blob/1eb71fd2cab4a379d055b07d868272ea02123dce/lib/TemporaryFilesystemStreamWrapper.php#L42-L48 | train |
OUTRAGElib/fs-temp | lib/TemporaryFilesystemStreamWrapper.php | TemporaryFilesystemStreamWrapper.unlink | public function unlink($path)
{
if(isset(static::$pointer_tree[$path_to]))
{
if(is_resource(static::$pointer_tree[$path_to]))
fclose(static::$pointer_tree[$path_to]);
unset(static::$pointer_tree[$path_to]);
}
return true;
} | php | public function unlink($path)
{
if(isset(static::$pointer_tree[$path_to]))
{
if(is_resource(static::$pointer_tree[$path_to]))
fclose(static::$pointer_tree[$path_to]);
unset(static::$pointer_tree[$path_to]);
}
return true;
} | [
"public",
"function",
"unlink",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"pointer_tree",
"[",
"$",
"path_to",
"]",
")",
")",
"{",
"if",
"(",
"is_resource",
"(",
"static",
"::",
"$",
"pointer_tree",
"[",
"$",
"path_to",
"]",
")",
")",
"fclose",
"(",
"static",
"::",
"$",
"pointer_tree",
"[",
"$",
"path_to",
"]",
")",
";",
"unset",
"(",
"static",
"::",
"$",
"pointer_tree",
"[",
"$",
"path_to",
"]",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Remove file from interface | [
"Remove",
"file",
"from",
"interface"
] | 1eb71fd2cab4a379d055b07d868272ea02123dce | https://github.com/OUTRAGElib/fs-temp/blob/1eb71fd2cab4a379d055b07d868272ea02123dce/lib/TemporaryFilesystemStreamWrapper.php#L159-L170 | train |
OUTRAGElib/fs-temp | lib/TemporaryFilesystemStreamWrapper.php | TemporaryFilesystemStreamWrapper.getLocalFilesystemPath | protected function getLocalFilesystemPath($path)
{
if(!isset(static::$pointer_tree[$path]))
static::$pointer_tree[$path] = tmpfile();
if($metadata = stream_get_meta_data(static::$pointer_tree[$path]))
return $metadata["uri"];
return null;
} | php | protected function getLocalFilesystemPath($path)
{
if(!isset(static::$pointer_tree[$path]))
static::$pointer_tree[$path] = tmpfile();
if($metadata = stream_get_meta_data(static::$pointer_tree[$path]))
return $metadata["uri"];
return null;
} | [
"protected",
"function",
"getLocalFilesystemPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"pointer_tree",
"[",
"$",
"path",
"]",
")",
")",
"static",
"::",
"$",
"pointer_tree",
"[",
"$",
"path",
"]",
"=",
"tmpfile",
"(",
")",
";",
"if",
"(",
"$",
"metadata",
"=",
"stream_get_meta_data",
"(",
"static",
"::",
"$",
"pointer_tree",
"[",
"$",
"path",
"]",
")",
")",
"return",
"$",
"metadata",
"[",
"\"uri\"",
"]",
";",
"return",
"null",
";",
"}"
] | Returns an instance of a resource, based on something
The educated folk will notice that this will end up leaving a pointer hanging - the
intention is to never, ever use this pointer - but, keep it languishing in existance | [
"Returns",
"an",
"instance",
"of",
"a",
"resource",
"based",
"on",
"something"
] | 1eb71fd2cab4a379d055b07d868272ea02123dce | https://github.com/OUTRAGElib/fs-temp/blob/1eb71fd2cab4a379d055b07d868272ea02123dce/lib/TemporaryFilesystemStreamWrapper.php#L191-L200 | train |
rodw1995/TemplateParser | src/TemplateParserHelper.php | TemplateParserHelper.loop | public static function loop(array $array, $string, $betweenStrings = PHP_EOL)
{
$output = [];
foreach ($array as $key => $value) {
// Flatten the array with dots and parse it
$output[] = static::parseString($string, array_map('addslashes', static::array_dot($value)));
}
return implode($betweenStrings, $output);
} | php | public static function loop(array $array, $string, $betweenStrings = PHP_EOL)
{
$output = [];
foreach ($array as $key => $value) {
// Flatten the array with dots and parse it
$output[] = static::parseString($string, array_map('addslashes', static::array_dot($value)));
}
return implode($betweenStrings, $output);
} | [
"public",
"static",
"function",
"loop",
"(",
"array",
"$",
"array",
",",
"$",
"string",
",",
"$",
"betweenStrings",
"=",
"PHP_EOL",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Flatten the array with dots and parse it",
"$",
"output",
"[",
"]",
"=",
"static",
"::",
"parseString",
"(",
"$",
"string",
",",
"array_map",
"(",
"'addslashes'",
",",
"static",
"::",
"array_dot",
"(",
"$",
"value",
")",
")",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"betweenStrings",
",",
"$",
"output",
")",
";",
"}"
] | Loop through an array and prints for every element the string
@param array $array
@param $string
@param string $betweenStrings
@return string | [
"Loop",
"through",
"an",
"array",
"and",
"prints",
"for",
"every",
"element",
"the",
"string"
] | ddb53d10f4ab0808bd6a941c6770e9419c50f6e9 | https://github.com/rodw1995/TemplateParser/blob/ddb53d10f4ab0808bd6a941c6770e9419c50f6e9/src/TemplateParserHelper.php#L73-L83 | train |
sil-project/VarietyBundle | src/Admin/VarietyAdmin.php | VarietyAdmin.configureShowFields | protected function configureShowFields(ShowMapper $mapper)
{
// call to aliased trait method
$this->configShowHandlesRelations($mapper);
$this->configureShowDescriptions($mapper);
//Removal of Variety/Strain specific fields
if ($this->getSubject()) {
if ($this->getSubject()->getIsStrain()) {
$tabs = $mapper->getadmin()->getShowTabs();
unset($tabs['form_tab_strains']);
$mapper->getAdmin()->setShowTabs($tabs);
$mapper->remove('children');
$mapper->remove('several_strains');
} else {
$mapper->remove('parent');
}
}
} | php | protected function configureShowFields(ShowMapper $mapper)
{
// call to aliased trait method
$this->configShowHandlesRelations($mapper);
$this->configureShowDescriptions($mapper);
//Removal of Variety/Strain specific fields
if ($this->getSubject()) {
if ($this->getSubject()->getIsStrain()) {
$tabs = $mapper->getadmin()->getShowTabs();
unset($tabs['form_tab_strains']);
$mapper->getAdmin()->setShowTabs($tabs);
$mapper->remove('children');
$mapper->remove('several_strains');
} else {
$mapper->remove('parent');
}
}
} | [
"protected",
"function",
"configureShowFields",
"(",
"ShowMapper",
"$",
"mapper",
")",
"{",
"// call to aliased trait method",
"$",
"this",
"->",
"configShowHandlesRelations",
"(",
"$",
"mapper",
")",
";",
"$",
"this",
"->",
"configureShowDescriptions",
"(",
"$",
"mapper",
")",
";",
"//Removal of Variety/Strain specific fields",
"if",
"(",
"$",
"this",
"->",
"getSubject",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getSubject",
"(",
")",
"->",
"getIsStrain",
"(",
")",
")",
"{",
"$",
"tabs",
"=",
"$",
"mapper",
"->",
"getadmin",
"(",
")",
"->",
"getShowTabs",
"(",
")",
";",
"unset",
"(",
"$",
"tabs",
"[",
"'form_tab_strains'",
"]",
")",
";",
"$",
"mapper",
"->",
"getAdmin",
"(",
")",
"->",
"setShowTabs",
"(",
"$",
"tabs",
")",
";",
"$",
"mapper",
"->",
"remove",
"(",
"'children'",
")",
";",
"$",
"mapper",
"->",
"remove",
"(",
"'several_strains'",
")",
";",
"}",
"else",
"{",
"$",
"mapper",
"->",
"remove",
"(",
"'parent'",
")",
";",
"}",
"}",
"}"
] | Configure Show view fields.
@param ShowMapper $mapper | [
"Configure",
"Show",
"view",
"fields",
"."
] | e9508ce13a4bb277d10bdcd925fdb84bc01f453f | https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Admin/VarietyAdmin.php#L72-L90 | train |
sil-project/VarietyBundle | src/Admin/VarietyAdmin.php | VarietyAdmin.prePersist | public function prePersist($variety)
{
parent::prePersist($variety);
if ($variety->getParent()) {
if ($variety->getParent()->getId() == $variety->getId()) {
$variety->setParent(null);
}
}
// $config = $this->getConfigurationPool()->getContainer()->getParameter('librinfo_varieties')['variety_descriptions'];
//
// foreach($config as $fieldset => $field){
// $getter = 'get' . ucfirst($fieldset) . 'Descriptions';
// $setter = 'set' . ucfirst($fieldset) . 'Descriptions';
//
// $descs = $variety->$getter();
//
// foreach($descs as $key =>$desc)
// if($desc->getValue() == null || $desc->getValue() == '' || $desc->getValue() == 0)
// unset($descs[$key]);
// }
} | php | public function prePersist($variety)
{
parent::prePersist($variety);
if ($variety->getParent()) {
if ($variety->getParent()->getId() == $variety->getId()) {
$variety->setParent(null);
}
}
// $config = $this->getConfigurationPool()->getContainer()->getParameter('librinfo_varieties')['variety_descriptions'];
//
// foreach($config as $fieldset => $field){
// $getter = 'get' . ucfirst($fieldset) . 'Descriptions';
// $setter = 'set' . ucfirst($fieldset) . 'Descriptions';
//
// $descs = $variety->$getter();
//
// foreach($descs as $key =>$desc)
// if($desc->getValue() == null || $desc->getValue() == '' || $desc->getValue() == 0)
// unset($descs[$key]);
// }
} | [
"public",
"function",
"prePersist",
"(",
"$",
"variety",
")",
"{",
"parent",
"::",
"prePersist",
"(",
"$",
"variety",
")",
";",
"if",
"(",
"$",
"variety",
"->",
"getParent",
"(",
")",
")",
"{",
"if",
"(",
"$",
"variety",
"->",
"getParent",
"(",
")",
"->",
"getId",
"(",
")",
"==",
"$",
"variety",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"variety",
"->",
"setParent",
"(",
"null",
")",
";",
"}",
"}",
"// $config = $this->getConfigurationPool()->getContainer()->getParameter('librinfo_varieties')['variety_descriptions'];",
"//",
"// foreach($config as $fieldset => $field){",
"// $getter = 'get' . ucfirst($fieldset) . 'Descriptions';",
"// $setter = 'set' . ucfirst($fieldset) . 'Descriptions';",
"//",
"// $descs = $variety->$getter();",
"//",
"// foreach($descs as $key =>$desc)",
"// if($desc->getValue() == null || $desc->getValue() == '' || $desc->getValue() == 0)",
"// unset($descs[$key]);",
"// }",
"}"
] | prevent primary key loop | [
"prevent",
"primary",
"key",
"loop"
] | e9508ce13a4bb277d10bdcd925fdb84bc01f453f | https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Admin/VarietyAdmin.php#L93-L115 | train |
ronanchilvers/container | src/Container.php | Container.register | public function register(ServiceProviderInterface $provider, $settings = [])
{
$provider->register($this);
foreach ($settings as $key => $value) {
$this->set($key, $value);
}
return $this;
} | php | public function register(ServiceProviderInterface $provider, $settings = [])
{
$provider->register($this);
foreach ($settings as $key => $value) {
$this->set($key, $value);
}
return $this;
} | [
"public",
"function",
"register",
"(",
"ServiceProviderInterface",
"$",
"provider",
",",
"$",
"settings",
"=",
"[",
"]",
")",
"{",
"$",
"provider",
"->",
"register",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Register a service provider, a la Pimple
@param Ronanchilvers\Container\ServiceProviderInterface
@return $this
@author Ronan Chilvers <ronan@d3r.com> | [
"Register",
"a",
"service",
"provider",
"a",
"la",
"Pimple"
] | bada52cba4777738a7eba1e1d182dd385d4f2f97 | https://github.com/ronanchilvers/container/blob/bada52cba4777738a7eba1e1d182dd385d4f2f97/src/Container.php#L73-L81 | train |
ronanchilvers/container | src/Container.php | Container.extend | public function extend($id, $definition)
{
if (!isset($this->extensions[$id])) {
$this->extensions = [];
}
$this->extensions[$id][] = $definition;
} | php | public function extend($id, $definition)
{
if (!isset($this->extensions[$id])) {
$this->extensions = [];
}
$this->extensions[$id][] = $definition;
} | [
"public",
"function",
"extend",
"(",
"$",
"id",
",",
"$",
"definition",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"extensions",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"extensions",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"extensions",
"[",
"$",
"id",
"]",
"[",
"]",
"=",
"$",
"definition",
";",
"}"
] | Extend a service
@param string $id
@param mixed $definition
@author Ronan Chilvers <ronan@d3r.com> | [
"Extend",
"a",
"service"
] | bada52cba4777738a7eba1e1d182dd385d4f2f97 | https://github.com/ronanchilvers/container/blob/bada52cba4777738a7eba1e1d182dd385d4f2f97/src/Container.php#L181-L187 | train |
ronanchilvers/container | src/Container.php | Container.setDefinition | protected function setDefinition($id, $definition, $shared = false)
{
$this->definitions[$id] = $definition;
if (true === $shared) {
$this->shared[$id] = $id;
}
} | php | protected function setDefinition($id, $definition, $shared = false)
{
$this->definitions[$id] = $definition;
if (true === $shared) {
$this->shared[$id] = $id;
}
} | [
"protected",
"function",
"setDefinition",
"(",
"$",
"id",
",",
"$",
"definition",
",",
"$",
"shared",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"definitions",
"[",
"$",
"id",
"]",
"=",
"$",
"definition",
";",
"if",
"(",
"true",
"===",
"$",
"shared",
")",
"{",
"$",
"this",
"->",
"shared",
"[",
"$",
"id",
"]",
"=",
"$",
"id",
";",
"}",
"}"
] | Set a definition in the container
@param string $key
@param mixed $definition
@author Ronan Chilvers <ronan@d3r.com> | [
"Set",
"a",
"definition",
"in",
"the",
"container"
] | bada52cba4777738a7eba1e1d182dd385d4f2f97 | https://github.com/ronanchilvers/container/blob/bada52cba4777738a7eba1e1d182dd385d4f2f97/src/Container.php#L196-L202 | train |
alphalemon/BootstrapBundle | Core/Autoloader/BundlesAutoloader.php | BundlesAutoloader.orderBundles | protected function orderBundles()
{
// Gives a score to each bundle
$order = array();
foreach ($this->overridedBundles as $overriderBundle => $overridedBundles) {
// An overrider bundle enters in the compilation, but takes any point
if (!array_key_exists($overriderBundle, $order)) $order[$overriderBundle] = 0;
// An overrided takes a point everytime is found
foreach ($overridedBundles as $overriderBundle => $overridedBundle) {
if (array_key_exists($overridedBundle, $order)) {
$order[$overridedBundle] = $order[$overridedBundle] + 1;
}
else {
$order[$overridedBundle] = 1;
}
}
}
arsort($order);
// Arranges the bundles entries
foreach ($order as $bundleName => $pos) {
$bundle = $this->bundles[$bundleName];
unset($this->bundles[$bundleName]);
$this->bundles[$bundleName] = $bundle;
}
} | php | protected function orderBundles()
{
// Gives a score to each bundle
$order = array();
foreach ($this->overridedBundles as $overriderBundle => $overridedBundles) {
// An overrider bundle enters in the compilation, but takes any point
if (!array_key_exists($overriderBundle, $order)) $order[$overriderBundle] = 0;
// An overrided takes a point everytime is found
foreach ($overridedBundles as $overriderBundle => $overridedBundle) {
if (array_key_exists($overridedBundle, $order)) {
$order[$overridedBundle] = $order[$overridedBundle] + 1;
}
else {
$order[$overridedBundle] = 1;
}
}
}
arsort($order);
// Arranges the bundles entries
foreach ($order as $bundleName => $pos) {
$bundle = $this->bundles[$bundleName];
unset($this->bundles[$bundleName]);
$this->bundles[$bundleName] = $bundle;
}
} | [
"protected",
"function",
"orderBundles",
"(",
")",
"{",
"// Gives a score to each bundle",
"$",
"order",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"overridedBundles",
"as",
"$",
"overriderBundle",
"=>",
"$",
"overridedBundles",
")",
"{",
"// An overrider bundle enters in the compilation, but takes any point",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"overriderBundle",
",",
"$",
"order",
")",
")",
"$",
"order",
"[",
"$",
"overriderBundle",
"]",
"=",
"0",
";",
"// An overrided takes a point everytime is found",
"foreach",
"(",
"$",
"overridedBundles",
"as",
"$",
"overriderBundle",
"=>",
"$",
"overridedBundle",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"overridedBundle",
",",
"$",
"order",
")",
")",
"{",
"$",
"order",
"[",
"$",
"overridedBundle",
"]",
"=",
"$",
"order",
"[",
"$",
"overridedBundle",
"]",
"+",
"1",
";",
"}",
"else",
"{",
"$",
"order",
"[",
"$",
"overridedBundle",
"]",
"=",
"1",
";",
"}",
"}",
"}",
"arsort",
"(",
"$",
"order",
")",
";",
"// Arranges the bundles entries",
"foreach",
"(",
"$",
"order",
"as",
"$",
"bundleName",
"=>",
"$",
"pos",
")",
"{",
"$",
"bundle",
"=",
"$",
"this",
"->",
"bundles",
"[",
"$",
"bundleName",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"bundles",
"[",
"$",
"bundleName",
"]",
")",
";",
"$",
"this",
"->",
"bundles",
"[",
"$",
"bundleName",
"]",
"=",
"$",
"bundle",
";",
"}",
"}"
] | Orders the bundles according to bundle's json param "overrided" | [
"Orders",
"the",
"bundles",
"according",
"to",
"bundle",
"s",
"json",
"param",
"overrided"
] | 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Autoloader/BundlesAutoloader.php#L129-L157 | train |
alphalemon/BootstrapBundle | Core/Autoloader/BundlesAutoloader.php | BundlesAutoloader.arrangeBundlesForEnvironment | protected function arrangeBundlesForEnvironment()
{
foreach ($this->autoloaderCollection as $autoloader) {
$autoloaderBundles = $autoloader->getBundles();
foreach ($autoloaderBundles as $environment => $bundles) {
foreach ($bundles as $bundle) {
$this->environmentsBundles[$environment][] = $bundle;
}
}
}
$this->register('all');
$this->register($this->environment);
$this->orderBundles();
} | php | protected function arrangeBundlesForEnvironment()
{
foreach ($this->autoloaderCollection as $autoloader) {
$autoloaderBundles = $autoloader->getBundles();
foreach ($autoloaderBundles as $environment => $bundles) {
foreach ($bundles as $bundle) {
$this->environmentsBundles[$environment][] = $bundle;
}
}
}
$this->register('all');
$this->register($this->environment);
$this->orderBundles();
} | [
"protected",
"function",
"arrangeBundlesForEnvironment",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"autoloaderCollection",
"as",
"$",
"autoloader",
")",
"{",
"$",
"autoloaderBundles",
"=",
"$",
"autoloader",
"->",
"getBundles",
"(",
")",
";",
"foreach",
"(",
"$",
"autoloaderBundles",
"as",
"$",
"environment",
"=>",
"$",
"bundles",
")",
"{",
"foreach",
"(",
"$",
"bundles",
"as",
"$",
"bundle",
")",
"{",
"$",
"this",
"->",
"environmentsBundles",
"[",
"$",
"environment",
"]",
"[",
"]",
"=",
"$",
"bundle",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"register",
"(",
"'all'",
")",
";",
"$",
"this",
"->",
"register",
"(",
"$",
"this",
"->",
"environment",
")",
";",
"$",
"this",
"->",
"orderBundles",
"(",
")",
";",
"}"
] | Parsers the autoloaders and arranges the bundles for environment | [
"Parsers",
"the",
"autoloaders",
"and",
"arranges",
"the",
"bundles",
"for",
"environment"
] | 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Autoloader/BundlesAutoloader.php#L162-L176 | train |
alphalemon/BootstrapBundle | Core/Autoloader/BundlesAutoloader.php | BundlesAutoloader.install | protected function install()
{
$installScripts = array();
foreach ($this->autoloaderCollection as $dir => $jsonAutoloader) {
$bundleName = $jsonAutoloader->getBundleName();
$this->installPackage($dir, $jsonAutoloader);
// Check if the bundle under exam has attached an ActionManager file
$actionsManager = $jsonAutoloader->getActionManager();
if ((!array_key_exists($bundleName, $this->installedBundles) && null !== $actionsManager)) {
if (null !== $jsonAutoloader->getActionManagerClass()) {
$installScripts[$bundleName] = $actionsManager;
// Copies the current ActionManager class to app/config/bundles/cache folder
// because it must be preserved when a bundle is uninstalled
$reflection = new \ReflectionClass($actionsManager);
$fileName = $reflection->getFileName();
$className = $this->cachePath . '/' . $bundleName . '/' . basename($fileName);
$this->filesystem->copy($fileName, $className, true);
}
}
unset($this->installedBundles[$bundleName]);
}
$installerScript = $this->scriptFactory->createScript('PreBootInstaller');
$installerScript->executeActions($installScripts);
} | php | protected function install()
{
$installScripts = array();
foreach ($this->autoloaderCollection as $dir => $jsonAutoloader) {
$bundleName = $jsonAutoloader->getBundleName();
$this->installPackage($dir, $jsonAutoloader);
// Check if the bundle under exam has attached an ActionManager file
$actionsManager = $jsonAutoloader->getActionManager();
if ((!array_key_exists($bundleName, $this->installedBundles) && null !== $actionsManager)) {
if (null !== $jsonAutoloader->getActionManagerClass()) {
$installScripts[$bundleName] = $actionsManager;
// Copies the current ActionManager class to app/config/bundles/cache folder
// because it must be preserved when a bundle is uninstalled
$reflection = new \ReflectionClass($actionsManager);
$fileName = $reflection->getFileName();
$className = $this->cachePath . '/' . $bundleName . '/' . basename($fileName);
$this->filesystem->copy($fileName, $className, true);
}
}
unset($this->installedBundles[$bundleName]);
}
$installerScript = $this->scriptFactory->createScript('PreBootInstaller');
$installerScript->executeActions($installScripts);
} | [
"protected",
"function",
"install",
"(",
")",
"{",
"$",
"installScripts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"autoloaderCollection",
"as",
"$",
"dir",
"=>",
"$",
"jsonAutoloader",
")",
"{",
"$",
"bundleName",
"=",
"$",
"jsonAutoloader",
"->",
"getBundleName",
"(",
")",
";",
"$",
"this",
"->",
"installPackage",
"(",
"$",
"dir",
",",
"$",
"jsonAutoloader",
")",
";",
"// Check if the bundle under exam has attached an ActionManager file",
"$",
"actionsManager",
"=",
"$",
"jsonAutoloader",
"->",
"getActionManager",
"(",
")",
";",
"if",
"(",
"(",
"!",
"array_key_exists",
"(",
"$",
"bundleName",
",",
"$",
"this",
"->",
"installedBundles",
")",
"&&",
"null",
"!==",
"$",
"actionsManager",
")",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"jsonAutoloader",
"->",
"getActionManagerClass",
"(",
")",
")",
"{",
"$",
"installScripts",
"[",
"$",
"bundleName",
"]",
"=",
"$",
"actionsManager",
";",
"// Copies the current ActionManager class to app/config/bundles/cache folder",
"// because it must be preserved when a bundle is uninstalled",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"actionsManager",
")",
";",
"$",
"fileName",
"=",
"$",
"reflection",
"->",
"getFileName",
"(",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"cachePath",
".",
"'/'",
".",
"$",
"bundleName",
".",
"'/'",
".",
"basename",
"(",
"$",
"fileName",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"copy",
"(",
"$",
"fileName",
",",
"$",
"className",
",",
"true",
")",
";",
"}",
"}",
"unset",
"(",
"$",
"this",
"->",
"installedBundles",
"[",
"$",
"bundleName",
"]",
")",
";",
"}",
"$",
"installerScript",
"=",
"$",
"this",
"->",
"scriptFactory",
"->",
"createScript",
"(",
"'PreBootInstaller'",
")",
";",
"$",
"installerScript",
"->",
"executeActions",
"(",
"$",
"installScripts",
")",
";",
"}"
] | Instantiates the bundles that must be autoconfigured, parsing the autoload_namespaces.php file
generated by composer | [
"Instantiates",
"the",
"bundles",
"that",
"must",
"be",
"autoconfigured",
"parsing",
"the",
"autoload_namespaces",
".",
"php",
"file",
"generated",
"by",
"composer"
] | 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Autoloader/BundlesAutoloader.php#L210-L237 | train |
alphalemon/BootstrapBundle | Core/Autoloader/BundlesAutoloader.php | BundlesAutoloader.installPackage | protected function installPackage($sourceFolder, JsonAutoloader $autoloader)
{
$bundleName = $autoloader->getBundleName();
if (array_key_exists('all', $autoloader->getBundles()) || array_key_exists($this->environment, $autoloader->getBundles())) {
$target = $this->autoloadersPath . '/' . $bundleName . '.json';
$this->copy($autoloader->getFilename(), $target);
$sourceFolder = $sourceFolder . '/Resources/config';
$filename = $bundleName . '.yml';
$this->copyConfigurationFile('config', $filename, $sourceFolder, $this->configPath);
$this->copy($sourceFolder . '/routing.yml', $this->routingPath . '/' . $filename);
}
} | php | protected function installPackage($sourceFolder, JsonAutoloader $autoloader)
{
$bundleName = $autoloader->getBundleName();
if (array_key_exists('all', $autoloader->getBundles()) || array_key_exists($this->environment, $autoloader->getBundles())) {
$target = $this->autoloadersPath . '/' . $bundleName . '.json';
$this->copy($autoloader->getFilename(), $target);
$sourceFolder = $sourceFolder . '/Resources/config';
$filename = $bundleName . '.yml';
$this->copyConfigurationFile('config', $filename, $sourceFolder, $this->configPath);
$this->copy($sourceFolder . '/routing.yml', $this->routingPath . '/' . $filename);
}
} | [
"protected",
"function",
"installPackage",
"(",
"$",
"sourceFolder",
",",
"JsonAutoloader",
"$",
"autoloader",
")",
"{",
"$",
"bundleName",
"=",
"$",
"autoloader",
"->",
"getBundleName",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'all'",
",",
"$",
"autoloader",
"->",
"getBundles",
"(",
")",
")",
"||",
"array_key_exists",
"(",
"$",
"this",
"->",
"environment",
",",
"$",
"autoloader",
"->",
"getBundles",
"(",
")",
")",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"autoloadersPath",
".",
"'/'",
".",
"$",
"bundleName",
".",
"'.json'",
";",
"$",
"this",
"->",
"copy",
"(",
"$",
"autoloader",
"->",
"getFilename",
"(",
")",
",",
"$",
"target",
")",
";",
"$",
"sourceFolder",
"=",
"$",
"sourceFolder",
".",
"'/Resources/config'",
";",
"$",
"filename",
"=",
"$",
"bundleName",
".",
"'.yml'",
";",
"$",
"this",
"->",
"copyConfigurationFile",
"(",
"'config'",
",",
"$",
"filename",
",",
"$",
"sourceFolder",
",",
"$",
"this",
"->",
"configPath",
")",
";",
"$",
"this",
"->",
"copy",
"(",
"$",
"sourceFolder",
".",
"'/routing.yml'",
",",
"$",
"this",
"->",
"routingPath",
".",
"'/'",
".",
"$",
"filename",
")",
";",
"}",
"}"
] | Installs the autoloader.json, the routing and config files
@param string $sourceFolder The source folder where the autoloader is placed
@param JsonAutoloader $autoloader The generated autoloader object | [
"Installs",
"the",
"autoloader",
".",
"json",
"the",
"routing",
"and",
"config",
"files"
] | 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Autoloader/BundlesAutoloader.php#L245-L258 | train |
alphalemon/BootstrapBundle | Core/Autoloader/BundlesAutoloader.php | BundlesAutoloader.retrieveInstalledBundles | protected function retrieveInstalledBundles()
{
$finder = new Finder();
$autoloaders = $finder->files()->depth(0)->name('*.json')->in($this->autoloadersPath);
foreach ($autoloaders as $autoloader) {
$bundleName = strtolower(basename($autoloader->getFilename(), '.json'));
$jsonAutoloader = new JsonAutoloader($bundleName, (string)$autoloader);
$this->installedBundles[$bundleName] = $jsonAutoloader;
}
} | php | protected function retrieveInstalledBundles()
{
$finder = new Finder();
$autoloaders = $finder->files()->depth(0)->name('*.json')->in($this->autoloadersPath);
foreach ($autoloaders as $autoloader) {
$bundleName = strtolower(basename($autoloader->getFilename(), '.json'));
$jsonAutoloader = new JsonAutoloader($bundleName, (string)$autoloader);
$this->installedBundles[$bundleName] = $jsonAutoloader;
}
} | [
"protected",
"function",
"retrieveInstalledBundles",
"(",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"autoloaders",
"=",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"depth",
"(",
"0",
")",
"->",
"name",
"(",
"'*.json'",
")",
"->",
"in",
"(",
"$",
"this",
"->",
"autoloadersPath",
")",
";",
"foreach",
"(",
"$",
"autoloaders",
"as",
"$",
"autoloader",
")",
"{",
"$",
"bundleName",
"=",
"strtolower",
"(",
"basename",
"(",
"$",
"autoloader",
"->",
"getFilename",
"(",
")",
",",
"'.json'",
")",
")",
";",
"$",
"jsonAutoloader",
"=",
"new",
"JsonAutoloader",
"(",
"$",
"bundleName",
",",
"(",
"string",
")",
"$",
"autoloader",
")",
";",
"$",
"this",
"->",
"installedBundles",
"[",
"$",
"bundleName",
"]",
"=",
"$",
"jsonAutoloader",
";",
"}",
"}"
] | Retrieves the current installed bundles | [
"Retrieves",
"the",
"current",
"installed",
"bundles"
] | 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Autoloader/BundlesAutoloader.php#L291-L300 | train |
alphalemon/BootstrapBundle | Core/Autoloader/BundlesAutoloader.php | BundlesAutoloader.getBundleName | protected function getBundleName($path)
{
if (is_dir($path)) {
$finder = new Finder();
$bundles = $finder->files()->depth(0)->name('*Bundle.php')->in($path);
foreach ($bundles as $bundle) {
return basename($bundle->getFilename(), 'Bundle.php');
}
}
return null;
} | php | protected function getBundleName($path)
{
if (is_dir($path)) {
$finder = new Finder();
$bundles = $finder->files()->depth(0)->name('*Bundle.php')->in($path);
foreach ($bundles as $bundle) {
return basename($bundle->getFilename(), 'Bundle.php');
}
}
return null;
} | [
"protected",
"function",
"getBundleName",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"bundles",
"=",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"depth",
"(",
"0",
")",
"->",
"name",
"(",
"'*Bundle.php'",
")",
"->",
"in",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"bundles",
"as",
"$",
"bundle",
")",
"{",
"return",
"basename",
"(",
"$",
"bundle",
"->",
"getFilename",
"(",
")",
",",
"'Bundle.php'",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Retrieves the current bundle class
@param string $path The bundle's path
@return string | [
"Retrieves",
"the",
"current",
"bundle",
"class"
] | 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Autoloader/BundlesAutoloader.php#L308-L319 | train |
alphalemon/BootstrapBundle | Core/Autoloader/BundlesAutoloader.php | BundlesAutoloader.copy | protected function copy($source, $target)
{
if (is_file($source)) {
$exists = is_file($target) ? true :false;
$this->filesystem->copy($source, $target);
if (!$exists) {
return true;
}
}
return false;
} | php | protected function copy($source, $target)
{
if (is_file($source)) {
$exists = is_file($target) ? true :false;
$this->filesystem->copy($source, $target);
if (!$exists) {
return true;
}
}
return false;
} | [
"protected",
"function",
"copy",
"(",
"$",
"source",
",",
"$",
"target",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"source",
")",
")",
"{",
"$",
"exists",
"=",
"is_file",
"(",
"$",
"target",
")",
"?",
"true",
":",
"false",
";",
"$",
"this",
"->",
"filesystem",
"->",
"copy",
"(",
"$",
"source",
",",
"$",
"target",
")",
";",
"if",
"(",
"!",
"$",
"exists",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Copies the source file
@param string $source
@param string $target
@return boolean | [
"Copies",
"the",
"source",
"file"
] | 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Autoloader/BundlesAutoloader.php#L348-L360 | train |
alphalemon/BootstrapBundle | Core/Autoloader/BundlesAutoloader.php | BundlesAutoloader.setupFolders | private function setupFolders()
{
$this->basePath = $this->kernelDir . '/config/bundles';
$this->autoloadersPath = $this->basePath . '/autoloaders';
$this->configPath = $this->basePath . '/config';
$this->routingPath = $this->basePath . '/routing';
$this->cachePath = $this->basePath . '/cache';
$this->filesystem->mkdir(array(
$this->basePath,
$this->autoloadersPath,
$this->configPath,
$this->routingPath,
$this->cachePath,));
} | php | private function setupFolders()
{
$this->basePath = $this->kernelDir . '/config/bundles';
$this->autoloadersPath = $this->basePath . '/autoloaders';
$this->configPath = $this->basePath . '/config';
$this->routingPath = $this->basePath . '/routing';
$this->cachePath = $this->basePath . '/cache';
$this->filesystem->mkdir(array(
$this->basePath,
$this->autoloadersPath,
$this->configPath,
$this->routingPath,
$this->cachePath,));
} | [
"private",
"function",
"setupFolders",
"(",
")",
"{",
"$",
"this",
"->",
"basePath",
"=",
"$",
"this",
"->",
"kernelDir",
".",
"'/config/bundles'",
";",
"$",
"this",
"->",
"autoloadersPath",
"=",
"$",
"this",
"->",
"basePath",
".",
"'/autoloaders'",
";",
"$",
"this",
"->",
"configPath",
"=",
"$",
"this",
"->",
"basePath",
".",
"'/config'",
";",
"$",
"this",
"->",
"routingPath",
"=",
"$",
"this",
"->",
"basePath",
".",
"'/routing'",
";",
"$",
"this",
"->",
"cachePath",
"=",
"$",
"this",
"->",
"basePath",
".",
"'/cache'",
";",
"$",
"this",
"->",
"filesystem",
"->",
"mkdir",
"(",
"array",
"(",
"$",
"this",
"->",
"basePath",
",",
"$",
"this",
"->",
"autoloadersPath",
",",
"$",
"this",
"->",
"configPath",
",",
"$",
"this",
"->",
"routingPath",
",",
"$",
"this",
"->",
"cachePath",
",",
")",
")",
";",
"}"
] | Sets up the paths and creates the folder if they not exist | [
"Sets",
"up",
"the",
"paths",
"and",
"creates",
"the",
"folder",
"if",
"they",
"not",
"exist"
] | 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Autoloader/BundlesAutoloader.php#L365-L379 | train |
alphalemon/BootstrapBundle | Core/Autoloader/BundlesAutoloader.php | BundlesAutoloader.requireCachedClasses | private function requireCachedClasses()
{
$classPath = $this->cachePath;
if (is_dir($classPath)) {
$finder = new Finder();
$actionManagerFiles = $finder->files()->depth(1)->name('*.php')->in($classPath);
foreach ($actionManagerFiles as $actionManagerFile) {
$classFileName = (string)$actionManagerFile;
$classContents = file_get_contents($classFileName);
preg_match('/namespace ([\w\\\]+);.*?class ([\w]+).*?{/s', $classContents, $match);
if (isset($match[1]) && isset($match[2])) {
$class = $match[1] . '\\' . $match[2];
if (!in_array($class, get_declared_classes())) @require_once $classFileName;
}
}
}
} | php | private function requireCachedClasses()
{
$classPath = $this->cachePath;
if (is_dir($classPath)) {
$finder = new Finder();
$actionManagerFiles = $finder->files()->depth(1)->name('*.php')->in($classPath);
foreach ($actionManagerFiles as $actionManagerFile) {
$classFileName = (string)$actionManagerFile;
$classContents = file_get_contents($classFileName);
preg_match('/namespace ([\w\\\]+);.*?class ([\w]+).*?{/s', $classContents, $match);
if (isset($match[1]) && isset($match[2])) {
$class = $match[1] . '\\' . $match[2];
if (!in_array($class, get_declared_classes())) @require_once $classFileName;
}
}
}
} | [
"private",
"function",
"requireCachedClasses",
"(",
")",
"{",
"$",
"classPath",
"=",
"$",
"this",
"->",
"cachePath",
";",
"if",
"(",
"is_dir",
"(",
"$",
"classPath",
")",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"actionManagerFiles",
"=",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"depth",
"(",
"1",
")",
"->",
"name",
"(",
"'*.php'",
")",
"->",
"in",
"(",
"$",
"classPath",
")",
";",
"foreach",
"(",
"$",
"actionManagerFiles",
"as",
"$",
"actionManagerFile",
")",
"{",
"$",
"classFileName",
"=",
"(",
"string",
")",
"$",
"actionManagerFile",
";",
"$",
"classContents",
"=",
"file_get_contents",
"(",
"$",
"classFileName",
")",
";",
"preg_match",
"(",
"'/namespace ([\\w\\\\\\]+);.*?class ([\\w]+).*?{/s'",
",",
"$",
"classContents",
",",
"$",
"match",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"1",
"]",
")",
"&&",
"isset",
"(",
"$",
"match",
"[",
"2",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"match",
"[",
"1",
"]",
".",
"'\\\\'",
".",
"$",
"match",
"[",
"2",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"class",
",",
"get_declared_classes",
"(",
")",
")",
")",
"@",
"require_once",
"$",
"classFileName",
";",
"}",
"}",
"}",
"}"
] | Requires the cached classes when needed | [
"Requires",
"the",
"cached",
"classes",
"when",
"needed"
] | 27ff5cbc58d58149ec72a974f2a9d765a6fd37a6 | https://github.com/alphalemon/BootstrapBundle/blob/27ff5cbc58d58149ec72a974f2a9d765a6fd37a6/Core/Autoloader/BundlesAutoloader.php#L384-L400 | train |
gplcart/cli | Main.php | Main.getRoutes | public function getRoutes()
{
$list = array();
foreach (glob(__DIR__ . '/config/commands/*.php') as $file) {
$command = pathinfo($file, PATHINFO_FILENAME);
$list[$command] = gplcart_config_get($file);
$method = $command;
$parts = explode('-', $command);
if (count($parts) > 1) {
$method = array_pop($parts);
}
$class_name = implode('', $parts);
$list[$command]['handlers']['controller'] = array(
"gplcart\\modules\\cli\\controllers\\commands\\$class_name", "cmd$method$class_name");
}
return $list;
} | php | public function getRoutes()
{
$list = array();
foreach (glob(__DIR__ . '/config/commands/*.php') as $file) {
$command = pathinfo($file, PATHINFO_FILENAME);
$list[$command] = gplcart_config_get($file);
$method = $command;
$parts = explode('-', $command);
if (count($parts) > 1) {
$method = array_pop($parts);
}
$class_name = implode('', $parts);
$list[$command]['handlers']['controller'] = array(
"gplcart\\modules\\cli\\controllers\\commands\\$class_name", "cmd$method$class_name");
}
return $list;
} | [
"public",
"function",
"getRoutes",
"(",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"glob",
"(",
"__DIR__",
".",
"'/config/commands/*.php'",
")",
"as",
"$",
"file",
")",
"{",
"$",
"command",
"=",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_FILENAME",
")",
";",
"$",
"list",
"[",
"$",
"command",
"]",
"=",
"gplcart_config_get",
"(",
"$",
"file",
")",
";",
"$",
"method",
"=",
"$",
"command",
";",
"$",
"parts",
"=",
"explode",
"(",
"'-'",
",",
"$",
"command",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"1",
")",
"{",
"$",
"method",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"$",
"class_name",
"=",
"implode",
"(",
"''",
",",
"$",
"parts",
")",
";",
"$",
"list",
"[",
"$",
"command",
"]",
"[",
"'handlers'",
"]",
"[",
"'controller'",
"]",
"=",
"array",
"(",
"\"gplcart\\\\modules\\\\cli\\\\controllers\\\\commands\\\\$class_name\"",
",",
"\"cmd$method$class_name\"",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
] | Returns an array of supported command routes
@return array | [
"Returns",
"an",
"array",
"of",
"supported",
"command",
"routes"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/Main.php#L32-L55 | train |
leprephp/di | src/Container.php | Container.set | public function set(string $id, $service)
{
if ($this->frozen) {
throw new FrozenContainerException(
"The container is frozen and is not possible to define the new service \"{$id}\"."
);
}
$this->definitions[$id] = $service;
// clean alias and internal cache
unset($this->services[$id]);
unset($this->aliases[$id]);
return $this;
} | php | public function set(string $id, $service)
{
if ($this->frozen) {
throw new FrozenContainerException(
"The container is frozen and is not possible to define the new service \"{$id}\"."
);
}
$this->definitions[$id] = $service;
// clean alias and internal cache
unset($this->services[$id]);
unset($this->aliases[$id]);
return $this;
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"id",
",",
"$",
"service",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"frozen",
")",
"{",
"throw",
"new",
"FrozenContainerException",
"(",
"\"The container is frozen and is not possible to define the new service \\\"{$id}\\\".\"",
")",
";",
"}",
"$",
"this",
"->",
"definitions",
"[",
"$",
"id",
"]",
"=",
"$",
"service",
";",
"// clean alias and internal cache",
"unset",
"(",
"$",
"this",
"->",
"services",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"id",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a new service.
@param string $id
@param mixed $service
@return $this | [
"Defines",
"a",
"new",
"service",
"."
] | d7de90c0d44714abd70c4f5bd5341a1a87203a7e | https://github.com/leprephp/di/blob/d7de90c0d44714abd70c4f5bd5341a1a87203a7e/src/Container.php#L80-L95 | train |
leprephp/di | src/Container.php | Container.alias | public function alias(string $alias, string $original)
{
$this->aliases[$alias] = $this->getRealId($original);
return $this;
} | php | public function alias(string $alias, string $original)
{
$this->aliases[$alias] = $this->getRealId($original);
return $this;
} | [
"public",
"function",
"alias",
"(",
"string",
"$",
"alias",
",",
"string",
"$",
"original",
")",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"this",
"->",
"getRealId",
"(",
"$",
"original",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets an alias for a service.
@param string $alias
@param string $original
@return $this | [
"Sets",
"an",
"alias",
"for",
"a",
"service",
"."
] | d7de90c0d44714abd70c4f5bd5341a1a87203a7e | https://github.com/leprephp/di/blob/d7de90c0d44714abd70c4f5bd5341a1a87203a7e/src/Container.php#L104-L109 | train |
leprephp/di | src/Container.php | Container.getNew | public function getNew(string $id)
{
$definition = $this->raw($id);
if (is_callable($definition)) {
$service = call_user_func($definition, $this);
} else {
$service = $definition;
}
if (isset($this->extensionQueues[$id])) {
$service = $this->extensionQueues[$id]->getService($service);
}
return $service;
} | php | public function getNew(string $id)
{
$definition = $this->raw($id);
if (is_callable($definition)) {
$service = call_user_func($definition, $this);
} else {
$service = $definition;
}
if (isset($this->extensionQueues[$id])) {
$service = $this->extensionQueues[$id]->getService($service);
}
return $service;
} | [
"public",
"function",
"getNew",
"(",
"string",
"$",
"id",
")",
"{",
"$",
"definition",
"=",
"$",
"this",
"->",
"raw",
"(",
"$",
"id",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"definition",
")",
")",
"{",
"$",
"service",
"=",
"call_user_func",
"(",
"$",
"definition",
",",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"service",
"=",
"$",
"definition",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"extensionQueues",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"extensionQueues",
"[",
"$",
"id",
"]",
"->",
"getService",
"(",
"$",
"service",
")",
";",
"}",
"return",
"$",
"service",
";",
"}"
] | Forces the container to return a new instance of the service.
@param string $id
@return mixed
@throws \InvalidArgumentException | [
"Forces",
"the",
"container",
"to",
"return",
"a",
"new",
"instance",
"of",
"the",
"service",
"."
] | d7de90c0d44714abd70c4f5bd5341a1a87203a7e | https://github.com/leprephp/di/blob/d7de90c0d44714abd70c4f5bd5341a1a87203a7e/src/Container.php#L118-L133 | train |
leprephp/di | src/Container.php | Container.raw | public function raw(string $id)
{
$id = $this->getRealId($id);
if (array_key_exists($id, $this->definitions)) {
return $this->definitions[$id];
}
throw new Exception\NotFoundException($id);
} | php | public function raw(string $id)
{
$id = $this->getRealId($id);
if (array_key_exists($id, $this->definitions)) {
return $this->definitions[$id];
}
throw new Exception\NotFoundException($id);
} | [
"public",
"function",
"raw",
"(",
"string",
"$",
"id",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getRealId",
"(",
"$",
"id",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"definitions",
")",
")",
"{",
"return",
"$",
"this",
"->",
"definitions",
"[",
"$",
"id",
"]",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"NotFoundException",
"(",
"$",
"id",
")",
";",
"}"
] | Gets the raw definition of the service.
@param string $id
@return mixed
@throws Exception\NotFoundException | [
"Gets",
"the",
"raw",
"definition",
"of",
"the",
"service",
"."
] | d7de90c0d44714abd70c4f5bd5341a1a87203a7e | https://github.com/leprephp/di/blob/d7de90c0d44714abd70c4f5bd5341a1a87203a7e/src/Container.php#L142-L151 | train |
TeknooSoftware/east-foundation | src/universal/Router/Result.php | Result.getReflectionInstance | private function getReflectionInstance()
{
if (\is_array($this->controller) && 2 === \count($this->controller)) {
//Reflection the method's argument in the controller class
return new \ReflectionMethod($this->controller[0], $this->controller[1]);
}
if (\is_object($this->controller) && !$this->controller instanceof \Closure) {
//Reflection the method's arguments of the callable object
$controllerReflected = new \ReflectionObject($this->controller);
return $controllerReflected->getMethod('__invoke');
}
return new \ReflectionFunction($this->controller);
} | php | private function getReflectionInstance()
{
if (\is_array($this->controller) && 2 === \count($this->controller)) {
//Reflection the method's argument in the controller class
return new \ReflectionMethod($this->controller[0], $this->controller[1]);
}
if (\is_object($this->controller) && !$this->controller instanceof \Closure) {
//Reflection the method's arguments of the callable object
$controllerReflected = new \ReflectionObject($this->controller);
return $controllerReflected->getMethod('__invoke');
}
return new \ReflectionFunction($this->controller);
} | [
"private",
"function",
"getReflectionInstance",
"(",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"controller",
")",
"&&",
"2",
"===",
"\\",
"count",
"(",
"$",
"this",
"->",
"controller",
")",
")",
"{",
"//Reflection the method's argument in the controller class",
"return",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"this",
"->",
"controller",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"controller",
"[",
"1",
"]",
")",
";",
"}",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"this",
"->",
"controller",
")",
"&&",
"!",
"$",
"this",
"->",
"controller",
"instanceof",
"\\",
"Closure",
")",
"{",
"//Reflection the method's arguments of the callable object",
"$",
"controllerReflected",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"this",
"->",
"controller",
")",
";",
"return",
"$",
"controllerReflected",
"->",
"getMethod",
"(",
"'__invoke'",
")",
";",
"}",
"return",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"this",
"->",
"controller",
")",
";",
"}"
] | To generate the \Reflection object dedicated to the controller. The controller is a callable, so it can be
a method of an object, a invokable object, or a function.
@return \ReflectionFunction|\ReflectionMethod
@throws \ReflectionException | [
"To",
"generate",
"the",
"\\",
"Reflection",
"object",
"dedicated",
"to",
"the",
"controller",
".",
"The",
"controller",
"is",
"a",
"callable",
"so",
"it",
"can",
"be",
"a",
"method",
"of",
"an",
"object",
"a",
"invokable",
"object",
"or",
"a",
"function",
"."
] | 45ca97c83ba08b973877a472c731f27ca1e82cdf | https://github.com/TeknooSoftware/east-foundation/blob/45ca97c83ba08b973877a472c731f27ca1e82cdf/src/universal/Router/Result.php#L92-L107 | train |
TeknooSoftware/east-foundation | src/universal/Router/Result.php | Result.extractArguments | private function extractArguments(): array
{
$parameters = [];
//Use the Reflection API to create Parameter Value object
foreach ($this->getReflectionInstance()->getParameters() as $param) {
$name = $param->getName();
$hasDefault = $param->isDefaultValueAvailable();
//Default value. To null if the parameter has no default value
$defaultValue = null;
if (true === $hasDefault) {
$defaultValue = $param->getDefaultValue();
}
$class = $param->getClass();
$parameters[$name] = new Parameter($name, $hasDefault, $defaultValue, $class);
}
return $parameters;
} | php | private function extractArguments(): array
{
$parameters = [];
//Use the Reflection API to create Parameter Value object
foreach ($this->getReflectionInstance()->getParameters() as $param) {
$name = $param->getName();
$hasDefault = $param->isDefaultValueAvailable();
//Default value. To null if the parameter has no default value
$defaultValue = null;
if (true === $hasDefault) {
$defaultValue = $param->getDefaultValue();
}
$class = $param->getClass();
$parameters[$name] = new Parameter($name, $hasDefault, $defaultValue, $class);
}
return $parameters;
} | [
"private",
"function",
"extractArguments",
"(",
")",
":",
"array",
"{",
"$",
"parameters",
"=",
"[",
"]",
";",
"//Use the Reflection API to create Parameter Value object",
"foreach",
"(",
"$",
"this",
"->",
"getReflectionInstance",
"(",
")",
"->",
"getParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"$",
"name",
"=",
"$",
"param",
"->",
"getName",
"(",
")",
";",
"$",
"hasDefault",
"=",
"$",
"param",
"->",
"isDefaultValueAvailable",
"(",
")",
";",
"//Default value. To null if the parameter has no default value",
"$",
"defaultValue",
"=",
"null",
";",
"if",
"(",
"true",
"===",
"$",
"hasDefault",
")",
"{",
"$",
"defaultValue",
"=",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
";",
"}",
"$",
"class",
"=",
"$",
"param",
"->",
"getClass",
"(",
")",
";",
"$",
"parameters",
"[",
"$",
"name",
"]",
"=",
"new",
"Parameter",
"(",
"$",
"name",
",",
"$",
"hasDefault",
",",
"$",
"defaultValue",
",",
"$",
"class",
")",
";",
"}",
"return",
"$",
"parameters",
";",
"}"
] | To extract controller's parameter from \Reflection Api and convert into ParameterInterface instance.
@return array
@throws \ReflectionException | [
"To",
"extract",
"controller",
"s",
"parameter",
"from",
"\\",
"Reflection",
"Api",
"and",
"convert",
"into",
"ParameterInterface",
"instance",
"."
] | 45ca97c83ba08b973877a472c731f27ca1e82cdf | https://github.com/TeknooSoftware/east-foundation/blob/45ca97c83ba08b973877a472c731f27ca1e82cdf/src/universal/Router/Result.php#L115-L135 | train |
padosoft/HTTPClient | src/HTTPClient.php | HTTPClient.getHeadersString | public function getHeadersString(\Psr\Http\Message\ResponseInterface $psr7response)
{
$strHeaders = '';
if($psr7response === null)
{
return $strHeaders;
}
$arrHeaders = $psr7response->getHeaders();
if (!is_array($arrHeaders) || count($arrHeaders) < 1) {
return '';
}
foreach ($arrHeaders as $key => $value) {
$strVal = '';
if(is_array($value) && count($value)>0){
$strVal = $value[0];
}elseif (is_string($value)){
$strVal = $value;
}
$strHeaders .= $key.':'.$strVal.PHP_EOL;
}
return $strHeaders;
} | php | public function getHeadersString(\Psr\Http\Message\ResponseInterface $psr7response)
{
$strHeaders = '';
if($psr7response === null)
{
return $strHeaders;
}
$arrHeaders = $psr7response->getHeaders();
if (!is_array($arrHeaders) || count($arrHeaders) < 1) {
return '';
}
foreach ($arrHeaders as $key => $value) {
$strVal = '';
if(is_array($value) && count($value)>0){
$strVal = $value[0];
}elseif (is_string($value)){
$strVal = $value;
}
$strHeaders .= $key.':'.$strVal.PHP_EOL;
}
return $strHeaders;
} | [
"public",
"function",
"getHeadersString",
"(",
"\\",
"Psr",
"\\",
"Http",
"\\",
"Message",
"\\",
"ResponseInterface",
"$",
"psr7response",
")",
"{",
"$",
"strHeaders",
"=",
"''",
";",
"if",
"(",
"$",
"psr7response",
"===",
"null",
")",
"{",
"return",
"$",
"strHeaders",
";",
"}",
"$",
"arrHeaders",
"=",
"$",
"psr7response",
"->",
"getHeaders",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arrHeaders",
")",
"||",
"count",
"(",
"$",
"arrHeaders",
")",
"<",
"1",
")",
"{",
"return",
"''",
";",
"}",
"foreach",
"(",
"$",
"arrHeaders",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"strVal",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"count",
"(",
"$",
"value",
")",
">",
"0",
")",
"{",
"$",
"strVal",
"=",
"$",
"value",
"[",
"0",
"]",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"strVal",
"=",
"$",
"value",
";",
"}",
"$",
"strHeaders",
".=",
"$",
"key",
".",
"':'",
".",
"$",
"strVal",
".",
"PHP_EOL",
";",
"}",
"return",
"$",
"strHeaders",
";",
"}"
] | Get psr7 headers array and return string representation.
@param \Psr\Http\Message\ResponseInterface
@return string | [
"Get",
"psr7",
"headers",
"array",
"and",
"return",
"string",
"representation",
"."
] | 916f3832275bfcb5cc0691a7f39e4c74557dabc4 | https://github.com/padosoft/HTTPClient/blob/916f3832275bfcb5cc0691a7f39e4c74557dabc4/src/HTTPClient.php#L227-L254 | train |
yuncms/yii2-oauth2 | frontend/controllers/AuthController.php | AuthController.actionAuthorize | public function actionAuthorize()
{
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
if ($this->isOauthRequest) {
$this->finishAuthorization();
} else {
return $this->goBack();
}
} else {
$this->layout = false;
return $this->render('authorize', [
'model' => $model,
]);
}
} | php | public function actionAuthorize()
{
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
if ($this->isOauthRequest) {
$this->finishAuthorization();
} else {
return $this->goBack();
}
} else {
$this->layout = false;
return $this->render('authorize', [
'model' => $model,
]);
}
} | [
"public",
"function",
"actionAuthorize",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"LoginForm",
"(",
")",
";",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"login",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isOauthRequest",
")",
"{",
"$",
"this",
"->",
"finishAuthorization",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"goBack",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"layout",
"=",
"false",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'authorize'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}",
"}"
] | Display login form, signup or something else.
AuthClients such as Google also may be used | [
"Display",
"login",
"form",
"signup",
"or",
"something",
"else",
".",
"AuthClients",
"such",
"as",
"Google",
"also",
"may",
"be",
"used"
] | 7fb41fc56d4a6a5f4107aec5429580729257ed3a | https://github.com/yuncms/yii2-oauth2/blob/7fb41fc56d4a6a5f4107aec5429580729257ed3a/frontend/controllers/AuthController.php#L65-L80 | train |
yuncms/yii2-oauth2 | frontend/controllers/AuthController.php | AuthController.successCallback | public function successCallback($client)
{
$account = Social::find()->byClient($client)->one();
if ($account === null) {
$account = Social::create($client);
}
if ($account->user instanceof Yii::$app->user->id) {
if ($account->user->isBlocked) {
Yii::$app->session->setFlash('danger', Yii::t('oauth2', 'Your account has been blocked.'));
$this->action->successUrl = Url::to(['/oauth2/auth/authorize']);
} else {
Yii::$app->user->login($account->user, $this->rememberFor);
if ($this->isOauthRequest) {
$this->finishAuthorization();
}
}
} else {
$this->action->successUrl = Url::to(['/oauth2/auth/authorize']);
}
} | php | public function successCallback($client)
{
$account = Social::find()->byClient($client)->one();
if ($account === null) {
$account = Social::create($client);
}
if ($account->user instanceof Yii::$app->user->id) {
if ($account->user->isBlocked) {
Yii::$app->session->setFlash('danger', Yii::t('oauth2', 'Your account has been blocked.'));
$this->action->successUrl = Url::to(['/oauth2/auth/authorize']);
} else {
Yii::$app->user->login($account->user, $this->rememberFor);
if ($this->isOauthRequest) {
$this->finishAuthorization();
}
}
} else {
$this->action->successUrl = Url::to(['/oauth2/auth/authorize']);
}
} | [
"public",
"function",
"successCallback",
"(",
"$",
"client",
")",
"{",
"$",
"account",
"=",
"Social",
"::",
"find",
"(",
")",
"->",
"byClient",
"(",
"$",
"client",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"account",
"===",
"null",
")",
"{",
"$",
"account",
"=",
"Social",
"::",
"create",
"(",
"$",
"client",
")",
";",
"}",
"if",
"(",
"$",
"account",
"->",
"user",
"instanceof",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"id",
")",
"{",
"if",
"(",
"$",
"account",
"->",
"user",
"->",
"isBlocked",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'danger'",
",",
"Yii",
"::",
"t",
"(",
"'oauth2'",
",",
"'Your account has been blocked.'",
")",
")",
";",
"$",
"this",
"->",
"action",
"->",
"successUrl",
"=",
"Url",
"::",
"to",
"(",
"[",
"'/oauth2/auth/authorize'",
"]",
")",
";",
"}",
"else",
"{",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"login",
"(",
"$",
"account",
"->",
"user",
",",
"$",
"this",
"->",
"rememberFor",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isOauthRequest",
")",
"{",
"$",
"this",
"->",
"finishAuthorization",
"(",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"action",
"->",
"successUrl",
"=",
"Url",
"::",
"to",
"(",
"[",
"'/oauth2/auth/authorize'",
"]",
")",
";",
"}",
"}"
] | OPTIONAL
Third party oauth callback sample
@param \yii\authclient\OAuth2 $client | [
"OPTIONAL",
"Third",
"party",
"oauth",
"callback",
"sample"
] | 7fb41fc56d4a6a5f4107aec5429580729257ed3a | https://github.com/yuncms/yii2-oauth2/blob/7fb41fc56d4a6a5f4107aec5429580729257ed3a/frontend/controllers/AuthController.php#L96-L115 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/ValueGenerator/UuidGenerator.php | UuidGenerator.generate | public function generate(DocumentManager $dm, $document)
{
$UUID = $this->generateV4();
return $this->generateV5($UUID, $this->salt ?: php_uname('n'));
} | php | public function generate(DocumentManager $dm, $document)
{
$UUID = $this->generateV4();
return $this->generateV5($UUID, $this->salt ?: php_uname('n'));
} | [
"public",
"function",
"generate",
"(",
"DocumentManager",
"$",
"dm",
",",
"$",
"document",
")",
"{",
"$",
"UUID",
"=",
"$",
"this",
"->",
"generateV4",
"(",
")",
";",
"return",
"$",
"this",
"->",
"generateV5",
"(",
"$",
"UUID",
",",
"$",
"this",
"->",
"salt",
"?",
":",
"php_uname",
"(",
"'n'",
")",
")",
";",
"}"
] | Generate a new UUID.
@param DocumentManager $dm Not used
@param object $document Not used
@return string | [
"Generate",
"a",
"new",
"UUID",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/ValueGenerator/UuidGenerator.php#L29-L34 | train |
angrycoders/db-driver | src/Database/SQL/SQLEncoder.php | SQLEncoder.encodeCreateTable | public static function encodeCreateTable($tableName, $fields)
{
$query = "CREATE TABLE IF NOT EXISTS $tableName (";
$keys = array_keys($fields);
$size = sizeof($keys);
foreach ($keys as $index => $field) {
$query .= " $field";
$attribs = $fields[$field];
foreach ($attribs as $i => $attrib) {
if ($i == 1)
$query .= ($attrib == "0" ? "" : "($attrib)");
else
$query .= " $attrib";
}
if ($index != ($size - 1))
$query .= " ,";
}
$query .= ") ENGINE=InnoDB DEFAULT CHARSET=latin1;";
return $query;
} | php | public static function encodeCreateTable($tableName, $fields)
{
$query = "CREATE TABLE IF NOT EXISTS $tableName (";
$keys = array_keys($fields);
$size = sizeof($keys);
foreach ($keys as $index => $field) {
$query .= " $field";
$attribs = $fields[$field];
foreach ($attribs as $i => $attrib) {
if ($i == 1)
$query .= ($attrib == "0" ? "" : "($attrib)");
else
$query .= " $attrib";
}
if ($index != ($size - 1))
$query .= " ,";
}
$query .= ") ENGINE=InnoDB DEFAULT CHARSET=latin1;";
return $query;
} | [
"public",
"static",
"function",
"encodeCreateTable",
"(",
"$",
"tableName",
",",
"$",
"fields",
")",
"{",
"$",
"query",
"=",
"\"CREATE TABLE IF NOT EXISTS $tableName (\"",
";",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"fields",
")",
";",
"$",
"size",
"=",
"sizeof",
"(",
"$",
"keys",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"index",
"=>",
"$",
"field",
")",
"{",
"$",
"query",
".=",
"\" $field\"",
";",
"$",
"attribs",
"=",
"$",
"fields",
"[",
"$",
"field",
"]",
";",
"foreach",
"(",
"$",
"attribs",
"as",
"$",
"i",
"=>",
"$",
"attrib",
")",
"{",
"if",
"(",
"$",
"i",
"==",
"1",
")",
"$",
"query",
".=",
"(",
"$",
"attrib",
"==",
"\"0\"",
"?",
"\"\"",
":",
"\"($attrib)\"",
")",
";",
"else",
"$",
"query",
".=",
"\" $attrib\"",
";",
"}",
"if",
"(",
"$",
"index",
"!=",
"(",
"$",
"size",
"-",
"1",
")",
")",
"$",
"query",
".=",
"\" ,\"",
";",
"}",
"$",
"query",
".=",
"\") ENGINE=InnoDB DEFAULT CHARSET=latin1;\"",
";",
"return",
"$",
"query",
";",
"}"
] | Creates a create table sql statement
@param $tableName
@param $fields
@return string executable sql statement | [
"Creates",
"a",
"create",
"table",
"sql",
"statement"
] | e5df527ac0ea5fa434cbda79692f37cf6f2abc73 | https://github.com/angrycoders/db-driver/blob/e5df527ac0ea5fa434cbda79692f37cf6f2abc73/src/Database/SQL/SQLEncoder.php#L25-L46 | train |
angrycoders/db-driver | src/Database/SQL/SQLEncoder.php | SQLEncoder.encodeInsertRecord | public static function encodeInsertRecord($tableName, $newRecord)
{
$query = "INSERT INTO $tableName VALUES (";
$size = sizeof($newRecord);
foreach ($newRecord as $index => $record) {
$query .= " '$record'";
if ($index != ($size - 1))
$query .= " ,";
}
$query .= " );";
return $query;
} | php | public static function encodeInsertRecord($tableName, $newRecord)
{
$query = "INSERT INTO $tableName VALUES (";
$size = sizeof($newRecord);
foreach ($newRecord as $index => $record) {
$query .= " '$record'";
if ($index != ($size - 1))
$query .= " ,";
}
$query .= " );";
return $query;
} | [
"public",
"static",
"function",
"encodeInsertRecord",
"(",
"$",
"tableName",
",",
"$",
"newRecord",
")",
"{",
"$",
"query",
"=",
"\"INSERT INTO $tableName VALUES (\"",
";",
"$",
"size",
"=",
"sizeof",
"(",
"$",
"newRecord",
")",
";",
"foreach",
"(",
"$",
"newRecord",
"as",
"$",
"index",
"=>",
"$",
"record",
")",
"{",
"$",
"query",
".=",
"\" '$record'\"",
";",
"if",
"(",
"$",
"index",
"!=",
"(",
"$",
"size",
"-",
"1",
")",
")",
"$",
"query",
".=",
"\" ,\"",
";",
"}",
"$",
"query",
".=",
"\" );\"",
";",
"return",
"$",
"query",
";",
"}"
] | Creates a insert record SQL statement
@param $tableName
@param $newRecord
@return string executable sql statement | [
"Creates",
"a",
"insert",
"record",
"SQL",
"statement"
] | e5df527ac0ea5fa434cbda79692f37cf6f2abc73 | https://github.com/angrycoders/db-driver/blob/e5df527ac0ea5fa434cbda79692f37cf6f2abc73/src/Database/SQL/SQLEncoder.php#L55-L66 | train |
angrycoders/db-driver | src/Database/SQL/SQLEncoder.php | SQLEncoder.encodeGetRecord | public static function encodeGetRecord($tableName, $field, $value, $fields = array())
{
$select = "";
$size = sizeof($fields);
//Select fields to be returned
if (sizeof($fields) > 0) {
foreach ($fields as $i => $column) {
$select .= " $column";
if ($i != ($size - 1))
$select .= ",";
}
} else {
$select = "*";
}
$query = "SELECT $select FROM $tableName WHERE $field = '$value';";
return $query;
} | php | public static function encodeGetRecord($tableName, $field, $value, $fields = array())
{
$select = "";
$size = sizeof($fields);
//Select fields to be returned
if (sizeof($fields) > 0) {
foreach ($fields as $i => $column) {
$select .= " $column";
if ($i != ($size - 1))
$select .= ",";
}
} else {
$select = "*";
}
$query = "SELECT $select FROM $tableName WHERE $field = '$value';";
return $query;
} | [
"public",
"static",
"function",
"encodeGetRecord",
"(",
"$",
"tableName",
",",
"$",
"field",
",",
"$",
"value",
",",
"$",
"fields",
"=",
"array",
"(",
")",
")",
"{",
"$",
"select",
"=",
"\"\"",
";",
"$",
"size",
"=",
"sizeof",
"(",
"$",
"fields",
")",
";",
"//Select fields to be returned",
"if",
"(",
"sizeof",
"(",
"$",
"fields",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"i",
"=>",
"$",
"column",
")",
"{",
"$",
"select",
".=",
"\" $column\"",
";",
"if",
"(",
"$",
"i",
"!=",
"(",
"$",
"size",
"-",
"1",
")",
")",
"$",
"select",
".=",
"\",\"",
";",
"}",
"}",
"else",
"{",
"$",
"select",
"=",
"\"*\"",
";",
"}",
"$",
"query",
"=",
"\"SELECT $select FROM $tableName WHERE $field = '$value';\"",
";",
"return",
"$",
"query",
";",
"}"
] | Encodes get record statement
@param string $tableName
@param string $field field to match
@param string $value value to match with field
@param array $fields columns to be returned
@return string executable SQL statement | [
"Encodes",
"get",
"record",
"statement"
] | e5df527ac0ea5fa434cbda79692f37cf6f2abc73 | https://github.com/angrycoders/db-driver/blob/e5df527ac0ea5fa434cbda79692f37cf6f2abc73/src/Database/SQL/SQLEncoder.php#L89-L106 | train |
angrycoders/db-driver | src/Database/SQL/SQLEncoder.php | SQLEncoder.encodeUpdateRecord | public static function encodeUpdateRecord($tableName, $fields, $values, $field, $value)
{
$query = "UPDATE $tableName SET";
$size = sizeof($fields);
foreach ($fields as $i => $column) {
$query .= " $column = '$values[$i]'";
if ($i != ($size - 1))
$query .= ",";
}
$query .= " WHERE $field = '$value';";
return $query;
} | php | public static function encodeUpdateRecord($tableName, $fields, $values, $field, $value)
{
$query = "UPDATE $tableName SET";
$size = sizeof($fields);
foreach ($fields as $i => $column) {
$query .= " $column = '$values[$i]'";
if ($i != ($size - 1))
$query .= ",";
}
$query .= " WHERE $field = '$value';";
return $query;
} | [
"public",
"static",
"function",
"encodeUpdateRecord",
"(",
"$",
"tableName",
",",
"$",
"fields",
",",
"$",
"values",
",",
"$",
"field",
",",
"$",
"value",
")",
"{",
"$",
"query",
"=",
"\"UPDATE $tableName SET\"",
";",
"$",
"size",
"=",
"sizeof",
"(",
"$",
"fields",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"i",
"=>",
"$",
"column",
")",
"{",
"$",
"query",
".=",
"\" $column = '$values[$i]'\"",
";",
"if",
"(",
"$",
"i",
"!=",
"(",
"$",
"size",
"-",
"1",
")",
")",
"$",
"query",
".=",
"\",\"",
";",
"}",
"$",
"query",
".=",
"\" WHERE $field = '$value';\"",
";",
"return",
"$",
"query",
";",
"}"
] | Encodes the params to an SQL statement
@param string $tableName the name of table in db
@param array $fields the fields to be updated
@param array $values the values to update the fields
@param string $field the field to check
@param string $value the value of the field to check
@return string executable SQL statement | [
"Encodes",
"the",
"params",
"to",
"an",
"SQL",
"statement"
] | e5df527ac0ea5fa434cbda79692f37cf6f2abc73 | https://github.com/angrycoders/db-driver/blob/e5df527ac0ea5fa434cbda79692f37cf6f2abc73/src/Database/SQL/SQLEncoder.php#L117-L128 | train |
angrycoders/db-driver | src/Database/SQL/SQLEncoder.php | SQLEncoder.encodeGetAllRecords | public static function encodeGetAllRecords($tableName, $fields = array(), $limit = 0, $start = 0)
{
if ($fields == null)
$fields = array();
$select = "";
$size = sizeof($fields);
//Select fields to be returned
if (sizeof($fields) > 0) {
foreach ($fields as $i => $column) {
$select .= " $column";
if ($i != ($size - 1))
$select .= ",";
}
} else {
$select = "*";
}
$query = "SELECT $select FROM $tableName";
if ($limit > 0) {
if ($start > 0) {
$query .= " LIMIT $start, $limit";
} else {
$query .= " LIMIT $limit";
}
}
$query .= ";";
return $query;
} | php | public static function encodeGetAllRecords($tableName, $fields = array(), $limit = 0, $start = 0)
{
if ($fields == null)
$fields = array();
$select = "";
$size = sizeof($fields);
//Select fields to be returned
if (sizeof($fields) > 0) {
foreach ($fields as $i => $column) {
$select .= " $column";
if ($i != ($size - 1))
$select .= ",";
}
} else {
$select = "*";
}
$query = "SELECT $select FROM $tableName";
if ($limit > 0) {
if ($start > 0) {
$query .= " LIMIT $start, $limit";
} else {
$query .= " LIMIT $limit";
}
}
$query .= ";";
return $query;
} | [
"public",
"static",
"function",
"encodeGetAllRecords",
"(",
"$",
"tableName",
",",
"$",
"fields",
"=",
"array",
"(",
")",
",",
"$",
"limit",
"=",
"0",
",",
"$",
"start",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"fields",
"==",
"null",
")",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"$",
"select",
"=",
"\"\"",
";",
"$",
"size",
"=",
"sizeof",
"(",
"$",
"fields",
")",
";",
"//Select fields to be returned",
"if",
"(",
"sizeof",
"(",
"$",
"fields",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"i",
"=>",
"$",
"column",
")",
"{",
"$",
"select",
".=",
"\" $column\"",
";",
"if",
"(",
"$",
"i",
"!=",
"(",
"$",
"size",
"-",
"1",
")",
")",
"$",
"select",
".=",
"\",\"",
";",
"}",
"}",
"else",
"{",
"$",
"select",
"=",
"\"*\"",
";",
"}",
"$",
"query",
"=",
"\"SELECT $select FROM $tableName\"",
";",
"if",
"(",
"$",
"limit",
">",
"0",
")",
"{",
"if",
"(",
"$",
"start",
">",
"0",
")",
"{",
"$",
"query",
".=",
"\" LIMIT $start, $limit\"",
";",
"}",
"else",
"{",
"$",
"query",
".=",
"\" LIMIT $limit\"",
";",
"}",
"}",
"$",
"query",
".=",
"\";\"",
";",
"return",
"$",
"query",
";",
"}"
] | Encode Get all record to SQL statement
@param $tableName the name of table in db
@param array $fields the field to be returned. Returns all fields if not specified
@param int $limit the number of records to return. Returns all record if not returned
@param int $start the record index to start record. Starts from the first record if not specified
@return string encoded SQL string | [
"Encode",
"Get",
"all",
"record",
"to",
"SQL",
"statement"
] | e5df527ac0ea5fa434cbda79692f37cf6f2abc73 | https://github.com/angrycoders/db-driver/blob/e5df527ac0ea5fa434cbda79692f37cf6f2abc73/src/Database/SQL/SQLEncoder.php#L138-L169 | train |
PaulDevelop/library-common | src/class/GenericCollection.php | GenericCollection.add | public
function add(
$value = null,
$key = ''
) {
//var_dump($this->type);
//var_dump($value);
//var_dump(is_object($value));
//die;
if ($this->isClass) {
//echo " isClass".PHP_EOL;
if (!is_a($value, $this->type)) {
//throw new TypeCheckException('Object type "'.get_class($value).'" is not of type "'.$this->type.'".');
$type = is_object($value) ? get_class($value) : gettype($value);
throw new TypeCheckException('Object type "'.$type.'" is not of type "'.$this->type.'".');
} else {
// add to collection
if ($key != '') {
if (array_key_exists($key, $this->collection)) {
throw new ArgumentException(
'Can not add object to key "'.$key.'", because key already exists.'
);
} else {
$this->collection[$key] = $value;
}
} else {
array_push($this->collection, $value);
}
}
} else {
//echo " noClass".PHP_EOL;
if ($this->type == gettype($value)) {
// add to collection
if ($key != '') {
if (array_key_exists($key, $this->collection)) {
throw new ArgumentException('Can not add value to key "'.$key.'", because key already exists.');
} else {
$this->collection[$key] = $value;
}
} else {
array_push($this->collection, $value);
}
} else {
throw new TypeCheckException('Value type "'.gettype($value).'" is not of type "'.$this->type.'".');
}
}
} | php | public
function add(
$value = null,
$key = ''
) {
//var_dump($this->type);
//var_dump($value);
//var_dump(is_object($value));
//die;
if ($this->isClass) {
//echo " isClass".PHP_EOL;
if (!is_a($value, $this->type)) {
//throw new TypeCheckException('Object type "'.get_class($value).'" is not of type "'.$this->type.'".');
$type = is_object($value) ? get_class($value) : gettype($value);
throw new TypeCheckException('Object type "'.$type.'" is not of type "'.$this->type.'".');
} else {
// add to collection
if ($key != '') {
if (array_key_exists($key, $this->collection)) {
throw new ArgumentException(
'Can not add object to key "'.$key.'", because key already exists.'
);
} else {
$this->collection[$key] = $value;
}
} else {
array_push($this->collection, $value);
}
}
} else {
//echo " noClass".PHP_EOL;
if ($this->type == gettype($value)) {
// add to collection
if ($key != '') {
if (array_key_exists($key, $this->collection)) {
throw new ArgumentException('Can not add value to key "'.$key.'", because key already exists.');
} else {
$this->collection[$key] = $value;
}
} else {
array_push($this->collection, $value);
}
} else {
throw new TypeCheckException('Value type "'.gettype($value).'" is not of type "'.$this->type.'".');
}
}
} | [
"public",
"function",
"add",
"(",
"$",
"value",
"=",
"null",
",",
"$",
"key",
"=",
"''",
")",
"{",
"//var_dump($this->type);",
"//var_dump($value);",
"//var_dump(is_object($value));",
"//die;",
"if",
"(",
"$",
"this",
"->",
"isClass",
")",
"{",
"//echo \" isClass\".PHP_EOL;",
"if",
"(",
"!",
"is_a",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"type",
")",
")",
"{",
"//throw new TypeCheckException('Object type \"'.get_class($value).'\" is not of type \"'.$this->type.'\".');",
"$",
"type",
"=",
"is_object",
"(",
"$",
"value",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
":",
"gettype",
"(",
"$",
"value",
")",
";",
"throw",
"new",
"TypeCheckException",
"(",
"'Object type \"'",
".",
"$",
"type",
".",
"'\" is not of type \"'",
".",
"$",
"this",
"->",
"type",
".",
"'\".'",
")",
";",
"}",
"else",
"{",
"// add to collection",
"if",
"(",
"$",
"key",
"!=",
"''",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"collection",
")",
")",
"{",
"throw",
"new",
"ArgumentException",
"(",
"'Can not add object to key \"'",
".",
"$",
"key",
".",
"'\", because key already exists.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"collection",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"collection",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"else",
"{",
"//echo \" noClass\".PHP_EOL;",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"// add to collection",
"if",
"(",
"$",
"key",
"!=",
"''",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"collection",
")",
")",
"{",
"throw",
"new",
"ArgumentException",
"(",
"'Can not add value to key \"'",
".",
"$",
"key",
".",
"'\", because key already exists.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"collection",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"collection",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"TypeCheckException",
"(",
"'Value type \"'",
".",
"gettype",
"(",
"$",
"value",
")",
".",
"'\" is not of type \"'",
".",
"$",
"this",
"->",
"type",
".",
"'\".'",
")",
";",
"}",
"}",
"}"
] | Add value to collection.
@param mixed $value
@param string $key
@throws TypeCheckException
@throws ArgumentException | [
"Add",
"value",
"to",
"collection",
"."
] | 12ebf86e1b660fa55724d2a168a61fc6c3a77f8b | https://github.com/PaulDevelop/library-common/blob/12ebf86e1b660fa55724d2a168a61fc6c3a77f8b/src/class/GenericCollection.php#L116-L162 | train |
spacek/contrastcms-application | src/model/TreeProvider.php | TreeProvider.hasChildren | public static function hasChildren($postRepository, $language, $postId)
{
$menuCount = $postRepository->countBy(array(
'lang' => $language,
'parent' => $postId
));
if ($menuCount > 0) {
return true;
}
return false;
} | php | public static function hasChildren($postRepository, $language, $postId)
{
$menuCount = $postRepository->countBy(array(
'lang' => $language,
'parent' => $postId
));
if ($menuCount > 0) {
return true;
}
return false;
} | [
"public",
"static",
"function",
"hasChildren",
"(",
"$",
"postRepository",
",",
"$",
"language",
",",
"$",
"postId",
")",
"{",
"$",
"menuCount",
"=",
"$",
"postRepository",
"->",
"countBy",
"(",
"array",
"(",
"'lang'",
"=>",
"$",
"language",
",",
"'parent'",
"=>",
"$",
"postId",
")",
")",
";",
"if",
"(",
"$",
"menuCount",
">",
"0",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Returns bool value whether item is containing children.
@param $postRepository
@param $language
@param $postId
@return bool | [
"Returns",
"bool",
"value",
"whether",
"item",
"is",
"containing",
"children",
"."
] | 054844cd531f98a3694b4dba554c935d3ca412b9 | https://github.com/spacek/contrastcms-application/blob/054844cd531f98a3694b4dba554c935d3ca412b9/src/model/TreeProvider.php#L81-L93 | train |
spacek/contrastcms-application | src/model/TreeProvider.php | TreeProvider.getChildren | public static function getChildren($postRepository, $language, $postId, $activeId = 0, $getUnpublished = true)
{
$menuObject = array();
$requirements = array(
'lang' => $language,
'parent' => $postId,
);
if (!$getUnpublished) {
$requirements['is_public'] = 1;
}
$subItems = $postRepository->findBy($requirements, 'priority DESC, version DESC');
foreach ($subItems as $item) {
$menuItem = new TreeItem($item->id, $item->id, $item->title, $item->is_public, $item->lang, $item->is_unfolded);
if ((int)$item->id == (int)$activeId) {
$menuItem->setActive(true);
} else {
$menuItem->setActive(false);
}
if (self::hasChildren($postRepository, $language, $item->id)) {
$children = (array)self::getChildren($postRepository, $language, $item->id, $activeId, $getUnpublished);
$menuItem->addChildren($children);
}
$menuObject[] = $menuItem;
}
return $menuObject;
} | php | public static function getChildren($postRepository, $language, $postId, $activeId = 0, $getUnpublished = true)
{
$menuObject = array();
$requirements = array(
'lang' => $language,
'parent' => $postId,
);
if (!$getUnpublished) {
$requirements['is_public'] = 1;
}
$subItems = $postRepository->findBy($requirements, 'priority DESC, version DESC');
foreach ($subItems as $item) {
$menuItem = new TreeItem($item->id, $item->id, $item->title, $item->is_public, $item->lang, $item->is_unfolded);
if ((int)$item->id == (int)$activeId) {
$menuItem->setActive(true);
} else {
$menuItem->setActive(false);
}
if (self::hasChildren($postRepository, $language, $item->id)) {
$children = (array)self::getChildren($postRepository, $language, $item->id, $activeId, $getUnpublished);
$menuItem->addChildren($children);
}
$menuObject[] = $menuItem;
}
return $menuObject;
} | [
"public",
"static",
"function",
"getChildren",
"(",
"$",
"postRepository",
",",
"$",
"language",
",",
"$",
"postId",
",",
"$",
"activeId",
"=",
"0",
",",
"$",
"getUnpublished",
"=",
"true",
")",
"{",
"$",
"menuObject",
"=",
"array",
"(",
")",
";",
"$",
"requirements",
"=",
"array",
"(",
"'lang'",
"=>",
"$",
"language",
",",
"'parent'",
"=>",
"$",
"postId",
",",
")",
";",
"if",
"(",
"!",
"$",
"getUnpublished",
")",
"{",
"$",
"requirements",
"[",
"'is_public'",
"]",
"=",
"1",
";",
"}",
"$",
"subItems",
"=",
"$",
"postRepository",
"->",
"findBy",
"(",
"$",
"requirements",
",",
"'priority DESC, version DESC'",
")",
";",
"foreach",
"(",
"$",
"subItems",
"as",
"$",
"item",
")",
"{",
"$",
"menuItem",
"=",
"new",
"TreeItem",
"(",
"$",
"item",
"->",
"id",
",",
"$",
"item",
"->",
"id",
",",
"$",
"item",
"->",
"title",
",",
"$",
"item",
"->",
"is_public",
",",
"$",
"item",
"->",
"lang",
",",
"$",
"item",
"->",
"is_unfolded",
")",
";",
"if",
"(",
"(",
"int",
")",
"$",
"item",
"->",
"id",
"==",
"(",
"int",
")",
"$",
"activeId",
")",
"{",
"$",
"menuItem",
"->",
"setActive",
"(",
"true",
")",
";",
"}",
"else",
"{",
"$",
"menuItem",
"->",
"setActive",
"(",
"false",
")",
";",
"}",
"if",
"(",
"self",
"::",
"hasChildren",
"(",
"$",
"postRepository",
",",
"$",
"language",
",",
"$",
"item",
"->",
"id",
")",
")",
"{",
"$",
"children",
"=",
"(",
"array",
")",
"self",
"::",
"getChildren",
"(",
"$",
"postRepository",
",",
"$",
"language",
",",
"$",
"item",
"->",
"id",
",",
"$",
"activeId",
",",
"$",
"getUnpublished",
")",
";",
"$",
"menuItem",
"->",
"addChildren",
"(",
"$",
"children",
")",
";",
"}",
"$",
"menuObject",
"[",
"]",
"=",
"$",
"menuItem",
";",
"}",
"return",
"$",
"menuObject",
";",
"}"
] | Returns array filled with MenuItem objects
@param $postRepository
@param $language
@param $postId
@return bool | [
"Returns",
"array",
"filled",
"with",
"MenuItem",
"objects"
] | 054844cd531f98a3694b4dba554c935d3ca412b9 | https://github.com/spacek/contrastcms-application/blob/054844cd531f98a3694b4dba554c935d3ca412b9/src/model/TreeProvider.php#L102-L137 | train |
foxslider/cmg-plugin | common/models/resources/Slide.php | Slide.findByNameSliderId | public static function findByNameSliderId( $name, $sliderId ) {
return Slide::find()->where( 'sliderId=:id', [ ':id' => $sliderId ] )->andwhere( 'name=:name', [ ':name' => $name ] )->one();
} | php | public static function findByNameSliderId( $name, $sliderId ) {
return Slide::find()->where( 'sliderId=:id', [ ':id' => $sliderId ] )->andwhere( 'name=:name', [ ':name' => $name ] )->one();
} | [
"public",
"static",
"function",
"findByNameSliderId",
"(",
"$",
"name",
",",
"$",
"sliderId",
")",
"{",
"return",
"Slide",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"'sliderId=:id'",
",",
"[",
"':id'",
"=>",
"$",
"sliderId",
"]",
")",
"->",
"andwhere",
"(",
"'name=:name'",
",",
"[",
"':name'",
"=>",
"$",
"name",
"]",
")",
"->",
"one",
"(",
")",
";",
"}"
] | Find and return the slide associated with given name and slider id.
@param string $name
@param integer $sliderId
@return Slide[] | [
"Find",
"and",
"return",
"the",
"slide",
"associated",
"with",
"given",
"name",
"and",
"slider",
"id",
"."
] | 843f723ebb512ab833feff581beb9714df4e41bd | https://github.com/foxslider/cmg-plugin/blob/843f723ebb512ab833feff581beb9714df4e41bd/common/models/resources/Slide.php#L209-L212 | train |
foxslider/cmg-plugin | common/models/resources/Slide.php | Slide.isExistByNameSliderId | public static function isExistByNameSliderId( $name, $sliderId ) {
$slide = self::findByNameSliderId( $name, $sliderId );
return isset( $slide );
} | php | public static function isExistByNameSliderId( $name, $sliderId ) {
$slide = self::findByNameSliderId( $name, $sliderId );
return isset( $slide );
} | [
"public",
"static",
"function",
"isExistByNameSliderId",
"(",
"$",
"name",
",",
"$",
"sliderId",
")",
"{",
"$",
"slide",
"=",
"self",
"::",
"findByNameSliderId",
"(",
"$",
"name",
",",
"$",
"sliderId",
")",
";",
"return",
"isset",
"(",
"$",
"slide",
")",
";",
"}"
] | Check whether slide exist by name and slider id.
@param string $name
@param integer $sliderId
@return boolean | [
"Check",
"whether",
"slide",
"exist",
"by",
"name",
"and",
"slider",
"id",
"."
] | 843f723ebb512ab833feff581beb9714df4e41bd | https://github.com/foxslider/cmg-plugin/blob/843f723ebb512ab833feff581beb9714df4e41bd/common/models/resources/Slide.php#L221-L226 | train |
MayMeow/may-encrypt | src/Factory/SecurityFactory.php | SecurityFactory.setKeyPair | public function setKeyPair(KeyPairLoaderInterface $keyPairLoader)
{
$this->privateKey = $keyPairLoader->getPrivateKey();
$this->publicKey = $keyPairLoader->getPublicKey();
} | php | public function setKeyPair(KeyPairLoaderInterface $keyPairLoader)
{
$this->privateKey = $keyPairLoader->getPrivateKey();
$this->publicKey = $keyPairLoader->getPublicKey();
} | [
"public",
"function",
"setKeyPair",
"(",
"KeyPairLoaderInterface",
"$",
"keyPairLoader",
")",
"{",
"$",
"this",
"->",
"privateKey",
"=",
"$",
"keyPairLoader",
"->",
"getPrivateKey",
"(",
")",
";",
"$",
"this",
"->",
"publicKey",
"=",
"$",
"keyPairLoader",
"->",
"getPublicKey",
"(",
")",
";",
"}"
] | Set key pair
@param KeyPairLoaderInterface $keyPairLoader | [
"Set",
"key",
"pair"
] | d67122e240037e6cc31e1c0742911e87cda93a86 | https://github.com/MayMeow/may-encrypt/blob/d67122e240037e6cc31e1c0742911e87cda93a86/src/Factory/SecurityFactory.php#L108-L112 | train |
Wedeto/Auth | src/ACL/Hierarchy.php | Hierarchy.is | public function is(Hierarchy $element)
{
if (get_class($this) !== get_class($element))
return false;
return $this->id === $element->id;
} | php | public function is(Hierarchy $element)
{
if (get_class($this) !== get_class($element))
return false;
return $this->id === $element->id;
} | [
"public",
"function",
"is",
"(",
"Hierarchy",
"$",
"element",
")",
"{",
"if",
"(",
"get_class",
"(",
"$",
"this",
")",
"!==",
"get_class",
"(",
"$",
"element",
")",
")",
"return",
"false",
";",
"return",
"$",
"this",
"->",
"id",
"===",
"$",
"element",
"->",
"id",
";",
"}"
] | Check if the objects are referring to the same element.
@return boolean True if both elements are the same class and ID, false otherwise | [
"Check",
"if",
"the",
"objects",
"are",
"referring",
"to",
"the",
"same",
"element",
"."
] | d53777d860a9e67154b84b425e29da5d4dcd28e0 | https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/Hierarchy.php#L91-L96 | train |
Wedeto/Auth | src/ACL/Hierarchy.php | Hierarchy.isAncestorOf | public function isAncestorOf(Hierarchy $element, LoaderInterface $loader = null)
{
return $loader !== null ? $element->isOffspringOf($this, $loader) : $element->isOffspringOf($this);
} | php | public function isAncestorOf(Hierarchy $element, LoaderInterface $loader = null)
{
return $loader !== null ? $element->isOffspringOf($this, $loader) : $element->isOffspringOf($this);
} | [
"public",
"function",
"isAncestorOf",
"(",
"Hierarchy",
"$",
"element",
",",
"LoaderInterface",
"$",
"loader",
"=",
"null",
")",
"{",
"return",
"$",
"loader",
"!==",
"null",
"?",
"$",
"element",
"->",
"isOffspringOf",
"(",
"$",
"this",
",",
"$",
"loader",
")",
":",
"$",
"element",
"->",
"isOffspringOf",
"(",
"$",
"this",
")",
";",
"}"
] | Check if the current element is an ancestor of the specified element
@param $element Hierarchy The element to check
@param $loader LoaderInterface A loader instance that can be used to load additional instances
@return boolean True when the current Entity is an ancestor of $element, false otherwise | [
"Check",
"if",
"the",
"current",
"element",
"is",
"an",
"ancestor",
"of",
"the",
"specified",
"element"
] | d53777d860a9e67154b84b425e29da5d4dcd28e0 | https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/Hierarchy.php#L105-L108 | train |
Wedeto/Auth | src/ACL/Hierarchy.php | Hierarchy.isOffspringOf | public function isOffspringOf(Hierarchy $element, LoaderInterface $loader = null)
{
if (get_class($element) !== get_class($this))
return 0;
$stack = [];
$parents = $this->getParents($loader);
foreach ($parents as $p)
$stack[] = [1, $p];
$seen = [];
$level = 0;
while (!empty($stack))
{
list($level, $cur) = array_shift($stack);
// Avoid infinite cycles
if (isset($seen[$cur->id]))
continue;
// If the ancestor is the requested element, we found our answer
if ($cur->id === $element->id)
return $level;
// Add all parents of this element to the stack
$parents = $loader === null ? $cur->getParents() : $cur->getParents($loader);
foreach ($cur->getParents($loader) as $p)
$stack[] = [$level + 1, $p];
// Store seen entities to avoid cycles
$seen[$cur->id] = true;
}
// Nothing found
return 0;
} | php | public function isOffspringOf(Hierarchy $element, LoaderInterface $loader = null)
{
if (get_class($element) !== get_class($this))
return 0;
$stack = [];
$parents = $this->getParents($loader);
foreach ($parents as $p)
$stack[] = [1, $p];
$seen = [];
$level = 0;
while (!empty($stack))
{
list($level, $cur) = array_shift($stack);
// Avoid infinite cycles
if (isset($seen[$cur->id]))
continue;
// If the ancestor is the requested element, we found our answer
if ($cur->id === $element->id)
return $level;
// Add all parents of this element to the stack
$parents = $loader === null ? $cur->getParents() : $cur->getParents($loader);
foreach ($cur->getParents($loader) as $p)
$stack[] = [$level + 1, $p];
// Store seen entities to avoid cycles
$seen[$cur->id] = true;
}
// Nothing found
return 0;
} | [
"public",
"function",
"isOffspringOf",
"(",
"Hierarchy",
"$",
"element",
",",
"LoaderInterface",
"$",
"loader",
"=",
"null",
")",
"{",
"if",
"(",
"get_class",
"(",
"$",
"element",
")",
"!==",
"get_class",
"(",
"$",
"this",
")",
")",
"return",
"0",
";",
"$",
"stack",
"=",
"[",
"]",
";",
"$",
"parents",
"=",
"$",
"this",
"->",
"getParents",
"(",
"$",
"loader",
")",
";",
"foreach",
"(",
"$",
"parents",
"as",
"$",
"p",
")",
"$",
"stack",
"[",
"]",
"=",
"[",
"1",
",",
"$",
"p",
"]",
";",
"$",
"seen",
"=",
"[",
"]",
";",
"$",
"level",
"=",
"0",
";",
"while",
"(",
"!",
"empty",
"(",
"$",
"stack",
")",
")",
"{",
"list",
"(",
"$",
"level",
",",
"$",
"cur",
")",
"=",
"array_shift",
"(",
"$",
"stack",
")",
";",
"// Avoid infinite cycles",
"if",
"(",
"isset",
"(",
"$",
"seen",
"[",
"$",
"cur",
"->",
"id",
"]",
")",
")",
"continue",
";",
"// If the ancestor is the requested element, we found our answer",
"if",
"(",
"$",
"cur",
"->",
"id",
"===",
"$",
"element",
"->",
"id",
")",
"return",
"$",
"level",
";",
"// Add all parents of this element to the stack",
"$",
"parents",
"=",
"$",
"loader",
"===",
"null",
"?",
"$",
"cur",
"->",
"getParents",
"(",
")",
":",
"$",
"cur",
"->",
"getParents",
"(",
"$",
"loader",
")",
";",
"foreach",
"(",
"$",
"cur",
"->",
"getParents",
"(",
"$",
"loader",
")",
"as",
"$",
"p",
")",
"$",
"stack",
"[",
"]",
"=",
"[",
"$",
"level",
"+",
"1",
",",
"$",
"p",
"]",
";",
"// Store seen entities to avoid cycles",
"$",
"seen",
"[",
"$",
"cur",
"->",
"id",
"]",
"=",
"true",
";",
"}",
"// Nothing found",
"return",
"0",
";",
"}"
] | Check if the current element is offspring of the specified element
@param $role Hierarchy The element to check
@param $loader LoaderInterface A loader that can be used to load additional instances
@return integer The number of generation levels between the $this and $element - 0 if they're not related | [
"Check",
"if",
"the",
"current",
"element",
"is",
"offspring",
"of",
"the",
"specified",
"element"
] | d53777d860a9e67154b84b425e29da5d4dcd28e0 | https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/Hierarchy.php#L117-L152 | train |
Wedeto/Auth | src/ACL/Hierarchy.php | Hierarchy.getParents | public function getParents(LoaderInterface $loader = null)
{
if (empty($this->parents) && $this->id !== static::$root)
$this->parents = [$this->getRoot()];
$acl = $this->getACL();
if (null === $acl)
throw new \RuntimeException("ACL is null on " . get_class($this));
$parents = [];
$ids = array_keys($this->parents);
foreach ($ids as $id)
{
if ($this->parents[$id] === null)
{
if (!$acl->hasInstance(static::class, $id) && $loader !== null)
{
$parent = $loader->load($id, static::class);
$acl->setInstance($parent);
$this->parents[$id] = $parent;
}
else
{
$this->parents[$id] = $acl->getInstance(static::class, $id);
}
}
$parents[] = $this->parents[$id];
}
return $parents;
} | php | public function getParents(LoaderInterface $loader = null)
{
if (empty($this->parents) && $this->id !== static::$root)
$this->parents = [$this->getRoot()];
$acl = $this->getACL();
if (null === $acl)
throw new \RuntimeException("ACL is null on " . get_class($this));
$parents = [];
$ids = array_keys($this->parents);
foreach ($ids as $id)
{
if ($this->parents[$id] === null)
{
if (!$acl->hasInstance(static::class, $id) && $loader !== null)
{
$parent = $loader->load($id, static::class);
$acl->setInstance($parent);
$this->parents[$id] = $parent;
}
else
{
$this->parents[$id] = $acl->getInstance(static::class, $id);
}
}
$parents[] = $this->parents[$id];
}
return $parents;
} | [
"public",
"function",
"getParents",
"(",
"LoaderInterface",
"$",
"loader",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"parents",
")",
"&&",
"$",
"this",
"->",
"id",
"!==",
"static",
"::",
"$",
"root",
")",
"$",
"this",
"->",
"parents",
"=",
"[",
"$",
"this",
"->",
"getRoot",
"(",
")",
"]",
";",
"$",
"acl",
"=",
"$",
"this",
"->",
"getACL",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"acl",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"ACL is null on \"",
".",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"parents",
"=",
"[",
"]",
";",
"$",
"ids",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"parents",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parents",
"[",
"$",
"id",
"]",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"acl",
"->",
"hasInstance",
"(",
"static",
"::",
"class",
",",
"$",
"id",
")",
"&&",
"$",
"loader",
"!==",
"null",
")",
"{",
"$",
"parent",
"=",
"$",
"loader",
"->",
"load",
"(",
"$",
"id",
",",
"static",
"::",
"class",
")",
";",
"$",
"acl",
"->",
"setInstance",
"(",
"$",
"parent",
")",
";",
"$",
"this",
"->",
"parents",
"[",
"$",
"id",
"]",
"=",
"$",
"parent",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"parents",
"[",
"$",
"id",
"]",
"=",
"$",
"acl",
"->",
"getInstance",
"(",
"static",
"::",
"class",
",",
"$",
"id",
")",
";",
"}",
"}",
"$",
"parents",
"[",
"]",
"=",
"$",
"this",
"->",
"parents",
"[",
"$",
"id",
"]",
";",
"}",
"return",
"$",
"parents",
";",
"}"
] | Return a list of all parent elements of this element
@param $loader LoaderInterface A loader that can be used to load additional instances
@return array An array of all parent elements | [
"Return",
"a",
"list",
"of",
"all",
"parent",
"elements",
"of",
"this",
"element"
] | d53777d860a9e67154b84b425e29da5d4dcd28e0 | https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/Hierarchy.php#L160-L188 | train |
Wedeto/Auth | src/ACL/Hierarchy.php | Hierarchy.setParents | public function setParents(array $parents)
{
$ownclass = get_class($this);
$is_root = ($this->id === static::$root);
$this->parents = array();
foreach ($parents as $parent)
{
if (is_object($parent) && get_class($parent) == $ownclass)
$this->parents[$parent->id] = $parent;
elseif (is_scalar($parent))
$this->parents[$parent] = null;
else
throw new Exception("Parent-ID must be a " . $ownclass . " object or a scalar");
}
if (empty($this->parents) && !$is_root)
$this->parents = [$this->getRoot()];
return $this;
} | php | public function setParents(array $parents)
{
$ownclass = get_class($this);
$is_root = ($this->id === static::$root);
$this->parents = array();
foreach ($parents as $parent)
{
if (is_object($parent) && get_class($parent) == $ownclass)
$this->parents[$parent->id] = $parent;
elseif (is_scalar($parent))
$this->parents[$parent] = null;
else
throw new Exception("Parent-ID must be a " . $ownclass . " object or a scalar");
}
if (empty($this->parents) && !$is_root)
$this->parents = [$this->getRoot()];
return $this;
} | [
"public",
"function",
"setParents",
"(",
"array",
"$",
"parents",
")",
"{",
"$",
"ownclass",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"is_root",
"=",
"(",
"$",
"this",
"->",
"id",
"===",
"static",
"::",
"$",
"root",
")",
";",
"$",
"this",
"->",
"parents",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parents",
"as",
"$",
"parent",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"parent",
")",
"&&",
"get_class",
"(",
"$",
"parent",
")",
"==",
"$",
"ownclass",
")",
"$",
"this",
"->",
"parents",
"[",
"$",
"parent",
"->",
"id",
"]",
"=",
"$",
"parent",
";",
"elseif",
"(",
"is_scalar",
"(",
"$",
"parent",
")",
")",
"$",
"this",
"->",
"parents",
"[",
"$",
"parent",
"]",
"=",
"null",
";",
"else",
"throw",
"new",
"Exception",
"(",
"\"Parent-ID must be a \"",
".",
"$",
"ownclass",
".",
"\" object or a scalar\"",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"parents",
")",
"&&",
"!",
"$",
"is_root",
")",
"$",
"this",
"->",
"parents",
"=",
"[",
"$",
"this",
"->",
"getRoot",
"(",
")",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Set the parent or parents of this element
@param $parents array One or more parent elements. The values can be instances of the same
class or scalars referring to these instances.
@Return $this Provides fluent interface
@throws Wedeto\ACL\Exception When invalid types of parents are specified | [
"Set",
"the",
"parent",
"or",
"parents",
"of",
"this",
"element"
] | d53777d860a9e67154b84b425e29da5d4dcd28e0 | https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/Hierarchy.php#L198-L218 | train |
nails/driver-cdn-awslocal | src/Aws.php | Aws.sdk | protected function sdk()
{
if (empty($this->oSdk)) {
$this->oSdk = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => $this->getRegion(),
'credentials' => new \Aws\Credentials\Credentials(
$this->getSetting('access_key'),
$this->getSetting('access_secret')
),
]);
}
return $this->oSdk;
} | php | protected function sdk()
{
if (empty($this->oSdk)) {
$this->oSdk = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => $this->getRegion(),
'credentials' => new \Aws\Credentials\Credentials(
$this->getSetting('access_key'),
$this->getSetting('access_secret')
),
]);
}
return $this->oSdk;
} | [
"protected",
"function",
"sdk",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"oSdk",
")",
")",
"{",
"$",
"this",
"->",
"oSdk",
"=",
"new",
"\\",
"Aws",
"\\",
"S3",
"\\",
"S3Client",
"(",
"[",
"'version'",
"=>",
"'latest'",
",",
"'region'",
"=>",
"$",
"this",
"->",
"getRegion",
"(",
")",
",",
"'credentials'",
"=>",
"new",
"\\",
"Aws",
"\\",
"Credentials",
"\\",
"Credentials",
"(",
"$",
"this",
"->",
"getSetting",
"(",
"'access_key'",
")",
",",
"$",
"this",
"->",
"getSetting",
"(",
"'access_secret'",
")",
")",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"oSdk",
";",
"}"
] | Returns an instance of the AWS S3 SDK
@return S3Client | [
"Returns",
"an",
"instance",
"of",
"the",
"AWS",
"S3",
"SDK"
] | 422fd0a7a911bec60dbe2791ac6bafd0a2502092 | https://github.com/nails/driver-cdn-awslocal/blob/422fd0a7a911bec60dbe2791ac6bafd0a2502092/src/Aws.php#L41-L55 | train |
nails/driver-cdn-awslocal | src/Aws.php | Aws.getBucket | protected function getBucket()
{
if (empty($this->sS3Bucket)) {
$this->sS3Bucket = $this->getRegionAndBucket()->bucket;
if (empty($this->sS3Bucket)) {
throw new DriverException('S3 Bucket has not been defined.');
}
}
return $this->sS3Bucket;
} | php | protected function getBucket()
{
if (empty($this->sS3Bucket)) {
$this->sS3Bucket = $this->getRegionAndBucket()->bucket;
if (empty($this->sS3Bucket)) {
throw new DriverException('S3 Bucket has not been defined.');
}
}
return $this->sS3Bucket;
} | [
"protected",
"function",
"getBucket",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"sS3Bucket",
")",
")",
"{",
"$",
"this",
"->",
"sS3Bucket",
"=",
"$",
"this",
"->",
"getRegionAndBucket",
"(",
")",
"->",
"bucket",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"sS3Bucket",
")",
")",
"{",
"throw",
"new",
"DriverException",
"(",
"'S3 Bucket has not been defined.'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"sS3Bucket",
";",
"}"
] | Returns the AWS bucket for this environment
@return string
@throws DriverException | [
"Returns",
"the",
"AWS",
"bucket",
"for",
"this",
"environment"
] | 422fd0a7a911bec60dbe2791ac6bafd0a2502092 | https://github.com/nails/driver-cdn-awslocal/blob/422fd0a7a911bec60dbe2791ac6bafd0a2502092/src/Aws.php#L66-L76 | train |
nails/driver-cdn-awslocal | src/Aws.php | Aws.getRegion | protected function getRegion()
{
if (empty($this->sS3Region)) {
$this->sS3Region = $this->getRegionAndBucket()->region;
if (empty($this->sS3Region)) {
throw new DriverException('S3 Region has not been defined.');
}
}
return $this->sS3Region;
} | php | protected function getRegion()
{
if (empty($this->sS3Region)) {
$this->sS3Region = $this->getRegionAndBucket()->region;
if (empty($this->sS3Region)) {
throw new DriverException('S3 Region has not been defined.');
}
}
return $this->sS3Region;
} | [
"protected",
"function",
"getRegion",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"sS3Region",
")",
")",
"{",
"$",
"this",
"->",
"sS3Region",
"=",
"$",
"this",
"->",
"getRegionAndBucket",
"(",
")",
"->",
"region",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"sS3Region",
")",
")",
"{",
"throw",
"new",
"DriverException",
"(",
"'S3 Region has not been defined.'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"sS3Region",
";",
"}"
] | Returns the AWS region for this environment
@return string
@throws DriverException | [
"Returns",
"the",
"AWS",
"region",
"for",
"this",
"environment"
] | 422fd0a7a911bec60dbe2791ac6bafd0a2502092 | https://github.com/nails/driver-cdn-awslocal/blob/422fd0a7a911bec60dbe2791ac6bafd0a2502092/src/Aws.php#L87-L97 | train |
nails/driver-cdn-awslocal | src/Aws.php | Aws.getRegionAndBucket | protected function getRegionAndBucket()
{
$aSpaces = json_decode($this->getSetting('buckets'), true);
if (empty($aSpaces)) {
throw new DriverException('S3 Buckets have not been defined.');
} elseif (empty($aSpaces[Environment::get()])) {
throw new DriverException('No bucket defined for the ' . Environment::get() . ' environment.');
} else {
$sRegionSpace = explode(':', $aSpaces[Environment::get()]);
return (object) [
'region' => getFromArray(0, $sRegionSpace, ''),
'bucket' => getFromArray(1, $sRegionSpace, ''),
];
}
} | php | protected function getRegionAndBucket()
{
$aSpaces = json_decode($this->getSetting('buckets'), true);
if (empty($aSpaces)) {
throw new DriverException('S3 Buckets have not been defined.');
} elseif (empty($aSpaces[Environment::get()])) {
throw new DriverException('No bucket defined for the ' . Environment::get() . ' environment.');
} else {
$sRegionSpace = explode(':', $aSpaces[Environment::get()]);
return (object) [
'region' => getFromArray(0, $sRegionSpace, ''),
'bucket' => getFromArray(1, $sRegionSpace, ''),
];
}
} | [
"protected",
"function",
"getRegionAndBucket",
"(",
")",
"{",
"$",
"aSpaces",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"getSetting",
"(",
"'buckets'",
")",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"aSpaces",
")",
")",
"{",
"throw",
"new",
"DriverException",
"(",
"'S3 Buckets have not been defined.'",
")",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"aSpaces",
"[",
"Environment",
"::",
"get",
"(",
")",
"]",
")",
")",
"{",
"throw",
"new",
"DriverException",
"(",
"'No bucket defined for the '",
".",
"Environment",
"::",
"get",
"(",
")",
".",
"' environment.'",
")",
";",
"}",
"else",
"{",
"$",
"sRegionSpace",
"=",
"explode",
"(",
"':'",
",",
"$",
"aSpaces",
"[",
"Environment",
"::",
"get",
"(",
")",
"]",
")",
";",
"return",
"(",
"object",
")",
"[",
"'region'",
"=>",
"getFromArray",
"(",
"0",
",",
"$",
"sRegionSpace",
",",
"''",
")",
",",
"'bucket'",
"=>",
"getFromArray",
"(",
"1",
",",
"$",
"sRegionSpace",
",",
"''",
")",
",",
"]",
";",
"}",
"}"
] | Extracts the Region and Bucket from the configs
@return \stdClass
@throws DriverException | [
"Extracts",
"the",
"Region",
"and",
"Bucket",
"from",
"the",
"configs"
] | 422fd0a7a911bec60dbe2791ac6bafd0a2502092 | https://github.com/nails/driver-cdn-awslocal/blob/422fd0a7a911bec60dbe2791ac6bafd0a2502092/src/Aws.php#L108-L122 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.