repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
ufocoder/yii2-SyncSocial | src/components/services/Vkontakte.php | Vkontakte.publishPost | public function publishPost( $message, $url = null ) {
$userAttributes = $this->service->getUserAttributes();
$postResponse = $this->service->api( 'wall.post', 'GET', [
'message' => $message
] );
$getResponse = $this->service->api( 'wall.getById', 'GET', [
'posts' => $userAttributes['id'] . '_' . $postResponse['response']['post_id']
] );
return $this->parsePublishPost( $getResponse, 'response.0', [
'service_id_author' => 'from_id',
'service_id_post' => 'id',
'time_created' => 'date'
] );
} | php | public function publishPost( $message, $url = null ) {
$userAttributes = $this->service->getUserAttributes();
$postResponse = $this->service->api( 'wall.post', 'GET', [
'message' => $message
] );
$getResponse = $this->service->api( 'wall.getById', 'GET', [
'posts' => $userAttributes['id'] . '_' . $postResponse['response']['post_id']
] );
return $this->parsePublishPost( $getResponse, 'response.0', [
'service_id_author' => 'from_id',
'service_id_post' => 'id',
'time_created' => 'date'
] );
} | [
"public",
"function",
"publishPost",
"(",
"$",
"message",
",",
"$",
"url",
"=",
"null",
")",
"{",
"$",
"userAttributes",
"=",
"$",
"this",
"->",
"service",
"->",
"getUserAttributes",
"(",
")",
";",
"$",
"postResponse",
"=",
"$",
"this",
"->",
"service",
"->",
"api",
"(",
"'wall.post'",
",",
"'GET'",
",",
"[",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"$",
"getResponse",
"=",
"$",
"this",
"->",
"service",
"->",
"api",
"(",
"'wall.getById'",
",",
"'GET'",
",",
"[",
"'posts'",
"=>",
"$",
"userAttributes",
"[",
"'id'",
"]",
".",
"'_'",
".",
"$",
"postResponse",
"[",
"'response'",
"]",
"[",
"'post_id'",
"]",
"]",
")",
";",
"return",
"$",
"this",
"->",
"parsePublishPost",
"(",
"$",
"getResponse",
",",
"'response.0'",
",",
"[",
"'service_id_author'",
"=>",
"'from_id'",
",",
"'service_id_post'",
"=>",
"'id'",
",",
"'time_created'",
"=>",
"'date'",
"]",
")",
";",
"}"
] | @param $message
@param null $url
@return array|void
@throws Exception | [
"@param",
"$message",
"@param",
"null",
"$url"
] | train | https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/components/services/Vkontakte.php#L39-L56 |
ufocoder/yii2-SyncSocial | src/components/services/Vkontakte.php | Vkontakte.deletePost | public function deletePost( $id ) {
$userAttributes = $this->service->getUserAttributes();
$response = $this->service->api( 'wall.delete', 'GET', [
'owner_id' => $userAttributes['id'],
'post_id' => $id
] );
return $response['response'] == 1;
} | php | public function deletePost( $id ) {
$userAttributes = $this->service->getUserAttributes();
$response = $this->service->api( 'wall.delete', 'GET', [
'owner_id' => $userAttributes['id'],
'post_id' => $id
] );
return $response['response'] == 1;
} | [
"public",
"function",
"deletePost",
"(",
"$",
"id",
")",
"{",
"$",
"userAttributes",
"=",
"$",
"this",
"->",
"service",
"->",
"getUserAttributes",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"api",
"(",
"'wall.delete'",
",",
"'GET'",
",",
"[",
"'owner_id'",
"=>",
"$",
"userAttributes",
"[",
"'id'",
"]",
",",
"'post_id'",
"=>",
"$",
"id",
"]",
")",
";",
"return",
"$",
"response",
"[",
"'response'",
"]",
"==",
"1",
";",
"}"
] | @param $id
@return bool | [
"@param",
"$id"
] | train | https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/components/services/Vkontakte.php#L63-L73 |
ufocoder/yii2-SyncSocial | src/components/services/Vkontakte.php | Vkontakte.getWallGetRequestUrl | protected function getWallGetRequestUrl( $limit = null ) {
$query = http_build_query( [
'owner_id' => ArrayHelper::getValue( $this->serviceSettings, 'options.owner_id' ),
'from_group' => ArrayHelper::getValue( $this->serviceSettings, 'options.from_group' ),
'limit' => $limit
] );
return 'wall.get' . ( ! empty( $query ) ? "?" . $query : null );
} | php | protected function getWallGetRequestUrl( $limit = null ) {
$query = http_build_query( [
'owner_id' => ArrayHelper::getValue( $this->serviceSettings, 'options.owner_id' ),
'from_group' => ArrayHelper::getValue( $this->serviceSettings, 'options.from_group' ),
'limit' => $limit
] );
return 'wall.get' . ( ! empty( $query ) ? "?" . $query : null );
} | [
"protected",
"function",
"getWallGetRequestUrl",
"(",
"$",
"limit",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"http_build_query",
"(",
"[",
"'owner_id'",
"=>",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"this",
"->",
"serviceSettings",
",",
"'options.owner_id'",
")",
",",
"'from_group'",
"=>",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"this",
"->",
"serviceSettings",
",",
"'options.from_group'",
")",
",",
"'limit'",
"=>",
"$",
"limit",
"]",
")",
";",
"return",
"'wall.get'",
".",
"(",
"!",
"empty",
"(",
"$",
"query",
")",
"?",
"\"?\"",
".",
"$",
"query",
":",
"null",
")",
";",
"}"
] | @param integer $limit
@return string | [
"@param",
"integer",
"$limit"
] | train | https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/components/services/Vkontakte.php#L80-L89 |
ufocoder/yii2-SyncSocial | src/components/services/Vkontakte.php | Vkontakte.getPosts | public function getPosts( $limit = 100 ) {
return $this->parseGetPosts(
$this->service->api( $this->getWallGetRequestUrl( $limit ), 'GET' ),
'response',
[
'id',
'text'
],
[
'service_id_author' => 'from_id',
'service_id_post' => 'id',
'time_created' => 'date',
'content' => 'text'
] );
} | php | public function getPosts( $limit = 100 ) {
return $this->parseGetPosts(
$this->service->api( $this->getWallGetRequestUrl( $limit ), 'GET' ),
'response',
[
'id',
'text'
],
[
'service_id_author' => 'from_id',
'service_id_post' => 'id',
'time_created' => 'date',
'content' => 'text'
] );
} | [
"public",
"function",
"getPosts",
"(",
"$",
"limit",
"=",
"100",
")",
"{",
"return",
"$",
"this",
"->",
"parseGetPosts",
"(",
"$",
"this",
"->",
"service",
"->",
"api",
"(",
"$",
"this",
"->",
"getWallGetRequestUrl",
"(",
"$",
"limit",
")",
",",
"'GET'",
")",
",",
"'response'",
",",
"[",
"'id'",
",",
"'text'",
"]",
",",
"[",
"'service_id_author'",
"=>",
"'from_id'",
",",
"'service_id_post'",
"=>",
"'id'",
",",
"'time_created'",
"=>",
"'date'",
",",
"'content'",
"=>",
"'text'",
"]",
")",
";",
"}"
] | @param int $limit
@return array
@throws Exception | [
"@param",
"int",
"$limit"
] | train | https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/components/services/Vkontakte.php#L97-L112 |
yuncms/framework | src/notifications/RoutesNotifications.php | RoutesNotifications.shouldReceiveNotification | public function shouldReceiveNotification(Notification $notification)
{
$alias = get_class($notification);
if (isset($this->notificationSettings)) {
$settings = $this->notificationSettings;
if (array_key_exists($alias, $settings)) {
if ($settings[$alias] instanceof \Closure) {
return call_user_func($settings[$alias], $notification);
}
return (bool)$settings[$alias];
}
}
return true;
} | php | public function shouldReceiveNotification(Notification $notification)
{
$alias = get_class($notification);
if (isset($this->notificationSettings)) {
$settings = $this->notificationSettings;
if (array_key_exists($alias, $settings)) {
if ($settings[$alias] instanceof \Closure) {
return call_user_func($settings[$alias], $notification);
}
return (bool)$settings[$alias];
}
}
return true;
} | [
"public",
"function",
"shouldReceiveNotification",
"(",
"Notification",
"$",
"notification",
")",
"{",
"$",
"alias",
"=",
"get_class",
"(",
"$",
"notification",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"notificationSettings",
")",
")",
"{",
"$",
"settings",
"=",
"$",
"this",
"->",
"notificationSettings",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"alias",
",",
"$",
"settings",
")",
")",
"{",
"if",
"(",
"$",
"settings",
"[",
"$",
"alias",
"]",
"instanceof",
"\\",
"Closure",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"settings",
"[",
"$",
"alias",
"]",
",",
"$",
"notification",
")",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"settings",
"[",
"$",
"alias",
"]",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | 确定通知实体是否应通过签入通知设置来接收通知。
@param Notification $notification
@return bool | [
"确定通知实体是否应通过签入通知设置来接收通知。"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/notifications/RoutesNotifications.php#L38-L51 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Style/TableFull.php | PHPWord_Style_TableFull.setBorderSize | public function setBorderSize($pValue = null) {
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->_borderInsideHSize = $pValue;
$this->_borderInsideVSize = $pValue;
} | php | public function setBorderSize($pValue = null) {
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->_borderInsideHSize = $pValue;
$this->_borderInsideVSize = $pValue;
} | [
"public",
"function",
"setBorderSize",
"(",
"$",
"pValue",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_borderTopSize",
"=",
"$",
"pValue",
";",
"$",
"this",
"->",
"_borderLeftSize",
"=",
"$",
"pValue",
";",
"$",
"this",
"->",
"_borderRightSize",
"=",
"$",
"pValue",
";",
"$",
"this",
"->",
"_borderBottomSize",
"=",
"$",
"pValue",
";",
"$",
"this",
"->",
"_borderInsideHSize",
"=",
"$",
"pValue",
";",
"$",
"this",
"->",
"_borderInsideVSize",
"=",
"$",
"pValue",
";",
"}"
] | Set TLRBVH Border Size
@param int $pValue | [
"Set",
"TLRBVH",
"Border",
"Size"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Style/TableFull.php#L250-L257 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Style/TableFull.php | PHPWord_Style_TableFull.getBorderSize | public function getBorderSize() {
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize();
$r = $this->getBorderRightSize();
$b = $this->getBorderBottomSize();
$h = $this->getBorderInsideHSize();
$v = $this->getBorderInsideVSize();
return array($t, $l, $r, $b, $h, $v);
} | php | public function getBorderSize() {
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize();
$r = $this->getBorderRightSize();
$b = $this->getBorderBottomSize();
$h = $this->getBorderInsideHSize();
$v = $this->getBorderInsideVSize();
return array($t, $l, $r, $b, $h, $v);
} | [
"public",
"function",
"getBorderSize",
"(",
")",
"{",
"$",
"t",
"=",
"$",
"this",
"->",
"getBorderTopSize",
"(",
")",
";",
"$",
"l",
"=",
"$",
"this",
"->",
"getBorderLeftSize",
"(",
")",
";",
"$",
"r",
"=",
"$",
"this",
"->",
"getBorderRightSize",
"(",
")",
";",
"$",
"b",
"=",
"$",
"this",
"->",
"getBorderBottomSize",
"(",
")",
";",
"$",
"h",
"=",
"$",
"this",
"->",
"getBorderInsideHSize",
"(",
")",
";",
"$",
"v",
"=",
"$",
"this",
"->",
"getBorderInsideVSize",
"(",
")",
";",
"return",
"array",
"(",
"$",
"t",
",",
"$",
"l",
",",
"$",
"r",
",",
"$",
"b",
",",
"$",
"h",
",",
"$",
"v",
")",
";",
"}"
] | Get TLRBVH Border Size
@return array | [
"Get",
"TLRBVH",
"Border",
"Size"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Style/TableFull.php#L264-L273 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Style/TableFull.php | PHPWord_Style_TableFull.getBorderColor | public function getBorderColor() {
$t = $this->getBorderTopColor();
$l = $this->getBorderLeftColor();
$r = $this->getBorderRightColor();
$b = $this->getBorderBottomColor();
$h = $this->getBorderInsideHColor();
$v = $this->getBorderInsideVColor();
return array($t, $l, $r, $b, $h, $v);
} | php | public function getBorderColor() {
$t = $this->getBorderTopColor();
$l = $this->getBorderLeftColor();
$r = $this->getBorderRightColor();
$b = $this->getBorderBottomColor();
$h = $this->getBorderInsideHColor();
$v = $this->getBorderInsideVColor();
return array($t, $l, $r, $b, $h, $v);
} | [
"public",
"function",
"getBorderColor",
"(",
")",
"{",
"$",
"t",
"=",
"$",
"this",
"->",
"getBorderTopColor",
"(",
")",
";",
"$",
"l",
"=",
"$",
"this",
"->",
"getBorderLeftColor",
"(",
")",
";",
"$",
"r",
"=",
"$",
"this",
"->",
"getBorderRightColor",
"(",
")",
";",
"$",
"b",
"=",
"$",
"this",
"->",
"getBorderBottomColor",
"(",
")",
";",
"$",
"h",
"=",
"$",
"this",
"->",
"getBorderInsideHColor",
"(",
")",
";",
"$",
"v",
"=",
"$",
"this",
"->",
"getBorderInsideVColor",
"(",
")",
";",
"return",
"array",
"(",
"$",
"t",
",",
"$",
"l",
",",
"$",
"r",
",",
"$",
"b",
",",
"$",
"h",
",",
"$",
"v",
")",
";",
"}"
] | Get TLRB Border Color
@return array | [
"Get",
"TLRB",
"Border",
"Color"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Style/TableFull.php#L292-L301 |
chubbyphp/chubbyphp-api-http | src/Manager/ResponseManager.php | ResponseManager.create | public function create(
$object,
string $accept,
int $status = 200,
NormalizerContextInterface $context = null
): ResponseInterface {
$body = $this->serializer->serialize($object, $accept, $context);
$response = $this->responseFactory->createResponse($status)->withHeader('Content-Type', $accept);
$response->getBody()->write($body);
return $response;
} | php | public function create(
$object,
string $accept,
int $status = 200,
NormalizerContextInterface $context = null
): ResponseInterface {
$body = $this->serializer->serialize($object, $accept, $context);
$response = $this->responseFactory->createResponse($status)->withHeader('Content-Type', $accept);
$response->getBody()->write($body);
return $response;
} | [
"public",
"function",
"create",
"(",
"$",
"object",
",",
"string",
"$",
"accept",
",",
"int",
"$",
"status",
"=",
"200",
",",
"NormalizerContextInterface",
"$",
"context",
"=",
"null",
")",
":",
"ResponseInterface",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"serializer",
"->",
"serialize",
"(",
"$",
"object",
",",
"$",
"accept",
",",
"$",
"context",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"responseFactory",
"->",
"createResponse",
"(",
"$",
"status",
")",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"$",
"accept",
")",
";",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"$",
"body",
")",
";",
"return",
"$",
"response",
";",
"}"
] | @param object $object
@param string $accept
@param int $status
@param NormalizerContextInterface|null $context
@return ResponseInterface | [
"@param",
"object",
"$object",
"@param",
"string",
"$accept",
"@param",
"int",
"$status",
"@param",
"NormalizerContextInterface|null",
"$context"
] | train | https://github.com/chubbyphp/chubbyphp-api-http/blob/675d657b686e96aa16be56d0e9e07aaa844266ed/src/Manager/ResponseManager.php#L54-L66 |
chubbyphp/chubbyphp-api-http | src/Manager/ResponseManager.php | ResponseManager.createEmpty | public function createEmpty(string $accept, int $status = 204): ResponseInterface
{
return $this->responseFactory->createResponse($status)->withHeader('Content-Type', $accept);
} | php | public function createEmpty(string $accept, int $status = 204): ResponseInterface
{
return $this->responseFactory->createResponse($status)->withHeader('Content-Type', $accept);
} | [
"public",
"function",
"createEmpty",
"(",
"string",
"$",
"accept",
",",
"int",
"$",
"status",
"=",
"204",
")",
":",
"ResponseInterface",
"{",
"return",
"$",
"this",
"->",
"responseFactory",
"->",
"createResponse",
"(",
"$",
"status",
")",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"$",
"accept",
")",
";",
"}"
] | @param string $accept
@param int $status
@return ResponseInterface | [
"@param",
"string",
"$accept",
"@param",
"int",
"$status"
] | train | https://github.com/chubbyphp/chubbyphp-api-http/blob/675d657b686e96aa16be56d0e9e07aaa844266ed/src/Manager/ResponseManager.php#L74-L77 |
chubbyphp/chubbyphp-api-http | src/Manager/ResponseManager.php | ResponseManager.createRedirect | public function createRedirect(string $location, int $status = 307): ResponseInterface
{
return $this->responseFactory->createResponse($status)->withHeader('Location', $location);
} | php | public function createRedirect(string $location, int $status = 307): ResponseInterface
{
return $this->responseFactory->createResponse($status)->withHeader('Location', $location);
} | [
"public",
"function",
"createRedirect",
"(",
"string",
"$",
"location",
",",
"int",
"$",
"status",
"=",
"307",
")",
":",
"ResponseInterface",
"{",
"return",
"$",
"this",
"->",
"responseFactory",
"->",
"createResponse",
"(",
"$",
"status",
")",
"->",
"withHeader",
"(",
"'Location'",
",",
"$",
"location",
")",
";",
"}"
] | @param string $location
@param int $status
@return ResponseInterface | [
"@param",
"string",
"$location",
"@param",
"int",
"$status"
] | train | https://github.com/chubbyphp/chubbyphp-api-http/blob/675d657b686e96aa16be56d0e9e07aaa844266ed/src/Manager/ResponseManager.php#L85-L88 |
chubbyphp/chubbyphp-api-http | src/Manager/ResponseManager.php | ResponseManager.createFromApiProblem | public function createFromApiProblem(
ApiProblemInterface $apiProblem,
string $accept,
NormalizerContextInterface $context = null
): ResponseInterface {
$status = $apiProblem->getStatus();
$response = $this->responseFactory->createResponse($status)
->withHeader('Content-Type', str_replace('/', '/problem+', $accept));
foreach ($apiProblem->getHeaders() as $name => $value) {
$response = $response->withHeader($name, $value);
}
$body = $this->serializer->serialize($apiProblem, $accept, $context);
$response->getBody()->write($body);
return $response;
} | php | public function createFromApiProblem(
ApiProblemInterface $apiProblem,
string $accept,
NormalizerContextInterface $context = null
): ResponseInterface {
$status = $apiProblem->getStatus();
$response = $this->responseFactory->createResponse($status)
->withHeader('Content-Type', str_replace('/', '/problem+', $accept));
foreach ($apiProblem->getHeaders() as $name => $value) {
$response = $response->withHeader($name, $value);
}
$body = $this->serializer->serialize($apiProblem, $accept, $context);
$response->getBody()->write($body);
return $response;
} | [
"public",
"function",
"createFromApiProblem",
"(",
"ApiProblemInterface",
"$",
"apiProblem",
",",
"string",
"$",
"accept",
",",
"NormalizerContextInterface",
"$",
"context",
"=",
"null",
")",
":",
"ResponseInterface",
"{",
"$",
"status",
"=",
"$",
"apiProblem",
"->",
"getStatus",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"responseFactory",
"->",
"createResponse",
"(",
"$",
"status",
")",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"str_replace",
"(",
"'/'",
",",
"'/problem+'",
",",
"$",
"accept",
")",
")",
";",
"foreach",
"(",
"$",
"apiProblem",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"$",
"body",
"=",
"$",
"this",
"->",
"serializer",
"->",
"serialize",
"(",
"$",
"apiProblem",
",",
"$",
"accept",
",",
"$",
"context",
")",
";",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"$",
"body",
")",
";",
"return",
"$",
"response",
";",
"}"
] | @param ApiProblemInterface $apiProblem
@param string $accept
@param NormalizerContextInterface $context
@return ResponseInterface | [
"@param",
"ApiProblemInterface",
"$apiProblem",
"@param",
"string",
"$accept",
"@param",
"NormalizerContextInterface",
"$context"
] | train | https://github.com/chubbyphp/chubbyphp-api-http/blob/675d657b686e96aa16be56d0e9e07aaa844266ed/src/Manager/ResponseManager.php#L97-L116 |
AydinHassan/cli-md-renderer | src/Renderer/FencedCodeRenderer.php | FencedCodeRenderer.render | public function render(AbstractBlock $block, CliRenderer $renderer)
{
if (!($block instanceof FencedCode)) {
throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
}
$infoWords = $block->getInfoWords();
$codeType = null;
if (count($infoWords) !== 0 && strlen($infoWords[0]) !== 0) {
$codeType = $infoWords[0];
}
if (null === $codeType || !isset($this->highlighters[$codeType])) {
return $this->indent($renderer->style($block->getStringContent(), 'yellow'));
}
return $this->indent(
sprintf("%s\n", $this->highlighters[$codeType]->highlight($block->getStringContent()))
);
} | php | public function render(AbstractBlock $block, CliRenderer $renderer)
{
if (!($block instanceof FencedCode)) {
throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
}
$infoWords = $block->getInfoWords();
$codeType = null;
if (count($infoWords) !== 0 && strlen($infoWords[0]) !== 0) {
$codeType = $infoWords[0];
}
if (null === $codeType || !isset($this->highlighters[$codeType])) {
return $this->indent($renderer->style($block->getStringContent(), 'yellow'));
}
return $this->indent(
sprintf("%s\n", $this->highlighters[$codeType]->highlight($block->getStringContent()))
);
} | [
"public",
"function",
"render",
"(",
"AbstractBlock",
"$",
"block",
",",
"CliRenderer",
"$",
"renderer",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"block",
"instanceof",
"FencedCode",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Incompatible block type: \"%s\"'",
",",
"get_class",
"(",
"$",
"block",
")",
")",
")",
";",
"}",
"$",
"infoWords",
"=",
"$",
"block",
"->",
"getInfoWords",
"(",
")",
";",
"$",
"codeType",
"=",
"null",
";",
"if",
"(",
"count",
"(",
"$",
"infoWords",
")",
"!==",
"0",
"&&",
"strlen",
"(",
"$",
"infoWords",
"[",
"0",
"]",
")",
"!==",
"0",
")",
"{",
"$",
"codeType",
"=",
"$",
"infoWords",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"codeType",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"highlighters",
"[",
"$",
"codeType",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"indent",
"(",
"$",
"renderer",
"->",
"style",
"(",
"$",
"block",
"->",
"getStringContent",
"(",
")",
",",
"'yellow'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"indent",
"(",
"sprintf",
"(",
"\"%s\\n\"",
",",
"$",
"this",
"->",
"highlighters",
"[",
"$",
"codeType",
"]",
"->",
"highlight",
"(",
"$",
"block",
"->",
"getStringContent",
"(",
")",
")",
")",
")",
";",
"}"
] | @param AbstractBlock $block
@param CliRenderer $renderer
@return string | [
"@param",
"AbstractBlock",
"$block",
"@param",
"CliRenderer",
"$renderer"
] | train | https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/Renderer/FencedCodeRenderer.php#L54-L73 |
phug-php/formatter | src/Phug/Formatter/Partial/PatternTrait.php | PatternTrait.setPattern | public function setPattern($name, $pattern)
{
if (is_array($pattern)) {
return $this->provideHelper($this->patternName($name), $pattern);
}
$this->registerHelper('patterns.'.$name, $pattern);
return $this->provideHelper($this->patternName($name), [
'pattern',
'patterns.'.$name,
function ($proceed, $pattern) {
return function () use ($proceed, $pattern) {
$args = func_get_args();
array_unshift($args, $pattern);
return call_user_func_array($proceed, $args);
};
},
]);
} | php | public function setPattern($name, $pattern)
{
if (is_array($pattern)) {
return $this->provideHelper($this->patternName($name), $pattern);
}
$this->registerHelper('patterns.'.$name, $pattern);
return $this->provideHelper($this->patternName($name), [
'pattern',
'patterns.'.$name,
function ($proceed, $pattern) {
return function () use ($proceed, $pattern) {
$args = func_get_args();
array_unshift($args, $pattern);
return call_user_func_array($proceed, $args);
};
},
]);
} | [
"public",
"function",
"setPattern",
"(",
"$",
"name",
",",
"$",
"pattern",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"pattern",
")",
")",
"{",
"return",
"$",
"this",
"->",
"provideHelper",
"(",
"$",
"this",
"->",
"patternName",
"(",
"$",
"name",
")",
",",
"$",
"pattern",
")",
";",
"}",
"$",
"this",
"->",
"registerHelper",
"(",
"'patterns.'",
".",
"$",
"name",
",",
"$",
"pattern",
")",
";",
"return",
"$",
"this",
"->",
"provideHelper",
"(",
"$",
"this",
"->",
"patternName",
"(",
"$",
"name",
")",
",",
"[",
"'pattern'",
",",
"'patterns.'",
".",
"$",
"name",
",",
"function",
"(",
"$",
"proceed",
",",
"$",
"pattern",
")",
"{",
"return",
"function",
"(",
")",
"use",
"(",
"$",
"proceed",
",",
"$",
"pattern",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"array_unshift",
"(",
"$",
"args",
",",
"$",
"pattern",
")",
";",
"return",
"call_user_func_array",
"(",
"$",
"proceed",
",",
"$",
"args",
")",
";",
"}",
";",
"}",
",",
"]",
")",
";",
"}"
] | @param $name
@param $pattern
@return PatternTrait | [
"@param",
"$name",
"@param",
"$pattern"
] | train | https://github.com/phug-php/formatter/blob/3f9286a169a0d45b8b8acc1fae64e880ebdb567e/src/Phug/Formatter/Partial/PatternTrait.php#L30-L50 |
phug-php/formatter | src/Phug/Formatter/Partial/PatternTrait.php | PatternTrait.addPattern | public function addPattern($name, $pattern)
{
if (!$this->hasPattern($name)) {
$this->setPattern($name, $pattern);
}
return $this;
} | php | public function addPattern($name, $pattern)
{
if (!$this->hasPattern($name)) {
$this->setPattern($name, $pattern);
}
return $this;
} | [
"public",
"function",
"addPattern",
"(",
"$",
"name",
",",
"$",
"pattern",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasPattern",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"setPattern",
"(",
"$",
"name",
",",
"$",
"pattern",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param $name
@param $pattern
@return PatternTrait | [
"@param",
"$name",
"@param",
"$pattern"
] | train | https://github.com/phug-php/formatter/blob/3f9286a169a0d45b8b8acc1fae64e880ebdb567e/src/Phug/Formatter/Partial/PatternTrait.php#L58-L65 |
phug-php/formatter | src/Phug/Formatter/Partial/PatternTrait.php | PatternTrait.addPatterns | public function addPatterns($patterns)
{
foreach ($patterns as $name => $pattern) {
$this->addPattern($name, $pattern);
}
return $this;
} | php | public function addPatterns($patterns)
{
foreach ($patterns as $name => $pattern) {
$this->addPattern($name, $pattern);
}
return $this;
} | [
"public",
"function",
"addPatterns",
"(",
"$",
"patterns",
")",
"{",
"foreach",
"(",
"$",
"patterns",
"as",
"$",
"name",
"=>",
"$",
"pattern",
")",
"{",
"$",
"this",
"->",
"addPattern",
"(",
"$",
"name",
",",
"$",
"pattern",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param $patterns
@return $this | [
"@param",
"$patterns"
] | train | https://github.com/phug-php/formatter/blob/3f9286a169a0d45b8b8acc1fae64e880ebdb567e/src/Phug/Formatter/Partial/PatternTrait.php#L72-L79 |
phug-php/formatter | src/Phug/Formatter/Partial/PatternTrait.php | PatternTrait.setPatterns | public function setPatterns($patterns)
{
foreach ($patterns as $name => $pattern) {
$this->setPattern($name, $pattern);
}
return $this;
} | php | public function setPatterns($patterns)
{
foreach ($patterns as $name => $pattern) {
$this->setPattern($name, $pattern);
}
return $this;
} | [
"public",
"function",
"setPatterns",
"(",
"$",
"patterns",
")",
"{",
"foreach",
"(",
"$",
"patterns",
"as",
"$",
"name",
"=>",
"$",
"pattern",
")",
"{",
"$",
"this",
"->",
"setPattern",
"(",
"$",
"name",
",",
"$",
"pattern",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param $patterns
@return $this | [
"@param",
"$patterns"
] | train | https://github.com/phug-php/formatter/blob/3f9286a169a0d45b8b8acc1fae64e880ebdb567e/src/Phug/Formatter/Partial/PatternTrait.php#L86-L93 |
phug-php/formatter | src/Phug/Formatter/Partial/PatternTrait.php | PatternTrait.exportHelper | public function exportHelper($name, array $arguments = null)
{
$this->requireHelper($name);
$code = $this->formatter->getDependencyStorage(
$this->helperName($name)
);
if (!is_null($arguments)) {
$code .= '('.implode(', ', $arguments).')';
}
return $code;
} | php | public function exportHelper($name, array $arguments = null)
{
$this->requireHelper($name);
$code = $this->formatter->getDependencyStorage(
$this->helperName($name)
);
if (!is_null($arguments)) {
$code .= '('.implode(', ', $arguments).')';
}
return $code;
} | [
"public",
"function",
"exportHelper",
"(",
"$",
"name",
",",
"array",
"$",
"arguments",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"requireHelper",
"(",
"$",
"name",
")",
";",
"$",
"code",
"=",
"$",
"this",
"->",
"formatter",
"->",
"getDependencyStorage",
"(",
"$",
"this",
"->",
"helperName",
"(",
"$",
"name",
")",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"arguments",
")",
")",
"{",
"$",
"code",
".=",
"'('",
".",
"implode",
"(",
"', '",
",",
"$",
"arguments",
")",
".",
"')'",
";",
"}",
"return",
"$",
"code",
";",
"}"
] | @param string $name
@param array $name
@return string | [
"@param",
"string",
"$name",
"@param",
"array",
"$name"
] | train | https://github.com/phug-php/formatter/blob/3f9286a169a0d45b8b8acc1fae64e880ebdb567e/src/Phug/Formatter/Partial/PatternTrait.php#L101-L113 |
webforge-labs/psc-cms | lib/Psc/Doctrine/EntityCollectionSynchronizer.php | EntityCollectionSynchronizer.init | public function init(Entity $entity) {
// check entity
if ($entity->getEntityName() !== ($class = $this->entityMeta->getClass())) {
throw new \InvalidArgumentException('Das übergebene Entity für diesen Synchronizer kann nur vom Typ: '.$class.' sein. Ein Entity des Typs '.$entity->getEntityName().' wurde übergeben');
}
// check relation
$collectionMeta = $this->getCollectionPropertyMeta();
if (!$collectionMeta->isRelation()) {
throw new \InvalidArgumentException(
sprintf('Das Property %s von %s ist keine Collection. Das Property muss ManyToMany oder OneToMany sein',
$this->collectionName, $this->entityMeta->getClass())
);
}
} | php | public function init(Entity $entity) {
// check entity
if ($entity->getEntityName() !== ($class = $this->entityMeta->getClass())) {
throw new \InvalidArgumentException('Das übergebene Entity für diesen Synchronizer kann nur vom Typ: '.$class.' sein. Ein Entity des Typs '.$entity->getEntityName().' wurde übergeben');
}
// check relation
$collectionMeta = $this->getCollectionPropertyMeta();
if (!$collectionMeta->isRelation()) {
throw new \InvalidArgumentException(
sprintf('Das Property %s von %s ist keine Collection. Das Property muss ManyToMany oder OneToMany sein',
$this->collectionName, $this->entityMeta->getClass())
);
}
} | [
"public",
"function",
"init",
"(",
"Entity",
"$",
"entity",
")",
"{",
"// check entity",
"if",
"(",
"$",
"entity",
"->",
"getEntityName",
"(",
")",
"!==",
"(",
"$",
"class",
"=",
"$",
"this",
"->",
"entityMeta",
"->",
"getClass",
"(",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Das übergebene Entity für diesen Synchronizer kann nur vom Typ: '.$",
"c",
"l",
"ass.'",
" ",
"sein. Ein Entity des Typs '.$",
"e",
"n",
"tity->",
"ge",
"tEntityName()",
".",
"'",
" ",
"wurde übergeben');",
"",
"",
"}",
"// check relation",
"$",
"collectionMeta",
"=",
"$",
"this",
"->",
"getCollectionPropertyMeta",
"(",
")",
";",
"if",
"(",
"!",
"$",
"collectionMeta",
"->",
"isRelation",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Das Property %s von %s ist keine Collection. Das Property muss ManyToMany oder OneToMany sein'",
",",
"$",
"this",
"->",
"collectionName",
",",
"$",
"this",
"->",
"entityMeta",
"->",
"getClass",
"(",
")",
")",
")",
";",
"}",
"}"
] | Initialisiert den Synchronizer mit dem $entity in dem $this->collectionName vorhanden ist
dies er gibt dann die fromCollection | [
"Initialisiert",
"den",
"Synchronizer",
"mit",
"dem",
"$entity",
"in",
"dem",
"$this",
"-",
">",
"collectionName",
"vorhanden",
"ist"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityCollectionSynchronizer.php#L52-L66 |
yuncms/framework | src/user/behaviors/LoginAttemptBehavior.php | LoginAttemptBehavior.getUserLoginAttempt | public function getUserLoginAttempt()
{
if (!$this->_attempt) {
$this->_attempt = new UserLoginAttempt;
$this->_attempt->key = $this->getKey();
}
return $this->_attempt;
} | php | public function getUserLoginAttempt()
{
if (!$this->_attempt) {
$this->_attempt = new UserLoginAttempt;
$this->_attempt->key = $this->getKey();
}
return $this->_attempt;
} | [
"public",
"function",
"getUserLoginAttempt",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_attempt",
")",
"{",
"$",
"this",
"->",
"_attempt",
"=",
"new",
"UserLoginAttempt",
";",
"$",
"this",
"->",
"_attempt",
"->",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_attempt",
";",
"}"
] | 获取拦截历史
@return UserLoginAttempt | [
"获取拦截历史"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/behaviors/LoginAttemptBehavior.php#L158-L165 |
slashworks/control-bundle | src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php | BaseCountryPeer.getFieldNames | public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
{
if (!array_key_exists($type, CountryPeer::$fieldNames)) {
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
}
return CountryPeer::$fieldNames[$type];
} | php | public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
{
if (!array_key_exists($type, CountryPeer::$fieldNames)) {
throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
}
return CountryPeer::$fieldNames[$type];
} | [
"public",
"static",
"function",
"getFieldNames",
"(",
"$",
"type",
"=",
"BasePeer",
"::",
"TYPE_PHPNAME",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"CountryPeer",
"::",
"$",
"fieldNames",
")",
")",
"{",
"throw",
"new",
"PropelException",
"(",
"'Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. '",
".",
"$",
"type",
".",
"' was given.'",
")",
";",
"}",
"return",
"CountryPeer",
"::",
"$",
"fieldNames",
"[",
"$",
"type",
"]",
";",
"}"
] | Returns an array of field names.
@param string $type The type of fieldnames to return:
One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
@return array A list of field names
@throws PropelException - if the type is not valid. | [
"Returns",
"an",
"array",
"of",
"field",
"names",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php#L124-L131 |
slashworks/control-bundle | src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php | BaseCountryPeer.addSelectColumns | public static function addSelectColumns(Criteria $criteria, $alias = null)
{
if (null === $alias) {
$criteria->addSelectColumn(CountryPeer::ID);
$criteria->addSelectColumn(CountryPeer::CODE);
$criteria->addSelectColumn(CountryPeer::EN);
$criteria->addSelectColumn(CountryPeer::DE);
} else {
$criteria->addSelectColumn($alias . '.id');
$criteria->addSelectColumn($alias . '.code');
$criteria->addSelectColumn($alias . '.en');
$criteria->addSelectColumn($alias . '.de');
}
} | php | public static function addSelectColumns(Criteria $criteria, $alias = null)
{
if (null === $alias) {
$criteria->addSelectColumn(CountryPeer::ID);
$criteria->addSelectColumn(CountryPeer::CODE);
$criteria->addSelectColumn(CountryPeer::EN);
$criteria->addSelectColumn(CountryPeer::DE);
} else {
$criteria->addSelectColumn($alias . '.id');
$criteria->addSelectColumn($alias . '.code');
$criteria->addSelectColumn($alias . '.en');
$criteria->addSelectColumn($alias . '.de');
}
} | [
"public",
"static",
"function",
"addSelectColumns",
"(",
"Criteria",
"$",
"criteria",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"alias",
")",
"{",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"CountryPeer",
"::",
"ID",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"CountryPeer",
"::",
"CODE",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"CountryPeer",
"::",
"EN",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"CountryPeer",
"::",
"DE",
")",
";",
"}",
"else",
"{",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"$",
"alias",
".",
"'.id'",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"$",
"alias",
".",
"'.code'",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"$",
"alias",
".",
"'.en'",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"$",
"alias",
".",
"'.de'",
")",
";",
"}",
"}"
] | Add all the columns needed to create a new object.
Note: any columns that were marked with lazyLoad="true" in the
XML schema will not be added to the select list and only loaded
on demand.
@param Criteria $criteria object containing the columns to add.
@param string $alias optional table alias
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException. | [
"Add",
"all",
"the",
"columns",
"needed",
"to",
"create",
"a",
"new",
"object",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php#L162-L175 |
slashworks/control-bundle | src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php | BaseCountryPeer.removeInstanceFromPool | public static function removeInstanceFromPool($value)
{
if (Propel::isInstancePoolingEnabled() && $value !== null) {
if (is_object($value) && $value instanceof Country) {
$key = (string) $value->getId();
} elseif (is_scalar($value)) {
// assume we've been passed a primary key
$key = (string) $value;
} else {
$e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or Country object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
throw $e;
}
unset(CountryPeer::$instances[$key]);
}
} | php | public static function removeInstanceFromPool($value)
{
if (Propel::isInstancePoolingEnabled() && $value !== null) {
if (is_object($value) && $value instanceof Country) {
$key = (string) $value->getId();
} elseif (is_scalar($value)) {
// assume we've been passed a primary key
$key = (string) $value;
} else {
$e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or Country object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
throw $e;
}
unset(CountryPeer::$instances[$key]);
}
} | [
"public",
"static",
"function",
"removeInstanceFromPool",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"Propel",
"::",
"isInstancePoolingEnabled",
"(",
")",
"&&",
"$",
"value",
"!==",
"null",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"instanceof",
"Country",
")",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"value",
"->",
"getId",
"(",
")",
";",
"}",
"elseif",
"(",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"// assume we've been passed a primary key",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"e",
"=",
"new",
"PropelException",
"(",
"\"Invalid value passed to removeInstanceFromPool(). Expected primary key or Country object; got \"",
".",
"(",
"is_object",
"(",
"$",
"value",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
".",
"' object.'",
":",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
")",
")",
";",
"throw",
"$",
"e",
";",
"}",
"unset",
"(",
"CountryPeer",
"::",
"$",
"instances",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] | Removes an object from the instance pool.
Propel keeps cached copies of objects in an instance pool when they are retrieved
from the database. In some cases -- especially when you override doDelete
methods in your stub classes -- you may need to explicitly remove objects
from the cache in order to prevent returning objects that no longer exist.
@param mixed $value A Country object or a primary key value.
@return void
@throws PropelException - if the value is invalid. | [
"Removes",
"an",
"object",
"from",
"the",
"instance",
"pool",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php#L319-L334 |
slashworks/control-bundle | src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php | BaseCountryPeer.getInstanceFromPool | public static function getInstanceFromPool($key)
{
if (Propel::isInstancePoolingEnabled()) {
if (isset(CountryPeer::$instances[$key])) {
return CountryPeer::$instances[$key];
}
}
return null; // just to be explicit
} | php | public static function getInstanceFromPool($key)
{
if (Propel::isInstancePoolingEnabled()) {
if (isset(CountryPeer::$instances[$key])) {
return CountryPeer::$instances[$key];
}
}
return null; // just to be explicit
} | [
"public",
"static",
"function",
"getInstanceFromPool",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"Propel",
"::",
"isInstancePoolingEnabled",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"CountryPeer",
"::",
"$",
"instances",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"CountryPeer",
"::",
"$",
"instances",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"null",
";",
"// just to be explicit",
"}"
] | Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
For tables with a single-column primary key, that simple pkey value will be returned. For tables with
a multi-column primary key, a serialize()d version of the primary key will be returned.
@param string $key The key (@see getPrimaryKeyHash()) for this instance.
@return Country Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
@see getPrimaryKeyHash() | [
"Retrieves",
"a",
"string",
"version",
"of",
"the",
"primary",
"key",
"from",
"the",
"DB",
"resultset",
"row",
"that",
"can",
"be",
"used",
"to",
"uniquely",
"identify",
"a",
"row",
"in",
"this",
"table",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php#L346-L355 |
slashworks/control-bundle | src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php | BaseCountryPeer.populateObject | public static function populateObject($row, $startcol = 0)
{
$key = CountryPeer::getPrimaryKeyHashFromRow($row, $startcol);
if (null !== ($obj = CountryPeer::getInstanceFromPool($key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// $obj->hydrate($row, $startcol, true); // rehydrate
$col = $startcol + CountryPeer::NUM_HYDRATE_COLUMNS;
} else {
$cls = CountryPeer::OM_CLASS;
$obj = new $cls();
$col = $obj->hydrate($row, $startcol);
CountryPeer::addInstanceToPool($obj, $key);
}
return array($obj, $col);
} | php | public static function populateObject($row, $startcol = 0)
{
$key = CountryPeer::getPrimaryKeyHashFromRow($row, $startcol);
if (null !== ($obj = CountryPeer::getInstanceFromPool($key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// $obj->hydrate($row, $startcol, true); // rehydrate
$col = $startcol + CountryPeer::NUM_HYDRATE_COLUMNS;
} else {
$cls = CountryPeer::OM_CLASS;
$obj = new $cls();
$col = $obj->hydrate($row, $startcol);
CountryPeer::addInstanceToPool($obj, $key);
}
return array($obj, $col);
} | [
"public",
"static",
"function",
"populateObject",
"(",
"$",
"row",
",",
"$",
"startcol",
"=",
"0",
")",
"{",
"$",
"key",
"=",
"CountryPeer",
"::",
"getPrimaryKeyHashFromRow",
"(",
"$",
"row",
",",
"$",
"startcol",
")",
";",
"if",
"(",
"null",
"!==",
"(",
"$",
"obj",
"=",
"CountryPeer",
"::",
"getInstanceFromPool",
"(",
"$",
"key",
")",
")",
")",
"{",
"// We no longer rehydrate the object, since this can cause data loss.",
"// See http://www.propelorm.org/ticket/509",
"// $obj->hydrate($row, $startcol, true); // rehydrate",
"$",
"col",
"=",
"$",
"startcol",
"+",
"CountryPeer",
"::",
"NUM_HYDRATE_COLUMNS",
";",
"}",
"else",
"{",
"$",
"cls",
"=",
"CountryPeer",
"::",
"OM_CLASS",
";",
"$",
"obj",
"=",
"new",
"$",
"cls",
"(",
")",
";",
"$",
"col",
"=",
"$",
"obj",
"->",
"hydrate",
"(",
"$",
"row",
",",
"$",
"startcol",
")",
";",
"CountryPeer",
"::",
"addInstanceToPool",
"(",
"$",
"obj",
",",
"$",
"key",
")",
";",
"}",
"return",
"array",
"(",
"$",
"obj",
",",
"$",
"col",
")",
";",
"}"
] | Populates an object of the default type or an object that inherit from the default.
@param array $row PropelPDO resultset row.
@param int $startcol The 0-based offset for reading from the resultset row.
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException.
@return array (Country object, last column rank) | [
"Populates",
"an",
"object",
"of",
"the",
"default",
"type",
"or",
"an",
"object",
"that",
"inherit",
"from",
"the",
"default",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php#L456-L472 |
slashworks/control-bundle | src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php | BaseCountryPeer.buildTableMap | public static function buildTableMap()
{
$dbMap = Propel::getDatabaseMap(BaseCountryPeer::DATABASE_NAME);
if (!$dbMap->hasTable(BaseCountryPeer::TABLE_NAME)) {
$dbMap->addTableObject(new \Slashworks\AppBundle\Model\map\CountryTableMap());
}
} | php | public static function buildTableMap()
{
$dbMap = Propel::getDatabaseMap(BaseCountryPeer::DATABASE_NAME);
if (!$dbMap->hasTable(BaseCountryPeer::TABLE_NAME)) {
$dbMap->addTableObject(new \Slashworks\AppBundle\Model\map\CountryTableMap());
}
} | [
"public",
"static",
"function",
"buildTableMap",
"(",
")",
"{",
"$",
"dbMap",
"=",
"Propel",
"::",
"getDatabaseMap",
"(",
"BaseCountryPeer",
"::",
"DATABASE_NAME",
")",
";",
"if",
"(",
"!",
"$",
"dbMap",
"->",
"hasTable",
"(",
"BaseCountryPeer",
"::",
"TABLE_NAME",
")",
")",
"{",
"$",
"dbMap",
"->",
"addTableObject",
"(",
"new",
"\\",
"Slashworks",
"\\",
"AppBundle",
"\\",
"Model",
"\\",
"map",
"\\",
"CountryTableMap",
"(",
")",
")",
";",
"}",
"}"
] | Add a TableMap instance to the database for this peer class. | [
"Add",
"a",
"TableMap",
"instance",
"to",
"the",
"database",
"for",
"this",
"peer",
"class",
"."
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseCountryPeer.php#L489-L495 |
ClanCats/Core | src/classes/CCShipyard.php | CCShipyard.create | public static function create()
{
$arguments = func_get_args();
$name = array_shift( $arguments );
$class_name = "Core\\CCShipyard_".ucfirst( $name );
if ( !class_exists( $class_name ) )
{
throw new CCException( "CCShipyard - invalid builder (".$name.") given." );
}
$builder = new $class_name;
call_user_func_array( array( $builder, 'create' ), $arguments );
return $builder;
} | php | public static function create()
{
$arguments = func_get_args();
$name = array_shift( $arguments );
$class_name = "Core\\CCShipyard_".ucfirst( $name );
if ( !class_exists( $class_name ) )
{
throw new CCException( "CCShipyard - invalid builder (".$name.") given." );
}
$builder = new $class_name;
call_user_func_array( array( $builder, 'create' ), $arguments );
return $builder;
} | [
"public",
"static",
"function",
"create",
"(",
")",
"{",
"$",
"arguments",
"=",
"func_get_args",
"(",
")",
";",
"$",
"name",
"=",
"array_shift",
"(",
"$",
"arguments",
")",
";",
"$",
"class_name",
"=",
"\"Core\\\\CCShipyard_\"",
".",
"ucfirst",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class_name",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"\"CCShipyard - invalid builder (\"",
".",
"$",
"name",
".",
"\") given.\"",
")",
";",
"}",
"$",
"builder",
"=",
"new",
"$",
"class_name",
";",
"call_user_func_array",
"(",
"array",
"(",
"$",
"builder",
",",
"'create'",
")",
",",
"$",
"arguments",
")",
";",
"return",
"$",
"builder",
";",
"}"
] | Static call wrapper to require the right builder
@param string $name
@param array $arguments
@return CCShipyard_Builder | [
"Static",
"call",
"wrapper",
"to",
"require",
"the",
"right",
"builder"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCShipyard.php#L21-L39 |
picamator/CacheManager | src/Operation/Search.php | Search.search | public function search(SearchCriteriaInterface $searchCriteria) : SearchResultInterface
{
$cacheItemGenerator = $this->getCacheItemGenerator($searchCriteria);
$fieldList = $searchCriteria->getFieldList();
$data = [];
$missedData = [];
/** @var \Psr\Cache\CacheItemInterface $value */
foreach ($cacheItemGenerator as $key => $value) {
if ($this->hasValidCacheItem($value, $fieldList)) {
$data[] = $value;
continue;
}
$missedData[] = $key;
}
return $this->searchResultFactory->create($data, $missedData);
} | php | public function search(SearchCriteriaInterface $searchCriteria) : SearchResultInterface
{
$cacheItemGenerator = $this->getCacheItemGenerator($searchCriteria);
$fieldList = $searchCriteria->getFieldList();
$data = [];
$missedData = [];
/** @var \Psr\Cache\CacheItemInterface $value */
foreach ($cacheItemGenerator as $key => $value) {
if ($this->hasValidCacheItem($value, $fieldList)) {
$data[] = $value;
continue;
}
$missedData[] = $key;
}
return $this->searchResultFactory->create($data, $missedData);
} | [
"public",
"function",
"search",
"(",
"SearchCriteriaInterface",
"$",
"searchCriteria",
")",
":",
"SearchResultInterface",
"{",
"$",
"cacheItemGenerator",
"=",
"$",
"this",
"->",
"getCacheItemGenerator",
"(",
"$",
"searchCriteria",
")",
";",
"$",
"fieldList",
"=",
"$",
"searchCriteria",
"->",
"getFieldList",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"missedData",
"=",
"[",
"]",
";",
"/** @var \\Psr\\Cache\\CacheItemInterface $value */",
"foreach",
"(",
"$",
"cacheItemGenerator",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasValidCacheItem",
"(",
"$",
"value",
",",
"$",
"fieldList",
")",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"value",
";",
"continue",
";",
"}",
"$",
"missedData",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"return",
"$",
"this",
"->",
"searchResultFactory",
"->",
"create",
"(",
"$",
"data",
",",
"$",
"missedData",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Operation/Search.php#L55-L74 |
picamator/CacheManager | src/Operation/Search.php | Search.hasValidCacheItem | private function hasValidCacheItem(CacheItemInterface $cacheItem, array $fieldList) : bool
{
$data = $cacheItem->get();
if (is_null($data)) {
return false;
}
$fieldDiff = array_diff($fieldList, array_keys($data));
return !$fieldDiff;
} | php | private function hasValidCacheItem(CacheItemInterface $cacheItem, array $fieldList) : bool
{
$data = $cacheItem->get();
if (is_null($data)) {
return false;
}
$fieldDiff = array_diff($fieldList, array_keys($data));
return !$fieldDiff;
} | [
"private",
"function",
"hasValidCacheItem",
"(",
"CacheItemInterface",
"$",
"cacheItem",
",",
"array",
"$",
"fieldList",
")",
":",
"bool",
"{",
"$",
"data",
"=",
"$",
"cacheItem",
"->",
"get",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fieldDiff",
"=",
"array_diff",
"(",
"$",
"fieldList",
",",
"array_keys",
"(",
"$",
"data",
")",
")",
";",
"return",
"!",
"$",
"fieldDiff",
";",
"}"
] | Has valid cache item.
@param CacheItemInterface $cacheItem
@param array $fieldList
@return bool | [
"Has",
"valid",
"cache",
"item",
"."
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Operation/Search.php#L84-L94 |
picamator/CacheManager | src/Operation/Search.php | Search.getCacheItemGenerator | private function getCacheItemGenerator(SearchCriteriaInterface $searchCriteria)
{
try {
foreach ($searchCriteria->getIdList() as $item) {
$cacheKey = $this->keyGenerator->generate($item, $searchCriteria);
yield $item => $this->cacheItemPool->getItem($cacheKey);
}
} catch (PsrCacheInvalidArgumentException $e) {
throw new InvalidCacheKeyException($e->getMessage(), $e->getCode(), $e);
}
} | php | private function getCacheItemGenerator(SearchCriteriaInterface $searchCriteria)
{
try {
foreach ($searchCriteria->getIdList() as $item) {
$cacheKey = $this->keyGenerator->generate($item, $searchCriteria);
yield $item => $this->cacheItemPool->getItem($cacheKey);
}
} catch (PsrCacheInvalidArgumentException $e) {
throw new InvalidCacheKeyException($e->getMessage(), $e->getCode(), $e);
}
} | [
"private",
"function",
"getCacheItemGenerator",
"(",
"SearchCriteriaInterface",
"$",
"searchCriteria",
")",
"{",
"try",
"{",
"foreach",
"(",
"$",
"searchCriteria",
"->",
"getIdList",
"(",
")",
"as",
"$",
"item",
")",
"{",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"keyGenerator",
"->",
"generate",
"(",
"$",
"item",
",",
"$",
"searchCriteria",
")",
";",
"yield",
"$",
"item",
"=>",
"$",
"this",
"->",
"cacheItemPool",
"->",
"getItem",
"(",
"$",
"cacheKey",
")",
";",
"}",
"}",
"catch",
"(",
"PsrCacheInvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"InvalidCacheKeyException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Retrieve cache data generator.
@param SearchCriteriaInterface $searchCriteria
@throws InvalidCacheKeyException
@return void | [
"Retrieve",
"cache",
"data",
"generator",
"."
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Operation/Search.php#L105-L116 |
christianblos/markdown2html | src/Builder.php | Builder.build | public function build($src, $dest, Theme $theme)
{
$this->filesystem->purge($dest);
foreach ($theme->getCopyFiles() as $from => $to) {
$this->filesystem->copy($from, $dest . '/' . $to);
}
$treeItems = $this->parse(new SplFileInfo($src), $dest);
$theme->setTreeItems($treeItems);
//build all doc pages
foreach ($treeItems as $item) {
$this->exportFile($item, $theme);
}
//build index page
if (!$this->filesystem->exists($dest . '/index.html')) {
$theme->setCurrentItem('index', '');
$html = $this->renderTemplate($theme);
$this->filesystem->writeFile($dest . '/index.html', $html);
}
} | php | public function build($src, $dest, Theme $theme)
{
$this->filesystem->purge($dest);
foreach ($theme->getCopyFiles() as $from => $to) {
$this->filesystem->copy($from, $dest . '/' . $to);
}
$treeItems = $this->parse(new SplFileInfo($src), $dest);
$theme->setTreeItems($treeItems);
//build all doc pages
foreach ($treeItems as $item) {
$this->exportFile($item, $theme);
}
//build index page
if (!$this->filesystem->exists($dest . '/index.html')) {
$theme->setCurrentItem('index', '');
$html = $this->renderTemplate($theme);
$this->filesystem->writeFile($dest . '/index.html', $html);
}
} | [
"public",
"function",
"build",
"(",
"$",
"src",
",",
"$",
"dest",
",",
"Theme",
"$",
"theme",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"purge",
"(",
"$",
"dest",
")",
";",
"foreach",
"(",
"$",
"theme",
"->",
"getCopyFiles",
"(",
")",
"as",
"$",
"from",
"=>",
"$",
"to",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"copy",
"(",
"$",
"from",
",",
"$",
"dest",
".",
"'/'",
".",
"$",
"to",
")",
";",
"}",
"$",
"treeItems",
"=",
"$",
"this",
"->",
"parse",
"(",
"new",
"SplFileInfo",
"(",
"$",
"src",
")",
",",
"$",
"dest",
")",
";",
"$",
"theme",
"->",
"setTreeItems",
"(",
"$",
"treeItems",
")",
";",
"//build all doc pages",
"foreach",
"(",
"$",
"treeItems",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"exportFile",
"(",
"$",
"item",
",",
"$",
"theme",
")",
";",
"}",
"//build index page",
"if",
"(",
"!",
"$",
"this",
"->",
"filesystem",
"->",
"exists",
"(",
"$",
"dest",
".",
"'/index.html'",
")",
")",
"{",
"$",
"theme",
"->",
"setCurrentItem",
"(",
"'index'",
",",
"''",
")",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"renderTemplate",
"(",
"$",
"theme",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"writeFile",
"(",
"$",
"dest",
".",
"'/index.html'",
",",
"$",
"html",
")",
";",
"}",
"}"
] | @param string $src
@param string $dest
@param Theme $theme
@throws \RuntimeException | [
"@param",
"string",
"$src",
"@param",
"string",
"$dest",
"@param",
"Theme",
"$theme"
] | train | https://github.com/christianblos/markdown2html/blob/2ae1177d71fe313c802962dbb9226b5a90bbc65a/src/Builder.php#L37-L59 |
christianblos/markdown2html | src/Builder.php | Builder.parse | private function parse(SplFileInfo $src, $destDir, TreeItem $parent = null)
{
$files = $this->filesystem->getFilesOfDir($src->getPathname());
$items = [];
foreach ($files as $file) {
$item = new TreeItem();
if ($file->isDir()) {
$item->isDir = true;
$filenameInfo = new FilenameInfo($file->getBasename());
$item->sort = $filenameInfo->getSort();
$item->label = $filenameInfo->getLabel();
$destFilename = $filenameInfo->getFilename();
} elseif (in_array($file->getExtension(), ['md', 'markdown'], true)) {
$filenameInfo = new FilenameInfo($file->getBasename('.' . $file->getExtension()));
$item->sort = $filenameInfo->getSort();
$item->label = $filenameInfo->getLabel();
$destFilename = $filenameInfo->getFilename() . '.html';
} else {
$item->isAsset = true;
$destFilename = $file->getBasename();
}
$item->relUrl = ($parent ? $parent->relUrl . '/' : '') . $destFilename;
$item->src = $file->getPathname();
$item->dest = $destDir . '/' . $destFilename;
$item->parent = $parent;
if ($file->isDir()) {
$item->children = $this->parse($file, $item->dest, $item);
}
$items[] = $item;
}
usort($items, function (TreeItem $a, TreeItem $b) {
if ($a->sort === $b->sort) {
return 0;
}
return $a->sort > $b->sort ? 1 : -1;
});
return $items;
} | php | private function parse(SplFileInfo $src, $destDir, TreeItem $parent = null)
{
$files = $this->filesystem->getFilesOfDir($src->getPathname());
$items = [];
foreach ($files as $file) {
$item = new TreeItem();
if ($file->isDir()) {
$item->isDir = true;
$filenameInfo = new FilenameInfo($file->getBasename());
$item->sort = $filenameInfo->getSort();
$item->label = $filenameInfo->getLabel();
$destFilename = $filenameInfo->getFilename();
} elseif (in_array($file->getExtension(), ['md', 'markdown'], true)) {
$filenameInfo = new FilenameInfo($file->getBasename('.' . $file->getExtension()));
$item->sort = $filenameInfo->getSort();
$item->label = $filenameInfo->getLabel();
$destFilename = $filenameInfo->getFilename() . '.html';
} else {
$item->isAsset = true;
$destFilename = $file->getBasename();
}
$item->relUrl = ($parent ? $parent->relUrl . '/' : '') . $destFilename;
$item->src = $file->getPathname();
$item->dest = $destDir . '/' . $destFilename;
$item->parent = $parent;
if ($file->isDir()) {
$item->children = $this->parse($file, $item->dest, $item);
}
$items[] = $item;
}
usort($items, function (TreeItem $a, TreeItem $b) {
if ($a->sort === $b->sort) {
return 0;
}
return $a->sort > $b->sort ? 1 : -1;
});
return $items;
} | [
"private",
"function",
"parse",
"(",
"SplFileInfo",
"$",
"src",
",",
"$",
"destDir",
",",
"TreeItem",
"$",
"parent",
"=",
"null",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"filesystem",
"->",
"getFilesOfDir",
"(",
"$",
"src",
"->",
"getPathname",
"(",
")",
")",
";",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"item",
"=",
"new",
"TreeItem",
"(",
")",
";",
"if",
"(",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"item",
"->",
"isDir",
"=",
"true",
";",
"$",
"filenameInfo",
"=",
"new",
"FilenameInfo",
"(",
"$",
"file",
"->",
"getBasename",
"(",
")",
")",
";",
"$",
"item",
"->",
"sort",
"=",
"$",
"filenameInfo",
"->",
"getSort",
"(",
")",
";",
"$",
"item",
"->",
"label",
"=",
"$",
"filenameInfo",
"->",
"getLabel",
"(",
")",
";",
"$",
"destFilename",
"=",
"$",
"filenameInfo",
"->",
"getFilename",
"(",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"file",
"->",
"getExtension",
"(",
")",
",",
"[",
"'md'",
",",
"'markdown'",
"]",
",",
"true",
")",
")",
"{",
"$",
"filenameInfo",
"=",
"new",
"FilenameInfo",
"(",
"$",
"file",
"->",
"getBasename",
"(",
"'.'",
".",
"$",
"file",
"->",
"getExtension",
"(",
")",
")",
")",
";",
"$",
"item",
"->",
"sort",
"=",
"$",
"filenameInfo",
"->",
"getSort",
"(",
")",
";",
"$",
"item",
"->",
"label",
"=",
"$",
"filenameInfo",
"->",
"getLabel",
"(",
")",
";",
"$",
"destFilename",
"=",
"$",
"filenameInfo",
"->",
"getFilename",
"(",
")",
".",
"'.html'",
";",
"}",
"else",
"{",
"$",
"item",
"->",
"isAsset",
"=",
"true",
";",
"$",
"destFilename",
"=",
"$",
"file",
"->",
"getBasename",
"(",
")",
";",
"}",
"$",
"item",
"->",
"relUrl",
"=",
"(",
"$",
"parent",
"?",
"$",
"parent",
"->",
"relUrl",
".",
"'/'",
":",
"''",
")",
".",
"$",
"destFilename",
";",
"$",
"item",
"->",
"src",
"=",
"$",
"file",
"->",
"getPathname",
"(",
")",
";",
"$",
"item",
"->",
"dest",
"=",
"$",
"destDir",
".",
"'/'",
".",
"$",
"destFilename",
";",
"$",
"item",
"->",
"parent",
"=",
"$",
"parent",
";",
"if",
"(",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"item",
"->",
"children",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"file",
",",
"$",
"item",
"->",
"dest",
",",
"$",
"item",
")",
";",
"}",
"$",
"items",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"usort",
"(",
"$",
"items",
",",
"function",
"(",
"TreeItem",
"$",
"a",
",",
"TreeItem",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"sort",
"===",
"$",
"b",
"->",
"sort",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"a",
"->",
"sort",
">",
"$",
"b",
"->",
"sort",
"?",
"1",
":",
"-",
"1",
";",
"}",
")",
";",
"return",
"$",
"items",
";",
"}"
] | @param SplFileInfo $src
@param string $destDir
@param TreeItem $parent
@return TreeItem[] | [
"@param",
"SplFileInfo",
"$src",
"@param",
"string",
"$destDir",
"@param",
"TreeItem",
"$parent"
] | train | https://github.com/christianblos/markdown2html/blob/2ae1177d71fe313c802962dbb9226b5a90bbc65a/src/Builder.php#L68-L113 |
christianblos/markdown2html | src/Builder.php | Builder.exportFile | private function exportFile(TreeItem $item, Theme $theme)
{
if ($item->isAsset) {
$this->filesystem->copy($item->src, $item->dest);
return;
}
if ($item->isDir) {
foreach ($item->children as $child) {
$this->exportFile($child, $theme);
}
$dest = $item->dest . '.html';
// don't create index if there is a custom doc file
if ($this->filesystem->exists($dest)) {
return;
}
// write index.html for folders
$theme->setCurrentItem($item->getId(), '');
// folders for assets don't need index.html
if (!$theme->getCurrentNavItem()) {
return;
}
$html = $this->renderTemplate($theme);
$this->filesystem->writeFile($dest, $html);
return;
}
$content = $this->filesystem->readFile($item->src);
$html = $this->parsedown->text($content);
$theme->setCurrentItem($item->getId(), $html);
$html = $this->renderTemplate($theme);
$this->filesystem->writeFile($item->dest, $html);
} | php | private function exportFile(TreeItem $item, Theme $theme)
{
if ($item->isAsset) {
$this->filesystem->copy($item->src, $item->dest);
return;
}
if ($item->isDir) {
foreach ($item->children as $child) {
$this->exportFile($child, $theme);
}
$dest = $item->dest . '.html';
// don't create index if there is a custom doc file
if ($this->filesystem->exists($dest)) {
return;
}
// write index.html for folders
$theme->setCurrentItem($item->getId(), '');
// folders for assets don't need index.html
if (!$theme->getCurrentNavItem()) {
return;
}
$html = $this->renderTemplate($theme);
$this->filesystem->writeFile($dest, $html);
return;
}
$content = $this->filesystem->readFile($item->src);
$html = $this->parsedown->text($content);
$theme->setCurrentItem($item->getId(), $html);
$html = $this->renderTemplate($theme);
$this->filesystem->writeFile($item->dest, $html);
} | [
"private",
"function",
"exportFile",
"(",
"TreeItem",
"$",
"item",
",",
"Theme",
"$",
"theme",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"isAsset",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"copy",
"(",
"$",
"item",
"->",
"src",
",",
"$",
"item",
"->",
"dest",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"isDir",
")",
"{",
"foreach",
"(",
"$",
"item",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"exportFile",
"(",
"$",
"child",
",",
"$",
"theme",
")",
";",
"}",
"$",
"dest",
"=",
"$",
"item",
"->",
"dest",
".",
"'.html'",
";",
"// don't create index if there is a custom doc file",
"if",
"(",
"$",
"this",
"->",
"filesystem",
"->",
"exists",
"(",
"$",
"dest",
")",
")",
"{",
"return",
";",
"}",
"// write index.html for folders",
"$",
"theme",
"->",
"setCurrentItem",
"(",
"$",
"item",
"->",
"getId",
"(",
")",
",",
"''",
")",
";",
"// folders for assets don't need index.html",
"if",
"(",
"!",
"$",
"theme",
"->",
"getCurrentNavItem",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"html",
"=",
"$",
"this",
"->",
"renderTemplate",
"(",
"$",
"theme",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"writeFile",
"(",
"$",
"dest",
",",
"$",
"html",
")",
";",
"return",
";",
"}",
"$",
"content",
"=",
"$",
"this",
"->",
"filesystem",
"->",
"readFile",
"(",
"$",
"item",
"->",
"src",
")",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"parsedown",
"->",
"text",
"(",
"$",
"content",
")",
";",
"$",
"theme",
"->",
"setCurrentItem",
"(",
"$",
"item",
"->",
"getId",
"(",
")",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"renderTemplate",
"(",
"$",
"theme",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"writeFile",
"(",
"$",
"item",
"->",
"dest",
",",
"$",
"html",
")",
";",
"}"
] | @param TreeItem $item
@param Theme $theme
@throws \RuntimeException | [
"@param",
"TreeItem",
"$item",
"@param",
"Theme",
"$theme"
] | train | https://github.com/christianblos/markdown2html/blob/2ae1177d71fe313c802962dbb9226b5a90bbc65a/src/Builder.php#L121-L163 |
cohesion/cohesion-core | src/Structure/Factory/UtilityFactory.php | UtilityFactory.get | public function get($class) {
if ($class instanceof ReflectionClass) {
$reflection = $class;
$class = $reflection->getName();
}
if (isset($this->utils[$class])) {
return $this->utils[$class];
}
if (!isset($reflection)) {
if (!class_exists($class) && !interface_exists($class)) {
throw new InvalidClassException("$class doesn't exist");
}
$reflection = new ReflectionClass($class);
}
$config = null;
if ($this->config) {
$config = $this->config->getConfig($class);
if (!$config) {
$config = $this->config->getConfig($reflection->getShortName());
}
}
if (!$config) {
if ($reflection->isInstantiable() && $this->getConstructor($reflection)->getNumberOfRequiredParameters() == 0) {
return $reflection->newInstance();
} else {
throw new MissingConfigurationException("No configuration found for utility $class");
}
}
$driver = $config->get('driver');
if (!$driver) {
if ($reflection->isInstantiable()) {
$driver = $reflection->getName();
$driverReflection = $reflection;
} else {
throw new MissingConfigurationException("Configuration for $class must include a driver");
}
} else {
if (!class_exists($driver)) {
throw new InvalidClassException("$class driver $driver doesn't exist");
}
$driverReflection = new ReflectionClass($driver);
if (!$driverReflection->isInstantiable()) {
throw new InvalidClassException("$class driver $driver is not instantiable");
}
}
$utility = $this->getClass($driverReflection, $config);
$this->utils[$class] = $utility;
return $utility;
} | php | public function get($class) {
if ($class instanceof ReflectionClass) {
$reflection = $class;
$class = $reflection->getName();
}
if (isset($this->utils[$class])) {
return $this->utils[$class];
}
if (!isset($reflection)) {
if (!class_exists($class) && !interface_exists($class)) {
throw new InvalidClassException("$class doesn't exist");
}
$reflection = new ReflectionClass($class);
}
$config = null;
if ($this->config) {
$config = $this->config->getConfig($class);
if (!$config) {
$config = $this->config->getConfig($reflection->getShortName());
}
}
if (!$config) {
if ($reflection->isInstantiable() && $this->getConstructor($reflection)->getNumberOfRequiredParameters() == 0) {
return $reflection->newInstance();
} else {
throw new MissingConfigurationException("No configuration found for utility $class");
}
}
$driver = $config->get('driver');
if (!$driver) {
if ($reflection->isInstantiable()) {
$driver = $reflection->getName();
$driverReflection = $reflection;
} else {
throw new MissingConfigurationException("Configuration for $class must include a driver");
}
} else {
if (!class_exists($driver)) {
throw new InvalidClassException("$class driver $driver doesn't exist");
}
$driverReflection = new ReflectionClass($driver);
if (!$driverReflection->isInstantiable()) {
throw new InvalidClassException("$class driver $driver is not instantiable");
}
}
$utility = $this->getClass($driverReflection, $config);
$this->utils[$class] = $utility;
return $utility;
} | [
"public",
"function",
"get",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"class",
"instanceof",
"ReflectionClass",
")",
"{",
"$",
"reflection",
"=",
"$",
"class",
";",
"$",
"class",
"=",
"$",
"reflection",
"->",
"getName",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"utils",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"utils",
"[",
"$",
"class",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"reflection",
")",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
"&&",
"!",
"interface_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"InvalidClassException",
"(",
"\"$class doesn't exist\"",
")",
";",
"}",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"}",
"$",
"config",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"config",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"getConfig",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"$",
"config",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
"->",
"getConfig",
"(",
"$",
"reflection",
"->",
"getShortName",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"config",
")",
"{",
"if",
"(",
"$",
"reflection",
"->",
"isInstantiable",
"(",
")",
"&&",
"$",
"this",
"->",
"getConstructor",
"(",
"$",
"reflection",
")",
"->",
"getNumberOfRequiredParameters",
"(",
")",
"==",
"0",
")",
"{",
"return",
"$",
"reflection",
"->",
"newInstance",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"MissingConfigurationException",
"(",
"\"No configuration found for utility $class\"",
")",
";",
"}",
"}",
"$",
"driver",
"=",
"$",
"config",
"->",
"get",
"(",
"'driver'",
")",
";",
"if",
"(",
"!",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"reflection",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"$",
"driver",
"=",
"$",
"reflection",
"->",
"getName",
"(",
")",
";",
"$",
"driverReflection",
"=",
"$",
"reflection",
";",
"}",
"else",
"{",
"throw",
"new",
"MissingConfigurationException",
"(",
"\"Configuration for $class must include a driver\"",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"driver",
")",
")",
"{",
"throw",
"new",
"InvalidClassException",
"(",
"\"$class driver $driver doesn't exist\"",
")",
";",
"}",
"$",
"driverReflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"driver",
")",
";",
"if",
"(",
"!",
"$",
"driverReflection",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidClassException",
"(",
"\"$class driver $driver is not instantiable\"",
")",
";",
"}",
"}",
"$",
"utility",
"=",
"$",
"this",
"->",
"getClass",
"(",
"$",
"driverReflection",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"utils",
"[",
"$",
"class",
"]",
"=",
"$",
"utility",
";",
"return",
"$",
"utility",
";",
"}"
] | Get a utility class
@param mixed $class Either a string of the class name or an instance of a \ReflectionClass representing the utility to get
@return mixed The utility matching the given class
@throws InvalidClassException if either the utility class or the utility driver class doesn't exist
@throws MissingConfigurationException if the utility requires configuration and it doesn't have any, or one of the required variable is missing form the configuration | [
"Get",
"a",
"utility",
"class"
] | train | https://github.com/cohesion/cohesion-core/blob/c6352aef7336e06285f0943da68235dc45523998/src/Structure/Factory/UtilityFactory.php#L25-L74 |
lmammino/e-foundation | src/Cart/Model/Cart.php | Cart.incrementExpiresAt | public function incrementExpiresAt(\DateInterval $interval = null)
{
if (null === $this->expiresAt) {
$this->expiresAt = new \DateTime();
}
if (null === $interval) {
$interval = new \DateInterval('PT3H');
}
$this->expiresAt->add($interval);
return $this;
} | php | public function incrementExpiresAt(\DateInterval $interval = null)
{
if (null === $this->expiresAt) {
$this->expiresAt = new \DateTime();
}
if (null === $interval) {
$interval = new \DateInterval('PT3H');
}
$this->expiresAt->add($interval);
return $this;
} | [
"public",
"function",
"incrementExpiresAt",
"(",
"\\",
"DateInterval",
"$",
"interval",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"expiresAt",
")",
"{",
"$",
"this",
"->",
"expiresAt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"interval",
")",
"{",
"$",
"interval",
"=",
"new",
"\\",
"DateInterval",
"(",
"'PT3H'",
")",
";",
"}",
"$",
"this",
"->",
"expiresAt",
"->",
"add",
"(",
"$",
"interval",
")",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Cart/Model/Cart.php#L126-L139 |
lmammino/e-foundation | src/Cart/Model/Cart.php | Cart.isExpired | public function isExpired()
{
if (null === $this->expiresAt) {
return false;
}
$now = new \DateTime();
return $this->expiresAt < $now;
} | php | public function isExpired()
{
if (null === $this->expiresAt) {
return false;
}
$now = new \DateTime();
return $this->expiresAt < $now;
} | [
"public",
"function",
"isExpired",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"expiresAt",
")",
"{",
"return",
"false",
";",
"}",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"return",
"$",
"this",
"->",
"expiresAt",
"<",
"$",
"now",
";",
"}"
] | Checks whether the cart is expired or not.
@return Boolean | [
"Checks",
"whether",
"the",
"cart",
"is",
"expired",
"or",
"not",
"."
] | train | https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Cart/Model/Cart.php#L146-L155 |
titon/db | src/Titon/Db/Query/BindingAware.php | BindingAware.addBinding | public function addBinding($field, $values) {
if (!is_array($values)) {
$values = [$values];
}
foreach ($values as $value) {
if ($value instanceof Predicate) {
$this->resolvePredicate($value);
} else if ($value instanceof SubQuery) {
$this->resolveSubQuery($value);
} else {
$this->_bindings[] = [
'field' => $field,
'value' => $value
];
}
}
return $this;
} | php | public function addBinding($field, $values) {
if (!is_array($values)) {
$values = [$values];
}
foreach ($values as $value) {
if ($value instanceof Predicate) {
$this->resolvePredicate($value);
} else if ($value instanceof SubQuery) {
$this->resolveSubQuery($value);
} else {
$this->_bindings[] = [
'field' => $field,
'value' => $value
];
}
}
return $this;
} | [
"public",
"function",
"addBinding",
"(",
"$",
"field",
",",
"$",
"values",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"[",
"$",
"values",
"]",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Predicate",
")",
"{",
"$",
"this",
"->",
"resolvePredicate",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"instanceof",
"SubQuery",
")",
"{",
"$",
"this",
"->",
"resolveSubQuery",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_bindings",
"[",
"]",
"=",
"[",
"'field'",
"=>",
"$",
"field",
",",
"'value'",
"=>",
"$",
"value",
"]",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a value to use in SQL parameter binding.
@param string $field
@param mixed $values
@return $this | [
"Add",
"a",
"value",
"to",
"use",
"in",
"SQL",
"parameter",
"binding",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Query/BindingAware.php#L32-L53 |
titon/db | src/Titon/Db/Query/BindingAware.php | BindingAware.resolvePredicate | public function resolvePredicate(Predicate $predicate) {
$this->_bindings = array_merge($this->_bindings, $predicate->getBindings());
return $this;
} | php | public function resolvePredicate(Predicate $predicate) {
$this->_bindings = array_merge($this->_bindings, $predicate->getBindings());
return $this;
} | [
"public",
"function",
"resolvePredicate",
"(",
"Predicate",
"$",
"predicate",
")",
"{",
"$",
"this",
"->",
"_bindings",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_bindings",
",",
"$",
"predicate",
"->",
"getBindings",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Merge an external predicates bindings with the current bindings.
@param \Titon\Db\Query\Predicate $predicate
@return $this | [
"Merge",
"an",
"external",
"predicates",
"bindings",
"with",
"the",
"current",
"bindings",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Query/BindingAware.php#L70-L74 |
titon/db | src/Titon/Db/Query/BindingAware.php | BindingAware.resolveSubQuery | public function resolveSubQuery(SubQuery $query) {
foreach ($query->getGroupedBindings() as $bindings) {
$this->_bindings = array_merge($this->_bindings, $bindings);
}
return $this;
} | php | public function resolveSubQuery(SubQuery $query) {
foreach ($query->getGroupedBindings() as $bindings) {
$this->_bindings = array_merge($this->_bindings, $bindings);
}
return $this;
} | [
"public",
"function",
"resolveSubQuery",
"(",
"SubQuery",
"$",
"query",
")",
"{",
"foreach",
"(",
"$",
"query",
"->",
"getGroupedBindings",
"(",
")",
"as",
"$",
"bindings",
")",
"{",
"$",
"this",
"->",
"_bindings",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_bindings",
",",
"$",
"bindings",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Merge an external sub-queries bindings with the current bindings.
@param \Titon\Db\Query\SubQuery $query
@return $this | [
"Merge",
"an",
"external",
"sub",
"-",
"queries",
"bindings",
"with",
"the",
"current",
"bindings",
"."
] | train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Query/BindingAware.php#L82-L88 |
simple-php-mvc/simple-php-mvc | src/MVC/Injection/Extension.php | Extension.getRootDirModule | public function getRootDirModule()
{
$r = new \ReflectionObject($this);
$injectionDir = str_replace('\\', '/', dirname($r->getFileName()));
return $injectionDir . '/..';
} | php | public function getRootDirModule()
{
$r = new \ReflectionObject($this);
$injectionDir = str_replace('\\', '/', dirname($r->getFileName()));
return $injectionDir . '/..';
} | [
"public",
"function",
"getRootDirModule",
"(",
")",
"{",
"$",
"r",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"this",
")",
";",
"$",
"injectionDir",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"dirname",
"(",
"$",
"r",
"->",
"getFileName",
"(",
")",
")",
")",
";",
"return",
"$",
"injectionDir",
".",
"'/..'",
";",
"}"
] | Get Root Dir Module
@return string Root Dir Module | [
"Get",
"Root",
"Dir",
"Module"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Injection/Extension.php#L74-L79 |
simple-php-mvc/simple-php-mvc | src/MVC/Injection/Extension.php | Extension.loadRoutes | public function loadRoutes()
{
$routesJsonFile = $this->configDir . '/routes.json';
$routesPhpFile = $this->configDir . '/routes.php';
if (file_exists($this->resourcesDir) && file_exists($this->configDir)) {
if (file_exists($routesJsonFile))
return json_decode(file_get_contents($routesJsonFile), true);
elseif (file_exists($routesPhpFile))
return require_once $routesPhpFile;
} else {
return array();
}
} | php | public function loadRoutes()
{
$routesJsonFile = $this->configDir . '/routes.json';
$routesPhpFile = $this->configDir . '/routes.php';
if (file_exists($this->resourcesDir) && file_exists($this->configDir)) {
if (file_exists($routesJsonFile))
return json_decode(file_get_contents($routesJsonFile), true);
elseif (file_exists($routesPhpFile))
return require_once $routesPhpFile;
} else {
return array();
}
} | [
"public",
"function",
"loadRoutes",
"(",
")",
"{",
"$",
"routesJsonFile",
"=",
"$",
"this",
"->",
"configDir",
".",
"'/routes.json'",
";",
"$",
"routesPhpFile",
"=",
"$",
"this",
"->",
"configDir",
".",
"'/routes.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"resourcesDir",
")",
"&&",
"file_exists",
"(",
"$",
"this",
"->",
"configDir",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"routesJsonFile",
")",
")",
"return",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"routesJsonFile",
")",
",",
"true",
")",
";",
"elseif",
"(",
"file_exists",
"(",
"$",
"routesPhpFile",
")",
")",
"return",
"require_once",
"$",
"routesPhpFile",
";",
"}",
"else",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}"
] | Load routes of the Module
@return array | [
"Load",
"routes",
"of",
"the",
"Module"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Injection/Extension.php#L86-L99 |
miisieq/InfaktClient | src/Infakt/Mapper/ReverseMapperTrait.php | ReverseMapperTrait.reverseMapPrice | public function reverseMapPrice(?float $price): ?int
{
if (null === $price) {
return null;
}
if (0.00 === $price) {
return 0;
}
return (int) str_replace('.', '', number_format($price, 2, '.', ''));
} | php | public function reverseMapPrice(?float $price): ?int
{
if (null === $price) {
return null;
}
if (0.00 === $price) {
return 0;
}
return (int) str_replace('.', '', number_format($price, 2, '.', ''));
} | [
"public",
"function",
"reverseMapPrice",
"(",
"?",
"float",
"$",
"price",
")",
":",
"?",
"int",
"{",
"if",
"(",
"null",
"===",
"$",
"price",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"0.00",
"===",
"$",
"price",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"int",
")",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"number_format",
"(",
"$",
"price",
",",
"2",
",",
"'.'",
",",
"''",
")",
")",
";",
"}"
] | Maps price to string.
@param float|null $price
@return int|null | [
"Maps",
"price",
"to",
"string",
"."
] | train | https://github.com/miisieq/InfaktClient/blob/5f0ae58c7be32580f3c92c2a7e7a7808d83d4e81/src/Infakt/Mapper/ReverseMapperTrait.php#L16-L27 |
CakeCMS/Core | src/Notify/Email.php | Email.send | public function send($subject, $content, $to, $fromName = '', $fromEmail = '')
{
$mail = new CakeEmail();
$fromName = ($fromName !== '') ? $fromName : $this->_fromName;
$fromEmail = ($fromEmail !== '') ? $fromEmail : $this->_fromEmail;
$transport = new MailTransport();
return $mail
->setTransport($transport)
->setTemplate($this->_tpl)
->setEmailFormat($this->_format)
->setFrom($fromEmail, $fromName)
->setTo($to)
->setSubject($subject)
->setViewVars(['page_title' => $subject])
->send($content);
} | php | public function send($subject, $content, $to, $fromName = '', $fromEmail = '')
{
$mail = new CakeEmail();
$fromName = ($fromName !== '') ? $fromName : $this->_fromName;
$fromEmail = ($fromEmail !== '') ? $fromEmail : $this->_fromEmail;
$transport = new MailTransport();
return $mail
->setTransport($transport)
->setTemplate($this->_tpl)
->setEmailFormat($this->_format)
->setFrom($fromEmail, $fromName)
->setTo($to)
->setSubject($subject)
->setViewVars(['page_title' => $subject])
->send($content);
} | [
"public",
"function",
"send",
"(",
"$",
"subject",
",",
"$",
"content",
",",
"$",
"to",
",",
"$",
"fromName",
"=",
"''",
",",
"$",
"fromEmail",
"=",
"''",
")",
"{",
"$",
"mail",
"=",
"new",
"CakeEmail",
"(",
")",
";",
"$",
"fromName",
"=",
"(",
"$",
"fromName",
"!==",
"''",
")",
"?",
"$",
"fromName",
":",
"$",
"this",
"->",
"_fromName",
";",
"$",
"fromEmail",
"=",
"(",
"$",
"fromEmail",
"!==",
"''",
")",
"?",
"$",
"fromEmail",
":",
"$",
"this",
"->",
"_fromEmail",
";",
"$",
"transport",
"=",
"new",
"MailTransport",
"(",
")",
";",
"return",
"$",
"mail",
"->",
"setTransport",
"(",
"$",
"transport",
")",
"->",
"setTemplate",
"(",
"$",
"this",
"->",
"_tpl",
")",
"->",
"setEmailFormat",
"(",
"$",
"this",
"->",
"_format",
")",
"->",
"setFrom",
"(",
"$",
"fromEmail",
",",
"$",
"fromName",
")",
"->",
"setTo",
"(",
"$",
"to",
")",
"->",
"setSubject",
"(",
"$",
"subject",
")",
"->",
"setViewVars",
"(",
"[",
"'page_title'",
"=>",
"$",
"subject",
"]",
")",
"->",
"send",
"(",
"$",
"content",
")",
";",
"}"
] | Send message method.
@param string $subject
@param string $content
@param string|array $to
@param string $fromName
@param string $fromEmail
@return array | [
"Send",
"message",
"method",
"."
] | train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/Notify/Email.php#L95-L111 |
factorio-item-browser/export-data | src/Entity/Mod.php | Mod.setDependencies | public function setDependencies(array $dependencies)
{
$this->dependencies = array_values(array_filter($dependencies, function ($dependency): bool {
return $dependency instanceof Dependency;
}));
return $this;
} | php | public function setDependencies(array $dependencies)
{
$this->dependencies = array_values(array_filter($dependencies, function ($dependency): bool {
return $dependency instanceof Dependency;
}));
return $this;
} | [
"public",
"function",
"setDependencies",
"(",
"array",
"$",
"dependencies",
")",
"{",
"$",
"this",
"->",
"dependencies",
"=",
"array_values",
"(",
"array_filter",
"(",
"$",
"dependencies",
",",
"function",
"(",
"$",
"dependency",
")",
":",
"bool",
"{",
"return",
"$",
"dependency",
"instanceof",
"Dependency",
";",
"}",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the dependencies of the mod.
@param array|Dependency[] $dependencies
@return $this Implementing fluent interface. | [
"Sets",
"the",
"dependencies",
"of",
"the",
"mod",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Mod.php#L258-L264 |
factorio-item-browser/export-data | src/Entity/Mod.php | Mod.writeData | public function writeData(): array
{
$dataBuilder = new DataBuilder();
$dataBuilder->setString('n', $this->name, '')
->setArray('t', $this->titles->writeData(), null, [])
->setArray('d', $this->descriptions->writeData(), null, [])
->setString('a', $this->author, '')
->setString('v', $this->version, '')
->setString('f', $this->fileName, '')
->setString('i', $this->directoryName, '')
->setArray('e', $this->dependencies, function (Dependency $dependency): array {
return $dependency->writeData();
}, [])
->setString('h', $this->thumbnailHash, '')
->setString('s', $this->checksum, '')
->setInteger('o', $this->order, 0)
->setArray('c', array_values(array_unique($this->combinationHashes)), 'strval', []);
return $dataBuilder->getData();
} | php | public function writeData(): array
{
$dataBuilder = new DataBuilder();
$dataBuilder->setString('n', $this->name, '')
->setArray('t', $this->titles->writeData(), null, [])
->setArray('d', $this->descriptions->writeData(), null, [])
->setString('a', $this->author, '')
->setString('v', $this->version, '')
->setString('f', $this->fileName, '')
->setString('i', $this->directoryName, '')
->setArray('e', $this->dependencies, function (Dependency $dependency): array {
return $dependency->writeData();
}, [])
->setString('h', $this->thumbnailHash, '')
->setString('s', $this->checksum, '')
->setInteger('o', $this->order, 0)
->setArray('c', array_values(array_unique($this->combinationHashes)), 'strval', []);
return $dataBuilder->getData();
} | [
"public",
"function",
"writeData",
"(",
")",
":",
"array",
"{",
"$",
"dataBuilder",
"=",
"new",
"DataBuilder",
"(",
")",
";",
"$",
"dataBuilder",
"->",
"setString",
"(",
"'n'",
",",
"$",
"this",
"->",
"name",
",",
"''",
")",
"->",
"setArray",
"(",
"'t'",
",",
"$",
"this",
"->",
"titles",
"->",
"writeData",
"(",
")",
",",
"null",
",",
"[",
"]",
")",
"->",
"setArray",
"(",
"'d'",
",",
"$",
"this",
"->",
"descriptions",
"->",
"writeData",
"(",
")",
",",
"null",
",",
"[",
"]",
")",
"->",
"setString",
"(",
"'a'",
",",
"$",
"this",
"->",
"author",
",",
"''",
")",
"->",
"setString",
"(",
"'v'",
",",
"$",
"this",
"->",
"version",
",",
"''",
")",
"->",
"setString",
"(",
"'f'",
",",
"$",
"this",
"->",
"fileName",
",",
"''",
")",
"->",
"setString",
"(",
"'i'",
",",
"$",
"this",
"->",
"directoryName",
",",
"''",
")",
"->",
"setArray",
"(",
"'e'",
",",
"$",
"this",
"->",
"dependencies",
",",
"function",
"(",
"Dependency",
"$",
"dependency",
")",
":",
"array",
"{",
"return",
"$",
"dependency",
"->",
"writeData",
"(",
")",
";",
"}",
",",
"[",
"]",
")",
"->",
"setString",
"(",
"'h'",
",",
"$",
"this",
"->",
"thumbnailHash",
",",
"''",
")",
"->",
"setString",
"(",
"'s'",
",",
"$",
"this",
"->",
"checksum",
",",
"''",
")",
"->",
"setInteger",
"(",
"'o'",
",",
"$",
"this",
"->",
"order",
",",
"0",
")",
"->",
"setArray",
"(",
"'c'",
",",
"array_values",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"combinationHashes",
")",
")",
",",
"'strval'",
",",
"[",
"]",
")",
";",
"return",
"$",
"dataBuilder",
"->",
"getData",
"(",
")",
";",
"}"
] | Writes the entity data to an array.
@return array | [
"Writes",
"the",
"entity",
"data",
"to",
"an",
"array",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Mod.php#L383-L401 |
factorio-item-browser/export-data | src/Entity/Mod.php | Mod.readData | public function readData(DataContainer $data)
{
$this->name = $data->getString('n', '');
$this->titles->readData($data->getObject('t'));
$this->descriptions->readData($data->getObject('d'));
$this->author = $data->getString('a', '');
$this->version = $data->getString('v', '');
$this->fileName = $data->getString('f', '');
$this->directoryName = $data->getString('i', '');
$this->dependencies = array_map(function (DataContainer $data): Dependency {
return (new Dependency())->readData($data);
}, $data->getObjectArray('e'));
$this->thumbnailHash = $data->getString('h', '');
$this->checksum = $data->getString('s', '');
$this->order = $data->getInteger('o', 0);
$this->combinationHashes = array_map('strval', $data->getArray('c'));
return $this;
} | php | public function readData(DataContainer $data)
{
$this->name = $data->getString('n', '');
$this->titles->readData($data->getObject('t'));
$this->descriptions->readData($data->getObject('d'));
$this->author = $data->getString('a', '');
$this->version = $data->getString('v', '');
$this->fileName = $data->getString('f', '');
$this->directoryName = $data->getString('i', '');
$this->dependencies = array_map(function (DataContainer $data): Dependency {
return (new Dependency())->readData($data);
}, $data->getObjectArray('e'));
$this->thumbnailHash = $data->getString('h', '');
$this->checksum = $data->getString('s', '');
$this->order = $data->getInteger('o', 0);
$this->combinationHashes = array_map('strval', $data->getArray('c'));
return $this;
} | [
"public",
"function",
"readData",
"(",
"DataContainer",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"data",
"->",
"getString",
"(",
"'n'",
",",
"''",
")",
";",
"$",
"this",
"->",
"titles",
"->",
"readData",
"(",
"$",
"data",
"->",
"getObject",
"(",
"'t'",
")",
")",
";",
"$",
"this",
"->",
"descriptions",
"->",
"readData",
"(",
"$",
"data",
"->",
"getObject",
"(",
"'d'",
")",
")",
";",
"$",
"this",
"->",
"author",
"=",
"$",
"data",
"->",
"getString",
"(",
"'a'",
",",
"''",
")",
";",
"$",
"this",
"->",
"version",
"=",
"$",
"data",
"->",
"getString",
"(",
"'v'",
",",
"''",
")",
";",
"$",
"this",
"->",
"fileName",
"=",
"$",
"data",
"->",
"getString",
"(",
"'f'",
",",
"''",
")",
";",
"$",
"this",
"->",
"directoryName",
"=",
"$",
"data",
"->",
"getString",
"(",
"'i'",
",",
"''",
")",
";",
"$",
"this",
"->",
"dependencies",
"=",
"array_map",
"(",
"function",
"(",
"DataContainer",
"$",
"data",
")",
":",
"Dependency",
"{",
"return",
"(",
"new",
"Dependency",
"(",
")",
")",
"->",
"readData",
"(",
"$",
"data",
")",
";",
"}",
",",
"$",
"data",
"->",
"getObjectArray",
"(",
"'e'",
")",
")",
";",
"$",
"this",
"->",
"thumbnailHash",
"=",
"$",
"data",
"->",
"getString",
"(",
"'h'",
",",
"''",
")",
";",
"$",
"this",
"->",
"checksum",
"=",
"$",
"data",
"->",
"getString",
"(",
"'s'",
",",
"''",
")",
";",
"$",
"this",
"->",
"order",
"=",
"$",
"data",
"->",
"getInteger",
"(",
"'o'",
",",
"0",
")",
";",
"$",
"this",
"->",
"combinationHashes",
"=",
"array_map",
"(",
"'strval'",
",",
"$",
"data",
"->",
"getArray",
"(",
"'c'",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Reads the entity data.
@param DataContainer $data
@return $this | [
"Reads",
"the",
"entity",
"data",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Mod.php#L408-L425 |
factorio-item-browser/export-data | src/Entity/Mod.php | Mod.calculateHash | public function calculateHash(): string
{
return EntityUtils::calculateHashOfArray([
$this->name,
$this->titles->calculateHash(),
$this->descriptions->calculateHash(),
$this->author,
$this->version,
$this->fileName,
$this->directoryName,
array_map(function (Dependency $dependency): string {
return $dependency->calculateHash();
}, $this->dependencies),
$this->thumbnailHash,
$this->checksum,
$this->order,
]);
} | php | public function calculateHash(): string
{
return EntityUtils::calculateHashOfArray([
$this->name,
$this->titles->calculateHash(),
$this->descriptions->calculateHash(),
$this->author,
$this->version,
$this->fileName,
$this->directoryName,
array_map(function (Dependency $dependency): string {
return $dependency->calculateHash();
}, $this->dependencies),
$this->thumbnailHash,
$this->checksum,
$this->order,
]);
} | [
"public",
"function",
"calculateHash",
"(",
")",
":",
"string",
"{",
"return",
"EntityUtils",
"::",
"calculateHashOfArray",
"(",
"[",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"titles",
"->",
"calculateHash",
"(",
")",
",",
"$",
"this",
"->",
"descriptions",
"->",
"calculateHash",
"(",
")",
",",
"$",
"this",
"->",
"author",
",",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"fileName",
",",
"$",
"this",
"->",
"directoryName",
",",
"array_map",
"(",
"function",
"(",
"Dependency",
"$",
"dependency",
")",
":",
"string",
"{",
"return",
"$",
"dependency",
"->",
"calculateHash",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"dependencies",
")",
",",
"$",
"this",
"->",
"thumbnailHash",
",",
"$",
"this",
"->",
"checksum",
",",
"$",
"this",
"->",
"order",
",",
"]",
")",
";",
"}"
] | Calculates a hash value representing the entity.
@return string | [
"Calculates",
"a",
"hash",
"value",
"representing",
"the",
"entity",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Mod.php#L431-L448 |
xinix-technology/norm | src/Norm/Connection/BonoConnection.php | BonoConnection.restGet | public function restGet($cursor) {
if ($cursor instanceof Cursor) {
$name = $cursor->getCollection()->getName();
$criteria = $cursor->getCriteria();
$limit = $cursor->limit();
$skip = $cursor->skip();
$sorts = $cursor->sort();
$query = array();
foreach ($criteria as $key => $value) {
$query[$key] = $value;
}
if ($limit) {
$query['!limit'] = $limit;
}
if ($skip) {
$query['!skip'] = $skip;
}
if (!empty($sorts)) {
foreach ($sorts as $key => $value) {
$query["!sort[$key]"] = $value;
}
}
$qs = array();
foreach ($query as $key => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$qs[] = '!'.$key.'='.$v;
}
} else {
$qs[] = $key.'='.$value;
}
}
if ($qs) {
$qs = '?'.implode('&', $qs);
} else {
$qs = '';
}
$url = $this->option('baseUrl').'/'.$name.'.json'.$qs;
$client = new Client();
$response = $client->get($url)->send();
return json_decode($response->getBody(true), true);
} else {
throw new Exception('Unimplemented yet!');
}
} | php | public function restGet($cursor) {
if ($cursor instanceof Cursor) {
$name = $cursor->getCollection()->getName();
$criteria = $cursor->getCriteria();
$limit = $cursor->limit();
$skip = $cursor->skip();
$sorts = $cursor->sort();
$query = array();
foreach ($criteria as $key => $value) {
$query[$key] = $value;
}
if ($limit) {
$query['!limit'] = $limit;
}
if ($skip) {
$query['!skip'] = $skip;
}
if (!empty($sorts)) {
foreach ($sorts as $key => $value) {
$query["!sort[$key]"] = $value;
}
}
$qs = array();
foreach ($query as $key => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$qs[] = '!'.$key.'='.$v;
}
} else {
$qs[] = $key.'='.$value;
}
}
if ($qs) {
$qs = '?'.implode('&', $qs);
} else {
$qs = '';
}
$url = $this->option('baseUrl').'/'.$name.'.json'.$qs;
$client = new Client();
$response = $client->get($url)->send();
return json_decode($response->getBody(true), true);
} else {
throw new Exception('Unimplemented yet!');
}
} | [
"public",
"function",
"restGet",
"(",
"$",
"cursor",
")",
"{",
"if",
"(",
"$",
"cursor",
"instanceof",
"Cursor",
")",
"{",
"$",
"name",
"=",
"$",
"cursor",
"->",
"getCollection",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"criteria",
"=",
"$",
"cursor",
"->",
"getCriteria",
"(",
")",
";",
"$",
"limit",
"=",
"$",
"cursor",
"->",
"limit",
"(",
")",
";",
"$",
"skip",
"=",
"$",
"cursor",
"->",
"skip",
"(",
")",
";",
"$",
"sorts",
"=",
"$",
"cursor",
"->",
"sort",
"(",
")",
";",
"$",
"query",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"criteria",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"query",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"limit",
")",
"{",
"$",
"query",
"[",
"'!limit'",
"]",
"=",
"$",
"limit",
";",
"}",
"if",
"(",
"$",
"skip",
")",
"{",
"$",
"query",
"[",
"'!skip'",
"]",
"=",
"$",
"skip",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"sorts",
")",
")",
"{",
"foreach",
"(",
"$",
"sorts",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"query",
"[",
"\"!sort[$key]\"",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"qs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"query",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"qs",
"[",
"]",
"=",
"'!'",
".",
"$",
"key",
".",
"'='",
".",
"$",
"v",
";",
"}",
"}",
"else",
"{",
"$",
"qs",
"[",
"]",
"=",
"$",
"key",
".",
"'='",
".",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"$",
"qs",
")",
"{",
"$",
"qs",
"=",
"'?'",
".",
"implode",
"(",
"'&'",
",",
"$",
"qs",
")",
";",
"}",
"else",
"{",
"$",
"qs",
"=",
"''",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"option",
"(",
"'baseUrl'",
")",
".",
"'/'",
".",
"$",
"name",
".",
"'.json'",
".",
"$",
"qs",
";",
"$",
"client",
"=",
"new",
"Client",
"(",
")",
";",
"$",
"response",
"=",
"$",
"client",
"->",
"get",
"(",
"$",
"url",
")",
"->",
"send",
"(",
")",
";",
"return",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
"true",
")",
",",
"true",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Unimplemented yet!'",
")",
";",
"}",
"}"
] | Get data from rest service.
@param \Norm\Cursor $cursor
@throws \Exception
@return array | [
"Get",
"data",
"from",
"rest",
"service",
"."
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Connection/BonoConnection.php#L52-L107 |
crypto-markets/common | src/Common/Gateway.php | Gateway.createRequest | public function createRequest($class, array $params = [])
{
$instance = new $class($this->getHttpClient());
return $instance->configure(array_replace($this->getOptions(), $params));
} | php | public function createRequest($class, array $params = [])
{
$instance = new $class($this->getHttpClient());
return $instance->configure(array_replace($this->getOptions(), $params));
} | [
"public",
"function",
"createRequest",
"(",
"$",
"class",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"getHttpClient",
"(",
")",
")",
";",
"return",
"$",
"instance",
"->",
"configure",
"(",
"array_replace",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
",",
"$",
"params",
")",
")",
";",
"}"
] | Create a new request object.
@param string $class
@param array $params
@return \CryptoMarkets\Common\Http\Request | [
"Create",
"a",
"new",
"request",
"object",
"."
] | train | https://github.com/crypto-markets/common/blob/206b1d9b88502d3fb73cef1323cd086156d3e633/src/Common/Gateway.php#L89-L94 |
picamator/CacheManager | src/Operation/Save.php | Save.save | public function save(SearchCriteriaInterface $searchCriteria, array $data) : bool
{
// validate
$idName = $searchCriteria->getIdName();
if (!$this->isValid($idName, $data)) {
throw new InvalidArgumentException(
sprintf('Invalid data "%s". Data should be array of entities with identifier "%s".', serialize($data), $idName)
);
}
// save
foreach ($data as $item) {
$cacheKey = $this->keyGenerator->generate($item[$idName], $searchCriteria);
$cacheItem = $this->cacheItemFactory->create($cacheKey, $item);
$this->cacheItemPool->saveDeferred($cacheItem);
}
return $this->cacheItemPool->commit();
} | php | public function save(SearchCriteriaInterface $searchCriteria, array $data) : bool
{
// validate
$idName = $searchCriteria->getIdName();
if (!$this->isValid($idName, $data)) {
throw new InvalidArgumentException(
sprintf('Invalid data "%s". Data should be array of entities with identifier "%s".', serialize($data), $idName)
);
}
// save
foreach ($data as $item) {
$cacheKey = $this->keyGenerator->generate($item[$idName], $searchCriteria);
$cacheItem = $this->cacheItemFactory->create($cacheKey, $item);
$this->cacheItemPool->saveDeferred($cacheItem);
}
return $this->cacheItemPool->commit();
} | [
"public",
"function",
"save",
"(",
"SearchCriteriaInterface",
"$",
"searchCriteria",
",",
"array",
"$",
"data",
")",
":",
"bool",
"{",
"// validate",
"$",
"idName",
"=",
"$",
"searchCriteria",
"->",
"getIdName",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isValid",
"(",
"$",
"idName",
",",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid data \"%s\". Data should be array of entities with identifier \"%s\".'",
",",
"serialize",
"(",
"$",
"data",
")",
",",
"$",
"idName",
")",
")",
";",
"}",
"// save",
"foreach",
"(",
"$",
"data",
"as",
"$",
"item",
")",
"{",
"$",
"cacheKey",
"=",
"$",
"this",
"->",
"keyGenerator",
"->",
"generate",
"(",
"$",
"item",
"[",
"$",
"idName",
"]",
",",
"$",
"searchCriteria",
")",
";",
"$",
"cacheItem",
"=",
"$",
"this",
"->",
"cacheItemFactory",
"->",
"create",
"(",
"$",
"cacheKey",
",",
"$",
"item",
")",
";",
"$",
"this",
"->",
"cacheItemPool",
"->",
"saveDeferred",
"(",
"$",
"cacheItem",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cacheItemPool",
"->",
"commit",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Operation/Save.php#L52-L71 |
picamator/CacheManager | src/Operation/Save.php | Save.isValid | private function isValid(string $idName, array $data)
{
foreach ($data as $item) {
if (!is_array($item) || !array_key_exists($idName, $item)) {
return false;
}
}
return true;
} | php | private function isValid(string $idName, array $data)
{
foreach ($data as $item) {
if (!is_array($item) || !array_key_exists($idName, $item)) {
return false;
}
}
return true;
} | [
"private",
"function",
"isValid",
"(",
"string",
"$",
"idName",
",",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"item",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"idName",
",",
"$",
"item",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validate data structure: array of arrays with presented correct id.
@param string $idName
@param array $data
@return bool _true_ for valid and _false_ otherwise | [
"Validate",
"data",
"structure",
":",
"array",
"of",
"arrays",
"with",
"presented",
"correct",
"id",
"."
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Operation/Save.php#L81-L90 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addInstallMacroblock | public function addInstallMacroblock($name, $file, $url)
{
$macroblockElement = new InstallMacroblock($name, $file, $url);
return $this->addElement($macroblockElement);
} | php | public function addInstallMacroblock($name, $file, $url)
{
$macroblockElement = new InstallMacroblock($name, $file, $url);
return $this->addElement($macroblockElement);
} | [
"public",
"function",
"addInstallMacroblock",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
"{",
"$",
"macroblockElement",
"=",
"new",
"InstallMacroblock",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"macroblockElement",
")",
";",
"}"
] | Install a Macroblock
@api
@param string $name Macroblock name
@param string $file Macroblock file
@param string $url Macroblock url
@return static | [
"Install",
"a",
"Macroblock"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L99-L103 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addInstallMap | public function addInstallMap($name, $url)
{
$mapElement = new InstallMap($name, $url);
return $this->addElement($mapElement);
} | php | public function addInstallMap($name, $url)
{
$mapElement = new InstallMap($name, $url);
return $this->addElement($mapElement);
} | [
"public",
"function",
"addInstallMap",
"(",
"$",
"name",
",",
"$",
"url",
")",
"{",
"$",
"mapElement",
"=",
"new",
"InstallMap",
"(",
"$",
"name",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"mapElement",
")",
";",
"}"
] | Install a map
@api
@param string $name Map name
@param string $url Map url
@return static | [
"Install",
"a",
"map"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L113-L117 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addPlayMap | public function addPlayMap($name, $url)
{
$mapElement = new PlayMap($name, $url);
return $this->addElement($mapElement);
} | php | public function addPlayMap($name, $url)
{
$mapElement = new PlayMap($name, $url);
return $this->addElement($mapElement);
} | [
"public",
"function",
"addPlayMap",
"(",
"$",
"name",
",",
"$",
"url",
")",
"{",
"$",
"mapElement",
"=",
"new",
"PlayMap",
"(",
"$",
"name",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"mapElement",
")",
";",
"}"
] | Play a map
@api
@param string $name Map name
@param string $url Map url
@return static | [
"Play",
"a",
"map"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L127-L131 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addInstallReplay | public function addInstallReplay($name, $url)
{
$replayElement = new InstallReplay($name, $url);
return $this->addElement($replayElement);
} | php | public function addInstallReplay($name, $url)
{
$replayElement = new InstallReplay($name, $url);
return $this->addElement($replayElement);
} | [
"public",
"function",
"addInstallReplay",
"(",
"$",
"name",
",",
"$",
"url",
")",
"{",
"$",
"replayElement",
"=",
"new",
"InstallReplay",
"(",
"$",
"name",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"replayElement",
")",
";",
"}"
] | Install a replay
@api
@param string $name Replay name
@param string $url Replay url
@return static | [
"Install",
"a",
"replay"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L141-L145 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addViewReplay | public function addViewReplay($name, $url)
{
$replayElement = new ViewReplay($name, $url);
return $this->addElement($replayElement);
} | php | public function addViewReplay($name, $url)
{
$replayElement = new ViewReplay($name, $url);
return $this->addElement($replayElement);
} | [
"public",
"function",
"addViewReplay",
"(",
"$",
"name",
",",
"$",
"url",
")",
"{",
"$",
"replayElement",
"=",
"new",
"ViewReplay",
"(",
"$",
"name",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"replayElement",
")",
";",
"}"
] | View a replay
@api
@param string $name Replay name
@param string $url Replay url
@return static | [
"View",
"a",
"replay"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L155-L159 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addPlayReplay | public function addPlayReplay($name, $url)
{
$replayElement = new PlayReplay($name, $url);
return $this->addElement($replayElement);
} | php | public function addPlayReplay($name, $url)
{
$replayElement = new PlayReplay($name, $url);
return $this->addElement($replayElement);
} | [
"public",
"function",
"addPlayReplay",
"(",
"$",
"name",
",",
"$",
"url",
")",
"{",
"$",
"replayElement",
"=",
"new",
"PlayReplay",
"(",
"$",
"name",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"replayElement",
")",
";",
"}"
] | Play a replay
@api
@param string $name Replay name
@param string $url Replay url
@return static | [
"Play",
"a",
"replay"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L169-L173 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addInstallSkin | public function addInstallSkin($name, $file, $url)
{
$skinElement = new InstallSkin($name, $file, $url);
return $this->addElement($skinElement);
} | php | public function addInstallSkin($name, $file, $url)
{
$skinElement = new InstallSkin($name, $file, $url);
return $this->addElement($skinElement);
} | [
"public",
"function",
"addInstallSkin",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
"{",
"$",
"skinElement",
"=",
"new",
"InstallSkin",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"skinElement",
")",
";",
"}"
] | Install a skin
@api
@param string $name Skin name
@param string $file Skin file
@param string $url Skin url
@return static | [
"Install",
"a",
"skin"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L184-L188 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addGetSkin | public function addGetSkin($name, $file, $url)
{
$skinElement = new GetSkin($name, $file, $url);
return $this->addElement($skinElement);
} | php | public function addGetSkin($name, $file, $url)
{
$skinElement = new GetSkin($name, $file, $url);
return $this->addElement($skinElement);
} | [
"public",
"function",
"addGetSkin",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
"{",
"$",
"skinElement",
"=",
"new",
"GetSkin",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"skinElement",
")",
";",
"}"
] | Get a skin
@api
@param string $name Skin name
@param string $file Skin file
@param string $url Skin url
@return static | [
"Get",
"a",
"skin"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L199-L203 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addJoinServer | public function addJoinServer($loginOrIp = null, $port = null)
{
$serverElement = new JoinServer($loginOrIp, $port);
return $this->addElement($serverElement);
} | php | public function addJoinServer($loginOrIp = null, $port = null)
{
$serverElement = new JoinServer($loginOrIp, $port);
return $this->addElement($serverElement);
} | [
"public",
"function",
"addJoinServer",
"(",
"$",
"loginOrIp",
"=",
"null",
",",
"$",
"port",
"=",
"null",
")",
"{",
"$",
"serverElement",
"=",
"new",
"JoinServer",
"(",
"$",
"loginOrIp",
",",
"$",
"port",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"serverElement",
")",
";",
"}"
] | Join a server
@api
@param string $loginOrIp (optional) Server login or ip
@param int $port (optional) Server port
@return static | [
"Join",
"a",
"server"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L239-L243 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addAddFavorite | public function addAddFavorite($loginOrIp = null, $port = null)
{
$favoriteElement = new AddFavorite($loginOrIp, $port);
return $this->addElement($favoriteElement);
} | php | public function addAddFavorite($loginOrIp = null, $port = null)
{
$favoriteElement = new AddFavorite($loginOrIp, $port);
return $this->addElement($favoriteElement);
} | [
"public",
"function",
"addAddFavorite",
"(",
"$",
"loginOrIp",
"=",
"null",
",",
"$",
"port",
"=",
"null",
")",
"{",
"$",
"favoriteElement",
"=",
"new",
"AddFavorite",
"(",
"$",
"loginOrIp",
",",
"$",
"port",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"favoriteElement",
")",
";",
"}"
] | Add a server as favorite
@api
@param string $loginOrIp (optional) Server login or ip
@param int $port (optional) Server port
@return static | [
"Add",
"a",
"server",
"as",
"favorite"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L253-L257 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addInstallScript | public function addInstallScript($name, $file, $url)
{
$scriptElement = new InstallScript($name, $file, $url);
return $this->addElement($scriptElement);
} | php | public function addInstallScript($name, $file, $url)
{
$scriptElement = new InstallScript($name, $file, $url);
return $this->addElement($scriptElement);
} | [
"public",
"function",
"addInstallScript",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
"{",
"$",
"scriptElement",
"=",
"new",
"InstallScript",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"scriptElement",
")",
";",
"}"
] | Install a script
@api
@param string $name Script name
@param string $file Script file
@param string $url Script url
@return static | [
"Install",
"a",
"script"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L268-L272 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addInstallPack | public function addInstallPack($name, $file, $url)
{
$packElement = new InstallPack($name, $file, $url);
return $this->addElement($packElement);
} | php | public function addInstallPack($name, $file, $url)
{
$packElement = new InstallPack($name, $file, $url);
return $this->addElement($packElement);
} | [
"public",
"function",
"addInstallPack",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
"{",
"$",
"packElement",
"=",
"new",
"InstallPack",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"url",
")",
";",
"return",
"$",
"this",
"->",
"addElement",
"(",
"$",
"packElement",
")",
";",
"}"
] | Install a title pack
@api
@param string $name Pack name
@param string $file Pack file
@param string $url Pack url
@return static | [
"Install",
"a",
"title",
"pack"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L283-L287 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.addElement | public function addElement(Element $element)
{
if (!in_array($element, $this->elements, true)) {
array_push($this->elements, $element);
}
return $this;
} | php | public function addElement(Element $element)
{
if (!in_array($element, $this->elements, true)) {
array_push($this->elements, $element);
}
return $this;
} | [
"public",
"function",
"addElement",
"(",
"Element",
"$",
"element",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"element",
",",
"$",
"this",
"->",
"elements",
",",
"true",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"elements",
",",
"$",
"element",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a ManiaCode Element
@api
@param Element $element Element to add
@return static | [
"Add",
"a",
"ManiaCode",
"Element"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L307-L313 |
steeffeen/FancyManiaLinks | FML/ManiaCode.php | ManiaCode.render | public function render($echo = false)
{
$domDocument = new \DOMDocument("1.0", "utf-8");
$domDocument->xmlStandalone = true;
$domElement = $domDocument->createElement("maniacode");
$domDocument->appendChild($domElement);
if ($this->disableConfirmation) {
$domElement->setAttribute("noconfirmation", 1);
}
foreach ($this->elements as $element) {
$childDomElement = $element->render($domDocument);
$domElement->appendChild($childDomElement);
}
if ($echo) {
header("Content-Type: application/xml; charset=utf-8;");
echo $domDocument->saveXML();
}
return $domDocument;
} | php | public function render($echo = false)
{
$domDocument = new \DOMDocument("1.0", "utf-8");
$domDocument->xmlStandalone = true;
$domElement = $domDocument->createElement("maniacode");
$domDocument->appendChild($domElement);
if ($this->disableConfirmation) {
$domElement->setAttribute("noconfirmation", 1);
}
foreach ($this->elements as $element) {
$childDomElement = $element->render($domDocument);
$domElement->appendChild($childDomElement);
}
if ($echo) {
header("Content-Type: application/xml; charset=utf-8;");
echo $domDocument->saveXML();
}
return $domDocument;
} | [
"public",
"function",
"render",
"(",
"$",
"echo",
"=",
"false",
")",
"{",
"$",
"domDocument",
"=",
"new",
"\\",
"DOMDocument",
"(",
"\"1.0\"",
",",
"\"utf-8\"",
")",
";",
"$",
"domDocument",
"->",
"xmlStandalone",
"=",
"true",
";",
"$",
"domElement",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"\"maniacode\"",
")",
";",
"$",
"domDocument",
"->",
"appendChild",
"(",
"$",
"domElement",
")",
";",
"if",
"(",
"$",
"this",
"->",
"disableConfirmation",
")",
"{",
"$",
"domElement",
"->",
"setAttribute",
"(",
"\"noconfirmation\"",
",",
"1",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"childDomElement",
"=",
"$",
"element",
"->",
"render",
"(",
"$",
"domDocument",
")",
";",
"$",
"domElement",
"->",
"appendChild",
"(",
"$",
"childDomElement",
")",
";",
"}",
"if",
"(",
"$",
"echo",
")",
"{",
"header",
"(",
"\"Content-Type: application/xml; charset=utf-8;\"",
")",
";",
"echo",
"$",
"domDocument",
"->",
"saveXML",
"(",
")",
";",
"}",
"return",
"$",
"domDocument",
";",
"}"
] | Render the ManiaCode
@api
@param bool $echo (optional) If the XML text should be echoed and the Content-Type header should be set
@return \DOMDocument | [
"Render",
"the",
"ManiaCode"
] | train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/ManiaCode.php#L362-L385 |
weew/url | src/Weew/Url/UrlParser.php | UrlParser.parse | public function parse($string) {
$segments = $this->parseSegments($string);
$segments = array_extend($segments, $this->parseHost(array_get($segments, 'host')));
return $this->replaceEmptyStringsWithNull($segments);
} | php | public function parse($string) {
$segments = $this->parseSegments($string);
$segments = array_extend($segments, $this->parseHost(array_get($segments, 'host')));
return $this->replaceEmptyStringsWithNull($segments);
} | [
"public",
"function",
"parse",
"(",
"$",
"string",
")",
"{",
"$",
"segments",
"=",
"$",
"this",
"->",
"parseSegments",
"(",
"$",
"string",
")",
";",
"$",
"segments",
"=",
"array_extend",
"(",
"$",
"segments",
",",
"$",
"this",
"->",
"parseHost",
"(",
"array_get",
"(",
"$",
"segments",
",",
"'host'",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"replaceEmptyStringsWithNull",
"(",
"$",
"segments",
")",
";",
"}"
] | @param $string
@return array | [
"@param",
"$string"
] | train | https://github.com/weew/url/blob/117be15e899cc343f22f04f5eb9e92e2164c56c1/src/Weew/Url/UrlParser.php#L11-L16 |
weew/url | src/Weew/Url/UrlParser.php | UrlParser.parseHost | public function parseHost($string) {
$segments = [
'tld' => null,
'domain' => null,
'subdomain' => null,
];
$parts = explode('.', $string);
if (count($parts) == 1) {
$segments['domain'] = $parts[0];
return $segments;
}
if (count($parts)) {
$segments['tld'] = array_pop($parts);
}
if (count($parts)) {
$segments['domain'] = array_pop($parts);
}
if (count($parts)) {
$segments['subdomain'] = implode('.', $parts);
}
return $this->replaceEmptyStringsWithNull($segments);
} | php | public function parseHost($string) {
$segments = [
'tld' => null,
'domain' => null,
'subdomain' => null,
];
$parts = explode('.', $string);
if (count($parts) == 1) {
$segments['domain'] = $parts[0];
return $segments;
}
if (count($parts)) {
$segments['tld'] = array_pop($parts);
}
if (count($parts)) {
$segments['domain'] = array_pop($parts);
}
if (count($parts)) {
$segments['subdomain'] = implode('.', $parts);
}
return $this->replaceEmptyStringsWithNull($segments);
} | [
"public",
"function",
"parseHost",
"(",
"$",
"string",
")",
"{",
"$",
"segments",
"=",
"[",
"'tld'",
"=>",
"null",
",",
"'domain'",
"=>",
"null",
",",
"'subdomain'",
"=>",
"null",
",",
"]",
";",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"string",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"1",
")",
"{",
"$",
"segments",
"[",
"'domain'",
"]",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"return",
"$",
"segments",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
")",
"{",
"$",
"segments",
"[",
"'tld'",
"]",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
")",
"{",
"$",
"segments",
"[",
"'domain'",
"]",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
")",
"{",
"$",
"segments",
"[",
"'subdomain'",
"]",
"=",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
";",
"}",
"return",
"$",
"this",
"->",
"replaceEmptyStringsWithNull",
"(",
"$",
"segments",
")",
";",
"}"
] | @param $string
@return array | [
"@param",
"$string"
] | train | https://github.com/weew/url/blob/117be15e899cc343f22f04f5eb9e92e2164c56c1/src/Weew/Url/UrlParser.php#L23-L51 |
weew/url | src/Weew/Url/UrlParser.php | UrlParser.parseSegments | protected function parseSegments($string) {
preg_match_all(
'/^' .
'((?P<protocol>.*):\/\/)?' .
'(' .
'(?P<username>.*?)' .
'(:(?P<password>.*?)' .
')@)?' .
'(?P<host>[^:\/\s]+)?' .
'(:(?P<port>\d*))?' .
'(?P<path>[^#\?]*)?' .
'(\?(?P<query>[^#]*))?' .
'(#(?P<fragment>.*))?' .
'$/',
$string,
$segments
);
foreach ($segments as $key => $value) {
if (is_numeric($key)) {
unset($segments[$key]);
} else {
$segments[$key] = array_pop($value);
}
}
$host = array_get($segments, 'host');
if ($host && $host !== 'localhost' && stripos($host, '.') === false) {
$segments['path'] = '/' . $host . array_get($segments, 'path');
$segments['host'] = null;
}
return $segments;
} | php | protected function parseSegments($string) {
preg_match_all(
'/^' .
'((?P<protocol>.*):\/\/)?' .
'(' .
'(?P<username>.*?)' .
'(:(?P<password>.*?)' .
')@)?' .
'(?P<host>[^:\/\s]+)?' .
'(:(?P<port>\d*))?' .
'(?P<path>[^#\?]*)?' .
'(\?(?P<query>[^#]*))?' .
'(#(?P<fragment>.*))?' .
'$/',
$string,
$segments
);
foreach ($segments as $key => $value) {
if (is_numeric($key)) {
unset($segments[$key]);
} else {
$segments[$key] = array_pop($value);
}
}
$host = array_get($segments, 'host');
if ($host && $host !== 'localhost' && stripos($host, '.') === false) {
$segments['path'] = '/' . $host . array_get($segments, 'path');
$segments['host'] = null;
}
return $segments;
} | [
"protected",
"function",
"parseSegments",
"(",
"$",
"string",
")",
"{",
"preg_match_all",
"(",
"'/^'",
".",
"'((?P<protocol>.*):\\/\\/)?'",
".",
"'('",
".",
"'(?P<username>.*?)'",
".",
"'(:(?P<password>.*?)'",
".",
"')@)?'",
".",
"'(?P<host>[^:\\/\\s]+)?'",
".",
"'(:(?P<port>\\d*))?'",
".",
"'(?P<path>[^#\\?]*)?'",
".",
"'(\\?(?P<query>[^#]*))?'",
".",
"'(#(?P<fragment>.*))?'",
".",
"'$/'",
",",
"$",
"string",
",",
"$",
"segments",
")",
";",
"foreach",
"(",
"$",
"segments",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"unset",
"(",
"$",
"segments",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"$",
"segments",
"[",
"$",
"key",
"]",
"=",
"array_pop",
"(",
"$",
"value",
")",
";",
"}",
"}",
"$",
"host",
"=",
"array_get",
"(",
"$",
"segments",
",",
"'host'",
")",
";",
"if",
"(",
"$",
"host",
"&&",
"$",
"host",
"!==",
"'localhost'",
"&&",
"stripos",
"(",
"$",
"host",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"$",
"segments",
"[",
"'path'",
"]",
"=",
"'/'",
".",
"$",
"host",
".",
"array_get",
"(",
"$",
"segments",
",",
"'path'",
")",
";",
"$",
"segments",
"[",
"'host'",
"]",
"=",
"null",
";",
"}",
"return",
"$",
"segments",
";",
"}"
] | @param $string
@return array | [
"@param",
"$string"
] | train | https://github.com/weew/url/blob/117be15e899cc343f22f04f5eb9e92e2164c56c1/src/Weew/Url/UrlParser.php#L58-L92 |
Craftsware/scissor | src/Scissor.php | Scissor.run | public function run() {
$router = new Router($this);
// // Get Route
if($route = $router->map($this->app('Routes'))) {
if($route instanceof \Closure) {
$body = $route->bindTo($this)($this->request, $this->response);
}
// Set headers
foreach((array) $this->headers->get() as $name => $value) {
if($name == 'Status') {
http_response_code($value);
} else {
header(sprintf('%s: %s', $name, $value), false);
}
}
echo $body;
}
} | php | public function run() {
$router = new Router($this);
// // Get Route
if($route = $router->map($this->app('Routes'))) {
if($route instanceof \Closure) {
$body = $route->bindTo($this)($this->request, $this->response);
}
// Set headers
foreach((array) $this->headers->get() as $name => $value) {
if($name == 'Status') {
http_response_code($value);
} else {
header(sprintf('%s: %s', $name, $value), false);
}
}
echo $body;
}
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"router",
"=",
"new",
"Router",
"(",
"$",
"this",
")",
";",
"// // Get Route",
"if",
"(",
"$",
"route",
"=",
"$",
"router",
"->",
"map",
"(",
"$",
"this",
"->",
"app",
"(",
"'Routes'",
")",
")",
")",
"{",
"if",
"(",
"$",
"route",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"body",
"=",
"$",
"route",
"->",
"bindTo",
"(",
"$",
"this",
")",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"this",
"->",
"response",
")",
";",
"}",
"// Set headers",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"headers",
"->",
"get",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"'Status'",
")",
"{",
"http_response_code",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"header",
"(",
"sprintf",
"(",
"'%s: %s'",
",",
"$",
"name",
",",
"$",
"value",
")",
",",
"false",
")",
";",
"}",
"}",
"echo",
"$",
"body",
";",
"}",
"}"
] | Run the app | [
"Run",
"the",
"app"
] | train | https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Scissor.php#L164-L191 |
Craftsware/scissor | src/Scissor.php | Scissor.render | public function render($name, $args = []) {
if(strstr($name, '::')) {
$name = explode('::', $name);
} else {
$name = [$name, strtolower($name)];
}
if($this->set('module[controller]', $name[0])) {
$module = $this->get('module');
if(isset($module['name'])) {
ob_start();
if(method_exists($instance = $this->controller($module['name'], $name[0]), $name[1])) {
if($ref = new \ReflectionMethod($instance, $name[1])) {
$ref->invokeArgs($instance, $args);
}
}
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}
} | php | public function render($name, $args = []) {
if(strstr($name, '::')) {
$name = explode('::', $name);
} else {
$name = [$name, strtolower($name)];
}
if($this->set('module[controller]', $name[0])) {
$module = $this->get('module');
if(isset($module['name'])) {
ob_start();
if(method_exists($instance = $this->controller($module['name'], $name[0]), $name[1])) {
if($ref = new \ReflectionMethod($instance, $name[1])) {
$ref->invokeArgs($instance, $args);
}
}
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}
} | [
"public",
"function",
"render",
"(",
"$",
"name",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"strstr",
"(",
"$",
"name",
",",
"'::'",
")",
")",
"{",
"$",
"name",
"=",
"explode",
"(",
"'::'",
",",
"$",
"name",
")",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"[",
"$",
"name",
",",
"strtolower",
"(",
"$",
"name",
")",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"set",
"(",
"'module[controller]'",
",",
"$",
"name",
"[",
"0",
"]",
")",
")",
"{",
"$",
"module",
"=",
"$",
"this",
"->",
"get",
"(",
"'module'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"module",
"[",
"'name'",
"]",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"instance",
"=",
"$",
"this",
"->",
"controller",
"(",
"$",
"module",
"[",
"'name'",
"]",
",",
"$",
"name",
"[",
"0",
"]",
")",
",",
"$",
"name",
"[",
"1",
"]",
")",
")",
"{",
"if",
"(",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"instance",
",",
"$",
"name",
"[",
"1",
"]",
")",
")",
"{",
"$",
"ref",
"->",
"invokeArgs",
"(",
"$",
"instance",
",",
"$",
"args",
")",
";",
"}",
"}",
"$",
"content",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"return",
"$",
"content",
";",
"}",
"}",
"}"
] | Render
@param string $name
@param array $args
@return string | [
"Render"
] | train | https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Scissor.php#L202-L238 |
Craftsware/scissor | src/Scissor.php | Scissor.controller | private function controller($module, $controller, $injetion = null) {
// Check if exist
if(class_exists($namespace = 'App\\Modules\\' . ucfirst($module) . '\\Controllers\\' . $controller)) {
return (new $namespace($injetion));
}
} | php | private function controller($module, $controller, $injetion = null) {
// Check if exist
if(class_exists($namespace = 'App\\Modules\\' . ucfirst($module) . '\\Controllers\\' . $controller)) {
return (new $namespace($injetion));
}
} | [
"private",
"function",
"controller",
"(",
"$",
"module",
",",
"$",
"controller",
",",
"$",
"injetion",
"=",
"null",
")",
"{",
"// Check if exist",
"if",
"(",
"class_exists",
"(",
"$",
"namespace",
"=",
"'App\\\\Modules\\\\'",
".",
"ucfirst",
"(",
"$",
"module",
")",
".",
"'\\\\Controllers\\\\'",
".",
"$",
"controller",
")",
")",
"{",
"return",
"(",
"new",
"$",
"namespace",
"(",
"$",
"injetion",
")",
")",
";",
"}",
"}"
] | Controller
@param string $module
@param object $injetion
@param array $controller
@return object $namespace | [
"Controller"
] | train | https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Scissor.php#L251-L258 |
spiral-modules/scaffolder | source/Scaffolder/Declarations/Database/DocumentDeclaration.php | DocumentDeclaration.normalizeDeclaration | public function normalizeDeclaration()
{
if (empty($this->getCollection())) {
$this->getConstants()->remove('COLLECTION');
}
if (empty($this->getDatabase())) {
$this->getConstants()->remove('DATABASE');
}
return $this;
} | php | public function normalizeDeclaration()
{
if (empty($this->getCollection())) {
$this->getConstants()->remove('COLLECTION');
}
if (empty($this->getDatabase())) {
$this->getConstants()->remove('DATABASE');
}
return $this;
} | [
"public",
"function",
"normalizeDeclaration",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"getCollection",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"getConstants",
"(",
")",
"->",
"remove",
"(",
"'COLLECTION'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"getDatabase",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"getConstants",
"(",
")",
"->",
"remove",
"(",
"'DATABASE'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Drop non required properties and methods
@return $this | [
"Drop",
"non",
"required",
"properties",
"and",
"methods"
] | train | https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/Scaffolder/Declarations/Database/DocumentDeclaration.php#L62-L73 |
spiral-modules/scaffolder | source/Scaffolder/Declarations/Database/DocumentDeclaration.php | DocumentDeclaration.declareStructure | protected function declareStructure()
{
$this->constant('COLLECTION');
$this->constant('DATABASE');
parent::declareStructure();
$this->constant('DEFAULTS')->setValue([]);
$this->constant('INDEXES')->setValue([]);
} | php | protected function declareStructure()
{
$this->constant('COLLECTION');
$this->constant('DATABASE');
parent::declareStructure();
$this->constant('DEFAULTS')->setValue([]);
$this->constant('INDEXES')->setValue([]);
} | [
"protected",
"function",
"declareStructure",
"(",
")",
"{",
"$",
"this",
"->",
"constant",
"(",
"'COLLECTION'",
")",
";",
"$",
"this",
"->",
"constant",
"(",
"'DATABASE'",
")",
";",
"parent",
"::",
"declareStructure",
"(",
")",
";",
"$",
"this",
"->",
"constant",
"(",
"'DEFAULTS'",
")",
"->",
"setValue",
"(",
"[",
"]",
")",
";",
"$",
"this",
"->",
"constant",
"(",
"'INDEXES'",
")",
"->",
"setValue",
"(",
"[",
"]",
")",
";",
"}"
] | Declare record entity structure. | [
"Declare",
"record",
"entity",
"structure",
"."
] | train | https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/Scaffolder/Declarations/Database/DocumentDeclaration.php#L78-L87 |
phug-php/formatter | src/Phug/Formatter/Format/XmlFormat.php | XmlFormat.yieldAssignmentElement | protected function yieldAssignmentElement(AssignmentElement $element)
{
foreach ($this->getOption('assignment_handlers') as $handler) {
$iterator = $handler($element) ?: [];
foreach ($iterator as $newElement) {
yield $newElement;
}
}
/* @var MarkupElement $markup */
$markup = $element->getContainer();
$arguments = [];
foreach ($markup->getAssignmentsByName('attributes') as $attributesAssignment) {
/* @var AssignmentElement $attributesAssignment */
foreach ($attributesAssignment->getAttributes() as $attribute) {
/* @var AbstractValueElement $attribute */
$value = $attribute;
$checked = method_exists($value, 'isChecked') && $value->isChecked();
while (method_exists($value, 'getValue')) {
$value = $value->getValue();
}
$arguments[] = $this->formatCode($value, $checked);
}
$markup->removedAssignment($attributesAssignment);
}
$attributes = $markup->getAttributes();
foreach ($attributes as $attribute) {
/* @var AttributeElement $attribute */
$arguments[] = $this->formatAttributeAsArrayItem($attribute);
}
$attributes->removeAll($attributes);
foreach ($markup->getAssignments() as $assignment) {
/* @var AssignmentElement $assignment */
$this->throwException(
'Unable to handle '.$assignment->getName().' assignment',
$assignment
);
}
if (count($arguments)) {
yield $this->attributesAssignmentsFromPairs($arguments);
}
} | php | protected function yieldAssignmentElement(AssignmentElement $element)
{
foreach ($this->getOption('assignment_handlers') as $handler) {
$iterator = $handler($element) ?: [];
foreach ($iterator as $newElement) {
yield $newElement;
}
}
/* @var MarkupElement $markup */
$markup = $element->getContainer();
$arguments = [];
foreach ($markup->getAssignmentsByName('attributes') as $attributesAssignment) {
/* @var AssignmentElement $attributesAssignment */
foreach ($attributesAssignment->getAttributes() as $attribute) {
/* @var AbstractValueElement $attribute */
$value = $attribute;
$checked = method_exists($value, 'isChecked') && $value->isChecked();
while (method_exists($value, 'getValue')) {
$value = $value->getValue();
}
$arguments[] = $this->formatCode($value, $checked);
}
$markup->removedAssignment($attributesAssignment);
}
$attributes = $markup->getAttributes();
foreach ($attributes as $attribute) {
/* @var AttributeElement $attribute */
$arguments[] = $this->formatAttributeAsArrayItem($attribute);
}
$attributes->removeAll($attributes);
foreach ($markup->getAssignments() as $assignment) {
/* @var AssignmentElement $assignment */
$this->throwException(
'Unable to handle '.$assignment->getName().' assignment',
$assignment
);
}
if (count($arguments)) {
yield $this->attributesAssignmentsFromPairs($arguments);
}
} | [
"protected",
"function",
"yieldAssignmentElement",
"(",
"AssignmentElement",
"$",
"element",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getOption",
"(",
"'assignment_handlers'",
")",
"as",
"$",
"handler",
")",
"{",
"$",
"iterator",
"=",
"$",
"handler",
"(",
"$",
"element",
")",
"?",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"newElement",
")",
"{",
"yield",
"$",
"newElement",
";",
"}",
"}",
"/* @var MarkupElement $markup */",
"$",
"markup",
"=",
"$",
"element",
"->",
"getContainer",
"(",
")",
";",
"$",
"arguments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"markup",
"->",
"getAssignmentsByName",
"(",
"'attributes'",
")",
"as",
"$",
"attributesAssignment",
")",
"{",
"/* @var AssignmentElement $attributesAssignment */",
"foreach",
"(",
"$",
"attributesAssignment",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"attribute",
")",
"{",
"/* @var AbstractValueElement $attribute */",
"$",
"value",
"=",
"$",
"attribute",
";",
"$",
"checked",
"=",
"method_exists",
"(",
"$",
"value",
",",
"'isChecked'",
")",
"&&",
"$",
"value",
"->",
"isChecked",
"(",
")",
";",
"while",
"(",
"method_exists",
"(",
"$",
"value",
",",
"'getValue'",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"getValue",
"(",
")",
";",
"}",
"$",
"arguments",
"[",
"]",
"=",
"$",
"this",
"->",
"formatCode",
"(",
"$",
"value",
",",
"$",
"checked",
")",
";",
"}",
"$",
"markup",
"->",
"removedAssignment",
"(",
"$",
"attributesAssignment",
")",
";",
"}",
"$",
"attributes",
"=",
"$",
"markup",
"->",
"getAttributes",
"(",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"/* @var AttributeElement $attribute */",
"$",
"arguments",
"[",
"]",
"=",
"$",
"this",
"->",
"formatAttributeAsArrayItem",
"(",
"$",
"attribute",
")",
";",
"}",
"$",
"attributes",
"->",
"removeAll",
"(",
"$",
"attributes",
")",
";",
"foreach",
"(",
"$",
"markup",
"->",
"getAssignments",
"(",
")",
"as",
"$",
"assignment",
")",
"{",
"/* @var AssignmentElement $assignment */",
"$",
"this",
"->",
"throwException",
"(",
"'Unable to handle '",
".",
"$",
"assignment",
"->",
"getName",
"(",
")",
".",
"' assignment'",
",",
"$",
"assignment",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"arguments",
")",
")",
"{",
"yield",
"$",
"this",
"->",
"attributesAssignmentsFromPairs",
"(",
"$",
"arguments",
")",
";",
"}",
"}"
] | @param AssignmentElement $element
@throws \Phug\FormatterException
@return \Generator | [
"@param",
"AssignmentElement",
"$element"
] | train | https://github.com/phug-php/formatter/blob/3f9286a169a0d45b8b8acc1fae64e880ebdb567e/src/Phug/Formatter/Format/XmlFormat.php#L255-L300 |
helthe/Chronos | Crontab.php | Crontab.read | private function read($user = null)
{
$process = new Process($this->getCommand() . ' -l');
$process->run();
return $process->getOutput();
} | php | private function read($user = null)
{
$process = new Process($this->getCommand() . ' -l');
$process->run();
return $process->getOutput();
} | [
"private",
"function",
"read",
"(",
"$",
"user",
"=",
"null",
")",
"{",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"this",
"->",
"getCommand",
"(",
")",
".",
"' -l'",
")",
";",
"$",
"process",
"->",
"run",
"(",
")",
";",
"return",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"}"
] | Reads the crontab file and returns the output. Default: current user.
@param string $user
@return string | [
"Reads",
"the",
"crontab",
"file",
"and",
"returns",
"the",
"output",
".",
"Default",
":",
"current",
"user",
"."
] | train | https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Crontab.php#L102-L109 |
helthe/Chronos | Crontab.php | Crontab.getCommand | private function getCommand($user = null)
{
$command = $this->executable;
if ($user) {
$command .= ' -u' . $user;
}
return $command;
} | php | private function getCommand($user = null)
{
$command = $this->executable;
if ($user) {
$command .= ' -u' . $user;
}
return $command;
} | [
"private",
"function",
"getCommand",
"(",
"$",
"user",
"=",
"null",
")",
"{",
"$",
"command",
"=",
"$",
"this",
"->",
"executable",
";",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"command",
".=",
"' -u'",
".",
"$",
"user",
";",
"}",
"return",
"$",
"command",
";",
"}"
] | Get the base crontab command. Default: current user.
@param string $user
@return string | [
"Get",
"the",
"base",
"crontab",
"command",
".",
"Default",
":",
"current",
"user",
"."
] | train | https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Crontab.php#L118-L127 |
helthe/Chronos | Crontab.php | Crontab.render | private function render()
{
$output = '';
foreach ($this->jobs as $job) {
$output .= $this->getTaskDefinition($job);
}
return $output;
} | php | private function render()
{
$output = '';
foreach ($this->jobs as $job) {
$output .= $this->getTaskDefinition($job);
}
return $output;
} | [
"private",
"function",
"render",
"(",
")",
"{",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"jobs",
"as",
"$",
"job",
")",
"{",
"$",
"output",
".=",
"$",
"this",
"->",
"getTaskDefinition",
"(",
"$",
"job",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Render all the cron jobs.
@return string | [
"Render",
"all",
"the",
"cron",
"jobs",
"."
] | train | https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Crontab.php#L166-L175 |
helthe/Chronos | Crontab.php | Crontab.write | private function write($content, $user = null)
{
$crontab = $this->read($user);
$header = $this->getHeaderComment();
$footer = $this->getFooterComment();
$content = $header . PHP_EOL . $content . $footer;
$hasHeader = preg_match("/^$header\s*$/m", $crontab) === 1;
$hasFooter = preg_match("/^$footer\s*$/m", $crontab) === 1;
if ($hasHeader && !$hasFooter) {
throw new InvalidIdentifierException(sprintf('Unclosed identifier. Your crontab contains "%s", but no "%s".', $header, $footer));
} elseif (!$hasHeader && $hasFooter) {
throw new InvalidIdentifierException(sprintf('Unopened identifier. Your crontab contains "%s", but no "%s".', $footer, $header));
}
if ($hasHeader && $hasFooter) {
$crontab = preg_replace("/^$header\s*$.*?^$footer\s*$/sm", $content, $crontab);
} else {
$crontab .= PHP_EOL . $content;
}
$tempFile = tempnam(sys_get_temp_dir(), 'helthe_cron');
file_put_contents($tempFile, $crontab);
$process = new Process($this->getCommand($user) . ' ' . $tempFile);
if ($process->run() === 1) {
throw new RuntimeException($process->getErrorOutput());
}
return $process->getExitCode();
} | php | private function write($content, $user = null)
{
$crontab = $this->read($user);
$header = $this->getHeaderComment();
$footer = $this->getFooterComment();
$content = $header . PHP_EOL . $content . $footer;
$hasHeader = preg_match("/^$header\s*$/m", $crontab) === 1;
$hasFooter = preg_match("/^$footer\s*$/m", $crontab) === 1;
if ($hasHeader && !$hasFooter) {
throw new InvalidIdentifierException(sprintf('Unclosed identifier. Your crontab contains "%s", but no "%s".', $header, $footer));
} elseif (!$hasHeader && $hasFooter) {
throw new InvalidIdentifierException(sprintf('Unopened identifier. Your crontab contains "%s", but no "%s".', $footer, $header));
}
if ($hasHeader && $hasFooter) {
$crontab = preg_replace("/^$header\s*$.*?^$footer\s*$/sm", $content, $crontab);
} else {
$crontab .= PHP_EOL . $content;
}
$tempFile = tempnam(sys_get_temp_dir(), 'helthe_cron');
file_put_contents($tempFile, $crontab);
$process = new Process($this->getCommand($user) . ' ' . $tempFile);
if ($process->run() === 1) {
throw new RuntimeException($process->getErrorOutput());
}
return $process->getExitCode();
} | [
"private",
"function",
"write",
"(",
"$",
"content",
",",
"$",
"user",
"=",
"null",
")",
"{",
"$",
"crontab",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"user",
")",
";",
"$",
"header",
"=",
"$",
"this",
"->",
"getHeaderComment",
"(",
")",
";",
"$",
"footer",
"=",
"$",
"this",
"->",
"getFooterComment",
"(",
")",
";",
"$",
"content",
"=",
"$",
"header",
".",
"PHP_EOL",
".",
"$",
"content",
".",
"$",
"footer",
";",
"$",
"hasHeader",
"=",
"preg_match",
"(",
"\"/^$header\\s*$/m\"",
",",
"$",
"crontab",
")",
"===",
"1",
";",
"$",
"hasFooter",
"=",
"preg_match",
"(",
"\"/^$footer\\s*$/m\"",
",",
"$",
"crontab",
")",
"===",
"1",
";",
"if",
"(",
"$",
"hasHeader",
"&&",
"!",
"$",
"hasFooter",
")",
"{",
"throw",
"new",
"InvalidIdentifierException",
"(",
"sprintf",
"(",
"'Unclosed identifier. Your crontab contains \"%s\", but no \"%s\".'",
",",
"$",
"header",
",",
"$",
"footer",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"hasHeader",
"&&",
"$",
"hasFooter",
")",
"{",
"throw",
"new",
"InvalidIdentifierException",
"(",
"sprintf",
"(",
"'Unopened identifier. Your crontab contains \"%s\", but no \"%s\".'",
",",
"$",
"footer",
",",
"$",
"header",
")",
")",
";",
"}",
"if",
"(",
"$",
"hasHeader",
"&&",
"$",
"hasFooter",
")",
"{",
"$",
"crontab",
"=",
"preg_replace",
"(",
"\"/^$header\\s*$.*?^$footer\\s*$/sm\"",
",",
"$",
"content",
",",
"$",
"crontab",
")",
";",
"}",
"else",
"{",
"$",
"crontab",
".=",
"PHP_EOL",
".",
"$",
"content",
";",
"}",
"$",
"tempFile",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'helthe_cron'",
")",
";",
"file_put_contents",
"(",
"$",
"tempFile",
",",
"$",
"crontab",
")",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"this",
"->",
"getCommand",
"(",
"$",
"user",
")",
".",
"' '",
".",
"$",
"tempFile",
")",
";",
"if",
"(",
"$",
"process",
"->",
"run",
"(",
")",
"===",
"1",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
")",
";",
"}",
"return",
"$",
"process",
"->",
"getExitCode",
"(",
")",
";",
"}"
] | Writes the crontab into the system for the given user. Default: current user.
@param string $content
@param string $user
@return integer
@throws InvalidIdentifierException
@throws RuntimeException | [
"Writes",
"the",
"crontab",
"into",
"the",
"system",
"for",
"the",
"given",
"user",
".",
"Default",
":",
"current",
"user",
"."
] | train | https://github.com/helthe/Chronos/blob/6c783c55c32b323550fc6f21cd644c2be82720b0/Crontab.php#L188-L218 |
joomlatools/joomlatools-platform-legacy | code/base/observable.php | JObservable.attach | public function attach($observer)
{
if (is_array($observer))
{
if (!isset($observer['handler']) || !isset($observer['event']) || !is_callable($observer['handler']))
{
return;
}
// Make sure we haven't already attached this array as an observer
foreach ($this->_observers as $check)
{
if (is_array($check) && $check['event'] == $observer['event'] && $check['handler'] == $observer['handler'])
{
return;
}
}
$this->_observers[] = $observer;
end($this->_observers);
$methods = array($observer['event']);
}
else
{
if (!($observer instanceof JObserver))
{
return;
}
// Make sure we haven't already attached this object as an observer
$class = get_class($observer);
foreach ($this->_observers as $check)
{
if ($check instanceof $class)
{
return;
}
}
$this->_observers[] = $observer;
$methods = array_diff(get_class_methods($observer), get_class_methods('JPlugin'));
}
$key = key($this->_observers);
foreach ($methods as $method)
{
$method = strtolower($method);
if (!isset($this->_methods[$method]))
{
$this->_methods[$method] = array();
}
$this->_methods[$method][] = $key;
}
} | php | public function attach($observer)
{
if (is_array($observer))
{
if (!isset($observer['handler']) || !isset($observer['event']) || !is_callable($observer['handler']))
{
return;
}
// Make sure we haven't already attached this array as an observer
foreach ($this->_observers as $check)
{
if (is_array($check) && $check['event'] == $observer['event'] && $check['handler'] == $observer['handler'])
{
return;
}
}
$this->_observers[] = $observer;
end($this->_observers);
$methods = array($observer['event']);
}
else
{
if (!($observer instanceof JObserver))
{
return;
}
// Make sure we haven't already attached this object as an observer
$class = get_class($observer);
foreach ($this->_observers as $check)
{
if ($check instanceof $class)
{
return;
}
}
$this->_observers[] = $observer;
$methods = array_diff(get_class_methods($observer), get_class_methods('JPlugin'));
}
$key = key($this->_observers);
foreach ($methods as $method)
{
$method = strtolower($method);
if (!isset($this->_methods[$method]))
{
$this->_methods[$method] = array();
}
$this->_methods[$method][] = $key;
}
} | [
"public",
"function",
"attach",
"(",
"$",
"observer",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"observer",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"observer",
"[",
"'handler'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"observer",
"[",
"'event'",
"]",
")",
"||",
"!",
"is_callable",
"(",
"$",
"observer",
"[",
"'handler'",
"]",
")",
")",
"{",
"return",
";",
"}",
"// Make sure we haven't already attached this array as an observer",
"foreach",
"(",
"$",
"this",
"->",
"_observers",
"as",
"$",
"check",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"check",
")",
"&&",
"$",
"check",
"[",
"'event'",
"]",
"==",
"$",
"observer",
"[",
"'event'",
"]",
"&&",
"$",
"check",
"[",
"'handler'",
"]",
"==",
"$",
"observer",
"[",
"'handler'",
"]",
")",
"{",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"_observers",
"[",
"]",
"=",
"$",
"observer",
";",
"end",
"(",
"$",
"this",
"->",
"_observers",
")",
";",
"$",
"methods",
"=",
"array",
"(",
"$",
"observer",
"[",
"'event'",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"(",
"$",
"observer",
"instanceof",
"JObserver",
")",
")",
"{",
"return",
";",
"}",
"// Make sure we haven't already attached this object as an observer",
"$",
"class",
"=",
"get_class",
"(",
"$",
"observer",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_observers",
"as",
"$",
"check",
")",
"{",
"if",
"(",
"$",
"check",
"instanceof",
"$",
"class",
")",
"{",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"_observers",
"[",
"]",
"=",
"$",
"observer",
";",
"$",
"methods",
"=",
"array_diff",
"(",
"get_class_methods",
"(",
"$",
"observer",
")",
",",
"get_class_methods",
"(",
"'JPlugin'",
")",
")",
";",
"}",
"$",
"key",
"=",
"key",
"(",
"$",
"this",
"->",
"_observers",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"$",
"method",
"=",
"strtolower",
"(",
"$",
"method",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_methods",
"[",
"$",
"method",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_methods",
"[",
"$",
"method",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_methods",
"[",
"$",
"method",
"]",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}"
] | Attach an observer object
@param object $observer An observer object to attach
@return void
@since 11.1
@deprecated 12.3 | [
"Attach",
"an",
"observer",
"object"
] | train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/base/observable.php#L102-L159 |
joomlatools/joomlatools-platform-legacy | code/base/observable.php | JObservable.detach | public function detach($observer)
{
$retval = false;
$key = array_search($observer, $this->_observers);
if ($key !== false)
{
unset($this->_observers[$key]);
$retval = true;
foreach ($this->_methods as &$method)
{
$k = array_search($key, $method);
if ($k !== false)
{
unset($method[$k]);
}
}
}
return $retval;
} | php | public function detach($observer)
{
$retval = false;
$key = array_search($observer, $this->_observers);
if ($key !== false)
{
unset($this->_observers[$key]);
$retval = true;
foreach ($this->_methods as &$method)
{
$k = array_search($key, $method);
if ($k !== false)
{
unset($method[$k]);
}
}
}
return $retval;
} | [
"public",
"function",
"detach",
"(",
"$",
"observer",
")",
"{",
"$",
"retval",
"=",
"false",
";",
"$",
"key",
"=",
"array_search",
"(",
"$",
"observer",
",",
"$",
"this",
"->",
"_observers",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_observers",
"[",
"$",
"key",
"]",
")",
";",
"$",
"retval",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"_methods",
"as",
"&",
"$",
"method",
")",
"{",
"$",
"k",
"=",
"array_search",
"(",
"$",
"key",
",",
"$",
"method",
")",
";",
"if",
"(",
"$",
"k",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"method",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"retval",
";",
"}"
] | Detach an observer object
@param object $observer An observer object to detach.
@return boolean True if the observer object was detached.
@since 11.1
@deprecated 12.3 | [
"Detach",
"an",
"observer",
"object"
] | train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/base/observable.php#L171-L194 |
ClanCats/Core | src/bundles/UI/E.php | E.attr | public static function attr( $attr = array() ) {
$buffer = " ";
foreach( $attr as $key => $value ) {
$buffer .= $key.'="'.$value.'" ';
}
return substr( $buffer, 0, -1 );
} | php | public static function attr( $attr = array() ) {
$buffer = " ";
foreach( $attr as $key => $value ) {
$buffer .= $key.'="'.$value.'" ';
}
return substr( $buffer, 0, -1 );
} | [
"public",
"static",
"function",
"attr",
"(",
"$",
"attr",
"=",
"array",
"(",
")",
")",
"{",
"$",
"buffer",
"=",
"\" \"",
";",
"foreach",
"(",
"$",
"attr",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"buffer",
".=",
"$",
"key",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\" '",
";",
"}",
"return",
"substr",
"(",
"$",
"buffer",
",",
"0",
",",
"-",
"1",
")",
";",
"}"
] | generates element attribute string
@param array $attr | [
"generates",
"element",
"attribute",
"string"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/E.php#L44-L51 |
ClanCats/Core | src/bundles/UI/E.php | E.set_attr | public function set_attr( $attribute, $value = null ) {
if ( is_null( $value ) || $value === false ) {
if ( array_key_exists( $attribute, $this->attr ) ) {
unset( $this->attr[$attribute] );
}
} else {
if ( $value === true ) {
$value = $attribute;
}
$this->attr[ $attribute ] = $value;
}
return $this;
} | php | public function set_attr( $attribute, $value = null ) {
if ( is_null( $value ) || $value === false ) {
if ( array_key_exists( $attribute, $this->attr ) ) {
unset( $this->attr[$attribute] );
}
} else {
if ( $value === true ) {
$value = $attribute;
}
$this->attr[ $attribute ] = $value;
}
return $this;
} | [
"public",
"function",
"set_attr",
"(",
"$",
"attribute",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"===",
"false",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"attribute",
",",
"$",
"this",
"->",
"attr",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"attr",
"[",
"$",
"attribute",
"]",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"===",
"true",
")",
"{",
"$",
"value",
"=",
"$",
"attribute",
";",
"}",
"$",
"this",
"->",
"attr",
"[",
"$",
"attribute",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set an attribute
@param string $attribute
@param mixed $value
@return $this | [
"Set",
"an",
"attribute"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/E.php#L103-L116 |
ClanCats/Core | src/bundles/UI/E.php | E.render | public function render() {
// execute callback if we have one first
if ( is_closure( $this->value ) ) {
ob_start(); $return = call_user_func( $this->value ); $this->value = ob_get_clean().$return;
}
return '<'.$this->name.static::attr( $this->attr ).
( !is_null( $this->value ) ? '>'.$this->value.'</'.$this->name.'>' : ' />' );
} | php | public function render() {
// execute callback if we have one first
if ( is_closure( $this->value ) ) {
ob_start(); $return = call_user_func( $this->value ); $this->value = ob_get_clean().$return;
}
return '<'.$this->name.static::attr( $this->attr ).
( !is_null( $this->value ) ? '>'.$this->value.'</'.$this->name.'>' : ' />' );
} | [
"public",
"function",
"render",
"(",
")",
"{",
"// execute callback if we have one first",
"if",
"(",
"is_closure",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"return",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"value",
")",
";",
"$",
"this",
"->",
"value",
"=",
"ob_get_clean",
"(",
")",
".",
"$",
"return",
";",
"}",
"return",
"'<'",
".",
"$",
"this",
"->",
"name",
".",
"static",
"::",
"attr",
"(",
"$",
"this",
"->",
"attr",
")",
".",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"value",
")",
"?",
"'>'",
".",
"$",
"this",
"->",
"value",
".",
"'</'",
".",
"$",
"this",
"->",
"name",
".",
"'>'",
":",
"' />'",
")",
";",
"}"
] | render this element
@return string | [
"render",
"this",
"element"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/E.php#L143-L150 |
factorio-item-browser/export-data | src/Registry/Adapter/FileSystemAdapter.php | FileSystemAdapter.save | public function save(string $namespace, string $hash, string $content): void
{
$fileName = $this->getFileName($namespace, $hash);
$this->ensureDirectory(dirname($fileName));
$success = false;
if (!file_exists($fileName) || is_writable($fileName)) {
$success = file_put_contents($fileName, $content);
}
if ($success === false) {
throw new ExportDataException('Unable to write file ' . $fileName);
}
} | php | public function save(string $namespace, string $hash, string $content): void
{
$fileName = $this->getFileName($namespace, $hash);
$this->ensureDirectory(dirname($fileName));
$success = false;
if (!file_exists($fileName) || is_writable($fileName)) {
$success = file_put_contents($fileName, $content);
}
if ($success === false) {
throw new ExportDataException('Unable to write file ' . $fileName);
}
} | [
"public",
"function",
"save",
"(",
"string",
"$",
"namespace",
",",
"string",
"$",
"hash",
",",
"string",
"$",
"content",
")",
":",
"void",
"{",
"$",
"fileName",
"=",
"$",
"this",
"->",
"getFileName",
"(",
"$",
"namespace",
",",
"$",
"hash",
")",
";",
"$",
"this",
"->",
"ensureDirectory",
"(",
"dirname",
"(",
"$",
"fileName",
")",
")",
";",
"$",
"success",
"=",
"false",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileName",
")",
"||",
"is_writable",
"(",
"$",
"fileName",
")",
")",
"{",
"$",
"success",
"=",
"file_put_contents",
"(",
"$",
"fileName",
",",
"$",
"content",
")",
";",
"}",
"if",
"(",
"$",
"success",
"===",
"false",
")",
"{",
"throw",
"new",
"ExportDataException",
"(",
"'Unable to write file '",
".",
"$",
"fileName",
")",
";",
"}",
"}"
] | Saves the content under the specified hash.
@param string $namespace
@param string $hash
@param string $content
@return void
@throws ExportDataException | [
"Saves",
"the",
"content",
"under",
"the",
"specified",
"hash",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Registry/Adapter/FileSystemAdapter.php#L43-L55 |
factorio-item-browser/export-data | src/Registry/Adapter/FileSystemAdapter.php | FileSystemAdapter.load | public function load(string $namespace, string $hash): ?string
{
$result = null;
$fileName = $this->getFileName($namespace, $hash);
if (file_exists($fileName) && is_readable($fileName)) {
$result = file_get_contents($fileName);
}
return is_string($result) ? $result : null;
} | php | public function load(string $namespace, string $hash): ?string
{
$result = null;
$fileName = $this->getFileName($namespace, $hash);
if (file_exists($fileName) && is_readable($fileName)) {
$result = file_get_contents($fileName);
}
return is_string($result) ? $result : null;
} | [
"public",
"function",
"load",
"(",
"string",
"$",
"namespace",
",",
"string",
"$",
"hash",
")",
":",
"?",
"string",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"fileName",
"=",
"$",
"this",
"->",
"getFileName",
"(",
"$",
"namespace",
",",
"$",
"hash",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fileName",
")",
"&&",
"is_readable",
"(",
"$",
"fileName",
")",
")",
"{",
"$",
"result",
"=",
"file_get_contents",
"(",
"$",
"fileName",
")",
";",
"}",
"return",
"is_string",
"(",
"$",
"result",
")",
"?",
"$",
"result",
":",
"null",
";",
"}"
] | Loads and returns the content of the specified hash, if available.
@param string $namespace
@param string $hash
@return string|null | [
"Loads",
"and",
"returns",
"the",
"content",
"of",
"the",
"specified",
"hash",
"if",
"available",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Registry/Adapter/FileSystemAdapter.php#L63-L71 |
factorio-item-browser/export-data | src/Registry/Adapter/FileSystemAdapter.php | FileSystemAdapter.delete | public function delete(string $namespace, string $hash): void
{
$fileName = $this->getFileName($namespace, $hash);
if (file_exists($fileName)) {
unlink($fileName);
}
} | php | public function delete(string $namespace, string $hash): void
{
$fileName = $this->getFileName($namespace, $hash);
if (file_exists($fileName)) {
unlink($fileName);
}
} | [
"public",
"function",
"delete",
"(",
"string",
"$",
"namespace",
",",
"string",
"$",
"hash",
")",
":",
"void",
"{",
"$",
"fileName",
"=",
"$",
"this",
"->",
"getFileName",
"(",
"$",
"namespace",
",",
"$",
"hash",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"unlink",
"(",
"$",
"fileName",
")",
";",
"}",
"}"
] | Deletes the content under the specified hash.
@param string $namespace
@param string $hash | [
"Deletes",
"the",
"content",
"under",
"the",
"specified",
"hash",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Registry/Adapter/FileSystemAdapter.php#L78-L84 |
factorio-item-browser/export-data | src/Registry/Adapter/FileSystemAdapter.php | FileSystemAdapter.getFileName | protected function getFileName(string $namespace, string $hash): string
{
$fileName = implode(DIRECTORY_SEPARATOR, [
$this->directory,
$namespace,
substr($hash, 0, 2),
$hash
]);
return $fileName;
} | php | protected function getFileName(string $namespace, string $hash): string
{
$fileName = implode(DIRECTORY_SEPARATOR, [
$this->directory,
$namespace,
substr($hash, 0, 2),
$hash
]);
return $fileName;
} | [
"protected",
"function",
"getFileName",
"(",
"string",
"$",
"namespace",
",",
"string",
"$",
"hash",
")",
":",
"string",
"{",
"$",
"fileName",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"$",
"this",
"->",
"directory",
",",
"$",
"namespace",
",",
"substr",
"(",
"$",
"hash",
",",
"0",
",",
"2",
")",
",",
"$",
"hash",
"]",
")",
";",
"return",
"$",
"fileName",
";",
"}"
] | Returns the filename to use to save the content with the specified namespace and hash.
@param string $namespace
@param string $hash
@return string | [
"Returns",
"the",
"filename",
"to",
"use",
"to",
"save",
"the",
"content",
"with",
"the",
"specified",
"namespace",
"and",
"hash",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Registry/Adapter/FileSystemAdapter.php#L92-L101 |
factorio-item-browser/export-data | src/Registry/Adapter/FileSystemAdapter.php | FileSystemAdapter.ensureDirectory | protected function ensureDirectory(string $directory): void
{
if (!is_dir($directory)) {
$success = @mkdir($directory, 0775, true);
if (!$success && !is_dir($directory)) {
throw new ExportDataException('Unable to create directory ' . $directory . '.');
}
}
if (!is_writable($directory)) {
throw new ExportDataException('Directory ' . $directory . ' is not writable.');
}
} | php | protected function ensureDirectory(string $directory): void
{
if (!is_dir($directory)) {
$success = @mkdir($directory, 0775, true);
if (!$success && !is_dir($directory)) {
throw new ExportDataException('Unable to create directory ' . $directory . '.');
}
}
if (!is_writable($directory)) {
throw new ExportDataException('Directory ' . $directory . ' is not writable.');
}
} | [
"protected",
"function",
"ensureDirectory",
"(",
"string",
"$",
"directory",
")",
":",
"void",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"$",
"success",
"=",
"@",
"mkdir",
"(",
"$",
"directory",
",",
"0775",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"success",
"&&",
"!",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"throw",
"new",
"ExportDataException",
"(",
"'Unable to create directory '",
".",
"$",
"directory",
".",
"'.'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"directory",
")",
")",
"{",
"throw",
"new",
"ExportDataException",
"(",
"'Directory '",
".",
"$",
"directory",
".",
"' is not writable.'",
")",
";",
"}",
"}"
] | Ensures that the specified directory is available and writable.
@param string $directory
@throws ExportDataException | [
"Ensures",
"that",
"the",
"specified",
"directory",
"is",
"available",
"and",
"writable",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Registry/Adapter/FileSystemAdapter.php#L108-L120 |
factorio-item-browser/export-data | src/Registry/Adapter/FileSystemAdapter.php | FileSystemAdapter.getAllHashes | public function getAllHashes(string $namespace): array
{
$directory = implode(DIRECTORY_SEPARATOR, [
$this->directory,
$namespace,
]);
$result = [];
if (is_dir($directory)) {
$directoryIterator = new RecursiveDirectoryIterator(
$directory,
RecursiveDirectoryIterator::SKIP_DOTS
);
foreach (new RecursiveIteratorIterator($directoryIterator) as $file) {
/* @var SplFileInfo $file */
$result[] = $file->getFilename();
}
}
return $result;
} | php | public function getAllHashes(string $namespace): array
{
$directory = implode(DIRECTORY_SEPARATOR, [
$this->directory,
$namespace,
]);
$result = [];
if (is_dir($directory)) {
$directoryIterator = new RecursiveDirectoryIterator(
$directory,
RecursiveDirectoryIterator::SKIP_DOTS
);
foreach (new RecursiveIteratorIterator($directoryIterator) as $file) {
/* @var SplFileInfo $file */
$result[] = $file->getFilename();
}
}
return $result;
} | [
"public",
"function",
"getAllHashes",
"(",
"string",
"$",
"namespace",
")",
":",
"array",
"{",
"$",
"directory",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"$",
"this",
"->",
"directory",
",",
"$",
"namespace",
",",
"]",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"$",
"directoryIterator",
"=",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"directory",
",",
"RecursiveDirectoryIterator",
"::",
"SKIP_DOTS",
")",
";",
"foreach",
"(",
"new",
"RecursiveIteratorIterator",
"(",
"$",
"directoryIterator",
")",
"as",
"$",
"file",
")",
"{",
"/* @var SplFileInfo $file */",
"$",
"result",
"[",
"]",
"=",
"$",
"file",
"->",
"getFilename",
"(",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns all hashes currently known to the adapter.
@param string $namespace
@return array|string[] | [
"Returns",
"all",
"hashes",
"currently",
"known",
"to",
"the",
"adapter",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Registry/Adapter/FileSystemAdapter.php#L127-L147 |
simple-php-mvc/simple-php-mvc | src/MVC/DataBase/Model.php | Model.getInstance | public static function getInstance(PDO $pdo, $table)
{
if (!self::$instance) {
self::$instance = new self($pdo, $table);
}
return self::$instance;
} | php | public static function getInstance(PDO $pdo, $table)
{
if (!self::$instance) {
self::$instance = new self($pdo, $table);
}
return self::$instance;
} | [
"public",
"static",
"function",
"getInstance",
"(",
"PDO",
"$",
"pdo",
",",
"$",
"table",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"instance",
")",
"{",
"self",
"::",
"$",
"instance",
"=",
"new",
"self",
"(",
"$",
"pdo",
",",
"$",
"table",
")",
";",
"}",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] | Get the instance
@access public
@param PDO $pdo
@param string $table
@return Model | [
"Get",
"the",
"instance"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/DataBase/Model.php#L56-L62 |
simple-php-mvc/simple-php-mvc | src/MVC/DataBase/Model.php | Model.delete | protected function delete(array $criteria = array())
{
$conditions = array();
foreach ($criteria as $field => $value) {
$conditions[] = "$field = ?";
}
$sql = "DELETE FROM $this->_table WHERE " . implode(' AND ', $conditions);
$pdos = $this->_pdo->prepare($sql);
$pdos->execute(array_values($criteria));
return $pdos->statement()->rowCount();
} | php | protected function delete(array $criteria = array())
{
$conditions = array();
foreach ($criteria as $field => $value) {
$conditions[] = "$field = ?";
}
$sql = "DELETE FROM $this->_table WHERE " . implode(' AND ', $conditions);
$pdos = $this->_pdo->prepare($sql);
$pdos->execute(array_values($criteria));
return $pdos->statement()->rowCount();
} | [
"protected",
"function",
"delete",
"(",
"array",
"$",
"criteria",
"=",
"array",
"(",
")",
")",
"{",
"$",
"conditions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"criteria",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"$field = ?\"",
";",
"}",
"$",
"sql",
"=",
"\"DELETE FROM $this->_table WHERE \"",
".",
"implode",
"(",
"' AND '",
",",
"$",
"conditions",
")",
";",
"$",
"pdos",
"=",
"$",
"this",
"->",
"_pdo",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"pdos",
"->",
"execute",
"(",
"array_values",
"(",
"$",
"criteria",
")",
")",
";",
"return",
"$",
"pdos",
"->",
"statement",
"(",
")",
"->",
"rowCount",
"(",
")",
";",
"}"
] | Function SQL DELETE
@access protected
@param array $criteria
@return int | [
"Function",
"SQL",
"DELETE"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/DataBase/Model.php#L81-L96 |
simple-php-mvc/simple-php-mvc | src/MVC/DataBase/Model.php | Model.insert | protected function insert(array $data = array())
{
$fields = array();
$values = array();
foreach ($data as $field => $value) {
$fields[] = $field;
$values[] = '?';
}
$sql = "INSERT INTO $this->_table "
. "(" . implode(', ', $fields) . ")"
. "VALUES (" . implode(', ', $values) . ")";
$pdos = $this->_pdo->prepare($sql);
$pdos->execute(array_values($data));
return $pdos->statement()->rowCount();
} | php | protected function insert(array $data = array())
{
$fields = array();
$values = array();
foreach ($data as $field => $value) {
$fields[] = $field;
$values[] = '?';
}
$sql = "INSERT INTO $this->_table "
. "(" . implode(', ', $fields) . ")"
. "VALUES (" . implode(', ', $values) . ")";
$pdos = $this->_pdo->prepare($sql);
$pdos->execute(array_values($data));
return $pdos->statement()->rowCount();
} | [
"protected",
"function",
"insert",
"(",
"array",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"$",
"values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"$",
"field",
";",
"$",
"values",
"[",
"]",
"=",
"'?'",
";",
"}",
"$",
"sql",
"=",
"\"INSERT INTO $this->_table \"",
".",
"\"(\"",
".",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
".",
"\")\"",
".",
"\"VALUES (\"",
".",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
".",
"\")\"",
";",
"$",
"pdos",
"=",
"$",
"this",
"->",
"_pdo",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"pdos",
"->",
"execute",
"(",
"array_values",
"(",
"$",
"data",
")",
")",
";",
"return",
"$",
"pdos",
"->",
"statement",
"(",
")",
"->",
"rowCount",
"(",
")",
";",
"}"
] | Function SQL INSERT
@access protected
@param array $data
@return int | [
"Function",
"SQL",
"INSERT"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/DataBase/Model.php#L104-L123 |
simple-php-mvc/simple-php-mvc | src/MVC/DataBase/Model.php | Model.select | protected function select(array $fields, array $criteria = array(), array $operators = array(), array $conditions = array())
{
$sql = "";
$stringConditions = array();
if ((!empty($criteria) && !empty($operators)) && !empty($conditions)) {
if ((count($criteria) == count($operators) && (count($criteria) - 1) == count($conditions))
&& ((count($operators) -1) != count($conditions) && count($criteria) > 1)) {
throw new \Exception("The number of Criteria, Operators and Conditions are not equals.");
}
$criteriaFields = array_keys($criteria);
$stringConditions[] = "$criteriaFields[0] $operators[0] ?";
for ($i = 1; $i < count($criteriaFields); $i++) {
$j = $i - 1;
$stringConditions[] = "$conditions[$j] $criteriaFields[$i] $operators[$i] ?";
}
$sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table "
. "WHERE " . implode(' ', $stringConditions);
} elseif ((!empty($criteria) && !empty($operators)) && count($criteria) > 1) {
if (count($criteria) != count($operators)) {
throw new \Exception("The number of Criteria and Operators are not equals.");
}
$criteriaFields = array_keys($criteria);
for ($i = 0; $i < count($criteriaFields); $i++) {
$stringConditions[] = "$criteriaFields[$i] $operators[$i] ?";
}
$sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table "
. "WHERE " . implode(' AND ', $stringConditions);
} elseif (!empty($criteria)) {
foreach ($criteria as $field => $value) {
$stringConditions[] = "$field = ?";
}
$sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table "
. "WHERE " . implode(' AND ', $stringConditions);
} elseif (!empty($fields)) {
$sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table";
}
$pdos = $this->_pdo->prepare($sql);
$pdos->execute(array_values($criteria));
return $pdos->fetchAll();
} | php | protected function select(array $fields, array $criteria = array(), array $operators = array(), array $conditions = array())
{
$sql = "";
$stringConditions = array();
if ((!empty($criteria) && !empty($operators)) && !empty($conditions)) {
if ((count($criteria) == count($operators) && (count($criteria) - 1) == count($conditions))
&& ((count($operators) -1) != count($conditions) && count($criteria) > 1)) {
throw new \Exception("The number of Criteria, Operators and Conditions are not equals.");
}
$criteriaFields = array_keys($criteria);
$stringConditions[] = "$criteriaFields[0] $operators[0] ?";
for ($i = 1; $i < count($criteriaFields); $i++) {
$j = $i - 1;
$stringConditions[] = "$conditions[$j] $criteriaFields[$i] $operators[$i] ?";
}
$sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table "
. "WHERE " . implode(' ', $stringConditions);
} elseif ((!empty($criteria) && !empty($operators)) && count($criteria) > 1) {
if (count($criteria) != count($operators)) {
throw new \Exception("The number of Criteria and Operators are not equals.");
}
$criteriaFields = array_keys($criteria);
for ($i = 0; $i < count($criteriaFields); $i++) {
$stringConditions[] = "$criteriaFields[$i] $operators[$i] ?";
}
$sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table "
. "WHERE " . implode(' AND ', $stringConditions);
} elseif (!empty($criteria)) {
foreach ($criteria as $field => $value) {
$stringConditions[] = "$field = ?";
}
$sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table "
. "WHERE " . implode(' AND ', $stringConditions);
} elseif (!empty($fields)) {
$sql = "SELECT " . implode(', ', $fields) . " FROM $this->_table";
}
$pdos = $this->_pdo->prepare($sql);
$pdos->execute(array_values($criteria));
return $pdos->fetchAll();
} | [
"protected",
"function",
"select",
"(",
"array",
"$",
"fields",
",",
"array",
"$",
"criteria",
"=",
"array",
"(",
")",
",",
"array",
"$",
"operators",
"=",
"array",
"(",
")",
",",
"array",
"$",
"conditions",
"=",
"array",
"(",
")",
")",
"{",
"$",
"sql",
"=",
"\"\"",
";",
"$",
"stringConditions",
"=",
"array",
"(",
")",
";",
"if",
"(",
"(",
"!",
"empty",
"(",
"$",
"criteria",
")",
"&&",
"!",
"empty",
"(",
"$",
"operators",
")",
")",
"&&",
"!",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"if",
"(",
"(",
"count",
"(",
"$",
"criteria",
")",
"==",
"count",
"(",
"$",
"operators",
")",
"&&",
"(",
"count",
"(",
"$",
"criteria",
")",
"-",
"1",
")",
"==",
"count",
"(",
"$",
"conditions",
")",
")",
"&&",
"(",
"(",
"count",
"(",
"$",
"operators",
")",
"-",
"1",
")",
"!=",
"count",
"(",
"$",
"conditions",
")",
"&&",
"count",
"(",
"$",
"criteria",
")",
">",
"1",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"The number of Criteria, Operators and Conditions are not equals.\"",
")",
";",
"}",
"$",
"criteriaFields",
"=",
"array_keys",
"(",
"$",
"criteria",
")",
";",
"$",
"stringConditions",
"[",
"]",
"=",
"\"$criteriaFields[0] $operators[0] ?\"",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"criteriaFields",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"j",
"=",
"$",
"i",
"-",
"1",
";",
"$",
"stringConditions",
"[",
"]",
"=",
"\"$conditions[$j] $criteriaFields[$i] $operators[$i] ?\"",
";",
"}",
"$",
"sql",
"=",
"\"SELECT \"",
".",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
".",
"\" FROM $this->_table \"",
".",
"\"WHERE \"",
".",
"implode",
"(",
"' '",
",",
"$",
"stringConditions",
")",
";",
"}",
"elseif",
"(",
"(",
"!",
"empty",
"(",
"$",
"criteria",
")",
"&&",
"!",
"empty",
"(",
"$",
"operators",
")",
")",
"&&",
"count",
"(",
"$",
"criteria",
")",
">",
"1",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"criteria",
")",
"!=",
"count",
"(",
"$",
"operators",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"The number of Criteria and Operators are not equals.\"",
")",
";",
"}",
"$",
"criteriaFields",
"=",
"array_keys",
"(",
"$",
"criteria",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"criteriaFields",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"stringConditions",
"[",
"]",
"=",
"\"$criteriaFields[$i] $operators[$i] ?\"",
";",
"}",
"$",
"sql",
"=",
"\"SELECT \"",
".",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
".",
"\" FROM $this->_table \"",
".",
"\"WHERE \"",
".",
"implode",
"(",
"' AND '",
",",
"$",
"stringConditions",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"criteria",
")",
")",
"{",
"foreach",
"(",
"$",
"criteria",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"stringConditions",
"[",
"]",
"=",
"\"$field = ?\"",
";",
"}",
"$",
"sql",
"=",
"\"SELECT \"",
".",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
".",
"\" FROM $this->_table \"",
".",
"\"WHERE \"",
".",
"implode",
"(",
"' AND '",
",",
"$",
"stringConditions",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"sql",
"=",
"\"SELECT \"",
".",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
".",
"\" FROM $this->_table\"",
";",
"}",
"$",
"pdos",
"=",
"$",
"this",
"->",
"_pdo",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"pdos",
"->",
"execute",
"(",
"array_values",
"(",
"$",
"criteria",
")",
")",
";",
"return",
"$",
"pdos",
"->",
"fetchAll",
"(",
")",
";",
"}"
] | Function SQL SELECT
@access protected
@param array $fields
@param array $criteria
@param array $operators
@param array $conditions
@return array
@throws \Exception | [
"Function",
"SQL",
"SELECT"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/DataBase/Model.php#L135-L185 |
simple-php-mvc/simple-php-mvc | src/MVC/DataBase/Model.php | Model.update | protected function update(array $data = array(), array $criteria)
{
$set = array();
foreach ($data as $columnName => $value) {
$set[] = "$columnName = ?";
}
$params = array_merge(array_values($data), array_values($criteria));
$sql = "UPDATE $this->_table SET " . implode(', ', $set)
. " WHERE " . implode(' = ? AND ', array_keys($criteria)) . " = ?";
$pdos = $this->_pdo->prepare($sql);
$pdos->execute($params);
return $pdos->statement()->rowCount();
} | php | protected function update(array $data = array(), array $criteria)
{
$set = array();
foreach ($data as $columnName => $value) {
$set[] = "$columnName = ?";
}
$params = array_merge(array_values($data), array_values($criteria));
$sql = "UPDATE $this->_table SET " . implode(', ', $set)
. " WHERE " . implode(' = ? AND ', array_keys($criteria)) . " = ?";
$pdos = $this->_pdo->prepare($sql);
$pdos->execute($params);
return $pdos->statement()->rowCount();
} | [
"protected",
"function",
"update",
"(",
"array",
"$",
"data",
"=",
"array",
"(",
")",
",",
"array",
"$",
"criteria",
")",
"{",
"$",
"set",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"columnName",
"=>",
"$",
"value",
")",
"{",
"$",
"set",
"[",
"]",
"=",
"\"$columnName = ?\"",
";",
"}",
"$",
"params",
"=",
"array_merge",
"(",
"array_values",
"(",
"$",
"data",
")",
",",
"array_values",
"(",
"$",
"criteria",
")",
")",
";",
"$",
"sql",
"=",
"\"UPDATE $this->_table SET \"",
".",
"implode",
"(",
"', '",
",",
"$",
"set",
")",
".",
"\" WHERE \"",
".",
"implode",
"(",
"' = ? AND '",
",",
"array_keys",
"(",
"$",
"criteria",
")",
")",
".",
"\" = ?\"",
";",
"$",
"pdos",
"=",
"$",
"this",
"->",
"_pdo",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"pdos",
"->",
"execute",
"(",
"$",
"params",
")",
";",
"return",
"$",
"pdos",
"->",
"statement",
"(",
")",
"->",
"rowCount",
"(",
")",
";",
"}"
] | Function SQL UPDATE
@access protected
@param array $data
@param array $criteria
@return int | [
"Function",
"SQL",
"UPDATE"
] | train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/DataBase/Model.php#L194-L211 |
picamator/CacheManager | src/Data/SearchResult.php | SearchResult.hasData | public function hasData() : bool
{
if (is_null($this->hasData)) {
$this->hasData = count($this->data) > 0;
}
return $this->hasData;
} | php | public function hasData() : bool
{
if (is_null($this->hasData)) {
$this->hasData = count($this->data) > 0;
}
return $this->hasData;
} | [
"public",
"function",
"hasData",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"hasData",
")",
")",
"{",
"$",
"this",
"->",
"hasData",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
")",
">",
"0",
";",
"}",
"return",
"$",
"this",
"->",
"hasData",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Data/SearchResult.php#L67-L74 |
picamator/CacheManager | src/Data/SearchResult.php | SearchResult.count | public function count() : int
{
if (is_null($this->count)) {
$this->count = count($this->data);
}
return $this->count;
} | php | public function count() : int
{
if (is_null($this->count)) {
$this->count = count($this->data);
}
return $this->count;
} | [
"public",
"function",
"count",
"(",
")",
":",
"int",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"count",
")",
")",
"{",
"$",
"this",
"->",
"count",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}",
"return",
"$",
"this",
"->",
"count",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Data/SearchResult.php#L79-L86 |
xinix-technology/norm | src/Norm/Connection/FlatFileConnection.php | FlatFileConnection.prepareDatabaseEcosystem | protected function prepareDatabaseEcosystem()
{
$basePath = realpath('../');
$dbPath = $basePath.'/'.$this->options['dbPath'].'/'.$this->options['database'];
if (! is_dir($dbPath)) {
mkdir($dbPath, 0755, true);
}
$this->dbPath = realpath($dbPath);
} | php | protected function prepareDatabaseEcosystem()
{
$basePath = realpath('../');
$dbPath = $basePath.'/'.$this->options['dbPath'].'/'.$this->options['database'];
if (! is_dir($dbPath)) {
mkdir($dbPath, 0755, true);
}
$this->dbPath = realpath($dbPath);
} | [
"protected",
"function",
"prepareDatabaseEcosystem",
"(",
")",
"{",
"$",
"basePath",
"=",
"realpath",
"(",
"'../'",
")",
";",
"$",
"dbPath",
"=",
"$",
"basePath",
".",
"'/'",
".",
"$",
"this",
"->",
"options",
"[",
"'dbPath'",
"]",
".",
"'/'",
".",
"$",
"this",
"->",
"options",
"[",
"'database'",
"]",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dbPath",
")",
")",
"{",
"mkdir",
"(",
"$",
"dbPath",
",",
"0755",
",",
"true",
")",
";",
"}",
"$",
"this",
"->",
"dbPath",
"=",
"realpath",
"(",
"$",
"dbPath",
")",
";",
"}"
] | Prepare database file and folder structure.
@return void | [
"Prepare",
"database",
"file",
"and",
"folder",
"structure",
"."
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Connection/FlatFileConnection.php#L63-L73 |
xinix-technology/norm | src/Norm/Connection/FlatFileConnection.php | FlatFileConnection.persist | public function persist($collection, array $document)
{
if (is_null($this->dbPath)) {
$this->prepareDatabaseEcosystem();
}
if ($collection instanceof Collection) {
$collectionName = $collection->getName();
} else {
$collectionName = $collection;
$collection = static::factory($collection);
}
if (! isset($document['$id'])) {
$document['$id'] = (string) Uuid::uuid1();
}
$marshalledDocument = $this->marshall($document);
$marshalledDocument['$id'] = $document['$id'];
$fileName = $this->dbPath.'/'.$collectionName.'/'.$marshalledDocument['$id'];
file_put_contents($fileName, json_encode($marshalledDocument));
return $this->unmarshall($marshalledDocument);
} | php | public function persist($collection, array $document)
{
if (is_null($this->dbPath)) {
$this->prepareDatabaseEcosystem();
}
if ($collection instanceof Collection) {
$collectionName = $collection->getName();
} else {
$collectionName = $collection;
$collection = static::factory($collection);
}
if (! isset($document['$id'])) {
$document['$id'] = (string) Uuid::uuid1();
}
$marshalledDocument = $this->marshall($document);
$marshalledDocument['$id'] = $document['$id'];
$fileName = $this->dbPath.'/'.$collectionName.'/'.$marshalledDocument['$id'];
file_put_contents($fileName, json_encode($marshalledDocument));
return $this->unmarshall($marshalledDocument);
} | [
"public",
"function",
"persist",
"(",
"$",
"collection",
",",
"array",
"$",
"document",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"dbPath",
")",
")",
"{",
"$",
"this",
"->",
"prepareDatabaseEcosystem",
"(",
")",
";",
"}",
"if",
"(",
"$",
"collection",
"instanceof",
"Collection",
")",
"{",
"$",
"collectionName",
"=",
"$",
"collection",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"collectionName",
"=",
"$",
"collection",
";",
"$",
"collection",
"=",
"static",
"::",
"factory",
"(",
"$",
"collection",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"document",
"[",
"'$id'",
"]",
")",
")",
"{",
"$",
"document",
"[",
"'$id'",
"]",
"=",
"(",
"string",
")",
"Uuid",
"::",
"uuid1",
"(",
")",
";",
"}",
"$",
"marshalledDocument",
"=",
"$",
"this",
"->",
"marshall",
"(",
"$",
"document",
")",
";",
"$",
"marshalledDocument",
"[",
"'$id'",
"]",
"=",
"$",
"document",
"[",
"'$id'",
"]",
";",
"$",
"fileName",
"=",
"$",
"this",
"->",
"dbPath",
".",
"'/'",
".",
"$",
"collectionName",
".",
"'/'",
".",
"$",
"marshalledDocument",
"[",
"'$id'",
"]",
";",
"file_put_contents",
"(",
"$",
"fileName",
",",
"json_encode",
"(",
"$",
"marshalledDocument",
")",
")",
";",
"return",
"$",
"this",
"->",
"unmarshall",
"(",
"$",
"marshalledDocument",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Connection/FlatFileConnection.php#L86-L112 |
xinix-technology/norm | src/Norm/Connection/FlatFileConnection.php | FlatFileConnection.getCollectionData | public function getCollectionData($collection, $criteria = null)
{
if (is_null($this->dbPath)) {
$this->prepareDatabaseEcosystem();
}
if (! is_dir($this->dbPath.'/'.$collection)) {
mkdir($this->dbPath.'/'.$collection, 0755, true);
}
$rows = array();
if ($handle = opendir($this->dbPath.'/'.$collection)) {
while (false !== ($entry = readdir($handle))) {
if (! in_array($entry, array('.', '..'))) {
if (is_readable($pathToFile = $this->dbPath.'/'.$collection.'/'.$entry)) {
$match = true;
$raw = file_get_contents($pathToFile);
$content = json_decode($raw, true);
if (! is_null($criteria) and ! empty($criteria)) {
if (isset($criteria['!or'])) {
$string = reset(array_values(reset($criteria['!or'])));
if (! preg_match('/'.$string.'/', strtolower($raw))) {
$match = false;
}
} else {
$intersection = array_intersect_assoc($content, $criteria);
if (empty($intersection)) {
$match = false;
}
}
}
if ($match) {
$rows[] = $content;
}
}
}
}
closedir($handle);
}
return $rows;
} | php | public function getCollectionData($collection, $criteria = null)
{
if (is_null($this->dbPath)) {
$this->prepareDatabaseEcosystem();
}
if (! is_dir($this->dbPath.'/'.$collection)) {
mkdir($this->dbPath.'/'.$collection, 0755, true);
}
$rows = array();
if ($handle = opendir($this->dbPath.'/'.$collection)) {
while (false !== ($entry = readdir($handle))) {
if (! in_array($entry, array('.', '..'))) {
if (is_readable($pathToFile = $this->dbPath.'/'.$collection.'/'.$entry)) {
$match = true;
$raw = file_get_contents($pathToFile);
$content = json_decode($raw, true);
if (! is_null($criteria) and ! empty($criteria)) {
if (isset($criteria['!or'])) {
$string = reset(array_values(reset($criteria['!or'])));
if (! preg_match('/'.$string.'/', strtolower($raw))) {
$match = false;
}
} else {
$intersection = array_intersect_assoc($content, $criteria);
if (empty($intersection)) {
$match = false;
}
}
}
if ($match) {
$rows[] = $content;
}
}
}
}
closedir($handle);
}
return $rows;
} | [
"public",
"function",
"getCollectionData",
"(",
"$",
"collection",
",",
"$",
"criteria",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"dbPath",
")",
")",
"{",
"$",
"this",
"->",
"prepareDatabaseEcosystem",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"dbPath",
".",
"'/'",
".",
"$",
"collection",
")",
")",
"{",
"mkdir",
"(",
"$",
"this",
"->",
"dbPath",
".",
"'/'",
".",
"$",
"collection",
",",
"0755",
",",
"true",
")",
";",
"}",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"handle",
"=",
"opendir",
"(",
"$",
"this",
"->",
"dbPath",
".",
"'/'",
".",
"$",
"collection",
")",
")",
"{",
"while",
"(",
"false",
"!==",
"(",
"$",
"entry",
"=",
"readdir",
"(",
"$",
"handle",
")",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"entry",
",",
"array",
"(",
"'.'",
",",
"'..'",
")",
")",
")",
"{",
"if",
"(",
"is_readable",
"(",
"$",
"pathToFile",
"=",
"$",
"this",
"->",
"dbPath",
".",
"'/'",
".",
"$",
"collection",
".",
"'/'",
".",
"$",
"entry",
")",
")",
"{",
"$",
"match",
"=",
"true",
";",
"$",
"raw",
"=",
"file_get_contents",
"(",
"$",
"pathToFile",
")",
";",
"$",
"content",
"=",
"json_decode",
"(",
"$",
"raw",
",",
"true",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"criteria",
")",
"and",
"!",
"empty",
"(",
"$",
"criteria",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"criteria",
"[",
"'!or'",
"]",
")",
")",
"{",
"$",
"string",
"=",
"reset",
"(",
"array_values",
"(",
"reset",
"(",
"$",
"criteria",
"[",
"'!or'",
"]",
")",
")",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/'",
".",
"$",
"string",
".",
"'/'",
",",
"strtolower",
"(",
"$",
"raw",
")",
")",
")",
"{",
"$",
"match",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"$",
"intersection",
"=",
"array_intersect_assoc",
"(",
"$",
"content",
",",
"$",
"criteria",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"intersection",
")",
")",
"{",
"$",
"match",
"=",
"false",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"match",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"$",
"content",
";",
"}",
"}",
"}",
"}",
"closedir",
"(",
"$",
"handle",
")",
";",
"}",
"return",
"$",
"rows",
";",
"}"
] | Getter for specific data for collection
@return array | [
"Getter",
"for",
"specific",
"data",
"for",
"collection"
] | train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Connection/FlatFileConnection.php#L159-L207 |
leedavis81/altr-ego | library/AltrEgo/Adapter/Php54.php | Php54._call | public function _call($name, $arguments)
{
$object = $this->getObject();
$callable = function() use ($name, $arguments, $object){
if (!method_exists($object, $name)) {
throw new \Exception('Unable to invoke method ' . $name . ' on object of class ' . get_class($object));
}
return call_user_func_array(array($object, $name), (array) $arguments);
};
return $this->breakScopeAndExecute($callable);
} | php | public function _call($name, $arguments)
{
$object = $this->getObject();
$callable = function() use ($name, $arguments, $object){
if (!method_exists($object, $name)) {
throw new \Exception('Unable to invoke method ' . $name . ' on object of class ' . get_class($object));
}
return call_user_func_array(array($object, $name), (array) $arguments);
};
return $this->breakScopeAndExecute($callable);
} | [
"public",
"function",
"_call",
"(",
"$",
"name",
",",
"$",
"arguments",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"getObject",
"(",
")",
";",
"$",
"callable",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"name",
",",
"$",
"arguments",
",",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"object",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unable to invoke method '",
".",
"$",
"name",
".",
"' on object of class '",
".",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"object",
",",
"$",
"name",
")",
",",
"(",
"array",
")",
"$",
"arguments",
")",
";",
"}",
";",
"return",
"$",
"this",
"->",
"breakScopeAndExecute",
"(",
"$",
"callable",
")",
";",
"}"
] | (non-PHPdoc)
@see AltrEgo\Adapter.AdapterInterface::_call() | [
"(",
"non",
"-",
"PHPdoc",
")"
] | train | https://github.com/leedavis81/altr-ego/blob/1556556a33c2b6caddef94444522c5bbffc217c7/library/AltrEgo/Adapter/Php54.php#L48-L58 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.