repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.loadJs | final protected function loadJs($src, $fromTheme = false, $once = false) {
if ($once && !$this->canLoadAsset($src, 'js'))
return null;
return '<script type="text/javascript" src="' . $this->getFile($src . '.js', $fromTheme) . '"></script>' . "\n";
} | php | final protected function loadJs($src, $fromTheme = false, $once = false) {
if ($once && !$this->canLoadAsset($src, 'js'))
return null;
return '<script type="text/javascript" src="' . $this->getFile($src . '.js', $fromTheme) . '"></script>' . "\n";
} | [
"final",
"protected",
"function",
"loadJs",
"(",
"$",
"src",
",",
"$",
"fromTheme",
"=",
"false",
",",
"$",
"once",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"once",
"&&",
"!",
"$",
"this",
"->",
"canLoadAsset",
"(",
"$",
"src",
",",
"'js'",
")",
")",
"return",
"null",
";",
"return",
"'<script type=\"text/javascript\" src=\"'",
".",
"$",
"this",
"->",
"getFile",
"(",
"$",
"src",
".",
"'.js'",
",",
"$",
"fromTheme",
")",
".",
"'\"></script>'",
".",
"\"\\n\"",
";",
"}"
]
| Loads a javascript file
@param string $src Filename without the extension with base as ./assets
@param boolean $fromTheme Indicates whether to load the javascript from the theme or current module
@param boolean $once Indicates whether to load the stylesheet only once
@return string|null | [
"Loads",
"a",
"javascript",
"file"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L363-L367 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.loadIcon | final protected function loadIcon($src, $fromTheme = false, $once = true) {
if ($once && !$this->canLoadAsset($src, 'icon'))
return null;
return '<link rel="shortcut icon" href="' . $this->getFile($src, $fromTheme) . '"/>' . "\n";
} | php | final protected function loadIcon($src, $fromTheme = false, $once = true) {
if ($once && !$this->canLoadAsset($src, 'icon'))
return null;
return '<link rel="shortcut icon" href="' . $this->getFile($src, $fromTheme) . '"/>' . "\n";
} | [
"final",
"protected",
"function",
"loadIcon",
"(",
"$",
"src",
",",
"$",
"fromTheme",
"=",
"false",
",",
"$",
"once",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"once",
"&&",
"!",
"$",
"this",
"->",
"canLoadAsset",
"(",
"$",
"src",
",",
"'icon'",
")",
")",
"return",
"null",
";",
"return",
"'<link rel=\"shortcut icon\" href=\"'",
".",
"$",
"this",
"->",
"getFile",
"(",
"$",
"src",
",",
"$",
"fromTheme",
")",
".",
"'\"/>'",
".",
"\"\\n\"",
";",
"}"
]
| Loads the icon for the page
@param string $src Filename with extension and base as ./assets in theme or module
@param boolean $fromTheme Indicates whether to load the icon from the theme or current module
@param boolean $once Indicates whether to load the stylesheet only once
@return string | [
"Loads",
"the",
"icon",
"for",
"the",
"page"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L376-L380 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.canLoadAsset | final protected function canLoadAsset($file, $type) {
$filename = basename($file);
if (in_array($filename, $this->loadedAssets[$type]))
return false;
$this->loadedAssets[$type][] = $filename;
return true;
} | php | final protected function canLoadAsset($file, $type) {
$filename = basename($file);
if (in_array($filename, $this->loadedAssets[$type]))
return false;
$this->loadedAssets[$type][] = $filename;
return true;
} | [
"final",
"protected",
"function",
"canLoadAsset",
"(",
"$",
"file",
",",
"$",
"type",
")",
"{",
"$",
"filename",
"=",
"basename",
"(",
"$",
"file",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"filename",
",",
"$",
"this",
"->",
"loadedAssets",
"[",
"$",
"type",
"]",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"loadedAssets",
"[",
"$",
"type",
"]",
"[",
"]",
"=",
"$",
"filename",
";",
"return",
"true",
";",
"}"
]
| Checks if the asset has not been loaded before
@param string $file
@param stirng $type css|js|icon|misc|update
@return boolean | [
"Checks",
"if",
"the",
"asset",
"has",
"not",
"been",
"loaded",
"before"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L401-L408 | train |
ezra-obiwale/dSCore | src/View/Renderer.php | Renderer.url | final public function url($module, $controller = null, $action = null, array $params = array(), $hash = null) {
return $this->view->url($module, $controller, $action, $params, $hash);
} | php | final public function url($module, $controller = null, $action = null, array $params = array(), $hash = null) {
return $this->view->url($module, $controller, $action, $params, $hash);
} | [
"final",
"public",
"function",
"url",
"(",
"$",
"module",
",",
"$",
"controller",
"=",
"null",
",",
"$",
"action",
"=",
"null",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"hash",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"view",
"->",
"url",
"(",
"$",
"module",
",",
"$",
"controller",
",",
"$",
"action",
",",
"$",
"params",
",",
"$",
"hash",
")",
";",
"}"
]
| Fetches the url path the a resource
@param string|null $module
@param string|null $controller
@param string|null $action
@param array $params
@param string $hash
@return string | [
"Fetches",
"the",
"url",
"path",
"the",
"a",
"resource"
]
| dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/Renderer.php#L429-L431 | train |
Nekland/BaseApi | lib/Nekland/BaseApi/Http/Request.php | Request.getId | public function getId()
{
return base64_encode($this->path . implode('', $this->parameters) . implode('', $this->body) . $this->method);
} | php | public function getId()
{
return base64_encode($this->path . implode('', $this->parameters) . implode('', $this->body) . $this->method);
} | [
"public",
"function",
"getId",
"(",
")",
"{",
"return",
"base64_encode",
"(",
"$",
"this",
"->",
"path",
".",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"parameters",
")",
".",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"body",
")",
".",
"$",
"this",
"->",
"method",
")",
";",
"}"
]
| Return an id unique for this request with identical parameters
@return string | [
"Return",
"an",
"id",
"unique",
"for",
"this",
"request",
"with",
"identical",
"parameters"
]
| c96051b36d6982abf2a8b1f1ec16351bcae2455e | https://github.com/Nekland/BaseApi/blob/c96051b36d6982abf2a8b1f1ec16351bcae2455e/lib/Nekland/BaseApi/Http/Request.php#L234-L237 | train |
OxfordInfoLabs/kinikit-core | src/Exception/SerialisableException.php | SerialisableException.returnWebServiceSerialisableData | public function returnWebServiceSerialisableData(){
$serialisableMap = $this->__getSerialisablePropertyMap();
unset($serialisableMap["trace"]);
unset($serialisableMap["file"]);
unset($serialisableMap["line"]);
unset($serialisableMap["traceAsString"]);
unset($serialisableMap["previous"]);
$serialisableMap["code"] = $this->getSourceException() ? $this->getSourceException()["code"] : $this->getCode();
$serialisableMap["message"] = $this->getSourceException() ? $this->getSourceException()["message"] : $this->getMessage();
unset($serialisableMap["sourceException"]);
return $serialisableMap;
} | php | public function returnWebServiceSerialisableData(){
$serialisableMap = $this->__getSerialisablePropertyMap();
unset($serialisableMap["trace"]);
unset($serialisableMap["file"]);
unset($serialisableMap["line"]);
unset($serialisableMap["traceAsString"]);
unset($serialisableMap["previous"]);
$serialisableMap["code"] = $this->getSourceException() ? $this->getSourceException()["code"] : $this->getCode();
$serialisableMap["message"] = $this->getSourceException() ? $this->getSourceException()["message"] : $this->getMessage();
unset($serialisableMap["sourceException"]);
return $serialisableMap;
} | [
"public",
"function",
"returnWebServiceSerialisableData",
"(",
")",
"{",
"$",
"serialisableMap",
"=",
"$",
"this",
"->",
"__getSerialisablePropertyMap",
"(",
")",
";",
"unset",
"(",
"$",
"serialisableMap",
"[",
"\"trace\"",
"]",
")",
";",
"unset",
"(",
"$",
"serialisableMap",
"[",
"\"file\"",
"]",
")",
";",
"unset",
"(",
"$",
"serialisableMap",
"[",
"\"line\"",
"]",
")",
";",
"unset",
"(",
"$",
"serialisableMap",
"[",
"\"traceAsString\"",
"]",
")",
";",
"unset",
"(",
"$",
"serialisableMap",
"[",
"\"previous\"",
"]",
")",
";",
"$",
"serialisableMap",
"[",
"\"code\"",
"]",
"=",
"$",
"this",
"->",
"getSourceException",
"(",
")",
"?",
"$",
"this",
"->",
"getSourceException",
"(",
")",
"[",
"\"code\"",
"]",
":",
"$",
"this",
"->",
"getCode",
"(",
")",
";",
"$",
"serialisableMap",
"[",
"\"message\"",
"]",
"=",
"$",
"this",
"->",
"getSourceException",
"(",
")",
"?",
"$",
"this",
"->",
"getSourceException",
"(",
")",
"[",
"\"message\"",
"]",
":",
"$",
"this",
"->",
"getMessage",
"(",
")",
";",
"unset",
"(",
"$",
"serialisableMap",
"[",
"\"sourceException\"",
"]",
")",
";",
"return",
"$",
"serialisableMap",
";",
"}"
]
| Return web service serialisable data
@return array | [
"Return",
"web",
"service",
"serialisable",
"data"
]
| edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Exception/SerialisableException.php#L73-L88 | train |
black-lamp/yii2-multi-lang | MultiLangUrlManager.php | MultiLangUrlManager.redirectToLanguage | protected function redirectToLanguage($language)
{
$result = parent::parseRequest($this->_request);
if ($result === false) {
throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
}
list ($route, $params) = $result;
if($language){
$params[$this->languageParam] = $language;
}
$params = $params + $this->_request->getQueryParams();
array_unshift($params, $route);
$url = $this->createUrl($params);
if ($this->suffix==='/' && $route==='') {
$url = rtrim($url, '/').'/';
}
Yii::$app->getResponse()->redirect($url);
if (YII_ENV_TEST) {
throw new Exception(Url::to($url));
} else {
Yii::$app->end();
}
} | php | protected function redirectToLanguage($language)
{
$result = parent::parseRequest($this->_request);
if ($result === false) {
throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'));
}
list ($route, $params) = $result;
if($language){
$params[$this->languageParam] = $language;
}
$params = $params + $this->_request->getQueryParams();
array_unshift($params, $route);
$url = $this->createUrl($params);
if ($this->suffix==='/' && $route==='') {
$url = rtrim($url, '/').'/';
}
Yii::$app->getResponse()->redirect($url);
if (YII_ENV_TEST) {
throw new Exception(Url::to($url));
} else {
Yii::$app->end();
}
} | [
"protected",
"function",
"redirectToLanguage",
"(",
"$",
"language",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"parseRequest",
"(",
"$",
"this",
"->",
"_request",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'Page not found.'",
")",
")",
";",
"}",
"list",
"(",
"$",
"route",
",",
"$",
"params",
")",
"=",
"$",
"result",
";",
"if",
"(",
"$",
"language",
")",
"{",
"$",
"params",
"[",
"$",
"this",
"->",
"languageParam",
"]",
"=",
"$",
"language",
";",
"}",
"$",
"params",
"=",
"$",
"params",
"+",
"$",
"this",
"->",
"_request",
"->",
"getQueryParams",
"(",
")",
";",
"array_unshift",
"(",
"$",
"params",
",",
"$",
"route",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"createUrl",
"(",
"$",
"params",
")",
";",
"if",
"(",
"$",
"this",
"->",
"suffix",
"===",
"'/'",
"&&",
"$",
"route",
"===",
"''",
")",
"{",
"$",
"url",
"=",
"rtrim",
"(",
"$",
"url",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
"->",
"redirect",
"(",
"$",
"url",
")",
";",
"if",
"(",
"YII_ENV_TEST",
")",
"{",
"throw",
"new",
"Exception",
"(",
"Url",
"::",
"to",
"(",
"$",
"url",
")",
")",
";",
"}",
"else",
"{",
"Yii",
"::",
"$",
"app",
"->",
"end",
"(",
")",
";",
"}",
"}"
]
| Redirect to the current URL with given language code applied
@param string $language the language code to add. Can also be empty to not add any language code. | [
"Redirect",
"to",
"the",
"current",
"URL",
"with",
"given",
"language",
"code",
"applied"
]
| 764992aba56a723bb4782cf7ed5b3bdc0c65ef44 | https://github.com/black-lamp/yii2-multi-lang/blob/764992aba56a723bb4782cf7ed5b3bdc0c65ef44/MultiLangUrlManager.php#L270-L296 | train |
Vectrex/vxPHP | src/User/RoleHierarchy.php | RoleHierarchy.getSubRoles | public function getSubRoles(Role $role) {
$parentName = $role->getRoleName();
$subRoles = [];
if(array_key_exists($role->getRoleName(), $this->mappedRoleNames)) {
foreach($this->mappedRoleNames[$parentName] as $subRoleName) {
$subRoles[] = new Role($subRoleName);
}
}
return $subRoles;
} | php | public function getSubRoles(Role $role) {
$parentName = $role->getRoleName();
$subRoles = [];
if(array_key_exists($role->getRoleName(), $this->mappedRoleNames)) {
foreach($this->mappedRoleNames[$parentName] as $subRoleName) {
$subRoles[] = new Role($subRoleName);
}
}
return $subRoles;
} | [
"public",
"function",
"getSubRoles",
"(",
"Role",
"$",
"role",
")",
"{",
"$",
"parentName",
"=",
"$",
"role",
"->",
"getRoleName",
"(",
")",
";",
"$",
"subRoles",
"=",
"[",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"role",
"->",
"getRoleName",
"(",
")",
",",
"$",
"this",
"->",
"mappedRoleNames",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"mappedRoleNames",
"[",
"$",
"parentName",
"]",
"as",
"$",
"subRoleName",
")",
"{",
"$",
"subRoles",
"[",
"]",
"=",
"new",
"Role",
"(",
"$",
"subRoleName",
")",
";",
"}",
"}",
"return",
"$",
"subRoles",
";",
"}"
]
| get all possible sub roles of a role
@param $role the parent role
@return array | [
"get",
"all",
"possible",
"sub",
"roles",
"of",
"a",
"role"
]
| 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/User/RoleHierarchy.php#L64-L79 | train |
Vectrex/vxPHP | src/User/RoleHierarchy.php | RoleHierarchy.buildRoleMap | private function buildRoleMap() {
$this->mappedRoleNames = [];
foreach ($this->hierarchy as $parent => $roles) {
$roles = array_map('strtolower', $roles);
$this->mappedRoleNames[$parent] = $roles;
$additionalRoles = $roles;
$foundParent = [];
// check for every role, whether there are other roles below it
while ($role = array_shift($additionalRoles)) {
if (!isset($this->hierarchy[$role])) {
// role has no further sub-roles defined
continue;
}
$foundParent[] = $role;
foreach ($this->hierarchy[$role] as $roleToAdd) {
$this->mappedRoleNames[$parent][] = $roleToAdd;
}
foreach (array_diff($this->hierarchy[$role], $foundParent) as $roleToAdd) {
$additionalRoles[] = $roleToAdd;
}
}
$this->mappedRoleNames[$parent] = array_unique($this->mappedRoleNames[$parent]);
}
} | php | private function buildRoleMap() {
$this->mappedRoleNames = [];
foreach ($this->hierarchy as $parent => $roles) {
$roles = array_map('strtolower', $roles);
$this->mappedRoleNames[$parent] = $roles;
$additionalRoles = $roles;
$foundParent = [];
// check for every role, whether there are other roles below it
while ($role = array_shift($additionalRoles)) {
if (!isset($this->hierarchy[$role])) {
// role has no further sub-roles defined
continue;
}
$foundParent[] = $role;
foreach ($this->hierarchy[$role] as $roleToAdd) {
$this->mappedRoleNames[$parent][] = $roleToAdd;
}
foreach (array_diff($this->hierarchy[$role], $foundParent) as $roleToAdd) {
$additionalRoles[] = $roleToAdd;
}
}
$this->mappedRoleNames[$parent] = array_unique($this->mappedRoleNames[$parent]);
}
} | [
"private",
"function",
"buildRoleMap",
"(",
")",
"{",
"$",
"this",
"->",
"mappedRoleNames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"hierarchy",
"as",
"$",
"parent",
"=>",
"$",
"roles",
")",
"{",
"$",
"roles",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"roles",
")",
";",
"$",
"this",
"->",
"mappedRoleNames",
"[",
"$",
"parent",
"]",
"=",
"$",
"roles",
";",
"$",
"additionalRoles",
"=",
"$",
"roles",
";",
"$",
"foundParent",
"=",
"[",
"]",
";",
"// check for every role, whether there are other roles below it",
"while",
"(",
"$",
"role",
"=",
"array_shift",
"(",
"$",
"additionalRoles",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"hierarchy",
"[",
"$",
"role",
"]",
")",
")",
"{",
"// role has no further sub-roles defined",
"continue",
";",
"}",
"$",
"foundParent",
"[",
"]",
"=",
"$",
"role",
";",
"foreach",
"(",
"$",
"this",
"->",
"hierarchy",
"[",
"$",
"role",
"]",
"as",
"$",
"roleToAdd",
")",
"{",
"$",
"this",
"->",
"mappedRoleNames",
"[",
"$",
"parent",
"]",
"[",
"]",
"=",
"$",
"roleToAdd",
";",
"}",
"foreach",
"(",
"array_diff",
"(",
"$",
"this",
"->",
"hierarchy",
"[",
"$",
"role",
"]",
",",
"$",
"foundParent",
")",
"as",
"$",
"roleToAdd",
")",
"{",
"$",
"additionalRoles",
"[",
"]",
"=",
"$",
"roleToAdd",
";",
"}",
"}",
"$",
"this",
"->",
"mappedRoleNames",
"[",
"$",
"parent",
"]",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"mappedRoleNames",
"[",
"$",
"parent",
"]",
")",
";",
"}",
"}"
]
| build the map which maps all sub-roles on any level to any of their parent roles
@param array $hierarchy | [
"build",
"the",
"map",
"which",
"maps",
"all",
"sub",
"-",
"roles",
"on",
"any",
"level",
"to",
"any",
"of",
"their",
"parent",
"roles"
]
| 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/User/RoleHierarchy.php#L86-L125 | train |
Dhii/iterator-abstract | src/TrackingIteratorTrait.php | TrackingIteratorTrait._reset | protected function _reset()
{
$tracker = $this->_getTracker();
$this->_resetTracker($tracker);
$iteration = $this->_createIterationFromTracker($tracker);
return $iteration;
} | php | protected function _reset()
{
$tracker = $this->_getTracker();
$this->_resetTracker($tracker);
$iteration = $this->_createIterationFromTracker($tracker);
return $iteration;
} | [
"protected",
"function",
"_reset",
"(",
")",
"{",
"$",
"tracker",
"=",
"$",
"this",
"->",
"_getTracker",
"(",
")",
";",
"$",
"this",
"->",
"_resetTracker",
"(",
"$",
"tracker",
")",
";",
"$",
"iteration",
"=",
"$",
"this",
"->",
"_createIterationFromTracker",
"(",
"$",
"tracker",
")",
";",
"return",
"$",
"iteration",
";",
"}"
]
| Resets the loop and calculates the first iteration.
@since [*next-version*]
@throws RootException If problem resetting.
@return IterationInterface The iteration that represents the new state. | [
"Resets",
"the",
"loop",
"and",
"calculates",
"the",
"first",
"iteration",
"."
]
| 576484183865575ffc2a0d586132741329626fb8 | https://github.com/Dhii/iterator-abstract/blob/576484183865575ffc2a0d586132741329626fb8/src/TrackingIteratorTrait.php#L23-L30 | train |
Dhii/iterator-abstract | src/TrackingIteratorTrait.php | TrackingIteratorTrait._loop | protected function _loop()
{
$tracker = $this->_getTracker();
$this->_advanceTracker($tracker);
$iteration = $this->_createIterationFromTracker($tracker);
return $iteration;
} | php | protected function _loop()
{
$tracker = $this->_getTracker();
$this->_advanceTracker($tracker);
$iteration = $this->_createIterationFromTracker($tracker);
return $iteration;
} | [
"protected",
"function",
"_loop",
"(",
")",
"{",
"$",
"tracker",
"=",
"$",
"this",
"->",
"_getTracker",
"(",
")",
";",
"$",
"this",
"->",
"_advanceTracker",
"(",
"$",
"tracker",
")",
";",
"$",
"iteration",
"=",
"$",
"this",
"->",
"_createIterationFromTracker",
"(",
"$",
"tracker",
")",
";",
"return",
"$",
"iteration",
";",
"}"
]
| Advances the loop and calculates the next iteration.
@since [*next-version*]
@throws RootException If problem looping.
@return IterationInterface The iteration that represents the new state. | [
"Advances",
"the",
"loop",
"and",
"calculates",
"the",
"next",
"iteration",
"."
]
| 576484183865575ffc2a0d586132741329626fb8 | https://github.com/Dhii/iterator-abstract/blob/576484183865575ffc2a0d586132741329626fb8/src/TrackingIteratorTrait.php#L41-L48 | train |
shgysk8zer0/core_api | traits/headers.php | Headers._readHeaders | final protected static function _readHeaders()
{
if (empty(static::$_request_headers)) {
$headers = function_exists('getallheaders') ? getallheaders() : [];
$keys = array_keys($headers);
array_walk($keys, [__CLASS__, '_cleanHeader']);
static::$_request_headers = array_combine($keys, array_values($headers));
}
return static::$_request_headers;
} | php | final protected static function _readHeaders()
{
if (empty(static::$_request_headers)) {
$headers = function_exists('getallheaders') ? getallheaders() : [];
$keys = array_keys($headers);
array_walk($keys, [__CLASS__, '_cleanHeader']);
static::$_request_headers = array_combine($keys, array_values($headers));
}
return static::$_request_headers;
} | [
"final",
"protected",
"static",
"function",
"_readHeaders",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"_request_headers",
")",
")",
"{",
"$",
"headers",
"=",
"function_exists",
"(",
"'getallheaders'",
")",
"?",
"getallheaders",
"(",
")",
":",
"[",
"]",
";",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"headers",
")",
";",
"array_walk",
"(",
"$",
"keys",
",",
"[",
"__CLASS__",
",",
"'_cleanHeader'",
"]",
")",
";",
"static",
"::",
"$",
"_request_headers",
"=",
"array_combine",
"(",
"$",
"keys",
",",
"array_values",
"(",
"$",
"headers",
")",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_request_headers",
";",
"}"
]
| Protected method to get the headers array, cleaned for usage with magic methods
@param void
@return array Headers array | [
"Protected",
"method",
"to",
"get",
"the",
"headers",
"array",
"cleaned",
"for",
"usage",
"with",
"magic",
"methods"
]
| 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/headers.php#L36-L45 | train |
romm/configuration_object | Classes/ConfigurationObjectMapper.php | ConfigurationObjectMapper.doMapping | protected function doMapping($source, $targetType, PropertyMappingConfigurationInterface $configuration, &$currentPropertyPath)
{
if ($source === null) {
return null;
}
$typeConverter = $this->getTypeConverter($source, $targetType, $configuration);
$targetType = ltrim($typeConverter->getTargetTypeForSource($source, $targetType), '\\');
if (Core::get()->classExists($targetType)) {
$targetType = $this->handleMixedType($source, $targetType, $currentPropertyPath);
$source = $this->handleDataPreProcessor($source, $targetType, $currentPropertyPath);
if (MixedTypesResolver::OBJECT_TYPE_NONE === $targetType) {
return null;
}
}
$convertedChildProperties = (is_array($source))
? $this->convertChildProperties($source, $targetType, $typeConverter, $configuration, $currentPropertyPath)
: [];
$this->configurationObjectConversionDTO
->setSource($source)
->setTargetType($targetType)
->setConvertedChildProperties($convertedChildProperties)
->setCurrentPropertyPath($currentPropertyPath)
->setResult(null);
$this->serviceFactory->runServicesFromEvent(ObjectConversionBeforeServiceEventInterface::class, 'objectConversionBefore', $this->configurationObjectConversionDTO);
if (null === $this->configurationObjectConversionDTO->getResult()) {
$result = $typeConverter->convertFrom($source, $targetType, $convertedChildProperties);
$this->configurationObjectConversionDTO->setResult($result);
}
$this->serviceFactory->runServicesFromEvent(ObjectConversionAfterServiceEventInterface::class, 'objectConversionAfter', $this->configurationObjectConversionDTO);
$result = $this->configurationObjectConversionDTO->getResult();
if ($result instanceof Error) {
$this->messages
->forProperty(implode('.', $currentPropertyPath))
->addError($result);
}
return $result;
} | php | protected function doMapping($source, $targetType, PropertyMappingConfigurationInterface $configuration, &$currentPropertyPath)
{
if ($source === null) {
return null;
}
$typeConverter = $this->getTypeConverter($source, $targetType, $configuration);
$targetType = ltrim($typeConverter->getTargetTypeForSource($source, $targetType), '\\');
if (Core::get()->classExists($targetType)) {
$targetType = $this->handleMixedType($source, $targetType, $currentPropertyPath);
$source = $this->handleDataPreProcessor($source, $targetType, $currentPropertyPath);
if (MixedTypesResolver::OBJECT_TYPE_NONE === $targetType) {
return null;
}
}
$convertedChildProperties = (is_array($source))
? $this->convertChildProperties($source, $targetType, $typeConverter, $configuration, $currentPropertyPath)
: [];
$this->configurationObjectConversionDTO
->setSource($source)
->setTargetType($targetType)
->setConvertedChildProperties($convertedChildProperties)
->setCurrentPropertyPath($currentPropertyPath)
->setResult(null);
$this->serviceFactory->runServicesFromEvent(ObjectConversionBeforeServiceEventInterface::class, 'objectConversionBefore', $this->configurationObjectConversionDTO);
if (null === $this->configurationObjectConversionDTO->getResult()) {
$result = $typeConverter->convertFrom($source, $targetType, $convertedChildProperties);
$this->configurationObjectConversionDTO->setResult($result);
}
$this->serviceFactory->runServicesFromEvent(ObjectConversionAfterServiceEventInterface::class, 'objectConversionAfter', $this->configurationObjectConversionDTO);
$result = $this->configurationObjectConversionDTO->getResult();
if ($result instanceof Error) {
$this->messages
->forProperty(implode('.', $currentPropertyPath))
->addError($result);
}
return $result;
} | [
"protected",
"function",
"doMapping",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"PropertyMappingConfigurationInterface",
"$",
"configuration",
",",
"&",
"$",
"currentPropertyPath",
")",
"{",
"if",
"(",
"$",
"source",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"typeConverter",
"=",
"$",
"this",
"->",
"getTypeConverter",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"$",
"configuration",
")",
";",
"$",
"targetType",
"=",
"ltrim",
"(",
"$",
"typeConverter",
"->",
"getTargetTypeForSource",
"(",
"$",
"source",
",",
"$",
"targetType",
")",
",",
"'\\\\'",
")",
";",
"if",
"(",
"Core",
"::",
"get",
"(",
")",
"->",
"classExists",
"(",
"$",
"targetType",
")",
")",
"{",
"$",
"targetType",
"=",
"$",
"this",
"->",
"handleMixedType",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"$",
"currentPropertyPath",
")",
";",
"$",
"source",
"=",
"$",
"this",
"->",
"handleDataPreProcessor",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"$",
"currentPropertyPath",
")",
";",
"if",
"(",
"MixedTypesResolver",
"::",
"OBJECT_TYPE_NONE",
"===",
"$",
"targetType",
")",
"{",
"return",
"null",
";",
"}",
"}",
"$",
"convertedChildProperties",
"=",
"(",
"is_array",
"(",
"$",
"source",
")",
")",
"?",
"$",
"this",
"->",
"convertChildProperties",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"$",
"typeConverter",
",",
"$",
"configuration",
",",
"$",
"currentPropertyPath",
")",
":",
"[",
"]",
";",
"$",
"this",
"->",
"configurationObjectConversionDTO",
"->",
"setSource",
"(",
"$",
"source",
")",
"->",
"setTargetType",
"(",
"$",
"targetType",
")",
"->",
"setConvertedChildProperties",
"(",
"$",
"convertedChildProperties",
")",
"->",
"setCurrentPropertyPath",
"(",
"$",
"currentPropertyPath",
")",
"->",
"setResult",
"(",
"null",
")",
";",
"$",
"this",
"->",
"serviceFactory",
"->",
"runServicesFromEvent",
"(",
"ObjectConversionBeforeServiceEventInterface",
"::",
"class",
",",
"'objectConversionBefore'",
",",
"$",
"this",
"->",
"configurationObjectConversionDTO",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"configurationObjectConversionDTO",
"->",
"getResult",
"(",
")",
")",
"{",
"$",
"result",
"=",
"$",
"typeConverter",
"->",
"convertFrom",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"$",
"convertedChildProperties",
")",
";",
"$",
"this",
"->",
"configurationObjectConversionDTO",
"->",
"setResult",
"(",
"$",
"result",
")",
";",
"}",
"$",
"this",
"->",
"serviceFactory",
"->",
"runServicesFromEvent",
"(",
"ObjectConversionAfterServiceEventInterface",
"::",
"class",
",",
"'objectConversionAfter'",
",",
"$",
"this",
"->",
"configurationObjectConversionDTO",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"configurationObjectConversionDTO",
"->",
"getResult",
"(",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"Error",
")",
"{",
"$",
"this",
"->",
"messages",
"->",
"forProperty",
"(",
"implode",
"(",
"'.'",
",",
"$",
"currentPropertyPath",
")",
")",
"->",
"addError",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Will recursively fill all the properties of the configuration object.
@inheritdoc | [
"Will",
"recursively",
"fill",
"all",
"the",
"properties",
"of",
"the",
"configuration",
"object",
"."
]
| d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/ConfigurationObjectMapper.php#L107-L152 | train |
romm/configuration_object | Classes/ConfigurationObjectMapper.php | ConfigurationObjectMapper.convertChildProperties | protected function convertChildProperties(array $source, $targetType, TypeConverterInterface $typeConverter, PropertyMappingConfigurationInterface $configuration, array &$currentPropertyPath)
{
$convertedChildProperties = [];
$properties = $source;
// If the target is a class, we get its properties, else we assume the source should be converted.
if (Core::get()->classExists($targetType)) {
$properties = $this->getProperties($targetType);
}
foreach ($source as $propertyName => $propertyValue) {
if (array_key_exists($propertyName, $properties)) {
$currentPropertyPath[] = $propertyName;
$targetPropertyType = $typeConverter->getTypeOfChildProperty($targetType, $propertyName, $configuration);
$targetPropertyTypeBis = $this->checkMixedTypeAnnotationForProperty($targetType, $propertyName, $targetPropertyType);
$targetPropertyType = $targetPropertyTypeBis ?: $targetPropertyType;
$targetPropertyValue = (null !== $targetPropertyType)
? $this->doMapping($propertyValue, $targetPropertyType, $configuration, $currentPropertyPath)
: $propertyValue;
array_pop($currentPropertyPath);
if (false === $targetPropertyValue instanceof Error) {
$convertedChildProperties[$propertyName] = $targetPropertyValue;
}
}
}
return $convertedChildProperties;
} | php | protected function convertChildProperties(array $source, $targetType, TypeConverterInterface $typeConverter, PropertyMappingConfigurationInterface $configuration, array &$currentPropertyPath)
{
$convertedChildProperties = [];
$properties = $source;
// If the target is a class, we get its properties, else we assume the source should be converted.
if (Core::get()->classExists($targetType)) {
$properties = $this->getProperties($targetType);
}
foreach ($source as $propertyName => $propertyValue) {
if (array_key_exists($propertyName, $properties)) {
$currentPropertyPath[] = $propertyName;
$targetPropertyType = $typeConverter->getTypeOfChildProperty($targetType, $propertyName, $configuration);
$targetPropertyTypeBis = $this->checkMixedTypeAnnotationForProperty($targetType, $propertyName, $targetPropertyType);
$targetPropertyType = $targetPropertyTypeBis ?: $targetPropertyType;
$targetPropertyValue = (null !== $targetPropertyType)
? $this->doMapping($propertyValue, $targetPropertyType, $configuration, $currentPropertyPath)
: $propertyValue;
array_pop($currentPropertyPath);
if (false === $targetPropertyValue instanceof Error) {
$convertedChildProperties[$propertyName] = $targetPropertyValue;
}
}
}
return $convertedChildProperties;
} | [
"protected",
"function",
"convertChildProperties",
"(",
"array",
"$",
"source",
",",
"$",
"targetType",
",",
"TypeConverterInterface",
"$",
"typeConverter",
",",
"PropertyMappingConfigurationInterface",
"$",
"configuration",
",",
"array",
"&",
"$",
"currentPropertyPath",
")",
"{",
"$",
"convertedChildProperties",
"=",
"[",
"]",
";",
"$",
"properties",
"=",
"$",
"source",
";",
"// If the target is a class, we get its properties, else we assume the source should be converted.",
"if",
"(",
"Core",
"::",
"get",
"(",
")",
"->",
"classExists",
"(",
"$",
"targetType",
")",
")",
"{",
"$",
"properties",
"=",
"$",
"this",
"->",
"getProperties",
"(",
"$",
"targetType",
")",
";",
"}",
"foreach",
"(",
"$",
"source",
"as",
"$",
"propertyName",
"=>",
"$",
"propertyValue",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"propertyName",
",",
"$",
"properties",
")",
")",
"{",
"$",
"currentPropertyPath",
"[",
"]",
"=",
"$",
"propertyName",
";",
"$",
"targetPropertyType",
"=",
"$",
"typeConverter",
"->",
"getTypeOfChildProperty",
"(",
"$",
"targetType",
",",
"$",
"propertyName",
",",
"$",
"configuration",
")",
";",
"$",
"targetPropertyTypeBis",
"=",
"$",
"this",
"->",
"checkMixedTypeAnnotationForProperty",
"(",
"$",
"targetType",
",",
"$",
"propertyName",
",",
"$",
"targetPropertyType",
")",
";",
"$",
"targetPropertyType",
"=",
"$",
"targetPropertyTypeBis",
"?",
":",
"$",
"targetPropertyType",
";",
"$",
"targetPropertyValue",
"=",
"(",
"null",
"!==",
"$",
"targetPropertyType",
")",
"?",
"$",
"this",
"->",
"doMapping",
"(",
"$",
"propertyValue",
",",
"$",
"targetPropertyType",
",",
"$",
"configuration",
",",
"$",
"currentPropertyPath",
")",
":",
"$",
"propertyValue",
";",
"array_pop",
"(",
"$",
"currentPropertyPath",
")",
";",
"if",
"(",
"false",
"===",
"$",
"targetPropertyValue",
"instanceof",
"Error",
")",
"{",
"$",
"convertedChildProperties",
"[",
"$",
"propertyName",
"]",
"=",
"$",
"targetPropertyValue",
";",
"}",
"}",
"}",
"return",
"$",
"convertedChildProperties",
";",
"}"
]
| Will convert all the properties of the given source, depending on the
target type.
@param array $source
@param string $targetType
@param TypeConverterInterface $typeConverter
@param PropertyMappingConfigurationInterface $configuration
@param array $currentPropertyPath
@return array | [
"Will",
"convert",
"all",
"the",
"properties",
"of",
"the",
"given",
"source",
"depending",
"on",
"the",
"target",
"type",
"."
]
| d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/ConfigurationObjectMapper.php#L165-L195 | train |
romm/configuration_object | Classes/ConfigurationObjectMapper.php | ConfigurationObjectMapper.handleDataPreProcessor | protected function handleDataPreProcessor($source, $targetType, $currentPropertyPath)
{
if ($this->serviceFactory->has(ServiceInterface::SERVICE_DATA_PRE_PROCESSOR)) {
/** @var DataPreProcessorService $dataProcessorService */
$dataProcessorService = $this->serviceFactory->get(ServiceInterface::SERVICE_DATA_PRE_PROCESSOR);
$processor = $dataProcessorService->getDataPreProcessor($source, $targetType);
$source = $processor->getData();
$processorResult = $processor->getResult();
if ($processorResult->hasErrors()) {
$this->messages->forProperty(implode('.', $currentPropertyPath))->merge($processorResult);
}
}
return $source;
} | php | protected function handleDataPreProcessor($source, $targetType, $currentPropertyPath)
{
if ($this->serviceFactory->has(ServiceInterface::SERVICE_DATA_PRE_PROCESSOR)) {
/** @var DataPreProcessorService $dataProcessorService */
$dataProcessorService = $this->serviceFactory->get(ServiceInterface::SERVICE_DATA_PRE_PROCESSOR);
$processor = $dataProcessorService->getDataPreProcessor($source, $targetType);
$source = $processor->getData();
$processorResult = $processor->getResult();
if ($processorResult->hasErrors()) {
$this->messages->forProperty(implode('.', $currentPropertyPath))->merge($processorResult);
}
}
return $source;
} | [
"protected",
"function",
"handleDataPreProcessor",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"$",
"currentPropertyPath",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"serviceFactory",
"->",
"has",
"(",
"ServiceInterface",
"::",
"SERVICE_DATA_PRE_PROCESSOR",
")",
")",
"{",
"/** @var DataPreProcessorService $dataProcessorService */",
"$",
"dataProcessorService",
"=",
"$",
"this",
"->",
"serviceFactory",
"->",
"get",
"(",
"ServiceInterface",
"::",
"SERVICE_DATA_PRE_PROCESSOR",
")",
";",
"$",
"processor",
"=",
"$",
"dataProcessorService",
"->",
"getDataPreProcessor",
"(",
"$",
"source",
",",
"$",
"targetType",
")",
";",
"$",
"source",
"=",
"$",
"processor",
"->",
"getData",
"(",
")",
";",
"$",
"processorResult",
"=",
"$",
"processor",
"->",
"getResult",
"(",
")",
";",
"if",
"(",
"$",
"processorResult",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"this",
"->",
"messages",
"->",
"forProperty",
"(",
"implode",
"(",
"'.'",
",",
"$",
"currentPropertyPath",
")",
")",
"->",
"merge",
"(",
"$",
"processorResult",
")",
";",
"}",
"}",
"return",
"$",
"source",
";",
"}"
]
| Will check if the target type is a class, then call functions which will
check the interfaces of the class.
@param mixed $source
@param mixed $targetType
@param array $currentPropertyPath
@return array | [
"Will",
"check",
"if",
"the",
"target",
"type",
"is",
"a",
"class",
"then",
"call",
"functions",
"which",
"will",
"check",
"the",
"interfaces",
"of",
"the",
"class",
"."
]
| d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/ConfigurationObjectMapper.php#L260-L276 | train |
romm/configuration_object | Classes/ConfigurationObjectMapper.php | ConfigurationObjectMapper.getTypeConverter | protected function getTypeConverter($source, $targetType, $configuration)
{
$compositeType = $this->parseCompositeType($targetType);
if (in_array($compositeType, ['\\ArrayObject', 'array'])) {
$typeConverter = $this->objectManager->get(ArrayConverter::class);
} else {
$typeConverter = $this->findTypeConverter($source, $targetType, $configuration);
if ($typeConverter instanceof ExtbaseArrayConverter) {
$typeConverter = $this->objectManager->get(ArrayConverter::class);
} elseif ($typeConverter instanceof ObjectConverter) {
$typeConverter = $this->getObjectConverter();
}
}
if (!is_object($typeConverter) || !$typeConverter instanceof TypeConverterInterface) {
throw new TypeConverterException('Type converter for "' . $source . '" -> "' . $targetType . '" not found.');
}
return $typeConverter;
} | php | protected function getTypeConverter($source, $targetType, $configuration)
{
$compositeType = $this->parseCompositeType($targetType);
if (in_array($compositeType, ['\\ArrayObject', 'array'])) {
$typeConverter = $this->objectManager->get(ArrayConverter::class);
} else {
$typeConverter = $this->findTypeConverter($source, $targetType, $configuration);
if ($typeConverter instanceof ExtbaseArrayConverter) {
$typeConverter = $this->objectManager->get(ArrayConverter::class);
} elseif ($typeConverter instanceof ObjectConverter) {
$typeConverter = $this->getObjectConverter();
}
}
if (!is_object($typeConverter) || !$typeConverter instanceof TypeConverterInterface) {
throw new TypeConverterException('Type converter for "' . $source . '" -> "' . $targetType . '" not found.');
}
return $typeConverter;
} | [
"protected",
"function",
"getTypeConverter",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"$",
"configuration",
")",
"{",
"$",
"compositeType",
"=",
"$",
"this",
"->",
"parseCompositeType",
"(",
"$",
"targetType",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"compositeType",
",",
"[",
"'\\\\ArrayObject'",
",",
"'array'",
"]",
")",
")",
"{",
"$",
"typeConverter",
"=",
"$",
"this",
"->",
"objectManager",
"->",
"get",
"(",
"ArrayConverter",
"::",
"class",
")",
";",
"}",
"else",
"{",
"$",
"typeConverter",
"=",
"$",
"this",
"->",
"findTypeConverter",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"$",
"configuration",
")",
";",
"if",
"(",
"$",
"typeConverter",
"instanceof",
"ExtbaseArrayConverter",
")",
"{",
"$",
"typeConverter",
"=",
"$",
"this",
"->",
"objectManager",
"->",
"get",
"(",
"ArrayConverter",
"::",
"class",
")",
";",
"}",
"elseif",
"(",
"$",
"typeConverter",
"instanceof",
"ObjectConverter",
")",
"{",
"$",
"typeConverter",
"=",
"$",
"this",
"->",
"getObjectConverter",
"(",
")",
";",
"}",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"typeConverter",
")",
"||",
"!",
"$",
"typeConverter",
"instanceof",
"TypeConverterInterface",
")",
"{",
"throw",
"new",
"TypeConverterException",
"(",
"'Type converter for \"'",
".",
"$",
"source",
".",
"'\" -> \"'",
".",
"$",
"targetType",
".",
"'\" not found.'",
")",
";",
"}",
"return",
"$",
"typeConverter",
";",
"}"
]
| This function will fetch the type converter which will convert the source
to the requested target type.
@param mixed $source
@param mixed $targetType
@param mixed $configuration
@return TypeConverterInterface
@throws TypeConverterException | [
"This",
"function",
"will",
"fetch",
"the",
"type",
"converter",
"which",
"will",
"convert",
"the",
"source",
"to",
"the",
"requested",
"target",
"type",
"."
]
| d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/ConfigurationObjectMapper.php#L288-L309 | train |
romm/configuration_object | Classes/ConfigurationObjectMapper.php | ConfigurationObjectMapper.getProperties | protected function getProperties($targetType)
{
$properties = ReflectionService::get()->getClassReflection($targetType)->getProperties();
$propertiesKeys = array_map(
function (PropertyReflection $propertyReflection) {
return $propertyReflection->getName();
},
$properties
);
return array_combine($propertiesKeys, $properties);
} | php | protected function getProperties($targetType)
{
$properties = ReflectionService::get()->getClassReflection($targetType)->getProperties();
$propertiesKeys = array_map(
function (PropertyReflection $propertyReflection) {
return $propertyReflection->getName();
},
$properties
);
return array_combine($propertiesKeys, $properties);
} | [
"protected",
"function",
"getProperties",
"(",
"$",
"targetType",
")",
"{",
"$",
"properties",
"=",
"ReflectionService",
"::",
"get",
"(",
")",
"->",
"getClassReflection",
"(",
"$",
"targetType",
")",
"->",
"getProperties",
"(",
")",
";",
"$",
"propertiesKeys",
"=",
"array_map",
"(",
"function",
"(",
"PropertyReflection",
"$",
"propertyReflection",
")",
"{",
"return",
"$",
"propertyReflection",
"->",
"getName",
"(",
")",
";",
"}",
",",
"$",
"properties",
")",
";",
"return",
"array_combine",
"(",
"$",
"propertiesKeys",
",",
"$",
"properties",
")",
";",
"}"
]
| Internal function that fetches the properties of a class.
@param $targetType
@return array | [
"Internal",
"function",
"that",
"fetches",
"the",
"properties",
"of",
"a",
"class",
"."
]
| d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/ConfigurationObjectMapper.php#L330-L341 | train |
squareproton/Bond | src/Bond/EntityManager.php | EntityManager.register | public function register( $entityClass, $repositoryClass )
{
$entityName = \Bond\get_unqualified_class($entityClass);
if( isset($this->names[$entityName]) ) {
throw new EntityAlreadyRegisteredException( $entityClass, $repositoryClass, $this );
}
$this->names[$entityName] = $entityClass;
$this->registrations[$entityClass] = $repositoryClass;
} | php | public function register( $entityClass, $repositoryClass )
{
$entityName = \Bond\get_unqualified_class($entityClass);
if( isset($this->names[$entityName]) ) {
throw new EntityAlreadyRegisteredException( $entityClass, $repositoryClass, $this );
}
$this->names[$entityName] = $entityClass;
$this->registrations[$entityClass] = $repositoryClass;
} | [
"public",
"function",
"register",
"(",
"$",
"entityClass",
",",
"$",
"repositoryClass",
")",
"{",
"$",
"entityName",
"=",
"\\",
"Bond",
"\\",
"get_unqualified_class",
"(",
"$",
"entityClass",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"names",
"[",
"$",
"entityName",
"]",
")",
")",
"{",
"throw",
"new",
"EntityAlreadyRegisteredException",
"(",
"$",
"entityClass",
",",
"$",
"repositoryClass",
",",
"$",
"this",
")",
";",
"}",
"$",
"this",
"->",
"names",
"[",
"$",
"entityName",
"]",
"=",
"$",
"entityClass",
";",
"$",
"this",
"->",
"registrations",
"[",
"$",
"entityClass",
"]",
"=",
"$",
"repositoryClass",
";",
"}"
]
| Register a entity.
@param String Fully qualified class name of Entity
@param String Fully qualified class name of Repository | [
"Register",
"a",
"entity",
"."
]
| a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/EntityManager.php#L91-L103 | train |
atk14/Files | src/files.php | Files.MkdirForFile | function MkdirForFile($filename,&$error = null,&$error_str = null){
$directory = preg_replace('/[^\/]+$/','',$filename);
if(!strlen($directory)){
$error = true;
$error_str = "can't determine directory name";
return;
}
return self::Mkdir($directory,$error,$error_str);
} | php | function MkdirForFile($filename,&$error = null,&$error_str = null){
$directory = preg_replace('/[^\/]+$/','',$filename);
if(!strlen($directory)){
$error = true;
$error_str = "can't determine directory name";
return;
}
return self::Mkdir($directory,$error,$error_str);
} | [
"function",
"MkdirForFile",
"(",
"$",
"filename",
",",
"&",
"$",
"error",
"=",
"null",
",",
"&",
"$",
"error_str",
"=",
"null",
")",
"{",
"$",
"directory",
"=",
"preg_replace",
"(",
"'/[^\\/]+$/'",
",",
"''",
",",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"strlen",
"(",
"$",
"directory",
")",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"can't determine directory name\"",
";",
"return",
";",
"}",
"return",
"self",
"::",
"Mkdir",
"(",
"$",
"directory",
",",
"$",
"error",
",",
"$",
"error_str",
")",
";",
"}"
]
| Created a directory for the given filename.
```
Files::MkdirForFile("/path/to/a/file.dat");
``` | [
"Created",
"a",
"directory",
"for",
"the",
"given",
"filename",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L92-L100 | train |
atk14/Files | src/files.php | Files.CopyFile | static function CopyFile($from_file,$to_file,&$error = null,&$error_str = null){
$bytes = 0;
$error = false;
$error_str = "";
settype($from_file,"string");
settype($to_file,"string");
$in = fopen($from_file,"r");
if(!$in){
$error = true;
$error_str = "can't open input file for reading";
return $bytes;
}
$__target_file_exists = false;
if(file_exists($to_file)){
$__target_file_exists = true;
}
$out = fopen($to_file,"w");
if(!$out){
$error = true;
$error_str = "can't open output file for writing";
return $bytes;
}
$buffer = "";
while(!feof($in) && $in){
$buffer = fread($in,4096);
fwrite($out,$buffer,strlen($buffer));
$bytes += strlen($buffer);
}
fclose($in);
fclose($out);
//menit modsouboru, jenom, kdyz soubor drive neexistoval
if(!$__target_file_exists){
$_old_umask = umask(0);
$_stat = chmod($to_file,0666);
umask($_old_umask);
if(!$_stat && $error==false){
$error = true;
$error_str = "failed to do chmod on $to_file";
return $bytes;
}
}
return $bytes;
} | php | static function CopyFile($from_file,$to_file,&$error = null,&$error_str = null){
$bytes = 0;
$error = false;
$error_str = "";
settype($from_file,"string");
settype($to_file,"string");
$in = fopen($from_file,"r");
if(!$in){
$error = true;
$error_str = "can't open input file for reading";
return $bytes;
}
$__target_file_exists = false;
if(file_exists($to_file)){
$__target_file_exists = true;
}
$out = fopen($to_file,"w");
if(!$out){
$error = true;
$error_str = "can't open output file for writing";
return $bytes;
}
$buffer = "";
while(!feof($in) && $in){
$buffer = fread($in,4096);
fwrite($out,$buffer,strlen($buffer));
$bytes += strlen($buffer);
}
fclose($in);
fclose($out);
//menit modsouboru, jenom, kdyz soubor drive neexistoval
if(!$__target_file_exists){
$_old_umask = umask(0);
$_stat = chmod($to_file,0666);
umask($_old_umask);
if(!$_stat && $error==false){
$error = true;
$error_str = "failed to do chmod on $to_file";
return $bytes;
}
}
return $bytes;
} | [
"static",
"function",
"CopyFile",
"(",
"$",
"from_file",
",",
"$",
"to_file",
",",
"&",
"$",
"error",
"=",
"null",
",",
"&",
"$",
"error_str",
"=",
"null",
")",
"{",
"$",
"bytes",
"=",
"0",
";",
"$",
"error",
"=",
"false",
";",
"$",
"error_str",
"=",
"\"\"",
";",
"settype",
"(",
"$",
"from_file",
",",
"\"string\"",
")",
";",
"settype",
"(",
"$",
"to_file",
",",
"\"string\"",
")",
";",
"$",
"in",
"=",
"fopen",
"(",
"$",
"from_file",
",",
"\"r\"",
")",
";",
"if",
"(",
"!",
"$",
"in",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"can't open input file for reading\"",
";",
"return",
"$",
"bytes",
";",
"}",
"$",
"__target_file_exists",
"=",
"false",
";",
"if",
"(",
"file_exists",
"(",
"$",
"to_file",
")",
")",
"{",
"$",
"__target_file_exists",
"=",
"true",
";",
"}",
"$",
"out",
"=",
"fopen",
"(",
"$",
"to_file",
",",
"\"w\"",
")",
";",
"if",
"(",
"!",
"$",
"out",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"can't open output file for writing\"",
";",
"return",
"$",
"bytes",
";",
"}",
"$",
"buffer",
"=",
"\"\"",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"in",
")",
"&&",
"$",
"in",
")",
"{",
"$",
"buffer",
"=",
"fread",
"(",
"$",
"in",
",",
"4096",
")",
";",
"fwrite",
"(",
"$",
"out",
",",
"$",
"buffer",
",",
"strlen",
"(",
"$",
"buffer",
")",
")",
";",
"$",
"bytes",
"+=",
"strlen",
"(",
"$",
"buffer",
")",
";",
"}",
"fclose",
"(",
"$",
"in",
")",
";",
"fclose",
"(",
"$",
"out",
")",
";",
"//menit modsouboru, jenom, kdyz soubor drive neexistoval",
"if",
"(",
"!",
"$",
"__target_file_exists",
")",
"{",
"$",
"_old_umask",
"=",
"umask",
"(",
"0",
")",
";",
"$",
"_stat",
"=",
"chmod",
"(",
"$",
"to_file",
",",
"0666",
")",
";",
"umask",
"(",
"$",
"_old_umask",
")",
";",
"if",
"(",
"!",
"$",
"_stat",
"&&",
"$",
"error",
"==",
"false",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"failed to do chmod on $to_file\"",
";",
"return",
"$",
"bytes",
";",
"}",
"}",
"return",
"$",
"bytes",
";",
"}"
]
| Creates a copy of a file.
When the target file does not exist, it is created with permissions 0666.
@param string $from_file Source file
@param string $to_file Target file
@param boolean &$error Error flag
@param string &$error_str Error message
@return int Number of copied bytes | [
"Creates",
"a",
"copy",
"of",
"a",
"file",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L114-L164 | train |
atk14/Files | src/files.php | Files.AppendToFile | static function AppendToFile($file,$content,&$error = null,&$error_str = null){
return Files::WriteToFile($file,$content,$error,$error_str,array("file_open_mode" => "a"));
} | php | static function AppendToFile($file,$content,&$error = null,&$error_str = null){
return Files::WriteToFile($file,$content,$error,$error_str,array("file_open_mode" => "a"));
} | [
"static",
"function",
"AppendToFile",
"(",
"$",
"file",
",",
"$",
"content",
",",
"&",
"$",
"error",
"=",
"null",
",",
"&",
"$",
"error_str",
"=",
"null",
")",
"{",
"return",
"Files",
"::",
"WriteToFile",
"(",
"$",
"file",
",",
"$",
"content",
",",
"$",
"error",
",",
"$",
"error_str",
",",
"array",
"(",
"\"file_open_mode\"",
"=>",
"\"a\"",
")",
")",
";",
"}"
]
| Appends content to the given file.
Opens a file in append mode and appends content to the end of it.
@param string $file name of the file to append the $content to
@param string $content
@param boolean &$error flag indicating that something went wrong
@param string &$error_str message describing the error
@return int number of bytes written to the file | [
"Appends",
"content",
"to",
"the",
"given",
"file",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L246-L248 | train |
atk14/Files | src/files.php | Files.IsUploadedFile | static function IsUploadedFile($filename){
settype($filename,"string");
if(!file_exists($filename)){
return false;
}
if(is_dir($filename)){
return false;
}
if(!is_uploaded_file($filename)){
return false;
}
if(fileowner($filename)!=posix_getuid() && !fileowner($filename)){
return false;
}
// nasl. podminka byla vyhozena - uzivatel prece muze uploadnout prazdny soubor...
//if(filesize($filename)==0){
// return false;
//}
return true;
} | php | static function IsUploadedFile($filename){
settype($filename,"string");
if(!file_exists($filename)){
return false;
}
if(is_dir($filename)){
return false;
}
if(!is_uploaded_file($filename)){
return false;
}
if(fileowner($filename)!=posix_getuid() && !fileowner($filename)){
return false;
}
// nasl. podminka byla vyhozena - uzivatel prece muze uploadnout prazdny soubor...
//if(filesize($filename)==0){
// return false;
//}
return true;
} | [
"static",
"function",
"IsUploadedFile",
"(",
"$",
"filename",
")",
"{",
"settype",
"(",
"$",
"filename",
",",
"\"string\"",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_uploaded_file",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"fileowner",
"(",
"$",
"filename",
")",
"!=",
"posix_getuid",
"(",
")",
"&&",
"!",
"fileowner",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"false",
";",
"}",
"// nasl. podminka byla vyhozena - uzivatel prece muze uploadnout prazdny soubor...",
"//if(filesize($filename)==0){",
"//\treturn false;",
"//}",
"return",
"true",
";",
"}"
]
| Checks if a file was uploaded via HTTP POST request.
@param string $filename Name of a file
@return bool true => file was securely uploaded; false => file was not uploaded
@see is_uploaded_file | [
"Checks",
"if",
"a",
"file",
"was",
"uploaded",
"via",
"HTTP",
"POST",
"request",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L258-L278 | train |
atk14/Files | src/files.php | Files.MoveFile | static function MoveFile($from_file,$to_file,&$error = null,&$error_str = null){
$error = false;
$error_str = "";
settype($from_file,"string");
settype($to_file,"string");
if(is_dir($to_file) && file_exists($from_file) && !is_dir($from_file)){
// copying a file to an existing directory
preg_match('/([^\/]+)$/',$from_file,$matches);
$to_file .= "/$matches[1]";
}elseif(is_dir($to_file) && file_exists($from_file) && is_dir($from_file)){
// copying a directory to an existing directory
preg_match('/([^\/]+)\/*$/',$from_file,$matches);
$to_file .= "/$matches[1]";
}
if($from_file==$to_file){
$error = true;
$error_str = "from_file and to_file are the same files";
return 0;
}
$_stat = rename($from_file,$to_file);
if(!$_stat){
$error = true;
$error_str = "can't rename $from_file to $to_file";
return 0;
}
return 1;
} | php | static function MoveFile($from_file,$to_file,&$error = null,&$error_str = null){
$error = false;
$error_str = "";
settype($from_file,"string");
settype($to_file,"string");
if(is_dir($to_file) && file_exists($from_file) && !is_dir($from_file)){
// copying a file to an existing directory
preg_match('/([^\/]+)$/',$from_file,$matches);
$to_file .= "/$matches[1]";
}elseif(is_dir($to_file) && file_exists($from_file) && is_dir($from_file)){
// copying a directory to an existing directory
preg_match('/([^\/]+)\/*$/',$from_file,$matches);
$to_file .= "/$matches[1]";
}
if($from_file==$to_file){
$error = true;
$error_str = "from_file and to_file are the same files";
return 0;
}
$_stat = rename($from_file,$to_file);
if(!$_stat){
$error = true;
$error_str = "can't rename $from_file to $to_file";
return 0;
}
return 1;
} | [
"static",
"function",
"MoveFile",
"(",
"$",
"from_file",
",",
"$",
"to_file",
",",
"&",
"$",
"error",
"=",
"null",
",",
"&",
"$",
"error_str",
"=",
"null",
")",
"{",
"$",
"error",
"=",
"false",
";",
"$",
"error_str",
"=",
"\"\"",
";",
"settype",
"(",
"$",
"from_file",
",",
"\"string\"",
")",
";",
"settype",
"(",
"$",
"to_file",
",",
"\"string\"",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"to_file",
")",
"&&",
"file_exists",
"(",
"$",
"from_file",
")",
"&&",
"!",
"is_dir",
"(",
"$",
"from_file",
")",
")",
"{",
"// copying a file to an existing directory",
"preg_match",
"(",
"'/([^\\/]+)$/'",
",",
"$",
"from_file",
",",
"$",
"matches",
")",
";",
"$",
"to_file",
".=",
"\"/$matches[1]\"",
";",
"}",
"elseif",
"(",
"is_dir",
"(",
"$",
"to_file",
")",
"&&",
"file_exists",
"(",
"$",
"from_file",
")",
"&&",
"is_dir",
"(",
"$",
"from_file",
")",
")",
"{",
"// copying a directory to an existing directory",
"preg_match",
"(",
"'/([^\\/]+)\\/*$/'",
",",
"$",
"from_file",
",",
"$",
"matches",
")",
";",
"$",
"to_file",
".=",
"\"/$matches[1]\"",
";",
"}",
"if",
"(",
"$",
"from_file",
"==",
"$",
"to_file",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"from_file and to_file are the same files\"",
";",
"return",
"0",
";",
"}",
"$",
"_stat",
"=",
"rename",
"(",
"$",
"from_file",
",",
"$",
"to_file",
")",
";",
"if",
"(",
"!",
"$",
"_stat",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"can't rename $from_file to $to_file\"",
";",
"return",
"0",
";",
"}",
"return",
"1",
";",
"}"
]
| Moves a file or a directory
```
Files::MoveFile("/path/to/file","/path/to/another/file",$error,$error_str);
Files::MoveFile("/path/to/file","/path/to/directory/",$error,$error_str);
Files::MoveFile("/path/to/directory/","/path/to/another/directory/",$error,$error_str);
```
@param string $from_file Source file
@param string $to_file Target file
@param boolean &$error Error flag
@param string &$error_str Error description
@return int number of moved files; ie. on success return 1 | [
"Moves",
"a",
"file",
"or",
"a",
"directory"
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L295-L327 | train |
atk14/Files | src/files.php | Files.Unlink | static function Unlink($file,&$error = null,&$error_str = null){
$error = false;
$error_str = "";
if(!file_exists($file)){
return 0;
}
$stat = unlink($file);
if(!$stat){
$error = true;
$error_str = "cannot unlink $file";
return 0;
}
return 1;
} | php | static function Unlink($file,&$error = null,&$error_str = null){
$error = false;
$error_str = "";
if(!file_exists($file)){
return 0;
}
$stat = unlink($file);
if(!$stat){
$error = true;
$error_str = "cannot unlink $file";
return 0;
}
return 1;
} | [
"static",
"function",
"Unlink",
"(",
"$",
"file",
",",
"&",
"$",
"error",
"=",
"null",
",",
"&",
"$",
"error_str",
"=",
"null",
")",
"{",
"$",
"error",
"=",
"false",
";",
"$",
"error_str",
"=",
"\"\"",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"0",
";",
"}",
"$",
"stat",
"=",
"unlink",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"$",
"stat",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"cannot unlink $file\"",
";",
"return",
"0",
";",
"}",
"return",
"1",
";",
"}"
]
| Removes a file from filesystem.
@param string $file Name of a file
@param boolean &$error Error flag
@param string &$error_str Error description
@return int Number of deleted files; on success returns 1; otherwise 0 | [
"Removes",
"a",
"file",
"from",
"filesystem",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L337-L354 | train |
atk14/Files | src/files.php | Files._RecursiveUnlinkDir | static function _RecursiveUnlinkDir($dir,&$error,&$error_str){
settype($dir,"string");
$out = 0;
if($error){
return $out;
}
if($dir==""){ return; }
if($dir[strlen($dir)-1]=="/"){
$dir = preg_replace('/\/$/','',$dir);
}
if($dir==""){ return; }
if(!file_exists($dir)){
return 0;
}
$dir .= "/";
$dir_handle = opendir($dir);
if(!$dir_handle){
return 0;
}
while(($item = readdir($dir_handle))!==false){
if($item=="." || $item==".." || $item==""){
continue;
}
if(is_dir($dir.$item)){
$out += Files::_RecursiveUnlinkDir($dir.$item,$error,$error_str);
//2005-10-21: nasledujici continue tady chybel, skript se proto chybne pokousel volat fci unlink na adresar
continue;
}
if($error){ break; }
//going to unlink file: $dir$item
$stat = unlink("$dir$item");
if(!$stat){
$error = true;
$error_str = "cannot unlink $dir$item";
}else{
$out++;
}
}
closedir($dir_handle);
if($error){ return; }
//going to unlink dir: $dir$item
$stat = rmdir($dir);
if(!$stat){
$error = true;
$error_str = "cannot unlink $dir";
}else{
$out++;
}
return $out;
} | php | static function _RecursiveUnlinkDir($dir,&$error,&$error_str){
settype($dir,"string");
$out = 0;
if($error){
return $out;
}
if($dir==""){ return; }
if($dir[strlen($dir)-1]=="/"){
$dir = preg_replace('/\/$/','',$dir);
}
if($dir==""){ return; }
if(!file_exists($dir)){
return 0;
}
$dir .= "/";
$dir_handle = opendir($dir);
if(!$dir_handle){
return 0;
}
while(($item = readdir($dir_handle))!==false){
if($item=="." || $item==".." || $item==""){
continue;
}
if(is_dir($dir.$item)){
$out += Files::_RecursiveUnlinkDir($dir.$item,$error,$error_str);
//2005-10-21: nasledujici continue tady chybel, skript se proto chybne pokousel volat fci unlink na adresar
continue;
}
if($error){ break; }
//going to unlink file: $dir$item
$stat = unlink("$dir$item");
if(!$stat){
$error = true;
$error_str = "cannot unlink $dir$item";
}else{
$out++;
}
}
closedir($dir_handle);
if($error){ return; }
//going to unlink dir: $dir$item
$stat = rmdir($dir);
if(!$stat){
$error = true;
$error_str = "cannot unlink $dir";
}else{
$out++;
}
return $out;
} | [
"static",
"function",
"_RecursiveUnlinkDir",
"(",
"$",
"dir",
",",
"&",
"$",
"error",
",",
"&",
"$",
"error_str",
")",
"{",
"settype",
"(",
"$",
"dir",
",",
"\"string\"",
")",
";",
"$",
"out",
"=",
"0",
";",
"if",
"(",
"$",
"error",
")",
"{",
"return",
"$",
"out",
";",
"}",
"if",
"(",
"$",
"dir",
"==",
"\"\"",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"dir",
"[",
"strlen",
"(",
"$",
"dir",
")",
"-",
"1",
"]",
"==",
"\"/\"",
")",
"{",
"$",
"dir",
"=",
"preg_replace",
"(",
"'/\\/$/'",
",",
"''",
",",
"$",
"dir",
")",
";",
"}",
"if",
"(",
"$",
"dir",
"==",
"\"\"",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"return",
"0",
";",
"}",
"$",
"dir",
".=",
"\"/\"",
";",
"$",
"dir_handle",
"=",
"opendir",
"(",
"$",
"dir",
")",
";",
"if",
"(",
"!",
"$",
"dir_handle",
")",
"{",
"return",
"0",
";",
"}",
"while",
"(",
"(",
"$",
"item",
"=",
"readdir",
"(",
"$",
"dir_handle",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"item",
"==",
"\".\"",
"||",
"$",
"item",
"==",
"\"..\"",
"||",
"$",
"item",
"==",
"\"\"",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
".",
"$",
"item",
")",
")",
"{",
"$",
"out",
"+=",
"Files",
"::",
"_RecursiveUnlinkDir",
"(",
"$",
"dir",
".",
"$",
"item",
",",
"$",
"error",
",",
"$",
"error_str",
")",
";",
"//2005-10-21: nasledujici continue tady chybel, skript se proto chybne pokousel volat fci unlink na adresar",
"continue",
";",
"}",
"if",
"(",
"$",
"error",
")",
"{",
"break",
";",
"}",
"//going to unlink file: $dir$item",
"$",
"stat",
"=",
"unlink",
"(",
"\"$dir$item\"",
")",
";",
"if",
"(",
"!",
"$",
"stat",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"cannot unlink $dir$item\"",
";",
"}",
"else",
"{",
"$",
"out",
"++",
";",
"}",
"}",
"closedir",
"(",
"$",
"dir_handle",
")",
";",
"if",
"(",
"$",
"error",
")",
"{",
"return",
";",
"}",
"//going to unlink dir: $dir$item",
"$",
"stat",
"=",
"rmdir",
"(",
"$",
"dir",
")",
";",
"if",
"(",
"!",
"$",
"stat",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"cannot unlink $dir\"",
";",
"}",
"else",
"{",
"$",
"out",
"++",
";",
"}",
"return",
"$",
"out",
";",
"}"
]
| Internal method making main part of RecursiveUnlinkDir call
@param string $dir Directory name
@param boolean &$error Error flag
@param string &$error_str Error description
@return int pocet smazanych souboru a adresaru
@ignore
@internal We should consider making this method private | [
"Internal",
"method",
"making",
"main",
"part",
"of",
"RecursiveUnlinkDir",
"call"
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L384-L441 | train |
atk14/Files | src/files.php | Files.GetFileContent | static function GetFileContent($filename,&$error = null,&$error_str = null){
$error = false;
$error_str = "";
$out = "";
settype($filename,"string");
if(!is_file($filename)){
$error = true;
$error_str = "$filename is not a file";
return null;
}
$filesize = filesize($filename);
if($filesize==0){ return ""; }
$f = fopen($filename,"r");
if(!$f){
$error = false;
$error_str = "can't open file $filename for writing";
return $out;
}
$out = fread($f,$filesize);
fclose($f);
return $out;
} | php | static function GetFileContent($filename,&$error = null,&$error_str = null){
$error = false;
$error_str = "";
$out = "";
settype($filename,"string");
if(!is_file($filename)){
$error = true;
$error_str = "$filename is not a file";
return null;
}
$filesize = filesize($filename);
if($filesize==0){ return ""; }
$f = fopen($filename,"r");
if(!$f){
$error = false;
$error_str = "can't open file $filename for writing";
return $out;
}
$out = fread($f,$filesize);
fclose($f);
return $out;
} | [
"static",
"function",
"GetFileContent",
"(",
"$",
"filename",
",",
"&",
"$",
"error",
"=",
"null",
",",
"&",
"$",
"error_str",
"=",
"null",
")",
"{",
"$",
"error",
"=",
"false",
";",
"$",
"error_str",
"=",
"\"\"",
";",
"$",
"out",
"=",
"\"\"",
";",
"settype",
"(",
"$",
"filename",
",",
"\"string\"",
")",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"$filename is not a file\"",
";",
"return",
"null",
";",
"}",
"$",
"filesize",
"=",
"filesize",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"$",
"filesize",
"==",
"0",
")",
"{",
"return",
"\"\"",
";",
"}",
"$",
"f",
"=",
"fopen",
"(",
"$",
"filename",
",",
"\"r\"",
")",
";",
"if",
"(",
"!",
"$",
"f",
")",
"{",
"$",
"error",
"=",
"false",
";",
"$",
"error_str",
"=",
"\"can't open file $filename for writing\"",
";",
"return",
"$",
"out",
";",
"}",
"$",
"out",
"=",
"fread",
"(",
"$",
"f",
",",
"$",
"filesize",
")",
";",
"fclose",
"(",
"$",
"f",
")",
";",
"return",
"$",
"out",
";",
"}"
]
| Reads content of a file.
@param string $filename Name of a file
@param boolean &$error Error flag
@param string &$error_str Error description
@return string Content of a file | [
"Reads",
"content",
"of",
"a",
"file",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L451-L478 | train |
atk14/Files | src/files.php | Files.IsReadableAndWritable | static function IsReadableAndWritable($filename,&$error = null,&$error_str = null){
$error = false;
$error_str = "";
settype($filename,"string");
if(!file_exists($filename)){
$error = true;
$error_str = "file does't exist";
return 0;
}
$_UID_ = posix_getuid();
$_FILE_OWNER = fileowner($filename);
$_FILE_PERMS = fileperms($filename);
if(!(
(($_FILE_OWNER!=$_UID_) && (((int)$_FILE_PERMS&(int)bindec("110")))==(int)bindec("110")) ||
(($_FILE_OWNER==$_UID_) && (((int)$_FILE_PERMS&(int)bindec("110000000"))==(int)bindec("110000000")))
)){
return 0;
}
return 1;
} | php | static function IsReadableAndWritable($filename,&$error = null,&$error_str = null){
$error = false;
$error_str = "";
settype($filename,"string");
if(!file_exists($filename)){
$error = true;
$error_str = "file does't exist";
return 0;
}
$_UID_ = posix_getuid();
$_FILE_OWNER = fileowner($filename);
$_FILE_PERMS = fileperms($filename);
if(!(
(($_FILE_OWNER!=$_UID_) && (((int)$_FILE_PERMS&(int)bindec("110")))==(int)bindec("110")) ||
(($_FILE_OWNER==$_UID_) && (((int)$_FILE_PERMS&(int)bindec("110000000"))==(int)bindec("110000000")))
)){
return 0;
}
return 1;
} | [
"static",
"function",
"IsReadableAndWritable",
"(",
"$",
"filename",
",",
"&",
"$",
"error",
"=",
"null",
",",
"&",
"$",
"error_str",
"=",
"null",
")",
"{",
"$",
"error",
"=",
"false",
";",
"$",
"error_str",
"=",
"\"\"",
";",
"settype",
"(",
"$",
"filename",
",",
"\"string\"",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"error",
"=",
"true",
";",
"$",
"error_str",
"=",
"\"file does't exist\"",
";",
"return",
"0",
";",
"}",
"$",
"_UID_",
"=",
"posix_getuid",
"(",
")",
";",
"$",
"_FILE_OWNER",
"=",
"fileowner",
"(",
"$",
"filename",
")",
";",
"$",
"_FILE_PERMS",
"=",
"fileperms",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"(",
"(",
"(",
"$",
"_FILE_OWNER",
"!=",
"$",
"_UID_",
")",
"&&",
"(",
"(",
"(",
"int",
")",
"$",
"_FILE_PERMS",
"&",
"(",
"int",
")",
"bindec",
"(",
"\"110\"",
")",
")",
")",
"==",
"(",
"int",
")",
"bindec",
"(",
"\"110\"",
")",
")",
"||",
"(",
"(",
"$",
"_FILE_OWNER",
"==",
"$",
"_UID_",
")",
"&&",
"(",
"(",
"(",
"int",
")",
"$",
"_FILE_PERMS",
"&",
"(",
"int",
")",
"bindec",
"(",
"\"110000000\"",
")",
")",
"==",
"(",
"int",
")",
"bindec",
"(",
"\"110000000\"",
")",
")",
")",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"1",
";",
"}"
]
| Checks if a file is both readable and writable.
@param string $filename Name of a file
@param boolean &$error Error flag
@param string &$error_str Error description
@return int 1 - is readable and writable; 0 - is not | [
"Checks",
"if",
"a",
"file",
"is",
"both",
"readable",
"and",
"writable",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L488-L510 | train |
atk14/Files | src/files.php | Files.GetImageSize | static function GetImageSize($image_content,&$error = null,&$error_str = null){
$temp = defined("TEMP") ? TEMP : "/tmp";
$filename = $temp."/get_image_filename_".posix_getpid();
if(!Files::WriteToFile($filename,$image_content,$error,$error_str)){ return null; }
$out = getimagesize($filename);
Files::Unlink($filename,$error,$error_str);
if(!is_array($out)){ $out = null; }
return $out;
} | php | static function GetImageSize($image_content,&$error = null,&$error_str = null){
$temp = defined("TEMP") ? TEMP : "/tmp";
$filename = $temp."/get_image_filename_".posix_getpid();
if(!Files::WriteToFile($filename,$image_content,$error,$error_str)){ return null; }
$out = getimagesize($filename);
Files::Unlink($filename,$error,$error_str);
if(!is_array($out)){ $out = null; }
return $out;
} | [
"static",
"function",
"GetImageSize",
"(",
"$",
"image_content",
",",
"&",
"$",
"error",
"=",
"null",
",",
"&",
"$",
"error_str",
"=",
"null",
")",
"{",
"$",
"temp",
"=",
"defined",
"(",
"\"TEMP\"",
")",
"?",
"TEMP",
":",
"\"/tmp\"",
";",
"$",
"filename",
"=",
"$",
"temp",
".",
"\"/get_image_filename_\"",
".",
"posix_getpid",
"(",
")",
";",
"if",
"(",
"!",
"Files",
"::",
"WriteToFile",
"(",
"$",
"filename",
",",
"$",
"image_content",
",",
"$",
"error",
",",
"$",
"error_str",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"out",
"=",
"getimagesize",
"(",
"$",
"filename",
")",
";",
"Files",
"::",
"Unlink",
"(",
"$",
"filename",
",",
"$",
"error",
",",
"$",
"error_str",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"out",
")",
")",
"{",
"$",
"out",
"=",
"null",
";",
"}",
"return",
"$",
"out",
";",
"}"
]
| Determines width and height of an image in parameter.
Example
```
list($width,$height) = Files::GetImageSize($image_content,$err,$err_str);
```
@param string $image_content Binary image data
@param boolean $error Error flag
@param string $error_str Error description
@return array Image dimensions | [
"Determines",
"width",
"and",
"height",
"of",
"an",
"image",
"in",
"parameter",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L526-L534 | train |
atk14/Files | src/files.php | Files.WriteToTemp | static function WriteToTemp($content, &$error = null, &$error_str = null){
$temp_filename = Files::GetTempFilename();
$out = Files::WriteToFile($temp_filename,$content,$error,$error_str);
if(!$error){
return $temp_filename;
}
} | php | static function WriteToTemp($content, &$error = null, &$error_str = null){
$temp_filename = Files::GetTempFilename();
$out = Files::WriteToFile($temp_filename,$content,$error,$error_str);
if(!$error){
return $temp_filename;
}
} | [
"static",
"function",
"WriteToTemp",
"(",
"$",
"content",
",",
"&",
"$",
"error",
"=",
"null",
",",
"&",
"$",
"error_str",
"=",
"null",
")",
"{",
"$",
"temp_filename",
"=",
"Files",
"::",
"GetTempFilename",
"(",
")",
";",
"$",
"out",
"=",
"Files",
"::",
"WriteToFile",
"(",
"$",
"temp_filename",
",",
"$",
"content",
",",
"$",
"error",
",",
"$",
"error_str",
")",
";",
"if",
"(",
"!",
"$",
"error",
")",
"{",
"return",
"$",
"temp_filename",
";",
"}",
"}"
]
| Write a content to a temporary file.
Example
```
$tmp_filename = Files::WriteToTemp($hot_content);
```
... do some work with $tmp_filename
```
Files::Unlink($tmp_filename);
```
@param string $content content to write to the temporary file
@param boolean &$error flag indicating a problem when calling this method
@param string &$error_str
@return string name of the temporary file | [
"Write",
"a",
"content",
"to",
"a",
"temporary",
"file",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L554-L561 | train |
atk14/Files | src/files.php | Files.GetTempDir | static function GetTempDir(){
$temp_dir = (defined("TEMP") && strlen("TEMP")) ? (string)TEMP : sys_get_temp_dir();
if(!strlen($temp_dir)){
$temp_dir = "/tmp";
}
return $temp_dir;
} | php | static function GetTempDir(){
$temp_dir = (defined("TEMP") && strlen("TEMP")) ? (string)TEMP : sys_get_temp_dir();
if(!strlen($temp_dir)){
$temp_dir = "/tmp";
}
return $temp_dir;
} | [
"static",
"function",
"GetTempDir",
"(",
")",
"{",
"$",
"temp_dir",
"=",
"(",
"defined",
"(",
"\"TEMP\"",
")",
"&&",
"strlen",
"(",
"\"TEMP\"",
")",
")",
"?",
"(",
"string",
")",
"TEMP",
":",
"sys_get_temp_dir",
"(",
")",
";",
"if",
"(",
"!",
"strlen",
"(",
"$",
"temp_dir",
")",
")",
"{",
"$",
"temp_dir",
"=",
"\"/tmp\"",
";",
"}",
"return",
"$",
"temp_dir",
";",
"}"
]
| Returns the temporary directory
```
$tmp_dir = Files::GetTempDir(); // e.g. "/tmp"
```
It is NOT ensured whether returned is ending with "/" or not.
@return string | [
"Returns",
"the",
"temporary",
"directory"
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L574-L580 | train |
atk14/Files | src/files.php | Files.DetermineFileType | static function DetermineFileType($filename, $options = array(), &$preferred_suffix = null){
$options += array(
"original_filename" => null,
);
if(!file_exists($filename) || is_dir($filename)){
return null;
}
if(function_exists("mime_content_type")){
$mime_type = mime_content_type($filename);
}elseif(function_exists("finfo_open")){
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $filename);
}else{
$command = "file -i ".escapeshellarg($filename);
$out = `$command`;
// /tmp/xxsEEws: text/plain charset=us-ascii
// -> text/plain
// ya.gif: image/gif; charset=binary
// -> image/gif
if(preg_match("/^.*?:\\s*([^\\s]+\\/[^\\s;]+)/",$out,$matches)){
$mime_type = $matches[1];
}else{
$mime_type = "application/octet-stream";
}
}
$original_filename = $options["original_filename"];
if(!$original_filename){
preg_match('/([^\/]+)$/',$filename,$matches); // "/path/to/file.jpg" -> "file.jpg"
$original_filename = $matches[1];
}
$original_suffix = "";
if(preg_match('/\.([^.]{1,10})$/i',$original_filename,$matches)){
$original_suffix = strtolower($matches[1]); // "FILE.JPG" -> "jpg"
}
$preferred_suffix = $original_suffix;
$tr_table = array(
// most desirable suffix is on the first position
// the most desirable type is on the first position
"xls" => array("application/vnd.ms-excel","application/msexcel","application/vnd.ms-office","application/msword"),
"xlsx" => array("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/zip","application/octet-stream"), // !! application/octet-stream seems to be a little odd
"doc" => array("application/msword","application/vnd.ms-office"),
"ppt" => array("application/vnd.ms-powerpoint","application/vnd.ms-office","application/msword"),
"jpg|jpeg" => array("image/jpeg","image/jpg"),
"svg" => array("image/svg+xml","image/svg","text/plain"),
"bmp" => array("image/bmp","image/x-bmp","image/x-ms-bmp","application/octet-stream"),
"eps" => array("application/postscript","application/eps"),
"csv" => array("text/csv","text/plain"),
"docx" => array("application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/zip"),
);
foreach($tr_table as $suffixes => $mime_types){
$suffixes = explode("|",$suffixes);
if(in_array($original_suffix,$suffixes) && in_array($mime_type,$mime_types)){
$mime_type = $mime_types[0];
$preferred_suffix = $suffixes[0];
break;
}
}
return $mime_type;
} | php | static function DetermineFileType($filename, $options = array(), &$preferred_suffix = null){
$options += array(
"original_filename" => null,
);
if(!file_exists($filename) || is_dir($filename)){
return null;
}
if(function_exists("mime_content_type")){
$mime_type = mime_content_type($filename);
}elseif(function_exists("finfo_open")){
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $filename);
}else{
$command = "file -i ".escapeshellarg($filename);
$out = `$command`;
// /tmp/xxsEEws: text/plain charset=us-ascii
// -> text/plain
// ya.gif: image/gif; charset=binary
// -> image/gif
if(preg_match("/^.*?:\\s*([^\\s]+\\/[^\\s;]+)/",$out,$matches)){
$mime_type = $matches[1];
}else{
$mime_type = "application/octet-stream";
}
}
$original_filename = $options["original_filename"];
if(!$original_filename){
preg_match('/([^\/]+)$/',$filename,$matches); // "/path/to/file.jpg" -> "file.jpg"
$original_filename = $matches[1];
}
$original_suffix = "";
if(preg_match('/\.([^.]{1,10})$/i',$original_filename,$matches)){
$original_suffix = strtolower($matches[1]); // "FILE.JPG" -> "jpg"
}
$preferred_suffix = $original_suffix;
$tr_table = array(
// most desirable suffix is on the first position
// the most desirable type is on the first position
"xls" => array("application/vnd.ms-excel","application/msexcel","application/vnd.ms-office","application/msword"),
"xlsx" => array("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/zip","application/octet-stream"), // !! application/octet-stream seems to be a little odd
"doc" => array("application/msword","application/vnd.ms-office"),
"ppt" => array("application/vnd.ms-powerpoint","application/vnd.ms-office","application/msword"),
"jpg|jpeg" => array("image/jpeg","image/jpg"),
"svg" => array("image/svg+xml","image/svg","text/plain"),
"bmp" => array("image/bmp","image/x-bmp","image/x-ms-bmp","application/octet-stream"),
"eps" => array("application/postscript","application/eps"),
"csv" => array("text/csv","text/plain"),
"docx" => array("application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/zip"),
);
foreach($tr_table as $suffixes => $mime_types){
$suffixes = explode("|",$suffixes);
if(in_array($original_suffix,$suffixes) && in_array($mime_type,$mime_types)){
$mime_type = $mime_types[0];
$preferred_suffix = $suffixes[0];
break;
}
}
return $mime_type;
} | [
"static",
"function",
"DetermineFileType",
"(",
"$",
"filename",
",",
"$",
"options",
"=",
"array",
"(",
")",
",",
"&",
"$",
"preferred_suffix",
"=",
"null",
")",
"{",
"$",
"options",
"+=",
"array",
"(",
"\"original_filename\"",
"=>",
"null",
",",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
"||",
"is_dir",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"function_exists",
"(",
"\"mime_content_type\"",
")",
")",
"{",
"$",
"mime_type",
"=",
"mime_content_type",
"(",
"$",
"filename",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"\"finfo_open\"",
")",
")",
"{",
"$",
"finfo",
"=",
"finfo_open",
"(",
"FILEINFO_MIME_TYPE",
")",
";",
"$",
"mime_type",
"=",
"finfo_file",
"(",
"$",
"finfo",
",",
"$",
"filename",
")",
";",
"}",
"else",
"{",
"$",
"command",
"=",
"\"file -i \"",
".",
"escapeshellarg",
"(",
"$",
"filename",
")",
";",
"$",
"out",
"=",
"`$command`",
";",
"// /tmp/xxsEEws: text/plain charset=us-ascii",
"// -> text/plain",
"// ya.gif: image/gif; charset=binary",
"// -> image/gif",
"if",
"(",
"preg_match",
"(",
"\"/^.*?:\\\\s*([^\\\\s]+\\\\/[^\\\\s;]+)/\"",
",",
"$",
"out",
",",
"$",
"matches",
")",
")",
"{",
"$",
"mime_type",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"mime_type",
"=",
"\"application/octet-stream\"",
";",
"}",
"}",
"$",
"original_filename",
"=",
"$",
"options",
"[",
"\"original_filename\"",
"]",
";",
"if",
"(",
"!",
"$",
"original_filename",
")",
"{",
"preg_match",
"(",
"'/([^\\/]+)$/'",
",",
"$",
"filename",
",",
"$",
"matches",
")",
";",
"// \"/path/to/file.jpg\" -> \"file.jpg\"",
"$",
"original_filename",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"$",
"original_suffix",
"=",
"\"\"",
";",
"if",
"(",
"preg_match",
"(",
"'/\\.([^.]{1,10})$/i'",
",",
"$",
"original_filename",
",",
"$",
"matches",
")",
")",
"{",
"$",
"original_suffix",
"=",
"strtolower",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"// \"FILE.JPG\" -> \"jpg\"",
"}",
"$",
"preferred_suffix",
"=",
"$",
"original_suffix",
";",
"$",
"tr_table",
"=",
"array",
"(",
"// most desirable suffix is on the first position",
"// \t\t\t\t\t\t\t\t\t\tthe most desirable type is on the first position",
"\"xls\"",
"=>",
"array",
"(",
"\"application/vnd.ms-excel\"",
",",
"\"application/msexcel\"",
",",
"\"application/vnd.ms-office\"",
",",
"\"application/msword\"",
")",
",",
"\"xlsx\"",
"=>",
"array",
"(",
"\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\"",
",",
"\"application/zip\"",
",",
"\"application/octet-stream\"",
")",
",",
"// !! application/octet-stream seems to be a little odd",
"\"doc\"",
"=>",
"array",
"(",
"\"application/msword\"",
",",
"\"application/vnd.ms-office\"",
")",
",",
"\"ppt\"",
"=>",
"array",
"(",
"\"application/vnd.ms-powerpoint\"",
",",
"\"application/vnd.ms-office\"",
",",
"\"application/msword\"",
")",
",",
"\"jpg|jpeg\"",
"=>",
"array",
"(",
"\"image/jpeg\"",
",",
"\"image/jpg\"",
")",
",",
"\"svg\"",
"=>",
"array",
"(",
"\"image/svg+xml\"",
",",
"\"image/svg\"",
",",
"\"text/plain\"",
")",
",",
"\"bmp\"",
"=>",
"array",
"(",
"\"image/bmp\"",
",",
"\"image/x-bmp\"",
",",
"\"image/x-ms-bmp\"",
",",
"\"application/octet-stream\"",
")",
",",
"\"eps\"",
"=>",
"array",
"(",
"\"application/postscript\"",
",",
"\"application/eps\"",
")",
",",
"\"csv\"",
"=>",
"array",
"(",
"\"text/csv\"",
",",
"\"text/plain\"",
")",
",",
"\"docx\"",
"=>",
"array",
"(",
"\"application/vnd.openxmlformats-officedocument.wordprocessingml.document\"",
",",
"\"application/zip\"",
")",
",",
")",
";",
"foreach",
"(",
"$",
"tr_table",
"as",
"$",
"suffixes",
"=>",
"$",
"mime_types",
")",
"{",
"$",
"suffixes",
"=",
"explode",
"(",
"\"|\"",
",",
"$",
"suffixes",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"original_suffix",
",",
"$",
"suffixes",
")",
"&&",
"in_array",
"(",
"$",
"mime_type",
",",
"$",
"mime_types",
")",
")",
"{",
"$",
"mime_type",
"=",
"$",
"mime_types",
"[",
"0",
"]",
";",
"$",
"preferred_suffix",
"=",
"$",
"suffixes",
"[",
"0",
"]",
";",
"break",
";",
"}",
"}",
"return",
"$",
"mime_type",
";",
"}"
]
| Determines the mime type of the file.
!! Note that it actualy runs the shell command file.
If it is unable to run the command, 'application/octet-string' is returned.
$mime_type = Files::DetermineFileType($_FILES['userfile']['tmp_name'],array(
"original_filename" => $_FILES['userfile']['name']) // like "strawber.jpeg"
),$preferred_suffix);
echo $mime_type; // "image/jpg"
echo $preferred_suffix; // "jpg"
@param string $filename name of the file to be examined
@param array $options
@param string &$preferred_suffix | [
"Determines",
"the",
"mime",
"type",
"of",
"the",
"file",
"."
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L611-L676 | train |
atk14/Files | src/files.php | Files.FindFiles | static function FindFiles($directory,$options = array()){
$options += array(
"pattern" => null, // '/^.*\.(log|err)$/'
"invert_pattern" => null, // '/^\./' - do not find files starting with dot
"min_mtime" => null, // time() - 2 * 60 * 60
"max_mtime" => null, // time() - 60 * 60
"maxdepth" => null // TODO: add maxdepth like in system command find
);
if(!preg_match('/\/$/',$directory)){
$directory = "$directory/"; // "./tmp" -> "./tmp/"
}
$pattern = $options["pattern"];
$invert_pattern = $options["invert_pattern"];
$min_mtime = $options["min_mtime"];
$max_mtime = $options["max_mtime"];
$maxdepth = $options["maxdepth"];
if(isset($maxdepth) && $maxdepth<=0){
return array();
}
// getting file list
$files = array();
$dir = opendir($directory);
while(is_string($item = readdir($dir))){
if($item=="." || $item==".."){ continue; }
$files[] = $item;
}
closedir($dir);
asort($files);
$out = array();
foreach($files as $file){
$_f = $file; // "application.log"
$file = "$directory$file"; // "./log/application.log"
if(is_dir($file) && !is_link($file)){
$_options = $options;
if(isset($_options["maxdepth"])){ $_options["maxdepth"]--; }
foreach(self::FindFiles($file,$_options) as $_file){
$out[] = $_file;
}
}
if(!is_file($file)){
continue;
}
if($pattern && !preg_match($pattern,$_f)){
continue;
}
if($invert_pattern && preg_match($invert_pattern,$_f)){
continue;
}
if(isset($min_mtime) && filemtime($file)<$min_mtime){
continue;
}
if(isset($max_mtime) && filemtime($file)>$max_mtime){
continue;
}
$out[] = $file;
}
return $out;
} | php | static function FindFiles($directory,$options = array()){
$options += array(
"pattern" => null, // '/^.*\.(log|err)$/'
"invert_pattern" => null, // '/^\./' - do not find files starting with dot
"min_mtime" => null, // time() - 2 * 60 * 60
"max_mtime" => null, // time() - 60 * 60
"maxdepth" => null // TODO: add maxdepth like in system command find
);
if(!preg_match('/\/$/',$directory)){
$directory = "$directory/"; // "./tmp" -> "./tmp/"
}
$pattern = $options["pattern"];
$invert_pattern = $options["invert_pattern"];
$min_mtime = $options["min_mtime"];
$max_mtime = $options["max_mtime"];
$maxdepth = $options["maxdepth"];
if(isset($maxdepth) && $maxdepth<=0){
return array();
}
// getting file list
$files = array();
$dir = opendir($directory);
while(is_string($item = readdir($dir))){
if($item=="." || $item==".."){ continue; }
$files[] = $item;
}
closedir($dir);
asort($files);
$out = array();
foreach($files as $file){
$_f = $file; // "application.log"
$file = "$directory$file"; // "./log/application.log"
if(is_dir($file) && !is_link($file)){
$_options = $options;
if(isset($_options["maxdepth"])){ $_options["maxdepth"]--; }
foreach(self::FindFiles($file,$_options) as $_file){
$out[] = $_file;
}
}
if(!is_file($file)){
continue;
}
if($pattern && !preg_match($pattern,$_f)){
continue;
}
if($invert_pattern && preg_match($invert_pattern,$_f)){
continue;
}
if(isset($min_mtime) && filemtime($file)<$min_mtime){
continue;
}
if(isset($max_mtime) && filemtime($file)>$max_mtime){
continue;
}
$out[] = $file;
}
return $out;
} | [
"static",
"function",
"FindFiles",
"(",
"$",
"directory",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"+=",
"array",
"(",
"\"pattern\"",
"=>",
"null",
",",
"// '/^.*\\.(log|err)$/'",
"\"invert_pattern\"",
"=>",
"null",
",",
"// '/^\\./' - do not find files starting with dot",
"\"min_mtime\"",
"=>",
"null",
",",
"// time() - 2 * 60 * 60",
"\"max_mtime\"",
"=>",
"null",
",",
"// time() - 60 * 60",
"\"maxdepth\"",
"=>",
"null",
"// TODO: add maxdepth like in system command find",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/\\/$/'",
",",
"$",
"directory",
")",
")",
"{",
"$",
"directory",
"=",
"\"$directory/\"",
";",
"// \"./tmp\" -> \"./tmp/\"",
"}",
"$",
"pattern",
"=",
"$",
"options",
"[",
"\"pattern\"",
"]",
";",
"$",
"invert_pattern",
"=",
"$",
"options",
"[",
"\"invert_pattern\"",
"]",
";",
"$",
"min_mtime",
"=",
"$",
"options",
"[",
"\"min_mtime\"",
"]",
";",
"$",
"max_mtime",
"=",
"$",
"options",
"[",
"\"max_mtime\"",
"]",
";",
"$",
"maxdepth",
"=",
"$",
"options",
"[",
"\"maxdepth\"",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"maxdepth",
")",
"&&",
"$",
"maxdepth",
"<=",
"0",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"// getting file list",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"dir",
"=",
"opendir",
"(",
"$",
"directory",
")",
";",
"while",
"(",
"is_string",
"(",
"$",
"item",
"=",
"readdir",
"(",
"$",
"dir",
")",
")",
")",
"{",
"if",
"(",
"$",
"item",
"==",
"\".\"",
"||",
"$",
"item",
"==",
"\"..\"",
")",
"{",
"continue",
";",
"}",
"$",
"files",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"closedir",
"(",
"$",
"dir",
")",
";",
"asort",
"(",
"$",
"files",
")",
";",
"$",
"out",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"_f",
"=",
"$",
"file",
";",
"// \"application.log\"",
"$",
"file",
"=",
"\"$directory$file\"",
";",
"// \"./log/application.log\"",
"if",
"(",
"is_dir",
"(",
"$",
"file",
")",
"&&",
"!",
"is_link",
"(",
"$",
"file",
")",
")",
"{",
"$",
"_options",
"=",
"$",
"options",
";",
"if",
"(",
"isset",
"(",
"$",
"_options",
"[",
"\"maxdepth\"",
"]",
")",
")",
"{",
"$",
"_options",
"[",
"\"maxdepth\"",
"]",
"--",
";",
"}",
"foreach",
"(",
"self",
"::",
"FindFiles",
"(",
"$",
"file",
",",
"$",
"_options",
")",
"as",
"$",
"_file",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"_file",
";",
"}",
"}",
"if",
"(",
"!",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"pattern",
"&&",
"!",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"_f",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"invert_pattern",
"&&",
"preg_match",
"(",
"$",
"invert_pattern",
",",
"$",
"_f",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"min_mtime",
")",
"&&",
"filemtime",
"(",
"$",
"file",
")",
"<",
"$",
"min_mtime",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"max_mtime",
")",
"&&",
"filemtime",
"(",
"$",
"file",
")",
">",
"$",
"max_mtime",
")",
"{",
"continue",
";",
"}",
"$",
"out",
"[",
"]",
"=",
"$",
"file",
";",
"}",
"return",
"$",
"out",
";",
"}"
]
| Find files in the given directory according to a regular pattern and other criteria
TODO: Currently only regular files are being found just in the given directory
$files = Files::FindFiles('./log/',array(
'pattern' => '/^.*\.(log|err)$/'
));
// array('./log/application.log', './log/application.err')
@return string[] | [
"Find",
"files",
"in",
"the",
"given",
"directory",
"according",
"to",
"a",
"regular",
"pattern",
"and",
"other",
"criteria"
]
| 87b43a297fce92f294c8b0bac53958a58ed11687 | https://github.com/atk14/Files/blob/87b43a297fce92f294c8b0bac53958a58ed11687/src/files.php#L690-L762 | train |
theopera/framework | src/Component/WebApplication/RouteEndpoint.php | RouteEndpoint.isCallable | public function isCallable() : bool
{
return is_callable(
[
$this->namespace . $this->getController(true),
$this->getAction(true)
]
);
} | php | public function isCallable() : bool
{
return is_callable(
[
$this->namespace . $this->getController(true),
$this->getAction(true)
]
);
} | [
"public",
"function",
"isCallable",
"(",
")",
":",
"bool",
"{",
"return",
"is_callable",
"(",
"[",
"$",
"this",
"->",
"namespace",
".",
"$",
"this",
"->",
"getController",
"(",
"true",
")",
",",
"$",
"this",
"->",
"getAction",
"(",
"true",
")",
"]",
")",
";",
"}"
]
| Is this route callable?
@return bool | [
"Is",
"this",
"route",
"callable?"
]
| fa6165d3891a310faa580c81dee49a63c150c711 | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/WebApplication/RouteEndpoint.php#L94-L102 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Query/JoinClause.php | JoinClause.orWhere | public function orWhere($first, $operator = null, $second = null)
{
return $this->on($first, $operator, $second, 'or', true);
} | php | public function orWhere($first, $operator = null, $second = null)
{
return $this->on($first, $operator, $second, 'or', true);
} | [
"public",
"function",
"orWhere",
"(",
"$",
"first",
",",
"$",
"operator",
"=",
"null",
",",
"$",
"second",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"on",
"(",
"$",
"first",
",",
"$",
"operator",
",",
"$",
"second",
",",
"'or'",
",",
"true",
")",
";",
"}"
]
| Add an "or on where" clause to the join.
@param \Closure|string $first
@param string|null $operator
@param string|null $second
@return JoinClause | [
"Add",
"an",
"or",
"on",
"where",
"clause",
"to",
"the",
"join",
"."
]
| 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Query/JoinClause.php#L130-L133 | train |
railken/amethyst-authentication | src/Concerns/Auth/User.php | User.findForPassport | public function findForPassport($identifier)
{
return (new static())->newQuery()->orWhere(function ($q) use ($identifier) {
return $q->orWhere('email', $identifier)->orWhere('name', $identifier);
})->where('enabled', 1)->first();
} | php | public function findForPassport($identifier)
{
return (new static())->newQuery()->orWhere(function ($q) use ($identifier) {
return $q->orWhere('email', $identifier)->orWhere('name', $identifier);
})->where('enabled', 1)->first();
} | [
"public",
"function",
"findForPassport",
"(",
"$",
"identifier",
")",
"{",
"return",
"(",
"new",
"static",
"(",
")",
")",
"->",
"newQuery",
"(",
")",
"->",
"orWhere",
"(",
"function",
"(",
"$",
"q",
")",
"use",
"(",
"$",
"identifier",
")",
"{",
"return",
"$",
"q",
"->",
"orWhere",
"(",
"'email'",
",",
"$",
"identifier",
")",
"->",
"orWhere",
"(",
"'name'",
",",
"$",
"identifier",
")",
";",
"}",
")",
"->",
"where",
"(",
"'enabled'",
",",
"1",
")",
"->",
"first",
"(",
")",
";",
"}"
]
| Retrieve user for passport oauth.
@param string $identifier
@return User | [
"Retrieve",
"user",
"for",
"passport",
"oauth",
"."
]
| 59f28ddffa41a5f7fae4d5504eacf7c664e54b46 | https://github.com/railken/amethyst-authentication/blob/59f28ddffa41a5f7fae4d5504eacf7c664e54b46/src/Concerns/Auth/User.php#L24-L29 | train |
BespokeSupport/Mime | src/FileMimesGenerator.php | FileMimesGenerator.fetch | public static function fetch($file)
{
$url = 'http://www.freeformatter.com/mime-types-list.html';
// no need to download again if csv present
if (file_exists($file)) {
return;
}
$filePointerCsv = fopen($file, 'wb');
$fileHtml = \dirname(__FILE__, 2) . '/resources/mimes.html';
if (!file_exists($fileHtml)) {
$contents = file_get_contents($url);
file_put_contents($fileHtml, $contents);
} else {
$contents = file_get_contents($fileHtml);
}
$contents = preg_replace('/(.*)<tbody>/is', '', $contents);
$contents = preg_replace('/<\/tbody>.*/is', '', $contents);
try {
$xml = new DOMDocument();
@$xml->loadHTML($contents);
$trs = $xml->getElementsByTagName('tr');
for ($i = 0; $i < $trs->length; $i++) {
$tr = $trs->item($i);
$tds = $tr->childNodes;
$nodeName = $tds->item(0);
$nodeMime = $tds->item(2);
$nodeFile = $tds->item(4);
$extText = ($nodeFile->textContent === 'N/A') ? null : str_replace('.', '', $nodeFile->textContent);
$extensions = explode(',', $extText);
$extension = \count($extensions) ? trim(array_pop($extensions)) : $extText;
fputcsv($filePointerCsv,
[
$nodeMime->textContent,
$nodeName->textContent,
$extension,
],
',',
'"'
);
}
} catch (Exception $e) {
}
fclose($filePointerCsv);
} | php | public static function fetch($file)
{
$url = 'http://www.freeformatter.com/mime-types-list.html';
// no need to download again if csv present
if (file_exists($file)) {
return;
}
$filePointerCsv = fopen($file, 'wb');
$fileHtml = \dirname(__FILE__, 2) . '/resources/mimes.html';
if (!file_exists($fileHtml)) {
$contents = file_get_contents($url);
file_put_contents($fileHtml, $contents);
} else {
$contents = file_get_contents($fileHtml);
}
$contents = preg_replace('/(.*)<tbody>/is', '', $contents);
$contents = preg_replace('/<\/tbody>.*/is', '', $contents);
try {
$xml = new DOMDocument();
@$xml->loadHTML($contents);
$trs = $xml->getElementsByTagName('tr');
for ($i = 0; $i < $trs->length; $i++) {
$tr = $trs->item($i);
$tds = $tr->childNodes;
$nodeName = $tds->item(0);
$nodeMime = $tds->item(2);
$nodeFile = $tds->item(4);
$extText = ($nodeFile->textContent === 'N/A') ? null : str_replace('.', '', $nodeFile->textContent);
$extensions = explode(',', $extText);
$extension = \count($extensions) ? trim(array_pop($extensions)) : $extText;
fputcsv($filePointerCsv,
[
$nodeMime->textContent,
$nodeName->textContent,
$extension,
],
',',
'"'
);
}
} catch (Exception $e) {
}
fclose($filePointerCsv);
} | [
"public",
"static",
"function",
"fetch",
"(",
"$",
"file",
")",
"{",
"$",
"url",
"=",
"'http://www.freeformatter.com/mime-types-list.html'",
";",
"// no need to download again if csv present",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
";",
"}",
"$",
"filePointerCsv",
"=",
"fopen",
"(",
"$",
"file",
",",
"'wb'",
")",
";",
"$",
"fileHtml",
"=",
"\\",
"dirname",
"(",
"__FILE__",
",",
"2",
")",
".",
"'/resources/mimes.html'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileHtml",
")",
")",
"{",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"url",
")",
";",
"file_put_contents",
"(",
"$",
"fileHtml",
",",
"$",
"contents",
")",
";",
"}",
"else",
"{",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"fileHtml",
")",
";",
"}",
"$",
"contents",
"=",
"preg_replace",
"(",
"'/(.*)<tbody>/is'",
",",
"''",
",",
"$",
"contents",
")",
";",
"$",
"contents",
"=",
"preg_replace",
"(",
"'/<\\/tbody>.*/is'",
",",
"''",
",",
"$",
"contents",
")",
";",
"try",
"{",
"$",
"xml",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"@",
"$",
"xml",
"->",
"loadHTML",
"(",
"$",
"contents",
")",
";",
"$",
"trs",
"=",
"$",
"xml",
"->",
"getElementsByTagName",
"(",
"'tr'",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"trs",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"tr",
"=",
"$",
"trs",
"->",
"item",
"(",
"$",
"i",
")",
";",
"$",
"tds",
"=",
"$",
"tr",
"->",
"childNodes",
";",
"$",
"nodeName",
"=",
"$",
"tds",
"->",
"item",
"(",
"0",
")",
";",
"$",
"nodeMime",
"=",
"$",
"tds",
"->",
"item",
"(",
"2",
")",
";",
"$",
"nodeFile",
"=",
"$",
"tds",
"->",
"item",
"(",
"4",
")",
";",
"$",
"extText",
"=",
"(",
"$",
"nodeFile",
"->",
"textContent",
"===",
"'N/A'",
")",
"?",
"null",
":",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"$",
"nodeFile",
"->",
"textContent",
")",
";",
"$",
"extensions",
"=",
"explode",
"(",
"','",
",",
"$",
"extText",
")",
";",
"$",
"extension",
"=",
"\\",
"count",
"(",
"$",
"extensions",
")",
"?",
"trim",
"(",
"array_pop",
"(",
"$",
"extensions",
")",
")",
":",
"$",
"extText",
";",
"fputcsv",
"(",
"$",
"filePointerCsv",
",",
"[",
"$",
"nodeMime",
"->",
"textContent",
",",
"$",
"nodeName",
"->",
"textContent",
",",
"$",
"extension",
",",
"]",
",",
"','",
",",
"'\"'",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"}",
"fclose",
"(",
"$",
"filePointerCsv",
")",
";",
"}"
]
| Convert HTML page to CSV then create Mime listings.
@param $file | [
"Convert",
"HTML",
"page",
"to",
"CSV",
"then",
"create",
"Mime",
"listings",
"."
]
| 2886bed1eaaa882edc08b096bd7ca9b39744c48f | https://github.com/BespokeSupport/Mime/blob/2886bed1eaaa882edc08b096bd7ca9b39744c48f/src/FileMimesGenerator.php#L46-L105 | train |
BespokeSupport/Mime | src/FileMimesGenerator.php | FileMimesGenerator.generate | public static function generate($file)
{
$filePointer = fopen($file, 'rb');
$names = '';
$extensions = '';
$header = true;
while (($row = fgetcsv($filePointer))) {
if ($header) {
$header = false;
continue;
}
$mime = trim($row[0]);
$name = trim(addslashes($row[1]));
$extension = trim($row[2]);
$extensions .= "\t\t'$mime' => '$extension',\n";
$names .= "\t\t'$mime' => '$name',\n";
}
$class = '';
$class .= self::getHeader();
$class .= self::getFunctions();
$class .= self::getPropertyMimesHeader();
$class .= $extensions;
$class .= self::getPropertyMimesFooter();
$class .= self::getPropertyNamesHeader();
$class .= $names;
$class .= self::getPropertyNamesFooter();
$class .= self::getFooter();
file_put_contents(__DIR__ . '/FileMimes.php', $class);
} | php | public static function generate($file)
{
$filePointer = fopen($file, 'rb');
$names = '';
$extensions = '';
$header = true;
while (($row = fgetcsv($filePointer))) {
if ($header) {
$header = false;
continue;
}
$mime = trim($row[0]);
$name = trim(addslashes($row[1]));
$extension = trim($row[2]);
$extensions .= "\t\t'$mime' => '$extension',\n";
$names .= "\t\t'$mime' => '$name',\n";
}
$class = '';
$class .= self::getHeader();
$class .= self::getFunctions();
$class .= self::getPropertyMimesHeader();
$class .= $extensions;
$class .= self::getPropertyMimesFooter();
$class .= self::getPropertyNamesHeader();
$class .= $names;
$class .= self::getPropertyNamesFooter();
$class .= self::getFooter();
file_put_contents(__DIR__ . '/FileMimes.php', $class);
} | [
"public",
"static",
"function",
"generate",
"(",
"$",
"file",
")",
"{",
"$",
"filePointer",
"=",
"fopen",
"(",
"$",
"file",
",",
"'rb'",
")",
";",
"$",
"names",
"=",
"''",
";",
"$",
"extensions",
"=",
"''",
";",
"$",
"header",
"=",
"true",
";",
"while",
"(",
"(",
"$",
"row",
"=",
"fgetcsv",
"(",
"$",
"filePointer",
")",
")",
")",
"{",
"if",
"(",
"$",
"header",
")",
"{",
"$",
"header",
"=",
"false",
";",
"continue",
";",
"}",
"$",
"mime",
"=",
"trim",
"(",
"$",
"row",
"[",
"0",
"]",
")",
";",
"$",
"name",
"=",
"trim",
"(",
"addslashes",
"(",
"$",
"row",
"[",
"1",
"]",
")",
")",
";",
"$",
"extension",
"=",
"trim",
"(",
"$",
"row",
"[",
"2",
"]",
")",
";",
"$",
"extensions",
".=",
"\"\\t\\t'$mime' => '$extension',\\n\"",
";",
"$",
"names",
".=",
"\"\\t\\t'$mime' => '$name',\\n\"",
";",
"}",
"$",
"class",
"=",
"''",
";",
"$",
"class",
".=",
"self",
"::",
"getHeader",
"(",
")",
";",
"$",
"class",
".=",
"self",
"::",
"getFunctions",
"(",
")",
";",
"$",
"class",
".=",
"self",
"::",
"getPropertyMimesHeader",
"(",
")",
";",
"$",
"class",
".=",
"$",
"extensions",
";",
"$",
"class",
".=",
"self",
"::",
"getPropertyMimesFooter",
"(",
")",
";",
"$",
"class",
".=",
"self",
"::",
"getPropertyNamesHeader",
"(",
")",
";",
"$",
"class",
".=",
"$",
"names",
";",
"$",
"class",
".=",
"self",
"::",
"getPropertyNamesFooter",
"(",
")",
";",
"$",
"class",
".=",
"self",
"::",
"getFooter",
"(",
")",
";",
"file_put_contents",
"(",
"__DIR__",
".",
"'/FileMimes.php'",
",",
"$",
"class",
")",
";",
"}"
]
| Generate FileMimes class.
@param $file | [
"Generate",
"FileMimes",
"class",
"."
]
| 2886bed1eaaa882edc08b096bd7ca9b39744c48f | https://github.com/BespokeSupport/Mime/blob/2886bed1eaaa882edc08b096bd7ca9b39744c48f/src/FileMimesGenerator.php#L112-L146 | train |
cogentParadigm/behat-starbug-extension | src/Context/StarbugContext.php | StarbugContext.createEntity | public function createEntity($entity, TableNode $fields) {
$this->models->get($entity)->store($fields->getRowsHash());
} | php | public function createEntity($entity, TableNode $fields) {
$this->models->get($entity)->store($fields->getRowsHash());
} | [
"public",
"function",
"createEntity",
"(",
"$",
"entity",
",",
"TableNode",
"$",
"fields",
")",
"{",
"$",
"this",
"->",
"models",
"->",
"get",
"(",
"$",
"entity",
")",
"->",
"store",
"(",
"$",
"fields",
"->",
"getRowsHash",
"(",
")",
")",
";",
"}"
]
| Creates an entity with specified fields
@Given there is a/an :entity entity with: | [
"Creates",
"an",
"entity",
"with",
"specified",
"fields"
]
| 76da5d943773857ad2388a7cccb6632176b452a9 | https://github.com/cogentParadigm/behat-starbug-extension/blob/76da5d943773857ad2388a7cccb6632176b452a9/src/Context/StarbugContext.php#L129-L131 | train |
cogentParadigm/behat-starbug-extension | src/Context/StarbugContext.php | StarbugContext.applyFixtures | public function applyFixtures(TableNode $fixtures) {
$fixtures = $fixtures->getColumn(0);
$dataSet = new CompositeDataSet();
foreach ($fixtures as $fixture) {
$dataSet->addDataSet($this->fixtures->createMySQLXMLDataSet($fixture));
}
$this->fixtures->applyDataSet($dataSet);
} | php | public function applyFixtures(TableNode $fixtures) {
$fixtures = $fixtures->getColumn(0);
$dataSet = new CompositeDataSet();
foreach ($fixtures as $fixture) {
$dataSet->addDataSet($this->fixtures->createMySQLXMLDataSet($fixture));
}
$this->fixtures->applyDataSet($dataSet);
} | [
"public",
"function",
"applyFixtures",
"(",
"TableNode",
"$",
"fixtures",
")",
"{",
"$",
"fixtures",
"=",
"$",
"fixtures",
"->",
"getColumn",
"(",
"0",
")",
";",
"$",
"dataSet",
"=",
"new",
"CompositeDataSet",
"(",
")",
";",
"foreach",
"(",
"$",
"fixtures",
"as",
"$",
"fixture",
")",
"{",
"$",
"dataSet",
"->",
"addDataSet",
"(",
"$",
"this",
"->",
"fixtures",
"->",
"createMySQLXMLDataSet",
"(",
"$",
"fixture",
")",
")",
";",
"}",
"$",
"this",
"->",
"fixtures",
"->",
"applyDataSet",
"(",
"$",
"dataSet",
")",
";",
"}"
]
| Populates a fixture into the database.
@Given I have the fixtures: | [
"Populates",
"a",
"fixture",
"into",
"the",
"database",
"."
]
| 76da5d943773857ad2388a7cccb6632176b452a9 | https://github.com/cogentParadigm/behat-starbug-extension/blob/76da5d943773857ad2388a7cccb6632176b452a9/src/Context/StarbugContext.php#L147-L154 | train |
Raphhh/trex-parser | src/ClassAnalyzer.php | ClassAnalyzer.getClassReflections | public function getClassReflections($code)
{
$result = [];
foreach ($this->getClassNames($code) as $className) {
$result[$className] = new \ReflectionClass($className);
}
return $result;
} | php | public function getClassReflections($code)
{
$result = [];
foreach ($this->getClassNames($code) as $className) {
$result[$className] = new \ReflectionClass($className);
}
return $result;
} | [
"public",
"function",
"getClassReflections",
"(",
"$",
"code",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getClassNames",
"(",
"$",
"code",
")",
"as",
"$",
"className",
")",
"{",
"$",
"result",
"[",
"$",
"className",
"]",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| returns the classes form an included code.
@param string $code
@return \ReflectionClass[] | [
"returns",
"the",
"classes",
"form",
"an",
"included",
"code",
"."
]
| 32a10af443b10b1ac57baef0f593ad71e924b51b | https://github.com/Raphhh/trex-parser/blob/32a10af443b10b1ac57baef0f593ad71e924b51b/src/ClassAnalyzer.php#L31-L38 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/controllers/NodeCmsController.php | NodeCmsController.undelete | protected function undelete()
{
if($this->saveButtonPushed())
{
$nodeRef = $this->buildCmsNodeRef();
$node = $nodeRef->generateNode();
$location = 'load';
$this->Events->trigger('NodeCmsController.undelete'.'.'.$location,
$this->errors, $this->templateVars, $node);
foreach((array)$nodeRef->getElement()->getAspects() as $aspect)
$this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'undelete'.'.'.$location,
$this->errors, $this->templateVars, $node);
if (!$node->hasTitle())
//get default form backing object
$node = $this->RegulatedNodeService->getByNodeRef($node->getNodeRef());
if (empty($node))
throw new NotFoundException('Record not found for NodeRef: '.$nodeRef);
// check permissions
// $this->checkUndeletePermission($node);
$location = 'pre';
$this->Events->trigger('NodeCmsController.undelete'.'.'.$location,
$this->errors, $this->templateVars, $node);
foreach ((array)$nodeRef->getElement()->getAspects() as $aspect)
$this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'undelete'.'.'.$location,
$this->errors, $this->templateVars, $node);
$this->getErrors()->throwOnError();
$this->RegulatedNodeService->undelete($nodeRef);
$location = 'post';
$this->Events->trigger('NodeCmsController.undelete'.'.'.$location, $this->errors, $this->templateVars, $node);
foreach ((array)$nodeRef->getElement()->getAspects() as $aspect)
$this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'undelete'.'.'.$location, $this->errors, $this->templateVars, $node);
//redirect to edit news (action_success_view)
return new View($this->successView(), array('slug'=> $nodeRef->getSlug()));
}
} | php | protected function undelete()
{
if($this->saveButtonPushed())
{
$nodeRef = $this->buildCmsNodeRef();
$node = $nodeRef->generateNode();
$location = 'load';
$this->Events->trigger('NodeCmsController.undelete'.'.'.$location,
$this->errors, $this->templateVars, $node);
foreach((array)$nodeRef->getElement()->getAspects() as $aspect)
$this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'undelete'.'.'.$location,
$this->errors, $this->templateVars, $node);
if (!$node->hasTitle())
//get default form backing object
$node = $this->RegulatedNodeService->getByNodeRef($node->getNodeRef());
if (empty($node))
throw new NotFoundException('Record not found for NodeRef: '.$nodeRef);
// check permissions
// $this->checkUndeletePermission($node);
$location = 'pre';
$this->Events->trigger('NodeCmsController.undelete'.'.'.$location,
$this->errors, $this->templateVars, $node);
foreach ((array)$nodeRef->getElement()->getAspects() as $aspect)
$this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'undelete'.'.'.$location,
$this->errors, $this->templateVars, $node);
$this->getErrors()->throwOnError();
$this->RegulatedNodeService->undelete($nodeRef);
$location = 'post';
$this->Events->trigger('NodeCmsController.undelete'.'.'.$location, $this->errors, $this->templateVars, $node);
foreach ((array)$nodeRef->getElement()->getAspects() as $aspect)
$this->Events->trigger('NodeCmsController.@'.$aspect->Slug.'.'.'undelete'.'.'.$location, $this->errors, $this->templateVars, $node);
//redirect to edit news (action_success_view)
return new View($this->successView(), array('slug'=> $nodeRef->getSlug()));
}
} | [
"protected",
"function",
"undelete",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"saveButtonPushed",
"(",
")",
")",
"{",
"$",
"nodeRef",
"=",
"$",
"this",
"->",
"buildCmsNodeRef",
"(",
")",
";",
"$",
"node",
"=",
"$",
"nodeRef",
"->",
"generateNode",
"(",
")",
";",
"$",
"location",
"=",
"'load'",
";",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"'NodeCmsController.undelete'",
".",
"'.'",
".",
"$",
"location",
",",
"$",
"this",
"->",
"errors",
",",
"$",
"this",
"->",
"templateVars",
",",
"$",
"node",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"nodeRef",
"->",
"getElement",
"(",
")",
"->",
"getAspects",
"(",
")",
"as",
"$",
"aspect",
")",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"'NodeCmsController.@'",
".",
"$",
"aspect",
"->",
"Slug",
".",
"'.'",
".",
"'undelete'",
".",
"'.'",
".",
"$",
"location",
",",
"$",
"this",
"->",
"errors",
",",
"$",
"this",
"->",
"templateVars",
",",
"$",
"node",
")",
";",
"if",
"(",
"!",
"$",
"node",
"->",
"hasTitle",
"(",
")",
")",
"//get default form backing object",
"$",
"node",
"=",
"$",
"this",
"->",
"RegulatedNodeService",
"->",
"getByNodeRef",
"(",
"$",
"node",
"->",
"getNodeRef",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"node",
")",
")",
"throw",
"new",
"NotFoundException",
"(",
"'Record not found for NodeRef: '",
".",
"$",
"nodeRef",
")",
";",
"// check permissions",
"// $this->checkUndeletePermission($node);",
"$",
"location",
"=",
"'pre'",
";",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"'NodeCmsController.undelete'",
".",
"'.'",
".",
"$",
"location",
",",
"$",
"this",
"->",
"errors",
",",
"$",
"this",
"->",
"templateVars",
",",
"$",
"node",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"nodeRef",
"->",
"getElement",
"(",
")",
"->",
"getAspects",
"(",
")",
"as",
"$",
"aspect",
")",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"'NodeCmsController.@'",
".",
"$",
"aspect",
"->",
"Slug",
".",
"'.'",
".",
"'undelete'",
".",
"'.'",
".",
"$",
"location",
",",
"$",
"this",
"->",
"errors",
",",
"$",
"this",
"->",
"templateVars",
",",
"$",
"node",
")",
";",
"$",
"this",
"->",
"getErrors",
"(",
")",
"->",
"throwOnError",
"(",
")",
";",
"$",
"this",
"->",
"RegulatedNodeService",
"->",
"undelete",
"(",
"$",
"nodeRef",
")",
";",
"$",
"location",
"=",
"'post'",
";",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"'NodeCmsController.undelete'",
".",
"'.'",
".",
"$",
"location",
",",
"$",
"this",
"->",
"errors",
",",
"$",
"this",
"->",
"templateVars",
",",
"$",
"node",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"nodeRef",
"->",
"getElement",
"(",
")",
"->",
"getAspects",
"(",
")",
"as",
"$",
"aspect",
")",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"'NodeCmsController.@'",
".",
"$",
"aspect",
"->",
"Slug",
".",
"'.'",
".",
"'undelete'",
".",
"'.'",
".",
"$",
"location",
",",
"$",
"this",
"->",
"errors",
",",
"$",
"this",
"->",
"templateVars",
",",
"$",
"node",
")",
";",
"//redirect to edit news (action_success_view)",
"return",
"new",
"View",
"(",
"$",
"this",
"->",
"successView",
"(",
")",
",",
"array",
"(",
"'slug'",
"=>",
"$",
"nodeRef",
"->",
"getSlug",
"(",
")",
")",
")",
";",
"}",
"}"
]
| Provides 'undelete' functionality for Nodes
@return View | [
"Provides",
"undelete",
"functionality",
"for",
"Nodes"
]
| 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/controllers/NodeCmsController.php#L688-L734 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/controllers/NodeCmsController.php | NodeCmsController.single | protected function single()
{
// check permissions
// $this->checkSinglePermission();
$nq = new NodeQuery();
$nq->setLimit(1);
// $this->buildFilters($nq);
$this->passthruTemplateVariable($nq, 'Elements.in');
$this->passthruTemplateVariable($nq, 'Sites.in');
//$this->passthruTemplateVariable($nq, 'SiteIDs.in');
$this->passthruTemplateVariable($nq, 'Meta.select');
$this->passthruTemplateVariable($nq, 'OutTags.select');
$this->passthruTemplateVariable($nq, 'InTags.select');
// $this->passthruTemplateVariable($nq, 'Sections.select');
// $this->passthruTemplateVariable($nq, 'Title.like');
// $this->passthruTemplateVariable($nq, 'Title.ieq');
// $this->passthruTemplateVariable($nq, 'Title.eq');
// $this->passthruTemplateVariable($nq, 'Title.firstChar');
// $this->passthruTemplateVariable($nq, 'Status.isActive');
// $this->passthruTemplateVariable($nq, 'Status.all');
// $this->passthruTemplateVariable($nq, 'Status.eq');
// $this->passthruTemplateVariable($nq, 'TreeID.childOf');
// $this->passthruTemplateVariable($nq, 'TreeID.eq');
//
// $this->passthruTemplateVariable($nq, 'ActiveDate.before');
// $this->passthruTemplateVariable($nq, 'ActiveDate.after');
// $this->passthruTemplateVariable($nq, 'ActiveDate.start');
// $this->passthruTemplateVariable($nq, 'ActiveDate.end');
//
// $this->passthruTemplateVariable($nq, 'CreationDate.before');
// $this->passthruTemplateVariable($nq, 'CreationDate.after');
// $this->passthruTemplateVariable($nq, 'CreationDate.start');
// $this->passthruTemplateVariable($nq, 'CreationDate.end');
// $this->passthruTemplateVariable($nq, 'OutTags.exist');
// $this->passthruTemplateVariable($nq, 'InTags.exist');
// $this->passthruTemplateVariable($nq, 'Meta.exist');
// foreach ($this->templateVars as $name => $value) {
// if (strpos($name, '#') === 0)
// $nq->setParameter($name, $value);
// }
$slug = $this->getTemplateVariable('Slugs.in');
if ($slug != null) {
$nq->setParameter('Slugs.in', $slug);
$nq = $this->NodeRefService->normalizeNodeQuery($nq);
$nodeRefs = $nq->getParameter('NodeRefs.normalized');
$nodePartials = $nq->getParameter('NodePartials.eq');
$allFullyQualified = $nq->getParameter('NodeRefs.fullyQualified');
if(!$allFullyQualified || count($nodeRefs) > 1)
throw new Exception('No Slugs.in set for DataSource');
$row = $this->RegulatedNodeService->getByNodeRef(current($nodeRefs), $nodePartials);
if(!empty($row))
$nq->setResults(array($row));
return $this->readNodeQuery($nq);
}
throw new Exception('No Slugs.in set for DataSource');
} | php | protected function single()
{
// check permissions
// $this->checkSinglePermission();
$nq = new NodeQuery();
$nq->setLimit(1);
// $this->buildFilters($nq);
$this->passthruTemplateVariable($nq, 'Elements.in');
$this->passthruTemplateVariable($nq, 'Sites.in');
//$this->passthruTemplateVariable($nq, 'SiteIDs.in');
$this->passthruTemplateVariable($nq, 'Meta.select');
$this->passthruTemplateVariable($nq, 'OutTags.select');
$this->passthruTemplateVariable($nq, 'InTags.select');
// $this->passthruTemplateVariable($nq, 'Sections.select');
// $this->passthruTemplateVariable($nq, 'Title.like');
// $this->passthruTemplateVariable($nq, 'Title.ieq');
// $this->passthruTemplateVariable($nq, 'Title.eq');
// $this->passthruTemplateVariable($nq, 'Title.firstChar');
// $this->passthruTemplateVariable($nq, 'Status.isActive');
// $this->passthruTemplateVariable($nq, 'Status.all');
// $this->passthruTemplateVariable($nq, 'Status.eq');
// $this->passthruTemplateVariable($nq, 'TreeID.childOf');
// $this->passthruTemplateVariable($nq, 'TreeID.eq');
//
// $this->passthruTemplateVariable($nq, 'ActiveDate.before');
// $this->passthruTemplateVariable($nq, 'ActiveDate.after');
// $this->passthruTemplateVariable($nq, 'ActiveDate.start');
// $this->passthruTemplateVariable($nq, 'ActiveDate.end');
//
// $this->passthruTemplateVariable($nq, 'CreationDate.before');
// $this->passthruTemplateVariable($nq, 'CreationDate.after');
// $this->passthruTemplateVariable($nq, 'CreationDate.start');
// $this->passthruTemplateVariable($nq, 'CreationDate.end');
// $this->passthruTemplateVariable($nq, 'OutTags.exist');
// $this->passthruTemplateVariable($nq, 'InTags.exist');
// $this->passthruTemplateVariable($nq, 'Meta.exist');
// foreach ($this->templateVars as $name => $value) {
// if (strpos($name, '#') === 0)
// $nq->setParameter($name, $value);
// }
$slug = $this->getTemplateVariable('Slugs.in');
if ($slug != null) {
$nq->setParameter('Slugs.in', $slug);
$nq = $this->NodeRefService->normalizeNodeQuery($nq);
$nodeRefs = $nq->getParameter('NodeRefs.normalized');
$nodePartials = $nq->getParameter('NodePartials.eq');
$allFullyQualified = $nq->getParameter('NodeRefs.fullyQualified');
if(!$allFullyQualified || count($nodeRefs) > 1)
throw new Exception('No Slugs.in set for DataSource');
$row = $this->RegulatedNodeService->getByNodeRef(current($nodeRefs), $nodePartials);
if(!empty($row))
$nq->setResults(array($row));
return $this->readNodeQuery($nq);
}
throw new Exception('No Slugs.in set for DataSource');
} | [
"protected",
"function",
"single",
"(",
")",
"{",
"// check permissions",
"// $this->checkSinglePermission();",
"$",
"nq",
"=",
"new",
"NodeQuery",
"(",
")",
";",
"$",
"nq",
"->",
"setLimit",
"(",
"1",
")",
";",
"// $this->buildFilters($nq);",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"nq",
",",
"'Elements.in'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"nq",
",",
"'Sites.in'",
")",
";",
"//$this->passthruTemplateVariable($nq, 'SiteIDs.in');",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"nq",
",",
"'Meta.select'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"nq",
",",
"'OutTags.select'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"nq",
",",
"'InTags.select'",
")",
";",
"// $this->passthruTemplateVariable($nq, 'Sections.select');",
"// $this->passthruTemplateVariable($nq, 'Title.like');",
"// $this->passthruTemplateVariable($nq, 'Title.ieq');",
"// $this->passthruTemplateVariable($nq, 'Title.eq');",
"// $this->passthruTemplateVariable($nq, 'Title.firstChar');",
"// $this->passthruTemplateVariable($nq, 'Status.isActive');",
"// $this->passthruTemplateVariable($nq, 'Status.all');",
"// $this->passthruTemplateVariable($nq, 'Status.eq');",
"// $this->passthruTemplateVariable($nq, 'TreeID.childOf');",
"// $this->passthruTemplateVariable($nq, 'TreeID.eq');",
"//",
"// $this->passthruTemplateVariable($nq, 'ActiveDate.before');",
"// $this->passthruTemplateVariable($nq, 'ActiveDate.after');",
"// $this->passthruTemplateVariable($nq, 'ActiveDate.start');",
"// $this->passthruTemplateVariable($nq, 'ActiveDate.end');",
"//",
"// $this->passthruTemplateVariable($nq, 'CreationDate.before');",
"// $this->passthruTemplateVariable($nq, 'CreationDate.after');",
"// $this->passthruTemplateVariable($nq, 'CreationDate.start');",
"// $this->passthruTemplateVariable($nq, 'CreationDate.end');",
"// $this->passthruTemplateVariable($nq, 'OutTags.exist');",
"// $this->passthruTemplateVariable($nq, 'InTags.exist');",
"// $this->passthruTemplateVariable($nq, 'Meta.exist');",
"// foreach ($this->templateVars as $name => $value) {",
"// if (strpos($name, '#') === 0)",
"// $nq->setParameter($name, $value);",
"// }",
"$",
"slug",
"=",
"$",
"this",
"->",
"getTemplateVariable",
"(",
"'Slugs.in'",
")",
";",
"if",
"(",
"$",
"slug",
"!=",
"null",
")",
"{",
"$",
"nq",
"->",
"setParameter",
"(",
"'Slugs.in'",
",",
"$",
"slug",
")",
";",
"$",
"nq",
"=",
"$",
"this",
"->",
"NodeRefService",
"->",
"normalizeNodeQuery",
"(",
"$",
"nq",
")",
";",
"$",
"nodeRefs",
"=",
"$",
"nq",
"->",
"getParameter",
"(",
"'NodeRefs.normalized'",
")",
";",
"$",
"nodePartials",
"=",
"$",
"nq",
"->",
"getParameter",
"(",
"'NodePartials.eq'",
")",
";",
"$",
"allFullyQualified",
"=",
"$",
"nq",
"->",
"getParameter",
"(",
"'NodeRefs.fullyQualified'",
")",
";",
"if",
"(",
"!",
"$",
"allFullyQualified",
"||",
"count",
"(",
"$",
"nodeRefs",
")",
">",
"1",
")",
"throw",
"new",
"Exception",
"(",
"'No Slugs.in set for DataSource'",
")",
";",
"$",
"row",
"=",
"$",
"this",
"->",
"RegulatedNodeService",
"->",
"getByNodeRef",
"(",
"current",
"(",
"$",
"nodeRefs",
")",
",",
"$",
"nodePartials",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"row",
")",
")",
"$",
"nq",
"->",
"setResults",
"(",
"array",
"(",
"$",
"row",
")",
")",
";",
"return",
"$",
"this",
"->",
"readNodeQuery",
"(",
"$",
"nq",
")",
";",
"}",
"throw",
"new",
"Exception",
"(",
"'No Slugs.in set for DataSource'",
")",
";",
"}"
]
| Datasource for returning a single Node
@return DTO Contains the matching node (as an array) or is empty | [
"Datasource",
"for",
"returning",
"a",
"single",
"Node"
]
| 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/controllers/NodeCmsController.php#L747-L817 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/controllers/NodeCmsController.php | NodeCmsController.items | protected function items()
{
// check permissions
// $siteIDs = $this->checkItemsPermission();
$dto = new NodeQuery();
$this->buildLimitOffset($dto);
$this->passthruTemplateVariable($dto, 'Elements.in');
$this->passthruTemplateVariable($dto, 'Sites.in');
//$this->passthruTemplateVariable($dto, 'SiteIDs.in');
$this->passthruTemplateVariable($dto, 'Slugs.in');
$this->passthruTemplateVariable($dto, 'Meta.select');
$this->passthruTemplateVariable($dto, 'OutTags.select');
$this->passthruTemplateVariable($dto, 'InTags.select');
// $this->passthruTemplateVariable($dto, 'Sections.select');
$this->passthruTemplateVariable($dto, 'OrderByInTag');
$this->passthruTemplateVariable($dto, 'OrderByOutTag');
$this->passthruTemplateVariable($dto, 'Title.like');
$this->passthruTemplateVariable($dto, 'Title.ieq');
$this->passthruTemplateVariable($dto, 'Title.eq');
$this->passthruTemplateVariable($dto, 'Title.firstChar');
$this->passthruTemplateVariable($dto, 'Status.isActive');
$this->passthruTemplateVariable($dto, 'Status.all');
$this->passthruTemplateVariable($dto, 'Status.eq');
$this->passthruTemplateVariable($dto, 'TreeID.childOf');
$this->passthruTemplateVariable($dto, 'TreeID.eq');
$this->passthruTemplateVariable($dto, 'ActiveDate.before');
$this->passthruTemplateVariable($dto, 'ActiveDate.after');
$this->passthruTemplateVariable($dto, 'ActiveDate.start');
$this->passthruTemplateVariable($dto, 'ActiveDate.end');
$this->passthruTemplateVariable($dto, 'CreationDate.before');
$this->passthruTemplateVariable($dto, 'CreationDate.after');
$this->passthruTemplateVariable($dto, 'CreationDate.start');
$this->passthruTemplateVariable($dto, 'CreationDate.end');
$this->passthruTemplateVariable($dto, 'OutTags.exist');
$this->passthruTemplateVariable($dto, 'InTags.exist');
$this->passthruTemplateVariable($dto, 'Meta.exist');
// $this->passthruTemplateVariable($dto, 'Sections.exist');
foreach ($this->templateVars as $name => $value) {
if (strpos($name, '#') === 0)
$dto->setParameter($name, $value);
}
$this->buildFilters($dto);
$dto->isRetrieveTotalRecords(true);
$dto->setOrderBy($this->getTemplateVariable('OrderBy'));
$this->buildSorts($dto);
$this->Events->trigger('NodeCmsController.items', $dto);
try {
$dto = $this->RegulatedNodeService->findAll($dto,
(($frw = $this->getTemplateVariable('ForceReadWrite'))!=null?StringUtils::strToBool($frw):false));
return $this->readNodeQuery($dto);
} catch (NoElementsException $e) {
throw new NotFoundException('No elements were found for this request.');
}
} | php | protected function items()
{
// check permissions
// $siteIDs = $this->checkItemsPermission();
$dto = new NodeQuery();
$this->buildLimitOffset($dto);
$this->passthruTemplateVariable($dto, 'Elements.in');
$this->passthruTemplateVariable($dto, 'Sites.in');
//$this->passthruTemplateVariable($dto, 'SiteIDs.in');
$this->passthruTemplateVariable($dto, 'Slugs.in');
$this->passthruTemplateVariable($dto, 'Meta.select');
$this->passthruTemplateVariable($dto, 'OutTags.select');
$this->passthruTemplateVariable($dto, 'InTags.select');
// $this->passthruTemplateVariable($dto, 'Sections.select');
$this->passthruTemplateVariable($dto, 'OrderByInTag');
$this->passthruTemplateVariable($dto, 'OrderByOutTag');
$this->passthruTemplateVariable($dto, 'Title.like');
$this->passthruTemplateVariable($dto, 'Title.ieq');
$this->passthruTemplateVariable($dto, 'Title.eq');
$this->passthruTemplateVariable($dto, 'Title.firstChar');
$this->passthruTemplateVariable($dto, 'Status.isActive');
$this->passthruTemplateVariable($dto, 'Status.all');
$this->passthruTemplateVariable($dto, 'Status.eq');
$this->passthruTemplateVariable($dto, 'TreeID.childOf');
$this->passthruTemplateVariable($dto, 'TreeID.eq');
$this->passthruTemplateVariable($dto, 'ActiveDate.before');
$this->passthruTemplateVariable($dto, 'ActiveDate.after');
$this->passthruTemplateVariable($dto, 'ActiveDate.start');
$this->passthruTemplateVariable($dto, 'ActiveDate.end');
$this->passthruTemplateVariable($dto, 'CreationDate.before');
$this->passthruTemplateVariable($dto, 'CreationDate.after');
$this->passthruTemplateVariable($dto, 'CreationDate.start');
$this->passthruTemplateVariable($dto, 'CreationDate.end');
$this->passthruTemplateVariable($dto, 'OutTags.exist');
$this->passthruTemplateVariable($dto, 'InTags.exist');
$this->passthruTemplateVariable($dto, 'Meta.exist');
// $this->passthruTemplateVariable($dto, 'Sections.exist');
foreach ($this->templateVars as $name => $value) {
if (strpos($name, '#') === 0)
$dto->setParameter($name, $value);
}
$this->buildFilters($dto);
$dto->isRetrieveTotalRecords(true);
$dto->setOrderBy($this->getTemplateVariable('OrderBy'));
$this->buildSorts($dto);
$this->Events->trigger('NodeCmsController.items', $dto);
try {
$dto = $this->RegulatedNodeService->findAll($dto,
(($frw = $this->getTemplateVariable('ForceReadWrite'))!=null?StringUtils::strToBool($frw):false));
return $this->readNodeQuery($dto);
} catch (NoElementsException $e) {
throw new NotFoundException('No elements were found for this request.');
}
} | [
"protected",
"function",
"items",
"(",
")",
"{",
"// check permissions",
"// $siteIDs = $this->checkItemsPermission();",
"$",
"dto",
"=",
"new",
"NodeQuery",
"(",
")",
";",
"$",
"this",
"->",
"buildLimitOffset",
"(",
"$",
"dto",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Elements.in'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Sites.in'",
")",
";",
"//$this->passthruTemplateVariable($dto, 'SiteIDs.in');",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Slugs.in'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Meta.select'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'OutTags.select'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'InTags.select'",
")",
";",
"// $this->passthruTemplateVariable($dto, 'Sections.select');",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'OrderByInTag'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'OrderByOutTag'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Title.like'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Title.ieq'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Title.eq'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Title.firstChar'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Status.isActive'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Status.all'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Status.eq'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'TreeID.childOf'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'TreeID.eq'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'ActiveDate.before'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'ActiveDate.after'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'ActiveDate.start'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'ActiveDate.end'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'CreationDate.before'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'CreationDate.after'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'CreationDate.start'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'CreationDate.end'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'OutTags.exist'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'InTags.exist'",
")",
";",
"$",
"this",
"->",
"passthruTemplateVariable",
"(",
"$",
"dto",
",",
"'Meta.exist'",
")",
";",
"// $this->passthruTemplateVariable($dto, 'Sections.exist');",
"foreach",
"(",
"$",
"this",
"->",
"templateVars",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'#'",
")",
"===",
"0",
")",
"$",
"dto",
"->",
"setParameter",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"buildFilters",
"(",
"$",
"dto",
")",
";",
"$",
"dto",
"->",
"isRetrieveTotalRecords",
"(",
"true",
")",
";",
"$",
"dto",
"->",
"setOrderBy",
"(",
"$",
"this",
"->",
"getTemplateVariable",
"(",
"'OrderBy'",
")",
")",
";",
"$",
"this",
"->",
"buildSorts",
"(",
"$",
"dto",
")",
";",
"$",
"this",
"->",
"Events",
"->",
"trigger",
"(",
"'NodeCmsController.items'",
",",
"$",
"dto",
")",
";",
"try",
"{",
"$",
"dto",
"=",
"$",
"this",
"->",
"RegulatedNodeService",
"->",
"findAll",
"(",
"$",
"dto",
",",
"(",
"(",
"$",
"frw",
"=",
"$",
"this",
"->",
"getTemplateVariable",
"(",
"'ForceReadWrite'",
")",
")",
"!=",
"null",
"?",
"StringUtils",
"::",
"strToBool",
"(",
"$",
"frw",
")",
":",
"false",
")",
")",
";",
"return",
"$",
"this",
"->",
"readNodeQuery",
"(",
"$",
"dto",
")",
";",
"}",
"catch",
"(",
"NoElementsException",
"$",
"e",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"'No elements were found for this request.'",
")",
";",
"}",
"}"
]
| Datasource for returning all matching Nodes
@return DTO contains all matching nodes (As array) | [
"Datasource",
"for",
"returning",
"all",
"matching",
"Nodes"
]
| 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/controllers/NodeCmsController.php#L824-L891 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/controllers/NodeCmsController.php | NodeCmsController.buildCmsNodeRef | protected function buildCmsNodeRef($slugKey = 'OriginalSlug')
{
if (empty($this->params['Element']))
throw new Exception('Element parameter is required');
$nodeElement = $this->ElementService->getBySlug($this->params['Element']);
if (!is_null($slugKey) && $this->Request->getParameter($slugKey) != '') {
$slug = $this->Request->getParameter($slugKey);
$this->nodeRef = new NodeRef($nodeElement, $slug);
} else {
$this->nodeRef = new NodeRef($nodeElement);
}
return $this->nodeRef;
} | php | protected function buildCmsNodeRef($slugKey = 'OriginalSlug')
{
if (empty($this->params['Element']))
throw new Exception('Element parameter is required');
$nodeElement = $this->ElementService->getBySlug($this->params['Element']);
if (!is_null($slugKey) && $this->Request->getParameter($slugKey) != '') {
$slug = $this->Request->getParameter($slugKey);
$this->nodeRef = new NodeRef($nodeElement, $slug);
} else {
$this->nodeRef = new NodeRef($nodeElement);
}
return $this->nodeRef;
} | [
"protected",
"function",
"buildCmsNodeRef",
"(",
"$",
"slugKey",
"=",
"'OriginalSlug'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"params",
"[",
"'Element'",
"]",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Element parameter is required'",
")",
";",
"$",
"nodeElement",
"=",
"$",
"this",
"->",
"ElementService",
"->",
"getBySlug",
"(",
"$",
"this",
"->",
"params",
"[",
"'Element'",
"]",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"slugKey",
")",
"&&",
"$",
"this",
"->",
"Request",
"->",
"getParameter",
"(",
"$",
"slugKey",
")",
"!=",
"''",
")",
"{",
"$",
"slug",
"=",
"$",
"this",
"->",
"Request",
"->",
"getParameter",
"(",
"$",
"slugKey",
")",
";",
"$",
"this",
"->",
"nodeRef",
"=",
"new",
"NodeRef",
"(",
"$",
"nodeElement",
",",
"$",
"slug",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"nodeRef",
"=",
"new",
"NodeRef",
"(",
"$",
"nodeElement",
")",
";",
"}",
"return",
"$",
"this",
"->",
"nodeRef",
";",
"}"
]
| Given a slug, builds a nodeRef
@param string $slugKey The slug to use
@return NodeRef | [
"Given",
"a",
"slug",
"builds",
"a",
"nodeRef"
]
| 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/controllers/NodeCmsController.php#L908-L925 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Models/Post.php | Post.date | public function date($date=null)
{
if(is_null($date)) {
$date = $this->created_at;
}
return String::date($date);
} | php | public function date($date=null)
{
if(is_null($date)) {
$date = $this->created_at;
}
return String::date($date);
} | [
"public",
"function",
"date",
"(",
"$",
"date",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"date",
")",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"created_at",
";",
"}",
"return",
"String",
"::",
"date",
"(",
"$",
"date",
")",
";",
"}"
]
| Get the date the post was created.
@param \Carbon|null $date
@return string | [
"Get",
"the",
"date",
"the",
"post",
"was",
"created",
"."
]
| 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Models/Post.php#L619-L625 | train |
squareproton/Bond | src/Bond/Normality/Notify.php | Notify.parse | public function parse( QuoteInterface $quoting )
{
$outputSql = "";
foreach( $this->relations as $relation ) {
$columns = array();
foreach( $relation->getPrimaryKeys() as $column ) {
$columns[$column->get('name')] = $column->getType()->getTypeQuery();
}
// trigger sql
if( $this->notificationSql( $quoting, $columns, $functionName, $triggerSql ) ) {
$outputSql .= $triggerSql;
}
$relationName = $relation->get('name');
$relationQuoted = $quoting->quoteIdent( $relation->get('fullyQualifiedName') );
// generate trigger for table
$outputSql .= <<<SQL
CREATE TRIGGER "trg_notify_{$relationName}_insert" AFTER INSERT ON {$relationQuoted} FOR EACH ROW EXECUTE PROCEDURE "{$functionName}_insert"();
CREATE TRIGGER "trg_notify_{$relationName}_update" AFTER UPDATE ON {$relationQuoted} FOR EACH ROW EXECUTE PROCEDURE "{$functionName}_update"();
CREATE TRIGGER "trg_notify_{$relationName}_delete" AFTER DELETE ON {$relationQuoted} FOR EACH ROW EXECUTE PROCEDURE "{$functionName}_delete"();\n\n
SQL;
}
// execute triggers
return $outputSql;
} | php | public function parse( QuoteInterface $quoting )
{
$outputSql = "";
foreach( $this->relations as $relation ) {
$columns = array();
foreach( $relation->getPrimaryKeys() as $column ) {
$columns[$column->get('name')] = $column->getType()->getTypeQuery();
}
// trigger sql
if( $this->notificationSql( $quoting, $columns, $functionName, $triggerSql ) ) {
$outputSql .= $triggerSql;
}
$relationName = $relation->get('name');
$relationQuoted = $quoting->quoteIdent( $relation->get('fullyQualifiedName') );
// generate trigger for table
$outputSql .= <<<SQL
CREATE TRIGGER "trg_notify_{$relationName}_insert" AFTER INSERT ON {$relationQuoted} FOR EACH ROW EXECUTE PROCEDURE "{$functionName}_insert"();
CREATE TRIGGER "trg_notify_{$relationName}_update" AFTER UPDATE ON {$relationQuoted} FOR EACH ROW EXECUTE PROCEDURE "{$functionName}_update"();
CREATE TRIGGER "trg_notify_{$relationName}_delete" AFTER DELETE ON {$relationQuoted} FOR EACH ROW EXECUTE PROCEDURE "{$functionName}_delete"();\n\n
SQL;
}
// execute triggers
return $outputSql;
} | [
"public",
"function",
"parse",
"(",
"QuoteInterface",
"$",
"quoting",
")",
"{",
"$",
"outputSql",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"relations",
"as",
"$",
"relation",
")",
"{",
"$",
"columns",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"relation",
"->",
"getPrimaryKeys",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"columns",
"[",
"$",
"column",
"->",
"get",
"(",
"'name'",
")",
"]",
"=",
"$",
"column",
"->",
"getType",
"(",
")",
"->",
"getTypeQuery",
"(",
")",
";",
"}",
"// trigger sql",
"if",
"(",
"$",
"this",
"->",
"notificationSql",
"(",
"$",
"quoting",
",",
"$",
"columns",
",",
"$",
"functionName",
",",
"$",
"triggerSql",
")",
")",
"{",
"$",
"outputSql",
".=",
"$",
"triggerSql",
";",
"}",
"$",
"relationName",
"=",
"$",
"relation",
"->",
"get",
"(",
"'name'",
")",
";",
"$",
"relationQuoted",
"=",
"$",
"quoting",
"->",
"quoteIdent",
"(",
"$",
"relation",
"->",
"get",
"(",
"'fullyQualifiedName'",
")",
")",
";",
"// generate trigger for table",
"$",
"outputSql",
".=",
" <<<SQL\nCREATE TRIGGER \"trg_notify_{$relationName}_insert\" AFTER INSERT ON {$relationQuoted} FOR EACH ROW EXECUTE PROCEDURE \"{$functionName}_insert\"();\nCREATE TRIGGER \"trg_notify_{$relationName}_update\" AFTER UPDATE ON {$relationQuoted} FOR EACH ROW EXECUTE PROCEDURE \"{$functionName}_update\"();\nCREATE TRIGGER \"trg_notify_{$relationName}_delete\" AFTER DELETE ON {$relationQuoted} FOR EACH ROW EXECUTE PROCEDURE \"{$functionName}_delete\"();\\n\\n\nSQL",
";",
"}",
"// execute triggers",
"return",
"$",
"outputSql",
";",
"}"
]
| Generate and execute sql which will attach notification triggers to relations
@inheritDoc | [
"Generate",
"and",
"execute",
"sql",
"which",
"will",
"attach",
"notification",
"triggers",
"to",
"relations"
]
| a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/Notify.php#L78-L110 | train |
squareproton/Bond | src/Bond/Normality/Notify.php | Notify.donovan | public function donovan( QuoteInterface $quoting, $prefix, $columns )
{
$sql = array();
foreach( $columns as $column => $type ) {
$sql[] = sprintf(
'donovan(%s%s)',
$prefix,
$quoting->quoteIdent( $column )
);
}
return sprintf(
"'['||%s||']'",
implode("||','||", $sql)
);
} | php | public function donovan( QuoteInterface $quoting, $prefix, $columns )
{
$sql = array();
foreach( $columns as $column => $type ) {
$sql[] = sprintf(
'donovan(%s%s)',
$prefix,
$quoting->quoteIdent( $column )
);
}
return sprintf(
"'['||%s||']'",
implode("||','||", $sql)
);
} | [
"public",
"function",
"donovan",
"(",
"QuoteInterface",
"$",
"quoting",
",",
"$",
"prefix",
",",
"$",
"columns",
")",
"{",
"$",
"sql",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
"=>",
"$",
"type",
")",
"{",
"$",
"sql",
"[",
"]",
"=",
"sprintf",
"(",
"'donovan(%s%s)'",
",",
"$",
"prefix",
",",
"$",
"quoting",
"->",
"quoteIdent",
"(",
"$",
"column",
")",
")",
";",
"}",
"return",
"sprintf",
"(",
"\"'['||%s||']'\"",
",",
"implode",
"(",
"\"||','||\"",
",",
"$",
"sql",
")",
")",
";",
"}"
]
| Produce a sql statement which resolves to a string but is a valid json
@return string Sql which evaluates to JSON | [
"Produce",
"a",
"sql",
"statement",
"which",
"resolves",
"to",
"a",
"string",
"but",
"is",
"a",
"valid",
"json"
]
| a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/Notify.php#L217-L231 | train |
squareproton/Bond | src/Bond/Normality/Notify.php | Notify.catalogRefresh | private function catalogRefresh()
{
Relation::r()->preload();
Attribute::r()->preload();
Type::r()->preload();
Index::r()->preload();
} | php | private function catalogRefresh()
{
Relation::r()->preload();
Attribute::r()->preload();
Type::r()->preload();
Index::r()->preload();
} | [
"private",
"function",
"catalogRefresh",
"(",
")",
"{",
"Relation",
"::",
"r",
"(",
")",
"->",
"preload",
"(",
")",
";",
"Attribute",
"::",
"r",
"(",
")",
"->",
"preload",
"(",
")",
";",
"Type",
"::",
"r",
"(",
")",
"->",
"preload",
"(",
")",
";",
"Index",
"::",
"r",
"(",
")",
"->",
"preload",
"(",
")",
";",
"}"
]
| Refresh the catalog | [
"Refresh",
"the",
"catalog"
]
| a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality/Notify.php#L236-L242 | train |
AnonymPHP/Anonym-Route | Controller.php | Controller.validate | public function validate(Request $request, array $rules = [], array $filters = [])
{
$all = $request->all();
return $request->getValidation()->make($all, $rules, $filters);
} | php | public function validate(Request $request, array $rules = [], array $filters = [])
{
$all = $request->all();
return $request->getValidation()->make($all, $rules, $filters);
} | [
"public",
"function",
"validate",
"(",
"Request",
"$",
"request",
",",
"array",
"$",
"rules",
"=",
"[",
"]",
",",
"array",
"$",
"filters",
"=",
"[",
"]",
")",
"{",
"$",
"all",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"return",
"$",
"request",
"->",
"getValidation",
"(",
")",
"->",
"make",
"(",
"$",
"all",
",",
"$",
"rules",
",",
"$",
"filters",
")",
";",
"}"
]
| validate the form
@param Request $request
@param array $rules
@param array $filters | [
"validate",
"the",
"form"
]
| bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Controller.php#L62-L67 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/encryption/Encryption.php | Encryption.encrypt | public function encrypt($value, $iv = null)
{
if(empty($value))
return false;
include_once PATH_SYSTEM . '/vendors/phpseclib0/Crypt/Rijndael.php';
include_once PATH_SYSTEM . '/vendors/phpseclib0/Crypt/AES.php';
$this->Crypt = new Crypt_AES();
$this->Crypt->setKey($this->key);
if (!is_null($iv))
$this->Crypt->setIV($iv);
return $this->Crypt->encrypt($value);
} | php | public function encrypt($value, $iv = null)
{
if(empty($value))
return false;
include_once PATH_SYSTEM . '/vendors/phpseclib0/Crypt/Rijndael.php';
include_once PATH_SYSTEM . '/vendors/phpseclib0/Crypt/AES.php';
$this->Crypt = new Crypt_AES();
$this->Crypt->setKey($this->key);
if (!is_null($iv))
$this->Crypt->setIV($iv);
return $this->Crypt->encrypt($value);
} | [
"public",
"function",
"encrypt",
"(",
"$",
"value",
",",
"$",
"iv",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"return",
"false",
";",
"include_once",
"PATH_SYSTEM",
".",
"'/vendors/phpseclib0/Crypt/Rijndael.php'",
";",
"include_once",
"PATH_SYSTEM",
".",
"'/vendors/phpseclib0/Crypt/AES.php'",
";",
"$",
"this",
"->",
"Crypt",
"=",
"new",
"Crypt_AES",
"(",
")",
";",
"$",
"this",
"->",
"Crypt",
"->",
"setKey",
"(",
"$",
"this",
"->",
"key",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"iv",
")",
")",
"$",
"this",
"->",
"Crypt",
"->",
"setIV",
"(",
"$",
"iv",
")",
";",
"return",
"$",
"this",
"->",
"Crypt",
"->",
"encrypt",
"(",
"$",
"value",
")",
";",
"}"
]
| Encrypts the given value using the included phpseclib AES implementation
@param string $value The value to encrypt
@param string $iv (optional) the initialization vector
@return string the encrypted version of $value | [
"Encrypts",
"the",
"given",
"value",
"using",
"the",
"included",
"phpseclib",
"AES",
"implementation"
]
| 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/encryption/Encryption.php#L130-L143 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/encryption/Encryption.php | Encryption.decryptSecureCookie | public function decryptSecureCookie($value)
{
$cookieValues = explode('|', $value, 4);
if ((count($cookieValues) === 4) && ($cookieValues[1] == 0 || $cookieValues[1] >= time())) {
$userid = $cookieValues[0];
$expire = $cookieValues[1];
$encrValue = $cookieValues[2];
$key = hash_hmac('sha1', $userid.$expire, $this->key);
$value = $this->decrypt(base64_decode(str_replace(' ', '+', $encrValue)), md5($expire));
if ($this->includeSSLKey == true && ($sslKey = $this->Request->getServerAttribute('SSL_SESSION_ID')))
$verifyKey = hash_hmac('sha1', $userid . $expire . $value . $sslKey, $key);
else
$verifyKey = hash_hmac('sha1', $userid . $expire . $value, $key);
if (strcmp($verifyKey, $cookieValues[3]) === 0)
return $value;
}
return false;
} | php | public function decryptSecureCookie($value)
{
$cookieValues = explode('|', $value, 4);
if ((count($cookieValues) === 4) && ($cookieValues[1] == 0 || $cookieValues[1] >= time())) {
$userid = $cookieValues[0];
$expire = $cookieValues[1];
$encrValue = $cookieValues[2];
$key = hash_hmac('sha1', $userid.$expire, $this->key);
$value = $this->decrypt(base64_decode(str_replace(' ', '+', $encrValue)), md5($expire));
if ($this->includeSSLKey == true && ($sslKey = $this->Request->getServerAttribute('SSL_SESSION_ID')))
$verifyKey = hash_hmac('sha1', $userid . $expire . $value . $sslKey, $key);
else
$verifyKey = hash_hmac('sha1', $userid . $expire . $value, $key);
if (strcmp($verifyKey, $cookieValues[3]) === 0)
return $value;
}
return false;
} | [
"public",
"function",
"decryptSecureCookie",
"(",
"$",
"value",
")",
"{",
"$",
"cookieValues",
"=",
"explode",
"(",
"'|'",
",",
"$",
"value",
",",
"4",
")",
";",
"if",
"(",
"(",
"count",
"(",
"$",
"cookieValues",
")",
"===",
"4",
")",
"&&",
"(",
"$",
"cookieValues",
"[",
"1",
"]",
"==",
"0",
"||",
"$",
"cookieValues",
"[",
"1",
"]",
">=",
"time",
"(",
")",
")",
")",
"{",
"$",
"userid",
"=",
"$",
"cookieValues",
"[",
"0",
"]",
";",
"$",
"expire",
"=",
"$",
"cookieValues",
"[",
"1",
"]",
";",
"$",
"encrValue",
"=",
"$",
"cookieValues",
"[",
"2",
"]",
";",
"$",
"key",
"=",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"userid",
".",
"$",
"expire",
",",
"$",
"this",
"->",
"key",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"decrypt",
"(",
"base64_decode",
"(",
"str_replace",
"(",
"' '",
",",
"'+'",
",",
"$",
"encrValue",
")",
")",
",",
"md5",
"(",
"$",
"expire",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"includeSSLKey",
"==",
"true",
"&&",
"(",
"$",
"sslKey",
"=",
"$",
"this",
"->",
"Request",
"->",
"getServerAttribute",
"(",
"'SSL_SESSION_ID'",
")",
")",
")",
"$",
"verifyKey",
"=",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"userid",
".",
"$",
"expire",
".",
"$",
"value",
".",
"$",
"sslKey",
",",
"$",
"key",
")",
";",
"else",
"$",
"verifyKey",
"=",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"userid",
".",
"$",
"expire",
".",
"$",
"value",
",",
"$",
"key",
")",
";",
"if",
"(",
"strcmp",
"(",
"$",
"verifyKey",
",",
"$",
"cookieValues",
"[",
"3",
"]",
")",
"===",
"0",
")",
"return",
"$",
"value",
";",
"}",
"return",
"false",
";",
"}"
]
| Retrieve a secured cookie value
@param string $value The secured value
@return string the value stored in the secured cookie or false if unsuccessful | [
"Retrieve",
"a",
"secured",
"cookie",
"value"
]
| 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/encryption/Encryption.php#L152-L172 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/encryption/Encryption.php | Encryption.encryptSecureCookie | public function encryptSecureCookie($value, $expire, $userid = null)
{
$expire = (strcmp(strtolower($expire), 'never') === 0 ? time() + 60 * 60 * 24 * 6000 : $expire);
if (is_null($userid))
$userid = (string)$this->RequestContext->getUserRef();
$key = hash_hmac('sha1', $userid.$expire, $this->key);
$encrValue = base64_encode($this->encrypt($value, md5($expire)));
if ($this->includeSSLKey == true && ($sslKey = $this->Request->getServerAttribute('SSL_SESSION_ID')))
$verifyKey = hash_hmac('sha1', $userid . $expire . $value . $sslKey, $key);
else
$verifyKey = hash_hmac('sha1', $userid . $expire . $value, $key);
$result = array($userid, $expire, $encrValue, $verifyKey);
return(implode('|', $result));
} | php | public function encryptSecureCookie($value, $expire, $userid = null)
{
$expire = (strcmp(strtolower($expire), 'never') === 0 ? time() + 60 * 60 * 24 * 6000 : $expire);
if (is_null($userid))
$userid = (string)$this->RequestContext->getUserRef();
$key = hash_hmac('sha1', $userid.$expire, $this->key);
$encrValue = base64_encode($this->encrypt($value, md5($expire)));
if ($this->includeSSLKey == true && ($sslKey = $this->Request->getServerAttribute('SSL_SESSION_ID')))
$verifyKey = hash_hmac('sha1', $userid . $expire . $value . $sslKey, $key);
else
$verifyKey = hash_hmac('sha1', $userid . $expire . $value, $key);
$result = array($userid, $expire, $encrValue, $verifyKey);
return(implode('|', $result));
} | [
"public",
"function",
"encryptSecureCookie",
"(",
"$",
"value",
",",
"$",
"expire",
",",
"$",
"userid",
"=",
"null",
")",
"{",
"$",
"expire",
"=",
"(",
"strcmp",
"(",
"strtolower",
"(",
"$",
"expire",
")",
",",
"'never'",
")",
"===",
"0",
"?",
"time",
"(",
")",
"+",
"60",
"*",
"60",
"*",
"24",
"*",
"6000",
":",
"$",
"expire",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"userid",
")",
")",
"$",
"userid",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"RequestContext",
"->",
"getUserRef",
"(",
")",
";",
"$",
"key",
"=",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"userid",
".",
"$",
"expire",
",",
"$",
"this",
"->",
"key",
")",
";",
"$",
"encrValue",
"=",
"base64_encode",
"(",
"$",
"this",
"->",
"encrypt",
"(",
"$",
"value",
",",
"md5",
"(",
"$",
"expire",
")",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"includeSSLKey",
"==",
"true",
"&&",
"(",
"$",
"sslKey",
"=",
"$",
"this",
"->",
"Request",
"->",
"getServerAttribute",
"(",
"'SSL_SESSION_ID'",
")",
")",
")",
"$",
"verifyKey",
"=",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"userid",
".",
"$",
"expire",
".",
"$",
"value",
".",
"$",
"sslKey",
",",
"$",
"key",
")",
";",
"else",
"$",
"verifyKey",
"=",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"userid",
".",
"$",
"expire",
".",
"$",
"value",
",",
"$",
"key",
")",
";",
"$",
"result",
"=",
"array",
"(",
"$",
"userid",
",",
"$",
"expire",
",",
"$",
"encrValue",
",",
"$",
"verifyKey",
")",
";",
"return",
"(",
"implode",
"(",
"'|'",
",",
"$",
"result",
")",
")",
";",
"}"
]
| Secure a cookie value
The initial value is transformed with this protocol :
secureValue = username|expire|base64((value)k,expire)|HMAC(user|expire|value,k)
where k = HMAC(user|expire, sk)
and sk is server's secret key
(value)k,md5(expire) is the result an cryptographic function (ex: AES256) on "value" with key k and initialisation vector = md5(expire)
@param string $value unsecure value
@param integer $expire expiration time
@param string $userid user id, or uses RequestContext->getUserRef
@return string secured value | [
"Secure",
"a",
"cookie",
"value"
]
| 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/encryption/Encryption.php#L190-L207 | train |
jenskooij/cloudcontrol | src/components/cms/CmsRouting.php | CmsRouting.doRouting | abstract public function __construct(Request $request, $relativeCmsUri, CmsComponent $cmsComponent);
/**
* @param Request $request
* @param string $relativeCmsUri
* @param CmsComponent $cmsComponent
* @throws \Exception
*/
protected function doRouting($request, $relativeCmsUri, $cmsComponent)
{
if (array_key_exists($relativeCmsUri, $this::$routes)) {
$method = $this::$routes[$relativeCmsUri];
$this->$method($request, $cmsComponent);
}
} | php | abstract public function __construct(Request $request, $relativeCmsUri, CmsComponent $cmsComponent);
/**
* @param Request $request
* @param string $relativeCmsUri
* @param CmsComponent $cmsComponent
* @throws \Exception
*/
protected function doRouting($request, $relativeCmsUri, $cmsComponent)
{
if (array_key_exists($relativeCmsUri, $this::$routes)) {
$method = $this::$routes[$relativeCmsUri];
$this->$method($request, $cmsComponent);
}
} | [
"abstract",
"public",
"function",
"__construct",
"(",
"Request",
"$",
"request",
",",
"$",
"relativeCmsUri",
",",
"CmsComponent",
"$",
"cmsComponent",
")",
";",
"/**\n * @param Request $request\n * @param string $relativeCmsUri\n * @param CmsComponent $cmsComponent\n * @throws \\Exception\n */",
"protected",
"function",
"doRouting",
"(",
"$",
"request",
",",
"$",
"relativeCmsUri",
",",
"$",
"cmsComponent",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"relativeCmsUri",
",",
"$",
"this",
"::",
"$",
"routes",
")",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"::",
"$",
"routes",
"[",
"$",
"relativeCmsUri",
"]",
";",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"request",
",",
"$",
"cmsComponent",
")",
";",
"}",
"}"
]
| CmsRouting constructor.
@param Request $request
@param string $relativeCmsUri
@param CmsComponent $cmsComponent | [
"CmsRouting",
"constructor",
"."
]
| 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/components/cms/CmsRouting.php#L34-L40 | train |
ebidtech/ebt-validator | src/EBT/Validator/Model/Validator/Validator.php | Validator.isRequiredIntegerRange | public static function isRequiredIntegerRange($value, $min, $max)
{
return is_int($value) && $min <= $value && $max >= $value;
} | php | public static function isRequiredIntegerRange($value, $min, $max)
{
return is_int($value) && $min <= $value && $max >= $value;
} | [
"public",
"static",
"function",
"isRequiredIntegerRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"return",
"is_int",
"(",
"$",
"value",
")",
"&&",
"$",
"min",
"<=",
"$",
"value",
"&&",
"$",
"max",
">=",
"$",
"value",
";",
"}"
]
| Required value is integer in range.
@param mixed $value Value.
@param int $min Lower limit.
@param int $max Upper limit.
@return bool | [
"Required",
"value",
"is",
"integer",
"in",
"range",
"."
]
| 4f826ee3298f87eb19a8d5b2c7f998da351e5104 | https://github.com/ebidtech/ebt-validator/blob/4f826ee3298f87eb19a8d5b2c7f998da351e5104/src/EBT/Validator/Model/Validator/Validator.php#L65-L68 | train |
ebidtech/ebt-validator | src/EBT/Validator/Model/Validator/Validator.php | Validator.isOptionalIntegerRange | public static function isOptionalIntegerRange($value, $min, $max)
{
/* No additional validations when the value is null. */
if (null === $value) {
return true;
}
return self::isRequiredIntegerRange($value, $min, $max);
} | php | public static function isOptionalIntegerRange($value, $min, $max)
{
/* No additional validations when the value is null. */
if (null === $value) {
return true;
}
return self::isRequiredIntegerRange($value, $min, $max);
} | [
"public",
"static",
"function",
"isOptionalIntegerRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"/* No additional validations when the value is null. */",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"return",
"self",
"::",
"isRequiredIntegerRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
";",
"}"
]
| Optional value is integer in range.
@param mixed $value Value.
@param int $min Lower limit.
@param int $max Upper limit.
@return bool | [
"Optional",
"value",
"is",
"integer",
"in",
"range",
"."
]
| 4f826ee3298f87eb19a8d5b2c7f998da351e5104 | https://github.com/ebidtech/ebt-validator/blob/4f826ee3298f87eb19a8d5b2c7f998da351e5104/src/EBT/Validator/Model/Validator/Validator.php#L133-L142 | train |
ebidtech/ebt-validator | src/EBT/Validator/Model/Validator/Validator.php | Validator.isRequiredFloatRange | public static function isRequiredFloatRange($value, $min, $max)
{
return is_float($value) && $min <= $value && $max >= $value;
} | php | public static function isRequiredFloatRange($value, $min, $max)
{
return is_float($value) && $min <= $value && $max >= $value;
} | [
"public",
"static",
"function",
"isRequiredFloatRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"return",
"is_float",
"(",
"$",
"value",
")",
"&&",
"$",
"min",
"<=",
"$",
"value",
"&&",
"$",
"max",
">=",
"$",
"value",
";",
"}"
]
| Required value is float in range.
@param mixed $value Value.
@param int $min Lower limit.
@param int $max Upper limit.
@return bool | [
"Required",
"value",
"is",
"float",
"in",
"range",
"."
]
| 4f826ee3298f87eb19a8d5b2c7f998da351e5104 | https://github.com/ebidtech/ebt-validator/blob/4f826ee3298f87eb19a8d5b2c7f998da351e5104/src/EBT/Validator/Model/Validator/Validator.php#L193-L196 | train |
ebidtech/ebt-validator | src/EBT/Validator/Model/Validator/Validator.php | Validator.isOptionalFloatRange | public static function isOptionalFloatRange($value, $min, $max)
{
/* No additional validations when the value is null. */
if (null === $value) {
return true;
}
return self::isRequiredFloatRange($value, $min, $max);
} | php | public static function isOptionalFloatRange($value, $min, $max)
{
/* No additional validations when the value is null. */
if (null === $value) {
return true;
}
return self::isRequiredFloatRange($value, $min, $max);
} | [
"public",
"static",
"function",
"isOptionalFloatRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"/* No additional validations when the value is null. */",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"return",
"self",
"::",
"isRequiredFloatRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
";",
"}"
]
| Optional value is float in range.
@param mixed $value Value.
@param int $min Lower limit.
@param int $max Upper limit.
@return bool | [
"Optional",
"value",
"is",
"float",
"in",
"range",
"."
]
| 4f826ee3298f87eb19a8d5b2c7f998da351e5104 | https://github.com/ebidtech/ebt-validator/blob/4f826ee3298f87eb19a8d5b2c7f998da351e5104/src/EBT/Validator/Model/Validator/Validator.php#L261-L270 | train |
ebidtech/ebt-validator | src/EBT/Validator/Model/Validator/Validator.php | Validator.isOptionalNumberRange | public static function isOptionalNumberRange($value, $min, $max)
{
/* No additional validations when the value is null. */
if (null === $value) {
return true;
}
return self::isRequiredNumberRange($value, $min, $max);
} | php | public static function isOptionalNumberRange($value, $min, $max)
{
/* No additional validations when the value is null. */
if (null === $value) {
return true;
}
return self::isRequiredNumberRange($value, $min, $max);
} | [
"public",
"static",
"function",
"isOptionalNumberRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"/* No additional validations when the value is null. */",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"return",
"self",
"::",
"isRequiredNumberRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
";",
"}"
]
| Optional value is number in range.
@param mixed $value Value.
@param int $min Lower limit.
@param int $max Upper limit.
@return bool | [
"Optional",
"value",
"is",
"number",
"in",
"range",
"."
]
| 4f826ee3298f87eb19a8d5b2c7f998da351e5104 | https://github.com/ebidtech/ebt-validator/blob/4f826ee3298f87eb19a8d5b2c7f998da351e5104/src/EBT/Validator/Model/Validator/Validator.php#L389-L398 | train |
ebidtech/ebt-validator | src/EBT/Validator/Model/Validator/Validator.php | Validator.isRequiredNumericRange | public static function isRequiredNumericRange($value, $min, $max)
{
return is_numeric($value) && $min <= $value && $max >= $value;
} | php | public static function isRequiredNumericRange($value, $min, $max)
{
return is_numeric($value) && $min <= $value && $max >= $value;
} | [
"public",
"static",
"function",
"isRequiredNumericRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"return",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"$",
"min",
"<=",
"$",
"value",
"&&",
"$",
"max",
">=",
"$",
"value",
";",
"}"
]
| Required value is numeric in range.
@param mixed $value Value.
@param int $min Lower limit.
@param int $max Upper limit.
@return bool | [
"Required",
"value",
"is",
"numeric",
"in",
"range",
"."
]
| 4f826ee3298f87eb19a8d5b2c7f998da351e5104 | https://github.com/ebidtech/ebt-validator/blob/4f826ee3298f87eb19a8d5b2c7f998da351e5104/src/EBT/Validator/Model/Validator/Validator.php#L449-L452 | train |
ebidtech/ebt-validator | src/EBT/Validator/Model/Validator/Validator.php | Validator.isOptionalNumericRange | public static function isOptionalNumericRange($value, $min, $max)
{
/* No additional validations when the value is null. */
if (null === $value) {
return true;
}
return self::isRequiredNumericRange($value, $min, $max);
} | php | public static function isOptionalNumericRange($value, $min, $max)
{
/* No additional validations when the value is null. */
if (null === $value) {
return true;
}
return self::isRequiredNumericRange($value, $min, $max);
} | [
"public",
"static",
"function",
"isOptionalNumericRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
"{",
"/* No additional validations when the value is null. */",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"return",
"self",
"::",
"isRequiredNumericRange",
"(",
"$",
"value",
",",
"$",
"min",
",",
"$",
"max",
")",
";",
"}"
]
| Optional value is numeric in range.
@param mixed $value Value.
@param int $min Lower limit.
@param int $max Upper limit.
@return bool | [
"Optional",
"value",
"is",
"numeric",
"in",
"range",
"."
]
| 4f826ee3298f87eb19a8d5b2c7f998da351e5104 | https://github.com/ebidtech/ebt-validator/blob/4f826ee3298f87eb19a8d5b2c7f998da351e5104/src/EBT/Validator/Model/Validator/Validator.php#L517-L526 | train |
ebidtech/ebt-validator | src/EBT/Validator/Model/Validator/Validator.php | Validator.isOptionalExistingKey | public static function isOptionalExistingKey($key, array $values)
{
/* No additional validations when the value is null. */
if (null === $key) {
return true;
}
return self::isRequiredExistingKey($key, $values);
} | php | public static function isOptionalExistingKey($key, array $values)
{
/* No additional validations when the value is null. */
if (null === $key) {
return true;
}
return self::isRequiredExistingKey($key, $values);
} | [
"public",
"static",
"function",
"isOptionalExistingKey",
"(",
"$",
"key",
",",
"array",
"$",
"values",
")",
"{",
"/* No additional validations when the value is null. */",
"if",
"(",
"null",
"===",
"$",
"key",
")",
"{",
"return",
"true",
";",
"}",
"return",
"self",
"::",
"isRequiredExistingKey",
"(",
"$",
"key",
",",
"$",
"values",
")",
";",
"}"
]
| Optional key exists.
@param string $key Key to check.
@param array $values Array in which to search.
@return bool | [
"Optional",
"key",
"exists",
"."
]
| 4f826ee3298f87eb19a8d5b2c7f998da351e5104 | https://github.com/ebidtech/ebt-validator/blob/4f826ee3298f87eb19a8d5b2c7f998da351e5104/src/EBT/Validator/Model/Validator/Validator.php#L848-L857 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.setParams | public function setParams($key, $value = null)
{
if(is_array($key))
{
$this->params = array_merge_recursive($this->params, $key);
return $this;
}
$this->params[$key] = $value;
return $this;
} | php | public function setParams($key, $value = null)
{
if(is_array($key))
{
$this->params = array_merge_recursive($this->params, $key);
return $this;
}
$this->params[$key] = $value;
return $this;
} | [
"public",
"function",
"setParams",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"params",
"=",
"array_merge_recursive",
"(",
"$",
"this",
"->",
"params",
",",
"$",
"key",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"params",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
]
| Set parameter data
@param string|array $key
@param mixed $value | [
"Set",
"parameter",
"data"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L158-L169 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.hasRelation | protected function hasRelation($key, $value, $relations)
{
if(is_numeric($relations)) {
if($relations > 0) {
return true;
}
return false;
}
foreach ($relations as $prop)
{
if($prop == 'assets')
{
if( $key === 'fields' || (! $this->resolved($value) && is_object($value) && property_exists($value, 'type') && $value->type == 'file'))
{
return true;
}
if(is_array($value) && ! empty($value))
{
$isAsset = true;
foreach ($value as $subValue)
{
if(!$this->isUnresolvedAsset($subValue)) {
$isAsset = false;
break;
}
}
if($isAsset) return true;
}
}
if($prop === $key || 0 === strpos($prop, $key.'.'))
{
return true;
}
}
return false;
} | php | protected function hasRelation($key, $value, $relations)
{
if(is_numeric($relations)) {
if($relations > 0) {
return true;
}
return false;
}
foreach ($relations as $prop)
{
if($prop == 'assets')
{
if( $key === 'fields' || (! $this->resolved($value) && is_object($value) && property_exists($value, 'type') && $value->type == 'file'))
{
return true;
}
if(is_array($value) && ! empty($value))
{
$isAsset = true;
foreach ($value as $subValue)
{
if(!$this->isUnresolvedAsset($subValue)) {
$isAsset = false;
break;
}
}
if($isAsset) return true;
}
}
if($prop === $key || 0 === strpos($prop, $key.'.'))
{
return true;
}
}
return false;
} | [
"protected",
"function",
"hasRelation",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"relations",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"relations",
")",
")",
"{",
"if",
"(",
"$",
"relations",
">",
"0",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"$",
"prop",
"==",
"'assets'",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'fields'",
"||",
"(",
"!",
"$",
"this",
"->",
"resolved",
"(",
"$",
"value",
")",
"&&",
"is_object",
"(",
"$",
"value",
")",
"&&",
"property_exists",
"(",
"$",
"value",
",",
"'type'",
")",
"&&",
"$",
"value",
"->",
"type",
"==",
"'file'",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"isAsset",
"=",
"true",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"subValue",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isUnresolvedAsset",
"(",
"$",
"subValue",
")",
")",
"{",
"$",
"isAsset",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"isAsset",
")",
"return",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"prop",
"===",
"$",
"key",
"||",
"0",
"===",
"strpos",
"(",
"$",
"prop",
",",
"$",
"key",
".",
"'.'",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Check if relation exists
@param string $key
@param mixed $value
@param array $relations
@return boolean | [
"Check",
"if",
"relation",
"exists"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L355-L392 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.getNestedRelations | protected function getNestedRelations($key, $relations)
{
if(is_numeric($relations))
{
if($key == 'fields')
{
return $relations;
}
if($relations - 1 > 0)
{
return $relations - 1;
}
return [];
}
$nestedRelations = [];
foreach ($relations as $prop)
{
if($prop === 'assets') {
$nestedRelations[] = $prop;
continue;
}
if(0 === strpos($prop, $key.'.'))
{
$newRelation = substr($prop, strlen($key) + 1);
if( strlen($newRelation) !== 0)
{
$nestedRelations[] = $newRelation;
}
}
}
$nestedRelations = array_unique($nestedRelations);
return $nestedRelations;
} | php | protected function getNestedRelations($key, $relations)
{
if(is_numeric($relations))
{
if($key == 'fields')
{
return $relations;
}
if($relations - 1 > 0)
{
return $relations - 1;
}
return [];
}
$nestedRelations = [];
foreach ($relations as $prop)
{
if($prop === 'assets') {
$nestedRelations[] = $prop;
continue;
}
if(0 === strpos($prop, $key.'.'))
{
$newRelation = substr($prop, strlen($key) + 1);
if( strlen($newRelation) !== 0)
{
$nestedRelations[] = $newRelation;
}
}
}
$nestedRelations = array_unique($nestedRelations);
return $nestedRelations;
} | [
"protected",
"function",
"getNestedRelations",
"(",
"$",
"key",
",",
"$",
"relations",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"relations",
")",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"'fields'",
")",
"{",
"return",
"$",
"relations",
";",
"}",
"if",
"(",
"$",
"relations",
"-",
"1",
">",
"0",
")",
"{",
"return",
"$",
"relations",
"-",
"1",
";",
"}",
"return",
"[",
"]",
";",
"}",
"$",
"nestedRelations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"$",
"prop",
"===",
"'assets'",
")",
"{",
"$",
"nestedRelations",
"[",
"]",
"=",
"$",
"prop",
";",
"continue",
";",
"}",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"prop",
",",
"$",
"key",
".",
"'.'",
")",
")",
"{",
"$",
"newRelation",
"=",
"substr",
"(",
"$",
"prop",
",",
"strlen",
"(",
"$",
"key",
")",
"+",
"1",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"newRelation",
")",
"!==",
"0",
")",
"{",
"$",
"nestedRelations",
"[",
"]",
"=",
"$",
"newRelation",
";",
"}",
"}",
"}",
"$",
"nestedRelations",
"=",
"array_unique",
"(",
"$",
"nestedRelations",
")",
";",
"return",
"$",
"nestedRelations",
";",
"}"
]
| Get nested relations for field
@param string $prop
@param array $relations
@return boolean | [
"Get",
"nested",
"relations",
"for",
"field"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L402-L435 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.loadQueue | protected function loadQueue()
{
$loadQueue = self::$loadQueue;
foreach ($loadQueue as $type => $queries)
{
foreach ($queries as $query)
{
$ids = [];
foreach ($query['ids'] as $id)
{
if( Trunk::has([$id, $query['relations']], $type) )
{
$object = Trunk::get([$id, $query['relations']], $type);
$this->addIncludes($object);
continue;
}
$ids[] = $id;
}
if( empty($ids) )
{
continue;
}
$locale = null;
if( ! empty($this->meta['locale']) )
{
$locale = $this->meta['locale'];
}
$result = Resolver::resolve($query['type'], $query['ids'], $query['relations'], $locale);
Trunk::put($result);
$this->addIncludes($result);
}
}
} | php | protected function loadQueue()
{
$loadQueue = self::$loadQueue;
foreach ($loadQueue as $type => $queries)
{
foreach ($queries as $query)
{
$ids = [];
foreach ($query['ids'] as $id)
{
if( Trunk::has([$id, $query['relations']], $type) )
{
$object = Trunk::get([$id, $query['relations']], $type);
$this->addIncludes($object);
continue;
}
$ids[] = $id;
}
if( empty($ids) )
{
continue;
}
$locale = null;
if( ! empty($this->meta['locale']) )
{
$locale = $this->meta['locale'];
}
$result = Resolver::resolve($query['type'], $query['ids'], $query['relations'], $locale);
Trunk::put($result);
$this->addIncludes($result);
}
}
} | [
"protected",
"function",
"loadQueue",
"(",
")",
"{",
"$",
"loadQueue",
"=",
"self",
"::",
"$",
"loadQueue",
";",
"foreach",
"(",
"$",
"loadQueue",
"as",
"$",
"type",
"=>",
"$",
"queries",
")",
"{",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"query",
")",
"{",
"$",
"ids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"[",
"'ids'",
"]",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"Trunk",
"::",
"has",
"(",
"[",
"$",
"id",
",",
"$",
"query",
"[",
"'relations'",
"]",
"]",
",",
"$",
"type",
")",
")",
"{",
"$",
"object",
"=",
"Trunk",
"::",
"get",
"(",
"[",
"$",
"id",
",",
"$",
"query",
"[",
"'relations'",
"]",
"]",
",",
"$",
"type",
")",
";",
"$",
"this",
"->",
"addIncludes",
"(",
"$",
"object",
")",
";",
"continue",
";",
"}",
"$",
"ids",
"[",
"]",
"=",
"$",
"id",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"continue",
";",
"}",
"$",
"locale",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"meta",
"[",
"'locale'",
"]",
")",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"meta",
"[",
"'locale'",
"]",
";",
"}",
"$",
"result",
"=",
"Resolver",
"::",
"resolve",
"(",
"$",
"query",
"[",
"'type'",
"]",
",",
"$",
"query",
"[",
"'ids'",
"]",
",",
"$",
"query",
"[",
"'relations'",
"]",
",",
"$",
"locale",
")",
";",
"Trunk",
"::",
"put",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"addIncludes",
"(",
"$",
"result",
")",
";",
"}",
"}",
"}"
]
| Load objects from queue
@return void | [
"Load",
"objects",
"from",
"queue"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L442-L482 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.addIncludes | public function addIncludes($includes)
{
if($includes instanceof Model)
{
$this->addItemToInclude($includes);
}
else
{
foreach ($includes as $item)
{
$this->addItemToInclude($item);
}
}
if($includes instanceof DataTransferObject)
{
$this->addIncludes($includes->getIncludes());
}
if($this instanceof Collection)
{
foreach ($this->data as $model)
{
$model->addIncludes($includes);
}
}
} | php | public function addIncludes($includes)
{
if($includes instanceof Model)
{
$this->addItemToInclude($includes);
}
else
{
foreach ($includes as $item)
{
$this->addItemToInclude($item);
}
}
if($includes instanceof DataTransferObject)
{
$this->addIncludes($includes->getIncludes());
}
if($this instanceof Collection)
{
foreach ($this->data as $model)
{
$model->addIncludes($includes);
}
}
} | [
"public",
"function",
"addIncludes",
"(",
"$",
"includes",
")",
"{",
"if",
"(",
"$",
"includes",
"instanceof",
"Model",
")",
"{",
"$",
"this",
"->",
"addItemToInclude",
"(",
"$",
"includes",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"includes",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"addItemToInclude",
"(",
"$",
"item",
")",
";",
"}",
"}",
"if",
"(",
"$",
"includes",
"instanceof",
"DataTransferObject",
")",
"{",
"$",
"this",
"->",
"addIncludes",
"(",
"$",
"includes",
"->",
"getIncludes",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"instanceof",
"Collection",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"model",
")",
"{",
"$",
"model",
"->",
"addIncludes",
"(",
"$",
"includes",
")",
";",
"}",
"}",
"}"
]
| Add items to include
@param mixed $includes
@return void | [
"Add",
"items",
"to",
"include"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L491-L517 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.offsetSet | public function offsetSet($offset, $value)
{
if (is_null($offset))
{
if( ! $this->isCollection)
{
throw new Exception('You need to specify a valid key for model.');
}
$this->data[] = $value;
}
else
{
if($this->isCollection)
{
$this->data[$offset] = $value;
return;
}
$this->data->{$offset} = $value;
}
} | php | public function offsetSet($offset, $value)
{
if (is_null($offset))
{
if( ! $this->isCollection)
{
throw new Exception('You need to specify a valid key for model.');
}
$this->data[] = $value;
}
else
{
if($this->isCollection)
{
$this->data[$offset] = $value;
return;
}
$this->data->{$offset} = $value;
}
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"offset",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCollection",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'You need to specify a valid key for model.'",
")",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"isCollection",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"offset",
"]",
"=",
"$",
"value",
";",
"return",
";",
"}",
"$",
"this",
"->",
"data",
"->",
"{",
"$",
"offset",
"}",
"=",
"$",
"value",
";",
"}",
"}"
]
| Set data at specific offset
@param string $offset
@param string $value
@return mixed | [
"Set",
"data",
"at",
"specific",
"offset"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L557-L578 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.offsetExists | public function offsetExists($offset) {
return ($this->isCollection)?
isset($this->data[$offset])
:isset($this->data->{$offset});
} | php | public function offsetExists($offset) {
return ($this->isCollection)?
isset($this->data[$offset])
:isset($this->data->{$offset});
} | [
"public",
"function",
"offsetExists",
"(",
"$",
"offset",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"isCollection",
")",
"?",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"offset",
"]",
")",
":",
"isset",
"(",
"$",
"this",
"->",
"data",
"->",
"{",
"$",
"offset",
"}",
")",
";",
"}"
]
| Check if provided offset exists
@param string $offset
@return boolean | [
"Check",
"if",
"provided",
"offset",
"exists"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L587-L591 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.offsetUnset | public function offsetUnset($offset) {
if($this->isCollection)
{
unset($this->data[$offset]);
}
else
{
unset($this->data->{$offset});
}
} | php | public function offsetUnset($offset) {
if($this->isCollection)
{
unset($this->data[$offset]);
}
else
{
unset($this->data->{$offset});
}
} | [
"public",
"function",
"offsetUnset",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCollection",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"offset",
"]",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"->",
"{",
"$",
"offset",
"}",
")",
";",
"}",
"}"
]
| Unset the provided offset
@param string $offset
@return boolean | [
"Unset",
"the",
"provided",
"offset"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L600-L609 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.toJson | public function toJson($options = 0, $includeMetaData = false, $nestedInclude = true, $callback = null)
{
$data = $this->toArray($includeMetaData, $nestedInclude, $callback);
return json_encode($data, $options);
} | php | public function toJson($options = 0, $includeMetaData = false, $nestedInclude = true, $callback = null)
{
$data = $this->toArray($includeMetaData, $nestedInclude, $callback);
return json_encode($data, $options);
} | [
"public",
"function",
"toJson",
"(",
"$",
"options",
"=",
"0",
",",
"$",
"includeMetaData",
"=",
"false",
",",
"$",
"nestedInclude",
"=",
"true",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"toArray",
"(",
"$",
"includeMetaData",
",",
"$",
"nestedInclude",
",",
"$",
"callback",
")",
";",
"return",
"json_encode",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"}"
]
| Get the instance as an json string.
@param int $optinos json options
@param boolean $includeMetaData
@return string | [
"Get",
"the",
"instance",
"as",
"an",
"json",
"string",
"."
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L677-L681 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.transformToArray | public function transformToArray($data, $nestedInclude = true, $extraIncludes = [], $callback = null)
{
if (is_object($data))
{
if( $nestedInclude && ! $this->resolved($data) )
{
$objectKey = $this->objectKey($data);
if(array_key_exists($objectKey, $extraIncludes))
{
$data = $extraIncludes[$objectKey];
}
else
{
$data = $this->getIncluded($data);
}
}
if($data instanceof DataTransferObject)
{
// $data->addIncludes($this->included);
$data = $data->transformToArray($data->getData(), $nestedInclude, $this->included + $extraIncludes);
}
elseif($data instanceof Carbon)
{
$data = $data->tz('UTC')->toIso8601String();
}
else
{
$data = get_object_vars($data);
}
}
if ( is_array($data) && ! empty($data) )
{
foreach ($data as $key => &$value)
{
$this->transformAttribute($data, $key, $value, $nestedInclude, $this->included + $extraIncludes, $callback);
}
}
if(is_callable($callback))
{
$data = call_user_func_array($callback, [[], 0, $data, $nestedInclude, $extraIncludes]);
}
return $data;
} | php | public function transformToArray($data, $nestedInclude = true, $extraIncludes = [], $callback = null)
{
if (is_object($data))
{
if( $nestedInclude && ! $this->resolved($data) )
{
$objectKey = $this->objectKey($data);
if(array_key_exists($objectKey, $extraIncludes))
{
$data = $extraIncludes[$objectKey];
}
else
{
$data = $this->getIncluded($data);
}
}
if($data instanceof DataTransferObject)
{
// $data->addIncludes($this->included);
$data = $data->transformToArray($data->getData(), $nestedInclude, $this->included + $extraIncludes);
}
elseif($data instanceof Carbon)
{
$data = $data->tz('UTC')->toIso8601String();
}
else
{
$data = get_object_vars($data);
}
}
if ( is_array($data) && ! empty($data) )
{
foreach ($data as $key => &$value)
{
$this->transformAttribute($data, $key, $value, $nestedInclude, $this->included + $extraIncludes, $callback);
}
}
if(is_callable($callback))
{
$data = call_user_func_array($callback, [[], 0, $data, $nestedInclude, $extraIncludes]);
}
return $data;
} | [
"public",
"function",
"transformToArray",
"(",
"$",
"data",
",",
"$",
"nestedInclude",
"=",
"true",
",",
"$",
"extraIncludes",
"=",
"[",
"]",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"$",
"nestedInclude",
"&&",
"!",
"$",
"this",
"->",
"resolved",
"(",
"$",
"data",
")",
")",
"{",
"$",
"objectKey",
"=",
"$",
"this",
"->",
"objectKey",
"(",
"$",
"data",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"objectKey",
",",
"$",
"extraIncludes",
")",
")",
"{",
"$",
"data",
"=",
"$",
"extraIncludes",
"[",
"$",
"objectKey",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getIncluded",
"(",
"$",
"data",
")",
";",
"}",
"}",
"if",
"(",
"$",
"data",
"instanceof",
"DataTransferObject",
")",
"{",
"// $data->addIncludes($this->included);",
"$",
"data",
"=",
"$",
"data",
"->",
"transformToArray",
"(",
"$",
"data",
"->",
"getData",
"(",
")",
",",
"$",
"nestedInclude",
",",
"$",
"this",
"->",
"included",
"+",
"$",
"extraIncludes",
")",
";",
"}",
"elseif",
"(",
"$",
"data",
"instanceof",
"Carbon",
")",
"{",
"$",
"data",
"=",
"$",
"data",
"->",
"tz",
"(",
"'UTC'",
")",
"->",
"toIso8601String",
"(",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"get_object_vars",
"(",
"$",
"data",
")",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
"&&",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"transformAttribute",
"(",
"$",
"data",
",",
"$",
"key",
",",
"$",
"value",
",",
"$",
"nestedInclude",
",",
"$",
"this",
"->",
"included",
"+",
"$",
"extraIncludes",
",",
"$",
"callback",
")",
";",
"}",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"data",
"=",
"call_user_func_array",
"(",
"$",
"callback",
",",
"[",
"[",
"]",
",",
"0",
",",
"$",
"data",
",",
"$",
"nestedInclude",
",",
"$",
"extraIncludes",
"]",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Convert Object to array deep
@param object $data
@return array | [
"Convert",
"Object",
"to",
"array",
"deep"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L708-L762 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.resolve | protected function resolve($obj)
{
if(Trunk::has($obj->id, $obj->type))
{
return $data = Trunk::get($obj->id, $obj->type);
}
return $obj;
} | php | protected function resolve($obj)
{
if(Trunk::has($obj->id, $obj->type))
{
return $data = Trunk::get($obj->id, $obj->type);
}
return $obj;
} | [
"protected",
"function",
"resolve",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"Trunk",
"::",
"has",
"(",
"$",
"obj",
"->",
"id",
",",
"$",
"obj",
"->",
"type",
")",
")",
"{",
"return",
"$",
"data",
"=",
"Trunk",
"::",
"get",
"(",
"$",
"obj",
"->",
"id",
",",
"$",
"obj",
"->",
"type",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
]
| Get resolved object form trunk if possible
@param object $obj
@return object | [
"Get",
"resolved",
"object",
"form",
"trunk",
"if",
"possible"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L831-L839 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.getIncluded | public function getIncluded($obj)
{
$includes = $this->getIncludes(true);
$objectKey = $this->objectKey($obj);
if(array_key_exists($objectKey, $includes))
{
return $includes[$objectKey];
}
return $obj;
} | php | public function getIncluded($obj)
{
$includes = $this->getIncludes(true);
$objectKey = $this->objectKey($obj);
if(array_key_exists($objectKey, $includes))
{
return $includes[$objectKey];
}
return $obj;
} | [
"public",
"function",
"getIncluded",
"(",
"$",
"obj",
")",
"{",
"$",
"includes",
"=",
"$",
"this",
"->",
"getIncludes",
"(",
"true",
")",
";",
"$",
"objectKey",
"=",
"$",
"this",
"->",
"objectKey",
"(",
"$",
"obj",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"objectKey",
",",
"$",
"includes",
")",
")",
"{",
"return",
"$",
"includes",
"[",
"$",
"objectKey",
"]",
";",
"}",
"return",
"$",
"obj",
";",
"}"
]
| Get resolved object from included
@param object $obj
@return object | [
"Get",
"resolved",
"object",
"from",
"included"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L848-L859 | train |
congraphcms/core | Repositories/DataTransferObject.php | DataTransferObject.objectKey | protected function objectKey($object)
{
return base64_encode(json_encode(['id' => $object->id, 'type' => $object->type, 'relations' => $this->relations]));
} | php | protected function objectKey($object)
{
return base64_encode(json_encode(['id' => $object->id, 'type' => $object->type, 'relations' => $this->relations]));
} | [
"protected",
"function",
"objectKey",
"(",
"$",
"object",
")",
"{",
"return",
"base64_encode",
"(",
"json_encode",
"(",
"[",
"'id'",
"=>",
"$",
"object",
"->",
"id",
",",
"'type'",
"=>",
"$",
"object",
"->",
"type",
",",
"'relations'",
"=>",
"$",
"this",
"->",
"relations",
"]",
")",
")",
";",
"}"
]
| Make base64 key from object
@param object $object
@return string | [
"Make",
"base64",
"key",
"from",
"object"
]
| d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Repositories/DataTransferObject.php#L873-L876 | train |
RSQueue/RSQueue | src/RSQueue/Resolver/QueueAliasResolver.php | QueueAliasResolver.getQueues | public function getQueues(array $queueAlias): array
{
$queues = [];
foreach ($queueAlias as $alias) {
$queues[] = $this->getQueue($alias);
}
return $queues;
} | php | public function getQueues(array $queueAlias): array
{
$queues = [];
foreach ($queueAlias as $alias) {
$queues[] = $this->getQueue($alias);
}
return $queues;
} | [
"public",
"function",
"getQueues",
"(",
"array",
"$",
"queueAlias",
")",
":",
"array",
"{",
"$",
"queues",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"queueAlias",
"as",
"$",
"alias",
")",
"{",
"$",
"queues",
"[",
"]",
"=",
"$",
"this",
"->",
"getQueue",
"(",
"$",
"alias",
")",
";",
"}",
"return",
"$",
"queues",
";",
"}"
]
| Given an array of queueAliases, return a valid queueNames array.
@param array $queueAlias Queue alias array
@return array valid queueName array | [
"Given",
"an",
"array",
"of",
"queueAliases",
"return",
"a",
"valid",
"queueNames",
"array",
"."
]
| 1a8d72a2b025ed65684644febf9493d4f6ac9333 | https://github.com/RSQueue/RSQueue/blob/1a8d72a2b025ed65684644febf9493d4f6ac9333/src/RSQueue/Resolver/QueueAliasResolver.php#L53-L61 | train |
RSQueue/RSQueue | src/RSQueue/Resolver/QueueAliasResolver.php | QueueAliasResolver.getQueueAliasByQueueName | public function getQueueAliasByQueueName(string $queueName): string
{
return is_array($this->queues)
? ((array_flip($this->queues)[$queueName]) ?? $queueName)
: $queueName;
} | php | public function getQueueAliasByQueueName(string $queueName): string
{
return is_array($this->queues)
? ((array_flip($this->queues)[$queueName]) ?? $queueName)
: $queueName;
} | [
"public",
"function",
"getQueueAliasByQueueName",
"(",
"string",
"$",
"queueName",
")",
":",
"string",
"{",
"return",
"is_array",
"(",
"$",
"this",
"->",
"queues",
")",
"?",
"(",
"(",
"array_flip",
"(",
"$",
"this",
"->",
"queues",
")",
"[",
"$",
"queueName",
"]",
")",
"??",
"$",
"queueName",
")",
":",
"$",
"queueName",
";",
"}"
]
| Return queue alias by queue name.
@param string $queueName
@return string | [
"Return",
"queue",
"alias",
"by",
"queue",
"name",
"."
]
| 1a8d72a2b025ed65684644febf9493d4f6ac9333 | https://github.com/RSQueue/RSQueue/blob/1a8d72a2b025ed65684644febf9493d4f6ac9333/src/RSQueue/Resolver/QueueAliasResolver.php#L82-L87 | train |
mpf-soft/admin-widgets | form/Form.php | Form.getButton | public function getButton($details)
{
if (is_string($details)) {
return HtmlHelper::get()->noContentElement('input', array(
'type' => 'submit',
'name' => $details,
'value' => $this->translate(ucwords(str_replace('_', ' ', $details)))
));
}
if (isset($details['visible']) && $details['visible'] == false) {
return ''; //return nothing if hidden;
}
$htmlOptions = isset($details['htmlOptions']) ? $details['htmlOptions'] : array();
$htmlOptions['type'] = isset($details['type']) ? $details['type'] : 'submit';
$htmlOptions['name'] = $details['name'];
$htmlOptions['value'] = $this->translate($details['label']);
return HtmlHelper::get()->noContentElement('input', $htmlOptions);
} | php | public function getButton($details)
{
if (is_string($details)) {
return HtmlHelper::get()->noContentElement('input', array(
'type' => 'submit',
'name' => $details,
'value' => $this->translate(ucwords(str_replace('_', ' ', $details)))
));
}
if (isset($details['visible']) && $details['visible'] == false) {
return ''; //return nothing if hidden;
}
$htmlOptions = isset($details['htmlOptions']) ? $details['htmlOptions'] : array();
$htmlOptions['type'] = isset($details['type']) ? $details['type'] : 'submit';
$htmlOptions['name'] = $details['name'];
$htmlOptions['value'] = $this->translate($details['label']);
return HtmlHelper::get()->noContentElement('input', $htmlOptions);
} | [
"public",
"function",
"getButton",
"(",
"$",
"details",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"details",
")",
")",
"{",
"return",
"HtmlHelper",
"::",
"get",
"(",
")",
"->",
"noContentElement",
"(",
"'input'",
",",
"array",
"(",
"'type'",
"=>",
"'submit'",
",",
"'name'",
"=>",
"$",
"details",
",",
"'value'",
"=>",
"$",
"this",
"->",
"translate",
"(",
"ucwords",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"details",
")",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"details",
"[",
"'visible'",
"]",
")",
"&&",
"$",
"details",
"[",
"'visible'",
"]",
"==",
"false",
")",
"{",
"return",
"''",
";",
"//return nothing if hidden;",
"}",
"$",
"htmlOptions",
"=",
"isset",
"(",
"$",
"details",
"[",
"'htmlOptions'",
"]",
")",
"?",
"$",
"details",
"[",
"'htmlOptions'",
"]",
":",
"array",
"(",
")",
";",
"$",
"htmlOptions",
"[",
"'type'",
"]",
"=",
"isset",
"(",
"$",
"details",
"[",
"'type'",
"]",
")",
"?",
"$",
"details",
"[",
"'type'",
"]",
":",
"'submit'",
";",
"$",
"htmlOptions",
"[",
"'name'",
"]",
"=",
"$",
"details",
"[",
"'name'",
"]",
";",
"$",
"htmlOptions",
"[",
"'value'",
"]",
"=",
"$",
"this",
"->",
"translate",
"(",
"$",
"details",
"[",
"'label'",
"]",
")",
";",
"return",
"HtmlHelper",
"::",
"get",
"(",
")",
"->",
"noContentElement",
"(",
"'input'",
",",
"$",
"htmlOptions",
")",
";",
"}"
]
| Return html code for a button.
@param string|array $details
@return string | [
"Return",
"html",
"code",
"for",
"a",
"button",
"."
]
| 92597f9a09d086664268d6b7e0111d5a5586d8c7 | https://github.com/mpf-soft/admin-widgets/blob/92597f9a09d086664268d6b7e0111d5a5586d8c7/form/Form.php#L250-L267 | train |
cmsgears/module-sns-connect | common/components/Factory.php | Factory.registerSystemServices | public function registerSystemServices() {
$factory = Yii::$app->factory->getContainer();
$factory->set( 'cmsgears\social\connect\common\services\interfaces\system\IFacebookService', 'cmsgears\social\connect\common\services\system\FacebookService' );
$factory->set( 'cmsgears\social\connect\common\services\interfaces\system\IGoogleService', 'cmsgears\social\connect\common\services\system\GoogleService' );
$factory->set( 'cmsgears\social\connect\common\services\interfaces\system\ITwitterService', 'cmsgears\social\connect\common\services\system\TwitterService' );
$factory->set( 'cmsgears\social\connect\common\services\interfaces\system\ILinkedinService', 'cmsgears\social\connect\common\services\system\LinkedinService' );
} | php | public function registerSystemServices() {
$factory = Yii::$app->factory->getContainer();
$factory->set( 'cmsgears\social\connect\common\services\interfaces\system\IFacebookService', 'cmsgears\social\connect\common\services\system\FacebookService' );
$factory->set( 'cmsgears\social\connect\common\services\interfaces\system\IGoogleService', 'cmsgears\social\connect\common\services\system\GoogleService' );
$factory->set( 'cmsgears\social\connect\common\services\interfaces\system\ITwitterService', 'cmsgears\social\connect\common\services\system\TwitterService' );
$factory->set( 'cmsgears\social\connect\common\services\interfaces\system\ILinkedinService', 'cmsgears\social\connect\common\services\system\LinkedinService' );
} | [
"public",
"function",
"registerSystemServices",
"(",
")",
"{",
"$",
"factory",
"=",
"Yii",
"::",
"$",
"app",
"->",
"factory",
"->",
"getContainer",
"(",
")",
";",
"$",
"factory",
"->",
"set",
"(",
"'cmsgears\\social\\connect\\common\\services\\interfaces\\system\\IFacebookService'",
",",
"'cmsgears\\social\\connect\\common\\services\\system\\FacebookService'",
")",
";",
"$",
"factory",
"->",
"set",
"(",
"'cmsgears\\social\\connect\\common\\services\\interfaces\\system\\IGoogleService'",
",",
"'cmsgears\\social\\connect\\common\\services\\system\\GoogleService'",
")",
";",
"$",
"factory",
"->",
"set",
"(",
"'cmsgears\\social\\connect\\common\\services\\interfaces\\system\\ITwitterService'",
",",
"'cmsgears\\social\\connect\\common\\services\\system\\TwitterService'",
")",
";",
"$",
"factory",
"->",
"set",
"(",
"'cmsgears\\social\\connect\\common\\services\\interfaces\\system\\ILinkedinService'",
",",
"'cmsgears\\social\\connect\\common\\services\\system\\LinkedinService'",
")",
";",
"}"
]
| Registers system services. | [
"Registers",
"system",
"services",
"."
]
| 753ee4157d41c81a701689624f4c44760a6cada3 | https://github.com/cmsgears/module-sns-connect/blob/753ee4157d41c81a701689624f4c44760a6cada3/common/components/Factory.php#L69-L77 | train |
cmsgears/module-sns-connect | common/components/Factory.php | Factory.registerSystemAliases | public function registerSystemAliases() {
$factory = Yii::$app->factory->getContainer();
$factory->set( 'facebookService', 'cmsgears\social\connect\common\services\system\FacebookService' );
$factory->set( 'googleService', 'cmsgears\social\connect\common\services\system\GoogleService' );
$factory->set( 'twitterService', 'cmsgears\social\connect\common\services\system\TwitterService' );
$factory->set( 'linkedinService', 'cmsgears\social\connect\common\services\system\LinkedinService' );
} | php | public function registerSystemAliases() {
$factory = Yii::$app->factory->getContainer();
$factory->set( 'facebookService', 'cmsgears\social\connect\common\services\system\FacebookService' );
$factory->set( 'googleService', 'cmsgears\social\connect\common\services\system\GoogleService' );
$factory->set( 'twitterService', 'cmsgears\social\connect\common\services\system\TwitterService' );
$factory->set( 'linkedinService', 'cmsgears\social\connect\common\services\system\LinkedinService' );
} | [
"public",
"function",
"registerSystemAliases",
"(",
")",
"{",
"$",
"factory",
"=",
"Yii",
"::",
"$",
"app",
"->",
"factory",
"->",
"getContainer",
"(",
")",
";",
"$",
"factory",
"->",
"set",
"(",
"'facebookService'",
",",
"'cmsgears\\social\\connect\\common\\services\\system\\FacebookService'",
")",
";",
"$",
"factory",
"->",
"set",
"(",
"'googleService'",
",",
"'cmsgears\\social\\connect\\common\\services\\system\\GoogleService'",
")",
";",
"$",
"factory",
"->",
"set",
"(",
"'twitterService'",
",",
"'cmsgears\\social\\connect\\common\\services\\system\\TwitterService'",
")",
";",
"$",
"factory",
"->",
"set",
"(",
"'linkedinService'",
",",
"'cmsgears\\social\\connect\\common\\services\\system\\LinkedinService'",
")",
";",
"}"
]
| Registers system aliases. | [
"Registers",
"system",
"aliases",
"."
]
| 753ee4157d41c81a701689624f4c44760a6cada3 | https://github.com/cmsgears/module-sns-connect/blob/753ee4157d41c81a701689624f4c44760a6cada3/common/components/Factory.php#L95-L103 | train |
zapheus/zapheus | src/Http/Server/ResolverHandler.php | ResolverHandler.response | protected function response($result)
{
$response = $this->container->get(Application::RESPONSE);
if ($result instanceof ResponseInterface)
{
return $result;
}
$response->stream()->write($result);
return $response;
} | php | protected function response($result)
{
$response = $this->container->get(Application::RESPONSE);
if ($result instanceof ResponseInterface)
{
return $result;
}
$response->stream()->write($result);
return $response;
} | [
"protected",
"function",
"response",
"(",
"$",
"result",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"Application",
"::",
"RESPONSE",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"ResponseInterface",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"response",
"->",
"stream",
"(",
")",
"->",
"write",
"(",
"$",
"result",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Converts the given result into a ResponseInterface.
@param mixed $result
@return \Zapheus\Http\Message\ResponseInterface | [
"Converts",
"the",
"given",
"result",
"into",
"a",
"ResponseInterface",
"."
]
| 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Http/Server/ResolverHandler.php#L71-L83 | train |
chalasr/RCHCapistranoBundle | Service/Capitalizer.php | Capitalizer.camelize | public function camelize($base)
{
$callback = create_function('$c', 'return strtoupper($c[1]);');
if (!is_array($base)) {
return preg_replace_callback('/_([a-z])/', $callback, $base);
}
foreach ($base as $key => $val) {
unset($base[$key]);
$newKey = preg_replace_callback('/_([a-z])/', $callback, $key);
$base[$newKey] = $val;
}
return $base;
} | php | public function camelize($base)
{
$callback = create_function('$c', 'return strtoupper($c[1]);');
if (!is_array($base)) {
return preg_replace_callback('/_([a-z])/', $callback, $base);
}
foreach ($base as $key => $val) {
unset($base[$key]);
$newKey = preg_replace_callback('/_([a-z])/', $callback, $key);
$base[$newKey] = $val;
}
return $base;
} | [
"public",
"function",
"camelize",
"(",
"$",
"base",
")",
"{",
"$",
"callback",
"=",
"create_function",
"(",
"'$c'",
",",
"'return strtoupper($c[1]);'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"base",
")",
")",
"{",
"return",
"preg_replace_callback",
"(",
"'/_([a-z])/'",
",",
"$",
"callback",
",",
"$",
"base",
")",
";",
"}",
"foreach",
"(",
"$",
"base",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"unset",
"(",
"$",
"base",
"[",
"$",
"key",
"]",
")",
";",
"$",
"newKey",
"=",
"preg_replace_callback",
"(",
"'/_([a-z])/'",
",",
"$",
"callback",
",",
"$",
"key",
")",
";",
"$",
"base",
"[",
"$",
"newKey",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"$",
"base",
";",
"}"
]
| Convert strings from under_scores to CamelCase.
@param mixed $base
@return mixed | [
"Convert",
"strings",
"from",
"under_scores",
"to",
"CamelCase",
"."
]
| c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Service/Capitalizer.php#L28-L43 | train |
chalasr/RCHCapistranoBundle | Service/Capitalizer.php | Capitalizer.uncamelize | public function uncamelize($base)
{
$callback = create_function('$c', 'return "_" . strtolower($c[1]);');
if (!is_array($base)) {
$base[0] = strtolower($base[0]);
return preg_replace_callback('/([A-Z])/', $callback, $base);
}
foreach ($base as $key => $val) {
unset($base[$key]);
$newKey = preg_replace_callback('/([A-Z])/', $callback, $key);
$base[$newKey] = $val;
}
return $base;
} | php | public function uncamelize($base)
{
$callback = create_function('$c', 'return "_" . strtolower($c[1]);');
if (!is_array($base)) {
$base[0] = strtolower($base[0]);
return preg_replace_callback('/([A-Z])/', $callback, $base);
}
foreach ($base as $key => $val) {
unset($base[$key]);
$newKey = preg_replace_callback('/([A-Z])/', $callback, $key);
$base[$newKey] = $val;
}
return $base;
} | [
"public",
"function",
"uncamelize",
"(",
"$",
"base",
")",
"{",
"$",
"callback",
"=",
"create_function",
"(",
"'$c'",
",",
"'return \"_\" . strtolower($c[1]);'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"base",
")",
")",
"{",
"$",
"base",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"base",
"[",
"0",
"]",
")",
";",
"return",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"$",
"callback",
",",
"$",
"base",
")",
";",
"}",
"foreach",
"(",
"$",
"base",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"unset",
"(",
"$",
"base",
"[",
"$",
"key",
"]",
")",
";",
"$",
"newKey",
"=",
"preg_replace_callback",
"(",
"'/([A-Z])/'",
",",
"$",
"callback",
",",
"$",
"key",
")",
";",
"$",
"base",
"[",
"$",
"newKey",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"$",
"base",
";",
"}"
]
| Converts strings from camelCase to under_score.
@param mixed $base
@return mixed | [
"Converts",
"strings",
"from",
"camelCase",
"to",
"under_score",
"."
]
| c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Service/Capitalizer.php#L52-L69 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.addIn | public function addIn($field, $values, $whereConcat = 'AND')
{
if (!is_array($values)) {
return $this;
}
$field = (0 < count($this->wheres) ? ' ' . $whereConcat . ' ' . $field : $field);
//~ Bind values (more safety)
$index = 1;
$fields = array();
foreach ($values as $value) {
$name = ':value_' . $index;
$fields[] = $name;
$this->binds[$name] = (string) $value;
$index++;
}
$this->wheres[] = $field . ' IN (' . implode(',', $fields) . ')';
return $this;
} | php | public function addIn($field, $values, $whereConcat = 'AND')
{
if (!is_array($values)) {
return $this;
}
$field = (0 < count($this->wheres) ? ' ' . $whereConcat . ' ' . $field : $field);
//~ Bind values (more safety)
$index = 1;
$fields = array();
foreach ($values as $value) {
$name = ':value_' . $index;
$fields[] = $name;
$this->binds[$name] = (string) $value;
$index++;
}
$this->wheres[] = $field . ' IN (' . implode(',', $fields) . ')';
return $this;
} | [
"public",
"function",
"addIn",
"(",
"$",
"field",
",",
"$",
"values",
",",
"$",
"whereConcat",
"=",
"'AND'",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"field",
"=",
"(",
"0",
"<",
"count",
"(",
"$",
"this",
"->",
"wheres",
")",
"?",
"' '",
".",
"$",
"whereConcat",
".",
"' '",
".",
"$",
"field",
":",
"$",
"field",
")",
";",
"//~ Bind values (more safety)",
"$",
"index",
"=",
"1",
";",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"name",
"=",
"':value_'",
".",
"$",
"index",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"binds",
"[",
"$",
"name",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"$",
"index",
"++",
";",
"}",
"$",
"this",
"->",
"wheres",
"[",
"]",
"=",
"$",
"field",
".",
"' IN ('",
".",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
".",
"')'",
";",
"return",
"$",
"this",
";",
"}"
]
| Add In list item.
@param string $field Field name
@param array $values List of values (integer)
@param string $whereConcat Concat type with other where elements
@return self | [
"Add",
"In",
"list",
"item",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L192-L216 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.addWhere | public function addWhere($field, $value, $sign = '=', $whereConcat = 'AND')
{
$fieldWhere = (0 < count($this->wheres) ? ' ' . $whereConcat . ' ' . $field : $field);
$fieldBind = ':' . strtolower($field);
if (isset($this->binds[$fieldBind])) {
$counter = 0;
while ($counter < 20) {
if (isset($this->binds[$fieldBind . '__' . $counter++])) {
continue;
}
$fieldBind .= '__' . $counter;
break;
};
}
$this->wheres[] = $fieldWhere . ' ' . $sign . ' ' . $fieldBind;
$this->binds[$fieldBind] = $value;
return $this;
} | php | public function addWhere($field, $value, $sign = '=', $whereConcat = 'AND')
{
$fieldWhere = (0 < count($this->wheres) ? ' ' . $whereConcat . ' ' . $field : $field);
$fieldBind = ':' . strtolower($field);
if (isset($this->binds[$fieldBind])) {
$counter = 0;
while ($counter < 20) {
if (isset($this->binds[$fieldBind . '__' . $counter++])) {
continue;
}
$fieldBind .= '__' . $counter;
break;
};
}
$this->wheres[] = $fieldWhere . ' ' . $sign . ' ' . $fieldBind;
$this->binds[$fieldBind] = $value;
return $this;
} | [
"public",
"function",
"addWhere",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"sign",
"=",
"'='",
",",
"$",
"whereConcat",
"=",
"'AND'",
")",
"{",
"$",
"fieldWhere",
"=",
"(",
"0",
"<",
"count",
"(",
"$",
"this",
"->",
"wheres",
")",
"?",
"' '",
".",
"$",
"whereConcat",
".",
"' '",
".",
"$",
"field",
":",
"$",
"field",
")",
";",
"$",
"fieldBind",
"=",
"':'",
".",
"strtolower",
"(",
"$",
"field",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"binds",
"[",
"$",
"fieldBind",
"]",
")",
")",
"{",
"$",
"counter",
"=",
"0",
";",
"while",
"(",
"$",
"counter",
"<",
"20",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"binds",
"[",
"$",
"fieldBind",
".",
"'__'",
".",
"$",
"counter",
"++",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"fieldBind",
".=",
"'__'",
".",
"$",
"counter",
";",
"break",
";",
"}",
";",
"}",
"$",
"this",
"->",
"wheres",
"[",
"]",
"=",
"$",
"fieldWhere",
".",
"' '",
".",
"$",
"sign",
".",
"' '",
".",
"$",
"fieldBind",
";",
"$",
"this",
"->",
"binds",
"[",
"$",
"fieldBind",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
]
| Add where clause.
@param string $field
@param string|integer $value
@param string $sign
@param string $whereConcat
@return self | [
"Add",
"where",
"clause",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L241-L263 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.clear | public function clear()
{
$this->wheres = array();
$this->sets = array();
$this->havings = array();
$this->orders = array();
$this->binds = array();
$this->limit = null;
$this->offset = null;
return $this;
} | php | public function clear()
{
$this->wheres = array();
$this->sets = array();
$this->havings = array();
$this->orders = array();
$this->binds = array();
$this->limit = null;
$this->offset = null;
return $this;
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"this",
"->",
"wheres",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"sets",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"havings",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"orders",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"binds",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"limit",
"=",
"null",
";",
"$",
"this",
"->",
"offset",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
]
| Clear query params
@return self | [
"Clear",
"query",
"params"
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L298-L309 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.getQueryFields | public function getQueryFields($usePrefix = false, $prefix = '')
{
$fields = $this->fields;
if ($usePrefix) {
$prefix = (empty($prefix) ? $this->getTable() : $prefix);
$fields = array();
foreach ($this->fields as $field) {
$fields[] = $prefix . '.' . $field;
}
}
return implode(', ', $fields);
} | php | public function getQueryFields($usePrefix = false, $prefix = '')
{
$fields = $this->fields;
if ($usePrefix) {
$prefix = (empty($prefix) ? $this->getTable() : $prefix);
$fields = array();
foreach ($this->fields as $field) {
$fields[] = $prefix . '.' . $field;
}
}
return implode(', ', $fields);
} | [
"public",
"function",
"getQueryFields",
"(",
"$",
"usePrefix",
"=",
"false",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"fields",
";",
"if",
"(",
"$",
"usePrefix",
")",
"{",
"$",
"prefix",
"=",
"(",
"empty",
"(",
"$",
"prefix",
")",
"?",
"$",
"this",
"->",
"getTable",
"(",
")",
":",
"$",
"prefix",
")",
";",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"$",
"prefix",
".",
"'.'",
".",
"$",
"field",
";",
"}",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
";",
"}"
]
| Get fields to select
@param bool $usePrefix
@param string $prefix
@return string | [
"Get",
"fields",
"to",
"select"
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L328-L341 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.getQueryLimit | public function getQueryLimit()
{
if ($this->limit !== null && $this->offset !== null) {
return 'LIMIT ' . $this->offset . ', ' . $this->limit;
} else {
if (null !== $this->limit) {
return 'LIMIT ' . $this->limit;
} else {
return '';
}
}
} | php | public function getQueryLimit()
{
if ($this->limit !== null && $this->offset !== null) {
return 'LIMIT ' . $this->offset . ', ' . $this->limit;
} else {
if (null !== $this->limit) {
return 'LIMIT ' . $this->limit;
} else {
return '';
}
}
} | [
"public",
"function",
"getQueryLimit",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"limit",
"!==",
"null",
"&&",
"$",
"this",
"->",
"offset",
"!==",
"null",
")",
"{",
"return",
"'LIMIT '",
".",
"$",
"this",
"->",
"offset",
".",
"', '",
".",
"$",
"this",
"->",
"limit",
";",
"}",
"else",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"limit",
")",
"{",
"return",
"'LIMIT '",
".",
"$",
"this",
"->",
"limit",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}",
"}"
]
| Get limit clause.
@return string | [
"Get",
"limit",
"clause",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L417-L428 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.count | public function count($field = '*')
{
if ($field !== '*' && !in_array($field, $this->getFields())) {
throw new \DomainException(__METHOD__ . '|Field is not allowed ! (field: ' . $field . ')');
}
$query = 'SELECT COUNT(' . $field . ') AS NB_RESULTS FROM ' . $this->table . ' ' . $this->getQueryWhere();
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
$this->clear();
return (int) $statement->fetchColumn(0);
} | php | public function count($field = '*')
{
if ($field !== '*' && !in_array($field, $this->getFields())) {
throw new \DomainException(__METHOD__ . '|Field is not allowed ! (field: ' . $field . ')');
}
$query = 'SELECT COUNT(' . $field . ') AS NB_RESULTS FROM ' . $this->table . ' ' . $this->getQueryWhere();
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
$this->clear();
return (int) $statement->fetchColumn(0);
} | [
"public",
"function",
"count",
"(",
"$",
"field",
"=",
"'*'",
")",
"{",
"if",
"(",
"$",
"field",
"!==",
"'*'",
"&&",
"!",
"in_array",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"getFields",
"(",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"__METHOD__",
".",
"'|Field is not allowed ! (field: '",
".",
"$",
"field",
".",
"')'",
")",
";",
"}",
"$",
"query",
"=",
"'SELECT COUNT('",
".",
"$",
"field",
".",
"') AS NB_RESULTS FROM '",
".",
"$",
"this",
"->",
"table",
".",
"' '",
".",
"$",
"this",
"->",
"getQueryWhere",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"$",
"this",
"->",
"binds",
")",
";",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"return",
"(",
"int",
")",
"$",
"statement",
"->",
"fetchColumn",
"(",
"0",
")",
";",
"}"
]
| Count number of results for query.
@param string $field
@return integer
@throws \DomainException | [
"Count",
"number",
"of",
"results",
"for",
"query",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L466-L480 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.rowExists | public function rowExists($field, $value)
{
$this->addWhere($field, $value);
try {
$this->selectOne();
return true;
} catch (ExceptionNoData $exception) {
return false;
}
} | php | public function rowExists($field, $value)
{
$this->addWhere($field, $value);
try {
$this->selectOne();
return true;
} catch (ExceptionNoData $exception) {
return false;
}
} | [
"public",
"function",
"rowExists",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"addWhere",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"try",
"{",
"$",
"this",
"->",
"selectOne",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"ExceptionNoData",
"$",
"exception",
")",
"{",
"return",
"false",
";",
"}",
"}"
]
| Check if value row exists in database..
@param string $field
@param mixed $value Value
@return bool | [
"Check",
"if",
"value",
"row",
"exists",
"in",
"database",
".."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L489-L500 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.query | public function query($query)
{
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
$this->clear();
$collection = array();
while (false !== ($row = $statement->fetchObject())) {
$collection[] = $this->newDataInstance($row, true);
}
return $collection;
} | php | public function query($query)
{
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
$this->clear();
$collection = array();
while (false !== ($row = $statement->fetchObject())) {
$collection[] = $this->newDataInstance($row, true);
}
return $collection;
} | [
"public",
"function",
"query",
"(",
"$",
"query",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"$",
"this",
"->",
"binds",
")",
";",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"collection",
"=",
"array",
"(",
")",
";",
"while",
"(",
"false",
"!==",
"(",
"$",
"row",
"=",
"$",
"statement",
"->",
"fetchObject",
"(",
")",
")",
")",
"{",
"$",
"collection",
"[",
"]",
"=",
"$",
"this",
"->",
"newDataInstance",
"(",
"$",
"row",
",",
"true",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
]
| Fetch rows for specified query.
@param string $query
@return array Array of model_base object for query. | [
"Fetch",
"rows",
"for",
"specified",
"query",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L508-L522 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.delete | public function delete(DataAbstract $data)
{
foreach ($this->primaryKeys as $key) {
$this->addWhere($key, $this->getDataValue($data, $key));
}
$where = $this->getQueryWhere();
if (empty($where)) {
throw new \LogicException(__METHOD__ . '| Where restriction is empty for current DELETE query !');
}
$query = 'DELETE FROM ' . $this->getTable() . ' ' . $this->getQueryWhere();
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
//~ Reset some data
$data->setExists(false);
$data->resetUpdated();
//~ Clear
$this->clear();
$this->deleteCache($data);
return $this;
} | php | public function delete(DataAbstract $data)
{
foreach ($this->primaryKeys as $key) {
$this->addWhere($key, $this->getDataValue($data, $key));
}
$where = $this->getQueryWhere();
if (empty($where)) {
throw new \LogicException(__METHOD__ . '| Where restriction is empty for current DELETE query !');
}
$query = 'DELETE FROM ' . $this->getTable() . ' ' . $this->getQueryWhere();
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
//~ Reset some data
$data->setExists(false);
$data->resetUpdated();
//~ Clear
$this->clear();
$this->deleteCache($data);
return $this;
} | [
"public",
"function",
"delete",
"(",
"DataAbstract",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"primaryKeys",
"as",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"addWhere",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"getDataValue",
"(",
"$",
"data",
",",
"$",
"key",
")",
")",
";",
"}",
"$",
"where",
"=",
"$",
"this",
"->",
"getQueryWhere",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"where",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"__METHOD__",
".",
"'| Where restriction is empty for current DELETE query !'",
")",
";",
"}",
"$",
"query",
"=",
"'DELETE FROM '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getQueryWhere",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"$",
"this",
"->",
"binds",
")",
";",
"//~ Reset some data",
"$",
"data",
"->",
"setExists",
"(",
"false",
")",
";",
"$",
"data",
"->",
"resetUpdated",
"(",
")",
";",
"//~ Clear",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"deleteCache",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Delete data from database.
@param DataAbstract $data
@return self
@throws \LogicException | [
"Delete",
"data",
"from",
"database",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L553-L578 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.persist | public function persist(DataAbstract $data)
{
if ($data->exists()) {
return $this->update($data);
} else {
return $this->insert($data);
}
} | php | public function persist(DataAbstract $data)
{
if ($data->exists()) {
return $this->update($data);
} else {
return $this->insert($data);
}
} | [
"public",
"function",
"persist",
"(",
"DataAbstract",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"->",
"exists",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"update",
"(",
"$",
"data",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"insert",
"(",
"$",
"data",
")",
";",
"}",
"}"
]
| Persist data in database.
@param DataAbstract $data
@return bool | [
"Persist",
"data",
"in",
"database",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L586-L593 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.update | public function update(DataAbstract $data)
{
if (!$data->isUpdated()) {
return false;
}
//~ Reset binded fields
$this->binds = array();
foreach ($this->primaryKeys as $key) {
$this->addWhere($key, $this->getDataValue($data, $key));
}
$set = $this->getQueryFieldsSet($data);
if (empty($set)) {
return false;
}
$where = $this->getQueryWhere();
if (empty($where)) {
throw new \LogicException(__METHOD__ . '|Where clause is empty!');
}
$query = 'UPDATE ' . $this->getTable() . ' ' . $set . ' ' . $where;
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
//~ Reset some data
$data->resetUpdated();
//~ Clear
$this->clear();
$this->deleteCache($data);
return true;
} | php | public function update(DataAbstract $data)
{
if (!$data->isUpdated()) {
return false;
}
//~ Reset binded fields
$this->binds = array();
foreach ($this->primaryKeys as $key) {
$this->addWhere($key, $this->getDataValue($data, $key));
}
$set = $this->getQueryFieldsSet($data);
if (empty($set)) {
return false;
}
$where = $this->getQueryWhere();
if (empty($where)) {
throw new \LogicException(__METHOD__ . '|Where clause is empty!');
}
$query = 'UPDATE ' . $this->getTable() . ' ' . $set . ' ' . $where;
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
//~ Reset some data
$data->resetUpdated();
//~ Clear
$this->clear();
$this->deleteCache($data);
return true;
} | [
"public",
"function",
"update",
"(",
"DataAbstract",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"data",
"->",
"isUpdated",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"//~ Reset binded fields",
"$",
"this",
"->",
"binds",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"primaryKeys",
"as",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"addWhere",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"getDataValue",
"(",
"$",
"data",
",",
"$",
"key",
")",
")",
";",
"}",
"$",
"set",
"=",
"$",
"this",
"->",
"getQueryFieldsSet",
"(",
"$",
"data",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"set",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"where",
"=",
"$",
"this",
"->",
"getQueryWhere",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"where",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"__METHOD__",
".",
"'|Where clause is empty!'",
")",
";",
"}",
"$",
"query",
"=",
"'UPDATE '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"' '",
".",
"$",
"set",
".",
"' '",
".",
"$",
"where",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"$",
"this",
"->",
"binds",
")",
";",
"//~ Reset some data",
"$",
"data",
"->",
"resetUpdated",
"(",
")",
";",
"//~ Clear",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"deleteCache",
"(",
"$",
"data",
")",
";",
"return",
"true",
";",
"}"
]
| Update data into database
@param $data
@return bool
@throws \LogicException | [
"Update",
"data",
"into",
"database"
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L661-L696 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.select | public function select()
{
$query = 'SELECT ' . $this->getQueryFields() . ' FROM ' . $this->getTable() . ' ' . $this->getQueryWhere() . ' ' . $this->getQueryOrderBy() . ' ' . $this->getQueryLimit();
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
$this->clear();
$collection = array();
while (false !== ($row = $statement->fetchObject())) {
$collection[] = $this->newDataInstance($row, true);
}
return $collection;
} | php | public function select()
{
$query = 'SELECT ' . $this->getQueryFields() . ' FROM ' . $this->getTable() . ' ' . $this->getQueryWhere() . ' ' . $this->getQueryOrderBy() . ' ' . $this->getQueryLimit();
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
$this->clear();
$collection = array();
while (false !== ($row = $statement->fetchObject())) {
$collection[] = $this->newDataInstance($row, true);
}
return $collection;
} | [
"public",
"function",
"select",
"(",
")",
"{",
"$",
"query",
"=",
"'SELECT '",
".",
"$",
"this",
"->",
"getQueryFields",
"(",
")",
".",
"' FROM '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getQueryWhere",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getQueryOrderBy",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getQueryLimit",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"$",
"this",
"->",
"binds",
")",
";",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"collection",
"=",
"array",
"(",
")",
";",
"while",
"(",
"false",
"!==",
"(",
"$",
"row",
"=",
"$",
"statement",
"->",
"fetchObject",
"(",
")",
")",
")",
"{",
"$",
"collection",
"[",
"]",
"=",
"$",
"this",
"->",
"newDataInstance",
"(",
"$",
"row",
",",
"true",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
]
| Select all rows corresponding of where clause.
@return DataAbstract[] List of row. | [
"Select",
"all",
"rows",
"corresponding",
"of",
"where",
"clause",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L759-L774 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.selectOne | public function selectOne()
{
$this->setLimit(1);
$query = 'SELECT ' . $this->getQueryFields() . ' FROM ' . $this->getTable() . ' ' . $this->getQueryWhere() . ' ' . $this->getQueryOrderBy() . ' ' . $this->getQueryLimit();
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
$this->clear();
if ($statement->rowCount() === 0) {
throw new ExceptionNoData('No data for current query! (query: ' . $query . ', bind: ' . json_encode($this->binds) . ')', 10001);
}
//~ Create new object, set data & save it in cache
return $this->newDataInstance($statement->fetchObject(), true);
} | php | public function selectOne()
{
$this->setLimit(1);
$query = 'SELECT ' . $this->getQueryFields() . ' FROM ' . $this->getTable() . ' ' . $this->getQueryWhere() . ' ' . $this->getQueryOrderBy() . ' ' . $this->getQueryLimit();
$statement = $this->db->prepare($query);
$statement->execute($this->binds);
$this->clear();
if ($statement->rowCount() === 0) {
throw new ExceptionNoData('No data for current query! (query: ' . $query . ', bind: ' . json_encode($this->binds) . ')', 10001);
}
//~ Create new object, set data & save it in cache
return $this->newDataInstance($statement->fetchObject(), true);
} | [
"public",
"function",
"selectOne",
"(",
")",
"{",
"$",
"this",
"->",
"setLimit",
"(",
"1",
")",
";",
"$",
"query",
"=",
"'SELECT '",
".",
"$",
"this",
"->",
"getQueryFields",
"(",
")",
".",
"' FROM '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getQueryWhere",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getQueryOrderBy",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getQueryLimit",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"$",
"this",
"->",
"binds",
")",
";",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"if",
"(",
"$",
"statement",
"->",
"rowCount",
"(",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"ExceptionNoData",
"(",
"'No data for current query! (query: '",
".",
"$",
"query",
".",
"', bind: '",
".",
"json_encode",
"(",
"$",
"this",
"->",
"binds",
")",
".",
"')'",
",",
"10001",
")",
";",
"}",
"//~ Create new object, set data & save it in cache",
"return",
"$",
"this",
"->",
"newDataInstance",
"(",
"$",
"statement",
"->",
"fetchObject",
"(",
")",
",",
"true",
")",
";",
"}"
]
| Select first rows corresponding to where clause.
@return DataAbstract
@throws ExceptionNoData | [
"Select",
"first",
"rows",
"corresponding",
"to",
"where",
"clause",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L782-L799 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.getCache | protected function getCache(DataAbstract $data)
{
if (!$this->isCacheEnabled) {
return false;
}
return $this->cache->get($data->getCacheKey());
} | php | protected function getCache(DataAbstract $data)
{
if (!$this->isCacheEnabled) {
return false;
}
return $this->cache->get($data->getCacheKey());
} | [
"protected",
"function",
"getCache",
"(",
"DataAbstract",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCacheEnabled",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"data",
"->",
"getCacheKey",
"(",
")",
")",
";",
"}"
]
| Get Data object from cache if is enabled.
@param DataAbstract $data
@return bool|DataAbstract | [
"Get",
"Data",
"object",
"from",
"cache",
"if",
"is",
"enabled",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L822-L829 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.setCache | protected function setCache(DataAbstract $data)
{
if (!$this->isCacheEnabled) {
return $this;
}
$this->cache->set($data->getCacheKey(), $data);
return $this;
} | php | protected function setCache(DataAbstract $data)
{
if (!$this->isCacheEnabled) {
return $this;
}
$this->cache->set($data->getCacheKey(), $data);
return $this;
} | [
"protected",
"function",
"setCache",
"(",
"DataAbstract",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isCacheEnabled",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"$",
"data",
"->",
"getCacheKey",
"(",
")",
",",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set data into cache if enabled.
@param DataAbstract $data
@return self | [
"Set",
"data",
"into",
"cache",
"if",
"enabled",
"."
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L837-L846 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.isDataUpdated | protected function isDataUpdated($data, $field)
{
if (!isset($this->dataNamesMap[$field]['property'])) {
throw new \DomainException('Field have not mapping with Data instance (field: ' . $field . ')');
}
$property = $this->dataNamesMap[$field]['property'];
return $data->isUpdated($property);
} | php | protected function isDataUpdated($data, $field)
{
if (!isset($this->dataNamesMap[$field]['property'])) {
throw new \DomainException('Field have not mapping with Data instance (field: ' . $field . ')');
}
$property = $this->dataNamesMap[$field]['property'];
return $data->isUpdated($property);
} | [
"protected",
"function",
"isDataUpdated",
"(",
"$",
"data",
",",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"dataNamesMap",
"[",
"$",
"field",
"]",
"[",
"'property'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Field have not mapping with Data instance (field: '",
".",
"$",
"field",
".",
"')'",
")",
";",
"}",
"$",
"property",
"=",
"$",
"this",
"->",
"dataNamesMap",
"[",
"$",
"field",
"]",
"[",
"'property'",
"]",
";",
"return",
"$",
"data",
"->",
"isUpdated",
"(",
"$",
"property",
")",
";",
"}"
]
| Check if data value is updated or not
@param DataAbstract $data
@param string $field
@return bool
@throws \DomainException | [
"Check",
"if",
"data",
"value",
"is",
"updated",
"or",
"not"
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L856-L865 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.getDataValue | protected function getDataValue($data, $field)
{
if (!isset($this->dataNamesMap[$field]['get'])) {
throw new \DomainException('Field have not mapping with Data instance (field: ' . $field . ')');
}
$method = $this->dataNamesMap[$field]['get'];
return $data->{$method}();
} | php | protected function getDataValue($data, $field)
{
if (!isset($this->dataNamesMap[$field]['get'])) {
throw new \DomainException('Field have not mapping with Data instance (field: ' . $field . ')');
}
$method = $this->dataNamesMap[$field]['get'];
return $data->{$method}();
} | [
"protected",
"function",
"getDataValue",
"(",
"$",
"data",
",",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"dataNamesMap",
"[",
"$",
"field",
"]",
"[",
"'get'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Field have not mapping with Data instance (field: '",
".",
"$",
"field",
".",
"')'",
")",
";",
"}",
"$",
"method",
"=",
"$",
"this",
"->",
"dataNamesMap",
"[",
"$",
"field",
"]",
"[",
"'get'",
"]",
";",
"return",
"$",
"data",
"->",
"{",
"$",
"method",
"}",
"(",
")",
";",
"}"
]
| Get value from DataAbstract instance based on field value
@param DataAbstract $data
@param string $field
@return mixed
@throws \DomainException | [
"Get",
"value",
"from",
"DataAbstract",
"instance",
"based",
"on",
"field",
"value"
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L875-L884 | train |
eureka-framework/component-orm | src/Orm/DataMapper/MapperAbstract.php | MapperAbstract.setDataValue | protected function setDataValue($data, $field, $value)
{
if (!isset($this->dataNamesMap[$field]['set'])) {
if (true === $this->ignoreNotMappedFields) {
return $this;
}
throw new \DomainException('Field have not mapping with Data instance (field: ' . $field . ')');
}
$method = $this->dataNamesMap[$field]['set'];
$data->{$method}($value);
return $this;
} | php | protected function setDataValue($data, $field, $value)
{
if (!isset($this->dataNamesMap[$field]['set'])) {
if (true === $this->ignoreNotMappedFields) {
return $this;
}
throw new \DomainException('Field have not mapping with Data instance (field: ' . $field . ')');
}
$method = $this->dataNamesMap[$field]['set'];
$data->{$method}($value);
return $this;
} | [
"protected",
"function",
"setDataValue",
"(",
"$",
"data",
",",
"$",
"field",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"dataNamesMap",
"[",
"$",
"field",
"]",
"[",
"'set'",
"]",
")",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"ignoreNotMappedFields",
")",
"{",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Field have not mapping with Data instance (field: '",
".",
"$",
"field",
".",
"')'",
")",
";",
"}",
"$",
"method",
"=",
"$",
"this",
"->",
"dataNamesMap",
"[",
"$",
"field",
"]",
"[",
"'set'",
"]",
";",
"$",
"data",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set value into DataAbstract instance based on field value
@param DataAbstract $data
@param string $field
@param mixed $value
@return mixed
@throws \DomainException | [
"Set",
"value",
"into",
"DataAbstract",
"instance",
"based",
"on",
"field",
"value"
]
| bce48121d26c4e923534f9dc70da597634184316 | https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/MapperAbstract.php#L895-L911 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.