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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.normilizeScopeName | public static function normilizeScopeName($name)
{
foreach (self::$reservedWordList as $reservedWord) {
if ($reservedWord.'Obj' == $name) {
return $reservedWord;
}
}
return $name;
} | php | public static function normilizeScopeName($name)
{
foreach (self::$reservedWordList as $reservedWord) {
if ($reservedWord.'Obj' == $name) {
return $reservedWord;
}
}
return $name;
} | [
"public",
"static",
"function",
"normilizeScopeName",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"reservedWordList",
"as",
"$",
"reservedWord",
")",
"{",
"if",
"(",
"$",
"reservedWord",
".",
"'Obj'",
"==",
"$",
"name",
")",
"{",
"return",
"$",
"reservedWord",
";",
"}",
"}",
"return",
"$",
"name",
";",
"}"
] | Remove 'Obj' if name is reserved PHP word.
@param string $name
@return string | [
"Remove",
"Obj",
"if",
"name",
"is",
"reserved",
"PHP",
"word",
"."
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L319-L328 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.getNaming | public static function getNaming($name, $prePostFix, $type = 'prefix', $symbol = '_')
{
if ($type == 'prefix') {
return static::toCamelCase($prePostFix.$symbol.$name, $symbol);
} else if ($type == 'postfix') {
return static::toCamelCase($name.$symbol.$prePostFix, $symbol);
}
return null;
} | php | public static function getNaming($name, $prePostFix, $type = 'prefix', $symbol = '_')
{
if ($type == 'prefix') {
return static::toCamelCase($prePostFix.$symbol.$name, $symbol);
} else if ($type == 'postfix') {
return static::toCamelCase($name.$symbol.$prePostFix, $symbol);
}
return null;
} | [
"public",
"static",
"function",
"getNaming",
"(",
"$",
"name",
",",
"$",
"prePostFix",
",",
"$",
"type",
"=",
"'prefix'",
",",
"$",
"symbol",
"=",
"'_'",
")",
"{",
"if",
"(",
"$",
"type",
"==",
"'prefix'",
")",
"{",
"return",
"static",
"::",
"toCamelCase",
"(",
"$",
"prePostFix",
".",
"$",
"symbol",
".",
"$",
"name",
",",
"$",
"symbol",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"==",
"'postfix'",
")",
"{",
"return",
"static",
"::",
"toCamelCase",
"(",
"$",
"name",
".",
"$",
"symbol",
".",
"$",
"prePostFix",
",",
"$",
"symbol",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get Naming according to prefix or postfix type
@param string $name
@param string $prePostFix
@param string $type
@return string | [
"Get",
"Naming",
"according",
"to",
"prefix",
"or",
"postfix",
"type"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L339-L348 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.unsetInArray | public static function unsetInArray(array $content, $unsets, $unsetParentEmptyArray = false)
{
if (empty($unsets)) {
return $content;
}
if (is_string($unsets)) {
$unsets = (array) $unsets;
}
foreach ($unsets as $rootKey => $unsetItem) {
$unsetItem = is_array($unsetItem) ? $unsetItem : (array) $unsetItem;
foreach ($unsetItem as $unsetString) {
if (is_string($rootKey)) {
$unsetString = $rootKey . '.' . $unsetString;
}
$keyArr = explode('.', $unsetString);
$keyChainCount = count($keyArr) - 1;
$elem = &$content;
$elementArr = [];
$elementArr[] = &$elem;
for ($i = 0; $i <= $keyChainCount; $i++) {
if (is_array($elem) && array_key_exists($keyArr[$i], $elem)) {
if ($i == $keyChainCount) {
unset($elem[$keyArr[$i]]);
if ($unsetParentEmptyArray) {
for ($j = count($elementArr); $j > 0; $j--) {
$pointer =& $elementArr[$j];
if (is_array($pointer) && empty($pointer)) {
$previous =& $elementArr[$j - 1];
unset($previous[$keyArr[$j - 1]]);
}
}
}
} else if (is_array($elem[$keyArr[$i]])) {
$elem = &$elem[$keyArr[$i]];
$elementArr[] = &$elem;
}
}
}
}
}
return $content;
} | php | public static function unsetInArray(array $content, $unsets, $unsetParentEmptyArray = false)
{
if (empty($unsets)) {
return $content;
}
if (is_string($unsets)) {
$unsets = (array) $unsets;
}
foreach ($unsets as $rootKey => $unsetItem) {
$unsetItem = is_array($unsetItem) ? $unsetItem : (array) $unsetItem;
foreach ($unsetItem as $unsetString) {
if (is_string($rootKey)) {
$unsetString = $rootKey . '.' . $unsetString;
}
$keyArr = explode('.', $unsetString);
$keyChainCount = count($keyArr) - 1;
$elem = &$content;
$elementArr = [];
$elementArr[] = &$elem;
for ($i = 0; $i <= $keyChainCount; $i++) {
if (is_array($elem) && array_key_exists($keyArr[$i], $elem)) {
if ($i == $keyChainCount) {
unset($elem[$keyArr[$i]]);
if ($unsetParentEmptyArray) {
for ($j = count($elementArr); $j > 0; $j--) {
$pointer =& $elementArr[$j];
if (is_array($pointer) && empty($pointer)) {
$previous =& $elementArr[$j - 1];
unset($previous[$keyArr[$j - 1]]);
}
}
}
} else if (is_array($elem[$keyArr[$i]])) {
$elem = &$elem[$keyArr[$i]];
$elementArr[] = &$elem;
}
}
}
}
}
return $content;
} | [
"public",
"static",
"function",
"unsetInArray",
"(",
"array",
"$",
"content",
",",
"$",
"unsets",
",",
"$",
"unsetParentEmptyArray",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"unsets",
")",
")",
"{",
"return",
"$",
"content",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"unsets",
")",
")",
"{",
"$",
"unsets",
"=",
"(",
"array",
")",
"$",
"unsets",
";",
"}",
"foreach",
"(",
"$",
"unsets",
"as",
"$",
"rootKey",
"=>",
"$",
"unsetItem",
")",
"{",
"$",
"unsetItem",
"=",
"is_array",
"(",
"$",
"unsetItem",
")",
"?",
"$",
"unsetItem",
":",
"(",
"array",
")",
"$",
"unsetItem",
";",
"foreach",
"(",
"$",
"unsetItem",
"as",
"$",
"unsetString",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"rootKey",
")",
")",
"{",
"$",
"unsetString",
"=",
"$",
"rootKey",
".",
"'.'",
".",
"$",
"unsetString",
";",
"}",
"$",
"keyArr",
"=",
"explode",
"(",
"'.'",
",",
"$",
"unsetString",
")",
";",
"$",
"keyChainCount",
"=",
"count",
"(",
"$",
"keyArr",
")",
"-",
"1",
";",
"$",
"elem",
"=",
"&",
"$",
"content",
";",
"$",
"elementArr",
"=",
"[",
"]",
";",
"$",
"elementArr",
"[",
"]",
"=",
"&",
"$",
"elem",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"$",
"keyChainCount",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"elem",
")",
"&&",
"array_key_exists",
"(",
"$",
"keyArr",
"[",
"$",
"i",
"]",
",",
"$",
"elem",
")",
")",
"{",
"if",
"(",
"$",
"i",
"==",
"$",
"keyChainCount",
")",
"{",
"unset",
"(",
"$",
"elem",
"[",
"$",
"keyArr",
"[",
"$",
"i",
"]",
"]",
")",
";",
"if",
"(",
"$",
"unsetParentEmptyArray",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"count",
"(",
"$",
"elementArr",
")",
";",
"$",
"j",
">",
"0",
";",
"$",
"j",
"--",
")",
"{",
"$",
"pointer",
"=",
"&",
"$",
"elementArr",
"[",
"$",
"j",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"pointer",
")",
"&&",
"empty",
"(",
"$",
"pointer",
")",
")",
"{",
"$",
"previous",
"=",
"&",
"$",
"elementArr",
"[",
"$",
"j",
"-",
"1",
"]",
";",
"unset",
"(",
"$",
"previous",
"[",
"$",
"keyArr",
"[",
"$",
"j",
"-",
"1",
"]",
"]",
")",
";",
"}",
"}",
"}",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"elem",
"[",
"$",
"keyArr",
"[",
"$",
"i",
"]",
"]",
")",
")",
"{",
"$",
"elem",
"=",
"&",
"$",
"elem",
"[",
"$",
"keyArr",
"[",
"$",
"i",
"]",
"]",
";",
"$",
"elementArr",
"[",
"]",
"=",
"&",
"$",
"elem",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"content",
";",
"}"
] | Unset content items defined in the unset.json
@param array $content
@param string | array $unsets in format
array(
'EntityName1' => array( 'unset1', 'unset2' ),
'EntityName2' => array( 'unset1', 'unset2' ),
)
OR
array('EntityName1.unset1', 'EntityName1.unset2', .....)
OR
'EntityName1.unset1'
@param bool $unsetParentEmptyArray - If unset empty parent array after unsets
@return array | [
"Unset",
"content",
"items",
"defined",
"in",
"the",
"unset",
".",
"json"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L397-L449 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.getClassName | public static function getClassName($filePath)
{
$className = preg_replace('/\.php$/i', '', $filePath);
$className = preg_replace('/^(application|custom)(\/|\\\)/i', '', $className);
$className = '\\'.static::toFormat($className, '\\');
return $className;
} | php | public static function getClassName($filePath)
{
$className = preg_replace('/\.php$/i', '', $filePath);
$className = preg_replace('/^(application|custom)(\/|\\\)/i', '', $className);
$className = '\\'.static::toFormat($className, '\\');
return $className;
} | [
"public",
"static",
"function",
"getClassName",
"(",
"$",
"filePath",
")",
"{",
"$",
"className",
"=",
"preg_replace",
"(",
"'/\\.php$/i'",
",",
"''",
",",
"$",
"filePath",
")",
";",
"$",
"className",
"=",
"preg_replace",
"(",
"'/^(application|custom)(\\/|\\\\\\)/i'",
",",
"''",
",",
"$",
"className",
")",
";",
"$",
"className",
"=",
"'\\\\'",
".",
"static",
"::",
"toFormat",
"(",
"$",
"className",
",",
"'\\\\'",
")",
";",
"return",
"$",
"className",
";",
"}"
] | Get class name from the file path
@param string $filePath
@return string | [
"Get",
"class",
"name",
"from",
"the",
"file",
"path"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L459-L466 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.isEquals | public static function isEquals($var1, $var2)
{
if (is_array($var1)) {
static::ksortRecursive($var1);
}
if (is_array($var2)) {
static::ksortRecursive($var2);
}
return ($var1 === $var2);
} | php | public static function isEquals($var1, $var2)
{
if (is_array($var1)) {
static::ksortRecursive($var1);
}
if (is_array($var2)) {
static::ksortRecursive($var2);
}
return ($var1 === $var2);
} | [
"public",
"static",
"function",
"isEquals",
"(",
"$",
"var1",
",",
"$",
"var2",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"var1",
")",
")",
"{",
"static",
"::",
"ksortRecursive",
"(",
"$",
"var1",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"var2",
")",
")",
"{",
"static",
"::",
"ksortRecursive",
"(",
"$",
"var2",
")",
";",
"}",
"return",
"(",
"$",
"var1",
"===",
"$",
"var2",
")",
";",
"}"
] | Check if two variables are equals
@param mixed $var1
@param mixed $var2
@return boolean | [
"Check",
"if",
"two",
"variables",
"are",
"equals"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L516-L526 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.ksortRecursive | public static function ksortRecursive(&$array)
{
if (!is_array($array)) {
return false;
}
ksort($array);
foreach ($array as $key => $value) {
static::ksortRecursive($array[$key]);
}
return true;
} | php | public static function ksortRecursive(&$array)
{
if (!is_array($array)) {
return false;
}
ksort($array);
foreach ($array as $key => $value) {
static::ksortRecursive($array[$key]);
}
return true;
} | [
"public",
"static",
"function",
"ksortRecursive",
"(",
"&",
"$",
"array",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"false",
";",
"}",
"ksort",
"(",
"$",
"array",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"static",
"::",
"ksortRecursive",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Sort array recursively
@param array $array
@return bool | [
"Sort",
"array",
"recursively"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L533-L545 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.arrayDiff | public static function arrayDiff(array $array1, array $array2)
{
$diff = array();
foreach ($array1 as $key1 => $value1) {
if (array_key_exists($key1, $array2)) {
if ($value1 !== $array2[$key1]) {
$diff[$key1] = $array2[$key1];
}
continue;
}
$diff[$key1] = $value1;
}
$diff = array_merge($diff, array_diff_key($array2, $array1));
return $diff;
} | php | public static function arrayDiff(array $array1, array $array2)
{
$diff = array();
foreach ($array1 as $key1 => $value1) {
if (array_key_exists($key1, $array2)) {
if ($value1 !== $array2[$key1]) {
$diff[$key1] = $array2[$key1];
}
continue;
}
$diff[$key1] = $value1;
}
$diff = array_merge($diff, array_diff_key($array2, $array1));
return $diff;
} | [
"public",
"static",
"function",
"arrayDiff",
"(",
"array",
"$",
"array1",
",",
"array",
"$",
"array2",
")",
"{",
"$",
"diff",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array1",
"as",
"$",
"key1",
"=>",
"$",
"value1",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key1",
",",
"$",
"array2",
")",
")",
"{",
"if",
"(",
"$",
"value1",
"!==",
"$",
"array2",
"[",
"$",
"key1",
"]",
")",
"{",
"$",
"diff",
"[",
"$",
"key1",
"]",
"=",
"$",
"array2",
"[",
"$",
"key1",
"]",
";",
"}",
"continue",
";",
"}",
"$",
"diff",
"[",
"$",
"key1",
"]",
"=",
"$",
"value1",
";",
"}",
"$",
"diff",
"=",
"array_merge",
"(",
"$",
"diff",
",",
"array_diff_key",
"(",
"$",
"array2",
",",
"$",
"array1",
")",
")",
";",
"return",
"$",
"diff",
";",
"}"
] | Improved computing the difference of arrays
@param array $array1
@param array $array2
@return array | [
"Improved",
"computing",
"the",
"difference",
"of",
"arrays"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L589-L607 | train |
espocrm/espocrm | application/Espo/Core/Utils/Util.php | Util.fillArrayKeys | public static function fillArrayKeys($keys, $value)
{
$arrayKeys = is_array($keys) ? $keys : explode('.', $keys);
$array = array();
foreach (array_reverse($arrayKeys) as $i => $key) {
$array = array(
$key => ($i == 0) ? $value : $array,
);
}
return $array;
} | php | public static function fillArrayKeys($keys, $value)
{
$arrayKeys = is_array($keys) ? $keys : explode('.', $keys);
$array = array();
foreach (array_reverse($arrayKeys) as $i => $key) {
$array = array(
$key => ($i == 0) ? $value : $array,
);
}
return $array;
} | [
"public",
"static",
"function",
"fillArrayKeys",
"(",
"$",
"keys",
",",
"$",
"value",
")",
"{",
"$",
"arrayKeys",
"=",
"is_array",
"(",
"$",
"keys",
")",
"?",
"$",
"keys",
":",
"explode",
"(",
"'.'",
",",
"$",
"keys",
")",
";",
"$",
"array",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"arrayKeys",
")",
"as",
"$",
"i",
"=>",
"$",
"key",
")",
"{",
"$",
"array",
"=",
"array",
"(",
"$",
"key",
"=>",
"(",
"$",
"i",
"==",
"0",
")",
"?",
"$",
"value",
":",
"$",
"array",
",",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Fill array with specified keys
@param array|string $keys
@param mixed $value
@return array | [
"Fill",
"array",
"with",
"specified",
"keys"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Util.php#L617-L629 | train |
espocrm/espocrm | application/Espo/Core/DataManager.php | DataManager.rebuild | public function rebuild($entityList = null)
{
$this->populateConfigParameters();
$result = $this->clearCache();
$result &= $this->rebuildMetadata();
$result &= $this->rebuildDatabase($entityList);
$this->rebuildScheduledJobs();
return $result;
} | php | public function rebuild($entityList = null)
{
$this->populateConfigParameters();
$result = $this->clearCache();
$result &= $this->rebuildMetadata();
$result &= $this->rebuildDatabase($entityList);
$this->rebuildScheduledJobs();
return $result;
} | [
"public",
"function",
"rebuild",
"(",
"$",
"entityList",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"populateConfigParameters",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"clearCache",
"(",
")",
";",
"$",
"result",
"&=",
"$",
"this",
"->",
"rebuildMetadata",
"(",
")",
";",
"$",
"result",
"&=",
"$",
"this",
"->",
"rebuildDatabase",
"(",
"$",
"entityList",
")",
";",
"$",
"this",
"->",
"rebuildScheduledJobs",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Rebuild the system with metadata, database and cache clearing
@return bool | [
"Rebuild",
"the",
"system",
"with",
"metadata",
"database",
"and",
"cache",
"clearing"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/DataManager.php#L54-L67 | train |
espocrm/espocrm | application/Espo/Core/DataManager.php | DataManager.clearCache | public function clearCache()
{
$result = $this->getContainer()->get('fileManager')->removeInDir($this->cachePath);
if ($result != true) {
throw new Exceptions\Error("Error while clearing cache");
}
$this->updateCacheTimestamp();
return $result;
} | php | public function clearCache()
{
$result = $this->getContainer()->get('fileManager')->removeInDir($this->cachePath);
if ($result != true) {
throw new Exceptions\Error("Error while clearing cache");
}
$this->updateCacheTimestamp();
return $result;
} | [
"public",
"function",
"clearCache",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'fileManager'",
")",
"->",
"removeInDir",
"(",
"$",
"this",
"->",
"cachePath",
")",
";",
"if",
"(",
"$",
"result",
"!=",
"true",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"Error",
"(",
"\"Error while clearing cache\"",
")",
";",
"}",
"$",
"this",
"->",
"updateCacheTimestamp",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Clear a cache
@return bool | [
"Clear",
"a",
"cache"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/DataManager.php#L74-L85 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.setDefaultPermissions | public function setDefaultPermissions($path, $recurse = false)
{
if (!file_exists($path)) {
return false;
}
$permission = $this->getDefaultPermissions();
$result = $this->chmod($path, array($permission['file'], $permission['dir']), $recurse);
if (!empty($permission['user'])) {
$result &= $this->chown($path, $permission['user'], $recurse);
}
if (!empty($permission['group'])) {
$result &= $this->chgrp($path, $permission['group'], $recurse);
}
return $result;
} | php | public function setDefaultPermissions($path, $recurse = false)
{
if (!file_exists($path)) {
return false;
}
$permission = $this->getDefaultPermissions();
$result = $this->chmod($path, array($permission['file'], $permission['dir']), $recurse);
if (!empty($permission['user'])) {
$result &= $this->chown($path, $permission['user'], $recurse);
}
if (!empty($permission['group'])) {
$result &= $this->chgrp($path, $permission['group'], $recurse);
}
return $result;
} | [
"public",
"function",
"setDefaultPermissions",
"(",
"$",
"path",
",",
"$",
"recurse",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"permission",
"=",
"$",
"this",
"->",
"getDefaultPermissions",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"chmod",
"(",
"$",
"path",
",",
"array",
"(",
"$",
"permission",
"[",
"'file'",
"]",
",",
"$",
"permission",
"[",
"'dir'",
"]",
")",
",",
"$",
"recurse",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"permission",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"result",
"&=",
"$",
"this",
"->",
"chown",
"(",
"$",
"path",
",",
"$",
"permission",
"[",
"'user'",
"]",
",",
"$",
"recurse",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"permission",
"[",
"'group'",
"]",
")",
")",
"{",
"$",
"result",
"&=",
"$",
"this",
"->",
"chgrp",
"(",
"$",
"path",
",",
"$",
"permission",
"[",
"'group'",
"]",
",",
"$",
"recurse",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Set default permission
@param string $path
@param bool $recurse
@return bool | [
"Set",
"default",
"permission"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L126-L143 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.getCurrentPermission | public function getCurrentPermission($filePath)
{
if (!file_exists($filePath)) {
return false;
}
$fileInfo= stat($filePath);
return substr(base_convert($fileInfo['mode'],10,8), -4);
} | php | public function getCurrentPermission($filePath)
{
if (!file_exists($filePath)) {
return false;
}
$fileInfo= stat($filePath);
return substr(base_convert($fileInfo['mode'],10,8), -4);
} | [
"public",
"function",
"getCurrentPermission",
"(",
"$",
"filePath",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fileInfo",
"=",
"stat",
"(",
"$",
"filePath",
")",
";",
"return",
"substr",
"(",
"base_convert",
"(",
"$",
"fileInfo",
"[",
"'mode'",
"]",
",",
"10",
",",
"8",
")",
",",
"-",
"4",
")",
";",
"}"
] | Get current permissions
@param string $filename
@return string | bool | [
"Get",
"current",
"permissions"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L151-L160 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.chown | public function chown($path, $user = '', $recurse = false)
{
if (!file_exists($path)) {
return false;
}
if (empty($user)) {
$user = $this->getDefaultOwner();
}
//Set chown for non-recursive request
if (!$recurse) {
return $this->chownReal($path, $user);
}
//Recursive chown
return $this->chownRecurse($path, $user);
} | php | public function chown($path, $user = '', $recurse = false)
{
if (!file_exists($path)) {
return false;
}
if (empty($user)) {
$user = $this->getDefaultOwner();
}
//Set chown for non-recursive request
if (!$recurse) {
return $this->chownReal($path, $user);
}
//Recursive chown
return $this->chownRecurse($path, $user);
} | [
"public",
"function",
"chown",
"(",
"$",
"path",
",",
"$",
"user",
"=",
"''",
",",
"$",
"recurse",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getDefaultOwner",
"(",
")",
";",
"}",
"//Set chown for non-recursive request",
"if",
"(",
"!",
"$",
"recurse",
")",
"{",
"return",
"$",
"this",
"->",
"chownReal",
"(",
"$",
"path",
",",
"$",
"user",
")",
";",
"}",
"//Recursive chown",
"return",
"$",
"this",
"->",
"chownRecurse",
"(",
"$",
"path",
",",
"$",
"user",
")",
";",
"}"
] | Change owner permission
@param string $path
@param int | string $user
@param bool $recurse
@return bool | [
"Change",
"owner",
"permission"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L261-L278 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.chownRecurse | protected function chownRecurse($path, $user)
{
if (!file_exists($path)) {
return false;
}
if (!is_dir($path)) {
return $this->chownReal($path, $user);
}
$result = $this->chownReal($path, $user);
$allFiles = $this->getFileManager()->getFileList($path);
foreach ($allFiles as $item) {
$result &= $this->chownRecurse($path . Utils\Util::getSeparator() . $item, $user);
}
return (bool) $result;
} | php | protected function chownRecurse($path, $user)
{
if (!file_exists($path)) {
return false;
}
if (!is_dir($path)) {
return $this->chownReal($path, $user);
}
$result = $this->chownReal($path, $user);
$allFiles = $this->getFileManager()->getFileList($path);
foreach ($allFiles as $item) {
$result &= $this->chownRecurse($path . Utils\Util::getSeparator() . $item, $user);
}
return (bool) $result;
} | [
"protected",
"function",
"chownRecurse",
"(",
"$",
"path",
",",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"this",
"->",
"chownReal",
"(",
"$",
"path",
",",
"$",
"user",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"chownReal",
"(",
"$",
"path",
",",
"$",
"user",
")",
";",
"$",
"allFiles",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"getFileList",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"allFiles",
"as",
"$",
"item",
")",
"{",
"$",
"result",
"&=",
"$",
"this",
"->",
"chownRecurse",
"(",
"$",
"path",
".",
"Utils",
"\\",
"Util",
"::",
"getSeparator",
"(",
")",
".",
"$",
"item",
",",
"$",
"user",
")",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"result",
";",
"}"
] | Change owner permission recursive
@param string $path
@param string $user
@return bool | [
"Change",
"owner",
"permission",
"recursive"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L288-L306 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.chgrp | public function chgrp($path, $group = null, $recurse = false)
{
if (!file_exists($path)) {
return false;
}
if (!isset($group)) {
$group = $this->getDefaultGroup();
}
//Set chgrp for non-recursive request
if (!$recurse) {
return $this->chgrpReal($path, $group);
}
//Recursive chown
return $this->chgrpRecurse($path, $group);
} | php | public function chgrp($path, $group = null, $recurse = false)
{
if (!file_exists($path)) {
return false;
}
if (!isset($group)) {
$group = $this->getDefaultGroup();
}
//Set chgrp for non-recursive request
if (!$recurse) {
return $this->chgrpReal($path, $group);
}
//Recursive chown
return $this->chgrpRecurse($path, $group);
} | [
"public",
"function",
"chgrp",
"(",
"$",
"path",
",",
"$",
"group",
"=",
"null",
",",
"$",
"recurse",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"group",
")",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"getDefaultGroup",
"(",
")",
";",
"}",
"//Set chgrp for non-recursive request",
"if",
"(",
"!",
"$",
"recurse",
")",
"{",
"return",
"$",
"this",
"->",
"chgrpReal",
"(",
"$",
"path",
",",
"$",
"group",
")",
";",
"}",
"//Recursive chown",
"return",
"$",
"this",
"->",
"chgrpRecurse",
"(",
"$",
"path",
",",
"$",
"group",
")",
";",
"}"
] | Change group permission
@param string $path
@param int | string $group
@param bool $recurse
@return bool | [
"Change",
"group",
"permission"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L317-L334 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.chgrpRecurse | protected function chgrpRecurse($path, $group) {
if (!file_exists($path)) {
return false;
}
if (!is_dir($path)) {
return $this->chgrpReal($path, $group);
}
$result = $this->chgrpReal($path, $group);
$allFiles = $this->getFileManager()->getFileList($path);
foreach ($allFiles as $item) {
$result &= $this->chgrpRecurse($path . Utils\Util::getSeparator() . $item, $group);
}
return (bool) $result;
} | php | protected function chgrpRecurse($path, $group) {
if (!file_exists($path)) {
return false;
}
if (!is_dir($path)) {
return $this->chgrpReal($path, $group);
}
$result = $this->chgrpReal($path, $group);
$allFiles = $this->getFileManager()->getFileList($path);
foreach ($allFiles as $item) {
$result &= $this->chgrpRecurse($path . Utils\Util::getSeparator() . $item, $group);
}
return (bool) $result;
} | [
"protected",
"function",
"chgrpRecurse",
"(",
"$",
"path",
",",
"$",
"group",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"this",
"->",
"chgrpReal",
"(",
"$",
"path",
",",
"$",
"group",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"chgrpReal",
"(",
"$",
"path",
",",
"$",
"group",
")",
";",
"$",
"allFiles",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"getFileList",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"allFiles",
"as",
"$",
"item",
")",
"{",
"$",
"result",
"&=",
"$",
"this",
"->",
"chgrpRecurse",
"(",
"$",
"path",
".",
"Utils",
"\\",
"Util",
"::",
"getSeparator",
"(",
")",
".",
"$",
"item",
",",
"$",
"group",
")",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"result",
";",
"}"
] | Change group permission recursive
@param string $filename
@param int $fileOctal - ex. 0644
@param int $dirOctal - ex. 0755
@return bool | [
"Change",
"group",
"permission",
"recursive"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L345-L363 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.getDefaultOwner | public function getDefaultOwner($usePosix = false)
{
$defaultPermissions = $this->getDefaultPermissions();
$owner = $defaultPermissions['user'];
if (empty($owner) && $usePosix) {
$owner = function_exists('posix_getuid') ? posix_getuid() : null;
}
if (empty($owner)) {
return false;
}
return $owner;
} | php | public function getDefaultOwner($usePosix = false)
{
$defaultPermissions = $this->getDefaultPermissions();
$owner = $defaultPermissions['user'];
if (empty($owner) && $usePosix) {
$owner = function_exists('posix_getuid') ? posix_getuid() : null;
}
if (empty($owner)) {
return false;
}
return $owner;
} | [
"public",
"function",
"getDefaultOwner",
"(",
"$",
"usePosix",
"=",
"false",
")",
"{",
"$",
"defaultPermissions",
"=",
"$",
"this",
"->",
"getDefaultPermissions",
"(",
")",
";",
"$",
"owner",
"=",
"$",
"defaultPermissions",
"[",
"'user'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"owner",
")",
"&&",
"$",
"usePosix",
")",
"{",
"$",
"owner",
"=",
"function_exists",
"(",
"'posix_getuid'",
")",
"?",
"posix_getuid",
"(",
")",
":",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"owner",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"owner",
";",
"}"
] | Get default owner user
@return int - owner id | [
"Get",
"default",
"owner",
"user"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L422-L436 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.getDefaultGroup | public function getDefaultGroup($usePosix = false)
{
$defaultPermissions = $this->getDefaultPermissions();
$group = $defaultPermissions['group'];
if (empty($group) && $usePosix) {
$group = function_exists('posix_getegid') ? posix_getegid() : null;
}
if (empty($group)) {
return false;
}
return $group;
} | php | public function getDefaultGroup($usePosix = false)
{
$defaultPermissions = $this->getDefaultPermissions();
$group = $defaultPermissions['group'];
if (empty($group) && $usePosix) {
$group = function_exists('posix_getegid') ? posix_getegid() : null;
}
if (empty($group)) {
return false;
}
return $group;
} | [
"public",
"function",
"getDefaultGroup",
"(",
"$",
"usePosix",
"=",
"false",
")",
"{",
"$",
"defaultPermissions",
"=",
"$",
"this",
"->",
"getDefaultPermissions",
"(",
")",
";",
"$",
"group",
"=",
"$",
"defaultPermissions",
"[",
"'group'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"group",
")",
"&&",
"$",
"usePosix",
")",
"{",
"$",
"group",
"=",
"function_exists",
"(",
"'posix_getegid'",
")",
"?",
"posix_getegid",
"(",
")",
":",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"group",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"group",
";",
"}"
] | Get default group user
@return int - group id | [
"Get",
"default",
"group",
"user"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L443-L457 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.setMapPermission | public function setMapPermission($mode = null)
{
$this->permissionError = array();
$this->permissionErrorRules = array();
$params = $this->getParams();
$permissionRules = $this->permissionRules;
if (isset($mode)) {
foreach ($permissionRules as &$value) {
$value = $mode;
}
}
$result = true;
foreach ($params['permissionMap'] as $type => $items) {
$permission = $permissionRules[$type];
foreach ($items as $item) {
if (file_exists($item)) {
try {
$this->chmod($item, $permission, true);
} catch (\Exception $e) {
}
$res = is_readable($item);
/** check is wtitable */
if ($type == 'writable') {
$res &= is_writable($item);
if (is_dir($item)) {
$name = uniqid();
try {
$res &= $this->getFileManager()->putContents(array($item, $name), 'test');
$res &= $this->getFileManager()->removeFile($name, $item);
} catch (\Exception $e) {
$res = false;
}
}
}
if (!$res) {
$result = false;
$this->permissionError[] = $item;
$this->permissionErrorRules[$item] = $permission;
}
}
}
}
return $result;
} | php | public function setMapPermission($mode = null)
{
$this->permissionError = array();
$this->permissionErrorRules = array();
$params = $this->getParams();
$permissionRules = $this->permissionRules;
if (isset($mode)) {
foreach ($permissionRules as &$value) {
$value = $mode;
}
}
$result = true;
foreach ($params['permissionMap'] as $type => $items) {
$permission = $permissionRules[$type];
foreach ($items as $item) {
if (file_exists($item)) {
try {
$this->chmod($item, $permission, true);
} catch (\Exception $e) {
}
$res = is_readable($item);
/** check is wtitable */
if ($type == 'writable') {
$res &= is_writable($item);
if (is_dir($item)) {
$name = uniqid();
try {
$res &= $this->getFileManager()->putContents(array($item, $name), 'test');
$res &= $this->getFileManager()->removeFile($name, $item);
} catch (\Exception $e) {
$res = false;
}
}
}
if (!$res) {
$result = false;
$this->permissionError[] = $item;
$this->permissionErrorRules[$item] = $permission;
}
}
}
}
return $result;
} | [
"public",
"function",
"setMapPermission",
"(",
"$",
"mode",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"permissionError",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"permissionErrorRules",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"getParams",
"(",
")",
";",
"$",
"permissionRules",
"=",
"$",
"this",
"->",
"permissionRules",
";",
"if",
"(",
"isset",
"(",
"$",
"mode",
")",
")",
"{",
"foreach",
"(",
"$",
"permissionRules",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"mode",
";",
"}",
"}",
"$",
"result",
"=",
"true",
";",
"foreach",
"(",
"$",
"params",
"[",
"'permissionMap'",
"]",
"as",
"$",
"type",
"=>",
"$",
"items",
")",
"{",
"$",
"permission",
"=",
"$",
"permissionRules",
"[",
"$",
"type",
"]",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"item",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"chmod",
"(",
"$",
"item",
",",
"$",
"permission",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"$",
"res",
"=",
"is_readable",
"(",
"$",
"item",
")",
";",
"/** check is wtitable */",
"if",
"(",
"$",
"type",
"==",
"'writable'",
")",
"{",
"$",
"res",
"&=",
"is_writable",
"(",
"$",
"item",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"item",
")",
")",
"{",
"$",
"name",
"=",
"uniqid",
"(",
")",
";",
"try",
"{",
"$",
"res",
"&=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"putContents",
"(",
"array",
"(",
"$",
"item",
",",
"$",
"name",
")",
",",
"'test'",
")",
";",
"$",
"res",
"&=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"removeFile",
"(",
"$",
"name",
",",
"$",
"item",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"res",
"=",
"false",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"$",
"result",
"=",
"false",
";",
"$",
"this",
"->",
"permissionError",
"[",
"]",
"=",
"$",
"item",
";",
"$",
"this",
"->",
"permissionErrorRules",
"[",
"$",
"item",
"]",
"=",
"$",
"permission",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Set permission regarding defined in permissionMap
@return bool | [
"Set",
"permission",
"regarding",
"defined",
"in",
"permissionMap"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L464-L521 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Permission.php | Permission.getSearchCount | protected function getSearchCount($search, array $array)
{
$search = $this->getPregQuote($search);
$number = 0;
foreach ($array as $value) {
if (preg_match('/^'.$search.'/', $value)) {
$number++;
}
}
return $number;
} | php | protected function getSearchCount($search, array $array)
{
$search = $this->getPregQuote($search);
$number = 0;
foreach ($array as $value) {
if (preg_match('/^'.$search.'/', $value)) {
$number++;
}
}
return $number;
} | [
"protected",
"function",
"getSearchCount",
"(",
"$",
"search",
",",
"array",
"$",
"array",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"getPregQuote",
"(",
"$",
"search",
")",
";",
"$",
"number",
"=",
"0",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^'",
".",
"$",
"search",
".",
"'/'",
",",
"$",
"value",
")",
")",
"{",
"$",
"number",
"++",
";",
"}",
"}",
"return",
"$",
"number",
";",
"}"
] | Get count of a search string in a array
@param string $search
@param array $array
@return bool | [
"Get",
"count",
"of",
"a",
"search",
"string",
"in",
"a",
"array"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Permission.php#L578-L590 | train |
espocrm/espocrm | application/Espo/Core/Utils/FieldManager.php | FieldManager.normalizeDefs | protected function normalizeDefs($scope, $fieldName, array $fieldDefs)
{
$defs = new \stdClass();
$normalizedFieldDefs = $this->prepareFieldDefs($scope, $fieldName, $fieldDefs);
if (!empty($normalizedFieldDefs)) {
$defs->fields = (object) array(
$fieldName => (object) $normalizedFieldDefs,
);
}
/** Save links for a field. */
$linkDefs = isset($fieldDefs['linkDefs']) ? $fieldDefs['linkDefs'] : null;
$metaLinkDefs = $this->getMetadataHelper()->getLinkDefsInFieldMeta($scope, $fieldDefs);
if (isset($linkDefs) || isset($metaLinkDefs)) {
$metaLinkDefs = isset($metaLinkDefs) ? $metaLinkDefs : array();
$linkDefs = isset($linkDefs) ? $linkDefs : array();
$normalizedLinkdDefs = Util::merge($metaLinkDefs, $linkDefs);
if (!empty($normalizedLinkdDefs)) {
$defs->links = (object) array(
$fieldName => (object) $normalizedLinkdDefs,
);
}
}
return $defs;
} | php | protected function normalizeDefs($scope, $fieldName, array $fieldDefs)
{
$defs = new \stdClass();
$normalizedFieldDefs = $this->prepareFieldDefs($scope, $fieldName, $fieldDefs);
if (!empty($normalizedFieldDefs)) {
$defs->fields = (object) array(
$fieldName => (object) $normalizedFieldDefs,
);
}
/** Save links for a field. */
$linkDefs = isset($fieldDefs['linkDefs']) ? $fieldDefs['linkDefs'] : null;
$metaLinkDefs = $this->getMetadataHelper()->getLinkDefsInFieldMeta($scope, $fieldDefs);
if (isset($linkDefs) || isset($metaLinkDefs)) {
$metaLinkDefs = isset($metaLinkDefs) ? $metaLinkDefs : array();
$linkDefs = isset($linkDefs) ? $linkDefs : array();
$normalizedLinkdDefs = Util::merge($metaLinkDefs, $linkDefs);
if (!empty($normalizedLinkdDefs)) {
$defs->links = (object) array(
$fieldName => (object) $normalizedLinkdDefs,
);
}
}
return $defs;
} | [
"protected",
"function",
"normalizeDefs",
"(",
"$",
"scope",
",",
"$",
"fieldName",
",",
"array",
"$",
"fieldDefs",
")",
"{",
"$",
"defs",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"normalizedFieldDefs",
"=",
"$",
"this",
"->",
"prepareFieldDefs",
"(",
"$",
"scope",
",",
"$",
"fieldName",
",",
"$",
"fieldDefs",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"normalizedFieldDefs",
")",
")",
"{",
"$",
"defs",
"->",
"fields",
"=",
"(",
"object",
")",
"array",
"(",
"$",
"fieldName",
"=>",
"(",
"object",
")",
"$",
"normalizedFieldDefs",
",",
")",
";",
"}",
"/** Save links for a field. */",
"$",
"linkDefs",
"=",
"isset",
"(",
"$",
"fieldDefs",
"[",
"'linkDefs'",
"]",
")",
"?",
"$",
"fieldDefs",
"[",
"'linkDefs'",
"]",
":",
"null",
";",
"$",
"metaLinkDefs",
"=",
"$",
"this",
"->",
"getMetadataHelper",
"(",
")",
"->",
"getLinkDefsInFieldMeta",
"(",
"$",
"scope",
",",
"$",
"fieldDefs",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"linkDefs",
")",
"||",
"isset",
"(",
"$",
"metaLinkDefs",
")",
")",
"{",
"$",
"metaLinkDefs",
"=",
"isset",
"(",
"$",
"metaLinkDefs",
")",
"?",
"$",
"metaLinkDefs",
":",
"array",
"(",
")",
";",
"$",
"linkDefs",
"=",
"isset",
"(",
"$",
"linkDefs",
")",
"?",
"$",
"linkDefs",
":",
"array",
"(",
")",
";",
"$",
"normalizedLinkdDefs",
"=",
"Util",
"::",
"merge",
"(",
"$",
"metaLinkDefs",
",",
"$",
"linkDefs",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"normalizedLinkdDefs",
")",
")",
"{",
"$",
"defs",
"->",
"links",
"=",
"(",
"object",
")",
"array",
"(",
"$",
"fieldName",
"=>",
"(",
"object",
")",
"$",
"normalizedLinkdDefs",
",",
")",
";",
"}",
"}",
"return",
"$",
"defs",
";",
"}"
] | Add all needed block for a field defenition
@param string $scope
@param string $fieldName
@param array $fieldDefs
@return array | [
"Add",
"all",
"needed",
"block",
"for",
"a",
"field",
"defenition"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/FieldManager.php#L598-L627 | train |
espocrm/espocrm | application/Espo/Core/Utils/FieldManager.php | FieldManager.isCore | protected function isCore($scope, $name)
{
$existingField = $this->getFieldDefs($scope, $name);
if (isset($existingField) && (!isset($existingField['isCustom']) || !$existingField['isCustom'])) {
return true;
}
return false;
} | php | protected function isCore($scope, $name)
{
$existingField = $this->getFieldDefs($scope, $name);
if (isset($existingField) && (!isset($existingField['isCustom']) || !$existingField['isCustom'])) {
return true;
}
return false;
} | [
"protected",
"function",
"isCore",
"(",
"$",
"scope",
",",
"$",
"name",
")",
"{",
"$",
"existingField",
"=",
"$",
"this",
"->",
"getFieldDefs",
"(",
"$",
"scope",
",",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"existingField",
")",
"&&",
"(",
"!",
"isset",
"(",
"$",
"existingField",
"[",
"'isCustom'",
"]",
")",
"||",
"!",
"$",
"existingField",
"[",
"'isCustom'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if a field is core field
@param string $name
@param string $scope
@return boolean | [
"Check",
"if",
"a",
"field",
"is",
"core",
"field"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/FieldManager.php#L652-L660 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/ClassParser.php | ClassParser.getData | public function getData($paths, $cacheFile = false)
{
$data = null;
if (is_string($paths)) {
$paths = array(
'corePath' => $paths,
);
}
if ($cacheFile && file_exists($cacheFile) && $this->getConfig()->get('useCache')) {
$data = $this->getFileManager()->getPhpContents($cacheFile);
} else {
$data = $this->getClassNameHash($paths['corePath']);
if (isset($paths['modulePath'])) {
foreach ($this->getMetadata()->getModuleList() as $moduleName) {
$path = str_replace('{*}', $moduleName, $paths['modulePath']);
$data = array_merge($data, $this->getClassNameHash($path));
}
}
if (isset($paths['customPath'])) {
$data = array_merge($data, $this->getClassNameHash($paths['customPath']));
}
if ($cacheFile && $this->getConfig()->get('useCache')) {
$result = $this->getFileManager()->putPhpContents($cacheFile, $data);
if ($result == false) {
throw new \Espo\Core\Exceptions\Error();
}
}
}
return $data;
} | php | public function getData($paths, $cacheFile = false)
{
$data = null;
if (is_string($paths)) {
$paths = array(
'corePath' => $paths,
);
}
if ($cacheFile && file_exists($cacheFile) && $this->getConfig()->get('useCache')) {
$data = $this->getFileManager()->getPhpContents($cacheFile);
} else {
$data = $this->getClassNameHash($paths['corePath']);
if (isset($paths['modulePath'])) {
foreach ($this->getMetadata()->getModuleList() as $moduleName) {
$path = str_replace('{*}', $moduleName, $paths['modulePath']);
$data = array_merge($data, $this->getClassNameHash($path));
}
}
if (isset($paths['customPath'])) {
$data = array_merge($data, $this->getClassNameHash($paths['customPath']));
}
if ($cacheFile && $this->getConfig()->get('useCache')) {
$result = $this->getFileManager()->putPhpContents($cacheFile, $data);
if ($result == false) {
throw new \Espo\Core\Exceptions\Error();
}
}
}
return $data;
} | [
"public",
"function",
"getData",
"(",
"$",
"paths",
",",
"$",
"cacheFile",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"paths",
")",
")",
"{",
"$",
"paths",
"=",
"array",
"(",
"'corePath'",
"=>",
"$",
"paths",
",",
")",
";",
"}",
"if",
"(",
"$",
"cacheFile",
"&&",
"file_exists",
"(",
"$",
"cacheFile",
")",
"&&",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'useCache'",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"getPhpContents",
"(",
"$",
"cacheFile",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getClassNameHash",
"(",
"$",
"paths",
"[",
"'corePath'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"paths",
"[",
"'modulePath'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"getModuleList",
"(",
")",
"as",
"$",
"moduleName",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'{*}'",
",",
"$",
"moduleName",
",",
"$",
"paths",
"[",
"'modulePath'",
"]",
")",
";",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"getClassNameHash",
"(",
"$",
"path",
")",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"paths",
"[",
"'customPath'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"getClassNameHash",
"(",
"$",
"paths",
"[",
"'customPath'",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"cacheFile",
"&&",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'useCache'",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"putPhpContents",
"(",
"$",
"cacheFile",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"result",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Espo",
"\\",
"Core",
"\\",
"Exceptions",
"\\",
"Error",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Return path data of classes
@param string $cacheFile full path for a cache file, ex. data/cache/application/entryPoints.php
@param string | array $paths in format array(
'corePath' => '',
'modulePath' => '',
'customPath' => '',
);
@return array | [
"Return",
"path",
"data",
"of",
"classes"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/ClassParser.php#L85-L121 | train |
espocrm/espocrm | application/Espo/Core/Utils/AdminNotificationManager.php | AdminNotificationManager.createNotification | public function createNotification($message, $userId = '1')
{
$notification = $this->getEntityManager()->getEntity('Notification');
$notification->set(array(
'type' => 'message',
'data' => array(
'userId' => $userId,
),
'userId' => $userId,
'message' => $message
));
$this->getEntityManager()->saveEntity($notification);
} | php | public function createNotification($message, $userId = '1')
{
$notification = $this->getEntityManager()->getEntity('Notification');
$notification->set(array(
'type' => 'message',
'data' => array(
'userId' => $userId,
),
'userId' => $userId,
'message' => $message
));
$this->getEntityManager()->saveEntity($notification);
} | [
"public",
"function",
"createNotification",
"(",
"$",
"message",
",",
"$",
"userId",
"=",
"'1'",
")",
"{",
"$",
"notification",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getEntity",
"(",
"'Notification'",
")",
";",
"$",
"notification",
"->",
"set",
"(",
"array",
"(",
"'type'",
"=>",
"'message'",
",",
"'data'",
"=>",
"array",
"(",
"'userId'",
"=>",
"$",
"userId",
",",
")",
",",
"'userId'",
"=>",
"$",
"userId",
",",
"'message'",
"=>",
"$",
"message",
")",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"saveEntity",
"(",
"$",
"notification",
")",
";",
"}"
] | Create EspoCRM notification for a user
@param string $message
@param string $userId
@return void | [
"Create",
"EspoCRM",
"notification",
"for",
"a",
"user"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/AdminNotificationManager.php#L190-L202 | train |
espocrm/espocrm | application/Espo/Core/Utils/Metadata.php | Metadata.getData | protected function getData()
{
if (empty($this->data) || !is_array($this->data)) {
$this->init();
}
return $this->data;
} | php | protected function getData()
{
if (empty($this->data) || !is_array($this->data)) {
$this->init();
}
return $this->data;
} | [
"protected",
"function",
"getData",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"init",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"data",
";",
"}"
] | Get metadata array
@return array | [
"Get",
"metadata",
"array"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Metadata.php#L176-L183 | train |
espocrm/espocrm | application/Espo/Core/Utils/Metadata.php | Metadata.getAll | public function getAll($isJSON = false, $reload = false)
{
if ($reload) {
$this->init($reload);
}
if ($isJSON) {
return Json::encode($this->data);
}
return $this->data;
} | php | public function getAll($isJSON = false, $reload = false)
{
if ($reload) {
$this->init($reload);
}
if ($isJSON) {
return Json::encode($this->data);
}
return $this->data;
} | [
"public",
"function",
"getAll",
"(",
"$",
"isJSON",
"=",
"false",
",",
"$",
"reload",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"reload",
")",
"{",
"$",
"this",
"->",
"init",
"(",
"$",
"reload",
")",
";",
"}",
"if",
"(",
"$",
"isJSON",
")",
"{",
"return",
"Json",
"::",
"encode",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}",
"return",
"$",
"this",
"->",
"data",
";",
"}"
] | Get All Metadata context
@param $isJSON
@param bool $reload
@return json | array | [
"Get",
"All",
"Metadata",
"context"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Metadata.php#L207-L217 | train |
espocrm/espocrm | application/Espo/Core/Utils/Metadata.php | Metadata.getObjects | public function getObjects($key = null, $default = null)
{
$objData = $this->getObjData();
return Util::getValueByKey($objData, $key, $default);
} | php | public function getObjects($key = null, $default = null)
{
$objData = $this->getObjData();
return Util::getValueByKey($objData, $key, $default);
} | [
"public",
"function",
"getObjects",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"objData",
"=",
"$",
"this",
"->",
"getObjData",
"(",
")",
";",
"return",
"Util",
"::",
"getValueByKey",
"(",
"$",
"objData",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] | Get Object Metadata
@param mixed string|array $key
@param mixed $default
@return object | [
"Get",
"Object",
"Metadata"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Metadata.php#L257-L262 | train |
espocrm/espocrm | application/Espo/Core/Utils/Metadata.php | Metadata.getCustom | public function getCustom($key1, $key2, $default = null)
{
$filePath = array($this->paths['customPath'], $key1, $key2.'.json');
$fileContent = $this->getFileManager()->getContents($filePath);
if ($fileContent) {
return Json::decode($fileContent);
}
return $default;
} | php | public function getCustom($key1, $key2, $default = null)
{
$filePath = array($this->paths['customPath'], $key1, $key2.'.json');
$fileContent = $this->getFileManager()->getContents($filePath);
if ($fileContent) {
return Json::decode($fileContent);
}
return $default;
} | [
"public",
"function",
"getCustom",
"(",
"$",
"key1",
",",
"$",
"key2",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"filePath",
"=",
"array",
"(",
"$",
"this",
"->",
"paths",
"[",
"'customPath'",
"]",
",",
"$",
"key1",
",",
"$",
"key2",
".",
"'.json'",
")",
";",
"$",
"fileContent",
"=",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"getContents",
"(",
"$",
"filePath",
")",
";",
"if",
"(",
"$",
"fileContent",
")",
"{",
"return",
"Json",
"::",
"decode",
"(",
"$",
"fileContent",
")",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Get metadata definition in custom directory
@param string|array $key
@param mixed $default
@return object|mixed | [
"Get",
"metadata",
"definition",
"in",
"custom",
"directory"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Metadata.php#L357-L367 | train |
espocrm/espocrm | application/Espo/Core/Utils/Metadata.php | Metadata.delete | public function delete($key1, $key2, $unsets = null)
{
if (!is_array($unsets)) {
$unsets = (array) $unsets;
}
switch ($key1) {
case 'entityDefs':
//unset related additional fields, e.g. a field with "address" type
$fieldDefinitionList = $this->get('fields');
$unsetList = $unsets;
foreach ($unsetList as $unsetItem) {
if (preg_match('/fields\.([^\.]+)/', $unsetItem, $matches) && isset($matches[1])) {
$fieldName = $matches[1];
$fieldPath = [$key1, $key2, 'fields', $fieldName];
$additionalFields = $this->getMetadataHelper()->getAdditionalFieldList($fieldName, $this->get($fieldPath, []), $fieldDefinitionList);
if (is_array($additionalFields)) {
foreach ($additionalFields as $additionalFieldName => $additionalFieldParams) {
$unsets[] = 'fields.' . $additionalFieldName;
}
}
}
}
break;
}
$normalizedData = array(
'__APPEND__',
);
$metadataUnsetData = array();
foreach ($unsets as $unsetItem) {
$normalizedData[] = $unsetItem;
$metadataUnsetData[] = implode('.', array($key1, $key2, $unsetItem));
}
$unsetData = array(
$key1 => array(
$key2 => $normalizedData
)
);
$this->deletedData = Util::merge($this->deletedData, $unsetData);
$this->deletedData = Util::unsetInArrayByValue('__APPEND__', $this->deletedData, true);
$this->data = Util::unsetInArray($this->getData(), $metadataUnsetData, true);
} | php | public function delete($key1, $key2, $unsets = null)
{
if (!is_array($unsets)) {
$unsets = (array) $unsets;
}
switch ($key1) {
case 'entityDefs':
//unset related additional fields, e.g. a field with "address" type
$fieldDefinitionList = $this->get('fields');
$unsetList = $unsets;
foreach ($unsetList as $unsetItem) {
if (preg_match('/fields\.([^\.]+)/', $unsetItem, $matches) && isset($matches[1])) {
$fieldName = $matches[1];
$fieldPath = [$key1, $key2, 'fields', $fieldName];
$additionalFields = $this->getMetadataHelper()->getAdditionalFieldList($fieldName, $this->get($fieldPath, []), $fieldDefinitionList);
if (is_array($additionalFields)) {
foreach ($additionalFields as $additionalFieldName => $additionalFieldParams) {
$unsets[] = 'fields.' . $additionalFieldName;
}
}
}
}
break;
}
$normalizedData = array(
'__APPEND__',
);
$metadataUnsetData = array();
foreach ($unsets as $unsetItem) {
$normalizedData[] = $unsetItem;
$metadataUnsetData[] = implode('.', array($key1, $key2, $unsetItem));
}
$unsetData = array(
$key1 => array(
$key2 => $normalizedData
)
);
$this->deletedData = Util::merge($this->deletedData, $unsetData);
$this->deletedData = Util::unsetInArrayByValue('__APPEND__', $this->deletedData, true);
$this->data = Util::unsetInArray($this->getData(), $metadataUnsetData, true);
} | [
"public",
"function",
"delete",
"(",
"$",
"key1",
",",
"$",
"key2",
",",
"$",
"unsets",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"unsets",
")",
")",
"{",
"$",
"unsets",
"=",
"(",
"array",
")",
"$",
"unsets",
";",
"}",
"switch",
"(",
"$",
"key1",
")",
"{",
"case",
"'entityDefs'",
":",
"//unset related additional fields, e.g. a field with \"address\" type",
"$",
"fieldDefinitionList",
"=",
"$",
"this",
"->",
"get",
"(",
"'fields'",
")",
";",
"$",
"unsetList",
"=",
"$",
"unsets",
";",
"foreach",
"(",
"$",
"unsetList",
"as",
"$",
"unsetItem",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/fields\\.([^\\.]+)/'",
",",
"$",
"unsetItem",
",",
"$",
"matches",
")",
"&&",
"isset",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
"{",
"$",
"fieldName",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"fieldPath",
"=",
"[",
"$",
"key1",
",",
"$",
"key2",
",",
"'fields'",
",",
"$",
"fieldName",
"]",
";",
"$",
"additionalFields",
"=",
"$",
"this",
"->",
"getMetadataHelper",
"(",
")",
"->",
"getAdditionalFieldList",
"(",
"$",
"fieldName",
",",
"$",
"this",
"->",
"get",
"(",
"$",
"fieldPath",
",",
"[",
"]",
")",
",",
"$",
"fieldDefinitionList",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"additionalFields",
")",
")",
"{",
"foreach",
"(",
"$",
"additionalFields",
"as",
"$",
"additionalFieldName",
"=>",
"$",
"additionalFieldParams",
")",
"{",
"$",
"unsets",
"[",
"]",
"=",
"'fields.'",
".",
"$",
"additionalFieldName",
";",
"}",
"}",
"}",
"}",
"break",
";",
"}",
"$",
"normalizedData",
"=",
"array",
"(",
"'__APPEND__'",
",",
")",
";",
"$",
"metadataUnsetData",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"unsets",
"as",
"$",
"unsetItem",
")",
"{",
"$",
"normalizedData",
"[",
"]",
"=",
"$",
"unsetItem",
";",
"$",
"metadataUnsetData",
"[",
"]",
"=",
"implode",
"(",
"'.'",
",",
"array",
"(",
"$",
"key1",
",",
"$",
"key2",
",",
"$",
"unsetItem",
")",
")",
";",
"}",
"$",
"unsetData",
"=",
"array",
"(",
"$",
"key1",
"=>",
"array",
"(",
"$",
"key2",
"=>",
"$",
"normalizedData",
")",
")",
";",
"$",
"this",
"->",
"deletedData",
"=",
"Util",
"::",
"merge",
"(",
"$",
"this",
"->",
"deletedData",
",",
"$",
"unsetData",
")",
";",
"$",
"this",
"->",
"deletedData",
"=",
"Util",
"::",
"unsetInArrayByValue",
"(",
"'__APPEND__'",
",",
"$",
"this",
"->",
"deletedData",
",",
"true",
")",
";",
"$",
"this",
"->",
"data",
"=",
"Util",
"::",
"unsetInArray",
"(",
"$",
"this",
"->",
"getData",
"(",
")",
",",
"$",
"metadataUnsetData",
",",
"true",
")",
";",
"}"
] | Unset some fields and other stuff in metadat
@param string $key1
@param string $key2
@param array | string $unsets Ex. 'fields.name'
@return bool | [
"Unset",
"some",
"fields",
"and",
"other",
"stuff",
"in",
"metadat"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Metadata.php#L439-L486 | train |
espocrm/espocrm | application/Espo/Core/Utils/Metadata.php | Metadata.undelete | protected function undelete($key1, $key2, $data)
{
if (isset($this->deletedData[$key1][$key2])) {
foreach ($this->deletedData[$key1][$key2] as $unsetIndex => $unsetItem) {
$value = Util::getValueByKey($data, $unsetItem);
if (isset($value)) {
unset($this->deletedData[$key1][$key2][$unsetIndex]);
}
}
}
} | php | protected function undelete($key1, $key2, $data)
{
if (isset($this->deletedData[$key1][$key2])) {
foreach ($this->deletedData[$key1][$key2] as $unsetIndex => $unsetItem) {
$value = Util::getValueByKey($data, $unsetItem);
if (isset($value)) {
unset($this->deletedData[$key1][$key2][$unsetIndex]);
}
}
}
} | [
"protected",
"function",
"undelete",
"(",
"$",
"key1",
",",
"$",
"key2",
",",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"deletedData",
"[",
"$",
"key1",
"]",
"[",
"$",
"key2",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"deletedData",
"[",
"$",
"key1",
"]",
"[",
"$",
"key2",
"]",
"as",
"$",
"unsetIndex",
"=>",
"$",
"unsetItem",
")",
"{",
"$",
"value",
"=",
"Util",
"::",
"getValueByKey",
"(",
"$",
"data",
",",
"$",
"unsetItem",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"value",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"deletedData",
"[",
"$",
"key1",
"]",
"[",
"$",
"key2",
"]",
"[",
"$",
"unsetIndex",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Undelete the deleted items
@param string $key1
@param string $key2
@param array $data
@return void | [
"Undelete",
"the",
"deleted",
"items"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Metadata.php#L496-L506 | train |
espocrm/espocrm | application/Espo/Core/Utils/Metadata.php | Metadata.getEntityPath | public function getEntityPath($entityName, $delim = '\\')
{
$path = $this->getScopePath($entityName, $delim);
return implode($delim, array($path, 'Entities', Util::normilizeClassName(ucfirst($entityName))));
} | php | public function getEntityPath($entityName, $delim = '\\')
{
$path = $this->getScopePath($entityName, $delim);
return implode($delim, array($path, 'Entities', Util::normilizeClassName(ucfirst($entityName))));
} | [
"public",
"function",
"getEntityPath",
"(",
"$",
"entityName",
",",
"$",
"delim",
"=",
"'\\\\'",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getScopePath",
"(",
"$",
"entityName",
",",
"$",
"delim",
")",
";",
"return",
"implode",
"(",
"$",
"delim",
",",
"array",
"(",
"$",
"path",
",",
"'Entities'",
",",
"Util",
"::",
"normilizeClassName",
"(",
"ucfirst",
"(",
"$",
"entityName",
")",
")",
")",
")",
";",
"}"
] | Get Entity path, ex. Espo.Entities.Account or Modules\Crm\Entities\MyModule
@param string $entityName
@param bool $delim - delimiter
@return string | [
"Get",
"Entity",
"path",
"ex",
".",
"Espo",
".",
"Entities",
".",
"Account",
"or",
"Modules",
"\\",
"Crm",
"\\",
"Entities",
"\\",
"MyModule"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Metadata.php#L571-L576 | train |
espocrm/espocrm | application/Espo/Core/Utils/Cron/Job.php | Job.removePendingJobDuplicates | public function removePendingJobDuplicates()
{
$pdo = $this->getEntityManager()->getPDO();
$query = "
SELECT scheduled_job_id
FROM job
WHERE
scheduled_job_id IS NOT NULL AND
`status` = '".CronManager::PENDING."' AND
execute_time <= '".date('Y-m-d H:i:s')."' AND
target_id IS NULL AND
deleted = 0
GROUP BY scheduled_job_id
HAVING count( * ) > 1
ORDER BY MAX(execute_time) ASC
";
$sth = $pdo->prepare($query);
$sth->execute();
$duplicateJobList = $sth->fetchAll(PDO::FETCH_ASSOC);
foreach ($duplicateJobList as $row) {
if (!empty($row['scheduled_job_id'])) {
$query = "
SELECT id FROM `job`
WHERE
scheduled_job_id = ".$pdo->quote($row['scheduled_job_id'])."
AND `status` = '" . CronManager::PENDING ."'
ORDER BY execute_time
DESC LIMIT 1, 100000
";
$sth = $pdo->prepare($query);
$sth->execute();
$jobIdList = $sth->fetchAll(PDO::FETCH_COLUMN);
if (empty($jobIdList)) {
continue;
}
$quotedJobIdList = [];
foreach ($jobIdList as $jobId) {
$quotedJobIdList[] = $pdo->quote($jobId);
}
$update = "
UPDATE job
SET deleted = 1
WHERE
id IN (".implode(", ", $quotedJobIdList).")
";
$sth = $pdo->prepare($update);
$sth->execute();
}
}
} | php | public function removePendingJobDuplicates()
{
$pdo = $this->getEntityManager()->getPDO();
$query = "
SELECT scheduled_job_id
FROM job
WHERE
scheduled_job_id IS NOT NULL AND
`status` = '".CronManager::PENDING."' AND
execute_time <= '".date('Y-m-d H:i:s')."' AND
target_id IS NULL AND
deleted = 0
GROUP BY scheduled_job_id
HAVING count( * ) > 1
ORDER BY MAX(execute_time) ASC
";
$sth = $pdo->prepare($query);
$sth->execute();
$duplicateJobList = $sth->fetchAll(PDO::FETCH_ASSOC);
foreach ($duplicateJobList as $row) {
if (!empty($row['scheduled_job_id'])) {
$query = "
SELECT id FROM `job`
WHERE
scheduled_job_id = ".$pdo->quote($row['scheduled_job_id'])."
AND `status` = '" . CronManager::PENDING ."'
ORDER BY execute_time
DESC LIMIT 1, 100000
";
$sth = $pdo->prepare($query);
$sth->execute();
$jobIdList = $sth->fetchAll(PDO::FETCH_COLUMN);
if (empty($jobIdList)) {
continue;
}
$quotedJobIdList = [];
foreach ($jobIdList as $jobId) {
$quotedJobIdList[] = $pdo->quote($jobId);
}
$update = "
UPDATE job
SET deleted = 1
WHERE
id IN (".implode(", ", $quotedJobIdList).")
";
$sth = $pdo->prepare($update);
$sth->execute();
}
}
} | [
"public",
"function",
"removePendingJobDuplicates",
"(",
")",
"{",
"$",
"pdo",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getPDO",
"(",
")",
";",
"$",
"query",
"=",
"\"\n SELECT scheduled_job_id\n FROM job\n WHERE\n scheduled_job_id IS NOT NULL AND\n `status` = '\"",
".",
"CronManager",
"::",
"PENDING",
".",
"\"' AND\n execute_time <= '\"",
".",
"date",
"(",
"'Y-m-d H:i:s'",
")",
".",
"\"' AND\n target_id IS NULL AND\n deleted = 0\n GROUP BY scheduled_job_id\n HAVING count( * ) > 1\n ORDER BY MAX(execute_time) ASC\n \"",
";",
"$",
"sth",
"=",
"$",
"pdo",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"sth",
"->",
"execute",
"(",
")",
";",
"$",
"duplicateJobList",
"=",
"$",
"sth",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"foreach",
"(",
"$",
"duplicateJobList",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"row",
"[",
"'scheduled_job_id'",
"]",
")",
")",
"{",
"$",
"query",
"=",
"\"\n SELECT id FROM `job`\n WHERE\n scheduled_job_id = \"",
".",
"$",
"pdo",
"->",
"quote",
"(",
"$",
"row",
"[",
"'scheduled_job_id'",
"]",
")",
".",
"\"\n AND `status` = '\"",
".",
"CronManager",
"::",
"PENDING",
".",
"\"'\n ORDER BY execute_time\n DESC LIMIT 1, 100000\n \"",
";",
"$",
"sth",
"=",
"$",
"pdo",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"sth",
"->",
"execute",
"(",
")",
";",
"$",
"jobIdList",
"=",
"$",
"sth",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_COLUMN",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"jobIdList",
")",
")",
"{",
"continue",
";",
"}",
"$",
"quotedJobIdList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"jobIdList",
"as",
"$",
"jobId",
")",
"{",
"$",
"quotedJobIdList",
"[",
"]",
"=",
"$",
"pdo",
"->",
"quote",
"(",
"$",
"jobId",
")",
";",
"}",
"$",
"update",
"=",
"\"\n UPDATE job\n SET deleted = 1\n WHERE\n id IN (\"",
".",
"implode",
"(",
"\", \"",
",",
"$",
"quotedJobIdList",
")",
".",
"\")\n \"",
";",
"$",
"sth",
"=",
"$",
"pdo",
"->",
"prepare",
"(",
"$",
"update",
")",
";",
"$",
"sth",
"->",
"execute",
"(",
")",
";",
"}",
"}",
"}"
] | Remove pending duplicate jobs, no need to run twice the same job
@return void | [
"Remove",
"pending",
"duplicate",
"jobs",
"no",
"need",
"to",
"run",
"twice",
"the",
"same",
"job"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Cron/Job.php#L325-L382 | train |
espocrm/espocrm | application/Espo/Core/Utils/Cron/Job.php | Job.updateFailedJobAttempts | public function updateFailedJobAttempts()
{
$query = "
SELECT * FROM job
WHERE
`status` = '" . CronManager::FAILED . "' AND
deleted = 0 AND
execute_time <= '".date('Y-m-d H:i:s')."' AND
attempts > 0
";
$pdo = $this->getEntityManager()->getPDO();
$sth = $pdo->prepare($query);
$sth->execute();
$rows = $sth->fetchAll(PDO::FETCH_ASSOC);
if ($rows) {
foreach ($rows as $row) {
$row['failed_attempts'] = isset($row['failed_attempts']) ? $row['failed_attempts'] : 0;
$attempts = $row['attempts'] - 1;
$failedAttempts = $row['failed_attempts'] + 1;
$update = "
UPDATE job
SET
`status` = '" . CronManager::PENDING ."',
attempts = ".$pdo->quote($attempts).",
failed_attempts = ".$pdo->quote($failedAttempts)."
WHERE
id = ".$pdo->quote($row['id'])."
";
$pdo->prepare($update)->execute();
}
}
} | php | public function updateFailedJobAttempts()
{
$query = "
SELECT * FROM job
WHERE
`status` = '" . CronManager::FAILED . "' AND
deleted = 0 AND
execute_time <= '".date('Y-m-d H:i:s')."' AND
attempts > 0
";
$pdo = $this->getEntityManager()->getPDO();
$sth = $pdo->prepare($query);
$sth->execute();
$rows = $sth->fetchAll(PDO::FETCH_ASSOC);
if ($rows) {
foreach ($rows as $row) {
$row['failed_attempts'] = isset($row['failed_attempts']) ? $row['failed_attempts'] : 0;
$attempts = $row['attempts'] - 1;
$failedAttempts = $row['failed_attempts'] + 1;
$update = "
UPDATE job
SET
`status` = '" . CronManager::PENDING ."',
attempts = ".$pdo->quote($attempts).",
failed_attempts = ".$pdo->quote($failedAttempts)."
WHERE
id = ".$pdo->quote($row['id'])."
";
$pdo->prepare($update)->execute();
}
}
} | [
"public",
"function",
"updateFailedJobAttempts",
"(",
")",
"{",
"$",
"query",
"=",
"\"\n SELECT * FROM job\n WHERE\n `status` = '\"",
".",
"CronManager",
"::",
"FAILED",
".",
"\"' AND\n deleted = 0 AND\n execute_time <= '\"",
".",
"date",
"(",
"'Y-m-d H:i:s'",
")",
".",
"\"' AND\n attempts > 0\n \"",
";",
"$",
"pdo",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getPDO",
"(",
")",
";",
"$",
"sth",
"=",
"$",
"pdo",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"sth",
"->",
"execute",
"(",
")",
";",
"$",
"rows",
"=",
"$",
"sth",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"$",
"rows",
")",
"{",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"row",
"[",
"'failed_attempts'",
"]",
"=",
"isset",
"(",
"$",
"row",
"[",
"'failed_attempts'",
"]",
")",
"?",
"$",
"row",
"[",
"'failed_attempts'",
"]",
":",
"0",
";",
"$",
"attempts",
"=",
"$",
"row",
"[",
"'attempts'",
"]",
"-",
"1",
";",
"$",
"failedAttempts",
"=",
"$",
"row",
"[",
"'failed_attempts'",
"]",
"+",
"1",
";",
"$",
"update",
"=",
"\"\n UPDATE job\n SET\n `status` = '\"",
".",
"CronManager",
"::",
"PENDING",
".",
"\"',\n attempts = \"",
".",
"$",
"pdo",
"->",
"quote",
"(",
"$",
"attempts",
")",
".",
"\",\n failed_attempts = \"",
".",
"$",
"pdo",
"->",
"quote",
"(",
"$",
"failedAttempts",
")",
".",
"\"\n WHERE\n id = \"",
".",
"$",
"pdo",
"->",
"quote",
"(",
"$",
"row",
"[",
"'id'",
"]",
")",
".",
"\"\n \"",
";",
"$",
"pdo",
"->",
"prepare",
"(",
"$",
"update",
")",
"->",
"execute",
"(",
")",
";",
"}",
"}",
"}"
] | Mark job attempts
@return void | [
"Mark",
"job",
"attempts"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Cron/Job.php#L389-L424 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Orm/Base.php | Base.getEntityParams | protected function getEntityParams($entityName = null, $isOrmEntityDefs = false, $returns = null)
{
if (!isset($entityName)) {
$entityName = $this->getEntityName();
}
$entityDefs = $this->getDefs($isOrmEntityDefs);
if (isset($entityDefs[$entityName])) {
return $entityDefs[$entityName];
}
return $returns;
} | php | protected function getEntityParams($entityName = null, $isOrmEntityDefs = false, $returns = null)
{
if (!isset($entityName)) {
$entityName = $this->getEntityName();
}
$entityDefs = $this->getDefs($isOrmEntityDefs);
if (isset($entityDefs[$entityName])) {
return $entityDefs[$entityName];
}
return $returns;
} | [
"protected",
"function",
"getEntityParams",
"(",
"$",
"entityName",
"=",
"null",
",",
"$",
"isOrmEntityDefs",
"=",
"false",
",",
"$",
"returns",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"entityName",
")",
")",
"{",
"$",
"entityName",
"=",
"$",
"this",
"->",
"getEntityName",
"(",
")",
";",
"}",
"$",
"entityDefs",
"=",
"$",
"this",
"->",
"getDefs",
"(",
"$",
"isOrmEntityDefs",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"entityDefs",
"[",
"$",
"entityName",
"]",
")",
")",
"{",
"return",
"$",
"entityDefs",
"[",
"$",
"entityName",
"]",
";",
"}",
"return",
"$",
"returns",
";",
"}"
] | Get entity params by name
@param string $entityName
@param bool $isOrmEntityDefs
@param mixed $returns
@return mixed | [
"Get",
"entity",
"params",
"by",
"name"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Orm/Base.php#L149-L162 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Orm/Base.php | Base.getFieldParams | protected function getFieldParams($fieldName = null, $entityName = null, $isOrmEntityDefs = false, $returns = null)
{
if (!isset($fieldName)) {
$fieldName = $this->getFieldName();
}
if (!isset($entityName)) {
$entityName = $this->getEntityName();
}
$entityDefs = $this->getDefs($isOrmEntityDefs);
if (isset($entityDefs[$entityName]) && isset($entityDefs[$entityName]['fields'][$fieldName])) {
return $entityDefs[$entityName]['fields'][$fieldName];
}
return $returns;
} | php | protected function getFieldParams($fieldName = null, $entityName = null, $isOrmEntityDefs = false, $returns = null)
{
if (!isset($fieldName)) {
$fieldName = $this->getFieldName();
}
if (!isset($entityName)) {
$entityName = $this->getEntityName();
}
$entityDefs = $this->getDefs($isOrmEntityDefs);
if (isset($entityDefs[$entityName]) && isset($entityDefs[$entityName]['fields'][$fieldName])) {
return $entityDefs[$entityName]['fields'][$fieldName];
}
return $returns;
} | [
"protected",
"function",
"getFieldParams",
"(",
"$",
"fieldName",
"=",
"null",
",",
"$",
"entityName",
"=",
"null",
",",
"$",
"isOrmEntityDefs",
"=",
"false",
",",
"$",
"returns",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"fieldName",
")",
")",
"{",
"$",
"fieldName",
"=",
"$",
"this",
"->",
"getFieldName",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"entityName",
")",
")",
"{",
"$",
"entityName",
"=",
"$",
"this",
"->",
"getEntityName",
"(",
")",
";",
"}",
"$",
"entityDefs",
"=",
"$",
"this",
"->",
"getDefs",
"(",
"$",
"isOrmEntityDefs",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"entityDefs",
"[",
"$",
"entityName",
"]",
")",
"&&",
"isset",
"(",
"$",
"entityDefs",
"[",
"$",
"entityName",
"]",
"[",
"'fields'",
"]",
"[",
"$",
"fieldName",
"]",
")",
")",
"{",
"return",
"$",
"entityDefs",
"[",
"$",
"entityName",
"]",
"[",
"'fields'",
"]",
"[",
"$",
"fieldName",
"]",
";",
"}",
"return",
"$",
"returns",
";",
"}"
] | Get field params by name for a specified entity
@param string $fieldName
@param string $entityName
@param bool $isOrmEntityDefs
@param mixed $returns
@return mixed | [
"Get",
"field",
"params",
"by",
"name",
"for",
"a",
"specified",
"entity"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Orm/Base.php#L173-L189 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Orm/Base.php | Base.getLinkParams | protected function getLinkParams($linkName = null, $entityName = null, $isOrmEntityDefs = false, $returns = null)
{
if (!isset($linkName)) {
$linkName = $this->getLinkName();
}
if (!isset($entityName)) {
$entityName = $this->getEntityName();
}
$entityDefs = $this->getDefs($isOrmEntityDefs);
$relationKeyName = $isOrmEntityDefs ? 'relations' : 'links';
if (isset($entityDefs[$entityName]) && isset($entityDefs[$entityName][$relationKeyName][$linkName])) {
return $entityDefs[$entityName][$relationKeyName][$linkName];
}
return $returns;
} | php | protected function getLinkParams($linkName = null, $entityName = null, $isOrmEntityDefs = false, $returns = null)
{
if (!isset($linkName)) {
$linkName = $this->getLinkName();
}
if (!isset($entityName)) {
$entityName = $this->getEntityName();
}
$entityDefs = $this->getDefs($isOrmEntityDefs);
$relationKeyName = $isOrmEntityDefs ? 'relations' : 'links';
if (isset($entityDefs[$entityName]) && isset($entityDefs[$entityName][$relationKeyName][$linkName])) {
return $entityDefs[$entityName][$relationKeyName][$linkName];
}
return $returns;
} | [
"protected",
"function",
"getLinkParams",
"(",
"$",
"linkName",
"=",
"null",
",",
"$",
"entityName",
"=",
"null",
",",
"$",
"isOrmEntityDefs",
"=",
"false",
",",
"$",
"returns",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"linkName",
")",
")",
"{",
"$",
"linkName",
"=",
"$",
"this",
"->",
"getLinkName",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"entityName",
")",
")",
"{",
"$",
"entityName",
"=",
"$",
"this",
"->",
"getEntityName",
"(",
")",
";",
"}",
"$",
"entityDefs",
"=",
"$",
"this",
"->",
"getDefs",
"(",
"$",
"isOrmEntityDefs",
")",
";",
"$",
"relationKeyName",
"=",
"$",
"isOrmEntityDefs",
"?",
"'relations'",
":",
"'links'",
";",
"if",
"(",
"isset",
"(",
"$",
"entityDefs",
"[",
"$",
"entityName",
"]",
")",
"&&",
"isset",
"(",
"$",
"entityDefs",
"[",
"$",
"entityName",
"]",
"[",
"$",
"relationKeyName",
"]",
"[",
"$",
"linkName",
"]",
")",
")",
"{",
"return",
"$",
"entityDefs",
"[",
"$",
"entityName",
"]",
"[",
"$",
"relationKeyName",
"]",
"[",
"$",
"linkName",
"]",
";",
"}",
"return",
"$",
"returns",
";",
"}"
] | Get relation params by name for a specified entity
@param string $linkName
@param string $entityName
@param bool $isOrmEntityDefs
@param mixed $returns
@return mixed | [
"Get",
"relation",
"params",
"by",
"name",
"for",
"a",
"specified",
"entity"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Orm/Base.php#L200-L217 | train |
espocrm/espocrm | application/Espo/Core/Utils/Database/Orm/Base.php | Base.getForeignField | protected function getForeignField($name, $entityName)
{
$foreignField = $this->getMetadata()->get('entityDefs.'.$entityName.'.fields.'.$name);
if ($foreignField['type'] != 'varchar') {
if ($foreignField['type'] == 'personName') {
return array('first' . ucfirst($name), ' ', 'last' . ucfirst($name));
}
}
return $name;
} | php | protected function getForeignField($name, $entityName)
{
$foreignField = $this->getMetadata()->get('entityDefs.'.$entityName.'.fields.'.$name);
if ($foreignField['type'] != 'varchar') {
if ($foreignField['type'] == 'personName') {
return array('first' . ucfirst($name), ' ', 'last' . ucfirst($name));
}
}
return $name;
} | [
"protected",
"function",
"getForeignField",
"(",
"$",
"name",
",",
"$",
"entityName",
")",
"{",
"$",
"foreignField",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
")",
"->",
"get",
"(",
"'entityDefs.'",
".",
"$",
"entityName",
".",
"'.fields.'",
".",
"$",
"name",
")",
";",
"if",
"(",
"$",
"foreignField",
"[",
"'type'",
"]",
"!=",
"'varchar'",
")",
"{",
"if",
"(",
"$",
"foreignField",
"[",
"'type'",
"]",
"==",
"'personName'",
")",
"{",
"return",
"array",
"(",
"'first'",
".",
"ucfirst",
"(",
"$",
"name",
")",
",",
"' '",
",",
"'last'",
".",
"ucfirst",
"(",
"$",
"name",
")",
")",
";",
"}",
"}",
"return",
"$",
"name",
";",
"}"
] | Get Foreign field
@param string $name
@param string $entityName
@return string | [
"Get",
"Foreign",
"field"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/Database/Orm/Base.php#L226-L237 | train |
espocrm/espocrm | install/core/SystemHelper.php | SystemHelper.getPermissionCommands | public function getPermissionCommands($path, $permissions = array('644', '755'), $isSudo = false, $isFile = null, $changeOwner = true)
{
if (is_string($path)) {
$path = array_fill(0, 2, $path);
}
list($chmodPath, $chownPath) = $path;
$commands = array();
$commands[] = $this->getChmodCommand($chmodPath, $permissions, $isSudo, $isFile);
if ($changeOwner) {
$chown = $this->getChownCommand($chownPath, $isSudo, false);
if (isset($chown)) {
$commands[] = $chown;
}
}
return implode(' ' . $this->combineOperator . ' ', $commands).';';
} | php | public function getPermissionCommands($path, $permissions = array('644', '755'), $isSudo = false, $isFile = null, $changeOwner = true)
{
if (is_string($path)) {
$path = array_fill(0, 2, $path);
}
list($chmodPath, $chownPath) = $path;
$commands = array();
$commands[] = $this->getChmodCommand($chmodPath, $permissions, $isSudo, $isFile);
if ($changeOwner) {
$chown = $this->getChownCommand($chownPath, $isSudo, false);
if (isset($chown)) {
$commands[] = $chown;
}
}
return implode(' ' . $this->combineOperator . ' ', $commands).';';
} | [
"public",
"function",
"getPermissionCommands",
"(",
"$",
"path",
",",
"$",
"permissions",
"=",
"array",
"(",
"'644'",
",",
"'755'",
")",
",",
"$",
"isSudo",
"=",
"false",
",",
"$",
"isFile",
"=",
"null",
",",
"$",
"changeOwner",
"=",
"true",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"array_fill",
"(",
"0",
",",
"2",
",",
"$",
"path",
")",
";",
"}",
"list",
"(",
"$",
"chmodPath",
",",
"$",
"chownPath",
")",
"=",
"$",
"path",
";",
"$",
"commands",
"=",
"array",
"(",
")",
";",
"$",
"commands",
"[",
"]",
"=",
"$",
"this",
"->",
"getChmodCommand",
"(",
"$",
"chmodPath",
",",
"$",
"permissions",
",",
"$",
"isSudo",
",",
"$",
"isFile",
")",
";",
"if",
"(",
"$",
"changeOwner",
")",
"{",
"$",
"chown",
"=",
"$",
"this",
"->",
"getChownCommand",
"(",
"$",
"chownPath",
",",
"$",
"isSudo",
",",
"false",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"chown",
")",
")",
"{",
"$",
"commands",
"[",
"]",
"=",
"$",
"chown",
";",
"}",
"}",
"return",
"implode",
"(",
"' '",
".",
"$",
"this",
"->",
"combineOperator",
".",
"' '",
",",
"$",
"commands",
")",
".",
"';'",
";",
"}"
] | Get permission commands
@param string | array $path
@param string | array $permissions
@param boolean $isSudo
@param bool $isFile
@return string | [
"Get",
"permission",
"commands"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/install/core/SystemHelper.php#L190-L207 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.getFileList | public function getFileList($path, $recursively = false, $filter = '', $onlyFileType = null, $isReturnSingleArray = false)
{
$path = $this->concatPaths($path);
$result = array();
if (!file_exists($path) || !is_dir($path)) {
return $result;
}
$cdir = scandir($path);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".", "..")))
{
$add = false;
if (is_dir($path . Utils\Util::getSeparator() . $value)) {
if ($recursively || (is_int($recursively) && $recursively!=0) ) {
$nextRecursively = is_int($recursively) ? ($recursively-1) : $recursively;
$result[$value] = $this->getFileList($path . Utils\Util::getSeparator() . $value, $nextRecursively, $filter, $onlyFileType);
}
else if (!isset($onlyFileType) || !$onlyFileType){ /*save only directories*/
$add = true;
}
}
else if (!isset($onlyFileType) || $onlyFileType) { /*save only files*/
$add = true;
}
if ($add) {
if (!empty($filter)) {
if (preg_match('/'.$filter.'/i', $value)) {
$result[] = $value;
}
}
else {
$result[] = $value;
}
}
}
}
if ($isReturnSingleArray) {
return $this->getSingeFileList($result, $onlyFileType, $path);
}
return $result;
} | php | public function getFileList($path, $recursively = false, $filter = '', $onlyFileType = null, $isReturnSingleArray = false)
{
$path = $this->concatPaths($path);
$result = array();
if (!file_exists($path) || !is_dir($path)) {
return $result;
}
$cdir = scandir($path);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".", "..")))
{
$add = false;
if (is_dir($path . Utils\Util::getSeparator() . $value)) {
if ($recursively || (is_int($recursively) && $recursively!=0) ) {
$nextRecursively = is_int($recursively) ? ($recursively-1) : $recursively;
$result[$value] = $this->getFileList($path . Utils\Util::getSeparator() . $value, $nextRecursively, $filter, $onlyFileType);
}
else if (!isset($onlyFileType) || !$onlyFileType){ /*save only directories*/
$add = true;
}
}
else if (!isset($onlyFileType) || $onlyFileType) { /*save only files*/
$add = true;
}
if ($add) {
if (!empty($filter)) {
if (preg_match('/'.$filter.'/i', $value)) {
$result[] = $value;
}
}
else {
$result[] = $value;
}
}
}
}
if ($isReturnSingleArray) {
return $this->getSingeFileList($result, $onlyFileType, $path);
}
return $result;
} | [
"public",
"function",
"getFileList",
"(",
"$",
"path",
",",
"$",
"recursively",
"=",
"false",
",",
"$",
"filter",
"=",
"''",
",",
"$",
"onlyFileType",
"=",
"null",
",",
"$",
"isReturnSingleArray",
"=",
"false",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"concatPaths",
"(",
"$",
"path",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
"||",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"cdir",
"=",
"scandir",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"cdir",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"array",
"(",
"\".\"",
",",
"\"..\"",
")",
")",
")",
"{",
"$",
"add",
"=",
"false",
";",
"if",
"(",
"is_dir",
"(",
"$",
"path",
".",
"Utils",
"\\",
"Util",
"::",
"getSeparator",
"(",
")",
".",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"recursively",
"||",
"(",
"is_int",
"(",
"$",
"recursively",
")",
"&&",
"$",
"recursively",
"!=",
"0",
")",
")",
"{",
"$",
"nextRecursively",
"=",
"is_int",
"(",
"$",
"recursively",
")",
"?",
"(",
"$",
"recursively",
"-",
"1",
")",
":",
"$",
"recursively",
";",
"$",
"result",
"[",
"$",
"value",
"]",
"=",
"$",
"this",
"->",
"getFileList",
"(",
"$",
"path",
".",
"Utils",
"\\",
"Util",
"::",
"getSeparator",
"(",
")",
".",
"$",
"value",
",",
"$",
"nextRecursively",
",",
"$",
"filter",
",",
"$",
"onlyFileType",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isset",
"(",
"$",
"onlyFileType",
")",
"||",
"!",
"$",
"onlyFileType",
")",
"{",
"/*save only directories*/",
"$",
"add",
"=",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"isset",
"(",
"$",
"onlyFileType",
")",
"||",
"$",
"onlyFileType",
")",
"{",
"/*save only files*/",
"$",
"add",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"add",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"filter",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/'",
".",
"$",
"filter",
".",
"'/i'",
",",
"$",
"value",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"isReturnSingleArray",
")",
"{",
"return",
"$",
"this",
"->",
"getSingeFileList",
"(",
"$",
"result",
",",
"$",
"onlyFileType",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get a list of files in specified directory
@param string $path string - Folder path, Ex. myfolder
@param bool | int $recursively - Find files in subfolders
@param string $filter - Filter for files. Use regular expression, Ex. \.json$
@param bool $onlyFileType [null, true, false] - Filter for type of files/directories. If TRUE - returns only file list, if FALSE - only directory list
@param bool $isReturnSingleArray - if need to return a single array of file list
@return array | [
"Get",
"a",
"list",
"of",
"files",
"in",
"specified",
"directory"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L70-L118 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.getSingeFileList | protected function getSingeFileList(array $fileList, $onlyFileType = null, $basePath = null, $parentDirName = '')
{
$singleFileList = array();
foreach($fileList as $dirName => $fileName) {
if (is_array($fileName)) {
$currentDir = Utils\Util::concatPath($parentDirName, $dirName);
if (!isset($onlyFileType) || $onlyFileType == $this->isFile($currentDir, $basePath)) {
$singleFileList[] = $currentDir;
}
$singleFileList = array_merge($singleFileList, $this->getSingeFileList($fileName, $onlyFileType, $basePath, $currentDir));
} else {
$currentFileName = Utils\Util::concatPath($parentDirName, $fileName);
if (!isset($onlyFileType) || $onlyFileType == $this->isFile($currentFileName, $basePath)) {
$singleFileList[] = $currentFileName;
}
}
}
return $singleFileList;
} | php | protected function getSingeFileList(array $fileList, $onlyFileType = null, $basePath = null, $parentDirName = '')
{
$singleFileList = array();
foreach($fileList as $dirName => $fileName) {
if (is_array($fileName)) {
$currentDir = Utils\Util::concatPath($parentDirName, $dirName);
if (!isset($onlyFileType) || $onlyFileType == $this->isFile($currentDir, $basePath)) {
$singleFileList[] = $currentDir;
}
$singleFileList = array_merge($singleFileList, $this->getSingeFileList($fileName, $onlyFileType, $basePath, $currentDir));
} else {
$currentFileName = Utils\Util::concatPath($parentDirName, $fileName);
if (!isset($onlyFileType) || $onlyFileType == $this->isFile($currentFileName, $basePath)) {
$singleFileList[] = $currentFileName;
}
}
}
return $singleFileList;
} | [
"protected",
"function",
"getSingeFileList",
"(",
"array",
"$",
"fileList",
",",
"$",
"onlyFileType",
"=",
"null",
",",
"$",
"basePath",
"=",
"null",
",",
"$",
"parentDirName",
"=",
"''",
")",
"{",
"$",
"singleFileList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fileList",
"as",
"$",
"dirName",
"=>",
"$",
"fileName",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fileName",
")",
")",
"{",
"$",
"currentDir",
"=",
"Utils",
"\\",
"Util",
"::",
"concatPath",
"(",
"$",
"parentDirName",
",",
"$",
"dirName",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"onlyFileType",
")",
"||",
"$",
"onlyFileType",
"==",
"$",
"this",
"->",
"isFile",
"(",
"$",
"currentDir",
",",
"$",
"basePath",
")",
")",
"{",
"$",
"singleFileList",
"[",
"]",
"=",
"$",
"currentDir",
";",
"}",
"$",
"singleFileList",
"=",
"array_merge",
"(",
"$",
"singleFileList",
",",
"$",
"this",
"->",
"getSingeFileList",
"(",
"$",
"fileName",
",",
"$",
"onlyFileType",
",",
"$",
"basePath",
",",
"$",
"currentDir",
")",
")",
";",
"}",
"else",
"{",
"$",
"currentFileName",
"=",
"Utils",
"\\",
"Util",
"::",
"concatPath",
"(",
"$",
"parentDirName",
",",
"$",
"fileName",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"onlyFileType",
")",
"||",
"$",
"onlyFileType",
"==",
"$",
"this",
"->",
"isFile",
"(",
"$",
"currentFileName",
",",
"$",
"basePath",
")",
")",
"{",
"$",
"singleFileList",
"[",
"]",
"=",
"$",
"currentFileName",
";",
"}",
"}",
"}",
"return",
"$",
"singleFileList",
";",
"}"
] | Convert file list to a single array
@param aray $fileList
@param bool $onlyFileType [null, true, false] - Filter for type of files/directories.
@param string $parentDirName
@return aray | [
"Convert",
"file",
"list",
"to",
"a",
"single",
"array"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L129-L153 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.getPhpContents | public function getPhpContents($path)
{
$fullPath = $this->concatPaths($path);
if (file_exists($fullPath) && strtolower(substr($fullPath, -4)) == '.php') {
$phpContents = include($fullPath);
return $phpContents;
}
return false;
} | php | public function getPhpContents($path)
{
$fullPath = $this->concatPaths($path);
if (file_exists($fullPath) && strtolower(substr($fullPath, -4)) == '.php') {
$phpContents = include($fullPath);
return $phpContents;
}
return false;
} | [
"public",
"function",
"getPhpContents",
"(",
"$",
"path",
")",
"{",
"$",
"fullPath",
"=",
"$",
"this",
"->",
"concatPaths",
"(",
"$",
"path",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fullPath",
")",
"&&",
"strtolower",
"(",
"substr",
"(",
"$",
"fullPath",
",",
"-",
"4",
")",
")",
"==",
"'.php'",
")",
"{",
"$",
"phpContents",
"=",
"include",
"(",
"$",
"fullPath",
")",
";",
"return",
"$",
"phpContents",
";",
"}",
"return",
"false",
";",
"}"
] | Get PHP array from PHP file
@param string | array $path
@return array | bool | [
"Get",
"PHP",
"array",
"from",
"PHP",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L178-L188 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.putContents | public function putContents($path, $data, $flags = 0)
{
$fullPath = $this->concatPaths($path); //todo remove after changing the params
if ($this->checkCreateFile($fullPath) === false) {
throw new Error('Permission denied for '. $fullPath);
}
$res = (file_put_contents($fullPath, $data, $flags) !== FALSE);
if ($res && function_exists('opcache_invalidate')) {
@opcache_invalidate($fullPath);
}
return $res;
} | php | public function putContents($path, $data, $flags = 0)
{
$fullPath = $this->concatPaths($path); //todo remove after changing the params
if ($this->checkCreateFile($fullPath) === false) {
throw new Error('Permission denied for '. $fullPath);
}
$res = (file_put_contents($fullPath, $data, $flags) !== FALSE);
if ($res && function_exists('opcache_invalidate')) {
@opcache_invalidate($fullPath);
}
return $res;
} | [
"public",
"function",
"putContents",
"(",
"$",
"path",
",",
"$",
"data",
",",
"$",
"flags",
"=",
"0",
")",
"{",
"$",
"fullPath",
"=",
"$",
"this",
"->",
"concatPaths",
"(",
"$",
"path",
")",
";",
"//todo remove after changing the params",
"if",
"(",
"$",
"this",
"->",
"checkCreateFile",
"(",
"$",
"fullPath",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Permission denied for '",
".",
"$",
"fullPath",
")",
";",
"}",
"$",
"res",
"=",
"(",
"file_put_contents",
"(",
"$",
"fullPath",
",",
"$",
"data",
",",
"$",
"flags",
")",
"!==",
"FALSE",
")",
";",
"if",
"(",
"$",
"res",
"&&",
"function_exists",
"(",
"'opcache_invalidate'",
")",
")",
"{",
"@",
"opcache_invalidate",
"(",
"$",
"fullPath",
")",
";",
"}",
"return",
"$",
"res",
";",
"}"
] | Write data to a file
@param string | array $path
@param mixed $data
@param integer $flags
@return bool | [
"Write",
"data",
"to",
"a",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L199-L213 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.putPhpContents | public function putPhpContents($path, $data, $withObjects = false)
{
return $this->putContents($path, $this->wrapForDataExport($data, $withObjects), LOCK_EX);
} | php | public function putPhpContents($path, $data, $withObjects = false)
{
return $this->putContents($path, $this->wrapForDataExport($data, $withObjects), LOCK_EX);
} | [
"public",
"function",
"putPhpContents",
"(",
"$",
"path",
",",
"$",
"data",
",",
"$",
"withObjects",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"putContents",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"wrapForDataExport",
"(",
"$",
"data",
",",
"$",
"withObjects",
")",
",",
"LOCK_EX",
")",
";",
"}"
] | Save PHP content to file
@param string | array $path
@param string $data
@return bool | [
"Save",
"PHP",
"content",
"to",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L223-L226 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.putContentsJson | public function putContentsJson($path, $data)
{
if (!Utils\Json::isJSON($data)) {
$data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
return $this->putContents($path, $data, LOCK_EX);
} | php | public function putContentsJson($path, $data)
{
if (!Utils\Json::isJSON($data)) {
$data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
return $this->putContents($path, $data, LOCK_EX);
} | [
"public",
"function",
"putContentsJson",
"(",
"$",
"path",
",",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"Utils",
"\\",
"Json",
"::",
"isJSON",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"Utils",
"\\",
"Json",
"::",
"encode",
"(",
"$",
"data",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_UNESCAPED_SLASHES",
")",
";",
"}",
"return",
"$",
"this",
"->",
"putContents",
"(",
"$",
"path",
",",
"$",
"data",
",",
"LOCK_EX",
")",
";",
"}"
] | Save JSON content to file
@param string | array $path
@param string $data
@param integer $flags
@param resource $context
@return bool | [
"Save",
"JSON",
"content",
"to",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L238-L245 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.mergeContents | public function mergeContents($path, $content, $isReturnJson = false, $removeOptions = null, $isPhp = false)
{
if ($isPhp) {
$fileContent = $this->getPhpContents($path);
} else {
$fileContent = $this->getContents($path);
}
$fullPath = $this->concatPaths($path);
if (file_exists($fullPath) && ($fileContent === false || empty($fileContent))) {
throw new Error('FileManager: Failed to read file [' . $fullPath .'].');
}
$savedDataArray = Utils\Json::getArrayData($fileContent);
$newDataArray = Utils\Json::getArrayData($content);
if (isset($removeOptions)) {
$savedDataArray = Utils\Util::unsetInArray($savedDataArray, $removeOptions);
$newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions);
}
$data = Utils\Util::merge($savedDataArray, $newDataArray);
if ($isReturnJson) {
$data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
if ($isPhp) {
return $this->putPhpContents($path, $data);
}
return $this->putContents($path, $data);
} | php | public function mergeContents($path, $content, $isReturnJson = false, $removeOptions = null, $isPhp = false)
{
if ($isPhp) {
$fileContent = $this->getPhpContents($path);
} else {
$fileContent = $this->getContents($path);
}
$fullPath = $this->concatPaths($path);
if (file_exists($fullPath) && ($fileContent === false || empty($fileContent))) {
throw new Error('FileManager: Failed to read file [' . $fullPath .'].');
}
$savedDataArray = Utils\Json::getArrayData($fileContent);
$newDataArray = Utils\Json::getArrayData($content);
if (isset($removeOptions)) {
$savedDataArray = Utils\Util::unsetInArray($savedDataArray, $removeOptions);
$newDataArray = Utils\Util::unsetInArray($newDataArray, $removeOptions);
}
$data = Utils\Util::merge($savedDataArray, $newDataArray);
if ($isReturnJson) {
$data = Utils\Json::encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
if ($isPhp) {
return $this->putPhpContents($path, $data);
}
return $this->putContents($path, $data);
} | [
"public",
"function",
"mergeContents",
"(",
"$",
"path",
",",
"$",
"content",
",",
"$",
"isReturnJson",
"=",
"false",
",",
"$",
"removeOptions",
"=",
"null",
",",
"$",
"isPhp",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isPhp",
")",
"{",
"$",
"fileContent",
"=",
"$",
"this",
"->",
"getPhpContents",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"$",
"fileContent",
"=",
"$",
"this",
"->",
"getContents",
"(",
"$",
"path",
")",
";",
"}",
"$",
"fullPath",
"=",
"$",
"this",
"->",
"concatPaths",
"(",
"$",
"path",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fullPath",
")",
"&&",
"(",
"$",
"fileContent",
"===",
"false",
"||",
"empty",
"(",
"$",
"fileContent",
")",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'FileManager: Failed to read file ['",
".",
"$",
"fullPath",
".",
"'].'",
")",
";",
"}",
"$",
"savedDataArray",
"=",
"Utils",
"\\",
"Json",
"::",
"getArrayData",
"(",
"$",
"fileContent",
")",
";",
"$",
"newDataArray",
"=",
"Utils",
"\\",
"Json",
"::",
"getArrayData",
"(",
"$",
"content",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"removeOptions",
")",
")",
"{",
"$",
"savedDataArray",
"=",
"Utils",
"\\",
"Util",
"::",
"unsetInArray",
"(",
"$",
"savedDataArray",
",",
"$",
"removeOptions",
")",
";",
"$",
"newDataArray",
"=",
"Utils",
"\\",
"Util",
"::",
"unsetInArray",
"(",
"$",
"newDataArray",
",",
"$",
"removeOptions",
")",
";",
"}",
"$",
"data",
"=",
"Utils",
"\\",
"Util",
"::",
"merge",
"(",
"$",
"savedDataArray",
",",
"$",
"newDataArray",
")",
";",
"if",
"(",
"$",
"isReturnJson",
")",
"{",
"$",
"data",
"=",
"Utils",
"\\",
"Json",
"::",
"encode",
"(",
"$",
"data",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_UNESCAPED_SLASHES",
")",
";",
"}",
"if",
"(",
"$",
"isPhp",
")",
"{",
"return",
"$",
"this",
"->",
"putPhpContents",
"(",
"$",
"path",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"this",
"->",
"putContents",
"(",
"$",
"path",
",",
"$",
"data",
")",
";",
"}"
] | Merge file content and save it to a file
@param string | array $path
@param string $content JSON string
@param bool $isReturnJson
@param string | array $removeOptions - List of unset keys from content
@param bool $isPhp - Is merge php files
@return bool | array | [
"Merge",
"file",
"content",
"and",
"save",
"it",
"to",
"a",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L258-L290 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.mergePhpContents | public function mergePhpContents($path, $content, $removeOptions = null)
{
return $this->mergeContents($path, $content, false, $removeOptions, true);
} | php | public function mergePhpContents($path, $content, $removeOptions = null)
{
return $this->mergeContents($path, $content, false, $removeOptions, true);
} | [
"public",
"function",
"mergePhpContents",
"(",
"$",
"path",
",",
"$",
"content",
",",
"$",
"removeOptions",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"mergeContents",
"(",
"$",
"path",
",",
"$",
"content",
",",
"false",
",",
"$",
"removeOptions",
",",
"true",
")",
";",
"}"
] | Merge PHP content and save it to a file
@param string | array $path
@param string $content JSON string
@param string | array $removeOptions - List of unset keys from content
@return bool | [
"Merge",
"PHP",
"content",
"and",
"save",
"it",
"to",
"a",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L300-L303 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.unsetContents | public function unsetContents($path, $unsets, $isJSON = true)
{
$currentData = $this->getContents($path);
if (!isset($currentData) || !$currentData) {
return true;
}
$currentDataArray = Utils\Json::getArrayData($currentData);
$unsettedData = Utils\Util::unsetInArray($currentDataArray, $unsets, true);
if (is_null($unsettedData) || (is_array($unsettedData) && empty($unsettedData))) {
$fullPath = $this->concatPaths($path);
if (!file_exists($fullPath)) {
return true;
}
return $this->unlink($fullPath);
}
if ($isJSON) {
return $this->putContentsJson($path, $unsettedData);
}
return $this->putContents($path, $unsettedData);
} | php | public function unsetContents($path, $unsets, $isJSON = true)
{
$currentData = $this->getContents($path);
if (!isset($currentData) || !$currentData) {
return true;
}
$currentDataArray = Utils\Json::getArrayData($currentData);
$unsettedData = Utils\Util::unsetInArray($currentDataArray, $unsets, true);
if (is_null($unsettedData) || (is_array($unsettedData) && empty($unsettedData))) {
$fullPath = $this->concatPaths($path);
if (!file_exists($fullPath)) {
return true;
}
return $this->unlink($fullPath);
}
if ($isJSON) {
return $this->putContentsJson($path, $unsettedData);
}
return $this->putContents($path, $unsettedData);
} | [
"public",
"function",
"unsetContents",
"(",
"$",
"path",
",",
"$",
"unsets",
",",
"$",
"isJSON",
"=",
"true",
")",
"{",
"$",
"currentData",
"=",
"$",
"this",
"->",
"getContents",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"currentData",
")",
"||",
"!",
"$",
"currentData",
")",
"{",
"return",
"true",
";",
"}",
"$",
"currentDataArray",
"=",
"Utils",
"\\",
"Json",
"::",
"getArrayData",
"(",
"$",
"currentData",
")",
";",
"$",
"unsettedData",
"=",
"Utils",
"\\",
"Util",
"::",
"unsetInArray",
"(",
"$",
"currentDataArray",
",",
"$",
"unsets",
",",
"true",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"unsettedData",
")",
"||",
"(",
"is_array",
"(",
"$",
"unsettedData",
")",
"&&",
"empty",
"(",
"$",
"unsettedData",
")",
")",
")",
"{",
"$",
"fullPath",
"=",
"$",
"this",
"->",
"concatPaths",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fullPath",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"unlink",
"(",
"$",
"fullPath",
")",
";",
"}",
"if",
"(",
"$",
"isJSON",
")",
"{",
"return",
"$",
"this",
"->",
"putContentsJson",
"(",
"$",
"path",
",",
"$",
"unsettedData",
")",
";",
"}",
"return",
"$",
"this",
"->",
"putContents",
"(",
"$",
"path",
",",
"$",
"unsettedData",
")",
";",
"}"
] | Unset some element of content data
@param string | array $path
@param array | string $unsets
@return bool | [
"Unset",
"some",
"element",
"of",
"content",
"data"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L325-L349 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.mkdir | public function mkdir($path, $permission = null, $recursive = false)
{
$fullPath = $this->concatPaths($path);
if (file_exists($fullPath) && is_dir($path)) {
return true;
}
$defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();
if (!isset($permission)) {
$permission = (string) $defaultPermissions['dir'];
$permission = base_convert($permission, 8, 10);
}
try {
$result = mkdir($fullPath, $permission, true);
if (!empty($defaultPermissions['user'])) {
$this->getPermissionUtils()->chown($fullPath);
}
if (!empty($defaultPermissions['group'])) {
$this->getPermissionUtils()->chgrp($fullPath);
}
} catch (\Exception $e) {
$GLOBALS['log']->critical('Permission denied: unable to create the folder on the server - '.$fullPath);
}
return isset($result) ? $result : false;
} | php | public function mkdir($path, $permission = null, $recursive = false)
{
$fullPath = $this->concatPaths($path);
if (file_exists($fullPath) && is_dir($path)) {
return true;
}
$defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();
if (!isset($permission)) {
$permission = (string) $defaultPermissions['dir'];
$permission = base_convert($permission, 8, 10);
}
try {
$result = mkdir($fullPath, $permission, true);
if (!empty($defaultPermissions['user'])) {
$this->getPermissionUtils()->chown($fullPath);
}
if (!empty($defaultPermissions['group'])) {
$this->getPermissionUtils()->chgrp($fullPath);
}
} catch (\Exception $e) {
$GLOBALS['log']->critical('Permission denied: unable to create the folder on the server - '.$fullPath);
}
return isset($result) ? $result : false;
} | [
"public",
"function",
"mkdir",
"(",
"$",
"path",
",",
"$",
"permission",
"=",
"null",
",",
"$",
"recursive",
"=",
"false",
")",
"{",
"$",
"fullPath",
"=",
"$",
"this",
"->",
"concatPaths",
"(",
"$",
"path",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fullPath",
")",
"&&",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"defaultPermissions",
"=",
"$",
"this",
"->",
"getPermissionUtils",
"(",
")",
"->",
"getDefaultPermissions",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"permission",
")",
")",
"{",
"$",
"permission",
"=",
"(",
"string",
")",
"$",
"defaultPermissions",
"[",
"'dir'",
"]",
";",
"$",
"permission",
"=",
"base_convert",
"(",
"$",
"permission",
",",
"8",
",",
"10",
")",
";",
"}",
"try",
"{",
"$",
"result",
"=",
"mkdir",
"(",
"$",
"fullPath",
",",
"$",
"permission",
",",
"true",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"defaultPermissions",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getPermissionUtils",
"(",
")",
"->",
"chown",
"(",
"$",
"fullPath",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"defaultPermissions",
"[",
"'group'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getPermissionUtils",
"(",
")",
"->",
"chgrp",
"(",
"$",
"fullPath",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"GLOBALS",
"[",
"'log'",
"]",
"->",
"critical",
"(",
"'Permission denied: unable to create the folder on the server - '",
".",
"$",
"fullPath",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"result",
")",
"?",
"$",
"result",
":",
"false",
";",
"}"
] | Create a new dir
@param string | array $path
@param int $permission - ex. 0755
@param bool $recursive
@return bool | [
"Create",
"a",
"new",
"dir"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L380-L410 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.checkCreateFile | public function checkCreateFile($filePath)
{
$defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();
if (file_exists($filePath)) {
if (!is_writable($filePath) && !in_array($this->getPermissionUtils()->getCurrentPermission($filePath), array($defaultPermissions['file'], $defaultPermissions['dir']))) {
return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
}
return true;
}
$pathParts = pathinfo($filePath);
if (!file_exists($pathParts['dirname'])) {
$dirPermission = $defaultPermissions['dir'];
$dirPermission = is_string($dirPermission) ? base_convert($dirPermission,8,10) : $dirPermission;
if (!$this->mkdir($pathParts['dirname'], $dirPermission, true)) {
throw new Error('Permission denied: unable to create a folder on the server - ' . $pathParts['dirname']);
}
}
if (touch($filePath)) {
return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
}
return false;
} | php | public function checkCreateFile($filePath)
{
$defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();
if (file_exists($filePath)) {
if (!is_writable($filePath) && !in_array($this->getPermissionUtils()->getCurrentPermission($filePath), array($defaultPermissions['file'], $defaultPermissions['dir']))) {
return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
}
return true;
}
$pathParts = pathinfo($filePath);
if (!file_exists($pathParts['dirname'])) {
$dirPermission = $defaultPermissions['dir'];
$dirPermission = is_string($dirPermission) ? base_convert($dirPermission,8,10) : $dirPermission;
if (!$this->mkdir($pathParts['dirname'], $dirPermission, true)) {
throw new Error('Permission denied: unable to create a folder on the server - ' . $pathParts['dirname']);
}
}
if (touch($filePath)) {
return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
}
return false;
} | [
"public",
"function",
"checkCreateFile",
"(",
"$",
"filePath",
")",
"{",
"$",
"defaultPermissions",
"=",
"$",
"this",
"->",
"getPermissionUtils",
"(",
")",
"->",
"getDefaultPermissions",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"filePath",
")",
"&&",
"!",
"in_array",
"(",
"$",
"this",
"->",
"getPermissionUtils",
"(",
")",
"->",
"getCurrentPermission",
"(",
"$",
"filePath",
")",
",",
"array",
"(",
"$",
"defaultPermissions",
"[",
"'file'",
"]",
",",
"$",
"defaultPermissions",
"[",
"'dir'",
"]",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getPermissionUtils",
"(",
")",
"->",
"setDefaultPermissions",
"(",
"$",
"filePath",
",",
"true",
")",
";",
"}",
"return",
"true",
";",
"}",
"$",
"pathParts",
"=",
"pathinfo",
"(",
"$",
"filePath",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"pathParts",
"[",
"'dirname'",
"]",
")",
")",
"{",
"$",
"dirPermission",
"=",
"$",
"defaultPermissions",
"[",
"'dir'",
"]",
";",
"$",
"dirPermission",
"=",
"is_string",
"(",
"$",
"dirPermission",
")",
"?",
"base_convert",
"(",
"$",
"dirPermission",
",",
"8",
",",
"10",
")",
":",
"$",
"dirPermission",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"mkdir",
"(",
"$",
"pathParts",
"[",
"'dirname'",
"]",
",",
"$",
"dirPermission",
",",
"true",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Permission denied: unable to create a folder on the server - '",
".",
"$",
"pathParts",
"[",
"'dirname'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"touch",
"(",
"$",
"filePath",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getPermissionUtils",
"(",
")",
"->",
"setDefaultPermissions",
"(",
"$",
"filePath",
",",
"true",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Create a new file if not exists with all folders in the path.
@param string $filePath
@return string | [
"Create",
"a",
"new",
"file",
"if",
"not",
"exists",
"with",
"all",
"folders",
"in",
"the",
"path",
"."
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L484-L510 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.removeInDir | public function removeInDir($dirPath, $removeWithDir = false)
{
$fileList = $this->getFileList($dirPath, false);
$result = true;
if (is_array($fileList)) {
foreach ($fileList as $file) {
$fullPath = Utils\Util::concatPath($dirPath, $file);
if (is_dir($fullPath)) {
$result &= $this->removeInDir($fullPath, true);
} else if (file_exists($fullPath)) {
$result &= unlink($fullPath);
}
}
}
if ($removeWithDir && $this->isDirEmpty($dirPath)) {
$result &= $this->rmdir($dirPath);
}
return (bool) $result;
} | php | public function removeInDir($dirPath, $removeWithDir = false)
{
$fileList = $this->getFileList($dirPath, false);
$result = true;
if (is_array($fileList)) {
foreach ($fileList as $file) {
$fullPath = Utils\Util::concatPath($dirPath, $file);
if (is_dir($fullPath)) {
$result &= $this->removeInDir($fullPath, true);
} else if (file_exists($fullPath)) {
$result &= unlink($fullPath);
}
}
}
if ($removeWithDir && $this->isDirEmpty($dirPath)) {
$result &= $this->rmdir($dirPath);
}
return (bool) $result;
} | [
"public",
"function",
"removeInDir",
"(",
"$",
"dirPath",
",",
"$",
"removeWithDir",
"=",
"false",
")",
"{",
"$",
"fileList",
"=",
"$",
"this",
"->",
"getFileList",
"(",
"$",
"dirPath",
",",
"false",
")",
";",
"$",
"result",
"=",
"true",
";",
"if",
"(",
"is_array",
"(",
"$",
"fileList",
")",
")",
"{",
"foreach",
"(",
"$",
"fileList",
"as",
"$",
"file",
")",
"{",
"$",
"fullPath",
"=",
"Utils",
"\\",
"Util",
"::",
"concatPath",
"(",
"$",
"dirPath",
",",
"$",
"file",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"fullPath",
")",
")",
"{",
"$",
"result",
"&=",
"$",
"this",
"->",
"removeInDir",
"(",
"$",
"fullPath",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"file_exists",
"(",
"$",
"fullPath",
")",
")",
"{",
"$",
"result",
"&=",
"unlink",
"(",
"$",
"fullPath",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"removeWithDir",
"&&",
"$",
"this",
"->",
"isDirEmpty",
"(",
"$",
"dirPath",
")",
")",
"{",
"$",
"result",
"&=",
"$",
"this",
"->",
"rmdir",
"(",
"$",
"dirPath",
")",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"result",
";",
"}"
] | Remove all files inside given path
@param string $dirPath - directory path
@param bool $removeWithDir - if remove with directory
@return bool | [
"Remove",
"all",
"files",
"inside",
"given",
"path"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L582-L603 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.removeEmptyDirs | protected function removeEmptyDirs($path)
{
$parentDirName = $this->getParentDirName($path);
$res = true;
if ($this->isDirEmpty($parentDirName)) {
$res &= $this->rmdir($parentDirName);
$res &= $this->removeEmptyDirs($parentDirName);
}
return (bool) $res;
} | php | protected function removeEmptyDirs($path)
{
$parentDirName = $this->getParentDirName($path);
$res = true;
if ($this->isDirEmpty($parentDirName)) {
$res &= $this->rmdir($parentDirName);
$res &= $this->removeEmptyDirs($parentDirName);
}
return (bool) $res;
} | [
"protected",
"function",
"removeEmptyDirs",
"(",
"$",
"path",
")",
"{",
"$",
"parentDirName",
"=",
"$",
"this",
"->",
"getParentDirName",
"(",
"$",
"path",
")",
";",
"$",
"res",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"isDirEmpty",
"(",
"$",
"parentDirName",
")",
")",
"{",
"$",
"res",
"&=",
"$",
"this",
"->",
"rmdir",
"(",
"$",
"parentDirName",
")",
";",
"$",
"res",
"&=",
"$",
"this",
"->",
"removeEmptyDirs",
"(",
"$",
"parentDirName",
")",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"res",
";",
"}"
] | Remove empty parent directories if they are empty
@param string $path
@return bool | [
"Remove",
"empty",
"parent",
"directories",
"if",
"they",
"are",
"empty"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L664-L675 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.isDirEmpty | public function isDirEmpty($path)
{
if (is_dir($path)) {
$fileList = $this->getFileList($path, true);
if (is_array($fileList) && empty($fileList)) {
return true;
}
}
return false;
} | php | public function isDirEmpty($path)
{
if (is_dir($path)) {
$fileList = $this->getFileList($path, true);
if (is_array($fileList) && empty($fileList)) {
return true;
}
}
return false;
} | [
"public",
"function",
"isDirEmpty",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"fileList",
"=",
"$",
"this",
"->",
"getFileList",
"(",
"$",
"path",
",",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"fileList",
")",
"&&",
"empty",
"(",
"$",
"fileList",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if directory is empty
@param string $path
@return boolean | [
"Check",
"if",
"directory",
"is",
"empty"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L725-L736 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.getFileName | public function getFileName($fileName, $ext='')
{
if (empty($ext)) {
$fileName= substr($fileName, 0, strrpos($fileName, '.', -1));
}
else {
if (substr($ext, 0, 1)!='.') {
$ext= '.'.$ext;
}
if (substr($fileName, -(strlen($ext)))==$ext) {
$fileName= substr($fileName, 0, -(strlen($ext)));
}
}
$exFileName = explode('/', Utils\Util::toFormat($fileName, '/'));
return end($exFileName);
} | php | public function getFileName($fileName, $ext='')
{
if (empty($ext)) {
$fileName= substr($fileName, 0, strrpos($fileName, '.', -1));
}
else {
if (substr($ext, 0, 1)!='.') {
$ext= '.'.$ext;
}
if (substr($fileName, -(strlen($ext)))==$ext) {
$fileName= substr($fileName, 0, -(strlen($ext)));
}
}
$exFileName = explode('/', Utils\Util::toFormat($fileName, '/'));
return end($exFileName);
} | [
"public",
"function",
"getFileName",
"(",
"$",
"fileName",
",",
"$",
"ext",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"ext",
")",
")",
"{",
"$",
"fileName",
"=",
"substr",
"(",
"$",
"fileName",
",",
"0",
",",
"strrpos",
"(",
"$",
"fileName",
",",
"'.'",
",",
"-",
"1",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"substr",
"(",
"$",
"ext",
",",
"0",
",",
"1",
")",
"!=",
"'.'",
")",
"{",
"$",
"ext",
"=",
"'.'",
".",
"$",
"ext",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"fileName",
",",
"-",
"(",
"strlen",
"(",
"$",
"ext",
")",
")",
")",
"==",
"$",
"ext",
")",
"{",
"$",
"fileName",
"=",
"substr",
"(",
"$",
"fileName",
",",
"0",
",",
"-",
"(",
"strlen",
"(",
"$",
"ext",
")",
")",
")",
";",
"}",
"}",
"$",
"exFileName",
"=",
"explode",
"(",
"'/'",
",",
"Utils",
"\\",
"Util",
"::",
"toFormat",
"(",
"$",
"fileName",
",",
"'/'",
")",
")",
";",
"return",
"end",
"(",
"$",
"exFileName",
")",
";",
"}"
] | Get a filename without the file extension
@param string $filename
@param string $ext - extension, ex. '.json'
@return array | [
"Get",
"a",
"filename",
"without",
"the",
"file",
"extension"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L746-L764 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.getDirName | public function getDirName($path, $isFullPath = true, $useIsDir = true)
{
$dirName = preg_replace('/\/$/i', '', $path);
$dirName = ($useIsDir && is_dir($dirName)) ? $dirName : pathinfo($dirName, PATHINFO_DIRNAME);
if (!$isFullPath) {
$pieces = explode('/', $dirName);
$dirName = $pieces[count($pieces)-1];
}
return $dirName;
} | php | public function getDirName($path, $isFullPath = true, $useIsDir = true)
{
$dirName = preg_replace('/\/$/i', '', $path);
$dirName = ($useIsDir && is_dir($dirName)) ? $dirName : pathinfo($dirName, PATHINFO_DIRNAME);
if (!$isFullPath) {
$pieces = explode('/', $dirName);
$dirName = $pieces[count($pieces)-1];
}
return $dirName;
} | [
"public",
"function",
"getDirName",
"(",
"$",
"path",
",",
"$",
"isFullPath",
"=",
"true",
",",
"$",
"useIsDir",
"=",
"true",
")",
"{",
"$",
"dirName",
"=",
"preg_replace",
"(",
"'/\\/$/i'",
",",
"''",
",",
"$",
"path",
")",
";",
"$",
"dirName",
"=",
"(",
"$",
"useIsDir",
"&&",
"is_dir",
"(",
"$",
"dirName",
")",
")",
"?",
"$",
"dirName",
":",
"pathinfo",
"(",
"$",
"dirName",
",",
"PATHINFO_DIRNAME",
")",
";",
"if",
"(",
"!",
"$",
"isFullPath",
")",
"{",
"$",
"pieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"dirName",
")",
";",
"$",
"dirName",
"=",
"$",
"pieces",
"[",
"count",
"(",
"$",
"pieces",
")",
"-",
"1",
"]",
";",
"}",
"return",
"$",
"dirName",
";",
"}"
] | Get a directory name from the path
@param string $path
@param bool $isFullPath
@return array | [
"Get",
"a",
"directory",
"name",
"from",
"the",
"path"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L774-L785 | train |
espocrm/espocrm | application/Espo/Core/Utils/File/Manager.php | Manager.wrapForDataExport | public function wrapForDataExport($content, $withObjects = false)
{
if (!isset($content)) {
return false;
}
if (!$withObjects) {
return "<?php\n".
"return " . var_export($content, true) . ";\n".
"?>";
} else {
return "<?php\n".
"return " . $this->varExport($content) . ";\n".
"?>";
}
} | php | public function wrapForDataExport($content, $withObjects = false)
{
if (!isset($content)) {
return false;
}
if (!$withObjects) {
return "<?php\n".
"return " . var_export($content, true) . ";\n".
"?>";
} else {
return "<?php\n".
"return " . $this->varExport($content) . ";\n".
"?>";
}
} | [
"public",
"function",
"wrapForDataExport",
"(",
"$",
"content",
",",
"$",
"withObjects",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"content",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"withObjects",
")",
"{",
"return",
"\"<?php\\n\"",
".",
"\"return \"",
".",
"var_export",
"(",
"$",
"content",
",",
"true",
")",
".",
"\";\\n\"",
".",
"\"?>\"",
";",
"}",
"else",
"{",
"return",
"\"<?php\\n\"",
".",
"\"return \"",
".",
"$",
"this",
"->",
"varExport",
"(",
"$",
"content",
")",
".",
"\";\\n\"",
".",
"\"?>\"",
";",
"}",
"}"
] | Return content of PHP file
@param string $varName - name of variable which contains the content
@param array $content
@return string | false | [
"Return",
"content",
"of",
"PHP",
"file"
] | 698f70a3586391143a65ca58c4aecfeec71128d2 | https://github.com/espocrm/espocrm/blob/698f70a3586391143a65ca58c4aecfeec71128d2/application/Espo/Core/Utils/File/Manager.php#L807-L822 | train |
santigarcor/laratrust | src/Helper.php | Helper.getIdFor | public static function getIdFor($object, $type)
{
if (is_null($object)) {
return null;
} elseif (is_object($object)) {
return $object->getKey();
} elseif (is_array($object)) {
return $object['id'];
} elseif (is_numeric($object)) {
return $object;
} elseif (is_string($object)) {
return call_user_func_array([
Config::get("laratrust.models.{$type}"), 'where'
], ['name', $object])->firstOrFail()->getKey();
}
throw new InvalidArgumentException(
'getIdFor function only accepts an integer, a Model object or an array with an "id" key'
);
} | php | public static function getIdFor($object, $type)
{
if (is_null($object)) {
return null;
} elseif (is_object($object)) {
return $object->getKey();
} elseif (is_array($object)) {
return $object['id'];
} elseif (is_numeric($object)) {
return $object;
} elseif (is_string($object)) {
return call_user_func_array([
Config::get("laratrust.models.{$type}"), 'where'
], ['name', $object])->firstOrFail()->getKey();
}
throw new InvalidArgumentException(
'getIdFor function only accepts an integer, a Model object or an array with an "id" key'
);
} | [
"public",
"static",
"function",
"getIdFor",
"(",
"$",
"object",
",",
"$",
"type",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"object",
")",
")",
"{",
"return",
"null",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"return",
"$",
"object",
"->",
"getKey",
"(",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"object",
")",
")",
"{",
"return",
"$",
"object",
"[",
"'id'",
"]",
";",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"object",
")",
")",
"{",
"return",
"$",
"object",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"object",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"[",
"Config",
"::",
"get",
"(",
"\"laratrust.models.{$type}\"",
")",
",",
"'where'",
"]",
",",
"[",
"'name'",
",",
"$",
"object",
"]",
")",
"->",
"firstOrFail",
"(",
")",
"->",
"getKey",
"(",
")",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'getIdFor function only accepts an integer, a Model object or an array with an \"id\" key'",
")",
";",
"}"
] | Gets the it from an array, object or integer.
@param mixed $object
@param string $type
@return int | [
"Gets",
"the",
"it",
"from",
"an",
"array",
"object",
"or",
"integer",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Helper.php#L19-L38 | train |
santigarcor/laratrust | src/Helper.php | Helper.fetchTeam | public static function fetchTeam($team = null)
{
if (is_null($team) || !Config::get('laratrust.use_teams')) {
return null;
}
return static::getIdFor($team, 'team');
} | php | public static function fetchTeam($team = null)
{
if (is_null($team) || !Config::get('laratrust.use_teams')) {
return null;
}
return static::getIdFor($team, 'team');
} | [
"public",
"static",
"function",
"fetchTeam",
"(",
"$",
"team",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"team",
")",
"||",
"!",
"Config",
"::",
"get",
"(",
"'laratrust.use_teams'",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"static",
"::",
"getIdFor",
"(",
"$",
"team",
",",
"'team'",
")",
";",
"}"
] | Fetch the team model from the name.
@param mixed $team
@return mixed | [
"Fetch",
"the",
"team",
"model",
"from",
"the",
"name",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Helper.php#L67-L74 | train |
santigarcor/laratrust | src/Helper.php | Helper.assignRealValuesTo | public static function assignRealValuesTo($team, $requireAllOrOptions, $method)
{
return [
($method($team) ? null : $team),
($method($team) ? $team : $requireAllOrOptions),
];
} | php | public static function assignRealValuesTo($team, $requireAllOrOptions, $method)
{
return [
($method($team) ? null : $team),
($method($team) ? $team : $requireAllOrOptions),
];
} | [
"public",
"static",
"function",
"assignRealValuesTo",
"(",
"$",
"team",
",",
"$",
"requireAllOrOptions",
",",
"$",
"method",
")",
"{",
"return",
"[",
"(",
"$",
"method",
"(",
"$",
"team",
")",
"?",
"null",
":",
"$",
"team",
")",
",",
"(",
"$",
"method",
"(",
"$",
"team",
")",
"?",
"$",
"team",
":",
"$",
"requireAllOrOptions",
")",
",",
"]",
";",
"}"
] | Assing the real values to the team and requireAllOrOptions parameters.
@param mixed $team
@param mixed $requireAllOrOptions
@return array | [
"Assing",
"the",
"real",
"values",
"to",
"the",
"team",
"and",
"requireAllOrOptions",
"parameters",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Helper.php#L83-L89 | train |
santigarcor/laratrust | src/Helper.php | Helper.standardize | public static function standardize($value, $toArray = false)
{
if (is_array($value) || ((strpos($value, '|') === false) && !$toArray)) {
return $value;
}
return explode('|', $value);
} | php | public static function standardize($value, $toArray = false)
{
if (is_array($value) || ((strpos($value, '|') === false) && !$toArray)) {
return $value;
}
return explode('|', $value);
} | [
"public",
"static",
"function",
"standardize",
"(",
"$",
"value",
",",
"$",
"toArray",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"||",
"(",
"(",
"strpos",
"(",
"$",
"value",
",",
"'|'",
")",
"===",
"false",
")",
"&&",
"!",
"$",
"toArray",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"explode",
"(",
"'|'",
",",
"$",
"value",
")",
";",
"}"
] | Checks if the string passed contains a pipe '|' and explodes the string to an array.
@param string|array $value
@return string|array | [
"Checks",
"if",
"the",
"string",
"passed",
"contains",
"a",
"pipe",
"|",
"and",
"explodes",
"the",
"string",
"to",
"an",
"array",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Helper.php#L96-L103 | train |
santigarcor/laratrust | src/Helper.php | Helper.isInSameTeam | public static function isInSameTeam($rolePermission, $team)
{
if (
!Config::get('laratrust.use_teams')
|| (!Config::get('laratrust.teams_strict_check') && is_null($team))
) {
return true;
}
$teamForeignKey = static::teamForeignKey();
return $rolePermission['pivot'][$teamForeignKey] == $team;
} | php | public static function isInSameTeam($rolePermission, $team)
{
if (
!Config::get('laratrust.use_teams')
|| (!Config::get('laratrust.teams_strict_check') && is_null($team))
) {
return true;
}
$teamForeignKey = static::teamForeignKey();
return $rolePermission['pivot'][$teamForeignKey] == $team;
} | [
"public",
"static",
"function",
"isInSameTeam",
"(",
"$",
"rolePermission",
",",
"$",
"team",
")",
"{",
"if",
"(",
"!",
"Config",
"::",
"get",
"(",
"'laratrust.use_teams'",
")",
"||",
"(",
"!",
"Config",
"::",
"get",
"(",
"'laratrust.teams_strict_check'",
")",
"&&",
"is_null",
"(",
"$",
"team",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"teamForeignKey",
"=",
"static",
"::",
"teamForeignKey",
"(",
")",
";",
"return",
"$",
"rolePermission",
"[",
"'pivot'",
"]",
"[",
"$",
"teamForeignKey",
"]",
"==",
"$",
"team",
";",
"}"
] | Check if a role or permission is attach to the user in a same team.
@param mixed $rolePermission
@param \Illuminate\Database\Eloquent\Model $team
@return boolean | [
"Check",
"if",
"a",
"role",
"or",
"permission",
"is",
"attach",
"to",
"the",
"user",
"in",
"a",
"same",
"team",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Helper.php#L112-L124 | train |
santigarcor/laratrust | src/Helper.php | Helper.checkOrSet | public static function checkOrSet($option, $array, $possibleValues)
{
if (!isset($array[$option])) {
$array[$option] = $possibleValues[0];
return $array;
}
$ignoredOptions = ['team', 'foreignKeyName'];
if (!in_array($option, $ignoredOptions) && !in_array($array[$option], $possibleValues, true)) {
throw new InvalidArgumentException();
}
return $array;
} | php | public static function checkOrSet($option, $array, $possibleValues)
{
if (!isset($array[$option])) {
$array[$option] = $possibleValues[0];
return $array;
}
$ignoredOptions = ['team', 'foreignKeyName'];
if (!in_array($option, $ignoredOptions) && !in_array($array[$option], $possibleValues, true)) {
throw new InvalidArgumentException();
}
return $array;
} | [
"public",
"static",
"function",
"checkOrSet",
"(",
"$",
"option",
",",
"$",
"array",
",",
"$",
"possibleValues",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"option",
"]",
")",
")",
"{",
"$",
"array",
"[",
"$",
"option",
"]",
"=",
"$",
"possibleValues",
"[",
"0",
"]",
";",
"return",
"$",
"array",
";",
"}",
"$",
"ignoredOptions",
"=",
"[",
"'team'",
",",
"'foreignKeyName'",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"option",
",",
"$",
"ignoredOptions",
")",
"&&",
"!",
"in_array",
"(",
"$",
"array",
"[",
"$",
"option",
"]",
",",
"$",
"possibleValues",
",",
"true",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Checks if the option exists inside the array,
otherwise, it sets the first option inside the default values array.
@param string $option
@param array $array
@param array $possibleValues
@return array | [
"Checks",
"if",
"the",
"option",
"exists",
"inside",
"the",
"array",
"otherwise",
"it",
"sets",
"the",
"first",
"option",
"inside",
"the",
"default",
"values",
"array",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Helper.php#L135-L150 | train |
santigarcor/laratrust | src/Helper.php | Helper.hidrateModel | public static function hidrateModel($class, $data)
{
if ($data instanceof Model) {
return $data;
}
if (!isset($data['pivot'])) {
throw new \Exception("The 'pivot' attribute in the {$class} is hidden");
}
$model = new $class;
$primaryKey = $model->getKeyName();
$model->setAttribute($primaryKey, $data[$primaryKey])->setAttribute('name', $data['name']);
$model->setRelation(
'pivot',
MorphPivot::fromRawAttributes($model, $data['pivot'], 'pivot_table')
);
return $model;
} | php | public static function hidrateModel($class, $data)
{
if ($data instanceof Model) {
return $data;
}
if (!isset($data['pivot'])) {
throw new \Exception("The 'pivot' attribute in the {$class} is hidden");
}
$model = new $class;
$primaryKey = $model->getKeyName();
$model->setAttribute($primaryKey, $data[$primaryKey])->setAttribute('name', $data['name']);
$model->setRelation(
'pivot',
MorphPivot::fromRawAttributes($model, $data['pivot'], 'pivot_table')
);
return $model;
} | [
"public",
"static",
"function",
"hidrateModel",
"(",
"$",
"class",
",",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"instanceof",
"Model",
")",
"{",
"return",
"$",
"data",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'pivot'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"The 'pivot' attribute in the {$class} is hidden\"",
")",
";",
"}",
"$",
"model",
"=",
"new",
"$",
"class",
";",
"$",
"primaryKey",
"=",
"$",
"model",
"->",
"getKeyName",
"(",
")",
";",
"$",
"model",
"->",
"setAttribute",
"(",
"$",
"primaryKey",
",",
"$",
"data",
"[",
"$",
"primaryKey",
"]",
")",
"->",
"setAttribute",
"(",
"'name'",
",",
"$",
"data",
"[",
"'name'",
"]",
")",
";",
"$",
"model",
"->",
"setRelation",
"(",
"'pivot'",
",",
"MorphPivot",
"::",
"fromRawAttributes",
"(",
"$",
"model",
",",
"$",
"data",
"[",
"'pivot'",
"]",
",",
"'pivot_table'",
")",
")",
";",
"return",
"$",
"model",
";",
"}"
] | Creates a model from an array filled with the class data.
@param string $class
@param string|\Illuminate\Database\Eloquent\Model $data
@return \Illuminate\Database\Eloquent\Model | [
"Creates",
"a",
"model",
"from",
"an",
"array",
"filled",
"with",
"the",
"class",
"data",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Helper.php#L159-L179 | train |
santigarcor/laratrust | src/Helper.php | Helper.getPermissionWithAndWithoutWildcards | public static function getPermissionWithAndWithoutWildcards($permissions)
{
$wildcard = [];
$noWildcard = [];
foreach ($permissions as $permission) {
if (strpos($permission, '*') === false) {
$noWildcard[] = $permission;
} else {
$wildcard[] = str_replace('*', '%', $permission);
}
}
return [$wildcard, $noWildcard];
} | php | public static function getPermissionWithAndWithoutWildcards($permissions)
{
$wildcard = [];
$noWildcard = [];
foreach ($permissions as $permission) {
if (strpos($permission, '*') === false) {
$noWildcard[] = $permission;
} else {
$wildcard[] = str_replace('*', '%', $permission);
}
}
return [$wildcard, $noWildcard];
} | [
"public",
"static",
"function",
"getPermissionWithAndWithoutWildcards",
"(",
"$",
"permissions",
")",
"{",
"$",
"wildcard",
"=",
"[",
"]",
";",
"$",
"noWildcard",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"permission",
",",
"'*'",
")",
"===",
"false",
")",
"{",
"$",
"noWildcard",
"[",
"]",
"=",
"$",
"permission",
";",
"}",
"else",
"{",
"$",
"wildcard",
"[",
"]",
"=",
"str_replace",
"(",
"'*'",
",",
"'%'",
",",
"$",
"permission",
")",
";",
"}",
"}",
"return",
"[",
"$",
"wildcard",
",",
"$",
"noWildcard",
"]",
";",
"}"
] | Return two arrays with the filtered permissions between the permissions
with wildcard and the permissions without it.
@param array $permissions
@return array [$wildcard, $noWildcard] | [
"Return",
"two",
"arrays",
"with",
"the",
"filtered",
"permissions",
"between",
"the",
"permissions",
"with",
"wildcard",
"and",
"the",
"permissions",
"without",
"it",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Helper.php#L188-L202 | train |
santigarcor/laratrust | src/Traits/LaratrustRoleTrait.php | LaratrustRoleTrait.bootLaratrustRoleTrait | public static function bootLaratrustRoleTrait()
{
$flushCache = function ($role) {
$role->flushCache();
};
// If the role doesn't use SoftDeletes.
if (method_exists(static::class, 'restored')) {
static::restored($flushCache);
}
static::deleted($flushCache);
static::saved($flushCache);
static::deleting(function ($role) {
if (method_exists($role, 'bootSoftDeletes') && !$role->forceDeleting) {
return;
}
$role->permissions()->sync([]);
foreach (array_keys(Config::get('laratrust.user_models')) as $key) {
$role->$key()->sync([]);
}
});
} | php | public static function bootLaratrustRoleTrait()
{
$flushCache = function ($role) {
$role->flushCache();
};
// If the role doesn't use SoftDeletes.
if (method_exists(static::class, 'restored')) {
static::restored($flushCache);
}
static::deleted($flushCache);
static::saved($flushCache);
static::deleting(function ($role) {
if (method_exists($role, 'bootSoftDeletes') && !$role->forceDeleting) {
return;
}
$role->permissions()->sync([]);
foreach (array_keys(Config::get('laratrust.user_models')) as $key) {
$role->$key()->sync([]);
}
});
} | [
"public",
"static",
"function",
"bootLaratrustRoleTrait",
"(",
")",
"{",
"$",
"flushCache",
"=",
"function",
"(",
"$",
"role",
")",
"{",
"$",
"role",
"->",
"flushCache",
"(",
")",
";",
"}",
";",
"// If the role doesn't use SoftDeletes.",
"if",
"(",
"method_exists",
"(",
"static",
"::",
"class",
",",
"'restored'",
")",
")",
"{",
"static",
"::",
"restored",
"(",
"$",
"flushCache",
")",
";",
"}",
"static",
"::",
"deleted",
"(",
"$",
"flushCache",
")",
";",
"static",
"::",
"saved",
"(",
"$",
"flushCache",
")",
";",
"static",
"::",
"deleting",
"(",
"function",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"role",
",",
"'bootSoftDeletes'",
")",
"&&",
"!",
"$",
"role",
"->",
"forceDeleting",
")",
"{",
"return",
";",
"}",
"$",
"role",
"->",
"permissions",
"(",
")",
"->",
"sync",
"(",
"[",
"]",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.user_models'",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"role",
"->",
"$",
"key",
"(",
")",
"->",
"sync",
"(",
"[",
"]",
")",
";",
"}",
"}",
")",
";",
"}"
] | Boots the role model and attaches event listener to
remove the many-to-many records when trying to delete.
Will NOT delete any records if the role model uses soft deletes.
@return void|bool | [
"Boots",
"the",
"role",
"model",
"and",
"attaches",
"event",
"listener",
"to",
"remove",
"the",
"many",
"-",
"to",
"-",
"many",
"records",
"when",
"trying",
"to",
"delete",
".",
"Will",
"NOT",
"delete",
"any",
"records",
"if",
"the",
"role",
"model",
"uses",
"soft",
"deletes",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustRoleTrait.php#L29-L54 | train |
santigarcor/laratrust | src/Traits/LaratrustRoleTrait.php | LaratrustRoleTrait.permissions | public function permissions()
{
return $this->belongsToMany(
Config::get('laratrust.models.permission'),
Config::get('laratrust.tables.permission_role'),
Config::get('laratrust.foreign_keys.role'),
Config::get('laratrust.foreign_keys.permission')
);
} | php | public function permissions()
{
return $this->belongsToMany(
Config::get('laratrust.models.permission'),
Config::get('laratrust.tables.permission_role'),
Config::get('laratrust.foreign_keys.role'),
Config::get('laratrust.foreign_keys.permission')
);
} | [
"public",
"function",
"permissions",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"belongsToMany",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.models.permission'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.tables.permission_role'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.role'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.permission'",
")",
")",
";",
"}"
] | Many-to-Many relations with the permission model.
@return \Illuminate\Database\Eloquent\Relations\BelongsToMany | [
"Many",
"-",
"to",
"-",
"Many",
"relations",
"with",
"the",
"permission",
"model",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustRoleTrait.php#L88-L96 | train |
santigarcor/laratrust | src/Traits/LaratrustRoleTrait.php | LaratrustRoleTrait.detachPermissions | public function detachPermissions($permissions = null)
{
if (!$permissions) {
$permissions = $this->permissions()->get();
}
foreach ($permissions as $permission) {
$this->detachPermission($permission);
}
return $this;
} | php | public function detachPermissions($permissions = null)
{
if (!$permissions) {
$permissions = $this->permissions()->get();
}
foreach ($permissions as $permission) {
$this->detachPermission($permission);
}
return $this;
} | [
"public",
"function",
"detachPermissions",
"(",
"$",
"permissions",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"permissions",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"permissions",
"(",
")",
"->",
"get",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"$",
"this",
"->",
"detachPermission",
"(",
"$",
"permission",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Detach multiple permissions from current role
@param mixed $permissions
@return void | [
"Detach",
"multiple",
"permissions",
"from",
"current",
"role"
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustRoleTrait.php#L187-L198 | train |
santigarcor/laratrust | src/Traits/LaratrustTeamTrait.php | LaratrustTeamTrait.bootLaratrustTeamTrait | public static function bootLaratrustTeamTrait()
{
static::deleting(function ($team) {
if (method_exists($team, 'bootSoftDeletes') && !$team->forceDeleting) {
return;
}
foreach (array_keys(Config::get('laratrust.user_models')) as $key) {
$team->$key()->sync([]);
}
});
} | php | public static function bootLaratrustTeamTrait()
{
static::deleting(function ($team) {
if (method_exists($team, 'bootSoftDeletes') && !$team->forceDeleting) {
return;
}
foreach (array_keys(Config::get('laratrust.user_models')) as $key) {
$team->$key()->sync([]);
}
});
} | [
"public",
"static",
"function",
"bootLaratrustTeamTrait",
"(",
")",
"{",
"static",
"::",
"deleting",
"(",
"function",
"(",
"$",
"team",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"team",
",",
"'bootSoftDeletes'",
")",
"&&",
"!",
"$",
"team",
"->",
"forceDeleting",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.user_models'",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"team",
"->",
"$",
"key",
"(",
")",
"->",
"sync",
"(",
"[",
"]",
")",
";",
"}",
"}",
")",
";",
"}"
] | Boots the team model and attaches event listener to
remove the many-to-many records when trying to delete.
Will NOT delete any records if the team model uses soft deletes.
@return void|bool | [
"Boots",
"the",
"team",
"model",
"and",
"attaches",
"event",
"listener",
"to",
"remove",
"the",
"many",
"-",
"to",
"-",
"many",
"records",
"when",
"trying",
"to",
"delete",
".",
"Will",
"NOT",
"delete",
"any",
"records",
"if",
"the",
"team",
"model",
"uses",
"soft",
"deletes",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustTeamTrait.php#L42-L53 | train |
santigarcor/laratrust | src/Laratrust.php | Laratrust.hasRole | public function hasRole($role, $team = null, $requireAll = false)
{
if ($user = $this->user()) {
return $user->hasRole($role, $team, $requireAll);
}
return false;
} | php | public function hasRole($role, $team = null, $requireAll = false)
{
if ($user = $this->user()) {
return $user->hasRole($role, $team, $requireAll);
}
return false;
} | [
"public",
"function",
"hasRole",
"(",
"$",
"role",
",",
"$",
"team",
"=",
"null",
",",
"$",
"requireAll",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"user",
"=",
"$",
"this",
"->",
"user",
"(",
")",
")",
"{",
"return",
"$",
"user",
"->",
"hasRole",
"(",
"$",
"role",
",",
"$",
"team",
",",
"$",
"requireAll",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if the current user has a role by its name.
@param string $role Role name.
@return bool | [
"Checks",
"if",
"the",
"current",
"user",
"has",
"a",
"role",
"by",
"its",
"name",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Laratrust.php#L38-L45 | train |
santigarcor/laratrust | src/Laratrust.php | Laratrust.ability | public function ability($roles, $permissions, $team = null, $options = [])
{
if ($user = $this->user()) {
return $user->ability($roles, $permissions, $team, $options);
}
return false;
} | php | public function ability($roles, $permissions, $team = null, $options = [])
{
if ($user = $this->user()) {
return $user->ability($roles, $permissions, $team, $options);
}
return false;
} | [
"public",
"function",
"ability",
"(",
"$",
"roles",
",",
"$",
"permissions",
",",
"$",
"team",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"user",
"=",
"$",
"this",
"->",
"user",
"(",
")",
")",
"{",
"return",
"$",
"user",
"->",
"ability",
"(",
"$",
"roles",
",",
"$",
"permissions",
",",
"$",
"team",
",",
"$",
"options",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Check if the current user has a role or permission by its name.
@param array|string $roles The role(s) needed.
@param array|string $permissions The permission(s) needed.
@param array $options The Options.
@return bool | [
"Check",
"if",
"the",
"current",
"user",
"has",
"a",
"role",
"or",
"permission",
"by",
"its",
"name",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Laratrust.php#L70-L77 | train |
santigarcor/laratrust | src/Traits/LaratrustHasScopes.php | LaratrustHasScopes.scopeWherePermissionIs | public function scopeWherePermissionIs($query, $permission = '', $boolean = 'and')
{
$method = $boolean == 'and' ? 'where' : 'orWhere';
return $query->$method(function ($query) use ($permission) {
$query->whereHas('roles.permissions', function ($permissionQuery) use ($permission) {
$permissionQuery->where('name', $permission);
})->orWhereHas('permissions', function ($permissionQuery) use ($permission) {
$permissionQuery->where('name', $permission);
});
});
} | php | public function scopeWherePermissionIs($query, $permission = '', $boolean = 'and')
{
$method = $boolean == 'and' ? 'where' : 'orWhere';
return $query->$method(function ($query) use ($permission) {
$query->whereHas('roles.permissions', function ($permissionQuery) use ($permission) {
$permissionQuery->where('name', $permission);
})->orWhereHas('permissions', function ($permissionQuery) use ($permission) {
$permissionQuery->where('name', $permission);
});
});
} | [
"public",
"function",
"scopeWherePermissionIs",
"(",
"$",
"query",
",",
"$",
"permission",
"=",
"''",
",",
"$",
"boolean",
"=",
"'and'",
")",
"{",
"$",
"method",
"=",
"$",
"boolean",
"==",
"'and'",
"?",
"'where'",
":",
"'orWhere'",
";",
"return",
"$",
"query",
"->",
"$",
"method",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"permission",
")",
"{",
"$",
"query",
"->",
"whereHas",
"(",
"'roles.permissions'",
",",
"function",
"(",
"$",
"permissionQuery",
")",
"use",
"(",
"$",
"permission",
")",
"{",
"$",
"permissionQuery",
"->",
"where",
"(",
"'name'",
",",
"$",
"permission",
")",
";",
"}",
")",
"->",
"orWhereHas",
"(",
"'permissions'",
",",
"function",
"(",
"$",
"permissionQuery",
")",
"use",
"(",
"$",
"permission",
")",
"{",
"$",
"permissionQuery",
"->",
"where",
"(",
"'name'",
",",
"$",
"permission",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | This scope allows to retrieve the users with a specific permission.
@param \Illuminate\Database\Eloquent\Builder $query
@param string $permission
@return \Illuminate\Database\Eloquent\Builder | [
"This",
"scope",
"allows",
"to",
"retrieve",
"the",
"users",
"with",
"a",
"specific",
"permission",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustHasScopes.php#L50-L61 | train |
santigarcor/laratrust | src/Traits/LaratrustHasEvents.php | LaratrustHasEvents.laratrustObserve | public static function laratrustObserve($class)
{
$className = is_string($class) ? $class : get_class($class);
foreach (self::$laratrustObservables as $event) {
if (method_exists($class, $event)) {
static::registerLaratrustEvent(Str::snake($event, '.'), $className.'@'.$event);
}
}
} | php | public static function laratrustObserve($class)
{
$className = is_string($class) ? $class : get_class($class);
foreach (self::$laratrustObservables as $event) {
if (method_exists($class, $event)) {
static::registerLaratrustEvent(Str::snake($event, '.'), $className.'@'.$event);
}
}
} | [
"public",
"static",
"function",
"laratrustObserve",
"(",
"$",
"class",
")",
"{",
"$",
"className",
"=",
"is_string",
"(",
"$",
"class",
")",
"?",
"$",
"class",
":",
"get_class",
"(",
"$",
"class",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"laratrustObservables",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"class",
",",
"$",
"event",
")",
")",
"{",
"static",
"::",
"registerLaratrustEvent",
"(",
"Str",
"::",
"snake",
"(",
"$",
"event",
",",
"'.'",
")",
",",
"$",
"className",
".",
"'@'",
".",
"$",
"event",
")",
";",
"}",
"}",
"}"
] | Register an observer to the Laratrust events.
@param object|string $class
@return void | [
"Register",
"an",
"observer",
"to",
"the",
"Laratrust",
"events",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustHasEvents.php#L24-L33 | train |
santigarcor/laratrust | src/LaratrustServiceProvider.php | LaratrustServiceProvider.registerMiddlewares | protected function registerMiddlewares()
{
if (!$this->app['config']->get('laratrust.middleware.register')) {
return;
}
$router = $this->app['router'];
if (method_exists($router, 'middleware')) {
$registerMethod = 'middleware';
} elseif (method_exists($router, 'aliasMiddleware')) {
$registerMethod = 'aliasMiddleware';
} else {
return;
}
foreach ($this->middlewares as $key => $class) {
$router->$registerMethod($key, $class);
}
} | php | protected function registerMiddlewares()
{
if (!$this->app['config']->get('laratrust.middleware.register')) {
return;
}
$router = $this->app['router'];
if (method_exists($router, 'middleware')) {
$registerMethod = 'middleware';
} elseif (method_exists($router, 'aliasMiddleware')) {
$registerMethod = 'aliasMiddleware';
} else {
return;
}
foreach ($this->middlewares as $key => $class) {
$router->$registerMethod($key, $class);
}
} | [
"protected",
"function",
"registerMiddlewares",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'laratrust.middleware.register'",
")",
")",
"{",
"return",
";",
"}",
"$",
"router",
"=",
"$",
"this",
"->",
"app",
"[",
"'router'",
"]",
";",
"if",
"(",
"method_exists",
"(",
"$",
"router",
",",
"'middleware'",
")",
")",
"{",
"$",
"registerMethod",
"=",
"'middleware'",
";",
"}",
"elseif",
"(",
"method_exists",
"(",
"$",
"router",
",",
"'aliasMiddleware'",
")",
")",
"{",
"$",
"registerMethod",
"=",
"'aliasMiddleware'",
";",
"}",
"else",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"middlewares",
"as",
"$",
"key",
"=>",
"$",
"class",
")",
"{",
"$",
"router",
"->",
"$",
"registerMethod",
"(",
"$",
"key",
",",
"$",
"class",
")",
";",
"}",
"}"
] | Register the middlewares automatically.
@return void | [
"Register",
"the",
"middlewares",
"automatically",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/LaratrustServiceProvider.php#L92-L111 | train |
santigarcor/laratrust | src/Checkers/User/LaratrustUserDefaultChecker.php | LaratrustUserDefaultChecker.userCachedRoles | protected function userCachedRoles()
{
$cacheKey = 'laratrust_roles_for_user_' . $this->user->getKey();
if (!Config::get('laratrust.cache.enabled')) {
return $this->user->roles()->get();
}
return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () {
return $this->user->roles()->get()->toArray();
});
} | php | protected function userCachedRoles()
{
$cacheKey = 'laratrust_roles_for_user_' . $this->user->getKey();
if (!Config::get('laratrust.cache.enabled')) {
return $this->user->roles()->get();
}
return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () {
return $this->user->roles()->get()->toArray();
});
} | [
"protected",
"function",
"userCachedRoles",
"(",
")",
"{",
"$",
"cacheKey",
"=",
"'laratrust_roles_for_user_'",
".",
"$",
"this",
"->",
"user",
"->",
"getKey",
"(",
")",
";",
"if",
"(",
"!",
"Config",
"::",
"get",
"(",
"'laratrust.cache.enabled'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"user",
"->",
"roles",
"(",
")",
"->",
"get",
"(",
")",
";",
"}",
"return",
"Cache",
"::",
"remember",
"(",
"$",
"cacheKey",
",",
"Config",
"::",
"get",
"(",
"'laratrust.cache.expiration_time'",
",",
"60",
")",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"user",
"->",
"roles",
"(",
")",
"->",
"get",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"}",
")",
";",
"}"
] | Tries to return all the cached roles of the user.
If it can't bring the roles from the cache,
it brings them back from the DB.
@param \Illuminate\Database\Eloquent\Model $model
@return \Illuminate\Database\Eloquent\Collection | [
"Tries",
"to",
"return",
"all",
"the",
"cached",
"roles",
"of",
"the",
"user",
".",
"If",
"it",
"can",
"t",
"bring",
"the",
"roles",
"from",
"the",
"cache",
"it",
"brings",
"them",
"back",
"from",
"the",
"DB",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Checkers/User/LaratrustUserDefaultChecker.php#L123-L134 | train |
santigarcor/laratrust | src/Checkers/User/LaratrustUserDefaultChecker.php | LaratrustUserDefaultChecker.userCachedPermissions | public function userCachedPermissions()
{
$cacheKey = 'laratrust_permissions_for_user_' . $this->user->getKey();
if (!Config::get('laratrust.cache.enabled')) {
return $this->user->permissions()->get();
}
return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () {
return $this->user->permissions()->get()->toArray();
});
} | php | public function userCachedPermissions()
{
$cacheKey = 'laratrust_permissions_for_user_' . $this->user->getKey();
if (!Config::get('laratrust.cache.enabled')) {
return $this->user->permissions()->get();
}
return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () {
return $this->user->permissions()->get()->toArray();
});
} | [
"public",
"function",
"userCachedPermissions",
"(",
")",
"{",
"$",
"cacheKey",
"=",
"'laratrust_permissions_for_user_'",
".",
"$",
"this",
"->",
"user",
"->",
"getKey",
"(",
")",
";",
"if",
"(",
"!",
"Config",
"::",
"get",
"(",
"'laratrust.cache.enabled'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"user",
"->",
"permissions",
"(",
")",
"->",
"get",
"(",
")",
";",
"}",
"return",
"Cache",
"::",
"remember",
"(",
"$",
"cacheKey",
",",
"Config",
"::",
"get",
"(",
"'laratrust.cache.expiration_time'",
",",
"60",
")",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"user",
"->",
"permissions",
"(",
")",
"->",
"get",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"}",
")",
";",
"}"
] | Tries to return all the cached permissions of the user
and if it can't bring the permissions from the cache,
it brings them back from the DB.
@return \Illuminate\Database\Eloquent\Collection | [
"Tries",
"to",
"return",
"all",
"the",
"cached",
"permissions",
"of",
"the",
"user",
"and",
"if",
"it",
"can",
"t",
"bring",
"the",
"permissions",
"from",
"the",
"cache",
"it",
"brings",
"them",
"back",
"from",
"the",
"DB",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Checkers/User/LaratrustUserDefaultChecker.php#L143-L154 | train |
santigarcor/laratrust | src/Traits/LaratrustPermissionTrait.php | LaratrustPermissionTrait.bootLaratrustPermissionTrait | public static function bootLaratrustPermissionTrait()
{
static::deleting(function ($permission) {
if (!method_exists(Config::get('laratrust.models.permission'), 'bootSoftDeletes')) {
$permission->roles()->sync([]);
}
});
static::deleting(function ($permission) {
if (method_exists($permission, 'bootSoftDeletes') && !$permission->forceDeleting) {
return;
}
$permission->roles()->sync([]);
foreach (array_keys(Config::get('laratrust.user_models')) as $key) {
$permission->$key()->sync([]);
}
});
} | php | public static function bootLaratrustPermissionTrait()
{
static::deleting(function ($permission) {
if (!method_exists(Config::get('laratrust.models.permission'), 'bootSoftDeletes')) {
$permission->roles()->sync([]);
}
});
static::deleting(function ($permission) {
if (method_exists($permission, 'bootSoftDeletes') && !$permission->forceDeleting) {
return;
}
$permission->roles()->sync([]);
foreach (array_keys(Config::get('laratrust.user_models')) as $key) {
$permission->$key()->sync([]);
}
});
} | [
"public",
"static",
"function",
"bootLaratrustPermissionTrait",
"(",
")",
"{",
"static",
"::",
"deleting",
"(",
"function",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.models.permission'",
")",
",",
"'bootSoftDeletes'",
")",
")",
"{",
"$",
"permission",
"->",
"roles",
"(",
")",
"->",
"sync",
"(",
"[",
"]",
")",
";",
"}",
"}",
")",
";",
"static",
"::",
"deleting",
"(",
"function",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"permission",
",",
"'bootSoftDeletes'",
")",
"&&",
"!",
"$",
"permission",
"->",
"forceDeleting",
")",
"{",
"return",
";",
"}",
"$",
"permission",
"->",
"roles",
"(",
")",
"->",
"sync",
"(",
"[",
"]",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.user_models'",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"permission",
"->",
"$",
"key",
"(",
")",
"->",
"sync",
"(",
"[",
"]",
")",
";",
"}",
"}",
")",
";",
"}"
] | Boots the permission model and attaches event listener to
remove the many-to-many records when trying to delete.
Will NOT delete any records if the permission model uses soft deletes.
@return void|bool | [
"Boots",
"the",
"permission",
"model",
"and",
"attaches",
"event",
"listener",
"to",
"remove",
"the",
"many",
"-",
"to",
"-",
"many",
"records",
"when",
"trying",
"to",
"delete",
".",
"Will",
"NOT",
"delete",
"any",
"records",
"if",
"the",
"permission",
"model",
"uses",
"soft",
"deletes",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustPermissionTrait.php#L25-L44 | train |
santigarcor/laratrust | src/Traits/LaratrustPermissionTrait.php | LaratrustPermissionTrait.roles | public function roles()
{
return $this->belongsToMany(
Config::get('laratrust.models.role'),
Config::get('laratrust.tables.permission_role'),
Config::get('laratrust.foreign_keys.permission'),
Config::get('laratrust.foreign_keys.role')
);
} | php | public function roles()
{
return $this->belongsToMany(
Config::get('laratrust.models.role'),
Config::get('laratrust.tables.permission_role'),
Config::get('laratrust.foreign_keys.permission'),
Config::get('laratrust.foreign_keys.role')
);
} | [
"public",
"function",
"roles",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"belongsToMany",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.models.role'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.tables.permission_role'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.permission'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.role'",
")",
")",
";",
"}"
] | Many-to-Many relations with role model.
@return \Illuminate\Database\Eloquent\Relations\BelongsToMany | [
"Many",
"-",
"to",
"-",
"Many",
"relations",
"with",
"role",
"model",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustPermissionTrait.php#L51-L59 | train |
santigarcor/laratrust | src/Traits/LaratrustPermissionTrait.php | LaratrustPermissionTrait.getMorphByUserRelation | public function getMorphByUserRelation($relationship)
{
return $this->morphedByMany(
Config::get('laratrust.user_models')[$relationship],
'user',
Config::get('laratrust.tables.permission_user'),
Config::get('laratrust.foreign_keys.permission'),
Config::get('laratrust.foreign_keys.user')
);
} | php | public function getMorphByUserRelation($relationship)
{
return $this->morphedByMany(
Config::get('laratrust.user_models')[$relationship],
'user',
Config::get('laratrust.tables.permission_user'),
Config::get('laratrust.foreign_keys.permission'),
Config::get('laratrust.foreign_keys.user')
);
} | [
"public",
"function",
"getMorphByUserRelation",
"(",
"$",
"relationship",
")",
"{",
"return",
"$",
"this",
"->",
"morphedByMany",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.user_models'",
")",
"[",
"$",
"relationship",
"]",
",",
"'user'",
",",
"Config",
"::",
"get",
"(",
"'laratrust.tables.permission_user'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.permission'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.user'",
")",
")",
";",
"}"
] | Morph by Many relationship between the permission and the one of the possible user models.
@param string $relationship
@return \Illuminate\Database\Eloquent\Relations\MorphToMany | [
"Morph",
"by",
"Many",
"relationship",
"between",
"the",
"permission",
"and",
"the",
"one",
"of",
"the",
"possible",
"user",
"models",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustPermissionTrait.php#L67-L76 | train |
santigarcor/laratrust | src/Checkers/Role/LaratrustRoleDefaultChecker.php | LaratrustRoleDefaultChecker.currentRoleCachedPermissions | public function currentRoleCachedPermissions()
{
$cacheKey = 'laratrust_permissions_for_role_' . $this->role->getKey();
if (!Config::get('laratrust.cache.enabled')) {
return $this->role->permissions()->get();
}
return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () {
return $this->role->permissions()->get()->toArray();
});
} | php | public function currentRoleCachedPermissions()
{
$cacheKey = 'laratrust_permissions_for_role_' . $this->role->getKey();
if (!Config::get('laratrust.cache.enabled')) {
return $this->role->permissions()->get();
}
return Cache::remember($cacheKey, Config::get('laratrust.cache.expiration_time', 60), function () {
return $this->role->permissions()->get()->toArray();
});
} | [
"public",
"function",
"currentRoleCachedPermissions",
"(",
")",
"{",
"$",
"cacheKey",
"=",
"'laratrust_permissions_for_role_'",
".",
"$",
"this",
"->",
"role",
"->",
"getKey",
"(",
")",
";",
"if",
"(",
"!",
"Config",
"::",
"get",
"(",
"'laratrust.cache.enabled'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"role",
"->",
"permissions",
"(",
")",
"->",
"get",
"(",
")",
";",
"}",
"return",
"Cache",
"::",
"remember",
"(",
"$",
"cacheKey",
",",
"Config",
"::",
"get",
"(",
"'laratrust.cache.expiration_time'",
",",
"60",
")",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"role",
"->",
"permissions",
"(",
")",
"->",
"get",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"}",
")",
";",
"}"
] | Tries to return all the cached permissions of the role.
If it can't bring the permissions from the cache,
it brings them back from the DB.
@return \Illuminate\Database\Eloquent\Collection | [
"Tries",
"to",
"return",
"all",
"the",
"cached",
"permissions",
"of",
"the",
"role",
".",
"If",
"it",
"can",
"t",
"bring",
"the",
"permissions",
"from",
"the",
"cache",
"it",
"brings",
"them",
"back",
"from",
"the",
"DB",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Checkers/Role/LaratrustRoleDefaultChecker.php#L66-L77 | train |
santigarcor/laratrust | src/LaratrustRegistersBladeDirectives.php | LaratrustRegistersBladeDirectives.handle | public function handle($laravelVersion = '5.3.0')
{
if (version_compare(strtolower($laravelVersion), '5.3.0-dev', '>=')) {
$this->registerWithParenthesis();
} else {
$this->registerWithoutParenthesis();
}
$this->registerClosingDirectives();
} | php | public function handle($laravelVersion = '5.3.0')
{
if (version_compare(strtolower($laravelVersion), '5.3.0-dev', '>=')) {
$this->registerWithParenthesis();
} else {
$this->registerWithoutParenthesis();
}
$this->registerClosingDirectives();
} | [
"public",
"function",
"handle",
"(",
"$",
"laravelVersion",
"=",
"'5.3.0'",
")",
"{",
"if",
"(",
"version_compare",
"(",
"strtolower",
"(",
"$",
"laravelVersion",
")",
",",
"'5.3.0-dev'",
",",
"'>='",
")",
")",
"{",
"$",
"this",
"->",
"registerWithParenthesis",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"registerWithoutParenthesis",
"(",
")",
";",
"}",
"$",
"this",
"->",
"registerClosingDirectives",
"(",
")",
";",
"}"
] | Handles the registration of the blades directives.
@param string $laravelVersion
@return void | [
"Handles",
"the",
"registration",
"of",
"the",
"blades",
"directives",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/LaratrustRegistersBladeDirectives.php#L20-L29 | train |
santigarcor/laratrust | src/LaratrustRegistersBladeDirectives.php | LaratrustRegistersBladeDirectives.registerWithParenthesis | protected function registerWithParenthesis()
{
// Call to Laratrust::hasRole.
Blade::directive('role', function ($expression) {
return "<?php if (app('laratrust')->hasRole({$expression})) : ?>";
});
// Call to Laratrust::can.
Blade::directive('permission', function ($expression) {
return "<?php if (app('laratrust')->can({$expression})) : ?>";
});
// Call to Laratrust::ability.
Blade::directive('ability', function ($expression) {
return "<?php if (app('laratrust')->ability({$expression})) : ?>";
});
// Call to Laratrust::canAndOwns.
Blade::directive('canAndOwns', function ($expression) {
return "<?php if (app('laratrust')->canAndOwns({$expression})) : ?>";
});
// Call to Laratrust::hasRoleAndOwns.
Blade::directive('hasRoleAndOwns', function ($expression) {
return "<?php if (app('laratrust')->hasRoleAndOwns({$expression})) : ?>";
});
} | php | protected function registerWithParenthesis()
{
// Call to Laratrust::hasRole.
Blade::directive('role', function ($expression) {
return "<?php if (app('laratrust')->hasRole({$expression})) : ?>";
});
// Call to Laratrust::can.
Blade::directive('permission', function ($expression) {
return "<?php if (app('laratrust')->can({$expression})) : ?>";
});
// Call to Laratrust::ability.
Blade::directive('ability', function ($expression) {
return "<?php if (app('laratrust')->ability({$expression})) : ?>";
});
// Call to Laratrust::canAndOwns.
Blade::directive('canAndOwns', function ($expression) {
return "<?php if (app('laratrust')->canAndOwns({$expression})) : ?>";
});
// Call to Laratrust::hasRoleAndOwns.
Blade::directive('hasRoleAndOwns', function ($expression) {
return "<?php if (app('laratrust')->hasRoleAndOwns({$expression})) : ?>";
});
} | [
"protected",
"function",
"registerWithParenthesis",
"(",
")",
"{",
"// Call to Laratrust::hasRole.",
"Blade",
"::",
"directive",
"(",
"'role'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->hasRole({$expression})) : ?>\"",
";",
"}",
")",
";",
"// Call to Laratrust::can.",
"Blade",
"::",
"directive",
"(",
"'permission'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->can({$expression})) : ?>\"",
";",
"}",
")",
";",
"// Call to Laratrust::ability.",
"Blade",
"::",
"directive",
"(",
"'ability'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->ability({$expression})) : ?>\"",
";",
"}",
")",
";",
"// Call to Laratrust::canAndOwns.",
"Blade",
"::",
"directive",
"(",
"'canAndOwns'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->canAndOwns({$expression})) : ?>\"",
";",
"}",
")",
";",
"// Call to Laratrust::hasRoleAndOwns.",
"Blade",
"::",
"directive",
"(",
"'hasRoleAndOwns'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->hasRoleAndOwns({$expression})) : ?>\"",
";",
"}",
")",
";",
"}"
] | Registers the directives with parenthesis.
@return void | [
"Registers",
"the",
"directives",
"with",
"parenthesis",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/LaratrustRegistersBladeDirectives.php#L36-L62 | train |
santigarcor/laratrust | src/LaratrustRegistersBladeDirectives.php | LaratrustRegistersBladeDirectives.registerWithoutParenthesis | protected function registerWithoutParenthesis()
{
// Call to Laratrust::hasRole.
Blade::directive('role', function ($expression) {
return "<?php if (app('laratrust')->hasRole{$expression}) : ?>";
});
// Call to Laratrust::can.
Blade::directive('permission', function ($expression) {
return "<?php if (app('laratrust')->can{$expression}) : ?>";
});
// Call to Laratrust::ability.
Blade::directive('ability', function ($expression) {
return "<?php if (app('laratrust')->ability{$expression}) : ?>";
});
// Call to Laratrust::canAndOwns.
Blade::directive('canAndOwns', function ($expression) {
return "<?php if (app('laratrust')->canAndOwns{$expression}) : ?>";
});
// Call to Laratrust::hasRoleAndOwns.
Blade::directive('hasRoleAndOwns', function ($expression) {
return "<?php if (app('laratrust')->hasRoleAndOwns{$expression}) : ?>";
});
} | php | protected function registerWithoutParenthesis()
{
// Call to Laratrust::hasRole.
Blade::directive('role', function ($expression) {
return "<?php if (app('laratrust')->hasRole{$expression}) : ?>";
});
// Call to Laratrust::can.
Blade::directive('permission', function ($expression) {
return "<?php if (app('laratrust')->can{$expression}) : ?>";
});
// Call to Laratrust::ability.
Blade::directive('ability', function ($expression) {
return "<?php if (app('laratrust')->ability{$expression}) : ?>";
});
// Call to Laratrust::canAndOwns.
Blade::directive('canAndOwns', function ($expression) {
return "<?php if (app('laratrust')->canAndOwns{$expression}) : ?>";
});
// Call to Laratrust::hasRoleAndOwns.
Blade::directive('hasRoleAndOwns', function ($expression) {
return "<?php if (app('laratrust')->hasRoleAndOwns{$expression}) : ?>";
});
} | [
"protected",
"function",
"registerWithoutParenthesis",
"(",
")",
"{",
"// Call to Laratrust::hasRole.",
"Blade",
"::",
"directive",
"(",
"'role'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->hasRole{$expression}) : ?>\"",
";",
"}",
")",
";",
"// Call to Laratrust::can.",
"Blade",
"::",
"directive",
"(",
"'permission'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->can{$expression}) : ?>\"",
";",
"}",
")",
";",
"// Call to Laratrust::ability.",
"Blade",
"::",
"directive",
"(",
"'ability'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->ability{$expression}) : ?>\"",
";",
"}",
")",
";",
"// Call to Laratrust::canAndOwns.",
"Blade",
"::",
"directive",
"(",
"'canAndOwns'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->canAndOwns{$expression}) : ?>\"",
";",
"}",
")",
";",
"// Call to Laratrust::hasRoleAndOwns.",
"Blade",
"::",
"directive",
"(",
"'hasRoleAndOwns'",
",",
"function",
"(",
"$",
"expression",
")",
"{",
"return",
"\"<?php if (app('laratrust')->hasRoleAndOwns{$expression}) : ?>\"",
";",
"}",
")",
";",
"}"
] | Registers the directives without parenthesis.
@return void | [
"Registers",
"the",
"directives",
"without",
"parenthesis",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/LaratrustRegistersBladeDirectives.php#L69-L95 | train |
santigarcor/laratrust | src/Middleware/LaratrustMiddleware.php | LaratrustMiddleware.authorization | protected function authorization($type, $rolesPermissions, $team, $options)
{
list($team, $requireAll, $guard) = $this->assignRealValuesTo($team, $options);
$method = $type == 'roles' ? 'hasRole' : 'hasPermission';
if (!is_array($rolesPermissions)) {
$rolesPermissions = explode(self::DELIMITER, $rolesPermissions);
}
return !Auth::guard($guard)->guest()
&& Auth::guard($guard)->user()->$method($rolesPermissions, $team, $requireAll);
} | php | protected function authorization($type, $rolesPermissions, $team, $options)
{
list($team, $requireAll, $guard) = $this->assignRealValuesTo($team, $options);
$method = $type == 'roles' ? 'hasRole' : 'hasPermission';
if (!is_array($rolesPermissions)) {
$rolesPermissions = explode(self::DELIMITER, $rolesPermissions);
}
return !Auth::guard($guard)->guest()
&& Auth::guard($guard)->user()->$method($rolesPermissions, $team, $requireAll);
} | [
"protected",
"function",
"authorization",
"(",
"$",
"type",
",",
"$",
"rolesPermissions",
",",
"$",
"team",
",",
"$",
"options",
")",
"{",
"list",
"(",
"$",
"team",
",",
"$",
"requireAll",
",",
"$",
"guard",
")",
"=",
"$",
"this",
"->",
"assignRealValuesTo",
"(",
"$",
"team",
",",
"$",
"options",
")",
";",
"$",
"method",
"=",
"$",
"type",
"==",
"'roles'",
"?",
"'hasRole'",
":",
"'hasPermission'",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"rolesPermissions",
")",
")",
"{",
"$",
"rolesPermissions",
"=",
"explode",
"(",
"self",
"::",
"DELIMITER",
",",
"$",
"rolesPermissions",
")",
";",
"}",
"return",
"!",
"Auth",
"::",
"guard",
"(",
"$",
"guard",
")",
"->",
"guest",
"(",
")",
"&&",
"Auth",
"::",
"guard",
"(",
"$",
"guard",
")",
"->",
"user",
"(",
")",
"->",
"$",
"method",
"(",
"$",
"rolesPermissions",
",",
"$",
"team",
",",
"$",
"requireAll",
")",
";",
"}"
] | Check if the request has authorization to continue.
@param string $type
@param string $rolesPermissions
@param string|null $team
@param string|null $options
@return boolean | [
"Check",
"if",
"the",
"request",
"has",
"authorization",
"to",
"continue",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Middleware/LaratrustMiddleware.php#L25-L36 | train |
santigarcor/laratrust | src/Middleware/LaratrustMiddleware.php | LaratrustMiddleware.assignRealValuesTo | protected function assignRealValuesTo($team, $options)
{
return [
(Str::contains($team, ['require_all', 'guard:']) ? null : $team),
(Str::contains($team, 'require_all') ?: Str::contains($options, 'require_all')),
(Str::contains($team, 'guard:') ? $this->extractGuard($team) : (
Str::contains($options, 'guard:')
? $this->extractGuard($options)
: Config::get('auth.defaults.guard')
)),
];
} | php | protected function assignRealValuesTo($team, $options)
{
return [
(Str::contains($team, ['require_all', 'guard:']) ? null : $team),
(Str::contains($team, 'require_all') ?: Str::contains($options, 'require_all')),
(Str::contains($team, 'guard:') ? $this->extractGuard($team) : (
Str::contains($options, 'guard:')
? $this->extractGuard($options)
: Config::get('auth.defaults.guard')
)),
];
} | [
"protected",
"function",
"assignRealValuesTo",
"(",
"$",
"team",
",",
"$",
"options",
")",
"{",
"return",
"[",
"(",
"Str",
"::",
"contains",
"(",
"$",
"team",
",",
"[",
"'require_all'",
",",
"'guard:'",
"]",
")",
"?",
"null",
":",
"$",
"team",
")",
",",
"(",
"Str",
"::",
"contains",
"(",
"$",
"team",
",",
"'require_all'",
")",
"?",
":",
"Str",
"::",
"contains",
"(",
"$",
"options",
",",
"'require_all'",
")",
")",
",",
"(",
"Str",
"::",
"contains",
"(",
"$",
"team",
",",
"'guard:'",
")",
"?",
"$",
"this",
"->",
"extractGuard",
"(",
"$",
"team",
")",
":",
"(",
"Str",
"::",
"contains",
"(",
"$",
"options",
",",
"'guard:'",
")",
"?",
"$",
"this",
"->",
"extractGuard",
"(",
"$",
"options",
")",
":",
"Config",
"::",
"get",
"(",
"'auth.defaults.guard'",
")",
")",
")",
",",
"]",
";",
"}"
] | Generate an array with the real values of the parameters given to the middleware.
@param string $team
@param string $options
@return array | [
"Generate",
"an",
"array",
"with",
"the",
"real",
"values",
"of",
"the",
"parameters",
"given",
"to",
"the",
"middleware",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Middleware/LaratrustMiddleware.php#L67-L78 | train |
santigarcor/laratrust | src/Middleware/LaratrustMiddleware.php | LaratrustMiddleware.extractGuard | protected function extractGuard($string)
{
$options = Collection::make(explode('|', $string));
return $options->reject(function ($option) {
return strpos($option, 'guard:') === false;
})->map(function ($option) {
return explode(':', $option)[1];
})->first();
} | php | protected function extractGuard($string)
{
$options = Collection::make(explode('|', $string));
return $options->reject(function ($option) {
return strpos($option, 'guard:') === false;
})->map(function ($option) {
return explode(':', $option)[1];
})->first();
} | [
"protected",
"function",
"extractGuard",
"(",
"$",
"string",
")",
"{",
"$",
"options",
"=",
"Collection",
"::",
"make",
"(",
"explode",
"(",
"'|'",
",",
"$",
"string",
")",
")",
";",
"return",
"$",
"options",
"->",
"reject",
"(",
"function",
"(",
"$",
"option",
")",
"{",
"return",
"strpos",
"(",
"$",
"option",
",",
"'guard:'",
")",
"===",
"false",
";",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"option",
")",
"{",
"return",
"explode",
"(",
"':'",
",",
"$",
"option",
")",
"[",
"1",
"]",
";",
"}",
")",
"->",
"first",
"(",
")",
";",
"}"
] | Extract the guard type from the given string.
@param string $string
@return string | [
"Extract",
"the",
"guard",
"type",
"from",
"the",
"given",
"string",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Middleware/LaratrustMiddleware.php#L86-L95 | train |
santigarcor/laratrust | src/Commands/UpgradeCommand.php | UpgradeCommand.getExistingMigrationsWarning | protected function getExistingMigrationsWarning(array $existingMigrations)
{
if (count($existingMigrations) > 1) {
$base = "Laratrust upgrade migrations already exist.\nFollowing files were found: ";
} else {
$base = "Laratrust upgrade migration already exists.\nFollowing file was found: ";
}
return $base . array_reduce($existingMigrations, function ($carry, $fileName) {
return $carry . "\n - " . $fileName;
});
} | php | protected function getExistingMigrationsWarning(array $existingMigrations)
{
if (count($existingMigrations) > 1) {
$base = "Laratrust upgrade migrations already exist.\nFollowing files were found: ";
} else {
$base = "Laratrust upgrade migration already exists.\nFollowing file was found: ";
}
return $base . array_reduce($existingMigrations, function ($carry, $fileName) {
return $carry . "\n - " . $fileName;
});
} | [
"protected",
"function",
"getExistingMigrationsWarning",
"(",
"array",
"$",
"existingMigrations",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"existingMigrations",
")",
">",
"1",
")",
"{",
"$",
"base",
"=",
"\"Laratrust upgrade migrations already exist.\\nFollowing files were found: \"",
";",
"}",
"else",
"{",
"$",
"base",
"=",
"\"Laratrust upgrade migration already exists.\\nFollowing file was found: \"",
";",
"}",
"return",
"$",
"base",
".",
"array_reduce",
"(",
"$",
"existingMigrations",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"fileName",
")",
"{",
"return",
"$",
"carry",
".",
"\"\\n - \"",
".",
"$",
"fileName",
";",
"}",
")",
";",
"}"
] | Build a warning regarding possible duplication
due to already existing migrations.
@param array $existingMigrations
@return string | [
"Build",
"a",
"warning",
"regarding",
"possible",
"duplication",
"due",
"to",
"already",
"existing",
"migrations",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Commands/UpgradeCommand.php#L113-L124 | train |
santigarcor/laratrust | src/Commands/UpgradeCommand.php | UpgradeCommand.alreadyExistingMigrations | protected function alreadyExistingMigrations()
{
$matchingFiles = glob($this->getMigrationPath('*'));
return array_map(function ($path) {
return basename($path);
}, $matchingFiles);
} | php | protected function alreadyExistingMigrations()
{
$matchingFiles = glob($this->getMigrationPath('*'));
return array_map(function ($path) {
return basename($path);
}, $matchingFiles);
} | [
"protected",
"function",
"alreadyExistingMigrations",
"(",
")",
"{",
"$",
"matchingFiles",
"=",
"glob",
"(",
"$",
"this",
"->",
"getMigrationPath",
"(",
"'*'",
")",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"path",
")",
"{",
"return",
"basename",
"(",
"$",
"path",
")",
";",
"}",
",",
"$",
"matchingFiles",
")",
";",
"}"
] | Check if there is another migration
with the same suffix.
@return array | [
"Check",
"if",
"there",
"is",
"another",
"migration",
"with",
"the",
"same",
"suffix",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Commands/UpgradeCommand.php#L132-L139 | train |
santigarcor/laratrust | src/Commands/MigrationCommand.php | MigrationCommand.generateMigrationMessage | protected function generateMigrationMessage()
{
$tables = Collection::make(Config::get('laratrust.tables'))
->reject(function ($value, $key) {
return $key == 'teams' && !Config::get('laratrust.use_teams');
})
->sort();
return "A migration that creates {$tables->implode(', ')} "
. "tables will be created in database/migrations directory";
} | php | protected function generateMigrationMessage()
{
$tables = Collection::make(Config::get('laratrust.tables'))
->reject(function ($value, $key) {
return $key == 'teams' && !Config::get('laratrust.use_teams');
})
->sort();
return "A migration that creates {$tables->implode(', ')} "
. "tables will be created in database/migrations directory";
} | [
"protected",
"function",
"generateMigrationMessage",
"(",
")",
"{",
"$",
"tables",
"=",
"Collection",
"::",
"make",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.tables'",
")",
")",
"->",
"reject",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"{",
"return",
"$",
"key",
"==",
"'teams'",
"&&",
"!",
"Config",
"::",
"get",
"(",
"'laratrust.use_teams'",
")",
";",
"}",
")",
"->",
"sort",
"(",
")",
";",
"return",
"\"A migration that creates {$tables->implode(', ')} \"",
".",
"\"tables will be created in database/migrations directory\"",
";",
"}"
] | Generate the message to display when running the
console command showing what tables are going
to be created.
@return string | [
"Generate",
"the",
"message",
"to",
"display",
"when",
"running",
"the",
"console",
"command",
"showing",
"what",
"tables",
"are",
"going",
"to",
"be",
"created",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Commands/MigrationCommand.php#L118-L128 | train |
santigarcor/laratrust | src/Commands/MakeSeederCommand.php | MakeSeederCommand.createSeeder | protected function createSeeder()
{
$permission = Config::get('laratrust.models.permission', 'App\Permission');
$role = Config::get('laratrust.models.role', 'App\Role');
$rolePermissions = Config::get('laratrust.tables.permission_role');
$roleUsers = Config::get('laratrust.tables.role_user');
$user = new Collection(Config::get('laratrust.user_models', ['App\User']));
$user = $user->first();
$output = $this->laravel->view->make('laratrust::seeder')
->with(compact([
'role',
'permission',
'user',
'rolePermissions',
'roleUsers',
]))
->render();
if ($fs = fopen($this->seederPath(), 'x')) {
fwrite($fs, $output);
fclose($fs);
return true;
}
return false;
} | php | protected function createSeeder()
{
$permission = Config::get('laratrust.models.permission', 'App\Permission');
$role = Config::get('laratrust.models.role', 'App\Role');
$rolePermissions = Config::get('laratrust.tables.permission_role');
$roleUsers = Config::get('laratrust.tables.role_user');
$user = new Collection(Config::get('laratrust.user_models', ['App\User']));
$user = $user->first();
$output = $this->laravel->view->make('laratrust::seeder')
->with(compact([
'role',
'permission',
'user',
'rolePermissions',
'roleUsers',
]))
->render();
if ($fs = fopen($this->seederPath(), 'x')) {
fwrite($fs, $output);
fclose($fs);
return true;
}
return false;
} | [
"protected",
"function",
"createSeeder",
"(",
")",
"{",
"$",
"permission",
"=",
"Config",
"::",
"get",
"(",
"'laratrust.models.permission'",
",",
"'App\\Permission'",
")",
";",
"$",
"role",
"=",
"Config",
"::",
"get",
"(",
"'laratrust.models.role'",
",",
"'App\\Role'",
")",
";",
"$",
"rolePermissions",
"=",
"Config",
"::",
"get",
"(",
"'laratrust.tables.permission_role'",
")",
";",
"$",
"roleUsers",
"=",
"Config",
"::",
"get",
"(",
"'laratrust.tables.role_user'",
")",
";",
"$",
"user",
"=",
"new",
"Collection",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.user_models'",
",",
"[",
"'App\\User'",
"]",
")",
")",
";",
"$",
"user",
"=",
"$",
"user",
"->",
"first",
"(",
")",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"laravel",
"->",
"view",
"->",
"make",
"(",
"'laratrust::seeder'",
")",
"->",
"with",
"(",
"compact",
"(",
"[",
"'role'",
",",
"'permission'",
",",
"'user'",
",",
"'rolePermissions'",
",",
"'roleUsers'",
",",
"]",
")",
")",
"->",
"render",
"(",
")",
";",
"if",
"(",
"$",
"fs",
"=",
"fopen",
"(",
"$",
"this",
"->",
"seederPath",
"(",
")",
",",
"'x'",
")",
")",
"{",
"fwrite",
"(",
"$",
"fs",
",",
"$",
"output",
")",
";",
"fclose",
"(",
"$",
"fs",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Create the seeder
@return bool | [
"Create",
"the",
"seeder"
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Commands/MakeSeederCommand.php#L66-L92 | train |
santigarcor/laratrust | src/Traits/LaratrustUserTrait.php | LaratrustUserTrait.bootLaratrustUserTrait | public static function bootLaratrustUserTrait()
{
$flushCache = function ($user) {
$user->flushCache();
};
// If the user doesn't use SoftDeletes.
if (method_exists(static::class, 'restored')) {
static::restored($flushCache);
}
static::deleted($flushCache);
static::saved($flushCache);
static::deleting(function ($user) {
if (method_exists($user, 'bootSoftDeletes') && !$user->forceDeleting) {
return;
}
$user->roles()->sync([]);
$user->permissions()->sync([]);
});
} | php | public static function bootLaratrustUserTrait()
{
$flushCache = function ($user) {
$user->flushCache();
};
// If the user doesn't use SoftDeletes.
if (method_exists(static::class, 'restored')) {
static::restored($flushCache);
}
static::deleted($flushCache);
static::saved($flushCache);
static::deleting(function ($user) {
if (method_exists($user, 'bootSoftDeletes') && !$user->forceDeleting) {
return;
}
$user->roles()->sync([]);
$user->permissions()->sync([]);
});
} | [
"public",
"static",
"function",
"bootLaratrustUserTrait",
"(",
")",
"{",
"$",
"flushCache",
"=",
"function",
"(",
"$",
"user",
")",
"{",
"$",
"user",
"->",
"flushCache",
"(",
")",
";",
"}",
";",
"// If the user doesn't use SoftDeletes.",
"if",
"(",
"method_exists",
"(",
"static",
"::",
"class",
",",
"'restored'",
")",
")",
"{",
"static",
"::",
"restored",
"(",
"$",
"flushCache",
")",
";",
"}",
"static",
"::",
"deleted",
"(",
"$",
"flushCache",
")",
";",
"static",
"::",
"saved",
"(",
"$",
"flushCache",
")",
";",
"static",
"::",
"deleting",
"(",
"function",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"user",
",",
"'bootSoftDeletes'",
")",
"&&",
"!",
"$",
"user",
"->",
"forceDeleting",
")",
"{",
"return",
";",
"}",
"$",
"user",
"->",
"roles",
"(",
")",
"->",
"sync",
"(",
"[",
"]",
")",
";",
"$",
"user",
"->",
"permissions",
"(",
")",
"->",
"sync",
"(",
"[",
"]",
")",
";",
"}",
")",
";",
"}"
] | Boots the user model and attaches event listener to
remove the many-to-many records when trying to delete.
Will NOT delete any records if the user model uses soft deletes.
@return void|bool | [
"Boots",
"the",
"user",
"model",
"and",
"attaches",
"event",
"listener",
"to",
"remove",
"the",
"many",
"-",
"to",
"-",
"many",
"records",
"when",
"trying",
"to",
"delete",
".",
"Will",
"NOT",
"delete",
"any",
"records",
"if",
"the",
"user",
"model",
"uses",
"soft",
"deletes",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustUserTrait.php#L31-L53 | train |
santigarcor/laratrust | src/Traits/LaratrustUserTrait.php | LaratrustUserTrait.rolesTeams | public function rolesTeams()
{
if (!Config::get('laratrust.use_teams')) {
return null;
}
return $this->morphToMany(
Config::get('laratrust.models.team'),
'user',
Config::get('laratrust.tables.role_user'),
Config::get('laratrust.foreign_keys.user'),
Config::get('laratrust.foreign_keys.team')
)
->withPivot(Config::get('laratrust.foreign_keys.role'));
} | php | public function rolesTeams()
{
if (!Config::get('laratrust.use_teams')) {
return null;
}
return $this->morphToMany(
Config::get('laratrust.models.team'),
'user',
Config::get('laratrust.tables.role_user'),
Config::get('laratrust.foreign_keys.user'),
Config::get('laratrust.foreign_keys.team')
)
->withPivot(Config::get('laratrust.foreign_keys.role'));
} | [
"public",
"function",
"rolesTeams",
"(",
")",
"{",
"if",
"(",
"!",
"Config",
"::",
"get",
"(",
"'laratrust.use_teams'",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"morphToMany",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.models.team'",
")",
",",
"'user'",
",",
"Config",
"::",
"get",
"(",
"'laratrust.tables.role_user'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.user'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.team'",
")",
")",
"->",
"withPivot",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.role'",
")",
")",
";",
"}"
] | Many-to-Many relations with Team associated through the roles.
@return \Illuminate\Database\Eloquent\Relations\MorphToMany | [
"Many",
"-",
"to",
"-",
"Many",
"relations",
"with",
"Team",
"associated",
"through",
"the",
"roles",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustUserTrait.php#L82-L96 | train |
santigarcor/laratrust | src/Traits/LaratrustUserTrait.php | LaratrustUserTrait.permissions | public function permissions()
{
$permissions = $this->morphToMany(
Config::get('laratrust.models.permission'),
'user',
Config::get('laratrust.tables.permission_user'),
Config::get('laratrust.foreign_keys.user'),
Config::get('laratrust.foreign_keys.permission')
);
if (Config::get('laratrust.use_teams')) {
$permissions->withPivot(Config::get('laratrust.foreign_keys.team'));
}
return $permissions;
} | php | public function permissions()
{
$permissions = $this->morphToMany(
Config::get('laratrust.models.permission'),
'user',
Config::get('laratrust.tables.permission_user'),
Config::get('laratrust.foreign_keys.user'),
Config::get('laratrust.foreign_keys.permission')
);
if (Config::get('laratrust.use_teams')) {
$permissions->withPivot(Config::get('laratrust.foreign_keys.team'));
}
return $permissions;
} | [
"public",
"function",
"permissions",
"(",
")",
"{",
"$",
"permissions",
"=",
"$",
"this",
"->",
"morphToMany",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.models.permission'",
")",
",",
"'user'",
",",
"Config",
"::",
"get",
"(",
"'laratrust.tables.permission_user'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.user'",
")",
",",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.permission'",
")",
")",
";",
"if",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.use_teams'",
")",
")",
"{",
"$",
"permissions",
"->",
"withPivot",
"(",
"Config",
"::",
"get",
"(",
"'laratrust.foreign_keys.team'",
")",
")",
";",
"}",
"return",
"$",
"permissions",
";",
"}"
] | Many-to-Many relations with Permission.
@return \Illuminate\Database\Eloquent\Relations\MorphToMany | [
"Many",
"-",
"to",
"-",
"Many",
"relations",
"with",
"Permission",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustUserTrait.php#L103-L118 | train |
santigarcor/laratrust | src/Traits/LaratrustUserTrait.php | LaratrustUserTrait.attachRoles | public function attachRoles($roles = [], $team = null)
{
foreach ($roles as $role) {
$this->attachRole($role, $team);
}
return $this;
} | php | public function attachRoles($roles = [], $team = null)
{
foreach ($roles as $role) {
$this->attachRole($role, $team);
}
return $this;
} | [
"public",
"function",
"attachRoles",
"(",
"$",
"roles",
"=",
"[",
"]",
",",
"$",
"team",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"$",
"this",
"->",
"attachRole",
"(",
"$",
"role",
",",
"$",
"team",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Attach multiple roles to a user.
@param mixed $roles
@param mixed $team
@return static | [
"Attach",
"multiple",
"roles",
"to",
"a",
"user",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustUserTrait.php#L385-L392 | train |
santigarcor/laratrust | src/Traits/LaratrustUserTrait.php | LaratrustUserTrait.syncRoles | public function syncRoles($roles = [], $team = null, $detaching = true)
{
return $this->syncModels('roles', $roles, $team, $detaching);
} | php | public function syncRoles($roles = [], $team = null, $detaching = true)
{
return $this->syncModels('roles', $roles, $team, $detaching);
} | [
"public",
"function",
"syncRoles",
"(",
"$",
"roles",
"=",
"[",
"]",
",",
"$",
"team",
"=",
"null",
",",
"$",
"detaching",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"syncModels",
"(",
"'roles'",
",",
"$",
"roles",
",",
"$",
"team",
",",
"$",
"detaching",
")",
";",
"}"
] | Sync roles to the user.
@param array $roles
@param mixed $team
@param boolean $detaching
@return static | [
"Sync",
"roles",
"to",
"the",
"user",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustUserTrait.php#L422-L425 | train |
santigarcor/laratrust | src/Traits/LaratrustUserTrait.php | LaratrustUserTrait.attachPermissions | public function attachPermissions($permissions = [], $team = null)
{
foreach ($permissions as $permission) {
$this->attachPermission($permission, $team);
}
return $this;
} | php | public function attachPermissions($permissions = [], $team = null)
{
foreach ($permissions as $permission) {
$this->attachPermission($permission, $team);
}
return $this;
} | [
"public",
"function",
"attachPermissions",
"(",
"$",
"permissions",
"=",
"[",
"]",
",",
"$",
"team",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"$",
"this",
"->",
"attachPermission",
"(",
"$",
"permission",
",",
"$",
"team",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Attach multiple permissions to a user.
@param mixed $permissions
@param mixed $team
@return static | [
"Attach",
"multiple",
"permissions",
"to",
"a",
"user",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustUserTrait.php#L470-L477 | train |
santigarcor/laratrust | src/Traits/LaratrustUserTrait.php | LaratrustUserTrait.syncPermissions | public function syncPermissions($permissions = [], $team = null, $detaching = true)
{
return $this->syncModels('permissions', $permissions, $team, $detaching);
} | php | public function syncPermissions($permissions = [], $team = null, $detaching = true)
{
return $this->syncModels('permissions', $permissions, $team, $detaching);
} | [
"public",
"function",
"syncPermissions",
"(",
"$",
"permissions",
"=",
"[",
"]",
",",
"$",
"team",
"=",
"null",
",",
"$",
"detaching",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"syncModels",
"(",
"'permissions'",
",",
"$",
"permissions",
",",
"$",
"team",
",",
"$",
"detaching",
")",
";",
"}"
] | Sync permissions to the user.
@param array $permissions
@param mixed $team
@param boolean $detaching
@return static | [
"Sync",
"permissions",
"to",
"the",
"user",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustUserTrait.php#L507-L510 | train |
santigarcor/laratrust | src/Traits/LaratrustUserTrait.php | LaratrustUserTrait.allPermissions | public function allPermissions()
{
$roles = $this->roles()->with('permissions')->get();
$roles = $roles->flatMap(function ($role) {
return $role->permissions;
});
return $this->permissions()->get()->merge($roles)->unique('name');
} | php | public function allPermissions()
{
$roles = $this->roles()->with('permissions')->get();
$roles = $roles->flatMap(function ($role) {
return $role->permissions;
});
return $this->permissions()->get()->merge($roles)->unique('name');
} | [
"public",
"function",
"allPermissions",
"(",
")",
"{",
"$",
"roles",
"=",
"$",
"this",
"->",
"roles",
"(",
")",
"->",
"with",
"(",
"'permissions'",
")",
"->",
"get",
"(",
")",
";",
"$",
"roles",
"=",
"$",
"roles",
"->",
"flatMap",
"(",
"function",
"(",
"$",
"role",
")",
"{",
"return",
"$",
"role",
"->",
"permissions",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"permissions",
"(",
")",
"->",
"get",
"(",
")",
"->",
"merge",
"(",
"$",
"roles",
")",
"->",
"unique",
"(",
"'name'",
")",
";",
"}"
] | Return all the user permissions.
@return boolean | [
"Return",
"all",
"the",
"user",
"permissions",
"."
] | 600aa87574e8915c3bb6d10c25d39b985327818a | https://github.com/santigarcor/laratrust/blob/600aa87574e8915c3bb6d10c25d39b985327818a/src/Traits/LaratrustUserTrait.php#L585-L594 | train |
googleads/googleads-php-lib | examples/AdManager/v201811/InventoryService/GetAdUnitHierarchy.php | GetAdUnitHierarchy.buildAndDisplayAdUnitTree | private static function buildAndDisplayAdUnitTree(
AdUnit $root,
array $adUnits
) {
if (is_null($root)) {
print "No root unit found.\n";
return;
}
$treeMap = [];
foreach ($adUnits as $adUnit) {
$parentId = $adUnit->getParentId();
if (!is_null($parentId)) {
if (!array_key_exists($parentId, $treeMap)) {
$treeMap[$parentId] = [];
}
$treeMap[$parentId][] = $adUnit;
}
}
self::displayInventoryTree($root, $treeMap);
} | php | private static function buildAndDisplayAdUnitTree(
AdUnit $root,
array $adUnits
) {
if (is_null($root)) {
print "No root unit found.\n";
return;
}
$treeMap = [];
foreach ($adUnits as $adUnit) {
$parentId = $adUnit->getParentId();
if (!is_null($parentId)) {
if (!array_key_exists($parentId, $treeMap)) {
$treeMap[$parentId] = [];
}
$treeMap[$parentId][] = $adUnit;
}
}
self::displayInventoryTree($root, $treeMap);
} | [
"private",
"static",
"function",
"buildAndDisplayAdUnitTree",
"(",
"AdUnit",
"$",
"root",
",",
"array",
"$",
"adUnits",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"root",
")",
")",
"{",
"print",
"\"No root unit found.\\n\"",
";",
"return",
";",
"}",
"$",
"treeMap",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"adUnits",
"as",
"$",
"adUnit",
")",
"{",
"$",
"parentId",
"=",
"$",
"adUnit",
"->",
"getParentId",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"parentId",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"parentId",
",",
"$",
"treeMap",
")",
")",
"{",
"$",
"treeMap",
"[",
"$",
"parentId",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"treeMap",
"[",
"$",
"parentId",
"]",
"[",
"]",
"=",
"$",
"adUnit",
";",
"}",
"}",
"self",
"::",
"displayInventoryTree",
"(",
"$",
"root",
",",
"$",
"treeMap",
")",
";",
"}"
] | Builds and displays an ad unit tree from ad units underneath
the root ad unit.
@param AdUnit $root the root ad unit to build the tree under
@param AdUnit[] $adUnits the ad units under the root | [
"Builds",
"and",
"displays",
"an",
"ad",
"unit",
"tree",
"from",
"ad",
"units",
"underneath",
"the",
"root",
"ad",
"unit",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdManager/v201811/InventoryService/GetAdUnitHierarchy.php#L117-L142 | train |
googleads/googleads-php-lib | examples/AdManager/v201811/InventoryService/GetAdUnitHierarchy.php | GetAdUnitHierarchy.displayInventoryTreeHelper | private static function displayInventoryTreeHelper(
AdUnit $root,
array $treeMap,
$depth
) {
$rootId = $root->getId();
printf(
"%s%s(%s)%s",
self::generateTab($depth),
$root->getName(),
$rootId,
PHP_EOL
);
if (!array_key_exists($rootId, $treeMap) || empty($treeMap[$rootId])) {
return;
}
foreach ($treeMap[$rootId] as $child) {
self::displayInventoryTreeHelper($child, $treeMap, $depth + 1);
}
} | php | private static function displayInventoryTreeHelper(
AdUnit $root,
array $treeMap,
$depth
) {
$rootId = $root->getId();
printf(
"%s%s(%s)%s",
self::generateTab($depth),
$root->getName(),
$rootId,
PHP_EOL
);
if (!array_key_exists($rootId, $treeMap) || empty($treeMap[$rootId])) {
return;
}
foreach ($treeMap[$rootId] as $child) {
self::displayInventoryTreeHelper($child, $treeMap, $depth + 1);
}
} | [
"private",
"static",
"function",
"displayInventoryTreeHelper",
"(",
"AdUnit",
"$",
"root",
",",
"array",
"$",
"treeMap",
",",
"$",
"depth",
")",
"{",
"$",
"rootId",
"=",
"$",
"root",
"->",
"getId",
"(",
")",
";",
"printf",
"(",
"\"%s%s(%s)%s\"",
",",
"self",
"::",
"generateTab",
"(",
"$",
"depth",
")",
",",
"$",
"root",
"->",
"getName",
"(",
")",
",",
"$",
"rootId",
",",
"PHP_EOL",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"rootId",
",",
"$",
"treeMap",
")",
"||",
"empty",
"(",
"$",
"treeMap",
"[",
"$",
"rootId",
"]",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"treeMap",
"[",
"$",
"rootId",
"]",
"as",
"$",
"child",
")",
"{",
"self",
"::",
"displayInventoryTreeHelper",
"(",
"$",
"child",
",",
"$",
"treeMap",
",",
"$",
"depth",
"+",
"1",
")",
";",
"}",
"}"
] | Helper for displaying inventory units.
@param AdUnit $root the root ad unit to build a subtree
@param array $treeMap associative array mapping each ad unit to its
children
@param int $depth the depth the tree has reached | [
"Helper",
"for",
"displaying",
"inventory",
"units",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdManager/v201811/InventoryService/GetAdUnitHierarchy.php#L164-L186 | train |
googleads/googleads-php-lib | examples/AdManager/v201811/InventoryService/GetAdUnitHierarchy.php | GetAdUnitHierarchy.generateTab | private static function generateTab($depth)
{
$builder = '';
if ($depth > 0) {
$builder .= ' ';
}
for ($i = 1; $i < $depth; $i++) {
$builder .= '| ';
}
$builder .= '+--';
return $builder;
} | php | private static function generateTab($depth)
{
$builder = '';
if ($depth > 0) {
$builder .= ' ';
}
for ($i = 1; $i < $depth; $i++) {
$builder .= '| ';
}
$builder .= '+--';
return $builder;
} | [
"private",
"static",
"function",
"generateTab",
"(",
"$",
"depth",
")",
"{",
"$",
"builder",
"=",
"''",
";",
"if",
"(",
"$",
"depth",
">",
"0",
")",
"{",
"$",
"builder",
".=",
"' '",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"depth",
";",
"$",
"i",
"++",
")",
"{",
"$",
"builder",
".=",
"'| '",
";",
"}",
"$",
"builder",
".=",
"'+--'",
";",
"return",
"$",
"builder",
";",
"}"
] | Generates tabs to represent branching to children.
@param int $depth the depth the tree has reached
@return string the tabs to insert in front of the root unit | [
"Generates",
"tabs",
"to",
"represent",
"branching",
"to",
"children",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdManager/v201811/InventoryService/GetAdUnitHierarchy.php#L194-L209 | train |
googleads/googleads-php-lib | examples/AdWords/v201809/AdvancedOperations/AddGmailAd.php | AddGmailAd.uploadImage | private static function uploadImage(MediaService $mediaService, $url)
{
// Creates an image and upload it to the server.
$image = new Image();
$image->setData(file_get_contents($url));
$image->setType(MediaMediaType::IMAGE);
return $mediaService->upload([$image])[0];
} | php | private static function uploadImage(MediaService $mediaService, $url)
{
// Creates an image and upload it to the server.
$image = new Image();
$image->setData(file_get_contents($url));
$image->setType(MediaMediaType::IMAGE);
return $mediaService->upload([$image])[0];
} | [
"private",
"static",
"function",
"uploadImage",
"(",
"MediaService",
"$",
"mediaService",
",",
"$",
"url",
")",
"{",
"// Creates an image and upload it to the server.",
"$",
"image",
"=",
"new",
"Image",
"(",
")",
";",
"$",
"image",
"->",
"setData",
"(",
"file_get_contents",
"(",
"$",
"url",
")",
")",
";",
"$",
"image",
"->",
"setType",
"(",
"MediaMediaType",
"::",
"IMAGE",
")",
";",
"return",
"$",
"mediaService",
"->",
"upload",
"(",
"[",
"$",
"image",
"]",
")",
"[",
"0",
"]",
";",
"}"
] | Uploads an image to the server.
@param MediaService $mediaService the media service
@param string $url the URL of image to upload
@return Image the uploaded image returned from the server | [
"Uploads",
"an",
"image",
"to",
"the",
"server",
"."
] | d552b800ad53c400b1a50c7852e7ad184245d2ea | https://github.com/googleads/googleads-php-lib/blob/d552b800ad53c400b1a50c7852e7ad184245d2ea/examples/AdWords/v201809/AdvancedOperations/AddGmailAd.php#L122-L130 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.