repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
ondrakoupil/tools | src/Arrays.php | Arrays.filterByKeys | static function filterByKeys($array, $requiredKeys) {
if (is_array($array)) {
return array_intersect_key($array, array_fill_keys($requiredKeys, true));
}
if ($array instanceof \ArrayAccess) {
$ret = array();
foreach ($requiredKeys as $k) {
if (isset($array[$k])) {
$ret[$k] = $array[$k];
}
}
return $ret;
}
throw new \InvalidArgumentException("Argument must be an array or object with ArrayAccess");
} | php | static function filterByKeys($array, $requiredKeys) {
if (is_array($array)) {
return array_intersect_key($array, array_fill_keys($requiredKeys, true));
}
if ($array instanceof \ArrayAccess) {
$ret = array();
foreach ($requiredKeys as $k) {
if (isset($array[$k])) {
$ret[$k] = $array[$k];
}
}
return $ret;
}
throw new \InvalidArgumentException("Argument must be an array or object with ArrayAccess");
} | [
"static",
"function",
"filterByKeys",
"(",
"$",
"array",
",",
"$",
"requiredKeys",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"array_intersect_key",
"(",
"$",
"array",
",",
"array_fill_keys",
"(",
"$",
"requiredKeys",
",",
"true",
")",
")",
";",
"}",
"if",
"(",
"$",
"array",
"instanceof",
"\\",
"ArrayAccess",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"requiredKeys",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"ret",
"[",
"$",
"k",
"]",
"=",
"$",
"array",
"[",
"$",
"k",
"]",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Argument must be an array or object with ArrayAccess\"",
")",
";",
"}"
] | Ze zadaného pole vybere jen ty položky, které mají klíč udaný v druhém poli.
@param array|\ArrayAccess $array Asociativní pole
@param array $requiredKeys Obyčejné pole klíčů
@return array | [
"Ze",
"zadaného",
"pole",
"vybere",
"jen",
"ty",
"položky",
"které",
"mají",
"klíč",
"udaný",
"v",
"druhém",
"poli",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L159-L174 |
ondrakoupil/tools | src/Arrays.php | Arrays.group | static public function group($data,$groupBy,$orderByKey=false) {
$vrat=array();
foreach($data as $index=>$radek) {
if (!isset($radek[$groupBy])) {
$radek[$groupBy]="0";
}
if (!isset($vrat[$radek[$groupBy]])) {
$vrat[$radek[$groupBy]]=array();
}
$vrat[$radek[$groupBy]][$index]=$radek;
}
if ($orderByKey) {
ksort($vrat);
}
if ($orderByKey==="desc") {
$vrat=array_reverse($vrat);
}
return $vrat;
} | php | static public function group($data,$groupBy,$orderByKey=false) {
$vrat=array();
foreach($data as $index=>$radek) {
if (!isset($radek[$groupBy])) {
$radek[$groupBy]="0";
}
if (!isset($vrat[$radek[$groupBy]])) {
$vrat[$radek[$groupBy]]=array();
}
$vrat[$radek[$groupBy]][$index]=$radek;
}
if ($orderByKey) {
ksort($vrat);
}
if ($orderByKey==="desc") {
$vrat=array_reverse($vrat);
}
return $vrat;
} | [
"static",
"public",
"function",
"group",
"(",
"$",
"data",
",",
"$",
"groupBy",
",",
"$",
"orderByKey",
"=",
"false",
")",
"{",
"$",
"vrat",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"index",
"=>",
"$",
"radek",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"radek",
"[",
"$",
"groupBy",
"]",
")",
")",
"{",
"$",
"radek",
"[",
"$",
"groupBy",
"]",
"=",
"\"0\"",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"vrat",
"[",
"$",
"radek",
"[",
"$",
"groupBy",
"]",
"]",
")",
")",
"{",
"$",
"vrat",
"[",
"$",
"radek",
"[",
"$",
"groupBy",
"]",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"vrat",
"[",
"$",
"radek",
"[",
"$",
"groupBy",
"]",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"radek",
";",
"}",
"if",
"(",
"$",
"orderByKey",
")",
"{",
"ksort",
"(",
"$",
"vrat",
")",
";",
"}",
"if",
"(",
"$",
"orderByKey",
"===",
"\"desc\"",
")",
"{",
"$",
"vrat",
"=",
"array_reverse",
"(",
"$",
"vrat",
")",
";",
"}",
"return",
"$",
"vrat",
";",
"}"
] | Z klasického dvojrozměrného pole udělá trojrozměrné pole, kde první index bude sdružovat řádku dle nějaké z hodnot.
@param array $data
@param string $groupBy Název políčka v $data, podle něhož se má sdružovat
@param bool|string $orderByKey False (def.) = nechat, jak to přišlo pod ruku. True = seřadit dle sdružované hodnoty. String "desc" = sestupně.
@return array | [
"Z",
"klasického",
"dvojrozměrného",
"pole",
"udělá",
"trojrozměrné",
"pole",
"kde",
"první",
"index",
"bude",
"sdružovat",
"řádku",
"dle",
"nějaké",
"z",
"hodnot",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L183-L201 |
ondrakoupil/tools | src/Arrays.php | Arrays.indexByKey | static public function indexByKey($input, $keyName) {
if (!is_array($input) and !($input instanceof \Traversable)) {
throw new \InvalidArgumentException("Given argument must be an array or traversable object.");
}
$returnedArray = array();
foreach($input as $index => $f) {
if (is_array($f)) {
$key = array_key_exists($keyName, $f) ? $f[$keyName] : $index;
$returnedArray[$key] = $f;
} elseif (is_object($f)) {
$key = property_exists($f, $keyName) ? $f->$keyName : $index;
$returnedArray[$key] = $f;
} else {
if (!isset($returnedArray[$index])) {
$returnedArray[$index] = $f;
}
}
}
return $returnedArray;
} | php | static public function indexByKey($input, $keyName) {
if (!is_array($input) and !($input instanceof \Traversable)) {
throw new \InvalidArgumentException("Given argument must be an array or traversable object.");
}
$returnedArray = array();
foreach($input as $index => $f) {
if (is_array($f)) {
$key = array_key_exists($keyName, $f) ? $f[$keyName] : $index;
$returnedArray[$key] = $f;
} elseif (is_object($f)) {
$key = property_exists($f, $keyName) ? $f->$keyName : $index;
$returnedArray[$key] = $f;
} else {
if (!isset($returnedArray[$index])) {
$returnedArray[$index] = $f;
}
}
}
return $returnedArray;
} | [
"static",
"public",
"function",
"indexByKey",
"(",
"$",
"input",
",",
"$",
"keyName",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"input",
")",
"and",
"!",
"(",
"$",
"input",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Given argument must be an array or traversable object.\"",
")",
";",
"}",
"$",
"returnedArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"input",
"as",
"$",
"index",
"=>",
"$",
"f",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"f",
")",
")",
"{",
"$",
"key",
"=",
"array_key_exists",
"(",
"$",
"keyName",
",",
"$",
"f",
")",
"?",
"$",
"f",
"[",
"$",
"keyName",
"]",
":",
"$",
"index",
";",
"$",
"returnedArray",
"[",
"$",
"key",
"]",
"=",
"$",
"f",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"f",
")",
")",
"{",
"$",
"key",
"=",
"property_exists",
"(",
"$",
"f",
",",
"$",
"keyName",
")",
"?",
"$",
"f",
"->",
"$",
"keyName",
":",
"$",
"index",
";",
"$",
"returnedArray",
"[",
"$",
"key",
"]",
"=",
"$",
"f",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"returnedArray",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"returnedArray",
"[",
"$",
"index",
"]",
"=",
"$",
"f",
";",
"}",
"}",
"}",
"return",
"$",
"returnedArray",
";",
"}"
] | Zadané dvourozměrné pole nebo traversable objekt přeindexuje tak, že jeho jednotlivé indexy
budou tvořeny určitým prvkem nebo public vlastností z každého prvku.
Pokud některý z prvků vstupního pole neobsahuje $keyName, zachová se jeho původní index.
@param array|\Traversable $input Vstupní pole/objekt
@param string $keyName Podle čeho indexovat
@return array | [
"Zadané",
"dvourozměrné",
"pole",
"nebo",
"traversable",
"objekt",
"přeindexuje",
"tak",
"že",
"jeho",
"jednotlivé",
"indexy",
"budou",
"tvořeny",
"určitým",
"prvkem",
"nebo",
"public",
"vlastností",
"z",
"každého",
"prvku",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L213-L235 |
ondrakoupil/tools | src/Arrays.php | Arrays.deleteValue | static public function deleteValue($dataArray, $valueToDelete, $keysInsignificant = true, $strict = false) {
if ($valueToDelete === null) throw new \InvalidArgumentException("\$valueToDelete cannot be null.");
$keys = array_keys($dataArray, $valueToDelete, $strict);
if ($keys) {
foreach($keys as $k) {
unset($dataArray[$k]);
}
if ($keysInsignificant) {
$dataArray = array_values($dataArray);
}
}
return $dataArray;
} | php | static public function deleteValue($dataArray, $valueToDelete, $keysInsignificant = true, $strict = false) {
if ($valueToDelete === null) throw new \InvalidArgumentException("\$valueToDelete cannot be null.");
$keys = array_keys($dataArray, $valueToDelete, $strict);
if ($keys) {
foreach($keys as $k) {
unset($dataArray[$k]);
}
if ($keysInsignificant) {
$dataArray = array_values($dataArray);
}
}
return $dataArray;
} | [
"static",
"public",
"function",
"deleteValue",
"(",
"$",
"dataArray",
",",
"$",
"valueToDelete",
",",
"$",
"keysInsignificant",
"=",
"true",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"valueToDelete",
"===",
"null",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"\\$valueToDelete cannot be null.\"",
")",
";",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"dataArray",
",",
"$",
"valueToDelete",
",",
"$",
"strict",
")",
";",
"if",
"(",
"$",
"keys",
")",
"{",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"k",
")",
"{",
"unset",
"(",
"$",
"dataArray",
"[",
"$",
"k",
"]",
")",
";",
"}",
"if",
"(",
"$",
"keysInsignificant",
")",
"{",
"$",
"dataArray",
"=",
"array_values",
"(",
"$",
"dataArray",
")",
";",
"}",
"}",
"return",
"$",
"dataArray",
";",
"}"
] | Zruší z pole všechny výskyty určité hodnoty.
@param array $dataArray
@param mixed $valueToDelete Nesmí být null!
@param bool $keysInsignificant True = přečíslovat vrácené pole, indexy nejsou podstatné. False = nechat původní indexy.
@param bool $strict == nebo ===
@return array Upravené $dataArray | [
"Zruší",
"z",
"pole",
"všechny",
"výskyty",
"určité",
"hodnoty",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L245-L257 |
ondrakoupil/tools | src/Arrays.php | Arrays.deleteValues | static public function deleteValues($dataArray, $arrayOfValuesToDelete, $keysInsignificant = true) {
$arrayOfValuesToDelete = self::arrayize($arrayOfValuesToDelete);
$invertedDeletes = array_fill_keys($arrayOfValuesToDelete, true);
foreach ($dataArray as $i=>$r) {
if (isset($invertedDeletes[$r])) {
unset($dataArray[$i]);
}
}
if ($keysInsignificant) {
$dataArray = array_values($dataArray);
}
return $dataArray;
} | php | static public function deleteValues($dataArray, $arrayOfValuesToDelete, $keysInsignificant = true) {
$arrayOfValuesToDelete = self::arrayize($arrayOfValuesToDelete);
$invertedDeletes = array_fill_keys($arrayOfValuesToDelete, true);
foreach ($dataArray as $i=>$r) {
if (isset($invertedDeletes[$r])) {
unset($dataArray[$i]);
}
}
if ($keysInsignificant) {
$dataArray = array_values($dataArray);
}
return $dataArray;
} | [
"static",
"public",
"function",
"deleteValues",
"(",
"$",
"dataArray",
",",
"$",
"arrayOfValuesToDelete",
",",
"$",
"keysInsignificant",
"=",
"true",
")",
"{",
"$",
"arrayOfValuesToDelete",
"=",
"self",
"::",
"arrayize",
"(",
"$",
"arrayOfValuesToDelete",
")",
";",
"$",
"invertedDeletes",
"=",
"array_fill_keys",
"(",
"$",
"arrayOfValuesToDelete",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"dataArray",
"as",
"$",
"i",
"=>",
"$",
"r",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"invertedDeletes",
"[",
"$",
"r",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"dataArray",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"keysInsignificant",
")",
"{",
"$",
"dataArray",
"=",
"array_values",
"(",
"$",
"dataArray",
")",
";",
"}",
"return",
"$",
"dataArray",
";",
"}"
] | Zruší z jednoho pole všechny hodnoty, které se vyskytují ve druhém poli.
Ve druhém poli musí jít o skalární typy, objekty nebo array povedou k chybě.
@param array $dataArray
@param array $arrayOfValuesToDelete
@param bool $keysInsignificant True = přečíslovat vrácené pole, indexy nejsou podstatné. False = nechat původní indexy.
@return array Upravené $dataArray | [
"Zruší",
"z",
"jednoho",
"pole",
"všechny",
"hodnoty",
"které",
"se",
"vyskytují",
"ve",
"druhém",
"poli",
".",
"Ve",
"druhém",
"poli",
"musí",
"jít",
"o",
"skalární",
"typy",
"objekty",
"nebo",
"array",
"povedou",
"k",
"chybě",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L267-L280 |
ondrakoupil/tools | src/Arrays.php | Arrays.enrich | static public function enrich($mainArray, $mixinArray, $fields=true, $changeIndexes = array()) {
if ($fields!==true) $fields=self::arrayize($fields);
foreach($mixinArray as $mixinId=>$mixinData) {
if (!isset($mainArray[$mixinId])) continue;
if ($changeIndexes) {
foreach($changeIndexes as $fromI=>$toI) {
if (isset($mixinData[$fromI])) {
$mixinData[$toI] = $mixinData[$fromI];
unset($mixinData[$fromI]);
} else {
$mixinData[$toI] = null;
}
}
}
if ($fields===true) {
$mainArray[$mixinId]+=$mixinData;
} else {
foreach($fields as $field) {
if (!isset($mainArray[$mixinId][$field])) {
if (isset($mixinData[$field])) {
$mainArray[$mixinId][$field]=$mixinData[$field];
} else {
$mainArray[$mixinId][$field]=null;
}
}
}
}
}
return $mainArray;
} | php | static public function enrich($mainArray, $mixinArray, $fields=true, $changeIndexes = array()) {
if ($fields!==true) $fields=self::arrayize($fields);
foreach($mixinArray as $mixinId=>$mixinData) {
if (!isset($mainArray[$mixinId])) continue;
if ($changeIndexes) {
foreach($changeIndexes as $fromI=>$toI) {
if (isset($mixinData[$fromI])) {
$mixinData[$toI] = $mixinData[$fromI];
unset($mixinData[$fromI]);
} else {
$mixinData[$toI] = null;
}
}
}
if ($fields===true) {
$mainArray[$mixinId]+=$mixinData;
} else {
foreach($fields as $field) {
if (!isset($mainArray[$mixinId][$field])) {
if (isset($mixinData[$field])) {
$mainArray[$mixinId][$field]=$mixinData[$field];
} else {
$mainArray[$mixinId][$field]=null;
}
}
}
}
}
return $mainArray;
} | [
"static",
"public",
"function",
"enrich",
"(",
"$",
"mainArray",
",",
"$",
"mixinArray",
",",
"$",
"fields",
"=",
"true",
",",
"$",
"changeIndexes",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"fields",
"!==",
"true",
")",
"$",
"fields",
"=",
"self",
"::",
"arrayize",
"(",
"$",
"fields",
")",
";",
"foreach",
"(",
"$",
"mixinArray",
"as",
"$",
"mixinId",
"=>",
"$",
"mixinData",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mainArray",
"[",
"$",
"mixinId",
"]",
")",
")",
"continue",
";",
"if",
"(",
"$",
"changeIndexes",
")",
"{",
"foreach",
"(",
"$",
"changeIndexes",
"as",
"$",
"fromI",
"=>",
"$",
"toI",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"mixinData",
"[",
"$",
"fromI",
"]",
")",
")",
"{",
"$",
"mixinData",
"[",
"$",
"toI",
"]",
"=",
"$",
"mixinData",
"[",
"$",
"fromI",
"]",
";",
"unset",
"(",
"$",
"mixinData",
"[",
"$",
"fromI",
"]",
")",
";",
"}",
"else",
"{",
"$",
"mixinData",
"[",
"$",
"toI",
"]",
"=",
"null",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"fields",
"===",
"true",
")",
"{",
"$",
"mainArray",
"[",
"$",
"mixinId",
"]",
"+=",
"$",
"mixinData",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mainArray",
"[",
"$",
"mixinId",
"]",
"[",
"$",
"field",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"mixinData",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"mainArray",
"[",
"$",
"mixinId",
"]",
"[",
"$",
"field",
"]",
"=",
"$",
"mixinData",
"[",
"$",
"field",
"]",
";",
"}",
"else",
"{",
"$",
"mainArray",
"[",
"$",
"mixinId",
"]",
"[",
"$",
"field",
"]",
"=",
"null",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"mainArray",
";",
"}"
] | Obohatí $mainArray o nějaké prvky z $mixinArray. Obě pole by měla být dvourozměrná pole, kde
první rozměr je ID a další rozměr je asociativní pole s nějakými vlastnostmi.
<br />Data z $mainArray se považují za prioritnější a správnější, a pokud již příslušný prvek obsahují,
nepřepíší se tím z $mixinArray.
@param array $mainArray
@param array $mixinArray
@param bool|array|string $fields True = obohatit vším, co v $mixinArray je. Jinak string/array stringů.
@param array $changeIndexes Do $mainField lze použít jiné indexy, než v originále. Sem zadej "překladovou tabulku" ve tvaru array([original_key] => new_key).
Ve $fields používej již indexy po přejmenování.
@return array Obohacené $mainArray | [
"Obohatí",
"$mainArray",
"o",
"nějaké",
"prvky",
"z",
"$mixinArray",
".",
"Obě",
"pole",
"by",
"měla",
"být",
"dvourozměrná",
"pole",
"kde",
"první",
"rozměr",
"je",
"ID",
"a",
"další",
"rozměr",
"je",
"asociativní",
"pole",
"s",
"nějakými",
"vlastnostmi",
".",
"<br",
"/",
">",
"Data",
"z",
"$mainArray",
"se",
"považují",
"za",
"prioritnější",
"a",
"správnější",
"a",
"pokud",
"již",
"příslušný",
"prvek",
"obsahují",
"nepřepíší",
"se",
"tím",
"z",
"$mixinArray",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L295-L324 |
ondrakoupil/tools | src/Arrays.php | Arrays.toObject | static function toObject($array) {
if (!is_array($array) and !($array instanceof \Traversable)) {
throw new \InvalidArgumentException("You must give me an array!");
}
$obj = new \stdClass();
foreach ($array as $i=>$r) {
$obj->$i = $r;
}
return $obj;
} | php | static function toObject($array) {
if (!is_array($array) and !($array instanceof \Traversable)) {
throw new \InvalidArgumentException("You must give me an array!");
}
$obj = new \stdClass();
foreach ($array as $i=>$r) {
$obj->$i = $r;
}
return $obj;
} | [
"static",
"function",
"toObject",
"(",
"$",
"array",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
"and",
"!",
"(",
"$",
"array",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"You must give me an array!\"",
")",
";",
"}",
"$",
"obj",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"i",
"=>",
"$",
"r",
")",
"{",
"$",
"obj",
"->",
"$",
"i",
"=",
"$",
"r",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Konverze asociativního pole na objekt třídy stdClass
@param array|Traversable $array
@return \stdClass | [
"Konverze",
"asociativního",
"pole",
"na",
"objekt",
"třídy",
"stdClass"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L331-L340 |
ondrakoupil/tools | src/Arrays.php | Arrays.flatten | static public function flatten($array) {
$out=array();
foreach($array as $i=>$subArray) {
foreach($subArray as $value) {
$out[$value]=true;
}
}
return array_keys($out);
} | php | static public function flatten($array) {
$out=array();
foreach($array as $i=>$subArray) {
foreach($subArray as $value) {
$out[$value]=true;
}
}
return array_keys($out);
} | [
"static",
"public",
"function",
"flatten",
"(",
"$",
"array",
")",
"{",
"$",
"out",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"i",
"=>",
"$",
"subArray",
")",
"{",
"foreach",
"(",
"$",
"subArray",
"as",
"$",
"value",
")",
"{",
"$",
"out",
"[",
"$",
"value",
"]",
"=",
"true",
";",
"}",
"}",
"return",
"array_keys",
"(",
"$",
"out",
")",
";",
"}"
] | Z dvourozměrného pole, které bylo sgrupované podle nějaké hodnoty, udělá zpět jednorozměrné, s výčtem jednotlivých hodnot.
Funguje pouze za předpokladu, že jednotlivé hodnoty jsou obyčejné skalární typy. Objekty nebo array třetího rozměru povede k chybě.
@param array $array
@return array | [
"Z",
"dvourozměrného",
"pole",
"které",
"bylo",
"sgrupované",
"podle",
"nějaké",
"hodnoty",
"udělá",
"zpět",
"jednorozměrné",
"s",
"výčtem",
"jednotlivých",
"hodnot",
".",
"Funguje",
"pouze",
"za",
"předpokladu",
"že",
"jednotlivé",
"hodnoty",
"jsou",
"obyčejné",
"skalární",
"typy",
".",
"Objekty",
"nebo",
"array",
"třetího",
"rozměru",
"povede",
"k",
"chybě",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L348-L356 |
ondrakoupil/tools | src/Arrays.php | Arrays.normaliseValues | static public function normaliseValues($array) {
$array=self::arrayize($array);
if (!$array) return $array;
$minValue=min($array);
$maxValue=max($array);
if ($maxValue==$minValue) {
$minValue-=1;
}
foreach($array as $index=>$value) {
$array[$index]=($value-$minValue)/($maxValue-$minValue);
}
return $array;
} | php | static public function normaliseValues($array) {
$array=self::arrayize($array);
if (!$array) return $array;
$minValue=min($array);
$maxValue=max($array);
if ($maxValue==$minValue) {
$minValue-=1;
}
foreach($array as $index=>$value) {
$array[$index]=($value-$minValue)/($maxValue-$minValue);
}
return $array;
} | [
"static",
"public",
"function",
"normaliseValues",
"(",
"$",
"array",
")",
"{",
"$",
"array",
"=",
"self",
"::",
"arrayize",
"(",
"$",
"array",
")",
";",
"if",
"(",
"!",
"$",
"array",
")",
"return",
"$",
"array",
";",
"$",
"minValue",
"=",
"min",
"(",
"$",
"array",
")",
";",
"$",
"maxValue",
"=",
"max",
"(",
"$",
"array",
")",
";",
"if",
"(",
"$",
"maxValue",
"==",
"$",
"minValue",
")",
"{",
"$",
"minValue",
"-=",
"1",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"$",
"array",
"[",
"$",
"index",
"]",
"=",
"(",
"$",
"value",
"-",
"$",
"minValue",
")",
"/",
"(",
"$",
"maxValue",
"-",
"$",
"minValue",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Normalizuje hodnoty v poli do rozsahu <0-1>
@param array $array
@return array | [
"Normalizuje",
"hodnoty",
"v",
"poli",
"do",
"rozsahu",
"<",
";",
"0",
"-",
"1>",
";"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L364-L376 |
ondrakoupil/tools | src/Arrays.php | Arrays.traversableToArray | static function traversableToArray($traversable, $depth = 0) {
$vrat = array();
if ($depth > 10) throw new \RuntimeException("Recursion is too deep.");
if (!is_array($traversable) and !($traversable instanceof \Traversable)) {
throw new \InvalidArgumentException("\$traversable must be an array or Traversable object.");
}
foreach ($traversable as $i=>$r) {
if (is_array($r) or ($r instanceof \Traversable)) {
$vrat[$i] = self::traversableToArray($r, $depth + 1);
} else {
$vrat[$i] = $r;
}
}
return $vrat;
} | php | static function traversableToArray($traversable, $depth = 0) {
$vrat = array();
if ($depth > 10) throw new \RuntimeException("Recursion is too deep.");
if (!is_array($traversable) and !($traversable instanceof \Traversable)) {
throw new \InvalidArgumentException("\$traversable must be an array or Traversable object.");
}
foreach ($traversable as $i=>$r) {
if (is_array($r) or ($r instanceof \Traversable)) {
$vrat[$i] = self::traversableToArray($r, $depth + 1);
} else {
$vrat[$i] = $r;
}
}
return $vrat;
} | [
"static",
"function",
"traversableToArray",
"(",
"$",
"traversable",
",",
"$",
"depth",
"=",
"0",
")",
"{",
"$",
"vrat",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"depth",
">",
"10",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Recursion is too deep.\"",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"traversable",
")",
"and",
"!",
"(",
"$",
"traversable",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"\\$traversable must be an array or Traversable object.\"",
")",
";",
"}",
"foreach",
"(",
"$",
"traversable",
"as",
"$",
"i",
"=>",
"$",
"r",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"r",
")",
"or",
"(",
"$",
"r",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"$",
"vrat",
"[",
"$",
"i",
"]",
"=",
"self",
"::",
"traversableToArray",
"(",
"$",
"r",
",",
"$",
"depth",
"+",
"1",
")",
";",
"}",
"else",
"{",
"$",
"vrat",
"[",
"$",
"i",
"]",
"=",
"$",
"r",
";",
"}",
"}",
"return",
"$",
"vrat",
";",
"}"
] | Rekurzivně převede traversable objekt na obyčejné array.
@param \Traversable $traversable
@param int $depth Interní, pro kontorlu nekonečné rekurze
@return array
@throws \RuntimeException | [
"Rekurzivně",
"převede",
"traversable",
"objekt",
"na",
"obyčejné",
"array",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L385-L399 |
ondrakoupil/tools | src/Arrays.php | Arrays.enumItem | static function enumItem ($data,$index,$pattern=false,$default=0,$reverse=false) {
if ($index!==false) {
if (!isset($data[$index])) {
$index=$default;
if (!isset($data[$index])) return $default;
}
if ($pattern===false) return $data[$index];
return self::enumItemPattern($pattern,$index,$data[$index],"");
}
if ($pattern===false) {
if ($reverse) return array_reverse($data,true);
return $data;
}
$vrat=array();
$i=0;
foreach($data as $di=>$dr) {
$vrat[$di]=self::enumItemPattern($pattern,$di,$dr,$i);
$i++;
}
if ($reverse) return array_reverse($vrat,true);
return $vrat;
} | php | static function enumItem ($data,$index,$pattern=false,$default=0,$reverse=false) {
if ($index!==false) {
if (!isset($data[$index])) {
$index=$default;
if (!isset($data[$index])) return $default;
}
if ($pattern===false) return $data[$index];
return self::enumItemPattern($pattern,$index,$data[$index],"");
}
if ($pattern===false) {
if ($reverse) return array_reverse($data,true);
return $data;
}
$vrat=array();
$i=0;
foreach($data as $di=>$dr) {
$vrat[$di]=self::enumItemPattern($pattern,$di,$dr,$i);
$i++;
}
if ($reverse) return array_reverse($vrat,true);
return $vrat;
} | [
"static",
"function",
"enumItem",
"(",
"$",
"data",
",",
"$",
"index",
",",
"$",
"pattern",
"=",
"false",
",",
"$",
"default",
"=",
"0",
",",
"$",
"reverse",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"index",
"=",
"$",
"default",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"index",
"]",
")",
")",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"$",
"pattern",
"===",
"false",
")",
"return",
"$",
"data",
"[",
"$",
"index",
"]",
";",
"return",
"self",
"::",
"enumItemPattern",
"(",
"$",
"pattern",
",",
"$",
"index",
",",
"$",
"data",
"[",
"$",
"index",
"]",
",",
"\"\"",
")",
";",
"}",
"if",
"(",
"$",
"pattern",
"===",
"false",
")",
"{",
"if",
"(",
"$",
"reverse",
")",
"return",
"array_reverse",
"(",
"$",
"data",
",",
"true",
")",
";",
"return",
"$",
"data",
";",
"}",
"$",
"vrat",
"=",
"array",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"di",
"=>",
"$",
"dr",
")",
"{",
"$",
"vrat",
"[",
"$",
"di",
"]",
"=",
"self",
"::",
"enumItemPattern",
"(",
"$",
"pattern",
",",
"$",
"di",
",",
"$",
"dr",
",",
"$",
"i",
")",
";",
"$",
"i",
"++",
";",
"}",
"if",
"(",
"$",
"reverse",
")",
"return",
"array_reverse",
"(",
"$",
"vrat",
",",
"true",
")",
";",
"return",
"$",
"vrat",
";",
"}"
] | Pomocná funkce zjednodušující práci s různými číselníky definovanými jako array v PHP. Umožňuje buď "lidsky" zformátovat jeden vybraný prvek z číselníku, nebo vrátit celé array hodnot.
@param array $data Celé array se všemi položkami ve tvaru [index]=>$value
@param string|int|bool $index False = vrať array se všemi. Jinak zadej index jedné konkrétní položky.
@param string|bool $pattern False = vrať tak, jak to je v $data. String = naformátuj. Entity %index%, %value%, %i%. %i% označuje pořadí a vyplňuje se jen je-li $index false a je 0-based.
@param string|int $default Pokud by snad v $data nebyla položka s indexem $indexPolozky, hledej index $default, pokud není, vrať $default.
@param bool $reverse dej True, má-li se vrátit v opačném pořadí.
@return array|string Array pokud $indexPolozky je false, jinak string. | [
"Pomocná",
"funkce",
"zjednodušující",
"práci",
"s",
"různými",
"číselníky",
"definovanými",
"jako",
"array",
"v",
"PHP",
".",
"Umožňuje",
"buď",
"lidsky",
"zformátovat",
"jeden",
"vybraný",
"prvek",
"z",
"číselníku",
"nebo",
"vrátit",
"celé",
"array",
"hodnot",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L411-L434 |
ondrakoupil/tools | src/Arrays.php | Arrays.compareValues | static function compareValues($array1, $array2, $strict = false) {
if (count($array1) != count($array2)) return false;
$array1 = array_values($array1);
$array2 = array_values($array2);
sort($array1, SORT_STRING);
sort($array2, SORT_STRING);
foreach($array1 as $i=>$r) {
if ($array2[$i] != $r) return false;
if ($strict and $array2[$i] !== $r) return false;
}
return true;
} | php | static function compareValues($array1, $array2, $strict = false) {
if (count($array1) != count($array2)) return false;
$array1 = array_values($array1);
$array2 = array_values($array2);
sort($array1, SORT_STRING);
sort($array2, SORT_STRING);
foreach($array1 as $i=>$r) {
if ($array2[$i] != $r) return false;
if ($strict and $array2[$i] !== $r) return false;
}
return true;
} | [
"static",
"function",
"compareValues",
"(",
"$",
"array1",
",",
"$",
"array2",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"array1",
")",
"!=",
"count",
"(",
"$",
"array2",
")",
")",
"return",
"false",
";",
"$",
"array1",
"=",
"array_values",
"(",
"$",
"array1",
")",
";",
"$",
"array2",
"=",
"array_values",
"(",
"$",
"array2",
")",
";",
"sort",
"(",
"$",
"array1",
",",
"SORT_STRING",
")",
";",
"sort",
"(",
"$",
"array2",
",",
"SORT_STRING",
")",
";",
"foreach",
"(",
"$",
"array1",
"as",
"$",
"i",
"=>",
"$",
"r",
")",
"{",
"if",
"(",
"$",
"array2",
"[",
"$",
"i",
"]",
"!=",
"$",
"r",
")",
"return",
"false",
";",
"if",
"(",
"$",
"strict",
"and",
"$",
"array2",
"[",
"$",
"i",
"]",
"!==",
"$",
"r",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Porovná, zda jsou hodnoty ve dvou polích stejné. Nezáleží na indexech ani na pořadí prvků v poli.
@param array $array1
@param array $array2
@param bool $strict Používat ===
@return boolean True = stejné. False = rozdílné. | [
"Porovná",
"zda",
"jsou",
"hodnoty",
"ve",
"dvou",
"polích",
"stejné",
".",
"Nezáleží",
"na",
"indexech",
"ani",
"na",
"pořadí",
"prvků",
"v",
"poli",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L454-L468 |
ondrakoupil/tools | src/Arrays.php | Arrays.iconv | static function iconv($from, $to, $array, $keys=false, $checkDepth = 0) {
if (is_object($array)) {
return $array;
}
if (!is_array($array)) {
if (is_string($array)) {
return iconv($from,$to,$array);
} else {
return $array;
}
}
if ($checkDepth>20) return $array;
$vrat=array();
foreach($array as $i=>$r) {
if ($keys) {
$i=iconv($from,$to,$i);
}
$vrat[$i]=self::iconv($from,$to,$r,$keys,$checkDepth+1);
}
return $vrat;
} | php | static function iconv($from, $to, $array, $keys=false, $checkDepth = 0) {
if (is_object($array)) {
return $array;
}
if (!is_array($array)) {
if (is_string($array)) {
return iconv($from,$to,$array);
} else {
return $array;
}
}
if ($checkDepth>20) return $array;
$vrat=array();
foreach($array as $i=>$r) {
if ($keys) {
$i=iconv($from,$to,$i);
}
$vrat[$i]=self::iconv($from,$to,$r,$keys,$checkDepth+1);
}
return $vrat;
} | [
"static",
"function",
"iconv",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"array",
",",
"$",
"keys",
"=",
"false",
",",
"$",
"checkDepth",
"=",
"0",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"array",
")",
")",
"{",
"return",
"$",
"array",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"array",
")",
")",
"{",
"return",
"iconv",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"array",
")",
";",
"}",
"else",
"{",
"return",
"$",
"array",
";",
"}",
"}",
"if",
"(",
"$",
"checkDepth",
">",
"20",
")",
"return",
"$",
"array",
";",
"$",
"vrat",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"i",
"=>",
"$",
"r",
")",
"{",
"if",
"(",
"$",
"keys",
")",
"{",
"$",
"i",
"=",
"iconv",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"i",
")",
";",
"}",
"$",
"vrat",
"[",
"$",
"i",
"]",
"=",
"self",
"::",
"iconv",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"r",
",",
"$",
"keys",
",",
"$",
"checkDepth",
"+",
"1",
")",
";",
"}",
"return",
"$",
"vrat",
";",
"}"
] | Rekurzivní změna kódování libovolného typu proměnné (array, string, atd., kromě objektů).
@param string $from Vstupní kódování
@param string $to Výstupní kódování
@param mixed $array Co překódovat
@param bool $keys Mají se iconvovat i klíče? Def. false.
@param int $checkDepth Tento parametr ignoruj, používá se jako pojistka proti nekonečné rekurzi.
@return mixed | [
"Rekurzivní",
"změna",
"kódování",
"libovolného",
"typu",
"proměnné",
"(",
"array",
"string",
"atd",
".",
"kromě",
"objektů",
")",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L479-L499 |
ondrakoupil/tools | src/Arrays.php | Arrays.cartesian | static function cartesian($input) {
$input = array_filter($input);
$result = array(array());
foreach ($input as $key => $values) {
$append = array();
foreach($result as $product) {
foreach($values as $item) {
$product[$key] = $item;
$append[] = $product;
}
}
$result = $append;
}
return $result;
} | php | static function cartesian($input) {
$input = array_filter($input);
$result = array(array());
foreach ($input as $key => $values) {
$append = array();
foreach($result as $product) {
foreach($values as $item) {
$product[$key] = $item;
$append[] = $product;
}
}
$result = $append;
}
return $result;
} | [
"static",
"function",
"cartesian",
"(",
"$",
"input",
")",
"{",
"$",
"input",
"=",
"array_filter",
"(",
"$",
"input",
")",
";",
"$",
"result",
"=",
"array",
"(",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"input",
"as",
"$",
"key",
"=>",
"$",
"values",
")",
"{",
"$",
"append",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"product",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"item",
")",
"{",
"$",
"product",
"[",
"$",
"key",
"]",
"=",
"$",
"item",
";",
"$",
"append",
"[",
"]",
"=",
"$",
"product",
";",
"}",
"}",
"$",
"result",
"=",
"$",
"append",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Vytvoří kartézský součin.
<code>
$input = array(
"barva" => array("red", "green"),
"size" => array("small", "big")
);
$output = array(
[0] => array("barva" => "red", "size" => "small"),
[1] => array("barva" => "green", "size" => "small"),
[2] => array("barva" => "red", "size" => "big"),
[3] => array("barva" => "green", "size" => "big")
);
</code>
@param array $input
@return array
@see http://stackoverflow.com/questions/6311779/finding-cartesian-product-with-php-associative-arrays | [
"Vytvoří",
"kartézský",
"součin",
".",
"<code",
">",
"$input",
"=",
"array",
"(",
"barva",
"=",
">",
"array",
"(",
"red",
"green",
")",
"size",
"=",
">",
"array",
"(",
"small",
"big",
")",
")",
";"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Arrays.php#L521-L540 |
kattsoftware/phassets | src/Phassets/Filters/ScssCompilerFilter.php | ScssCompilerFilter.filter | public function filter(Asset $asset)
{
if ($asset->getOutputExtension() !== 'scss') {
throw new PhassetsInternalException('Only .scss files can be filtered by ' . __CLASS__);
}
$scssCompiler = new Compiler();
// Custom import paths?
$importPaths = $this->configurator->getConfig('scsscompiler_filter', 'import_paths');
if ($importPaths) {
$scssCompiler->setImportPaths($importPaths);
}
// Custom vars?
$customVars = $this->configurator->getConfig('scsscompiler_filter', 'custom_vars');
if ($customVars) {
$scssCompiler->setVariables($customVars);
}
// Formatter
$formatter = $this->configurator->getConfig('scsscompiler_filter', 'formatter');
switch ($formatter) {
case 'expanded':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Expanded::class);
break;
case 'nested':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Nested::class);
break;
case 'compressed':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Compressed::class);
break;
case 'compact':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Compact::class);
break;
default:
case 'crunched':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Crunched::class);
}
$asset->setContents($scssCompiler->compile($asset->getContents()));
} | php | public function filter(Asset $asset)
{
if ($asset->getOutputExtension() !== 'scss') {
throw new PhassetsInternalException('Only .scss files can be filtered by ' . __CLASS__);
}
$scssCompiler = new Compiler();
// Custom import paths?
$importPaths = $this->configurator->getConfig('scsscompiler_filter', 'import_paths');
if ($importPaths) {
$scssCompiler->setImportPaths($importPaths);
}
// Custom vars?
$customVars = $this->configurator->getConfig('scsscompiler_filter', 'custom_vars');
if ($customVars) {
$scssCompiler->setVariables($customVars);
}
// Formatter
$formatter = $this->configurator->getConfig('scsscompiler_filter', 'formatter');
switch ($formatter) {
case 'expanded':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Expanded::class);
break;
case 'nested':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Nested::class);
break;
case 'compressed':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Compressed::class);
break;
case 'compact':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Compact::class);
break;
default:
case 'crunched':
$scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Crunched::class);
}
$asset->setContents($scssCompiler->compile($asset->getContents()));
} | [
"public",
"function",
"filter",
"(",
"Asset",
"$",
"asset",
")",
"{",
"if",
"(",
"$",
"asset",
"->",
"getOutputExtension",
"(",
")",
"!==",
"'scss'",
")",
"{",
"throw",
"new",
"PhassetsInternalException",
"(",
"'Only .scss files can be filtered by '",
".",
"__CLASS__",
")",
";",
"}",
"$",
"scssCompiler",
"=",
"new",
"Compiler",
"(",
")",
";",
"// Custom import paths?",
"$",
"importPaths",
"=",
"$",
"this",
"->",
"configurator",
"->",
"getConfig",
"(",
"'scsscompiler_filter'",
",",
"'import_paths'",
")",
";",
"if",
"(",
"$",
"importPaths",
")",
"{",
"$",
"scssCompiler",
"->",
"setImportPaths",
"(",
"$",
"importPaths",
")",
";",
"}",
"// Custom vars?",
"$",
"customVars",
"=",
"$",
"this",
"->",
"configurator",
"->",
"getConfig",
"(",
"'scsscompiler_filter'",
",",
"'custom_vars'",
")",
";",
"if",
"(",
"$",
"customVars",
")",
"{",
"$",
"scssCompiler",
"->",
"setVariables",
"(",
"$",
"customVars",
")",
";",
"}",
"// Formatter",
"$",
"formatter",
"=",
"$",
"this",
"->",
"configurator",
"->",
"getConfig",
"(",
"'scsscompiler_filter'",
",",
"'formatter'",
")",
";",
"switch",
"(",
"$",
"formatter",
")",
"{",
"case",
"'expanded'",
":",
"$",
"scssCompiler",
"->",
"setFormatter",
"(",
"\\",
"Leafo",
"\\",
"ScssPhp",
"\\",
"Formatter",
"\\",
"Expanded",
"::",
"class",
")",
";",
"break",
";",
"case",
"'nested'",
":",
"$",
"scssCompiler",
"->",
"setFormatter",
"(",
"\\",
"Leafo",
"\\",
"ScssPhp",
"\\",
"Formatter",
"\\",
"Nested",
"::",
"class",
")",
";",
"break",
";",
"case",
"'compressed'",
":",
"$",
"scssCompiler",
"->",
"setFormatter",
"(",
"\\",
"Leafo",
"\\",
"ScssPhp",
"\\",
"Formatter",
"\\",
"Compressed",
"::",
"class",
")",
";",
"break",
";",
"case",
"'compact'",
":",
"$",
"scssCompiler",
"->",
"setFormatter",
"(",
"\\",
"Leafo",
"\\",
"ScssPhp",
"\\",
"Formatter",
"\\",
"Compact",
"::",
"class",
")",
";",
"break",
";",
"default",
":",
"case",
"'crunched'",
":",
"$",
"scssCompiler",
"->",
"setFormatter",
"(",
"\\",
"Leafo",
"\\",
"ScssPhp",
"\\",
"Formatter",
"\\",
"Crunched",
"::",
"class",
")",
";",
"}",
"$",
"asset",
"->",
"setContents",
"(",
"$",
"scssCompiler",
"->",
"compile",
"(",
"$",
"asset",
"->",
"getContents",
"(",
")",
")",
")",
";",
"}"
] | Process the Asset received and using Asset::setContents(), update
the contents accordingly. If it fails, will throw PhassetsInternalException
@param Asset $asset Asset instance which will be updated via setContents()
@throws PhassetsInternalException in case of failure | [
"Process",
"the",
"Asset",
"received",
"and",
"using",
"Asset",
"::",
"setContents",
"()",
"update",
"the",
"contents",
"accordingly",
".",
"If",
"it",
"fails",
"will",
"throw",
"PhassetsInternalException"
] | train | https://github.com/kattsoftware/phassets/blob/cc982cf1941eb5776287d64f027218bd4835ed2b/src/Phassets/Filters/ScssCompilerFilter.php#L42-L86 |
lode/fem | src/login_password.php | login_password.get_by_email | public static function get_by_email($email_address) {
$mysql = bootstrap::get_library('mysql');
$sql = "SELECT * FROM `login_passwords` WHERE `email_address` = '%s';";
$login = $mysql::select('row', $sql, $email_address);
if (empty($login)) {
return false;
}
return new static($login['id']);
} | php | public static function get_by_email($email_address) {
$mysql = bootstrap::get_library('mysql');
$sql = "SELECT * FROM `login_passwords` WHERE `email_address` = '%s';";
$login = $mysql::select('row', $sql, $email_address);
if (empty($login)) {
return false;
}
return new static($login['id']);
} | [
"public",
"static",
"function",
"get_by_email",
"(",
"$",
"email_address",
")",
"{",
"$",
"mysql",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'mysql'",
")",
";",
"$",
"sql",
"=",
"\"SELECT * FROM `login_passwords` WHERE `email_address` = '%s';\"",
";",
"$",
"login",
"=",
"$",
"mysql",
"::",
"select",
"(",
"'row'",
",",
"$",
"sql",
",",
"$",
"email_address",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"login",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"login",
"[",
"'id'",
"]",
")",
";",
"}"
] | checks whether the given email address match one on file
@param string $email_address
@return $this|boolean false when the email address is not found | [
"checks",
"whether",
"the",
"given",
"email",
"address",
"match",
"one",
"on",
"file"
] | train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_password.php#L74-L84 |
lode/fem | src/login_password.php | login_password.is_valid | public function is_valid($password, $check_rehash=true) {
if (password_verify($password, $this->data['hash']) == false) {
return false;
}
if ($check_rehash && password_needs_rehash($this->data['hash'], PASSWORD_DEFAULT)) {
$new_hash = self::hash_password($password);
$this->set_new_hash($this->data['user_id'], $this->data['email_address'], $new_hash);
}
return true;
} | php | public function is_valid($password, $check_rehash=true) {
if (password_verify($password, $this->data['hash']) == false) {
return false;
}
if ($check_rehash && password_needs_rehash($this->data['hash'], PASSWORD_DEFAULT)) {
$new_hash = self::hash_password($password);
$this->set_new_hash($this->data['user_id'], $this->data['email_address'], $new_hash);
}
return true;
} | [
"public",
"function",
"is_valid",
"(",
"$",
"password",
",",
"$",
"check_rehash",
"=",
"true",
")",
"{",
"if",
"(",
"password_verify",
"(",
"$",
"password",
",",
"$",
"this",
"->",
"data",
"[",
"'hash'",
"]",
")",
"==",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"check_rehash",
"&&",
"password_needs_rehash",
"(",
"$",
"this",
"->",
"data",
"[",
"'hash'",
"]",
",",
"PASSWORD_DEFAULT",
")",
")",
"{",
"$",
"new_hash",
"=",
"self",
"::",
"hash_password",
"(",
"$",
"password",
")",
";",
"$",
"this",
"->",
"set_new_hash",
"(",
"$",
"this",
"->",
"data",
"[",
"'user_id'",
"]",
",",
"$",
"this",
"->",
"data",
"[",
"'email_address'",
"]",
",",
"$",
"new_hash",
")",
";",
"}",
"return",
"true",
";",
"}"
] | check if the password gives access to the login
also re-hashes the password hash if the algorithm is out of date
@param string $password in plain text
@param boolean $check_rehash set to false to skip re-hashing
@return boolean | [
"check",
"if",
"the",
"password",
"gives",
"access",
"to",
"the",
"login",
"also",
"re",
"-",
"hashes",
"the",
"password",
"hash",
"if",
"the",
"algorithm",
"is",
"out",
"of",
"date"
] | train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_password.php#L94-L105 |
lode/fem | src/login_password.php | login_password.add | public function add($user_id, $email_address, $password) {
$mysql = bootstrap::get_library('mysql');
$sql = "INSERT INTO `login_passwords` SET `user_id` = %d, `email_address` = '%s';";
$binds = [$user_id, $email_address];
$mysql::query($sql, $binds);
$login = new static($mysql::$insert_id);
$hash = self::hash_password($password);
$login->set_new_hash($hash);
} | php | public function add($user_id, $email_address, $password) {
$mysql = bootstrap::get_library('mysql');
$sql = "INSERT INTO `login_passwords` SET `user_id` = %d, `email_address` = '%s';";
$binds = [$user_id, $email_address];
$mysql::query($sql, $binds);
$login = new static($mysql::$insert_id);
$hash = self::hash_password($password);
$login->set_new_hash($hash);
} | [
"public",
"function",
"add",
"(",
"$",
"user_id",
",",
"$",
"email_address",
",",
"$",
"password",
")",
"{",
"$",
"mysql",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'mysql'",
")",
";",
"$",
"sql",
"=",
"\"INSERT INTO `login_passwords` SET `user_id` = %d, `email_address` = '%s';\"",
";",
"$",
"binds",
"=",
"[",
"$",
"user_id",
",",
"$",
"email_address",
"]",
";",
"$",
"mysql",
"::",
"query",
"(",
"$",
"sql",
",",
"$",
"binds",
")",
";",
"$",
"login",
"=",
"new",
"static",
"(",
"$",
"mysql",
"::",
"$",
"insert_id",
")",
";",
"$",
"hash",
"=",
"self",
"::",
"hash_password",
"(",
"$",
"password",
")",
";",
"$",
"login",
"->",
"set_new_hash",
"(",
"$",
"hash",
")",
";",
"}"
] | adds a login
@param int $user_id
@param string $email_address
@param string $password in plain text | [
"adds",
"a",
"login"
] | train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_password.php#L123-L134 |
lode/fem | src/login_password.php | login_password.set_new_hash | public function set_new_hash($new_hash) {
$mysql = bootstrap::get_library('mysql');
$sql = "UPDATE `login_passwords` SET `hash` = '%s' WHERE `id` = %d;";
$binds = [$new_hash, $this->data['id']];
$mysql::query($sql, $binds);
$this->data['hash'] = $new_hash;
} | php | public function set_new_hash($new_hash) {
$mysql = bootstrap::get_library('mysql');
$sql = "UPDATE `login_passwords` SET `hash` = '%s' WHERE `id` = %d;";
$binds = [$new_hash, $this->data['id']];
$mysql::query($sql, $binds);
$this->data['hash'] = $new_hash;
} | [
"public",
"function",
"set_new_hash",
"(",
"$",
"new_hash",
")",
"{",
"$",
"mysql",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'mysql'",
")",
";",
"$",
"sql",
"=",
"\"UPDATE `login_passwords` SET `hash` = '%s' WHERE `id` = %d;\"",
";",
"$",
"binds",
"=",
"[",
"$",
"new_hash",
",",
"$",
"this",
"->",
"data",
"[",
"'id'",
"]",
"]",
";",
"$",
"mysql",
"::",
"query",
"(",
"$",
"sql",
",",
"$",
"binds",
")",
";",
"$",
"this",
"->",
"data",
"[",
"'hash'",
"]",
"=",
"$",
"new_hash",
";",
"}"
] | stores a new hash for the current login
@param string $new_hash
@return void | [
"stores",
"a",
"new",
"hash",
"for",
"the",
"current",
"login"
] | train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_password.php#L142-L150 |
lode/fem | src/login_password.php | login_password.hash_password | public static function hash_password($password) {
$exception = bootstrap::get_library('exception');
if (mb_strlen($password) < self::MINIMUM_LENGTH) {
throw new $exception('passwords need a minimum length of '.self::MINIMUM_LENGTH);
}
$hash = password_hash($password, PASSWORD_DEFAULT);
if (empty($hash)) {
throw new $exception('unable to hash password');
}
return $hash;
} | php | public static function hash_password($password) {
$exception = bootstrap::get_library('exception');
if (mb_strlen($password) < self::MINIMUM_LENGTH) {
throw new $exception('passwords need a minimum length of '.self::MINIMUM_LENGTH);
}
$hash = password_hash($password, PASSWORD_DEFAULT);
if (empty($hash)) {
throw new $exception('unable to hash password');
}
return $hash;
} | [
"public",
"static",
"function",
"hash_password",
"(",
"$",
"password",
")",
"{",
"$",
"exception",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'exception'",
")",
";",
"if",
"(",
"mb_strlen",
"(",
"$",
"password",
")",
"<",
"self",
"::",
"MINIMUM_LENGTH",
")",
"{",
"throw",
"new",
"$",
"exception",
"(",
"'passwords need a minimum length of '",
".",
"self",
"::",
"MINIMUM_LENGTH",
")",
";",
"}",
"$",
"hash",
"=",
"password_hash",
"(",
"$",
"password",
",",
"PASSWORD_DEFAULT",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"hash",
")",
")",
"{",
"throw",
"new",
"$",
"exception",
"(",
"'unable to hash password'",
")",
";",
"}",
"return",
"$",
"hash",
";",
"}"
] | generates a new hash for the given password
we wrap the native method to ensure a successful hash
also enforces a minimum length for passwords
@see ::MINIMUM_LENGTH
@param string $password
@return string | [
"generates",
"a",
"new",
"hash",
"for",
"the",
"given",
"password",
"we",
"wrap",
"the",
"native",
"method",
"to",
"ensure",
"a",
"successful",
"hash"
] | train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_password.php#L162-L175 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Controller/InstallController.php | InstallController.requirementsAction | public function requirementsAction()
{
// include symfony requirements class
$sAppPath = $this->getParameter('kernel.root_dir');
require_once $sAppPath.'/SymfonyRequirements.php';
$symfonyRequirements = new \SymfonyRequirements();
// add additional requirement for mcrypt
$symfonyRequirements->addRequirement(extension_loaded('mcrypt'), "Check if mcrypt ist loaded for RSA encryption", "Please enable mcrypt-Extension. See <a href='http://php.net/manual/de/mcrypt.setup.php'>http://php.net/manual/de/mcrypt.setup.php</a>");
// fetch all data
$aRequirements = $symfonyRequirements->getRequirements();
$aRecommendations = $symfonyRequirements->getRecommendations();
$aFailedRequirements = $symfonyRequirements->getFailedRequirements();
$aFailedRecommendations = $symfonyRequirements->getFailedRecommendations();
$iniPath = $symfonyRequirements->getPhpIniConfigPath();
// render template
return $this->render('SlashworksBackendBundle:Install:requirements.html.twig', array("iniPath" => $iniPath, "requirements" => $aRequirements, "recommendations" => $aRecommendations, "failedrequirements" => $aFailedRequirements, "failedrecommendations" => $aFailedRecommendations));
} | php | public function requirementsAction()
{
// include symfony requirements class
$sAppPath = $this->getParameter('kernel.root_dir');
require_once $sAppPath.'/SymfonyRequirements.php';
$symfonyRequirements = new \SymfonyRequirements();
// add additional requirement for mcrypt
$symfonyRequirements->addRequirement(extension_loaded('mcrypt'), "Check if mcrypt ist loaded for RSA encryption", "Please enable mcrypt-Extension. See <a href='http://php.net/manual/de/mcrypt.setup.php'>http://php.net/manual/de/mcrypt.setup.php</a>");
// fetch all data
$aRequirements = $symfonyRequirements->getRequirements();
$aRecommendations = $symfonyRequirements->getRecommendations();
$aFailedRequirements = $symfonyRequirements->getFailedRequirements();
$aFailedRecommendations = $symfonyRequirements->getFailedRecommendations();
$iniPath = $symfonyRequirements->getPhpIniConfigPath();
// render template
return $this->render('SlashworksBackendBundle:Install:requirements.html.twig', array("iniPath" => $iniPath, "requirements" => $aRequirements, "recommendations" => $aRecommendations, "failedrequirements" => $aFailedRequirements, "failedrecommendations" => $aFailedRecommendations));
} | [
"public",
"function",
"requirementsAction",
"(",
")",
"{",
"// include symfony requirements class",
"$",
"sAppPath",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'kernel.root_dir'",
")",
";",
"require_once",
"$",
"sAppPath",
".",
"'/SymfonyRequirements.php'",
";",
"$",
"symfonyRequirements",
"=",
"new",
"\\",
"SymfonyRequirements",
"(",
")",
";",
"// add additional requirement for mcrypt",
"$",
"symfonyRequirements",
"->",
"addRequirement",
"(",
"extension_loaded",
"(",
"'mcrypt'",
")",
",",
"\"Check if mcrypt ist loaded for RSA encryption\"",
",",
"\"Please enable mcrypt-Extension. See <a href='http://php.net/manual/de/mcrypt.setup.php'>http://php.net/manual/de/mcrypt.setup.php</a>\"",
")",
";",
"// fetch all data",
"$",
"aRequirements",
"=",
"$",
"symfonyRequirements",
"->",
"getRequirements",
"(",
")",
";",
"$",
"aRecommendations",
"=",
"$",
"symfonyRequirements",
"->",
"getRecommendations",
"(",
")",
";",
"$",
"aFailedRequirements",
"=",
"$",
"symfonyRequirements",
"->",
"getFailedRequirements",
"(",
")",
";",
"$",
"aFailedRecommendations",
"=",
"$",
"symfonyRequirements",
"->",
"getFailedRecommendations",
"(",
")",
";",
"$",
"iniPath",
"=",
"$",
"symfonyRequirements",
"->",
"getPhpIniConfigPath",
"(",
")",
";",
"// render template",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksBackendBundle:Install:requirements.html.twig'",
",",
"array",
"(",
"\"iniPath\"",
"=>",
"$",
"iniPath",
",",
"\"requirements\"",
"=>",
"$",
"aRequirements",
",",
"\"recommendations\"",
"=>",
"$",
"aRecommendations",
",",
"\"failedrequirements\"",
"=>",
"$",
"aFailedRequirements",
",",
"\"failedrecommendations\"",
"=>",
"$",
"aFailedRecommendations",
")",
")",
";",
"}"
] | Check System Requirements
@return \Symfony\Component\HttpFoundation\Response | [
"Check",
"System",
"Requirements"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Controller/InstallController.php#L43-L63 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Controller/InstallController.php | InstallController.installAction | public function installAction()
{
// create install form
$form = $this->createForm(new InstallType(), null, array('action' => $this->generateUrl('install_process')));
// redirect to login if config already filled
if ($this->container->getParameter('database_password') !== null) {
return $this->redirect($this->generateUrl('login'));
} else {
return $this->render('SlashworksBackendBundle:Install:install.html.twig', array("error" => false, "errorMessage" => false, "form" => $form->createView()));
}
} | php | public function installAction()
{
// create install form
$form = $this->createForm(new InstallType(), null, array('action' => $this->generateUrl('install_process')));
// redirect to login if config already filled
if ($this->container->getParameter('database_password') !== null) {
return $this->redirect($this->generateUrl('login'));
} else {
return $this->render('SlashworksBackendBundle:Install:install.html.twig', array("error" => false, "errorMessage" => false, "form" => $form->createView()));
}
} | [
"public",
"function",
"installAction",
"(",
")",
"{",
"// create install form",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"InstallType",
"(",
")",
",",
"null",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'install_process'",
")",
")",
")",
";",
"// redirect to login if config already filled",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'database_password'",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'login'",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksBackendBundle:Install:install.html.twig'",
",",
"array",
"(",
"\"error\"",
"=>",
"false",
",",
"\"errorMessage\"",
"=>",
"false",
",",
"\"form\"",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
")",
")",
";",
"}",
"}"
] | Display install form
@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response | [
"Display",
"install",
"form"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Controller/InstallController.php#L96-L108 |
slashworks/control-bundle | src/Slashworks/BackendBundle/Controller/InstallController.php | InstallController.processInstallAction | public function processInstallAction(Request $request)
{
// include symfony requirements class
$sAppPath = $this->getParameter('kernel.root_dir');
require_once $sAppPath.'/SymfonyRequirements.php';
// prevent from being called directly after install...
if ($this->container->getParameter('database_password') !== null) {
return $this->redirect($this->generateUrl('login'));
}
// get form type for validation
$form = $this->createForm(new InstallType(), null, array('action' => $this->generateUrl('install_process')));
$form->handleRequest($request);
if ($form->isValid()) {
try {
// get data and do install
$aData = $request->request->all();
InstallHelper::doInstall($this->container, $aData);
// goto login if successful
return $this->redirect($this->generateUrl('login'));
} catch (\Exception $e) {
return $this->render('SlashworksBackendBundle:Install:install.html.twig', array("form" => $form->createView(), "error" => true, "errorMessage" => $e->getMessage()));
}
} else {
return $this->render('SlashworksBackendBundle:Install:install.html.twig', array("form" => $form->createView(), "error" => true, "errorMessage" => false));
}
} | php | public function processInstallAction(Request $request)
{
// include symfony requirements class
$sAppPath = $this->getParameter('kernel.root_dir');
require_once $sAppPath.'/SymfonyRequirements.php';
// prevent from being called directly after install...
if ($this->container->getParameter('database_password') !== null) {
return $this->redirect($this->generateUrl('login'));
}
// get form type for validation
$form = $this->createForm(new InstallType(), null, array('action' => $this->generateUrl('install_process')));
$form->handleRequest($request);
if ($form->isValid()) {
try {
// get data and do install
$aData = $request->request->all();
InstallHelper::doInstall($this->container, $aData);
// goto login if successful
return $this->redirect($this->generateUrl('login'));
} catch (\Exception $e) {
return $this->render('SlashworksBackendBundle:Install:install.html.twig', array("form" => $form->createView(), "error" => true, "errorMessage" => $e->getMessage()));
}
} else {
return $this->render('SlashworksBackendBundle:Install:install.html.twig', array("form" => $form->createView(), "error" => true, "errorMessage" => false));
}
} | [
"public",
"function",
"processInstallAction",
"(",
"Request",
"$",
"request",
")",
"{",
"// include symfony requirements class",
"$",
"sAppPath",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'kernel.root_dir'",
")",
";",
"require_once",
"$",
"sAppPath",
".",
"'/SymfonyRequirements.php'",
";",
"// prevent from being called directly after install...",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'database_password'",
")",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'login'",
")",
")",
";",
"}",
"// get form type for validation",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"InstallType",
"(",
")",
",",
"null",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'install_process'",
")",
")",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"try",
"{",
"// get data and do install",
"$",
"aData",
"=",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"InstallHelper",
"::",
"doInstall",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"aData",
")",
";",
"// goto login if successful",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'login'",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksBackendBundle:Install:install.html.twig'",
",",
"array",
"(",
"\"form\"",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"\"error\"",
"=>",
"true",
",",
"\"errorMessage\"",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksBackendBundle:Install:install.html.twig'",
",",
"array",
"(",
"\"form\"",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"\"error\"",
"=>",
"true",
",",
"\"errorMessage\"",
"=>",
"false",
")",
")",
";",
"}",
"}"
] | Process provided informations and perform installation
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response | [
"Process",
"provided",
"informations",
"and",
"perform",
"installation"
] | train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/BackendBundle/Controller/InstallController.php#L118-L150 |
transfer-framework/ezplatform | src/Transfer/EzPlatform/Repository/Manager/UserGroupManager.php | UserGroupManager.find | public function find(ValueObject $object, $throwException = false)
{
try {
if (isset($object->data['remote_id'])) {
$contentObject = $this->contentService->loadContentByRemoteId($object->data['remote_id']);
$userGroup = $this->userService->loadUserGroup($contentObject->contentInfo->id);
} elseif ($object->getProperty('id')) {
$userGroup = $this->userService->loadUserGroup($object->getProperty('id'));
}
} catch (NotFoundException $notFoundException) {
// We'll throw our own exception later instead.
}
if (!isset($userGroup)) {
throw new ObjectNotFoundException(UserGroup::class, array('remote_id', 'id'));
}
return $userGroup;
} | php | public function find(ValueObject $object, $throwException = false)
{
try {
if (isset($object->data['remote_id'])) {
$contentObject = $this->contentService->loadContentByRemoteId($object->data['remote_id']);
$userGroup = $this->userService->loadUserGroup($contentObject->contentInfo->id);
} elseif ($object->getProperty('id')) {
$userGroup = $this->userService->loadUserGroup($object->getProperty('id'));
}
} catch (NotFoundException $notFoundException) {
// We'll throw our own exception later instead.
}
if (!isset($userGroup)) {
throw new ObjectNotFoundException(UserGroup::class, array('remote_id', 'id'));
}
return $userGroup;
} | [
"public",
"function",
"find",
"(",
"ValueObject",
"$",
"object",
",",
"$",
"throwException",
"=",
"false",
")",
"{",
"try",
"{",
"if",
"(",
"isset",
"(",
"$",
"object",
"->",
"data",
"[",
"'remote_id'",
"]",
")",
")",
"{",
"$",
"contentObject",
"=",
"$",
"this",
"->",
"contentService",
"->",
"loadContentByRemoteId",
"(",
"$",
"object",
"->",
"data",
"[",
"'remote_id'",
"]",
")",
";",
"$",
"userGroup",
"=",
"$",
"this",
"->",
"userService",
"->",
"loadUserGroup",
"(",
"$",
"contentObject",
"->",
"contentInfo",
"->",
"id",
")",
";",
"}",
"elseif",
"(",
"$",
"object",
"->",
"getProperty",
"(",
"'id'",
")",
")",
"{",
"$",
"userGroup",
"=",
"$",
"this",
"->",
"userService",
"->",
"loadUserGroup",
"(",
"$",
"object",
"->",
"getProperty",
"(",
"'id'",
")",
")",
";",
"}",
"}",
"catch",
"(",
"NotFoundException",
"$",
"notFoundException",
")",
"{",
"// We'll throw our own exception later instead.",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"userGroup",
")",
")",
"{",
"throw",
"new",
"ObjectNotFoundException",
"(",
"UserGroup",
"::",
"class",
",",
"array",
"(",
"'remote_id'",
",",
"'id'",
")",
")",
";",
"}",
"return",
"$",
"userGroup",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/UserGroupManager.php#L86-L104 |
transfer-framework/ezplatform | src/Transfer/EzPlatform/Repository/Manager/UserGroupManager.php | UserGroupManager.create | public function create(ObjectInterface $object)
{
if (!$object instanceof UserGroupObject) {
throw new UnsupportedObjectOperationException(UserGroupObject::class, get_class($object));
}
$this->ensureDefaults($object);
$parentUserGroup = $this->findById($object->data['parent_id'], true);
// Instantiate usergroup
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($object->data['content_type_identifier']);
$userGroupCreateStruct = $this->userService->newUserGroupCreateStruct(
$object->data['main_language_code'],
$contentType
);
// Populate usergroup fields
$object->getMapper()->mapObjectToCreateStruct($userGroupCreateStruct);
// Create usergroup
$userGroup = $this->userService->createUserGroup($userGroupCreateStruct, $parentUserGroup);
$object->getMapper()->userGroupToObject($userGroup);
return $object;
} | php | public function create(ObjectInterface $object)
{
if (!$object instanceof UserGroupObject) {
throw new UnsupportedObjectOperationException(UserGroupObject::class, get_class($object));
}
$this->ensureDefaults($object);
$parentUserGroup = $this->findById($object->data['parent_id'], true);
// Instantiate usergroup
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($object->data['content_type_identifier']);
$userGroupCreateStruct = $this->userService->newUserGroupCreateStruct(
$object->data['main_language_code'],
$contentType
);
// Populate usergroup fields
$object->getMapper()->mapObjectToCreateStruct($userGroupCreateStruct);
// Create usergroup
$userGroup = $this->userService->createUserGroup($userGroupCreateStruct, $parentUserGroup);
$object->getMapper()->userGroupToObject($userGroup);
return $object;
} | [
"public",
"function",
"create",
"(",
"ObjectInterface",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"UserGroupObject",
")",
"{",
"throw",
"new",
"UnsupportedObjectOperationException",
"(",
"UserGroupObject",
"::",
"class",
",",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"}",
"$",
"this",
"->",
"ensureDefaults",
"(",
"$",
"object",
")",
";",
"$",
"parentUserGroup",
"=",
"$",
"this",
"->",
"findById",
"(",
"$",
"object",
"->",
"data",
"[",
"'parent_id'",
"]",
",",
"true",
")",
";",
"// Instantiate usergroup",
"$",
"contentType",
"=",
"$",
"this",
"->",
"contentTypeService",
"->",
"loadContentTypeByIdentifier",
"(",
"$",
"object",
"->",
"data",
"[",
"'content_type_identifier'",
"]",
")",
";",
"$",
"userGroupCreateStruct",
"=",
"$",
"this",
"->",
"userService",
"->",
"newUserGroupCreateStruct",
"(",
"$",
"object",
"->",
"data",
"[",
"'main_language_code'",
"]",
",",
"$",
"contentType",
")",
";",
"// Populate usergroup fields",
"$",
"object",
"->",
"getMapper",
"(",
")",
"->",
"mapObjectToCreateStruct",
"(",
"$",
"userGroupCreateStruct",
")",
";",
"// Create usergroup",
"$",
"userGroup",
"=",
"$",
"this",
"->",
"userService",
"->",
"createUserGroup",
"(",
"$",
"userGroupCreateStruct",
",",
"$",
"parentUserGroup",
")",
";",
"$",
"object",
"->",
"getMapper",
"(",
")",
"->",
"userGroupToObject",
"(",
"$",
"userGroup",
")",
";",
"return",
"$",
"object",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/UserGroupManager.php#L124-L150 |
transfer-framework/ezplatform | src/Transfer/EzPlatform/Repository/Manager/UserGroupManager.php | UserGroupManager.update | public function update(ObjectInterface $object)
{
if (!$object instanceof UserGroupObject) {
throw new UnsupportedObjectOperationException(UserGroupObject::class, get_class($object));
}
$userGroup = $this->find($object, true);
$this->ensureDefaults($object);
$userGroupUpdateStruct = $this->userService->newUserGroupUpdateStruct();
$userGroupUpdateStruct->contentUpdateStruct = $this->contentService->newContentUpdateStruct();
$object->getMapper()->mapObjectToUpdateStruct($userGroupUpdateStruct);
$userGroup = $this->userService->updateUserGroup($userGroup, $userGroupUpdateStruct);
if ($userGroup->parentId !== $object->data['parent_id']) {
$newParentGroup = $this->findById($object->data['parent_id'], true);
$this->userService->moveUserGroup($userGroup, $newParentGroup);
$userGroup = $this->find($object, true);
}
$object->getMapper()->userGroupToObject($userGroup);
return $object;
} | php | public function update(ObjectInterface $object)
{
if (!$object instanceof UserGroupObject) {
throw new UnsupportedObjectOperationException(UserGroupObject::class, get_class($object));
}
$userGroup = $this->find($object, true);
$this->ensureDefaults($object);
$userGroupUpdateStruct = $this->userService->newUserGroupUpdateStruct();
$userGroupUpdateStruct->contentUpdateStruct = $this->contentService->newContentUpdateStruct();
$object->getMapper()->mapObjectToUpdateStruct($userGroupUpdateStruct);
$userGroup = $this->userService->updateUserGroup($userGroup, $userGroupUpdateStruct);
if ($userGroup->parentId !== $object->data['parent_id']) {
$newParentGroup = $this->findById($object->data['parent_id'], true);
$this->userService->moveUserGroup($userGroup, $newParentGroup);
$userGroup = $this->find($object, true);
}
$object->getMapper()->userGroupToObject($userGroup);
return $object;
} | [
"public",
"function",
"update",
"(",
"ObjectInterface",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"UserGroupObject",
")",
"{",
"throw",
"new",
"UnsupportedObjectOperationException",
"(",
"UserGroupObject",
"::",
"class",
",",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"}",
"$",
"userGroup",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"object",
",",
"true",
")",
";",
"$",
"this",
"->",
"ensureDefaults",
"(",
"$",
"object",
")",
";",
"$",
"userGroupUpdateStruct",
"=",
"$",
"this",
"->",
"userService",
"->",
"newUserGroupUpdateStruct",
"(",
")",
";",
"$",
"userGroupUpdateStruct",
"->",
"contentUpdateStruct",
"=",
"$",
"this",
"->",
"contentService",
"->",
"newContentUpdateStruct",
"(",
")",
";",
"$",
"object",
"->",
"getMapper",
"(",
")",
"->",
"mapObjectToUpdateStruct",
"(",
"$",
"userGroupUpdateStruct",
")",
";",
"$",
"userGroup",
"=",
"$",
"this",
"->",
"userService",
"->",
"updateUserGroup",
"(",
"$",
"userGroup",
",",
"$",
"userGroupUpdateStruct",
")",
";",
"if",
"(",
"$",
"userGroup",
"->",
"parentId",
"!==",
"$",
"object",
"->",
"data",
"[",
"'parent_id'",
"]",
")",
"{",
"$",
"newParentGroup",
"=",
"$",
"this",
"->",
"findById",
"(",
"$",
"object",
"->",
"data",
"[",
"'parent_id'",
"]",
",",
"true",
")",
";",
"$",
"this",
"->",
"userService",
"->",
"moveUserGroup",
"(",
"$",
"userGroup",
",",
"$",
"newParentGroup",
")",
";",
"$",
"userGroup",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"object",
",",
"true",
")",
";",
"}",
"$",
"object",
"->",
"getMapper",
"(",
")",
"->",
"userGroupToObject",
"(",
"$",
"userGroup",
")",
";",
"return",
"$",
"object",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/UserGroupManager.php#L155-L181 |
transfer-framework/ezplatform | src/Transfer/EzPlatform/Repository/Manager/UserGroupManager.php | UserGroupManager.remove | public function remove(ObjectInterface $object)
{
if (!$object instanceof UserGroupObject) {
throw new UnsupportedObjectOperationException(UserGroupObject::class, get_class($object));
}
try {
$userGroup = $this->find($object);
$this->userService->deleteUserGroup($userGroup);
return true;
} catch (NotFoundException $notFound) {
return false;
}
} | php | public function remove(ObjectInterface $object)
{
if (!$object instanceof UserGroupObject) {
throw new UnsupportedObjectOperationException(UserGroupObject::class, get_class($object));
}
try {
$userGroup = $this->find($object);
$this->userService->deleteUserGroup($userGroup);
return true;
} catch (NotFoundException $notFound) {
return false;
}
} | [
"public",
"function",
"remove",
"(",
"ObjectInterface",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"UserGroupObject",
")",
"{",
"throw",
"new",
"UnsupportedObjectOperationException",
"(",
"UserGroupObject",
"::",
"class",
",",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"}",
"try",
"{",
"$",
"userGroup",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"object",
")",
";",
"$",
"this",
"->",
"userService",
"->",
"deleteUserGroup",
"(",
"$",
"userGroup",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"notFound",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Manager/UserGroupManager.php#L204-L218 |
joomlatools/joomlatools-platform-legacy | code/request/request.php | JRequest.getVar | public static function getVar($name, $default = null, $hash = 'default', $type = 'none', $mask = 0)
{
// Ensure hash and type are uppercase
$hash = strtoupper($hash);
if ($hash === 'METHOD')
{
$hash = strtoupper($_SERVER['REQUEST_METHOD']);
}
$type = strtoupper($type);
$sig = $hash . $type . $mask;
// Get the input hash
switch ($hash)
{
case 'GET':
$input = &$_GET;
break;
case 'POST':
$input = &$_POST;
break;
case 'FILES':
$input = &$_FILES;
break;
case 'COOKIE':
$input = &$_COOKIE;
break;
case 'ENV':
$input = &$_ENV;
break;
case 'SERVER':
$input = &$_SERVER;
break;
default:
$input = &$_REQUEST;
$hash = 'REQUEST';
break;
}
if (isset($GLOBALS['_JREQUEST'][$name]['SET.' . $hash]) && ($GLOBALS['_JREQUEST'][$name]['SET.' . $hash] === true))
{
// Get the variable from the input hash
$var = (isset($input[$name]) && $input[$name] !== null) ? $input[$name] : $default;
$var = self::_cleanVar($var, $mask, $type);
}
elseif (!isset($GLOBALS['_JREQUEST'][$name][$sig]))
{
if (isset($input[$name]) && $input[$name] !== null)
{
// Get the variable from the input hash and clean it
$var = self::_cleanVar($input[$name], $mask, $type);
$GLOBALS['_JREQUEST'][$name][$sig] = $var;
}
elseif ($default !== null)
{
// Clean the default value
$var = self::_cleanVar($default, $mask, $type);
}
else
{
$var = $default;
}
}
else
{
$var = $GLOBALS['_JREQUEST'][$name][$sig];
}
return $var;
} | php | public static function getVar($name, $default = null, $hash = 'default', $type = 'none', $mask = 0)
{
// Ensure hash and type are uppercase
$hash = strtoupper($hash);
if ($hash === 'METHOD')
{
$hash = strtoupper($_SERVER['REQUEST_METHOD']);
}
$type = strtoupper($type);
$sig = $hash . $type . $mask;
// Get the input hash
switch ($hash)
{
case 'GET':
$input = &$_GET;
break;
case 'POST':
$input = &$_POST;
break;
case 'FILES':
$input = &$_FILES;
break;
case 'COOKIE':
$input = &$_COOKIE;
break;
case 'ENV':
$input = &$_ENV;
break;
case 'SERVER':
$input = &$_SERVER;
break;
default:
$input = &$_REQUEST;
$hash = 'REQUEST';
break;
}
if (isset($GLOBALS['_JREQUEST'][$name]['SET.' . $hash]) && ($GLOBALS['_JREQUEST'][$name]['SET.' . $hash] === true))
{
// Get the variable from the input hash
$var = (isset($input[$name]) && $input[$name] !== null) ? $input[$name] : $default;
$var = self::_cleanVar($var, $mask, $type);
}
elseif (!isset($GLOBALS['_JREQUEST'][$name][$sig]))
{
if (isset($input[$name]) && $input[$name] !== null)
{
// Get the variable from the input hash and clean it
$var = self::_cleanVar($input[$name], $mask, $type);
$GLOBALS['_JREQUEST'][$name][$sig] = $var;
}
elseif ($default !== null)
{
// Clean the default value
$var = self::_cleanVar($default, $mask, $type);
}
else
{
$var = $default;
}
}
else
{
$var = $GLOBALS['_JREQUEST'][$name][$sig];
}
return $var;
} | [
"public",
"static",
"function",
"getVar",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
",",
"$",
"hash",
"=",
"'default'",
",",
"$",
"type",
"=",
"'none'",
",",
"$",
"mask",
"=",
"0",
")",
"{",
"// Ensure hash and type are uppercase",
"$",
"hash",
"=",
"strtoupper",
"(",
"$",
"hash",
")",
";",
"if",
"(",
"$",
"hash",
"===",
"'METHOD'",
")",
"{",
"$",
"hash",
"=",
"strtoupper",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
";",
"}",
"$",
"type",
"=",
"strtoupper",
"(",
"$",
"type",
")",
";",
"$",
"sig",
"=",
"$",
"hash",
".",
"$",
"type",
".",
"$",
"mask",
";",
"// Get the input hash",
"switch",
"(",
"$",
"hash",
")",
"{",
"case",
"'GET'",
":",
"$",
"input",
"=",
"&",
"$",
"_GET",
";",
"break",
";",
"case",
"'POST'",
":",
"$",
"input",
"=",
"&",
"$",
"_POST",
";",
"break",
";",
"case",
"'FILES'",
":",
"$",
"input",
"=",
"&",
"$",
"_FILES",
";",
"break",
";",
"case",
"'COOKIE'",
":",
"$",
"input",
"=",
"&",
"$",
"_COOKIE",
";",
"break",
";",
"case",
"'ENV'",
":",
"$",
"input",
"=",
"&",
"$",
"_ENV",
";",
"break",
";",
"case",
"'SERVER'",
":",
"$",
"input",
"=",
"&",
"$",
"_SERVER",
";",
"break",
";",
"default",
":",
"$",
"input",
"=",
"&",
"$",
"_REQUEST",
";",
"$",
"hash",
"=",
"'REQUEST'",
";",
"break",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'_JREQUEST'",
"]",
"[",
"$",
"name",
"]",
"[",
"'SET.'",
".",
"$",
"hash",
"]",
")",
"&&",
"(",
"$",
"GLOBALS",
"[",
"'_JREQUEST'",
"]",
"[",
"$",
"name",
"]",
"[",
"'SET.'",
".",
"$",
"hash",
"]",
"===",
"true",
")",
")",
"{",
"// Get the variable from the input hash",
"$",
"var",
"=",
"(",
"isset",
"(",
"$",
"input",
"[",
"$",
"name",
"]",
")",
"&&",
"$",
"input",
"[",
"$",
"name",
"]",
"!==",
"null",
")",
"?",
"$",
"input",
"[",
"$",
"name",
"]",
":",
"$",
"default",
";",
"$",
"var",
"=",
"self",
"::",
"_cleanVar",
"(",
"$",
"var",
",",
"$",
"mask",
",",
"$",
"type",
")",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'_JREQUEST'",
"]",
"[",
"$",
"name",
"]",
"[",
"$",
"sig",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"input",
"[",
"$",
"name",
"]",
")",
"&&",
"$",
"input",
"[",
"$",
"name",
"]",
"!==",
"null",
")",
"{",
"// Get the variable from the input hash and clean it",
"$",
"var",
"=",
"self",
"::",
"_cleanVar",
"(",
"$",
"input",
"[",
"$",
"name",
"]",
",",
"$",
"mask",
",",
"$",
"type",
")",
";",
"$",
"GLOBALS",
"[",
"'_JREQUEST'",
"]",
"[",
"$",
"name",
"]",
"[",
"$",
"sig",
"]",
"=",
"$",
"var",
";",
"}",
"elseif",
"(",
"$",
"default",
"!==",
"null",
")",
"{",
"// Clean the default value",
"$",
"var",
"=",
"self",
"::",
"_cleanVar",
"(",
"$",
"default",
",",
"$",
"mask",
",",
"$",
"type",
")",
";",
"}",
"else",
"{",
"$",
"var",
"=",
"$",
"default",
";",
"}",
"}",
"else",
"{",
"$",
"var",
"=",
"$",
"GLOBALS",
"[",
"'_JREQUEST'",
"]",
"[",
"$",
"name",
"]",
"[",
"$",
"sig",
"]",
";",
"}",
"return",
"$",
"var",
";",
"}"
] | Fetches and returns a given variable.
The default behaviour is fetching variables depending on the
current request method: GET and HEAD will result in returning
an entry from $_GET, POST and PUT will result in returning an
entry from $_POST.
You can force the source by setting the $hash parameter:
post $_POST
get $_GET
files $_FILES
cookie $_COOKIE
env $_ENV
server $_SERVER
method via current $_SERVER['REQUEST_METHOD']
default $_REQUEST
@param string $name Variable name.
@param string $default Default value if the variable does not exist.
@param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD).
@param string $type Return type for the variable, for valid values see {@link JFilterInput::clean()}.
@param integer $mask Filter mask for the variable.
@return mixed Requested variable.
@since 11.1
@deprecated 12.1 Use JInput::Get | [
"Fetches",
"and",
"returns",
"a",
"given",
"variable",
"."
] | train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/request/request.php#L101-L172 |
joomlatools/joomlatools-platform-legacy | code/request/request.php | JRequest.getString | public static function getString($name, $default = '', $hash = 'default', $mask = 0)
{
// Cast to string, in case JREQUEST_ALLOWRAW was specified for mask
return (string) self::getVar($name, $default, $hash, 'string', $mask);
} | php | public static function getString($name, $default = '', $hash = 'default', $mask = 0)
{
// Cast to string, in case JREQUEST_ALLOWRAW was specified for mask
return (string) self::getVar($name, $default, $hash, 'string', $mask);
} | [
"public",
"static",
"function",
"getString",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"''",
",",
"$",
"hash",
"=",
"'default'",
",",
"$",
"mask",
"=",
"0",
")",
"{",
"// Cast to string, in case JREQUEST_ALLOWRAW was specified for mask",
"return",
"(",
"string",
")",
"self",
"::",
"getVar",
"(",
"$",
"name",
",",
"$",
"default",
",",
"$",
"hash",
",",
"'string'",
",",
"$",
"mask",
")",
";",
"}"
] | Fetches and returns a given filtered variable. The string
filter deletes 'bad' HTML code, if not overridden by the mask.
This is currently only a proxy function for getVar().
See getVar() for more in-depth documentation on the parameters.
@param string $name Variable name
@param string $default Default value if the variable does not exist
@param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD)
@param integer $mask Filter mask for the variable
@return string Requested variable
@since 11.1
@deprecated 12.1 | [
"Fetches",
"and",
"returns",
"a",
"given",
"filtered",
"variable",
".",
"The",
"string",
"filter",
"deletes",
"bad",
"HTML",
"code",
"if",
"not",
"overridden",
"by",
"the",
"mask",
".",
"This",
"is",
"currently",
"only",
"a",
"proxy",
"function",
"for",
"getVar",
"()",
"."
] | train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/request/request.php#L323-L327 |
joomlatools/joomlatools-platform-legacy | code/request/request.php | JRequest.setVar | public static function setVar($name, $value = null, $hash = 'method', $overwrite = true)
{
// If overwrite is true, makes sure the variable hasn't been set yet
if (!$overwrite && array_key_exists($name, $_REQUEST))
{
return $_REQUEST[$name];
}
// Clean global request var
$GLOBALS['_JREQUEST'][$name] = array();
// Get the request hash value
$hash = strtoupper($hash);
if ($hash === 'METHOD')
{
$hash = strtoupper($_SERVER['REQUEST_METHOD']);
}
$previous = array_key_exists($name, $_REQUEST) ? $_REQUEST[$name] : null;
switch ($hash)
{
case 'GET':
$_GET[$name] = $value;
$_REQUEST[$name] = $value;
break;
case 'POST':
$_POST[$name] = $value;
$_REQUEST[$name] = $value;
break;
case 'COOKIE':
$_COOKIE[$name] = $value;
$_REQUEST[$name] = $value;
break;
case 'FILES':
$_FILES[$name] = $value;
break;
case 'ENV':
$_ENV[$name] = $value;
break;
case 'SERVER':
$_SERVER[$name] = $value;
break;
}
// Mark this variable as 'SET'
$GLOBALS['_JREQUEST'][$name]['SET.' . $hash] = true;
$GLOBALS['_JREQUEST'][$name]['SET.REQUEST'] = true;
return $previous;
} | php | public static function setVar($name, $value = null, $hash = 'method', $overwrite = true)
{
// If overwrite is true, makes sure the variable hasn't been set yet
if (!$overwrite && array_key_exists($name, $_REQUEST))
{
return $_REQUEST[$name];
}
// Clean global request var
$GLOBALS['_JREQUEST'][$name] = array();
// Get the request hash value
$hash = strtoupper($hash);
if ($hash === 'METHOD')
{
$hash = strtoupper($_SERVER['REQUEST_METHOD']);
}
$previous = array_key_exists($name, $_REQUEST) ? $_REQUEST[$name] : null;
switch ($hash)
{
case 'GET':
$_GET[$name] = $value;
$_REQUEST[$name] = $value;
break;
case 'POST':
$_POST[$name] = $value;
$_REQUEST[$name] = $value;
break;
case 'COOKIE':
$_COOKIE[$name] = $value;
$_REQUEST[$name] = $value;
break;
case 'FILES':
$_FILES[$name] = $value;
break;
case 'ENV':
$_ENV[$name] = $value;
break;
case 'SERVER':
$_SERVER[$name] = $value;
break;
}
// Mark this variable as 'SET'
$GLOBALS['_JREQUEST'][$name]['SET.' . $hash] = true;
$GLOBALS['_JREQUEST'][$name]['SET.REQUEST'] = true;
return $previous;
} | [
"public",
"static",
"function",
"setVar",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"$",
"hash",
"=",
"'method'",
",",
"$",
"overwrite",
"=",
"true",
")",
"{",
"// If overwrite is true, makes sure the variable hasn't been set yet",
"if",
"(",
"!",
"$",
"overwrite",
"&&",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"_REQUEST",
")",
")",
"{",
"return",
"$",
"_REQUEST",
"[",
"$",
"name",
"]",
";",
"}",
"// Clean global request var",
"$",
"GLOBALS",
"[",
"'_JREQUEST'",
"]",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
")",
";",
"// Get the request hash value",
"$",
"hash",
"=",
"strtoupper",
"(",
"$",
"hash",
")",
";",
"if",
"(",
"$",
"hash",
"===",
"'METHOD'",
")",
"{",
"$",
"hash",
"=",
"strtoupper",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
";",
"}",
"$",
"previous",
"=",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"_REQUEST",
")",
"?",
"$",
"_REQUEST",
"[",
"$",
"name",
"]",
":",
"null",
";",
"switch",
"(",
"$",
"hash",
")",
"{",
"case",
"'GET'",
":",
"$",
"_GET",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"$",
"_REQUEST",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'POST'",
":",
"$",
"_POST",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"$",
"_REQUEST",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'COOKIE'",
":",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"$",
"_REQUEST",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'FILES'",
":",
"$",
"_FILES",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'ENV'",
":",
"$",
"_ENV",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'SERVER'",
":",
"$",
"_SERVER",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"break",
";",
"}",
"// Mark this variable as 'SET'",
"$",
"GLOBALS",
"[",
"'_JREQUEST'",
"]",
"[",
"$",
"name",
"]",
"[",
"'SET.'",
".",
"$",
"hash",
"]",
"=",
"true",
";",
"$",
"GLOBALS",
"[",
"'_JREQUEST'",
"]",
"[",
"$",
"name",
"]",
"[",
"'SET.REQUEST'",
"]",
"=",
"true",
";",
"return",
"$",
"previous",
";",
"}"
] | Set a variable in one of the request variables.
@param string $name Name
@param string $value Value
@param string $hash Hash
@param boolean $overwrite Boolean
@return string Previous value
@since 11.1
@deprecated 12.1 | [
"Set",
"a",
"variable",
"in",
"one",
"of",
"the",
"request",
"variables",
"."
] | train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/request/request.php#L343-L394 |
joomlatools/joomlatools-platform-legacy | code/request/request.php | JRequest.get | public static function get($hash = 'default', $mask = 0)
{
$hash = strtoupper($hash);
if ($hash === 'METHOD')
{
$hash = strtoupper($_SERVER['REQUEST_METHOD']);
}
switch ($hash)
{
case 'GET':
$input = $_GET;
break;
case 'POST':
$input = $_POST;
break;
case 'FILES':
$input = $_FILES;
break;
case 'COOKIE':
$input = $_COOKIE;
break;
case 'ENV':
$input = &$_ENV;
break;
case 'SERVER':
$input = &$_SERVER;
break;
default:
$input = $_REQUEST;
break;
}
$result = self::_cleanVar($input, $mask);
return $result;
} | php | public static function get($hash = 'default', $mask = 0)
{
$hash = strtoupper($hash);
if ($hash === 'METHOD')
{
$hash = strtoupper($_SERVER['REQUEST_METHOD']);
}
switch ($hash)
{
case 'GET':
$input = $_GET;
break;
case 'POST':
$input = $_POST;
break;
case 'FILES':
$input = $_FILES;
break;
case 'COOKIE':
$input = $_COOKIE;
break;
case 'ENV':
$input = &$_ENV;
break;
case 'SERVER':
$input = &$_SERVER;
break;
default:
$input = $_REQUEST;
break;
}
$result = self::_cleanVar($input, $mask);
return $result;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"hash",
"=",
"'default'",
",",
"$",
"mask",
"=",
"0",
")",
"{",
"$",
"hash",
"=",
"strtoupper",
"(",
"$",
"hash",
")",
";",
"if",
"(",
"$",
"hash",
"===",
"'METHOD'",
")",
"{",
"$",
"hash",
"=",
"strtoupper",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
";",
"}",
"switch",
"(",
"$",
"hash",
")",
"{",
"case",
"'GET'",
":",
"$",
"input",
"=",
"$",
"_GET",
";",
"break",
";",
"case",
"'POST'",
":",
"$",
"input",
"=",
"$",
"_POST",
";",
"break",
";",
"case",
"'FILES'",
":",
"$",
"input",
"=",
"$",
"_FILES",
";",
"break",
";",
"case",
"'COOKIE'",
":",
"$",
"input",
"=",
"$",
"_COOKIE",
";",
"break",
";",
"case",
"'ENV'",
":",
"$",
"input",
"=",
"&",
"$",
"_ENV",
";",
"break",
";",
"case",
"'SERVER'",
":",
"$",
"input",
"=",
"&",
"$",
"_SERVER",
";",
"break",
";",
"default",
":",
"$",
"input",
"=",
"$",
"_REQUEST",
";",
"break",
";",
"}",
"$",
"result",
"=",
"self",
"::",
"_cleanVar",
"(",
"$",
"input",
",",
"$",
"mask",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Fetches and returns a request array.
The default behaviour is fetching variables depending on the
current request method: GET and HEAD will result in returning
$_GET, POST and PUT will result in returning $_POST.
You can force the source by setting the $hash parameter:
post $_POST
get $_GET
files $_FILES
cookie $_COOKIE
env $_ENV
server $_SERVER
method via current $_SERVER['REQUEST_METHOD']
default $_REQUEST
@param string $hash to get (POST, GET, FILES, METHOD).
@param integer $mask Filter mask for the variable.
@return mixed Request hash.
@deprecated 12.1 User JInput::get
@see JInput
@since 11.1 | [
"Fetches",
"and",
"returns",
"a",
"request",
"array",
"."
] | train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/request/request.php#L423-L466 |
joomlatools/joomlatools-platform-legacy | code/request/request.php | JRequest.set | public static function set($array, $hash = 'default', $overwrite = true)
{
foreach ($array as $key => $value)
{
self::setVar($key, $value, $hash, $overwrite);
}
} | php | public static function set($array, $hash = 'default', $overwrite = true)
{
foreach ($array as $key => $value)
{
self::setVar($key, $value, $hash, $overwrite);
}
} | [
"public",
"static",
"function",
"set",
"(",
"$",
"array",
",",
"$",
"hash",
"=",
"'default'",
",",
"$",
"overwrite",
"=",
"true",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"self",
"::",
"setVar",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"hash",
",",
"$",
"overwrite",
")",
";",
"}",
"}"
] | Sets a request variable.
@param array $array An associative array of key-value pairs.
@param string $hash The request variable to set (POST, GET, FILES, METHOD).
@param boolean $overwrite If true and an existing key is found, the value is overwritten, otherwise it is ignored.
@return void
@deprecated 12.1 Use JInput::set()
@see JInput::set()
@since 11.1 | [
"Sets",
"a",
"request",
"variable",
"."
] | train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/request/request.php#L481-L487 |
joomlatools/joomlatools-platform-legacy | code/request/request.php | JRequest._cleanVar | protected static function _cleanVar($var, $mask = 0, $type = null)
{
// If the no trim flag is not set, trim the variable
if (!($mask & 1) && is_string($var))
{
$var = trim($var);
}
// Now we handle input filtering
if ($mask & 2)
{
// If the allow raw flag is set, do not modify the variable
$var = $var;
}
elseif ($mask & 4)
{
// If the allow HTML flag is set, apply a safe HTML filter to the variable
$safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
$var = $safeHtmlFilter->clean($var, $type);
}
else
{
// Since no allow flags were set, we will apply the most strict filter to the variable
// $tags, $attr, $tag_method, $attr_method, $xss_auto use defaults.
$noHtmlFilter = JFilterInput::getInstance();
$var = $noHtmlFilter->clean($var, $type);
}
return $var;
} | php | protected static function _cleanVar($var, $mask = 0, $type = null)
{
// If the no trim flag is not set, trim the variable
if (!($mask & 1) && is_string($var))
{
$var = trim($var);
}
// Now we handle input filtering
if ($mask & 2)
{
// If the allow raw flag is set, do not modify the variable
$var = $var;
}
elseif ($mask & 4)
{
// If the allow HTML flag is set, apply a safe HTML filter to the variable
$safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1);
$var = $safeHtmlFilter->clean($var, $type);
}
else
{
// Since no allow flags were set, we will apply the most strict filter to the variable
// $tags, $attr, $tag_method, $attr_method, $xss_auto use defaults.
$noHtmlFilter = JFilterInput::getInstance();
$var = $noHtmlFilter->clean($var, $type);
}
return $var;
} | [
"protected",
"static",
"function",
"_cleanVar",
"(",
"$",
"var",
",",
"$",
"mask",
"=",
"0",
",",
"$",
"type",
"=",
"null",
")",
"{",
"// If the no trim flag is not set, trim the variable",
"if",
"(",
"!",
"(",
"$",
"mask",
"&",
"1",
")",
"&&",
"is_string",
"(",
"$",
"var",
")",
")",
"{",
"$",
"var",
"=",
"trim",
"(",
"$",
"var",
")",
";",
"}",
"// Now we handle input filtering",
"if",
"(",
"$",
"mask",
"&",
"2",
")",
"{",
"// If the allow raw flag is set, do not modify the variable",
"$",
"var",
"=",
"$",
"var",
";",
"}",
"elseif",
"(",
"$",
"mask",
"&",
"4",
")",
"{",
"// If the allow HTML flag is set, apply a safe HTML filter to the variable",
"$",
"safeHtmlFilter",
"=",
"JFilterInput",
"::",
"getInstance",
"(",
"null",
",",
"null",
",",
"1",
",",
"1",
")",
";",
"$",
"var",
"=",
"$",
"safeHtmlFilter",
"->",
"clean",
"(",
"$",
"var",
",",
"$",
"type",
")",
";",
"}",
"else",
"{",
"// Since no allow flags were set, we will apply the most strict filter to the variable",
"// $tags, $attr, $tag_method, $attr_method, $xss_auto use defaults.",
"$",
"noHtmlFilter",
"=",
"JFilterInput",
"::",
"getInstance",
"(",
")",
";",
"$",
"var",
"=",
"$",
"noHtmlFilter",
"->",
"clean",
"(",
"$",
"var",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"var",
";",
"}"
] | Clean up an input variable.
@param mixed $var The input variable.
@param integer $mask Filter bit mask.
1 = no trim: If this flag is cleared and the input is a string, the string will have leading and trailing
whitespace trimmed.
2 = allow_raw: If set, no more filtering is performed, higher bits are ignored.
4 = allow_html: HTML is allowed, but passed through a safe HTML filter first. If set, no more filtering
is performed. If no bits other than the 1 bit is set, a strict filter is applied.
@param string $type The variable type {@see JFilterInput::clean()}.
@return mixed Same as $var
@deprecated 12.1
@since 11.1 | [
"Clean",
"up",
"an",
"input",
"variable",
"."
] | train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/request/request.php#L528-L557 |
webforge-labs/psc-cms | lib/Psc/UI/Component/SingleImage.php | SingleImage.dpi | public function dpi(EntityMeta $entityMeta, DCPackage $dc) {
$this->entityMeta = $entityMeta;
$this->dc = $dc;
return $this;
} | php | public function dpi(EntityMeta $entityMeta, DCPackage $dc) {
$this->entityMeta = $entityMeta;
$this->dc = $dc;
return $this;
} | [
"public",
"function",
"dpi",
"(",
"EntityMeta",
"$",
"entityMeta",
",",
"DCPackage",
"$",
"dc",
")",
"{",
"$",
"this",
"->",
"entityMeta",
"=",
"$",
"entityMeta",
";",
"$",
"this",
"->",
"dc",
"=",
"$",
"dc",
";",
"return",
"$",
"this",
";",
"}"
] | EntityMeta der Bild-Klasse | [
"EntityMeta",
"der",
"Bild",
"-",
"Klasse"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/UI/Component/SingleImage.php#L33-L37 |
phpmob/changmin | src/PhpMob/CoreBundle/Fixture/WebUserFactory.php | WebUserFactory.create | public function create(array $options = [])
{
$options = $this->optionsResolver->resolve($options);
/** @var WebUserInterface $user */
$user = $this->userFactory->createNew();
$user->setEmail($options['email']);
$user->setUsername($options['username']);
$user->setPlainPassword($options['password']);
$user->setDisplayName($options['displayName']);
$user->setEnabled($options['enabled']);
$user->setFirstName($options['firstName']);
$user->setLastName($options['lastName']);
$user->setPhoneNumber($options['phoneNumber']);
$user->setCountryCode($options['countryCode']);
$user->setLocale($options['locale']);
$user->setBirthday($options['birthday']);
$user->setGender($options['gender']);
$user->addRole('ROLE_USER');
return $user;
} | php | public function create(array $options = [])
{
$options = $this->optionsResolver->resolve($options);
/** @var WebUserInterface $user */
$user = $this->userFactory->createNew();
$user->setEmail($options['email']);
$user->setUsername($options['username']);
$user->setPlainPassword($options['password']);
$user->setDisplayName($options['displayName']);
$user->setEnabled($options['enabled']);
$user->setFirstName($options['firstName']);
$user->setLastName($options['lastName']);
$user->setPhoneNumber($options['phoneNumber']);
$user->setCountryCode($options['countryCode']);
$user->setLocale($options['locale']);
$user->setBirthday($options['birthday']);
$user->setGender($options['gender']);
$user->addRole('ROLE_USER');
return $user;
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"optionsResolver",
"->",
"resolve",
"(",
"$",
"options",
")",
";",
"/** @var WebUserInterface $user */",
"$",
"user",
"=",
"$",
"this",
"->",
"userFactory",
"->",
"createNew",
"(",
")",
";",
"$",
"user",
"->",
"setEmail",
"(",
"$",
"options",
"[",
"'email'",
"]",
")",
";",
"$",
"user",
"->",
"setUsername",
"(",
"$",
"options",
"[",
"'username'",
"]",
")",
";",
"$",
"user",
"->",
"setPlainPassword",
"(",
"$",
"options",
"[",
"'password'",
"]",
")",
";",
"$",
"user",
"->",
"setDisplayName",
"(",
"$",
"options",
"[",
"'displayName'",
"]",
")",
";",
"$",
"user",
"->",
"setEnabled",
"(",
"$",
"options",
"[",
"'enabled'",
"]",
")",
";",
"$",
"user",
"->",
"setFirstName",
"(",
"$",
"options",
"[",
"'firstName'",
"]",
")",
";",
"$",
"user",
"->",
"setLastName",
"(",
"$",
"options",
"[",
"'lastName'",
"]",
")",
";",
"$",
"user",
"->",
"setPhoneNumber",
"(",
"$",
"options",
"[",
"'phoneNumber'",
"]",
")",
";",
"$",
"user",
"->",
"setCountryCode",
"(",
"$",
"options",
"[",
"'countryCode'",
"]",
")",
";",
"$",
"user",
"->",
"setLocale",
"(",
"$",
"options",
"[",
"'locale'",
"]",
")",
";",
"$",
"user",
"->",
"setBirthday",
"(",
"$",
"options",
"[",
"'birthday'",
"]",
")",
";",
"$",
"user",
"->",
"setGender",
"(",
"$",
"options",
"[",
"'gender'",
"]",
")",
";",
"$",
"user",
"->",
"addRole",
"(",
"'ROLE_USER'",
")",
";",
"return",
"$",
"user",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CoreBundle/Fixture/WebUserFactory.php#L53-L74 |
phpmob/changmin | src/PhpMob/CoreBundle/Fixture/WebUserFactory.php | WebUserFactory.configureOptions | protected function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('email', function (Options $options) {
return $this->faker->email;
})
->setDefault('username', function (Options $options) {
return $this->faker->userName;
})
->setDefault('displayName', function (Options $options) {
return $this->faker->name;
})
->setDefault('firstName', function (Options $options) {
return $this->faker->firstName;
})
->setDefault('lastName', function (Options $options) {
return $this->faker->lastName;
})
->setDefault('gender', function (Options $options) {
return ['f', 'm'][rand(0, 1)];
})
->setDefault('phoneNumber', function (Options $options) {
return $this->faker->phoneNumber;
})
->setDefault('birthday', function (Options $options) {
return $this->faker->dateTime;
})
->setDefault('countryCode', function (Options $options) {
return $this->faker->countryCode;
})
->setDefault('locale', LazyOption::randomOne($this->localeRepository))
->setDefault('enabled', true)
->setAllowedTypes('enabled', 'bool')
->setDefault('password', 'password123')
;
} | php | protected function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefault('email', function (Options $options) {
return $this->faker->email;
})
->setDefault('username', function (Options $options) {
return $this->faker->userName;
})
->setDefault('displayName', function (Options $options) {
return $this->faker->name;
})
->setDefault('firstName', function (Options $options) {
return $this->faker->firstName;
})
->setDefault('lastName', function (Options $options) {
return $this->faker->lastName;
})
->setDefault('gender', function (Options $options) {
return ['f', 'm'][rand(0, 1)];
})
->setDefault('phoneNumber', function (Options $options) {
return $this->faker->phoneNumber;
})
->setDefault('birthday', function (Options $options) {
return $this->faker->dateTime;
})
->setDefault('countryCode', function (Options $options) {
return $this->faker->countryCode;
})
->setDefault('locale', LazyOption::randomOne($this->localeRepository))
->setDefault('enabled', true)
->setAllowedTypes('enabled', 'bool')
->setDefault('password', 'password123')
;
} | [
"protected",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setDefault",
"(",
"'email'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"email",
";",
"}",
")",
"->",
"setDefault",
"(",
"'username'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"userName",
";",
"}",
")",
"->",
"setDefault",
"(",
"'displayName'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"name",
";",
"}",
")",
"->",
"setDefault",
"(",
"'firstName'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"firstName",
";",
"}",
")",
"->",
"setDefault",
"(",
"'lastName'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"lastName",
";",
"}",
")",
"->",
"setDefault",
"(",
"'gender'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"[",
"'f'",
",",
"'m'",
"]",
"[",
"rand",
"(",
"0",
",",
"1",
")",
"]",
";",
"}",
")",
"->",
"setDefault",
"(",
"'phoneNumber'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"phoneNumber",
";",
"}",
")",
"->",
"setDefault",
"(",
"'birthday'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"dateTime",
";",
"}",
")",
"->",
"setDefault",
"(",
"'countryCode'",
",",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"faker",
"->",
"countryCode",
";",
"}",
")",
"->",
"setDefault",
"(",
"'locale'",
",",
"LazyOption",
"::",
"randomOne",
"(",
"$",
"this",
"->",
"localeRepository",
")",
")",
"->",
"setDefault",
"(",
"'enabled'",
",",
"true",
")",
"->",
"setAllowedTypes",
"(",
"'enabled'",
",",
"'bool'",
")",
"->",
"setDefault",
"(",
"'password'",
",",
"'password123'",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/CoreBundle/Fixture/WebUserFactory.php#L79-L114 |
anime-db/app-bundle | src/Util/Pagination/View.php | View.buildLink | protected function buildLink($page)
{
if ($page == 1 && $this->config->getFirstPageLink()) {
return $this->config->getFirstPageLink();
}
if (is_callable($this->config->getPageLink())) {
return call_user_func($this->config->getPageLink(), $page);
} else {
return sprintf($this->config->getPageLink(), $page);
}
} | php | protected function buildLink($page)
{
if ($page == 1 && $this->config->getFirstPageLink()) {
return $this->config->getFirstPageLink();
}
if (is_callable($this->config->getPageLink())) {
return call_user_func($this->config->getPageLink(), $page);
} else {
return sprintf($this->config->getPageLink(), $page);
}
} | [
"protected",
"function",
"buildLink",
"(",
"$",
"page",
")",
"{",
"if",
"(",
"$",
"page",
"==",
"1",
"&&",
"$",
"this",
"->",
"config",
"->",
"getFirstPageLink",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"->",
"getFirstPageLink",
"(",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"config",
"->",
"getPageLink",
"(",
")",
")",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"config",
"->",
"getPageLink",
"(",
")",
",",
"$",
"page",
")",
";",
"}",
"else",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"config",
"->",
"getPageLink",
"(",
")",
",",
"$",
"page",
")",
";",
"}",
"}"
] | @param int $page
@return string | [
"@param",
"int",
"$page"
] | train | https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Util/Pagination/View.php#L186-L197 |
ondrakoupil/tools | src/Strings.php | Strings.plural | static function plural($amount, $one, $two = null, $five = null, $zero = null) {
if ($two === null) $two = $one;
if ($five === null) $five = $two;
if ($zero === null) $zero = $five;
if ($amount==1) return str_replace("%%",$amount,$one);
if ($amount>1 and $amount<5) return str_replace("%%",$amount,$two);
if ($amount == 0) return str_replace("%%",$amount,$zero);
return str_replace("%%",$amount,$five);
} | php | static function plural($amount, $one, $two = null, $five = null, $zero = null) {
if ($two === null) $two = $one;
if ($five === null) $five = $two;
if ($zero === null) $zero = $five;
if ($amount==1) return str_replace("%%",$amount,$one);
if ($amount>1 and $amount<5) return str_replace("%%",$amount,$two);
if ($amount == 0) return str_replace("%%",$amount,$zero);
return str_replace("%%",$amount,$five);
} | [
"static",
"function",
"plural",
"(",
"$",
"amount",
",",
"$",
"one",
",",
"$",
"two",
"=",
"null",
",",
"$",
"five",
"=",
"null",
",",
"$",
"zero",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"two",
"===",
"null",
")",
"$",
"two",
"=",
"$",
"one",
";",
"if",
"(",
"$",
"five",
"===",
"null",
")",
"$",
"five",
"=",
"$",
"two",
";",
"if",
"(",
"$",
"zero",
"===",
"null",
")",
"$",
"zero",
"=",
"$",
"five",
";",
"if",
"(",
"$",
"amount",
"==",
"1",
")",
"return",
"str_replace",
"(",
"\"%%\"",
",",
"$",
"amount",
",",
"$",
"one",
")",
";",
"if",
"(",
"$",
"amount",
">",
"1",
"and",
"$",
"amount",
"<",
"5",
")",
"return",
"str_replace",
"(",
"\"%%\"",
",",
"$",
"amount",
",",
"$",
"two",
")",
";",
"if",
"(",
"$",
"amount",
"==",
"0",
")",
"return",
"str_replace",
"(",
"\"%%\"",
",",
"$",
"amount",
",",
"$",
"zero",
")",
";",
"return",
"str_replace",
"(",
"\"%%\"",
",",
"$",
"amount",
",",
"$",
"five",
")",
";",
"}"
] | Skloňuje řetězec dle českých pravidel řetězec
@param number $amount
@param string $one Lze použít dvě procenta - %% - pro nahrazení za $amount
@param string $two
@param string $five Vynechat nebo null = použít $two
@param string $zero Vynechat nebo null = použít $five
@return string | [
"Skloňuje",
"řetězec",
"dle",
"českých",
"pravidel",
"řetězec"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L18-L26 |
ondrakoupil/tools | src/Strings.php | Strings.substring | static function substring($input, $start, $length = null) {
return self::substr($input, $start, $length, "utf-8");
} | php | static function substring($input, $start, $length = null) {
return self::substr($input, $start, $length, "utf-8");
} | [
"static",
"function",
"substring",
"(",
"$",
"input",
",",
"$",
"start",
",",
"$",
"length",
"=",
"null",
")",
"{",
"return",
"self",
"::",
"substr",
"(",
"$",
"input",
",",
"$",
"start",
",",
"$",
"length",
",",
"\"utf-8\"",
")",
";",
"}"
] | substr() pro UTF-8
@param string $input
@param int $start
@param int $length
@return string | [
"substr",
"()",
"pro",
"UTF",
"-",
"8"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L54-L56 |
ondrakoupil/tools | src/Strings.php | Strings.substr | static function substr($input, $start, $length = null) {
if ($length === null) {
$length = self::length($input) - $start;
}
return mb_substr($input, $start, $length, "utf-8");
} | php | static function substr($input, $start, $length = null) {
if ($length === null) {
$length = self::length($input) - $start;
}
return mb_substr($input, $start, $length, "utf-8");
} | [
"static",
"function",
"substr",
"(",
"$",
"input",
",",
"$",
"start",
",",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"length",
"===",
"null",
")",
"{",
"$",
"length",
"=",
"self",
"::",
"length",
"(",
"$",
"input",
")",
"-",
"$",
"start",
";",
"}",
"return",
"mb_substr",
"(",
"$",
"input",
",",
"$",
"start",
",",
"$",
"length",
",",
"\"utf-8\"",
")",
";",
"}"
] | substr() pro UTF-8
@param string $input
@param int $start
@param int $length
@return string | [
"substr",
"()",
"pro",
"UTF",
"-",
"8"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L66-L71 |
ondrakoupil/tools | src/Strings.php | Strings.shorten | static function shorten($text, $length, $ending="…", $stripHtml=true, $ignoreWords = false) {
if ($stripHtml) {
$text=self::br2nl($text);
$text=strip_tags($text);
}
$text=trim($text);
if ($ending===true) $ending="…";
$needsTrim = (self::strlen($text) > $length);
if (!$needsTrim) {
return $text;
}
$hardTrimmed = self::substr($text, 0, $length);
$nextChar = self::substr($text, $length, 1);
if (!preg_match('~[\s.,/\-]~', $nextChar)) {
$endingRemains = preg_match('~[\s.,/\-]([^\s.,/\-]*)$~', $hardTrimmed, $foundParts);
if ($endingRemains) {
$endingLength = self::strlen($foundParts[1]);
$hardTrimmed = self::substr($hardTrimmed, 0, -1 * $endingLength - 1);
}
}
$hardTrimmed .= $ending;
return $hardTrimmed;
} | php | static function shorten($text, $length, $ending="…", $stripHtml=true, $ignoreWords = false) {
if ($stripHtml) {
$text=self::br2nl($text);
$text=strip_tags($text);
}
$text=trim($text);
if ($ending===true) $ending="…";
$needsTrim = (self::strlen($text) > $length);
if (!$needsTrim) {
return $text;
}
$hardTrimmed = self::substr($text, 0, $length);
$nextChar = self::substr($text, $length, 1);
if (!preg_match('~[\s.,/\-]~', $nextChar)) {
$endingRemains = preg_match('~[\s.,/\-]([^\s.,/\-]*)$~', $hardTrimmed, $foundParts);
if ($endingRemains) {
$endingLength = self::strlen($foundParts[1]);
$hardTrimmed = self::substr($hardTrimmed, 0, -1 * $endingLength - 1);
}
}
$hardTrimmed .= $ending;
return $hardTrimmed;
} | [
"static",
"function",
"shorten",
"(",
"$",
"text",
",",
"$",
"length",
",",
"$",
"ending",
"=",
"\"…\"",
",",
"$",
"stripHtml",
"=",
"true",
",",
"$",
"ignoreWords",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"stripHtml",
")",
"{",
"$",
"text",
"=",
"self",
"::",
"br2nl",
"(",
"$",
"text",
")",
";",
"$",
"text",
"=",
"strip_tags",
"(",
"$",
"text",
")",
";",
"}",
"$",
"text",
"=",
"trim",
"(",
"$",
"text",
")",
";",
"if",
"(",
"$",
"ending",
"===",
"true",
")",
"$",
"ending",
"=",
"\"…\"",
";",
"$",
"needsTrim",
"=",
"(",
"self",
"::",
"strlen",
"(",
"$",
"text",
")",
">",
"$",
"length",
")",
";",
"if",
"(",
"!",
"$",
"needsTrim",
")",
"{",
"return",
"$",
"text",
";",
"}",
"$",
"hardTrimmed",
"=",
"self",
"::",
"substr",
"(",
"$",
"text",
",",
"0",
",",
"$",
"length",
")",
";",
"$",
"nextChar",
"=",
"self",
"::",
"substr",
"(",
"$",
"text",
",",
"$",
"length",
",",
"1",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'~[\\s.,/\\-]~'",
",",
"$",
"nextChar",
")",
")",
"{",
"$",
"endingRemains",
"=",
"preg_match",
"(",
"'~[\\s.,/\\-]([^\\s.,/\\-]*)$~'",
",",
"$",
"hardTrimmed",
",",
"$",
"foundParts",
")",
";",
"if",
"(",
"$",
"endingRemains",
")",
"{",
"$",
"endingLength",
"=",
"self",
"::",
"strlen",
"(",
"$",
"foundParts",
"[",
"1",
"]",
")",
";",
"$",
"hardTrimmed",
"=",
"self",
"::",
"substr",
"(",
"$",
"hardTrimmed",
",",
"0",
",",
"-",
"1",
"*",
"$",
"endingLength",
"-",
"1",
")",
";",
"}",
"}",
"$",
"hardTrimmed",
".=",
"$",
"ending",
";",
"return",
"$",
"hardTrimmed",
";",
"}"
] | Funkce pro zkrácení dlouhého textu na menší délku.
Ořezává tak, aby nerozdělovala slova, a případně umí i odstranit HTML znaky.
@param string $text Původní (dlouhý) text
@param int $length Požadovaná délka textu. Oříznutý text nebude mít přesně tuto délku, může být o nějaké znaky kratší nebo delší podle toho, kde končí slovo.
@param string $ending Pokud dojde ke zkrácení textu, tak s na jeho konec přilepí tento řetězec. Defaultně trojtečka (jako HTML entita &hellip;). TRUE = &hellip; (nemusíš si pak pamatovat tu entitu)
@param bool $stripHtml Mají se odstraňovat HTML tagy? True = odstranit. Zachovají se pouze <br />, a všechny konce řádků (\n i \r) budou nahrazeny za <br />.
Odstraňování je důležité, jinak by mohlo dojít k ořezu uprostřed HTML tagu, anebo by nebyl nějaký tag správně ukončen.
Pro ořezávání se zachováním html tagů je shortenHtml().
@param bool $ignoreWords Ignorovat slova a rozdělit přesně.
@return string Zkrácený text | [
"Funkce",
"pro",
"zkrácení",
"dlouhého",
"textu",
"na",
"menší",
"délku",
".",
"Ořezává",
"tak",
"aby",
"nerozdělovala",
"slova",
"a",
"případně",
"umí",
"i",
"odstranit",
"HTML",
"znaky",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L126-L152 |
ondrakoupil/tools | src/Strings.php | Strings.replaceEntities | static function replaceEntities($string, $valuesArray, $escapeFunction = "!!default", $entityDelimiter = "%", $entityNameChars = 'a-z0-9_-') {
if ($escapeFunction === "!!default") {
$escapeFunction = "\\OndraKoupil\\Tools\\Html::escape";
}
$arrayMode = is_array($valuesArray);
$arrayAccessMode = (!is_array($valuesArray) and $valuesArray instanceof ArrayAccess);
$string = \preg_replace_callback('~'.preg_quote($entityDelimiter).'(['.$entityNameChars.']+)'.preg_quote($entityDelimiter).'~i', function($found) use ($valuesArray, $escapeFunction, $arrayMode, $arrayAccessMode) {
if ($arrayMode and key_exists($found[1], $valuesArray)) {
$v = $valuesArray[$found[1]];
if ($escapeFunction) {
$v = call_user_func_array($escapeFunction, array($v));
}
return $v;
}
if ($arrayAccessMode) {
if (isset($valuesArray[$found[1]])) {
$v = $valuesArray[$found[1]];
if ($escapeFunction) {
$v = call_user_func_array($escapeFunction, array($v));
}
return $v;
}
}
if (!$arrayAccessMode and !$arrayMode) {
if (property_exists($valuesArray, $found[1])) {
$v = $valuesArray->{$found[1]};
if ($escapeFunction) {
$v = call_user_func_array($escapeFunction, array($v));
}
return $v;
}
}
return $found[0];
}, $string);
return $string;
} | php | static function replaceEntities($string, $valuesArray, $escapeFunction = "!!default", $entityDelimiter = "%", $entityNameChars = 'a-z0-9_-') {
if ($escapeFunction === "!!default") {
$escapeFunction = "\\OndraKoupil\\Tools\\Html::escape";
}
$arrayMode = is_array($valuesArray);
$arrayAccessMode = (!is_array($valuesArray) and $valuesArray instanceof ArrayAccess);
$string = \preg_replace_callback('~'.preg_quote($entityDelimiter).'(['.$entityNameChars.']+)'.preg_quote($entityDelimiter).'~i', function($found) use ($valuesArray, $escapeFunction, $arrayMode, $arrayAccessMode) {
if ($arrayMode and key_exists($found[1], $valuesArray)) {
$v = $valuesArray[$found[1]];
if ($escapeFunction) {
$v = call_user_func_array($escapeFunction, array($v));
}
return $v;
}
if ($arrayAccessMode) {
if (isset($valuesArray[$found[1]])) {
$v = $valuesArray[$found[1]];
if ($escapeFunction) {
$v = call_user_func_array($escapeFunction, array($v));
}
return $v;
}
}
if (!$arrayAccessMode and !$arrayMode) {
if (property_exists($valuesArray, $found[1])) {
$v = $valuesArray->{$found[1]};
if ($escapeFunction) {
$v = call_user_func_array($escapeFunction, array($v));
}
return $v;
}
}
return $found[0];
}, $string);
return $string;
} | [
"static",
"function",
"replaceEntities",
"(",
"$",
"string",
",",
"$",
"valuesArray",
",",
"$",
"escapeFunction",
"=",
"\"!!default\"",
",",
"$",
"entityDelimiter",
"=",
"\"%\"",
",",
"$",
"entityNameChars",
"=",
"'a-z0-9_-'",
")",
"{",
"if",
"(",
"$",
"escapeFunction",
"===",
"\"!!default\"",
")",
"{",
"$",
"escapeFunction",
"=",
"\"\\\\OndraKoupil\\\\Tools\\\\Html::escape\"",
";",
"}",
"$",
"arrayMode",
"=",
"is_array",
"(",
"$",
"valuesArray",
")",
";",
"$",
"arrayAccessMode",
"=",
"(",
"!",
"is_array",
"(",
"$",
"valuesArray",
")",
"and",
"$",
"valuesArray",
"instanceof",
"ArrayAccess",
")",
";",
"$",
"string",
"=",
"\\",
"preg_replace_callback",
"(",
"'~'",
".",
"preg_quote",
"(",
"$",
"entityDelimiter",
")",
".",
"'(['",
".",
"$",
"entityNameChars",
".",
"']+)'",
".",
"preg_quote",
"(",
"$",
"entityDelimiter",
")",
".",
"'~i'",
",",
"function",
"(",
"$",
"found",
")",
"use",
"(",
"$",
"valuesArray",
",",
"$",
"escapeFunction",
",",
"$",
"arrayMode",
",",
"$",
"arrayAccessMode",
")",
"{",
"if",
"(",
"$",
"arrayMode",
"and",
"key_exists",
"(",
"$",
"found",
"[",
"1",
"]",
",",
"$",
"valuesArray",
")",
")",
"{",
"$",
"v",
"=",
"$",
"valuesArray",
"[",
"$",
"found",
"[",
"1",
"]",
"]",
";",
"if",
"(",
"$",
"escapeFunction",
")",
"{",
"$",
"v",
"=",
"call_user_func_array",
"(",
"$",
"escapeFunction",
",",
"array",
"(",
"$",
"v",
")",
")",
";",
"}",
"return",
"$",
"v",
";",
"}",
"if",
"(",
"$",
"arrayAccessMode",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"valuesArray",
"[",
"$",
"found",
"[",
"1",
"]",
"]",
")",
")",
"{",
"$",
"v",
"=",
"$",
"valuesArray",
"[",
"$",
"found",
"[",
"1",
"]",
"]",
";",
"if",
"(",
"$",
"escapeFunction",
")",
"{",
"$",
"v",
"=",
"call_user_func_array",
"(",
"$",
"escapeFunction",
",",
"array",
"(",
"$",
"v",
")",
")",
";",
"}",
"return",
"$",
"v",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"arrayAccessMode",
"and",
"!",
"$",
"arrayMode",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"valuesArray",
",",
"$",
"found",
"[",
"1",
"]",
")",
")",
"{",
"$",
"v",
"=",
"$",
"valuesArray",
"->",
"{",
"$",
"found",
"[",
"1",
"]",
"}",
";",
"if",
"(",
"$",
"escapeFunction",
")",
"{",
"$",
"v",
"=",
"call_user_func_array",
"(",
"$",
"escapeFunction",
",",
"array",
"(",
"$",
"v",
")",
")",
";",
"}",
"return",
"$",
"v",
";",
"}",
"}",
"return",
"$",
"found",
"[",
"0",
"]",
";",
"}",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}"
] | Nahradí entity v řetězci hodnotami ze zadaného pole.
@param string $string
@param array|ArrayAccess $valuesArray
@param callback $escapeFunction Funkce, ktrsou se prožene každá nahrazená entita (např. kvůli escapování paznaků). Defaultně Html::escape()
@param string $entityDelimiter Jeden znak
@param string $entityNameChars Rozsah povolených znaků v názvech entit
@return string | [
"Nahradí",
"entity",
"v",
"řetězci",
"hodnotami",
"ze",
"zadaného",
"pole",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L183-L221 |
ondrakoupil/tools | src/Strings.php | Strings.parsePhpNumber | static function parsePhpNumber($number) {
$number = trim($number);
if (is_numeric($number)) {
return $number * 1;
}
if (preg_match('~^(-?)([0-9\.,]+)([kmgt]?)$~i', $number, $parts)) {
$base = self::number($parts[2]);
switch ($parts[3]) {
case "K": case "k":
$base *= 1024;
break;
case "M": case "m":
$base *= 1024 * 1024;
break;
case "G": case "g":
$base *= 1024 * 1024 * 1024;
break;
case "T": case "t":
$base *= 1024 * 1024 * 1024 * 1024;
break;
}
if ($parts[1]) {
$c = -1;
} else {
$c = 1;
}
return $base * $c;
}
return false;
} | php | static function parsePhpNumber($number) {
$number = trim($number);
if (is_numeric($number)) {
return $number * 1;
}
if (preg_match('~^(-?)([0-9\.,]+)([kmgt]?)$~i', $number, $parts)) {
$base = self::number($parts[2]);
switch ($parts[3]) {
case "K": case "k":
$base *= 1024;
break;
case "M": case "m":
$base *= 1024 * 1024;
break;
case "G": case "g":
$base *= 1024 * 1024 * 1024;
break;
case "T": case "t":
$base *= 1024 * 1024 * 1024 * 1024;
break;
}
if ($parts[1]) {
$c = -1;
} else {
$c = 1;
}
return $base * $c;
}
return false;
} | [
"static",
"function",
"parsePhpNumber",
"(",
"$",
"number",
")",
"{",
"$",
"number",
"=",
"trim",
"(",
"$",
"number",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"number",
")",
")",
"{",
"return",
"$",
"number",
"*",
"1",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'~^(-?)([0-9\\.,]+)([kmgt]?)$~i'",
",",
"$",
"number",
",",
"$",
"parts",
")",
")",
"{",
"$",
"base",
"=",
"self",
"::",
"number",
"(",
"$",
"parts",
"[",
"2",
"]",
")",
";",
"switch",
"(",
"$",
"parts",
"[",
"3",
"]",
")",
"{",
"case",
"\"K\"",
":",
"case",
"\"k\"",
":",
"$",
"base",
"*=",
"1024",
";",
"break",
";",
"case",
"\"M\"",
":",
"case",
"\"m\"",
":",
"$",
"base",
"*=",
"1024",
"*",
"1024",
";",
"break",
";",
"case",
"\"G\"",
":",
"case",
"\"g\"",
":",
"$",
"base",
"*=",
"1024",
"*",
"1024",
"*",
"1024",
";",
"break",
";",
"case",
"\"T\"",
":",
"case",
"\"t\"",
":",
"$",
"base",
"*=",
"1024",
"*",
"1024",
"*",
"1024",
"*",
"1024",
";",
"break",
";",
"}",
"if",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"{",
"$",
"c",
"=",
"-",
"1",
";",
"}",
"else",
"{",
"$",
"c",
"=",
"1",
";",
"}",
"return",
"$",
"base",
"*",
"$",
"c",
";",
"}",
"return",
"false",
";",
"}"
] | Převede číslo s lidsky čitelným násobitelem, jako to zadávané v php.ini (např. 100M jako 100 mega), na normální číslo
@param string $number
@return number|boolean False, pokud je vstup nepřevoditelný | [
"Převede",
"číslo",
"s",
"lidsky",
"čitelným",
"násobitelem",
"jako",
"to",
"zadávané",
"v",
"php",
".",
"ini",
"(",
"např",
".",
"100M",
"jako",
"100",
"mega",
")",
"na",
"normální",
"číslo"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L228-L267 |
ondrakoupil/tools | src/Strings.php | Strings.phoneNumberFormatter | static function phoneNumberFormatter($input, $international = true, $spaces = false, $internationalPrefix = "+", $defaultInternational = "420") {
if (!trim($input)) {
return "";
}
if ($spaces === true) {
$spaces = " ";
}
$filteredInput = preg_replace('~\D~', '', $input);
$parsedInternational = "";
$parsedMain = "";
if (strlen($filteredInput) > 9) {
$parsedInternational = self::substr($filteredInput, 0, -9);
$parsedMain = self::substr($filteredInput, -9);
} else {
$parsedMain = $filteredInput;
}
if (self::startsWith($parsedInternational, $internationalPrefix)) {
$parsedInternational = self::substr($parsedInternational, self::strlen($internationalPrefix));
}
if ($spaces) {
$spacedMain = "";
$len = self::strlen($parsedMain);
for ($i = $len; $i > -3; $i-=3) {
$spacedMain = self::substr($parsedMain, ($i >= 0 ? $i : 0), ($i >= 0 ? 3 : (3 - $i * -1)))
.($spacedMain ? ($spaces.$spacedMain) : "");
}
} else {
$spacedMain = $parsedMain;
}
$output = "";
if ($international) {
if (!$parsedInternational) {
$parsedInternational = $defaultInternational;
}
$output .= $internationalPrefix.$parsedInternational;
if ($spaces) {
$output .= $spaces;
}
}
$output .= $spacedMain;
return $output;
} | php | static function phoneNumberFormatter($input, $international = true, $spaces = false, $internationalPrefix = "+", $defaultInternational = "420") {
if (!trim($input)) {
return "";
}
if ($spaces === true) {
$spaces = " ";
}
$filteredInput = preg_replace('~\D~', '', $input);
$parsedInternational = "";
$parsedMain = "";
if (strlen($filteredInput) > 9) {
$parsedInternational = self::substr($filteredInput, 0, -9);
$parsedMain = self::substr($filteredInput, -9);
} else {
$parsedMain = $filteredInput;
}
if (self::startsWith($parsedInternational, $internationalPrefix)) {
$parsedInternational = self::substr($parsedInternational, self::strlen($internationalPrefix));
}
if ($spaces) {
$spacedMain = "";
$len = self::strlen($parsedMain);
for ($i = $len; $i > -3; $i-=3) {
$spacedMain = self::substr($parsedMain, ($i >= 0 ? $i : 0), ($i >= 0 ? 3 : (3 - $i * -1)))
.($spacedMain ? ($spaces.$spacedMain) : "");
}
} else {
$spacedMain = $parsedMain;
}
$output = "";
if ($international) {
if (!$parsedInternational) {
$parsedInternational = $defaultInternational;
}
$output .= $internationalPrefix.$parsedInternational;
if ($spaces) {
$output .= $spaces;
}
}
$output .= $spacedMain;
return $output;
} | [
"static",
"function",
"phoneNumberFormatter",
"(",
"$",
"input",
",",
"$",
"international",
"=",
"true",
",",
"$",
"spaces",
"=",
"false",
",",
"$",
"internationalPrefix",
"=",
"\"+\"",
",",
"$",
"defaultInternational",
"=",
"\"420\"",
")",
"{",
"if",
"(",
"!",
"trim",
"(",
"$",
"input",
")",
")",
"{",
"return",
"\"\"",
";",
"}",
"if",
"(",
"$",
"spaces",
"===",
"true",
")",
"{",
"$",
"spaces",
"=",
"\" \"",
";",
"}",
"$",
"filteredInput",
"=",
"preg_replace",
"(",
"'~\\D~'",
",",
"''",
",",
"$",
"input",
")",
";",
"$",
"parsedInternational",
"=",
"\"\"",
";",
"$",
"parsedMain",
"=",
"\"\"",
";",
"if",
"(",
"strlen",
"(",
"$",
"filteredInput",
")",
">",
"9",
")",
"{",
"$",
"parsedInternational",
"=",
"self",
"::",
"substr",
"(",
"$",
"filteredInput",
",",
"0",
",",
"-",
"9",
")",
";",
"$",
"parsedMain",
"=",
"self",
"::",
"substr",
"(",
"$",
"filteredInput",
",",
"-",
"9",
")",
";",
"}",
"else",
"{",
"$",
"parsedMain",
"=",
"$",
"filteredInput",
";",
"}",
"if",
"(",
"self",
"::",
"startsWith",
"(",
"$",
"parsedInternational",
",",
"$",
"internationalPrefix",
")",
")",
"{",
"$",
"parsedInternational",
"=",
"self",
"::",
"substr",
"(",
"$",
"parsedInternational",
",",
"self",
"::",
"strlen",
"(",
"$",
"internationalPrefix",
")",
")",
";",
"}",
"if",
"(",
"$",
"spaces",
")",
"{",
"$",
"spacedMain",
"=",
"\"\"",
";",
"$",
"len",
"=",
"self",
"::",
"strlen",
"(",
"$",
"parsedMain",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"len",
";",
"$",
"i",
">",
"-",
"3",
";",
"$",
"i",
"-=",
"3",
")",
"{",
"$",
"spacedMain",
"=",
"self",
"::",
"substr",
"(",
"$",
"parsedMain",
",",
"(",
"$",
"i",
">=",
"0",
"?",
"$",
"i",
":",
"0",
")",
",",
"(",
"$",
"i",
">=",
"0",
"?",
"3",
":",
"(",
"3",
"-",
"$",
"i",
"*",
"-",
"1",
")",
")",
")",
".",
"(",
"$",
"spacedMain",
"?",
"(",
"$",
"spaces",
".",
"$",
"spacedMain",
")",
":",
"\"\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"spacedMain",
"=",
"$",
"parsedMain",
";",
"}",
"$",
"output",
"=",
"\"\"",
";",
"if",
"(",
"$",
"international",
")",
"{",
"if",
"(",
"!",
"$",
"parsedInternational",
")",
"{",
"$",
"parsedInternational",
"=",
"$",
"defaultInternational",
";",
"}",
"$",
"output",
".=",
"$",
"internationalPrefix",
".",
"$",
"parsedInternational",
";",
"if",
"(",
"$",
"spaces",
")",
"{",
"$",
"output",
".=",
"$",
"spaces",
";",
"}",
"}",
"$",
"output",
".=",
"$",
"spacedMain",
";",
"return",
"$",
"output",
";",
"}"
] | Naformátuje telefonní číslo
@param string $input
@param bool $international Nechat/přidat mezinárodní předvolbu?
@param bool|string $spaces Přidat mezery pro trojčíslí? True = mezery. False = žádné mezery. String = zadaný řetězec použít jako mezeru.
@param string $internationalPrefix Prefix pro mezinárodní řpedvolbu, používá se většinou "+" nebo "00"
@param string $defaultInternational Výchozí mezinárodní předvolba (je-li $international == true a $input je bez předvolby). Zadávej BEZ prefixu.
@return string | [
"Naformátuje",
"telefonní",
"číslo"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L279-L328 |
ondrakoupil/tools | src/Strings.php | Strings.startsWith | static function startsWith($string, $startsWith, $caseSensitive = true) {
$len = self::strlen($startsWith);
if ($caseSensitive) return self::substr($string, 0, $len) == $startsWith;
return self::strtolower(self::substr($string, 0, $len)) == self::strtolower($startsWith);
} | php | static function startsWith($string, $startsWith, $caseSensitive = true) {
$len = self::strlen($startsWith);
if ($caseSensitive) return self::substr($string, 0, $len) == $startsWith;
return self::strtolower(self::substr($string, 0, $len)) == self::strtolower($startsWith);
} | [
"static",
"function",
"startsWith",
"(",
"$",
"string",
",",
"$",
"startsWith",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"$",
"len",
"=",
"self",
"::",
"strlen",
"(",
"$",
"startsWith",
")",
";",
"if",
"(",
"$",
"caseSensitive",
")",
"return",
"self",
"::",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"len",
")",
"==",
"$",
"startsWith",
";",
"return",
"self",
"::",
"strtolower",
"(",
"self",
"::",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"len",
")",
")",
"==",
"self",
"::",
"strtolower",
"(",
"$",
"startsWith",
")",
";",
"}"
] | Začíná $string na $startsWith?
@param string $string
@param string $startsWith
@param bool $caseSensitive
@return bool | [
"Začíná",
"$string",
"na",
"$startsWith?"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L337-L341 |
ondrakoupil/tools | src/Strings.php | Strings.endsWith | static function endsWith($string, $endsWith, $caseSensitive = true) {
$len = self::strlen($endsWith);
if ($caseSensitive) return self::substr($string, -1 * $len) == $endsWith;
return self::strtolower(self::substr($string, -1 * $len)) == self::strtolower($endsWith);
} | php | static function endsWith($string, $endsWith, $caseSensitive = true) {
$len = self::strlen($endsWith);
if ($caseSensitive) return self::substr($string, -1 * $len) == $endsWith;
return self::strtolower(self::substr($string, -1 * $len)) == self::strtolower($endsWith);
} | [
"static",
"function",
"endsWith",
"(",
"$",
"string",
",",
"$",
"endsWith",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"$",
"len",
"=",
"self",
"::",
"strlen",
"(",
"$",
"endsWith",
")",
";",
"if",
"(",
"$",
"caseSensitive",
")",
"return",
"self",
"::",
"substr",
"(",
"$",
"string",
",",
"-",
"1",
"*",
"$",
"len",
")",
"==",
"$",
"endsWith",
";",
"return",
"self",
"::",
"strtolower",
"(",
"self",
"::",
"substr",
"(",
"$",
"string",
",",
"-",
"1",
"*",
"$",
"len",
")",
")",
"==",
"self",
"::",
"strtolower",
"(",
"$",
"endsWith",
")",
";",
"}"
] | Končí $string na $endsWith?
@param string $string
@param string $endsWith
@return string | [
"Končí",
"$string",
"na",
"$endsWith?"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L349-L353 |
ondrakoupil/tools | src/Strings.php | Strings.number | static function number($string, $default = 0, $positiveOnly = false) {
if (is_bool($string) or is_object($string) or is_array($string)) return $default;
$string=str_replace(array(","," "),array(".",""),trim($string));
if (!is_numeric($string)) return $default;
$string = $string * 1; // Convert to number
if ($positiveOnly and $string<0) return $default;
return $string;
} | php | static function number($string, $default = 0, $positiveOnly = false) {
if (is_bool($string) or is_object($string) or is_array($string)) return $default;
$string=str_replace(array(","," "),array(".",""),trim($string));
if (!is_numeric($string)) return $default;
$string = $string * 1; // Convert to number
if ($positiveOnly and $string<0) return $default;
return $string;
} | [
"static",
"function",
"number",
"(",
"$",
"string",
",",
"$",
"default",
"=",
"0",
",",
"$",
"positiveOnly",
"=",
"false",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"string",
")",
"or",
"is_object",
"(",
"$",
"string",
")",
"or",
"is_array",
"(",
"$",
"string",
")",
")",
"return",
"$",
"default",
";",
"$",
"string",
"=",
"str_replace",
"(",
"array",
"(",
"\",\"",
",",
"\" \"",
")",
",",
"array",
"(",
"\".\"",
",",
"\"\"",
")",
",",
"trim",
"(",
"$",
"string",
")",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"string",
")",
")",
"return",
"$",
"default",
";",
"$",
"string",
"=",
"$",
"string",
"*",
"1",
";",
"// Convert to number",
"if",
"(",
"$",
"positiveOnly",
"and",
"$",
"string",
"<",
"0",
")",
"return",
"$",
"default",
";",
"return",
"$",
"string",
";",
"}"
] | Ošetří zadanou hodnotu tak, aby z ní bylo číslo.
(normalizuje desetinnou čárku na tečku a ověří is_numeric).
@param mixed $string
@param int|float $default Vrátí se, pokud $vstup není čílený řetězec ani číslo (tj. je array, object, bool nebo nenumerický řetězec)
@param bool $positiveOnly Dáš-li true, tak se záporné číslo bude považovat za nepřijatelné a vrátí se $default (vhodné např. pro strtotime)
@return int|float | [
"Ošetří",
"zadanou",
"hodnotu",
"tak",
"aby",
"z",
"ní",
"bylo",
"číslo",
".",
"(",
"normalizuje",
"desetinnou",
"čárku",
"na",
"tečku",
"a",
"ověří",
"is_numeric",
")",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L363-L370 |
ondrakoupil/tools | src/Strings.php | Strings.numberOnly | static function numberOnly($string, $decimalPoint = ".", $convertedDecimalPoint = ".") {
$vystup="";
for ($i=0;$i<strlen($string);$i++) {
$znak=substr($string,$i,1);
if (is_numeric($znak)) $vystup.=$znak;
else {
if ($znak==$decimalPoint) {
$vystup.=$convertedDecimalPoint;
}
}
}
return $vystup;
} | php | static function numberOnly($string, $decimalPoint = ".", $convertedDecimalPoint = ".") {
$vystup="";
for ($i=0;$i<strlen($string);$i++) {
$znak=substr($string,$i,1);
if (is_numeric($znak)) $vystup.=$znak;
else {
if ($znak==$decimalPoint) {
$vystup.=$convertedDecimalPoint;
}
}
}
return $vystup;
} | [
"static",
"function",
"numberOnly",
"(",
"$",
"string",
",",
"$",
"decimalPoint",
"=",
"\".\"",
",",
"$",
"convertedDecimalPoint",
"=",
"\".\"",
")",
"{",
"$",
"vystup",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"string",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"znak",
"=",
"substr",
"(",
"$",
"string",
",",
"$",
"i",
",",
"1",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"znak",
")",
")",
"$",
"vystup",
".=",
"$",
"znak",
";",
"else",
"{",
"if",
"(",
"$",
"znak",
"==",
"$",
"decimalPoint",
")",
"{",
"$",
"vystup",
".=",
"$",
"convertedDecimalPoint",
";",
"}",
"}",
"}",
"return",
"$",
"vystup",
";",
"}"
] | Funkce zlikviduje z řetězce všechno kromě číselných znaků a vybraného desetinného oddělovače.
@param string $string
@param string $decimalPoint
@param string $convertedDecimalPoint Takto lze normalizovat desetinný oddělovač.
@return string | [
"Funkce",
"zlikviduje",
"z",
"řetězce",
"všechno",
"kromě",
"číselných",
"znaků",
"a",
"vybraného",
"desetinného",
"oddělovače",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L379-L391 |
ondrakoupil/tools | src/Strings.php | Strings.toAscii | public static function toAscii($s)
{
$s = preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $s);
$s = strtr($s, '`\'"^~', "\x01\x02\x03\x04\x05");
if (ICONV_IMPL === 'glibc') {
$s = @iconv('UTF-8', 'WINDOWS-1250//TRANSLIT', $s); // intentionally @
$s = strtr($s, "\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e"
. "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
. "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8"
. "\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x96",
"ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt-");
} else {
$s = @iconv('UTF-8', 'ASCII//TRANSLIT', $s); // intentionally @
}
$s = str_replace(array('`', "'", '"', '^', '~'), '', $s);
return strtr($s, "\x01\x02\x03\x04\x05", '`\'"^~');
} | php | public static function toAscii($s)
{
$s = preg_replace('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{2FF}\x{370}-\x{10FFFF}]#u', '', $s);
$s = strtr($s, '`\'"^~', "\x01\x02\x03\x04\x05");
if (ICONV_IMPL === 'glibc') {
$s = @iconv('UTF-8', 'WINDOWS-1250//TRANSLIT', $s); // intentionally @
$s = strtr($s, "\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e"
. "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3"
. "\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8"
. "\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x96",
"ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt-");
} else {
$s = @iconv('UTF-8', 'ASCII//TRANSLIT', $s); // intentionally @
}
$s = str_replace(array('`', "'", '"', '^', '~'), '', $s);
return strtr($s, "\x01\x02\x03\x04\x05", '`\'"^~');
} | [
"public",
"static",
"function",
"toAscii",
"(",
"$",
"s",
")",
"{",
"$",
"s",
"=",
"preg_replace",
"(",
"'#[^\\x09\\x0A\\x0D\\x20-\\x7E\\xA0-\\x{2FF}\\x{370}-\\x{10FFFF}]#u'",
",",
"''",
",",
"$",
"s",
")",
";",
"$",
"s",
"=",
"strtr",
"(",
"$",
"s",
",",
"'`\\'\"^~'",
",",
"\"\\x01\\x02\\x03\\x04\\x05\"",
")",
";",
"if",
"(",
"ICONV_IMPL",
"===",
"'glibc'",
")",
"{",
"$",
"s",
"=",
"@",
"iconv",
"(",
"'UTF-8'",
",",
"'WINDOWS-1250//TRANSLIT'",
",",
"$",
"s",
")",
";",
"// intentionally @",
"$",
"s",
"=",
"strtr",
"(",
"$",
"s",
",",
"\"\\xa5\\xa3\\xbc\\x8c\\xa7\\x8a\\xaa\\x8d\\x8f\\x8e\\xaf\\xb9\\xb3\\xbe\\x9c\\x9a\\xba\\x9d\\x9f\\x9e\"",
".",
"\"\\xbf\\xc0\\xc1\\xc2\\xc3\\xc4\\xc5\\xc6\\xc7\\xc8\\xc9\\xca\\xcb\\xcc\\xcd\\xce\\xcf\\xd0\\xd1\\xd2\\xd3\"",
".",
"\"\\xd4\\xd5\\xd6\\xd7\\xd8\\xd9\\xda\\xdb\\xdc\\xdd\\xde\\xdf\\xe0\\xe1\\xe2\\xe3\\xe4\\xe5\\xe6\\xe7\\xe8\"",
".",
"\"\\xe9\\xea\\xeb\\xec\\xed\\xee\\xef\\xf0\\xf1\\xf2\\xf3\\xf4\\xf5\\xf6\\xf8\\xf9\\xfa\\xfb\\xfc\\xfd\\xfe\\x96\"",
",",
"\"ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt-\"",
")",
";",
"}",
"else",
"{",
"$",
"s",
"=",
"@",
"iconv",
"(",
"'UTF-8'",
",",
"'ASCII//TRANSLIT'",
",",
"$",
"s",
")",
";",
"// intentionally @",
"}",
"$",
"s",
"=",
"str_replace",
"(",
"array",
"(",
"'`'",
",",
"\"'\"",
",",
"'\"'",
",",
"'^'",
",",
"'~'",
")",
",",
"''",
",",
"$",
"s",
")",
";",
"return",
"strtr",
"(",
"$",
"s",
",",
"\"\\x01\\x02\\x03\\x04\\x05\"",
",",
"'`\\'\"^~'",
")",
";",
"}"
] | Converts to ASCII.
@param string UTF-8 encoding
@return string ASCII
@author Nette Framework | [
"Converts",
"to",
"ASCII",
"."
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L410-L426 |
ondrakoupil/tools | src/Strings.php | Strings.formatSize | public static function formatSize($size, $decimalPrecision = 2) {
if ($size < 1024) return $size . ' B';
elseif ($size < 1048576) return round($size / 1024, $decimalPrecision) . ' kB';
elseif ($size < 1073741824) return round($size / 1048576, $decimalPrecision) . ' MB';
elseif ($size < 1099511627776) return round($size / 1073741824, $decimalPrecision) . ' GB';
elseif ($size < 1125899906842624) return round($size / 1099511627776, $decimalPrecision) . ' TB';
elseif ($size < 1152921504606846976) return round($size / 1125899906842624, $decimalPrecision) . ' PB';
else return round($size / 1152921504606846976, $decimalPrecision) . ' EB';
} | php | public static function formatSize($size, $decimalPrecision = 2) {
if ($size < 1024) return $size . ' B';
elseif ($size < 1048576) return round($size / 1024, $decimalPrecision) . ' kB';
elseif ($size < 1073741824) return round($size / 1048576, $decimalPrecision) . ' MB';
elseif ($size < 1099511627776) return round($size / 1073741824, $decimalPrecision) . ' GB';
elseif ($size < 1125899906842624) return round($size / 1099511627776, $decimalPrecision) . ' TB';
elseif ($size < 1152921504606846976) return round($size / 1125899906842624, $decimalPrecision) . ' PB';
else return round($size / 1152921504606846976, $decimalPrecision) . ' EB';
} | [
"public",
"static",
"function",
"formatSize",
"(",
"$",
"size",
",",
"$",
"decimalPrecision",
"=",
"2",
")",
"{",
"if",
"(",
"$",
"size",
"<",
"1024",
")",
"return",
"$",
"size",
".",
"' B'",
";",
"elseif",
"(",
"$",
"size",
"<",
"1048576",
")",
"return",
"round",
"(",
"$",
"size",
"/",
"1024",
",",
"$",
"decimalPrecision",
")",
".",
"' kB'",
";",
"elseif",
"(",
"$",
"size",
"<",
"1073741824",
")",
"return",
"round",
"(",
"$",
"size",
"/",
"1048576",
",",
"$",
"decimalPrecision",
")",
".",
"' MB'",
";",
"elseif",
"(",
"$",
"size",
"<",
"1099511627776",
")",
"return",
"round",
"(",
"$",
"size",
"/",
"1073741824",
",",
"$",
"decimalPrecision",
")",
".",
"' GB'",
";",
"elseif",
"(",
"$",
"size",
"<",
"1125899906842624",
")",
"return",
"round",
"(",
"$",
"size",
"/",
"1099511627776",
",",
"$",
"decimalPrecision",
")",
".",
"' TB'",
";",
"elseif",
"(",
"$",
"size",
"<",
"1152921504606846976",
")",
"return",
"round",
"(",
"$",
"size",
"/",
"1125899906842624",
",",
"$",
"decimalPrecision",
")",
".",
"' PB'",
";",
"else",
"return",
"round",
"(",
"$",
"size",
"/",
"1152921504606846976",
",",
"$",
"decimalPrecision",
")",
".",
"' EB'",
";",
"}"
] | Převede číselnou velikost na textové výjádření v jednotkách velikosti (KB,MB,...)
@param $size
@return string | [
"Převede",
"číselnou",
"velikost",
"na",
"textové",
"výjádření",
"v",
"jednotkách",
"velikosti",
"(",
"KB",
"MB",
"...",
")"
] | train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Strings.php#L454-L463 |
netgen/ngopengraph | autoloads/opengraphoperator.php | OpenGraphOperator.modify | function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace,
&$currentNamespace, &$operatorValue, &$namedParameters )
{
switch ( $operatorName )
{
case 'opengraph':
{
$operatorValue = $this->generateOpenGraphTags( $namedParameters['nodeid'] );
break;
}
case 'language_code':
{
$operatorValue = eZLocale::instance()->httpLocaleCode();
break;
}
}
} | php | function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace,
&$currentNamespace, &$operatorValue, &$namedParameters )
{
switch ( $operatorName )
{
case 'opengraph':
{
$operatorValue = $this->generateOpenGraphTags( $namedParameters['nodeid'] );
break;
}
case 'language_code':
{
$operatorValue = eZLocale::instance()->httpLocaleCode();
break;
}
}
} | [
"function",
"modify",
"(",
"&",
"$",
"tpl",
",",
"&",
"$",
"operatorName",
",",
"&",
"$",
"operatorParameters",
",",
"&",
"$",
"rootNamespace",
",",
"&",
"$",
"currentNamespace",
",",
"&",
"$",
"operatorValue",
",",
"&",
"$",
"namedParameters",
")",
"{",
"switch",
"(",
"$",
"operatorName",
")",
"{",
"case",
"'opengraph'",
":",
"{",
"$",
"operatorValue",
"=",
"$",
"this",
"->",
"generateOpenGraphTags",
"(",
"$",
"namedParameters",
"[",
"'nodeid'",
"]",
")",
";",
"break",
";",
"}",
"case",
"'language_code'",
":",
"{",
"$",
"operatorValue",
"=",
"eZLocale",
"::",
"instance",
"(",
")",
"->",
"httpLocaleCode",
"(",
")",
";",
"break",
";",
"}",
"}",
"}"
] | Executes the operators
@param eZTemplate $tpl
@param string $operatorName
@param array $operatorParameters
@param string $rootNamespace
@param string $currentNamespace
@param mixed $operatorValue
@param array $namedParameters | [
"Executes",
"the",
"operators"
] | train | https://github.com/netgen/ngopengraph/blob/68a99862f240ee74174ea9b888a9a33743142e27/autoloads/opengraphoperator.php#L78-L94 |
netgen/ngopengraph | autoloads/opengraphoperator.php | OpenGraphOperator.generateOpenGraphTags | function generateOpenGraphTags( $nodeID )
{
$this->ogIni = eZINI::instance( 'ngopengraph.ini' );
$this->facebookCompatible = $this->ogIni->variable( 'General', 'FacebookCompatible' );
$this->debug = $this->ogIni->variable( 'General', 'Debug' ) == 'enabled';
$availableClasses = $this->ogIni->variable( 'General', 'Classes' );
if ( $nodeID instanceof eZContentObjectTreeNode )
{
$contentNode = $nodeID;
}
else
{
$contentNode = eZContentObjectTreeNode::fetch( $nodeID );
if ( !$contentNode instanceof eZContentObjectTreeNode )
{
return array();
}
}
$contentObject = $contentNode->object();
if ( !$contentObject instanceof eZContentObject || !in_array( $contentObject->contentClassIdentifier(), $availableClasses ) )
{
return array();
}
$returnArray = $this->processGenericData( $contentNode );
$returnArray = $this->processObject( $contentObject, $returnArray );
if ( $this->checkRequirements( $returnArray ) )
{
return $returnArray;
}
else
{
if ( $this->debug )
{
eZDebug::writeDebug( 'No', 'Facebook Compatible?' );
}
return array();
}
} | php | function generateOpenGraphTags( $nodeID )
{
$this->ogIni = eZINI::instance( 'ngopengraph.ini' );
$this->facebookCompatible = $this->ogIni->variable( 'General', 'FacebookCompatible' );
$this->debug = $this->ogIni->variable( 'General', 'Debug' ) == 'enabled';
$availableClasses = $this->ogIni->variable( 'General', 'Classes' );
if ( $nodeID instanceof eZContentObjectTreeNode )
{
$contentNode = $nodeID;
}
else
{
$contentNode = eZContentObjectTreeNode::fetch( $nodeID );
if ( !$contentNode instanceof eZContentObjectTreeNode )
{
return array();
}
}
$contentObject = $contentNode->object();
if ( !$contentObject instanceof eZContentObject || !in_array( $contentObject->contentClassIdentifier(), $availableClasses ) )
{
return array();
}
$returnArray = $this->processGenericData( $contentNode );
$returnArray = $this->processObject( $contentObject, $returnArray );
if ( $this->checkRequirements( $returnArray ) )
{
return $returnArray;
}
else
{
if ( $this->debug )
{
eZDebug::writeDebug( 'No', 'Facebook Compatible?' );
}
return array();
}
} | [
"function",
"generateOpenGraphTags",
"(",
"$",
"nodeID",
")",
"{",
"$",
"this",
"->",
"ogIni",
"=",
"eZINI",
"::",
"instance",
"(",
"'ngopengraph.ini'",
")",
";",
"$",
"this",
"->",
"facebookCompatible",
"=",
"$",
"this",
"->",
"ogIni",
"->",
"variable",
"(",
"'General'",
",",
"'FacebookCompatible'",
")",
";",
"$",
"this",
"->",
"debug",
"=",
"$",
"this",
"->",
"ogIni",
"->",
"variable",
"(",
"'General'",
",",
"'Debug'",
")",
"==",
"'enabled'",
";",
"$",
"availableClasses",
"=",
"$",
"this",
"->",
"ogIni",
"->",
"variable",
"(",
"'General'",
",",
"'Classes'",
")",
";",
"if",
"(",
"$",
"nodeID",
"instanceof",
"eZContentObjectTreeNode",
")",
"{",
"$",
"contentNode",
"=",
"$",
"nodeID",
";",
"}",
"else",
"{",
"$",
"contentNode",
"=",
"eZContentObjectTreeNode",
"::",
"fetch",
"(",
"$",
"nodeID",
")",
";",
"if",
"(",
"!",
"$",
"contentNode",
"instanceof",
"eZContentObjectTreeNode",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}",
"$",
"contentObject",
"=",
"$",
"contentNode",
"->",
"object",
"(",
")",
";",
"if",
"(",
"!",
"$",
"contentObject",
"instanceof",
"eZContentObject",
"||",
"!",
"in_array",
"(",
"$",
"contentObject",
"->",
"contentClassIdentifier",
"(",
")",
",",
"$",
"availableClasses",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"returnArray",
"=",
"$",
"this",
"->",
"processGenericData",
"(",
"$",
"contentNode",
")",
";",
"$",
"returnArray",
"=",
"$",
"this",
"->",
"processObject",
"(",
"$",
"contentObject",
",",
"$",
"returnArray",
")",
";",
"if",
"(",
"$",
"this",
"->",
"checkRequirements",
"(",
"$",
"returnArray",
")",
")",
"{",
"return",
"$",
"returnArray",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"{",
"eZDebug",
"::",
"writeDebug",
"(",
"'No'",
",",
"'Facebook Compatible?'",
")",
";",
"}",
"return",
"array",
"(",
")",
";",
"}",
"}"
] | Executes opengraph operator
@param int|eZContentObjectTreeNode $nodeID
@return array | [
"Executes",
"opengraph",
"operator"
] | train | https://github.com/netgen/ngopengraph/blob/68a99862f240ee74174ea9b888a9a33743142e27/autoloads/opengraphoperator.php#L103-L148 |
netgen/ngopengraph | autoloads/opengraphoperator.php | OpenGraphOperator.processGenericData | function processGenericData( $contentNode )
{
$returnArray = array();
$siteName = trim( eZINI::instance()->variable( 'SiteSettings', 'SiteName' ) );
if ( !empty( $siteName ) )
{
$returnArray['og:site_name'] = $siteName;
}
$urlAlias = $contentNode->urlAlias();
eZURI::transformURI( $urlAlias, false, 'full' );
$returnArray['og:url'] = $urlAlias;
if ( $this->facebookCompatible == 'true' )
{
$appID = trim( $this->ogIni->variable( 'GenericData', 'app_id' ) );
if ( !empty( $appID ) )
{
$returnArray['fb:app_id'] = $appID;
}
$defaultAdmin = trim( $this->ogIni->variable( 'GenericData', 'default_admin' ) );
$data = '';
if ( !empty( $defaultAdmin ) )
{
$data = $defaultAdmin;
$admins = $this->ogIni->variable( 'GenericData', 'admins' );
if ( !empty( $admins ) )
{
$admins = trim( implode( ',', $admins ) );
$data = $data . ',' . $admins;
}
}
if ( !empty( $data ) )
{
$returnArray['fb:admins'] = $data;
}
}
return $returnArray;
} | php | function processGenericData( $contentNode )
{
$returnArray = array();
$siteName = trim( eZINI::instance()->variable( 'SiteSettings', 'SiteName' ) );
if ( !empty( $siteName ) )
{
$returnArray['og:site_name'] = $siteName;
}
$urlAlias = $contentNode->urlAlias();
eZURI::transformURI( $urlAlias, false, 'full' );
$returnArray['og:url'] = $urlAlias;
if ( $this->facebookCompatible == 'true' )
{
$appID = trim( $this->ogIni->variable( 'GenericData', 'app_id' ) );
if ( !empty( $appID ) )
{
$returnArray['fb:app_id'] = $appID;
}
$defaultAdmin = trim( $this->ogIni->variable( 'GenericData', 'default_admin' ) );
$data = '';
if ( !empty( $defaultAdmin ) )
{
$data = $defaultAdmin;
$admins = $this->ogIni->variable( 'GenericData', 'admins' );
if ( !empty( $admins ) )
{
$admins = trim( implode( ',', $admins ) );
$data = $data . ',' . $admins;
}
}
if ( !empty( $data ) )
{
$returnArray['fb:admins'] = $data;
}
}
return $returnArray;
} | [
"function",
"processGenericData",
"(",
"$",
"contentNode",
")",
"{",
"$",
"returnArray",
"=",
"array",
"(",
")",
";",
"$",
"siteName",
"=",
"trim",
"(",
"eZINI",
"::",
"instance",
"(",
")",
"->",
"variable",
"(",
"'SiteSettings'",
",",
"'SiteName'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"siteName",
")",
")",
"{",
"$",
"returnArray",
"[",
"'og:site_name'",
"]",
"=",
"$",
"siteName",
";",
"}",
"$",
"urlAlias",
"=",
"$",
"contentNode",
"->",
"urlAlias",
"(",
")",
";",
"eZURI",
"::",
"transformURI",
"(",
"$",
"urlAlias",
",",
"false",
",",
"'full'",
")",
";",
"$",
"returnArray",
"[",
"'og:url'",
"]",
"=",
"$",
"urlAlias",
";",
"if",
"(",
"$",
"this",
"->",
"facebookCompatible",
"==",
"'true'",
")",
"{",
"$",
"appID",
"=",
"trim",
"(",
"$",
"this",
"->",
"ogIni",
"->",
"variable",
"(",
"'GenericData'",
",",
"'app_id'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"appID",
")",
")",
"{",
"$",
"returnArray",
"[",
"'fb:app_id'",
"]",
"=",
"$",
"appID",
";",
"}",
"$",
"defaultAdmin",
"=",
"trim",
"(",
"$",
"this",
"->",
"ogIni",
"->",
"variable",
"(",
"'GenericData'",
",",
"'default_admin'",
")",
")",
";",
"$",
"data",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"defaultAdmin",
")",
")",
"{",
"$",
"data",
"=",
"$",
"defaultAdmin",
";",
"$",
"admins",
"=",
"$",
"this",
"->",
"ogIni",
"->",
"variable",
"(",
"'GenericData'",
",",
"'admins'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"admins",
")",
")",
"{",
"$",
"admins",
"=",
"trim",
"(",
"implode",
"(",
"','",
",",
"$",
"admins",
")",
")",
";",
"$",
"data",
"=",
"$",
"data",
".",
"','",
".",
"$",
"admins",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"returnArray",
"[",
"'fb:admins'",
"]",
"=",
"$",
"data",
";",
"}",
"}",
"return",
"$",
"returnArray",
";",
"}"
] | Processes literal Open Graph metadata
@param eZContentObjectTreeNode $contentNode
@return array | [
"Processes",
"literal",
"Open",
"Graph",
"metadata"
] | train | https://github.com/netgen/ngopengraph/blob/68a99862f240ee74174ea9b888a9a33743142e27/autoloads/opengraphoperator.php#L157-L201 |
netgen/ngopengraph | autoloads/opengraphoperator.php | OpenGraphOperator.processObject | function processObject( $contentObject, $returnArray )
{
if ( $this->ogIni->hasVariable( $contentObject->contentClassIdentifier(), 'LiteralMap' ) )
{
$literalValues = $this->ogIni->variable( $contentObject->contentClassIdentifier(), 'LiteralMap' );
if ( $this->debug )
{
eZDebug::writeDebug( $literalValues, 'LiteralMap' );
}
if ( $literalValues )
{
foreach ( $literalValues as $key => $value )
{
if ( !empty( $value ) )
{
$returnArray[$key] = $value;
}
}
}
}
if ( $this->ogIni->hasVariable( $contentObject->contentClassIdentifier(), 'AttributeMap' ) )
{
$attributeValues = $this->ogIni->variableArray( $contentObject->contentClassIdentifier(), 'AttributeMap' );
if ( $this->debug )
{
eZDebug::writeDebug( $attributeValues, 'AttributeMap' );
}
if ( $attributeValues )
{
foreach ( $attributeValues as $key => $value )
{
$contentObjectAttributeArray = $contentObject->fetchAttributesByIdentifier( array( $value[0] ) );
if ( !is_array( $contentObjectAttributeArray ) )
{
continue;
}
$contentObjectAttributeArray = array_values( $contentObjectAttributeArray );
$contentObjectAttribute = $contentObjectAttributeArray[0];
if ( $contentObjectAttribute instanceof eZContentObjectAttribute )
{
$openGraphHandler = ngOpenGraphBase::getInstance( $contentObjectAttribute );
if ( count( $value ) == 1 )
{
$data = $openGraphHandler->getData();
}
else if ( count( $value ) == 2 )
{
$data = $openGraphHandler->getDataMember( $value[1] );
}
else
{
$data = "";
}
if ( !empty( $data ) )
{
$returnArray[$key] = $data;
}
}
}
}
}
return $returnArray;
} | php | function processObject( $contentObject, $returnArray )
{
if ( $this->ogIni->hasVariable( $contentObject->contentClassIdentifier(), 'LiteralMap' ) )
{
$literalValues = $this->ogIni->variable( $contentObject->contentClassIdentifier(), 'LiteralMap' );
if ( $this->debug )
{
eZDebug::writeDebug( $literalValues, 'LiteralMap' );
}
if ( $literalValues )
{
foreach ( $literalValues as $key => $value )
{
if ( !empty( $value ) )
{
$returnArray[$key] = $value;
}
}
}
}
if ( $this->ogIni->hasVariable( $contentObject->contentClassIdentifier(), 'AttributeMap' ) )
{
$attributeValues = $this->ogIni->variableArray( $contentObject->contentClassIdentifier(), 'AttributeMap' );
if ( $this->debug )
{
eZDebug::writeDebug( $attributeValues, 'AttributeMap' );
}
if ( $attributeValues )
{
foreach ( $attributeValues as $key => $value )
{
$contentObjectAttributeArray = $contentObject->fetchAttributesByIdentifier( array( $value[0] ) );
if ( !is_array( $contentObjectAttributeArray ) )
{
continue;
}
$contentObjectAttributeArray = array_values( $contentObjectAttributeArray );
$contentObjectAttribute = $contentObjectAttributeArray[0];
if ( $contentObjectAttribute instanceof eZContentObjectAttribute )
{
$openGraphHandler = ngOpenGraphBase::getInstance( $contentObjectAttribute );
if ( count( $value ) == 1 )
{
$data = $openGraphHandler->getData();
}
else if ( count( $value ) == 2 )
{
$data = $openGraphHandler->getDataMember( $value[1] );
}
else
{
$data = "";
}
if ( !empty( $data ) )
{
$returnArray[$key] = $data;
}
}
}
}
}
return $returnArray;
} | [
"function",
"processObject",
"(",
"$",
"contentObject",
",",
"$",
"returnArray",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ogIni",
"->",
"hasVariable",
"(",
"$",
"contentObject",
"->",
"contentClassIdentifier",
"(",
")",
",",
"'LiteralMap'",
")",
")",
"{",
"$",
"literalValues",
"=",
"$",
"this",
"->",
"ogIni",
"->",
"variable",
"(",
"$",
"contentObject",
"->",
"contentClassIdentifier",
"(",
")",
",",
"'LiteralMap'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"{",
"eZDebug",
"::",
"writeDebug",
"(",
"$",
"literalValues",
",",
"'LiteralMap'",
")",
";",
"}",
"if",
"(",
"$",
"literalValues",
")",
"{",
"foreach",
"(",
"$",
"literalValues",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"returnArray",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"ogIni",
"->",
"hasVariable",
"(",
"$",
"contentObject",
"->",
"contentClassIdentifier",
"(",
")",
",",
"'AttributeMap'",
")",
")",
"{",
"$",
"attributeValues",
"=",
"$",
"this",
"->",
"ogIni",
"->",
"variableArray",
"(",
"$",
"contentObject",
"->",
"contentClassIdentifier",
"(",
")",
",",
"'AttributeMap'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"{",
"eZDebug",
"::",
"writeDebug",
"(",
"$",
"attributeValues",
",",
"'AttributeMap'",
")",
";",
"}",
"if",
"(",
"$",
"attributeValues",
")",
"{",
"foreach",
"(",
"$",
"attributeValues",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"contentObjectAttributeArray",
"=",
"$",
"contentObject",
"->",
"fetchAttributesByIdentifier",
"(",
"array",
"(",
"$",
"value",
"[",
"0",
"]",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"contentObjectAttributeArray",
")",
")",
"{",
"continue",
";",
"}",
"$",
"contentObjectAttributeArray",
"=",
"array_values",
"(",
"$",
"contentObjectAttributeArray",
")",
";",
"$",
"contentObjectAttribute",
"=",
"$",
"contentObjectAttributeArray",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"contentObjectAttribute",
"instanceof",
"eZContentObjectAttribute",
")",
"{",
"$",
"openGraphHandler",
"=",
"ngOpenGraphBase",
"::",
"getInstance",
"(",
"$",
"contentObjectAttribute",
")",
";",
"if",
"(",
"count",
"(",
"$",
"value",
")",
"==",
"1",
")",
"{",
"$",
"data",
"=",
"$",
"openGraphHandler",
"->",
"getData",
"(",
")",
";",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"value",
")",
"==",
"2",
")",
"{",
"$",
"data",
"=",
"$",
"openGraphHandler",
"->",
"getDataMember",
"(",
"$",
"value",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"\"\"",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"returnArray",
"[",
"$",
"key",
"]",
"=",
"$",
"data",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"returnArray",
";",
"}"
] | Processes Open Graph metadata from object attributes
@param eZContentObject $contentObject
@param array $returnArray
@return array | [
"Processes",
"Open",
"Graph",
"metadata",
"from",
"object",
"attributes"
] | train | https://github.com/netgen/ngopengraph/blob/68a99862f240ee74174ea9b888a9a33743142e27/autoloads/opengraphoperator.php#L211-L281 |
netgen/ngopengraph | autoloads/opengraphoperator.php | OpenGraphOperator.checkRequirements | function checkRequirements( $returnArray )
{
$arrayKeys = array_keys( $returnArray );
if ( !in_array( 'og:title', $arrayKeys ) || !in_array( 'og:type', $arrayKeys ) ||
!in_array( 'og:image', $arrayKeys ) || !in_array( 'og:url', $arrayKeys ) )
{
if ( $this->debug )
{
eZDebug::writeError( $arrayKeys, 'Missing an OG required field: title, image, type, or url' );
}
return false;
}
if ( $this->facebookCompatible == 'true' )
{
if ( !in_array( 'og:site_name', $arrayKeys ) || ( !in_array( 'fb:app_id', $arrayKeys ) && !in_array( 'fb:admins', $arrayKeys ) ) )
{
if ( $this->debug )
{
eZDebug::writeError( $arrayKeys, 'Missing a FB required field (in ngopengraph.ini): app_id, DefaultAdmin, or site name (site.ini)' );
}
return false;
}
}
return true;
} | php | function checkRequirements( $returnArray )
{
$arrayKeys = array_keys( $returnArray );
if ( !in_array( 'og:title', $arrayKeys ) || !in_array( 'og:type', $arrayKeys ) ||
!in_array( 'og:image', $arrayKeys ) || !in_array( 'og:url', $arrayKeys ) )
{
if ( $this->debug )
{
eZDebug::writeError( $arrayKeys, 'Missing an OG required field: title, image, type, or url' );
}
return false;
}
if ( $this->facebookCompatible == 'true' )
{
if ( !in_array( 'og:site_name', $arrayKeys ) || ( !in_array( 'fb:app_id', $arrayKeys ) && !in_array( 'fb:admins', $arrayKeys ) ) )
{
if ( $this->debug )
{
eZDebug::writeError( $arrayKeys, 'Missing a FB required field (in ngopengraph.ini): app_id, DefaultAdmin, or site name (site.ini)' );
}
return false;
}
}
return true;
} | [
"function",
"checkRequirements",
"(",
"$",
"returnArray",
")",
"{",
"$",
"arrayKeys",
"=",
"array_keys",
"(",
"$",
"returnArray",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"'og:title'",
",",
"$",
"arrayKeys",
")",
"||",
"!",
"in_array",
"(",
"'og:type'",
",",
"$",
"arrayKeys",
")",
"||",
"!",
"in_array",
"(",
"'og:image'",
",",
"$",
"arrayKeys",
")",
"||",
"!",
"in_array",
"(",
"'og:url'",
",",
"$",
"arrayKeys",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"{",
"eZDebug",
"::",
"writeError",
"(",
"$",
"arrayKeys",
",",
"'Missing an OG required field: title, image, type, or url'",
")",
";",
"}",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"facebookCompatible",
"==",
"'true'",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"'og:site_name'",
",",
"$",
"arrayKeys",
")",
"||",
"(",
"!",
"in_array",
"(",
"'fb:app_id'",
",",
"$",
"arrayKeys",
")",
"&&",
"!",
"in_array",
"(",
"'fb:admins'",
",",
"$",
"arrayKeys",
")",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"{",
"eZDebug",
"::",
"writeError",
"(",
"$",
"arrayKeys",
",",
"'Missing a FB required field (in ngopengraph.ini): app_id, DefaultAdmin, or site name (site.ini)'",
")",
";",
"}",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks if all required Open Graph metadata are present
@param array $returnArray
@return bool | [
"Checks",
"if",
"all",
"required",
"Open",
"Graph",
"metadata",
"are",
"present"
] | train | https://github.com/netgen/ngopengraph/blob/68a99862f240ee74174ea9b888a9a33743142e27/autoloads/opengraphoperator.php#L290-L319 |
dunkelfrosch/phpcoverfish | src/PHPCoverFish/Base/BaseScanner.php | BaseScanner.checkSourceAutoload | public function checkSourceAutoload($autoloadFile)
{
if (false === $this->coverFishHelper->checkFileExist($autoloadFile)) {
throw new \Exception(sprintf('autoload file "%s" not found! please define your autoload.php file to use (e.g. ../app/autoload.php in symfony)', $autoloadFile));
}
return true;
} | php | public function checkSourceAutoload($autoloadFile)
{
if (false === $this->coverFishHelper->checkFileExist($autoloadFile)) {
throw new \Exception(sprintf('autoload file "%s" not found! please define your autoload.php file to use (e.g. ../app/autoload.php in symfony)', $autoloadFile));
}
return true;
} | [
"public",
"function",
"checkSourceAutoload",
"(",
"$",
"autoloadFile",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"coverFishHelper",
"->",
"checkFileExist",
"(",
"$",
"autoloadFile",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'autoload file \"%s\" not found! please define your autoload.php file to use (e.g. ../app/autoload.php in symfony)'",
",",
"$",
"autoloadFile",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | check existence of given autoload file (raw/psr-0/psr-4)
@param string $autoloadFile
@return bool
@throws \Exception | [
"check",
"existence",
"of",
"given",
"autoload",
"file",
"(",
"raw",
"/",
"psr",
"-",
"0",
"/",
"psr",
"-",
"4",
")"
] | train | https://github.com/dunkelfrosch/phpcoverfish/blob/779bd399ec8f4cadb3b7854200695c5eb3f5a8ad/src/PHPCoverFish/Base/BaseScanner.php#L262-L269 |
dunkelfrosch/phpcoverfish | src/PHPCoverFish/Base/BaseScanner.php | BaseScanner.getAttributeFromXML | public function getAttributeFromXML($attribute, \SimpleXMLElement $xmlDocument)
{
/** @var \SimpleXMLElement $value */
foreach ($xmlDocument->attributes() as $key => $value) {
/** @var \SimpleXMLElement $attribute */
if ($attribute === $key) {
return (string) ($this->xmlToArray($value)[0]);
}
}
return false;
} | php | public function getAttributeFromXML($attribute, \SimpleXMLElement $xmlDocument)
{
/** @var \SimpleXMLElement $value */
foreach ($xmlDocument->attributes() as $key => $value) {
/** @var \SimpleXMLElement $attribute */
if ($attribute === $key) {
return (string) ($this->xmlToArray($value)[0]);
}
}
return false;
} | [
"public",
"function",
"getAttributeFromXML",
"(",
"$",
"attribute",
",",
"\\",
"SimpleXMLElement",
"$",
"xmlDocument",
")",
"{",
"/** @var \\SimpleXMLElement $value */",
"foreach",
"(",
"$",
"xmlDocument",
"->",
"attributes",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"/** @var \\SimpleXMLElement $attribute */",
"if",
"(",
"$",
"attribute",
"===",
"$",
"key",
")",
"{",
"return",
"(",
"string",
")",
"(",
"$",
"this",
"->",
"xmlToArray",
"(",
"$",
"value",
")",
"[",
"0",
"]",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | get a testSuite main attribute of given phpunit xml file (like name, bootstrap ...)
@param string $attribute
@param \SimpleXMLElement $xmlDocument
@return bool|string | [
"get",
"a",
"testSuite",
"main",
"attribute",
"of",
"given",
"phpunit",
"xml",
"file",
"(",
"like",
"name",
"bootstrap",
"...",
")"
] | train | https://github.com/dunkelfrosch/phpcoverfish/blob/779bd399ec8f4cadb3b7854200695c5eb3f5a8ad/src/PHPCoverFish/Base/BaseScanner.php#L279-L290 |
dunkelfrosch/phpcoverfish | src/PHPCoverFish/Base/BaseScanner.php | BaseScanner.xmlToArray | public function xmlToArray($xmlObject, $output = array())
{
foreach ((array) $xmlObject as $index => $node) {
$output[$index] = ($node instanceof \SimpleXMLElement || is_array($node))
? $this->xmlToArray($node)
: $node;
}
return $output;
} | php | public function xmlToArray($xmlObject, $output = array())
{
foreach ((array) $xmlObject as $index => $node) {
$output[$index] = ($node instanceof \SimpleXMLElement || is_array($node))
? $this->xmlToArray($node)
: $node;
}
return $output;
} | [
"public",
"function",
"xmlToArray",
"(",
"$",
"xmlObject",
",",
"$",
"output",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"xmlObject",
"as",
"$",
"index",
"=>",
"$",
"node",
")",
"{",
"$",
"output",
"[",
"$",
"index",
"]",
"=",
"(",
"$",
"node",
"instanceof",
"\\",
"SimpleXMLElement",
"||",
"is_array",
"(",
"$",
"node",
")",
")",
"?",
"$",
"this",
"->",
"xmlToArray",
"(",
"$",
"node",
")",
":",
"$",
"node",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | @param \SimpleXMLElement|array $xmlObject
@param array $output
@return array | [
"@param",
"\\",
"SimpleXMLElement|array",
"$xmlObject",
"@param",
"array",
"$output"
] | train | https://github.com/dunkelfrosch/phpcoverfish/blob/779bd399ec8f4cadb3b7854200695c5eb3f5a8ad/src/PHPCoverFish/Base/BaseScanner.php#L342-L351 |
dunkelfrosch/phpcoverfish | src/PHPCoverFish/Base/BaseScanner.php | BaseScanner.removeExcludedPath | public function removeExcludedPath(array $files, $excludePath)
{
$result = $includedFiles = array();
if (true === empty($excludePath)) {
return $files;
}
foreach ($files as $filePath) {
preg_match_all($this->coverFishHelper->getRegexPath($excludePath), $filePath, $result, PREG_SET_ORDER);
if (true === empty($result)) {
$includedFiles[] = $filePath;
}
}
return $includedFiles;
} | php | public function removeExcludedPath(array $files, $excludePath)
{
$result = $includedFiles = array();
if (true === empty($excludePath)) {
return $files;
}
foreach ($files as $filePath) {
preg_match_all($this->coverFishHelper->getRegexPath($excludePath), $filePath, $result, PREG_SET_ORDER);
if (true === empty($result)) {
$includedFiles[] = $filePath;
}
}
return $includedFiles;
} | [
"public",
"function",
"removeExcludedPath",
"(",
"array",
"$",
"files",
",",
"$",
"excludePath",
")",
"{",
"$",
"result",
"=",
"$",
"includedFiles",
"=",
"array",
"(",
")",
";",
"if",
"(",
"true",
"===",
"empty",
"(",
"$",
"excludePath",
")",
")",
"{",
"return",
"$",
"files",
";",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"filePath",
")",
"{",
"preg_match_all",
"(",
"$",
"this",
"->",
"coverFishHelper",
"->",
"getRegexPath",
"(",
"$",
"excludePath",
")",
",",
"$",
"filePath",
",",
"$",
"result",
",",
"PREG_SET_ORDER",
")",
";",
"if",
"(",
"true",
"===",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"includedFiles",
"[",
"]",
"=",
"$",
"filePath",
";",
"}",
"}",
"return",
"$",
"includedFiles",
";",
"}"
] | workaround for missing/buggy path exclude in symfony finder class
@param array $files
@param string $excludePath
@return array | [
"workaround",
"for",
"missing",
"/",
"buggy",
"path",
"exclude",
"in",
"symfony",
"finder",
"class"
] | train | https://github.com/dunkelfrosch/phpcoverfish/blob/779bd399ec8f4cadb3b7854200695c5eb3f5a8ad/src/PHPCoverFish/Base/BaseScanner.php#L371-L387 |
dunkelfrosch/phpcoverfish | src/PHPCoverFish/Base/BaseScanner.php | BaseScanner.scanFilesInPath | public function scanFilesInPath($sourcePath)
{
$filePattern = $this->filePattern;
if (strpos($sourcePath, str_replace('*', null, $filePattern))) {
$filePattern = $this->coverFishHelper->getFileNameFromPath($sourcePath);
}
$facade = new FinderFacade(
array($sourcePath),
$this->filePatternExclude,
array($filePattern)
);
return $this->removeExcludedPath($facade->findFiles(), $this->testExcludePath);
} | php | public function scanFilesInPath($sourcePath)
{
$filePattern = $this->filePattern;
if (strpos($sourcePath, str_replace('*', null, $filePattern))) {
$filePattern = $this->coverFishHelper->getFileNameFromPath($sourcePath);
}
$facade = new FinderFacade(
array($sourcePath),
$this->filePatternExclude,
array($filePattern)
);
return $this->removeExcludedPath($facade->findFiles(), $this->testExcludePath);
} | [
"public",
"function",
"scanFilesInPath",
"(",
"$",
"sourcePath",
")",
"{",
"$",
"filePattern",
"=",
"$",
"this",
"->",
"filePattern",
";",
"if",
"(",
"strpos",
"(",
"$",
"sourcePath",
",",
"str_replace",
"(",
"'*'",
",",
"null",
",",
"$",
"filePattern",
")",
")",
")",
"{",
"$",
"filePattern",
"=",
"$",
"this",
"->",
"coverFishHelper",
"->",
"getFileNameFromPath",
"(",
"$",
"sourcePath",
")",
";",
"}",
"$",
"facade",
"=",
"new",
"FinderFacade",
"(",
"array",
"(",
"$",
"sourcePath",
")",
",",
"$",
"this",
"->",
"filePatternExclude",
",",
"array",
"(",
"$",
"filePattern",
")",
")",
";",
"return",
"$",
"this",
"->",
"removeExcludedPath",
"(",
"$",
"facade",
"->",
"findFiles",
"(",
")",
",",
"$",
"this",
"->",
"testExcludePath",
")",
";",
"}"
] | scan all files by given path recursively, if one php file will be provided within given path,
this file will be returned in finder format
@param string $sourcePath
@return array | [
"scan",
"all",
"files",
"by",
"given",
"path",
"recursively",
"if",
"one",
"php",
"file",
"will",
"be",
"provided",
"within",
"given",
"path",
"this",
"file",
"will",
"be",
"returned",
"in",
"finder",
"format"
] | train | https://github.com/dunkelfrosch/phpcoverfish/blob/779bd399ec8f4cadb3b7854200695c5eb3f5a8ad/src/PHPCoverFish/Base/BaseScanner.php#L397-L411 |
yuncms/framework | src/rest/ErrorAction.php | ErrorAction.init | public function init()
{
$this->exception = $this->findException();
if ($this->defaultMessage === null) {
$this->defaultMessage = Yii::t('yii', 'An internal server error occurred.');
}
if ($this->defaultName === null) {
$this->defaultName = Yii::t('yuncms', 'Exception');
}
} | php | public function init()
{
$this->exception = $this->findException();
if ($this->defaultMessage === null) {
$this->defaultMessage = Yii::t('yii', 'An internal server error occurred.');
}
if ($this->defaultName === null) {
$this->defaultName = Yii::t('yuncms', 'Exception');
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"exception",
"=",
"$",
"this",
"->",
"findException",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"defaultMessage",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"defaultMessage",
"=",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'An internal server error occurred.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"defaultName",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"defaultName",
"=",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Exception'",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/ErrorAction.php#L72-L81 |
yuncms/framework | src/rest/ErrorAction.php | ErrorAction.getExceptionName | protected function getExceptionName()
{
if ($this->exception instanceof Exception) {
$name = $this->exception->getName();
} elseif ($this->exception instanceof ErrorException) {
$name = $this->exception->getName();
} else {
$name = $this->defaultName;
}
return $name;
} | php | protected function getExceptionName()
{
if ($this->exception instanceof Exception) {
$name = $this->exception->getName();
} elseif ($this->exception instanceof ErrorException) {
$name = $this->exception->getName();
} else {
$name = $this->defaultName;
}
return $name;
} | [
"protected",
"function",
"getExceptionName",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"exception",
"instanceof",
"Exception",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"exception",
"->",
"getName",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"exception",
"instanceof",
"ErrorException",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"exception",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"defaultName",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Returns the exception name, followed by the code (if present).
@return string | [
"Returns",
"the",
"exception",
"name",
"followed",
"by",
"the",
"code",
"(",
"if",
"present",
")",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/rest/ErrorAction.php#L132-L142 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getNameFromInstance($instance)
{
static $namnes;
if (!isset($namnes)) {
$namnes = array();
}
//only create a new plugin instance if it has not been created before
if (!isset($namnes[$instance])) {
$db = static::getDbo();
$query = $db->getQuery(true)
->select('original_name')
->from('#__jfusion')
->where('name = ' . $db->quote($instance));
$db->setQuery($query);
$name = $db->loadResult();
if (!$name) {
$name = $instance;
}
$namnes[$instance] = $name;
}
return $namnes[$instance];
} | php | public static function &getNameFromInstance($instance)
{
static $namnes;
if (!isset($namnes)) {
$namnes = array();
}
//only create a new plugin instance if it has not been created before
if (!isset($namnes[$instance])) {
$db = static::getDbo();
$query = $db->getQuery(true)
->select('original_name')
->from('#__jfusion')
->where('name = ' . $db->quote($instance));
$db->setQuery($query);
$name = $db->loadResult();
if (!$name) {
$name = $instance;
}
$namnes[$instance] = $name;
}
return $namnes[$instance];
} | [
"public",
"static",
"function",
"&",
"getNameFromInstance",
"(",
"$",
"instance",
")",
"{",
"static",
"$",
"namnes",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"namnes",
")",
")",
"{",
"$",
"namnes",
"=",
"array",
"(",
")",
";",
"}",
"//only create a new plugin instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"namnes",
"[",
"$",
"instance",
"]",
")",
")",
"{",
"$",
"db",
"=",
"static",
"::",
"getDbo",
"(",
")",
";",
"$",
"query",
"=",
"$",
"db",
"->",
"getQuery",
"(",
"true",
")",
"->",
"select",
"(",
"'original_name'",
")",
"->",
"from",
"(",
"'#__jfusion'",
")",
"->",
"where",
"(",
"'name = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"instance",
")",
")",
";",
"$",
"db",
"->",
"setQuery",
"(",
"$",
"query",
")",
";",
"$",
"name",
"=",
"$",
"db",
"->",
"loadResult",
"(",
")",
";",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"instance",
";",
"}",
"$",
"namnes",
"[",
"$",
"instance",
"]",
"=",
"$",
"name",
";",
"}",
"return",
"$",
"namnes",
"[",
"$",
"instance",
"]",
";",
"}"
] | Gets an Fusion front object
@param string $instance name of the JFusion plugin used
@return string object for the JFusion plugin | [
"Gets",
"an",
"Fusion",
"front",
"object"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L115-L139 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getFront($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new plugin instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Front';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Front';
}
$instances[$instance] = new $class($instance);
}
return $instances[$instance];
} | php | public static function &getFront($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new plugin instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Front';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Front';
}
$instances[$instance] = new $class($instance);
}
return $instances[$instance];
} | [
"public",
"static",
"function",
"&",
"getFront",
"(",
"$",
"instance",
")",
"{",
"static",
"$",
"instances",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
")",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"}",
"//only create a new plugin instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
"[",
"$",
"instance",
"]",
")",
")",
"{",
"$",
"name",
"=",
"static",
"::",
"getNameFromInstance",
"(",
"$",
"instance",
")",
";",
"static",
"::",
"pluginAutoLoad",
"(",
"$",
"name",
")",
";",
"$",
"class",
"=",
"'\\JFusion\\Plugins\\\\'",
".",
"$",
"name",
".",
"'\\Front'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"'\\JFusion\\Plugin\\Front'",
";",
"}",
"$",
"instances",
"[",
"$",
"instance",
"]",
"=",
"new",
"$",
"class",
"(",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"instances",
"[",
"$",
"instance",
"]",
";",
"}"
] | Gets an Fusion front object
@param string $instance name of the JFusion plugin used
@return Front object for the JFusion plugin | [
"Gets",
"an",
"Fusion",
"front",
"object"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L148-L167 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getAdmin($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new plugin instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Admin';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Admin';
}
$instances[$instance] = new $class($instance);
}
return $instances[$instance];
} | php | public static function &getAdmin($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new plugin instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Admin';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Admin';
}
$instances[$instance] = new $class($instance);
}
return $instances[$instance];
} | [
"public",
"static",
"function",
"&",
"getAdmin",
"(",
"$",
"instance",
")",
"{",
"static",
"$",
"instances",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
")",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"}",
"//only create a new plugin instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
"[",
"$",
"instance",
"]",
")",
")",
"{",
"$",
"name",
"=",
"static",
"::",
"getNameFromInstance",
"(",
"$",
"instance",
")",
";",
"static",
"::",
"pluginAutoLoad",
"(",
"$",
"name",
")",
";",
"$",
"class",
"=",
"'\\JFusion\\Plugins\\\\'",
".",
"$",
"name",
".",
"'\\Admin'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"'\\JFusion\\Plugin\\Admin'",
";",
"}",
"$",
"instances",
"[",
"$",
"instance",
"]",
"=",
"new",
"$",
"class",
"(",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"instances",
"[",
"$",
"instance",
"]",
";",
"}"
] | Gets an Fusion front object
@param string $instance name of the JFusion plugin used
@return Admin object for the JFusion plugin | [
"Gets",
"an",
"Fusion",
"front",
"object"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L175-L194 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getAuth($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new authentication instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Auth';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Auth';
}
$instances[$instance] = new $class($instance);
}
return $instances[$instance];
} | php | public static function &getAuth($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new authentication instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Auth';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Auth';
}
$instances[$instance] = new $class($instance);
}
return $instances[$instance];
} | [
"public",
"static",
"function",
"&",
"getAuth",
"(",
"$",
"instance",
")",
"{",
"static",
"$",
"instances",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
")",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"}",
"//only create a new authentication instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
"[",
"$",
"instance",
"]",
")",
")",
"{",
"$",
"name",
"=",
"static",
"::",
"getNameFromInstance",
"(",
"$",
"instance",
")",
";",
"static",
"::",
"pluginAutoLoad",
"(",
"$",
"name",
")",
";",
"$",
"class",
"=",
"'\\JFusion\\Plugins\\\\'",
".",
"$",
"name",
".",
"'\\Auth'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"'\\JFusion\\Plugin\\Auth'",
";",
"}",
"$",
"instances",
"[",
"$",
"instance",
"]",
"=",
"new",
"$",
"class",
"(",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"instances",
"[",
"$",
"instance",
"]",
";",
"}"
] | Gets an Authentication Class for the JFusion Plugin
@param string $instance name of the JFusion plugin used
@return Auth JFusion Authentication class for the JFusion plugin | [
"Gets",
"an",
"Authentication",
"Class",
"for",
"the",
"JFusion",
"Plugin"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L203-L222 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getUser($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new user instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\User';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\User';
}
$instances[$instance] = new $class($instance);
}
return $instances[$instance];
} | php | public static function &getUser($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new user instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\User';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\User';
}
$instances[$instance] = new $class($instance);
}
return $instances[$instance];
} | [
"public",
"static",
"function",
"&",
"getUser",
"(",
"$",
"instance",
")",
"{",
"static",
"$",
"instances",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
")",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"}",
"//only create a new user instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
"[",
"$",
"instance",
"]",
")",
")",
"{",
"$",
"name",
"=",
"static",
"::",
"getNameFromInstance",
"(",
"$",
"instance",
")",
";",
"static",
"::",
"pluginAutoLoad",
"(",
"$",
"name",
")",
";",
"$",
"class",
"=",
"'\\JFusion\\Plugins\\\\'",
".",
"$",
"name",
".",
"'\\User'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"'\\JFusion\\Plugin\\User'",
";",
"}",
"$",
"instances",
"[",
"$",
"instance",
"]",
"=",
"new",
"$",
"class",
"(",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"instances",
"[",
"$",
"instance",
"]",
";",
"}"
] | Gets an User Class for the JFusion Plugin
@param string $instance name of the JFusion plugin used
@return User JFusion User class for the JFusion plugin | [
"Gets",
"an",
"User",
"Class",
"for",
"the",
"JFusion",
"Plugin"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L231-L250 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getPlatform($platform, $instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
$platform = ucfirst(strtolower($platform));
//only create a new thread instance if it has not been created before
if (!isset($instances[$platform][$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Platform\\' . $platform . '\\Platform';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Platform\\' . $platform;
}
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Platform';
}
$instances[$platform][$instance] = new $class($instance);
}
return $instances[$platform][$instance];
} | php | public static function &getPlatform($platform, $instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
$platform = ucfirst(strtolower($platform));
//only create a new thread instance if it has not been created before
if (!isset($instances[$platform][$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Platform\\' . $platform . '\\Platform';
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Platform\\' . $platform;
}
if (!class_exists($class)) {
$class = '\JFusion\Plugin\Platform';
}
$instances[$platform][$instance] = new $class($instance);
}
return $instances[$platform][$instance];
} | [
"public",
"static",
"function",
"&",
"getPlatform",
"(",
"$",
"platform",
",",
"$",
"instance",
")",
"{",
"static",
"$",
"instances",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
")",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"}",
"$",
"platform",
"=",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"platform",
")",
")",
";",
"//only create a new thread instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
"[",
"$",
"platform",
"]",
"[",
"$",
"instance",
"]",
")",
")",
"{",
"$",
"name",
"=",
"static",
"::",
"getNameFromInstance",
"(",
"$",
"instance",
")",
";",
"static",
"::",
"pluginAutoLoad",
"(",
"$",
"name",
")",
";",
"$",
"class",
"=",
"'\\JFusion\\Plugins\\\\'",
".",
"$",
"name",
".",
"'\\Platform\\\\'",
".",
"$",
"platform",
".",
"'\\\\Platform'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"'\\JFusion\\Plugin\\Platform\\\\'",
".",
"$",
"platform",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"'\\JFusion\\Plugin\\Platform'",
";",
"}",
"$",
"instances",
"[",
"$",
"platform",
"]",
"[",
"$",
"instance",
"]",
"=",
"new",
"$",
"class",
"(",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"instances",
"[",
"$",
"platform",
"]",
"[",
"$",
"instance",
"]",
";",
"}"
] | Gets a Forum Class for the JFusion Plugin
@param string $platform
@param string $instance name of the JFusion plugin used
@return Platform JFusion Thread class for the JFusion plugin | [
"Gets",
"a",
"Forum",
"Class",
"for",
"the",
"JFusion",
"Plugin"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L260-L285 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getHelper($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new thread instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Helper';
if (!class_exists($class)) {
$instances[$instance] = false;
} else {
$instances[$instance] = new $class($instance);
}
}
return $instances[$instance];
} | php | public static function &getHelper($instance)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new thread instance if it has not been created before
if (!isset($instances[$instance])) {
$name = static::getNameFromInstance($instance);
static::pluginAutoLoad($name);
$class = '\JFusion\Plugins\\' . $name . '\Helper';
if (!class_exists($class)) {
$instances[$instance] = false;
} else {
$instances[$instance] = new $class($instance);
}
}
return $instances[$instance];
} | [
"public",
"static",
"function",
"&",
"getHelper",
"(",
"$",
"instance",
")",
"{",
"static",
"$",
"instances",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
")",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"}",
"//only create a new thread instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
"[",
"$",
"instance",
"]",
")",
")",
"{",
"$",
"name",
"=",
"static",
"::",
"getNameFromInstance",
"(",
"$",
"instance",
")",
";",
"static",
"::",
"pluginAutoLoad",
"(",
"$",
"name",
")",
";",
"$",
"class",
"=",
"'\\JFusion\\Plugins\\\\'",
".",
"$",
"name",
".",
"'\\Helper'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"instances",
"[",
"$",
"instance",
"]",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"instances",
"[",
"$",
"instance",
"]",
"=",
"new",
"$",
"class",
"(",
"$",
"instance",
")",
";",
"}",
"}",
"return",
"$",
"instances",
"[",
"$",
"instance",
"]",
";",
"}"
] | Gets a Helper Class for the JFusion Plugin which is only used internally by the plugin
@param string $instance name of the JFusion plugin used
@return Plugin|false JFusion Helper class for the JFusion plugin | [
"Gets",
"a",
"Helper",
"Class",
"for",
"the",
"JFusion",
"Plugin",
"which",
"is",
"only",
"used",
"internally",
"by",
"the",
"plugin"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L294-L314 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getDatabase($jname)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new database instance if it has not been created before
if (!isset($instances[$jname])) {
/**
* TODO: MUST BE CHANGED! as do not rely on joomla_int
*/
if ($jname == 'joomla_int') {
$db = self::getDBO();
} else {
//get config values
$params = static::getParams($jname);
//prepare the data for creating a database connection
$host = $params->get('database_host');
$user = $params->get('database_user');
$password = $params->get('database_password');
$database = $params->get('database_name');
$prefix = $params->get('database_prefix', '');
$driver = $params->get('database_type');
$charset = $params->get('database_charset', 'utf8');
//added extra code to prevent error when $driver is incorrect
$options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
$db = DatabaseFactory::getInstance()->getDriver($driver, $options);
if ($driver != 'sqlite') {
//add support for UTF8
$db->setQuery('SET names ' . $db->quote($charset));
$db->execute();
}
//get the debug configuration setting
$db->setDebug(Config::get()->get('debug'));
}
$instances[$jname] = $db;
}
return $instances[$jname];
} | php | public static function &getDatabase($jname)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
//only create a new database instance if it has not been created before
if (!isset($instances[$jname])) {
/**
* TODO: MUST BE CHANGED! as do not rely on joomla_int
*/
if ($jname == 'joomla_int') {
$db = self::getDBO();
} else {
//get config values
$params = static::getParams($jname);
//prepare the data for creating a database connection
$host = $params->get('database_host');
$user = $params->get('database_user');
$password = $params->get('database_password');
$database = $params->get('database_name');
$prefix = $params->get('database_prefix', '');
$driver = $params->get('database_type');
$charset = $params->get('database_charset', 'utf8');
//added extra code to prevent error when $driver is incorrect
$options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
$db = DatabaseFactory::getInstance()->getDriver($driver, $options);
if ($driver != 'sqlite') {
//add support for UTF8
$db->setQuery('SET names ' . $db->quote($charset));
$db->execute();
}
//get the debug configuration setting
$db->setDebug(Config::get()->get('debug'));
}
$instances[$jname] = $db;
}
return $instances[$jname];
} | [
"public",
"static",
"function",
"&",
"getDatabase",
"(",
"$",
"jname",
")",
"{",
"static",
"$",
"instances",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
")",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"}",
"//only create a new database instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
"[",
"$",
"jname",
"]",
")",
")",
"{",
"/**\n\t\t\t * TODO: MUST BE CHANGED! as do not rely on joomla_int\n\t\t\t */",
"if",
"(",
"$",
"jname",
"==",
"'joomla_int'",
")",
"{",
"$",
"db",
"=",
"self",
"::",
"getDBO",
"(",
")",
";",
"}",
"else",
"{",
"//get config values",
"$",
"params",
"=",
"static",
"::",
"getParams",
"(",
"$",
"jname",
")",
";",
"//prepare the data for creating a database connection",
"$",
"host",
"=",
"$",
"params",
"->",
"get",
"(",
"'database_host'",
")",
";",
"$",
"user",
"=",
"$",
"params",
"->",
"get",
"(",
"'database_user'",
")",
";",
"$",
"password",
"=",
"$",
"params",
"->",
"get",
"(",
"'database_password'",
")",
";",
"$",
"database",
"=",
"$",
"params",
"->",
"get",
"(",
"'database_name'",
")",
";",
"$",
"prefix",
"=",
"$",
"params",
"->",
"get",
"(",
"'database_prefix'",
",",
"''",
")",
";",
"$",
"driver",
"=",
"$",
"params",
"->",
"get",
"(",
"'database_type'",
")",
";",
"$",
"charset",
"=",
"$",
"params",
"->",
"get",
"(",
"'database_charset'",
",",
"'utf8'",
")",
";",
"//added extra code to prevent error when $driver is incorrect",
"$",
"options",
"=",
"array",
"(",
"'driver'",
"=>",
"$",
"driver",
",",
"'host'",
"=>",
"$",
"host",
",",
"'user'",
"=>",
"$",
"user",
",",
"'password'",
"=>",
"$",
"password",
",",
"'database'",
"=>",
"$",
"database",
",",
"'prefix'",
"=>",
"$",
"prefix",
")",
";",
"$",
"db",
"=",
"DatabaseFactory",
"::",
"getInstance",
"(",
")",
"->",
"getDriver",
"(",
"$",
"driver",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"driver",
"!=",
"'sqlite'",
")",
"{",
"//add support for UTF8",
"$",
"db",
"->",
"setQuery",
"(",
"'SET names '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"charset",
")",
")",
";",
"$",
"db",
"->",
"execute",
"(",
")",
";",
"}",
"//get the debug configuration setting",
"$",
"db",
"->",
"setDebug",
"(",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'debug'",
")",
")",
";",
"}",
"$",
"instances",
"[",
"$",
"jname",
"]",
"=",
"$",
"db",
";",
"}",
"return",
"$",
"instances",
"[",
"$",
"jname",
"]",
";",
"}"
] | Gets an Database Connection for the JFusion Plugin
@param string $jname name of the JFusion plugin used
@return DatabaseDriver Database connection for the JFusion plugin
@throws RuntimeException | [
"Gets",
"an",
"Database",
"Connection",
"for",
"the",
"JFusion",
"Plugin"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L338-L380 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getParams($jname, $reset = false)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
try {
//only create a new parameter instance if it has not been created before
if (!isset($instances[$jname]) || $reset) {
$db = self::getDBO();
$query = $db->getQuery(true)
->select('params')
->from('#__jfusion')
->where('name = ' . $db->quote($jname));
$db->setQuery($query);
$params = $db->loadResult();
$instances[$jname] = new Registry($params);
}
return $instances[$jname];
} catch (Exception $e) {
return new Registry();
}
} | php | public static function &getParams($jname, $reset = false)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
try {
//only create a new parameter instance if it has not been created before
if (!isset($instances[$jname]) || $reset) {
$db = self::getDBO();
$query = $db->getQuery(true)
->select('params')
->from('#__jfusion')
->where('name = ' . $db->quote($jname));
$db->setQuery($query);
$params = $db->loadResult();
$instances[$jname] = new Registry($params);
}
return $instances[$jname];
} catch (Exception $e) {
return new Registry();
}
} | [
"public",
"static",
"function",
"&",
"getParams",
"(",
"$",
"jname",
",",
"$",
"reset",
"=",
"false",
")",
"{",
"static",
"$",
"instances",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
")",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"}",
"try",
"{",
"//only create a new parameter instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
"[",
"$",
"jname",
"]",
")",
"||",
"$",
"reset",
")",
"{",
"$",
"db",
"=",
"self",
"::",
"getDBO",
"(",
")",
";",
"$",
"query",
"=",
"$",
"db",
"->",
"getQuery",
"(",
"true",
")",
"->",
"select",
"(",
"'params'",
")",
"->",
"from",
"(",
"'#__jfusion'",
")",
"->",
"where",
"(",
"'name = '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"jname",
")",
")",
";",
"$",
"db",
"->",
"setQuery",
"(",
"$",
"query",
")",
";",
"$",
"params",
"=",
"$",
"db",
"->",
"loadResult",
"(",
")",
";",
"$",
"instances",
"[",
"$",
"jname",
"]",
"=",
"new",
"Registry",
"(",
"$",
"params",
")",
";",
"}",
"return",
"$",
"instances",
"[",
"$",
"jname",
"]",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"new",
"Registry",
"(",
")",
";",
"}",
"}"
] | Gets an Parameter Object for the JFusion Plugin
@param string $jname name of the JFusion plugin used
@param boolean $reset switch to force a recreate of the instance
@return Registry JParam object for the JFusion plugin | [
"Gets",
"an",
"Parameter",
"Object",
"for",
"the",
"JFusion",
"Plugin"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L390-L415 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.getPlugins | public static function getPlugins($criteria = 'both', $exclude = false, $status = 2)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
$db = self::getDBO();
$query = $db->getQuery(true)
->select('*')
->from('#__jfusion');
$key = $criteria . '_' . $exclude . '_' . $status;
if (!isset($instances[$key])) {
if ($exclude !== false) {
$query->where('name NOT LIKE ' . $db->quote($exclude));
}
$query->where('status >= ' . (int)$status);
$query->order('ordering');
$db->setQuery($query);
$list = $db->loadObjectList();
switch ($criteria) {
case 'slave':
if (isset($list[0])) {
unset($list[0]);
}
break;
case 'master':
if (isset($list[0])) {
$list = $list[0];
} else {
$list = null;
}
break;
}
$instances[$key] = $list;
}
return $instances[$key];
} | php | public static function getPlugins($criteria = 'both', $exclude = false, $status = 2)
{
static $instances;
if (!isset($instances)) {
$instances = array();
}
$db = self::getDBO();
$query = $db->getQuery(true)
->select('*')
->from('#__jfusion');
$key = $criteria . '_' . $exclude . '_' . $status;
if (!isset($instances[$key])) {
if ($exclude !== false) {
$query->where('name NOT LIKE ' . $db->quote($exclude));
}
$query->where('status >= ' . (int)$status);
$query->order('ordering');
$db->setQuery($query);
$list = $db->loadObjectList();
switch ($criteria) {
case 'slave':
if (isset($list[0])) {
unset($list[0]);
}
break;
case 'master':
if (isset($list[0])) {
$list = $list[0];
} else {
$list = null;
}
break;
}
$instances[$key] = $list;
}
return $instances[$key];
} | [
"public",
"static",
"function",
"getPlugins",
"(",
"$",
"criteria",
"=",
"'both'",
",",
"$",
"exclude",
"=",
"false",
",",
"$",
"status",
"=",
"2",
")",
"{",
"static",
"$",
"instances",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
")",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"}",
"$",
"db",
"=",
"self",
"::",
"getDBO",
"(",
")",
";",
"$",
"query",
"=",
"$",
"db",
"->",
"getQuery",
"(",
"true",
")",
"->",
"select",
"(",
"'*'",
")",
"->",
"from",
"(",
"'#__jfusion'",
")",
";",
"$",
"key",
"=",
"$",
"criteria",
".",
"'_'",
".",
"$",
"exclude",
".",
"'_'",
".",
"$",
"status",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"instances",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"$",
"exclude",
"!==",
"false",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'name NOT LIKE '",
".",
"$",
"db",
"->",
"quote",
"(",
"$",
"exclude",
")",
")",
";",
"}",
"$",
"query",
"->",
"where",
"(",
"'status >= '",
".",
"(",
"int",
")",
"$",
"status",
")",
";",
"$",
"query",
"->",
"order",
"(",
"'ordering'",
")",
";",
"$",
"db",
"->",
"setQuery",
"(",
"$",
"query",
")",
";",
"$",
"list",
"=",
"$",
"db",
"->",
"loadObjectList",
"(",
")",
";",
"switch",
"(",
"$",
"criteria",
")",
"{",
"case",
"'slave'",
":",
"if",
"(",
"isset",
"(",
"$",
"list",
"[",
"0",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"list",
"[",
"0",
"]",
")",
";",
"}",
"break",
";",
"case",
"'master'",
":",
"if",
"(",
"isset",
"(",
"$",
"list",
"[",
"0",
"]",
")",
")",
"{",
"$",
"list",
"=",
"$",
"list",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"list",
"=",
"null",
";",
"}",
"break",
";",
"}",
"$",
"instances",
"[",
"$",
"key",
"]",
"=",
"$",
"list",
";",
"}",
"return",
"$",
"instances",
"[",
"$",
"key",
"]",
";",
"}"
] | returns array of plugins depending on the arguments
@param string $criteria the type of plugins to retrieve Use: master | slave | both
@param string|boolean $exclude should we exclude joomla_int
@param int $status only plugins with status equal or higher.
@return array|stdClass plugin details | [
"returns",
"array",
"of",
"plugins",
"depending",
"on",
"the",
"arguments"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L426-L466 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.getPluginNodeId | public static function getPluginNodeId($jname) {
$params = static::getParams($jname);
$source_url = $params->get('source_url');
return strtolower(rtrim(parse_url($source_url, PHP_URL_HOST) . parse_url($source_url, PHP_URL_PATH), '/'));
} | php | public static function getPluginNodeId($jname) {
$params = static::getParams($jname);
$source_url = $params->get('source_url');
return strtolower(rtrim(parse_url($source_url, PHP_URL_HOST) . parse_url($source_url, PHP_URL_PATH), '/'));
} | [
"public",
"static",
"function",
"getPluginNodeId",
"(",
"$",
"jname",
")",
"{",
"$",
"params",
"=",
"static",
"::",
"getParams",
"(",
"$",
"jname",
")",
";",
"$",
"source_url",
"=",
"$",
"params",
"->",
"get",
"(",
"'source_url'",
")",
";",
"return",
"strtolower",
"(",
"rtrim",
"(",
"parse_url",
"(",
"$",
"source_url",
",",
"PHP_URL_HOST",
")",
".",
"parse_url",
"(",
"$",
"source_url",
",",
"PHP_URL_PATH",
")",
",",
"'/'",
")",
")",
";",
"}"
] | Gets the jnode_id for the JFusion Plugin
@param string $jname name of the JFusion plugin used
@return string jnodeid for the JFusion Plugin | [
"Gets",
"the",
"jnode_id",
"for",
"the",
"JFusion",
"Plugin"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L473-L477 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.getPluginNameFromNodeId | public static function getPluginNameFromNodeId($jnode_id) {
$result = '';
//$jid = $jnode_id;
$plugins = static::getPlugins('both');
foreach($plugins as $plugin) {
$id = rtrim(static::getPluginNodeId($plugin->name), '/');
if (strcasecmp($jnode_id, $id) == 0) {
$result = $plugin->name;
break;
}
}
return $result;
} | php | public static function getPluginNameFromNodeId($jnode_id) {
$result = '';
//$jid = $jnode_id;
$plugins = static::getPlugins('both');
foreach($plugins as $plugin) {
$id = rtrim(static::getPluginNodeId($plugin->name), '/');
if (strcasecmp($jnode_id, $id) == 0) {
$result = $plugin->name;
break;
}
}
return $result;
} | [
"public",
"static",
"function",
"getPluginNameFromNodeId",
"(",
"$",
"jnode_id",
")",
"{",
"$",
"result",
"=",
"''",
";",
"//$jid = $jnode_id;",
"$",
"plugins",
"=",
"static",
"::",
"getPlugins",
"(",
"'both'",
")",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
")",
"{",
"$",
"id",
"=",
"rtrim",
"(",
"static",
"::",
"getPluginNodeId",
"(",
"$",
"plugin",
"->",
"name",
")",
",",
"'/'",
")",
";",
"if",
"(",
"strcasecmp",
"(",
"$",
"jnode_id",
",",
"$",
"id",
")",
"==",
"0",
")",
"{",
"$",
"result",
"=",
"$",
"plugin",
"->",
"name",
";",
"break",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Gets the plugin name for a JFusion Plugin given the jnodeid
@param string $jnode_id jnodeid to use
@return string jname name for the JFusion Plugin, empty if no plugin found | [
"Gets",
"the",
"plugin",
"name",
"for",
"a",
"JFusion",
"Plugin",
"given",
"the",
"jnodeid",
"@param",
"string",
"$jnode_id",
"jnodeid",
"to",
"use"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L484-L496 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.& | public static function &getCookies() {
static $instance;
//only create a new plugin instance if it has not been created before
if (!isset($instance)) {
$instance = new Cookies(Config::get()->get('apikey'));
}
return $instance;
} | php | public static function &getCookies() {
static $instance;
//only create a new plugin instance if it has not been created before
if (!isset($instance)) {
$instance = new Cookies(Config::get()->get('apikey'));
}
return $instance;
} | [
"public",
"static",
"function",
"&",
"getCookies",
"(",
")",
"{",
"static",
"$",
"instance",
";",
"//only create a new plugin instance if it has not been created before",
"if",
"(",
"!",
"isset",
"(",
"$",
"instance",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"Cookies",
"(",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'apikey'",
")",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Gets an JFusion cross domain cookie object
@return Cookies object for the JFusion cookies | [
"Gets",
"an",
"JFusion",
"cross",
"domain",
"cookie",
"object"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L503-L510 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.getDbo | public static function getDbo()
{
if (!self::$database)
{
//get config values
$host = Config::get()->get('database.host');
$user = Config::get()->get('database.user');
$password = Config::get()->get('database.password');
$database = Config::get()->get('database.name');
$prefix = Config::get()->get('database.prefix');
$driver = Config::get()->get('database.driver');
$debug = Config::get()->get('database.debug');
//added extra code to prevent error when $driver is incorrect
$options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
self::$database = DatabaseFactory::getInstance()->getDriver($driver, $options);
//get the debug configuration setting
self::$database->setDebug(Config::get()->get('debug'));
}
return self::$database;
} | php | public static function getDbo()
{
if (!self::$database)
{
//get config values
$host = Config::get()->get('database.host');
$user = Config::get()->get('database.user');
$password = Config::get()->get('database.password');
$database = Config::get()->get('database.name');
$prefix = Config::get()->get('database.prefix');
$driver = Config::get()->get('database.driver');
$debug = Config::get()->get('database.debug');
//added extra code to prevent error when $driver is incorrect
$options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
self::$database = DatabaseFactory::getInstance()->getDriver($driver, $options);
//get the debug configuration setting
self::$database->setDebug(Config::get()->get('debug'));
}
return self::$database;
} | [
"public",
"static",
"function",
"getDbo",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"database",
")",
"{",
"//get config values",
"$",
"host",
"=",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'database.host'",
")",
";",
"$",
"user",
"=",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'database.user'",
")",
";",
"$",
"password",
"=",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'database.password'",
")",
";",
"$",
"database",
"=",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'database.name'",
")",
";",
"$",
"prefix",
"=",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'database.prefix'",
")",
";",
"$",
"driver",
"=",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'database.driver'",
")",
";",
"$",
"debug",
"=",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'database.debug'",
")",
";",
"//added extra code to prevent error when $driver is incorrect",
"$",
"options",
"=",
"array",
"(",
"'driver'",
"=>",
"$",
"driver",
",",
"'host'",
"=>",
"$",
"host",
",",
"'user'",
"=>",
"$",
"user",
",",
"'password'",
"=>",
"$",
"password",
",",
"'database'",
"=>",
"$",
"database",
",",
"'prefix'",
"=>",
"$",
"prefix",
")",
";",
"self",
"::",
"$",
"database",
"=",
"DatabaseFactory",
"::",
"getInstance",
"(",
")",
"->",
"getDriver",
"(",
"$",
"driver",
",",
"$",
"options",
")",
";",
"//get the debug configuration setting",
"self",
"::",
"$",
"database",
"->",
"setDebug",
"(",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'debug'",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"database",
";",
"}"
] | Get a database object.
Returns the global {@link Driver} object, only creating it if it doesn't already exist.
@return DatabaseDriver | [
"Get",
"a",
"database",
"object",
"."
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L519-L543 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.getLanguage | public static function getLanguage()
{
if (!self::$language)
{
$locale = Config::get()->get('language.language');
$debug = Config::get()->get('language.debug');
self::$language = Language::getInstance($locale, $debug);
Text::setLanguage(self::$language);
}
return self::$language;
} | php | public static function getLanguage()
{
if (!self::$language)
{
$locale = Config::get()->get('language.language');
$debug = Config::get()->get('language.debug');
self::$language = Language::getInstance($locale, $debug);
Text::setLanguage(self::$language);
}
return self::$language;
} | [
"public",
"static",
"function",
"getLanguage",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"language",
")",
"{",
"$",
"locale",
"=",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'language.language'",
")",
";",
"$",
"debug",
"=",
"Config",
"::",
"get",
"(",
")",
"->",
"get",
"(",
"'language.debug'",
")",
";",
"self",
"::",
"$",
"language",
"=",
"Language",
"::",
"getInstance",
"(",
"$",
"locale",
",",
"$",
"debug",
")",
";",
"Text",
"::",
"setLanguage",
"(",
"self",
"::",
"$",
"language",
")",
";",
"}",
"return",
"self",
"::",
"$",
"language",
";",
"}"
] | Get a language object.
Returns the global {@link JLanguage} object, only creating it if it doesn't already exist.
@return Language object
@see Language
@since 11.1 | [
"Get",
"a",
"language",
"object",
"."
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L555-L566 |
jfusion/org.jfusion.framework | src/Factory.php | Factory.getDate | public static function getDate($time = 'now', $tzOffset = null)
{
static $classname;
static $mainLocale;
$language = self::getLanguage();
$locale = $language->getTag();
if (!isset($classname) || $locale != $mainLocale)
{
// Store the locale for future reference
$mainLocale = $locale;
if ($mainLocale !== false)
{
$classname = str_replace('-', '_', $mainLocale) . 'Date';
if (!class_exists($classname))
{
// The class does not exist, default to JDate
$classname = 'Date';
}
}
else
{
// No tag, so default to JDate
$classname = 'Date';
}
}
$key = $time . '-' . ($tzOffset instanceof DateTimeZone ? $tzOffset->getName() : (string) $tzOffset);
if (!isset(self::$dates[$classname][$key]))
{
self::$dates[$classname][$key] = new $classname($time, $tzOffset);
}
$date = clone self::$dates[$classname][$key];
return $date;
} | php | public static function getDate($time = 'now', $tzOffset = null)
{
static $classname;
static $mainLocale;
$language = self::getLanguage();
$locale = $language->getTag();
if (!isset($classname) || $locale != $mainLocale)
{
// Store the locale for future reference
$mainLocale = $locale;
if ($mainLocale !== false)
{
$classname = str_replace('-', '_', $mainLocale) . 'Date';
if (!class_exists($classname))
{
// The class does not exist, default to JDate
$classname = 'Date';
}
}
else
{
// No tag, so default to JDate
$classname = 'Date';
}
}
$key = $time . '-' . ($tzOffset instanceof DateTimeZone ? $tzOffset->getName() : (string) $tzOffset);
if (!isset(self::$dates[$classname][$key]))
{
self::$dates[$classname][$key] = new $classname($time, $tzOffset);
}
$date = clone self::$dates[$classname][$key];
return $date;
} | [
"public",
"static",
"function",
"getDate",
"(",
"$",
"time",
"=",
"'now'",
",",
"$",
"tzOffset",
"=",
"null",
")",
"{",
"static",
"$",
"classname",
";",
"static",
"$",
"mainLocale",
";",
"$",
"language",
"=",
"self",
"::",
"getLanguage",
"(",
")",
";",
"$",
"locale",
"=",
"$",
"language",
"->",
"getTag",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"classname",
")",
"||",
"$",
"locale",
"!=",
"$",
"mainLocale",
")",
"{",
"// Store the locale for future reference",
"$",
"mainLocale",
"=",
"$",
"locale",
";",
"if",
"(",
"$",
"mainLocale",
"!==",
"false",
")",
"{",
"$",
"classname",
"=",
"str_replace",
"(",
"'-'",
",",
"'_'",
",",
"$",
"mainLocale",
")",
".",
"'Date'",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"// The class does not exist, default to JDate",
"$",
"classname",
"=",
"'Date'",
";",
"}",
"}",
"else",
"{",
"// No tag, so default to JDate",
"$",
"classname",
"=",
"'Date'",
";",
"}",
"}",
"$",
"key",
"=",
"$",
"time",
".",
"'-'",
".",
"(",
"$",
"tzOffset",
"instanceof",
"DateTimeZone",
"?",
"$",
"tzOffset",
"->",
"getName",
"(",
")",
":",
"(",
"string",
")",
"$",
"tzOffset",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"dates",
"[",
"$",
"classname",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"self",
"::",
"$",
"dates",
"[",
"$",
"classname",
"]",
"[",
"$",
"key",
"]",
"=",
"new",
"$",
"classname",
"(",
"$",
"time",
",",
"$",
"tzOffset",
")",
";",
"}",
"$",
"date",
"=",
"clone",
"self",
"::",
"$",
"dates",
"[",
"$",
"classname",
"]",
"[",
"$",
"key",
"]",
";",
"return",
"$",
"date",
";",
"}"
] | Return the {@link JDate} object
@param mixed $time The initial time for the JDate object
@param mixed $tzOffset The timezone offset.
@return Date object
@see Date
@since 11.1 | [
"Return",
"the",
"{",
"@link",
"JDate",
"}",
"object"
] | train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Factory.php#L579-L619 |
ClanCats/Core | src/classes/CCRouter.php | CCRouter._init | public static function _init()
{
// default string
static::filter( 'any', '[a-zA-Z0-9'.ClanCats::$config->get( 'router.allowed_special_chars' ).']' );
// only numbers
static::filter( 'num', '[0-9]' );
// only alpha characters
static::filter( 'alpha', '[a-zA-Z]' );
// only alphanumeric characters
static::filter( 'alphanum', '[a-zA-Z0-9]' );
// 404 not found error
CCRouter::on( '#404', function()
{
return CCResponse::create( CCView::create( 'Core::CCF/404' )->render(), 404 );
});
} | php | public static function _init()
{
// default string
static::filter( 'any', '[a-zA-Z0-9'.ClanCats::$config->get( 'router.allowed_special_chars' ).']' );
// only numbers
static::filter( 'num', '[0-9]' );
// only alpha characters
static::filter( 'alpha', '[a-zA-Z]' );
// only alphanumeric characters
static::filter( 'alphanum', '[a-zA-Z0-9]' );
// 404 not found error
CCRouter::on( '#404', function()
{
return CCResponse::create( CCView::create( 'Core::CCF/404' )->render(), 404 );
});
} | [
"public",
"static",
"function",
"_init",
"(",
")",
"{",
"// default string",
"static",
"::",
"filter",
"(",
"'any'",
",",
"'[a-zA-Z0-9'",
".",
"ClanCats",
"::",
"$",
"config",
"->",
"get",
"(",
"'router.allowed_special_chars'",
")",
".",
"']'",
")",
";",
"// only numbers",
"static",
"::",
"filter",
"(",
"'num'",
",",
"'[0-9]'",
")",
";",
"// only alpha characters",
"static",
"::",
"filter",
"(",
"'alpha'",
",",
"'[a-zA-Z]'",
")",
";",
"// only alphanumeric characters",
"static",
"::",
"filter",
"(",
"'alphanum'",
",",
"'[a-zA-Z0-9]'",
")",
";",
"// 404 not found error",
"CCRouter",
"::",
"on",
"(",
"'#404'",
",",
"function",
"(",
")",
"{",
"return",
"CCResponse",
"::",
"create",
"(",
"CCView",
"::",
"create",
"(",
"'Core::CCF/404'",
")",
"->",
"render",
"(",
")",
",",
"404",
")",
";",
"}",
")",
";",
"}"
] | Set up the basic uri filters in our static init and
also add a default 404 response
@return void | [
"Set",
"up",
"the",
"basic",
"uri",
"filters",
"in",
"our",
"static",
"init",
"and",
"also",
"add",
"a",
"default",
"404",
"response"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCRouter.php#L64-L83 |
ClanCats/Core | src/classes/CCRouter.php | CCRouter.alias | public static function alias( $key, $to = null )
{
if ( is_null( $to ) || is_array( $to ) )
{
if ( array_key_exists( $key, static::$aliases ) )
{
if ( is_array( $to ) )
{
// Workaround for HHVM: return preg_replace( "/\[\w+\]/e", 'array_shift($to)', static::$aliases[$key] );
$return = static::$aliases[$key];
foreach( $to as $rpl )
{
$return = preg_replace( "/\[\w+\]/", $rpl, $return, 1 );
}
return $return;
}
return static::$aliases[$key];
}
return false;
}
static::$aliases[$key] = $to;
} | php | public static function alias( $key, $to = null )
{
if ( is_null( $to ) || is_array( $to ) )
{
if ( array_key_exists( $key, static::$aliases ) )
{
if ( is_array( $to ) )
{
// Workaround for HHVM: return preg_replace( "/\[\w+\]/e", 'array_shift($to)', static::$aliases[$key] );
$return = static::$aliases[$key];
foreach( $to as $rpl )
{
$return = preg_replace( "/\[\w+\]/", $rpl, $return, 1 );
}
return $return;
}
return static::$aliases[$key];
}
return false;
}
static::$aliases[$key] = $to;
} | [
"public",
"static",
"function",
"alias",
"(",
"$",
"key",
",",
"$",
"to",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"to",
")",
"||",
"is_array",
"(",
"$",
"to",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"static",
"::",
"$",
"aliases",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"to",
")",
")",
"{",
"// Workaround for HHVM: return preg_replace( \"/\\[\\w+\\]/e\", 'array_shift($to)', static::$aliases[$key] );",
"$",
"return",
"=",
"static",
"::",
"$",
"aliases",
"[",
"$",
"key",
"]",
";",
"foreach",
"(",
"$",
"to",
"as",
"$",
"rpl",
")",
"{",
"$",
"return",
"=",
"preg_replace",
"(",
"\"/\\[\\w+\\]/\"",
",",
"$",
"rpl",
",",
"$",
"return",
",",
"1",
")",
";",
"}",
"return",
"$",
"return",
";",
"}",
"return",
"static",
"::",
"$",
"aliases",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"false",
";",
"}",
"static",
"::",
"$",
"aliases",
"[",
"$",
"key",
"]",
"=",
"$",
"to",
";",
"}"
] | Creates an alias to a route or gets one
@param string $key
@param string $to
@return void | false | [
"Creates",
"an",
"alias",
"to",
"a",
"route",
"or",
"gets",
"one"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCRouter.php#L92-L115 |
ClanCats/Core | src/classes/CCRouter.php | CCRouter.events_matching | public static function events_matching( $event, $rule )
{
if ( !array_key_exists( $event, static::$events ) )
{
return array();
}
$callbacks = array();
foreach( static::$events[$event] as $route => $events )
{
$rgx = "~^".str_replace( '*', '(.*)', $route )."$~";
if ( preg_match( $rgx, $rule ) )
{
$callbacks = array_merge( $callbacks, $events );
}
}
return $callbacks;
} | php | public static function events_matching( $event, $rule )
{
if ( !array_key_exists( $event, static::$events ) )
{
return array();
}
$callbacks = array();
foreach( static::$events[$event] as $route => $events )
{
$rgx = "~^".str_replace( '*', '(.*)', $route )."$~";
if ( preg_match( $rgx, $rule ) )
{
$callbacks = array_merge( $callbacks, $events );
}
}
return $callbacks;
} | [
"public",
"static",
"function",
"events_matching",
"(",
"$",
"event",
",",
"$",
"rule",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"event",
",",
"static",
"::",
"$",
"events",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"callbacks",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"static",
"::",
"$",
"events",
"[",
"$",
"event",
"]",
"as",
"$",
"route",
"=>",
"$",
"events",
")",
"{",
"$",
"rgx",
"=",
"\"~^\"",
".",
"str_replace",
"(",
"'*'",
",",
"'(.*)'",
",",
"$",
"route",
")",
".",
"\"$~\"",
";",
"if",
"(",
"preg_match",
"(",
"$",
"rgx",
",",
"$",
"rule",
")",
")",
"{",
"$",
"callbacks",
"=",
"array_merge",
"(",
"$",
"callbacks",
",",
"$",
"events",
")",
";",
"}",
"}",
"return",
"$",
"callbacks",
";",
"}"
] | Get all events matching a rule
@param string $event
@param string $route
@param mixed $callback
@return void | [
"Get",
"all",
"events",
"matching",
"a",
"rule"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCRouter.php#L138-L157 |
ClanCats/Core | src/classes/CCRouter.php | CCRouter.on | public static function on( $param1, $param2 = null, $param3 = null )
{
// call contains options
if ( !is_null( $param3 ) && !is_callable( $param2 ) )
{
// if the param2 is a string we going to use it as alias
if ( is_string( $param2 ) )
{
static::alias( $param2, $param1 );
}
elseif ( is_array( $param2 ) )
{
// assign alias
if ( array_key_exists( 'alias', $param2 ) )
{
static::alias( $param2['alias'], $param1 );
}
// asign wake event
if ( array_key_exists( 'wake', $param2 ) )
{
static::event( 'wake', $param1, $param2['wake'] );
}
// assign sleep event
if ( array_key_exists( 'sleep', $param2 ) )
{
static::event( 'sleep', $param1, $param2['sleep'] );
}
}
$param2 = $param3; unset( $param3 );
}
if ( !is_array( $param1 ) )
{
$param1 = array( $param1 => $param2 );
}
static::prepare( $param1 );
} | php | public static function on( $param1, $param2 = null, $param3 = null )
{
// call contains options
if ( !is_null( $param3 ) && !is_callable( $param2 ) )
{
// if the param2 is a string we going to use it as alias
if ( is_string( $param2 ) )
{
static::alias( $param2, $param1 );
}
elseif ( is_array( $param2 ) )
{
// assign alias
if ( array_key_exists( 'alias', $param2 ) )
{
static::alias( $param2['alias'], $param1 );
}
// asign wake event
if ( array_key_exists( 'wake', $param2 ) )
{
static::event( 'wake', $param1, $param2['wake'] );
}
// assign sleep event
if ( array_key_exists( 'sleep', $param2 ) )
{
static::event( 'sleep', $param1, $param2['sleep'] );
}
}
$param2 = $param3; unset( $param3 );
}
if ( !is_array( $param1 ) )
{
$param1 = array( $param1 => $param2 );
}
static::prepare( $param1 );
} | [
"public",
"static",
"function",
"on",
"(",
"$",
"param1",
",",
"$",
"param2",
"=",
"null",
",",
"$",
"param3",
"=",
"null",
")",
"{",
"// call contains options",
"if",
"(",
"!",
"is_null",
"(",
"$",
"param3",
")",
"&&",
"!",
"is_callable",
"(",
"$",
"param2",
")",
")",
"{",
"// if the param2 is a string we going to use it as alias",
"if",
"(",
"is_string",
"(",
"$",
"param2",
")",
")",
"{",
"static",
"::",
"alias",
"(",
"$",
"param2",
",",
"$",
"param1",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"param2",
")",
")",
"{",
"// assign alias",
"if",
"(",
"array_key_exists",
"(",
"'alias'",
",",
"$",
"param2",
")",
")",
"{",
"static",
"::",
"alias",
"(",
"$",
"param2",
"[",
"'alias'",
"]",
",",
"$",
"param1",
")",
";",
"}",
"// asign wake event",
"if",
"(",
"array_key_exists",
"(",
"'wake'",
",",
"$",
"param2",
")",
")",
"{",
"static",
"::",
"event",
"(",
"'wake'",
",",
"$",
"param1",
",",
"$",
"param2",
"[",
"'wake'",
"]",
")",
";",
"}",
"// assign sleep event",
"if",
"(",
"array_key_exists",
"(",
"'sleep'",
",",
"$",
"param2",
")",
")",
"{",
"static",
"::",
"event",
"(",
"'sleep'",
",",
"$",
"param1",
",",
"$",
"param2",
"[",
"'sleep'",
"]",
")",
";",
"}",
"}",
"$",
"param2",
"=",
"$",
"param3",
";",
"unset",
"(",
"$",
"param3",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"param1",
")",
")",
"{",
"$",
"param1",
"=",
"array",
"(",
"$",
"param1",
"=>",
"$",
"param2",
")",
";",
"}",
"static",
"::",
"prepare",
"(",
"$",
"param1",
")",
";",
"}"
] | Add a route to the router
example:
CCRouter::on( 'user/mario', function(){} )
CCRouter::on( 'user/mario', array( 'alias' => 'profile' ), function(){} )
@param mixed $param1
@param mixed $param2
@param mixed $param3
@return void | [
"Add",
"a",
"route",
"to",
"the",
"router"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCRouter.php#L171-L209 |
ClanCats/Core | src/classes/CCRouter.php | CCRouter.prepare | protected static function prepare( $routes )
{
// flatten if needed
if ( ClanCats::$config->get( 'router.flatten_routes' ) )
{
$routes = static::flatten( $routes );
}
foreach( $routes as $uri => $route )
{
// check for an alias to a private
if ( is_string( $route ) )
{
if ( substr( $route, 0, 1 ) == '#' )
{
$route = static::$privates[$route];
}
}
// does this uri contain an alias?
if ( strpos( $uri, '@' ) !== false )
{
// is the entire route an alias
if ( $uri[0] == '@' )
{
static::$aliases[substr( $uri, 1 )] = $route;
}
// does it just contain an alias
else
{
list( $uri, $alias ) = explode( '@', $uri );
static::$aliases[$alias] = $uri;
}
}
// check for a private
if ( substr( $uri, 0, 1 ) == '#' )
{
static::$privates[$uri] = $route;
}
// just a normal one
else
{
static::$routes[$uri] = $route;
}
}
} | php | protected static function prepare( $routes )
{
// flatten if needed
if ( ClanCats::$config->get( 'router.flatten_routes' ) )
{
$routes = static::flatten( $routes );
}
foreach( $routes as $uri => $route )
{
// check for an alias to a private
if ( is_string( $route ) )
{
if ( substr( $route, 0, 1 ) == '#' )
{
$route = static::$privates[$route];
}
}
// does this uri contain an alias?
if ( strpos( $uri, '@' ) !== false )
{
// is the entire route an alias
if ( $uri[0] == '@' )
{
static::$aliases[substr( $uri, 1 )] = $route;
}
// does it just contain an alias
else
{
list( $uri, $alias ) = explode( '@', $uri );
static::$aliases[$alias] = $uri;
}
}
// check for a private
if ( substr( $uri, 0, 1 ) == '#' )
{
static::$privates[$uri] = $route;
}
// just a normal one
else
{
static::$routes[$uri] = $route;
}
}
} | [
"protected",
"static",
"function",
"prepare",
"(",
"$",
"routes",
")",
"{",
"// flatten if needed",
"if",
"(",
"ClanCats",
"::",
"$",
"config",
"->",
"get",
"(",
"'router.flatten_routes'",
")",
")",
"{",
"$",
"routes",
"=",
"static",
"::",
"flatten",
"(",
"$",
"routes",
")",
";",
"}",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"uri",
"=>",
"$",
"route",
")",
"{",
"// check for an alias to a private",
"if",
"(",
"is_string",
"(",
"$",
"route",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"route",
",",
"0",
",",
"1",
")",
"==",
"'#'",
")",
"{",
"$",
"route",
"=",
"static",
"::",
"$",
"privates",
"[",
"$",
"route",
"]",
";",
"}",
"}",
"// does this uri contain an alias?",
"if",
"(",
"strpos",
"(",
"$",
"uri",
",",
"'@'",
")",
"!==",
"false",
")",
"{",
"// is the entire route an alias",
"if",
"(",
"$",
"uri",
"[",
"0",
"]",
"==",
"'@'",
")",
"{",
"static",
"::",
"$",
"aliases",
"[",
"substr",
"(",
"$",
"uri",
",",
"1",
")",
"]",
"=",
"$",
"route",
";",
"}",
"// does it just contain an alias",
"else",
"{",
"list",
"(",
"$",
"uri",
",",
"$",
"alias",
")",
"=",
"explode",
"(",
"'@'",
",",
"$",
"uri",
")",
";",
"static",
"::",
"$",
"aliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"uri",
";",
"}",
"}",
"// check for a private ",
"if",
"(",
"substr",
"(",
"$",
"uri",
",",
"0",
",",
"1",
")",
"==",
"'#'",
")",
"{",
"static",
"::",
"$",
"privates",
"[",
"$",
"uri",
"]",
"=",
"$",
"route",
";",
"}",
"// just a normal one",
"else",
"{",
"static",
"::",
"$",
"routes",
"[",
"$",
"uri",
"]",
"=",
"$",
"route",
";",
"}",
"}",
"}"
] | Prepare the routes assing them to their containers
@param array $routes
@return void | [
"Prepare",
"the",
"routes",
"assing",
"them",
"to",
"their",
"containers"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCRouter.php#L217-L263 |
ClanCats/Core | src/classes/CCRouter.php | CCRouter.flatten | protected static function flatten( $routes, $param_prefix = '' )
{
$flattened = array();
foreach( $routes as $prefix => $route )
{
if ( is_array( $route ) && !is_callable( $route ) )
{
$flattened = array_merge( static::flatten( $route, $param_prefix.$prefix.'/' ), $flattened );
}
else
{
if ( $prefix == '/' )
{
$prefix = ''; $param_prefix = substr( $param_prefix, 0, -1 );
$flattened[$param_prefix.$prefix] = $route;
$param_prefix.= '/';
}
else
{
$flattened[$param_prefix.$prefix] = $route;
}
}
}
return $flattened;
} | php | protected static function flatten( $routes, $param_prefix = '' )
{
$flattened = array();
foreach( $routes as $prefix => $route )
{
if ( is_array( $route ) && !is_callable( $route ) )
{
$flattened = array_merge( static::flatten( $route, $param_prefix.$prefix.'/' ), $flattened );
}
else
{
if ( $prefix == '/' )
{
$prefix = ''; $param_prefix = substr( $param_prefix, 0, -1 );
$flattened[$param_prefix.$prefix] = $route;
$param_prefix.= '/';
}
else
{
$flattened[$param_prefix.$prefix] = $route;
}
}
}
return $flattened;
} | [
"protected",
"static",
"function",
"flatten",
"(",
"$",
"routes",
",",
"$",
"param_prefix",
"=",
"''",
")",
"{",
"$",
"flattened",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"prefix",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"route",
")",
"&&",
"!",
"is_callable",
"(",
"$",
"route",
")",
")",
"{",
"$",
"flattened",
"=",
"array_merge",
"(",
"static",
"::",
"flatten",
"(",
"$",
"route",
",",
"$",
"param_prefix",
".",
"$",
"prefix",
".",
"'/'",
")",
",",
"$",
"flattened",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"prefix",
"==",
"'/'",
")",
"{",
"$",
"prefix",
"=",
"''",
";",
"$",
"param_prefix",
"=",
"substr",
"(",
"$",
"param_prefix",
",",
"0",
",",
"-",
"1",
")",
";",
"$",
"flattened",
"[",
"$",
"param_prefix",
".",
"$",
"prefix",
"]",
"=",
"$",
"route",
";",
"$",
"param_prefix",
".=",
"'/'",
";",
"}",
"else",
"{",
"$",
"flattened",
"[",
"$",
"param_prefix",
".",
"$",
"prefix",
"]",
"=",
"$",
"route",
";",
"}",
"}",
"}",
"return",
"$",
"flattened",
";",
"}"
] | Flatten the routes
@param array $routes
@param string $param_prefix
@return array | [
"Flatten",
"the",
"routes"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCRouter.php#L284-L311 |
ClanCats/Core | src/classes/CCRouter.php | CCRouter.resolve | public static function resolve( $uri )
{
// cut unnecessary slashes and params
if ( substr( $uri, -1 ) == '/' )
{
$uri = substr( $uri, 0, -1 );
}
if ( substr( $uri, 0, 1 ) == '/' )
{
$uri = substr( $uri, 1 );
}
$uri = CCStr::cut( $uri, '?' );
// create new route instance
$route = new CCRoute( $uri );
// private route
if ( substr( $uri, 0, 1 ) == '#' ) {
if ( !array_key_exists( $uri, static::$privates ) )
{
throw new CCException( "CCRouter::resolve() - private route {$uri} could not be found." );
}
return static::configure( $route, static::$privates[$uri] );
}
// pass the route trough the priority events
if ( $hook_route = CCEvent::pass( 'ccf.router.resolve.before', array( $route, false ) ) )
{
if ( $hook_route[1] === true )
{
return static::configure( $route, $hook_route[0] );
}
}
// if the uri is empty root is requestet
if ( empty( $uri ) )
{
// try one slash also aka empty
if ( array_key_exists( '', static::$routes ) )
{
return static::configure( $route, static::$routes[''] );
}
return static::configure( $route, static::$privates['#root'] );
}
// simple static key route
if ( isset( static::$routes[$uri] ) )
{
return static::configure( $route, static::$routes[$uri] );
}
// explode the uri
$uri_parts = explode( '/', $uri );
// get the action
$action = array_pop( $uri_parts );
// implode the uri without action
$uri_without_action = implode( '/', $uri_parts );
// try the static key with an action
if ( isset( $action ) )
{
if ( isset( static::$routes[$uri_without_action] ) )
{
if ( CCController::has_action( static::$routes[$uri_without_action], $action ) )
{
$route->action = $action;
return static::configure( $route, static::$routes[$uri_without_action] );
}
}
}
// dynamic keys
foreach( static::$routes as $pattern => $dynamic_route )
{
// try the dynamic route only if it can be a pattern
if ( strpos( $pattern, '[' ) !== false && strpos( $pattern, ']' ) !== false )
{
// build an reqular expression
$regx = '#^'.CCStr::replace( $pattern, static::$filters ).'$#i';
// try to match the uri with regex
if ( preg_match( $regx, $uri, $params ) )
{
// remove the first param
unset( $params[0] );
$route->action = null;
$route->params = $params;
return static::configure( $route, $dynamic_route );
}
// try to match the uri without the action with the regex
if ( is_string($dynamic_route) && preg_match( $regx, $uri_without_action, $params ) )
{
if ( CCController::has_action( $dynamic_route, $action ) )
{
// remove the first param
unset( $params[0] );
$route->action = $action;
$route->params = $params;
return static::configure( $route, $dynamic_route );
}
}
}
}
/*
* pass to events
*/
if ( $hook_route = CCEvent::pass( 'ccf.router.resolve.after', array( $route, false ) ) ) {
if ( $hook_route[1] === true ) {
return static::configure( $route, $hook_route[0] );
}
}
return false;
} | php | public static function resolve( $uri )
{
// cut unnecessary slashes and params
if ( substr( $uri, -1 ) == '/' )
{
$uri = substr( $uri, 0, -1 );
}
if ( substr( $uri, 0, 1 ) == '/' )
{
$uri = substr( $uri, 1 );
}
$uri = CCStr::cut( $uri, '?' );
// create new route instance
$route = new CCRoute( $uri );
// private route
if ( substr( $uri, 0, 1 ) == '#' ) {
if ( !array_key_exists( $uri, static::$privates ) )
{
throw new CCException( "CCRouter::resolve() - private route {$uri} could not be found." );
}
return static::configure( $route, static::$privates[$uri] );
}
// pass the route trough the priority events
if ( $hook_route = CCEvent::pass( 'ccf.router.resolve.before', array( $route, false ) ) )
{
if ( $hook_route[1] === true )
{
return static::configure( $route, $hook_route[0] );
}
}
// if the uri is empty root is requestet
if ( empty( $uri ) )
{
// try one slash also aka empty
if ( array_key_exists( '', static::$routes ) )
{
return static::configure( $route, static::$routes[''] );
}
return static::configure( $route, static::$privates['#root'] );
}
// simple static key route
if ( isset( static::$routes[$uri] ) )
{
return static::configure( $route, static::$routes[$uri] );
}
// explode the uri
$uri_parts = explode( '/', $uri );
// get the action
$action = array_pop( $uri_parts );
// implode the uri without action
$uri_without_action = implode( '/', $uri_parts );
// try the static key with an action
if ( isset( $action ) )
{
if ( isset( static::$routes[$uri_without_action] ) )
{
if ( CCController::has_action( static::$routes[$uri_without_action], $action ) )
{
$route->action = $action;
return static::configure( $route, static::$routes[$uri_without_action] );
}
}
}
// dynamic keys
foreach( static::$routes as $pattern => $dynamic_route )
{
// try the dynamic route only if it can be a pattern
if ( strpos( $pattern, '[' ) !== false && strpos( $pattern, ']' ) !== false )
{
// build an reqular expression
$regx = '#^'.CCStr::replace( $pattern, static::$filters ).'$#i';
// try to match the uri with regex
if ( preg_match( $regx, $uri, $params ) )
{
// remove the first param
unset( $params[0] );
$route->action = null;
$route->params = $params;
return static::configure( $route, $dynamic_route );
}
// try to match the uri without the action with the regex
if ( is_string($dynamic_route) && preg_match( $regx, $uri_without_action, $params ) )
{
if ( CCController::has_action( $dynamic_route, $action ) )
{
// remove the first param
unset( $params[0] );
$route->action = $action;
$route->params = $params;
return static::configure( $route, $dynamic_route );
}
}
}
}
/*
* pass to events
*/
if ( $hook_route = CCEvent::pass( 'ccf.router.resolve.after', array( $route, false ) ) ) {
if ( $hook_route[1] === true ) {
return static::configure( $route, $hook_route[0] );
}
}
return false;
} | [
"public",
"static",
"function",
"resolve",
"(",
"$",
"uri",
")",
"{",
"// cut unnecessary slashes and params",
"if",
"(",
"substr",
"(",
"$",
"uri",
",",
"-",
"1",
")",
"==",
"'/'",
")",
"{",
"$",
"uri",
"=",
"substr",
"(",
"$",
"uri",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"uri",
",",
"0",
",",
"1",
")",
"==",
"'/'",
")",
"{",
"$",
"uri",
"=",
"substr",
"(",
"$",
"uri",
",",
"1",
")",
";",
"}",
"$",
"uri",
"=",
"CCStr",
"::",
"cut",
"(",
"$",
"uri",
",",
"'?'",
")",
";",
"// create new route instance",
"$",
"route",
"=",
"new",
"CCRoute",
"(",
"$",
"uri",
")",
";",
"// private route",
"if",
"(",
"substr",
"(",
"$",
"uri",
",",
"0",
",",
"1",
")",
"==",
"'#'",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"uri",
",",
"static",
"::",
"$",
"privates",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"\"CCRouter::resolve() - private route {$uri} could not be found.\"",
")",
";",
"}",
"return",
"static",
"::",
"configure",
"(",
"$",
"route",
",",
"static",
"::",
"$",
"privates",
"[",
"$",
"uri",
"]",
")",
";",
"}",
"// pass the route trough the priority events",
"if",
"(",
"$",
"hook_route",
"=",
"CCEvent",
"::",
"pass",
"(",
"'ccf.router.resolve.before'",
",",
"array",
"(",
"$",
"route",
",",
"false",
")",
")",
")",
"{",
"if",
"(",
"$",
"hook_route",
"[",
"1",
"]",
"===",
"true",
")",
"{",
"return",
"static",
"::",
"configure",
"(",
"$",
"route",
",",
"$",
"hook_route",
"[",
"0",
"]",
")",
";",
"}",
"}",
"// if the uri is empty root is requestet",
"if",
"(",
"empty",
"(",
"$",
"uri",
")",
")",
"{",
"// try one slash also aka empty",
"if",
"(",
"array_key_exists",
"(",
"''",
",",
"static",
"::",
"$",
"routes",
")",
")",
"{",
"return",
"static",
"::",
"configure",
"(",
"$",
"route",
",",
"static",
"::",
"$",
"routes",
"[",
"''",
"]",
")",
";",
"}",
"return",
"static",
"::",
"configure",
"(",
"$",
"route",
",",
"static",
"::",
"$",
"privates",
"[",
"'#root'",
"]",
")",
";",
"}",
"// simple static key route",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"routes",
"[",
"$",
"uri",
"]",
")",
")",
"{",
"return",
"static",
"::",
"configure",
"(",
"$",
"route",
",",
"static",
"::",
"$",
"routes",
"[",
"$",
"uri",
"]",
")",
";",
"}",
"// explode the uri",
"$",
"uri_parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"uri",
")",
";",
"// get the action",
"$",
"action",
"=",
"array_pop",
"(",
"$",
"uri_parts",
")",
";",
"// implode the uri without action",
"$",
"uri_without_action",
"=",
"implode",
"(",
"'/'",
",",
"$",
"uri_parts",
")",
";",
"// try the static key with an action",
"if",
"(",
"isset",
"(",
"$",
"action",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"routes",
"[",
"$",
"uri_without_action",
"]",
")",
")",
"{",
"if",
"(",
"CCController",
"::",
"has_action",
"(",
"static",
"::",
"$",
"routes",
"[",
"$",
"uri_without_action",
"]",
",",
"$",
"action",
")",
")",
"{",
"$",
"route",
"->",
"action",
"=",
"$",
"action",
";",
"return",
"static",
"::",
"configure",
"(",
"$",
"route",
",",
"static",
"::",
"$",
"routes",
"[",
"$",
"uri_without_action",
"]",
")",
";",
"}",
"}",
"}",
"// dynamic keys",
"foreach",
"(",
"static",
"::",
"$",
"routes",
"as",
"$",
"pattern",
"=>",
"$",
"dynamic_route",
")",
"{",
"// try the dynamic route only if it can be a pattern",
"if",
"(",
"strpos",
"(",
"$",
"pattern",
",",
"'['",
")",
"!==",
"false",
"&&",
"strpos",
"(",
"$",
"pattern",
",",
"']'",
")",
"!==",
"false",
")",
"{",
"// build an reqular expression\t",
"$",
"regx",
"=",
"'#^'",
".",
"CCStr",
"::",
"replace",
"(",
"$",
"pattern",
",",
"static",
"::",
"$",
"filters",
")",
".",
"'$#i'",
";",
"// try to match the uri with regex",
"if",
"(",
"preg_match",
"(",
"$",
"regx",
",",
"$",
"uri",
",",
"$",
"params",
")",
")",
"{",
"// remove the first param",
"unset",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"route",
"->",
"action",
"=",
"null",
";",
"$",
"route",
"->",
"params",
"=",
"$",
"params",
";",
"return",
"static",
"::",
"configure",
"(",
"$",
"route",
",",
"$",
"dynamic_route",
")",
";",
"}",
"// try to match the uri without the action with the regex",
"if",
"(",
"is_string",
"(",
"$",
"dynamic_route",
")",
"&&",
"preg_match",
"(",
"$",
"regx",
",",
"$",
"uri_without_action",
",",
"$",
"params",
")",
")",
"{",
"if",
"(",
"CCController",
"::",
"has_action",
"(",
"$",
"dynamic_route",
",",
"$",
"action",
")",
")",
"{",
"// remove the first param",
"unset",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"route",
"->",
"action",
"=",
"$",
"action",
";",
"$",
"route",
"->",
"params",
"=",
"$",
"params",
";",
"return",
"static",
"::",
"configure",
"(",
"$",
"route",
",",
"$",
"dynamic_route",
")",
";",
"}",
"}",
"}",
"}",
"/*\n\t\t * pass to events\n\t\t */",
"if",
"(",
"$",
"hook_route",
"=",
"CCEvent",
"::",
"pass",
"(",
"'ccf.router.resolve.after'",
",",
"array",
"(",
"$",
"route",
",",
"false",
")",
")",
")",
"{",
"if",
"(",
"$",
"hook_route",
"[",
"1",
"]",
"===",
"true",
")",
"{",
"return",
"static",
"::",
"configure",
"(",
"$",
"route",
",",
"$",
"hook_route",
"[",
"0",
"]",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Resolve an uri and get the route object
@param string $uri
@return CCRoute | [
"Resolve",
"an",
"uri",
"and",
"get",
"the",
"route",
"object"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCRouter.php#L319-L443 |
ClanCats/Core | src/classes/CCRouter.php | CCRouter.configure | protected static function configure( $route, $raw_route )
{
// deal with emptiness
if ( is_null( $raw_route ) )
{
return false;
}
// this might be a controller
if ( is_string( $raw_route ) )
{
// are there overwrite parameters?
if ( strpos( $raw_route, '?' ) !== false )
{
$route->params = explode( ',', CCStr::suffix( $raw_route, '?' ) );
$raw_route = CCStr::cut( $raw_route, '?' );
}
// is there a overwrite action?
if ( strpos( $raw_route, '@' ) !== false )
{
$route->action = CCStr::suffix( $raw_route, '@' );
$raw_route = CCStr::cut( $raw_route, '@' );
}
// try creating an controller instance
$controller = CCController::create( $raw_route );
// set the callback on controller execute
$route->callback = array( $controller, 'execute' );
}
// is the route callable set it up
elseif ( is_callable( $raw_route ) )
{
$route->callback = $raw_route;
}
return $route;
} | php | protected static function configure( $route, $raw_route )
{
// deal with emptiness
if ( is_null( $raw_route ) )
{
return false;
}
// this might be a controller
if ( is_string( $raw_route ) )
{
// are there overwrite parameters?
if ( strpos( $raw_route, '?' ) !== false )
{
$route->params = explode( ',', CCStr::suffix( $raw_route, '?' ) );
$raw_route = CCStr::cut( $raw_route, '?' );
}
// is there a overwrite action?
if ( strpos( $raw_route, '@' ) !== false )
{
$route->action = CCStr::suffix( $raw_route, '@' );
$raw_route = CCStr::cut( $raw_route, '@' );
}
// try creating an controller instance
$controller = CCController::create( $raw_route );
// set the callback on controller execute
$route->callback = array( $controller, 'execute' );
}
// is the route callable set it up
elseif ( is_callable( $raw_route ) )
{
$route->callback = $raw_route;
}
return $route;
} | [
"protected",
"static",
"function",
"configure",
"(",
"$",
"route",
",",
"$",
"raw_route",
")",
"{",
"// deal with emptiness",
"if",
"(",
"is_null",
"(",
"$",
"raw_route",
")",
")",
"{",
"return",
"false",
";",
"}",
"// this might be a controller",
"if",
"(",
"is_string",
"(",
"$",
"raw_route",
")",
")",
"{",
"// are there overwrite parameters?",
"if",
"(",
"strpos",
"(",
"$",
"raw_route",
",",
"'?'",
")",
"!==",
"false",
")",
"{",
"$",
"route",
"->",
"params",
"=",
"explode",
"(",
"','",
",",
"CCStr",
"::",
"suffix",
"(",
"$",
"raw_route",
",",
"'?'",
")",
")",
";",
"$",
"raw_route",
"=",
"CCStr",
"::",
"cut",
"(",
"$",
"raw_route",
",",
"'?'",
")",
";",
"}",
"// is there a overwrite action?",
"if",
"(",
"strpos",
"(",
"$",
"raw_route",
",",
"'@'",
")",
"!==",
"false",
")",
"{",
"$",
"route",
"->",
"action",
"=",
"CCStr",
"::",
"suffix",
"(",
"$",
"raw_route",
",",
"'@'",
")",
";",
"$",
"raw_route",
"=",
"CCStr",
"::",
"cut",
"(",
"$",
"raw_route",
",",
"'@'",
")",
";",
"}",
"// try creating an controller instance",
"$",
"controller",
"=",
"CCController",
"::",
"create",
"(",
"$",
"raw_route",
")",
";",
"// set the callback on controller execute",
"$",
"route",
"->",
"callback",
"=",
"array",
"(",
"$",
"controller",
",",
"'execute'",
")",
";",
"}",
"// is the route callable set it up",
"elseif",
"(",
"is_callable",
"(",
"$",
"raw_route",
")",
")",
"{",
"$",
"route",
"->",
"callback",
"=",
"$",
"raw_route",
";",
"}",
"return",
"$",
"route",
";",
"}"
] | Check and complete a route
@param CCRoute $route
@param mixed $raw_route
@return false|CCRoute | [
"Check",
"and",
"complete",
"a",
"route"
] | train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCRouter.php#L452-L489 |
shrink0r/workflux | src/State/ExecutionTracker.php | ExecutionTracker.track | public function track(StateInterface $state): int
{
$this->breadcrumbs->push($state->getName());
$this->execution_counts[$state->getName()]++;
return $this->execution_counts[$state->getName()];
} | php | public function track(StateInterface $state): int
{
$this->breadcrumbs->push($state->getName());
$this->execution_counts[$state->getName()]++;
return $this->execution_counts[$state->getName()];
} | [
"public",
"function",
"track",
"(",
"StateInterface",
"$",
"state",
")",
":",
"int",
"{",
"$",
"this",
"->",
"breadcrumbs",
"->",
"push",
"(",
"$",
"state",
"->",
"getName",
"(",
")",
")",
";",
"$",
"this",
"->",
"execution_counts",
"[",
"$",
"state",
"->",
"getName",
"(",
")",
"]",
"++",
";",
"return",
"$",
"this",
"->",
"execution_counts",
"[",
"$",
"state",
"->",
"getName",
"(",
")",
"]",
";",
"}"
] | @param StateInterface $state
@return int | [
"@param",
"StateInterface",
"$state"
] | train | https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/State/ExecutionTracker.php#L46-L51 |
fyuze/framework | src/Fyuze/Http/Message/Response.php | Response.withStatus | public function withStatus($code, $reasonPhrase = '')
{
$instance = clone $this;
$code = (int)$code;
if (is_float($code) || $code < 100 || $code >= 600) {
throw new \InvalidArgumentException(sprintf('Invalid status code %d', $code));
}
$instance->statusCode = $code;
$instance->reasonPhrase = $reasonPhrase;
return $instance;
} | php | public function withStatus($code, $reasonPhrase = '')
{
$instance = clone $this;
$code = (int)$code;
if (is_float($code) || $code < 100 || $code >= 600) {
throw new \InvalidArgumentException(sprintf('Invalid status code %d', $code));
}
$instance->statusCode = $code;
$instance->reasonPhrase = $reasonPhrase;
return $instance;
} | [
"public",
"function",
"withStatus",
"(",
"$",
"code",
",",
"$",
"reasonPhrase",
"=",
"''",
")",
"{",
"$",
"instance",
"=",
"clone",
"$",
"this",
";",
"$",
"code",
"=",
"(",
"int",
")",
"$",
"code",
";",
"if",
"(",
"is_float",
"(",
"$",
"code",
")",
"||",
"$",
"code",
"<",
"100",
"||",
"$",
"code",
">=",
"600",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid status code %d'",
",",
"$",
"code",
")",
")",
";",
"}",
"$",
"instance",
"->",
"statusCode",
"=",
"$",
"code",
";",
"$",
"instance",
"->",
"reasonPhrase",
"=",
"$",
"reasonPhrase",
";",
"return",
"$",
"instance",
";",
"}"
] | {@inheritdoc}
@link http://tools.ietf.org/html/rfc7231#section-6
@link http://www.iana.org/assignments/http-status-code s/http-status-codes.xhtml
@param int $code The 3-digit integer result code to set.
@param string $reasonPhrase
@return self
@throws \InvalidArgumentException For invalid status code arguments. | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/fyuze/framework/blob/89b3984f7225e24bfcdafb090ee197275b3222c9/src/Fyuze/Http/Message/Response.php#L108-L119 |
ixudra/generators | src/Commands/GenerateFileCommand.php | GenerateFileCommand.deriveArguments | protected function deriveArguments()
{
$this->tableName = strtolower( $this->getPluralResourceName() );
$this->classSingular = $this->getSingularClassName();
$this->classPlural = $this->getPluralClassName();
$this->variableSingular = $this->getSingularVariableName();
$this->variablePlural = $this->getPluralVariableName();
$this->constantSingular = strtoupper( $this->getSingularResourceName() );
$this->constantPlural = strtoupper( $this->getPluralResourceName() );
} | php | protected function deriveArguments()
{
$this->tableName = strtolower( $this->getPluralResourceName() );
$this->classSingular = $this->getSingularClassName();
$this->classPlural = $this->getPluralClassName();
$this->variableSingular = $this->getSingularVariableName();
$this->variablePlural = $this->getPluralVariableName();
$this->constantSingular = strtoupper( $this->getSingularResourceName() );
$this->constantPlural = strtoupper( $this->getPluralResourceName() );
} | [
"protected",
"function",
"deriveArguments",
"(",
")",
"{",
"$",
"this",
"->",
"tableName",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"getPluralResourceName",
"(",
")",
")",
";",
"$",
"this",
"->",
"classSingular",
"=",
"$",
"this",
"->",
"getSingularClassName",
"(",
")",
";",
"$",
"this",
"->",
"classPlural",
"=",
"$",
"this",
"->",
"getPluralClassName",
"(",
")",
";",
"$",
"this",
"->",
"variableSingular",
"=",
"$",
"this",
"->",
"getSingularVariableName",
"(",
")",
";",
"$",
"this",
"->",
"variablePlural",
"=",
"$",
"this",
"->",
"getPluralVariableName",
"(",
")",
";",
"$",
"this",
"->",
"constantSingular",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"getSingularResourceName",
"(",
")",
")",
";",
"$",
"this",
"->",
"constantPlural",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"getPluralResourceName",
"(",
")",
")",
";",
"}"
] | - Value deduction --- | [
"-",
"Value",
"deduction",
"---"
] | train | https://github.com/ixudra/generators/blob/3fa16efa157716f1425afa7a252b87df0d248a14/src/Commands/GenerateFileCommand.php#L79-L91 |
ixudra/generators | src/Commands/GenerateFileCommand.php | GenerateFileCommand.generateFromTemplate | protected function generateFromTemplate($template, $fileName, $path)
{
$file = $this->loadTemplate($template);
$content = $this->replaceValues( $file );
$this->createFile( $fileName, $path, $content );
return true;
} | php | protected function generateFromTemplate($template, $fileName, $path)
{
$file = $this->loadTemplate($template);
$content = $this->replaceValues( $file );
$this->createFile( $fileName, $path, $content );
return true;
} | [
"protected",
"function",
"generateFromTemplate",
"(",
"$",
"template",
",",
"$",
"fileName",
",",
"$",
"path",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"loadTemplate",
"(",
"$",
"template",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"replaceValues",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"createFile",
"(",
"$",
"fileName",
",",
"$",
"path",
",",
"$",
"content",
")",
";",
"return",
"true",
";",
"}"
] | - File generation --- | [
"-",
"File",
"generation",
"---"
] | train | https://github.com/ixudra/generators/blob/3fa16efa157716f1425afa7a252b87df0d248a14/src/Commands/GenerateFileCommand.php#L96-L103 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Section/Header.php | PHPWord_Section_Header.addTable | public function addTable($style = null) {
$table = new PHPWord_Section_Table('header', $this->_headerCount, $style);
$this->_elementCollection[] = $table;
return $table;
} | php | public function addTable($style = null) {
$table = new PHPWord_Section_Table('header', $this->_headerCount, $style);
$this->_elementCollection[] = $table;
return $table;
} | [
"public",
"function",
"addTable",
"(",
"$",
"style",
"=",
"null",
")",
"{",
"$",
"table",
"=",
"new",
"PHPWord_Section_Table",
"(",
"'header'",
",",
"$",
"this",
"->",
"_headerCount",
",",
"$",
"style",
")",
";",
"$",
"this",
"->",
"_elementCollection",
"[",
"]",
"=",
"$",
"table",
";",
"return",
"$",
"table",
";",
"}"
] | Add a Table Element
@param mixed $style
@return PHPWord_Section_Table | [
"Add",
"a",
"Table",
"Element"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/Header.php#L108-L112 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Section/Header.php | PHPWord_Section_Header.addImage | public function addImage($src, $style = null) {
$image = new PHPWord_Section_Image($src, $style);
if(!is_null($image->getSource())) {
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
trigger_error('Src does not exist or invalid image type.', E_ERROR);
}
} | php | public function addImage($src, $style = null) {
$image = new PHPWord_Section_Image($src, $style);
if(!is_null($image->getSource())) {
$rID = PHPWord_Media::addHeaderMediaElement($this->_headerCount, $src);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
trigger_error('Src does not exist or invalid image type.', E_ERROR);
}
} | [
"public",
"function",
"addImage",
"(",
"$",
"src",
",",
"$",
"style",
"=",
"null",
")",
"{",
"$",
"image",
"=",
"new",
"PHPWord_Section_Image",
"(",
"$",
"src",
",",
"$",
"style",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"image",
"->",
"getSource",
"(",
")",
")",
")",
"{",
"$",
"rID",
"=",
"PHPWord_Media",
"::",
"addHeaderMediaElement",
"(",
"$",
"this",
"->",
"_headerCount",
",",
"$",
"src",
")",
";",
"$",
"image",
"->",
"setRelationId",
"(",
"$",
"rID",
")",
";",
"$",
"this",
"->",
"_elementCollection",
"[",
"]",
"=",
"$",
"image",
";",
"return",
"$",
"image",
";",
"}",
"else",
"{",
"trigger_error",
"(",
"'Src does not exist or invalid image type.'",
",",
"E_ERROR",
")",
";",
"}",
"}"
] | Add a Image Element
@param string $src
@param mixed $style
@return PHPWord_Section_Image | [
"Add",
"a",
"Image",
"Element"
] | train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Section/Header.php#L121-L133 |
egeloen/IvorySerializerBundle | DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = $this->createTreeBuilder();
$treeBuilder->root('ivory_serializer')
->children()
->append($this->createEventNode())
->append($this->createMappingNode())
->append($this->createTypesNode())
->append($this->createVisitorsNode());
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = $this->createTreeBuilder();
$treeBuilder->root('ivory_serializer')
->children()
->append($this->createEventNode())
->append($this->createMappingNode())
->append($this->createTypesNode())
->append($this->createVisitorsNode());
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"$",
"this",
"->",
"createTreeBuilder",
"(",
")",
";",
"$",
"treeBuilder",
"->",
"root",
"(",
"'ivory_serializer'",
")",
"->",
"children",
"(",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createEventNode",
"(",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createMappingNode",
"(",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createTypesNode",
"(",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"createVisitorsNode",
"(",
")",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/egeloen/IvorySerializerBundle/blob/a2bdd912bf715c61b823cf7257ee232d5c823dd3/DependencyInjection/Configuration.php#L41-L52 |
RequestLab/Estat | src/RequestLab/HttpAdapter/JsonHttpAdapter.php | JsonHttpAdapter.fixContent | protected function fixContent($content)
{
if (is_array($content)) {
if (isset($content[0]) && $this->isJson($content[0])) {
return $content[0];
}
}
return parent::fixContent($content);
} | php | protected function fixContent($content)
{
if (is_array($content)) {
if (isset($content[0]) && $this->isJson($content[0])) {
return $content[0];
}
}
return parent::fixContent($content);
} | [
"protected",
"function",
"fixContent",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"content",
"[",
"0",
"]",
")",
"&&",
"$",
"this",
"->",
"isJson",
"(",
"$",
"content",
"[",
"0",
"]",
")",
")",
"{",
"return",
"$",
"content",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"parent",
"::",
"fixContent",
"(",
"$",
"content",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/RequestLab/Estat/blob/9517fcf359346f6c145c7a06975ab5a85352fed2/src/RequestLab/HttpAdapter/JsonHttpAdapter.php#L27-L36 |
webtown-php/KunstmaanExtensionBundle | src/Command/UserEditCommand.php | UserEditCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->logger = new SymfonyStyle($input, $output);
$this->input = $input;
$this->output = $output;
$this->userEditor = $this->getContainer()->get('webtown_kunstmaan_extension.user_edit');
$this->logger->title('User updater');
// find by options or find all users
$this->choices = $this->userEditor->getChoices($input->getOption('username'), $input->getOption('email'));
$this->selectionHandler();
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->logger = new SymfonyStyle($input, $output);
$this->input = $input;
$this->output = $output;
$this->userEditor = $this->getContainer()->get('webtown_kunstmaan_extension.user_edit');
$this->logger->title('User updater');
// find by options or find all users
$this->choices = $this->userEditor->getChoices($input->getOption('username'), $input->getOption('email'));
$this->selectionHandler();
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"logger",
"=",
"new",
"SymfonyStyle",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"this",
"->",
"input",
"=",
"$",
"input",
";",
"$",
"this",
"->",
"output",
"=",
"$",
"output",
";",
"$",
"this",
"->",
"userEditor",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'webtown_kunstmaan_extension.user_edit'",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"title",
"(",
"'User updater'",
")",
";",
"// find by options or find all users",
"$",
"this",
"->",
"choices",
"=",
"$",
"this",
"->",
"userEditor",
"->",
"getChoices",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'username'",
")",
",",
"$",
"input",
"->",
"getOption",
"(",
"'email'",
")",
")",
";",
"$",
"this",
"->",
"selectionHandler",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/webtown-php/KunstmaanExtensionBundle/blob/86c656c131295fe1f3f7694fd4da1e5e454076b9/src/Command/UserEditCommand.php#L67-L79 |
webtown-php/KunstmaanExtensionBundle | src/Command/UserEditCommand.php | UserEditCommand.selectionHandler | protected function selectionHandler()
{
$userCount = count($this->choices);
if ($userCount > static::MAX_USER_CHOICES) {
$this->autocomplete();
} elseif ($userCount > 1) {
$this->selector();
} elseif (1 === $userCount) {
$this->editor($this->choices[0]);
}
} | php | protected function selectionHandler()
{
$userCount = count($this->choices);
if ($userCount > static::MAX_USER_CHOICES) {
$this->autocomplete();
} elseif ($userCount > 1) {
$this->selector();
} elseif (1 === $userCount) {
$this->editor($this->choices[0]);
}
} | [
"protected",
"function",
"selectionHandler",
"(",
")",
"{",
"$",
"userCount",
"=",
"count",
"(",
"$",
"this",
"->",
"choices",
")",
";",
"if",
"(",
"$",
"userCount",
">",
"static",
"::",
"MAX_USER_CHOICES",
")",
"{",
"$",
"this",
"->",
"autocomplete",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"userCount",
">",
"1",
")",
"{",
"$",
"this",
"->",
"selector",
"(",
")",
";",
"}",
"elseif",
"(",
"1",
"===",
"$",
"userCount",
")",
"{",
"$",
"this",
"->",
"editor",
"(",
"$",
"this",
"->",
"choices",
"[",
"0",
"]",
")",
";",
"}",
"}"
] | Handle user selection depending on options and user count in db | [
"Handle",
"user",
"selection",
"depending",
"on",
"options",
"and",
"user",
"count",
"in",
"db"
] | train | https://github.com/webtown-php/KunstmaanExtensionBundle/blob/86c656c131295fe1f3f7694fd4da1e5e454076b9/src/Command/UserEditCommand.php#L84-L94 |
webtown-php/KunstmaanExtensionBundle | src/Command/UserEditCommand.php | UserEditCommand.selector | protected function selector(&$choices = null)
{
$choices = $choices ? $choices : $this->choices;
$choices = $this->userEditor->getChoicesAsEmailUsername($choices);
$question = new ChoiceQuestion(static::PLEASE_SELECT_A_USER, $choices);
$selectedUser = $this->ask($question);
$user = $this->getChoiceBySelection($selectedUser);
if ($user) {
$this->editor($user);
}
} | php | protected function selector(&$choices = null)
{
$choices = $choices ? $choices : $this->choices;
$choices = $this->userEditor->getChoicesAsEmailUsername($choices);
$question = new ChoiceQuestion(static::PLEASE_SELECT_A_USER, $choices);
$selectedUser = $this->ask($question);
$user = $this->getChoiceBySelection($selectedUser);
if ($user) {
$this->editor($user);
}
} | [
"protected",
"function",
"selector",
"(",
"&",
"$",
"choices",
"=",
"null",
")",
"{",
"$",
"choices",
"=",
"$",
"choices",
"?",
"$",
"choices",
":",
"$",
"this",
"->",
"choices",
";",
"$",
"choices",
"=",
"$",
"this",
"->",
"userEditor",
"->",
"getChoicesAsEmailUsername",
"(",
"$",
"choices",
")",
";",
"$",
"question",
"=",
"new",
"ChoiceQuestion",
"(",
"static",
"::",
"PLEASE_SELECT_A_USER",
",",
"$",
"choices",
")",
";",
"$",
"selectedUser",
"=",
"$",
"this",
"->",
"ask",
"(",
"$",
"question",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getChoiceBySelection",
"(",
"$",
"selectedUser",
")",
";",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"editor",
"(",
"$",
"user",
")",
";",
"}",
"}"
] | Multiple choices user select
@param User[] $choices | [
"Multiple",
"choices",
"user",
"select"
] | train | https://github.com/webtown-php/KunstmaanExtensionBundle/blob/86c656c131295fe1f3f7694fd4da1e5e454076b9/src/Command/UserEditCommand.php#L101-L111 |
webtown-php/KunstmaanExtensionBundle | src/Command/UserEditCommand.php | UserEditCommand.autocomplete | protected function autocomplete()
{
$question = new Question(static::PLEASE_SELECT_A_USER);
$question->setAutocompleterValues($this->userEditor->getChoicesAsSeparateEmailUsername($this->choices));
$selectedUser = $this->ask($question);
// nem választott usert, vége
if ('' === $selectedUser) {
return;
}
$user = $this->getChoiceByUsernameOrEmail($selectedUser);
// kiválasztott egy usert
if (!is_null($user)) {
$this->editor($user);
// nem választott konkrét usert
} else {
$choices = $this->userEditor->getChoices($selectedUser, $selectedUser, true, static::MAX_USER_CHOICES);
$this->selector($choices);
}
} | php | protected function autocomplete()
{
$question = new Question(static::PLEASE_SELECT_A_USER);
$question->setAutocompleterValues($this->userEditor->getChoicesAsSeparateEmailUsername($this->choices));
$selectedUser = $this->ask($question);
// nem választott usert, vége
if ('' === $selectedUser) {
return;
}
$user = $this->getChoiceByUsernameOrEmail($selectedUser);
// kiválasztott egy usert
if (!is_null($user)) {
$this->editor($user);
// nem választott konkrét usert
} else {
$choices = $this->userEditor->getChoices($selectedUser, $selectedUser, true, static::MAX_USER_CHOICES);
$this->selector($choices);
}
} | [
"protected",
"function",
"autocomplete",
"(",
")",
"{",
"$",
"question",
"=",
"new",
"Question",
"(",
"static",
"::",
"PLEASE_SELECT_A_USER",
")",
";",
"$",
"question",
"->",
"setAutocompleterValues",
"(",
"$",
"this",
"->",
"userEditor",
"->",
"getChoicesAsSeparateEmailUsername",
"(",
"$",
"this",
"->",
"choices",
")",
")",
";",
"$",
"selectedUser",
"=",
"$",
"this",
"->",
"ask",
"(",
"$",
"question",
")",
";",
"// nem választott usert, vége",
"if",
"(",
"''",
"===",
"$",
"selectedUser",
")",
"{",
"return",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"getChoiceByUsernameOrEmail",
"(",
"$",
"selectedUser",
")",
";",
"// kiválasztott egy usert",
"if",
"(",
"!",
"is_null",
"(",
"$",
"user",
")",
")",
"{",
"$",
"this",
"->",
"editor",
"(",
"$",
"user",
")",
";",
"// nem választott konkrét usert",
"}",
"else",
"{",
"$",
"choices",
"=",
"$",
"this",
"->",
"userEditor",
"->",
"getChoices",
"(",
"$",
"selectedUser",
",",
"$",
"selectedUser",
",",
"true",
",",
"static",
"::",
"MAX_USER_CHOICES",
")",
";",
"$",
"this",
"->",
"selector",
"(",
"$",
"choices",
")",
";",
"}",
"}"
] | Autocomplete user select | [
"Autocomplete",
"user",
"select"
] | train | https://github.com/webtown-php/KunstmaanExtensionBundle/blob/86c656c131295fe1f3f7694fd4da1e5e454076b9/src/Command/UserEditCommand.php#L116-L134 |
webtown-php/KunstmaanExtensionBundle | src/Command/UserEditCommand.php | UserEditCommand.editor | protected function editor(User $user)
{
// store props
$oldProps = new UserUpdater($user);
$newProps = $this->getNewValues($user);
// confirm
$ln = <<<EOL
Summary
-------
Username: "{$newProps->getUsername()}"
Email: "{$newProps->getEmail()}"
Password: "{$newProps->getPassword()}"
EOL;
$this->logger->block($ln);
// check changes
$changedValues = $oldProps->getChanged($newProps);
if (empty($changedValues)) {
$this->logger->note('Nothing changed, exiting.');
return;
}
// persist
if ($persist = $this->ask(new ConfirmationQuestion('Confirm user update?'))) {
$this->userEditor->updateUser($user, $newProps);
$this->logger->success('User updated!');
}
// send mail
if ($persist) {
$dontSend = 'Don\'t send';
$emailChoices = [$dontSend, $oldProps->getEmail()];
if (isset($changedValues['email'])) {
$emailChoices[] = $changedValues['email'];
}
$to = $this->ask(new ChoiceQuestion('Send notification to', $emailChoices));
if ($to !== $dontSend) {
$this->sendNotification($to, $changedValues);
}
}
} | php | protected function editor(User $user)
{
// store props
$oldProps = new UserUpdater($user);
$newProps = $this->getNewValues($user);
// confirm
$ln = <<<EOL
Summary
-------
Username: "{$newProps->getUsername()}"
Email: "{$newProps->getEmail()}"
Password: "{$newProps->getPassword()}"
EOL;
$this->logger->block($ln);
// check changes
$changedValues = $oldProps->getChanged($newProps);
if (empty($changedValues)) {
$this->logger->note('Nothing changed, exiting.');
return;
}
// persist
if ($persist = $this->ask(new ConfirmationQuestion('Confirm user update?'))) {
$this->userEditor->updateUser($user, $newProps);
$this->logger->success('User updated!');
}
// send mail
if ($persist) {
$dontSend = 'Don\'t send';
$emailChoices = [$dontSend, $oldProps->getEmail()];
if (isset($changedValues['email'])) {
$emailChoices[] = $changedValues['email'];
}
$to = $this->ask(new ChoiceQuestion('Send notification to', $emailChoices));
if ($to !== $dontSend) {
$this->sendNotification($to, $changedValues);
}
}
} | [
"protected",
"function",
"editor",
"(",
"User",
"$",
"user",
")",
"{",
"// store props",
"$",
"oldProps",
"=",
"new",
"UserUpdater",
"(",
"$",
"user",
")",
";",
"$",
"newProps",
"=",
"$",
"this",
"->",
"getNewValues",
"(",
"$",
"user",
")",
";",
"// confirm",
"$",
"ln",
"=",
" <<<EOL\nSummary\n-------\nUsername: \"{$newProps->getUsername()}\"\nEmail: \"{$newProps->getEmail()}\"\nPassword: \"{$newProps->getPassword()}\"\nEOL",
";",
"$",
"this",
"->",
"logger",
"->",
"block",
"(",
"$",
"ln",
")",
";",
"// check changes",
"$",
"changedValues",
"=",
"$",
"oldProps",
"->",
"getChanged",
"(",
"$",
"newProps",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"changedValues",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"note",
"(",
"'Nothing changed, exiting.'",
")",
";",
"return",
";",
"}",
"// persist",
"if",
"(",
"$",
"persist",
"=",
"$",
"this",
"->",
"ask",
"(",
"new",
"ConfirmationQuestion",
"(",
"'Confirm user update?'",
")",
")",
")",
"{",
"$",
"this",
"->",
"userEditor",
"->",
"updateUser",
"(",
"$",
"user",
",",
"$",
"newProps",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"success",
"(",
"'User updated!'",
")",
";",
"}",
"// send mail",
"if",
"(",
"$",
"persist",
")",
"{",
"$",
"dontSend",
"=",
"'Don\\'t send'",
";",
"$",
"emailChoices",
"=",
"[",
"$",
"dontSend",
",",
"$",
"oldProps",
"->",
"getEmail",
"(",
")",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"changedValues",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"emailChoices",
"[",
"]",
"=",
"$",
"changedValues",
"[",
"'email'",
"]",
";",
"}",
"$",
"to",
"=",
"$",
"this",
"->",
"ask",
"(",
"new",
"ChoiceQuestion",
"(",
"'Send notification to'",
",",
"$",
"emailChoices",
")",
")",
";",
"if",
"(",
"$",
"to",
"!==",
"$",
"dontSend",
")",
"{",
"$",
"this",
"->",
"sendNotification",
"(",
"$",
"to",
",",
"$",
"changedValues",
")",
";",
"}",
"}",
"}"
] | Show user editor
@param User $user | [
"Show",
"user",
"editor"
] | train | https://github.com/webtown-php/KunstmaanExtensionBundle/blob/86c656c131295fe1f3f7694fd4da1e5e454076b9/src/Command/UserEditCommand.php#L141-L181 |
webtown-php/KunstmaanExtensionBundle | src/Command/UserEditCommand.php | UserEditCommand.sendNotification | protected function sendNotification($to, array $changedValues)
{
$message = \Swift_Message::newInstance()
->setSubject('User details updated')
->setFrom($this->getContainer()->getParameter('fos_user.resetting.email.from_email'))
->setTo($to)
->setBody(
$this->getContainer()->get('twig')->render(
'@WebtownKunstmaanExtension/email/user_edit.html.twig',
['changes' => $changedValues]
),
'text/html'
);
$this->getContainer()->get('mailer')->send($message);
} | php | protected function sendNotification($to, array $changedValues)
{
$message = \Swift_Message::newInstance()
->setSubject('User details updated')
->setFrom($this->getContainer()->getParameter('fos_user.resetting.email.from_email'))
->setTo($to)
->setBody(
$this->getContainer()->get('twig')->render(
'@WebtownKunstmaanExtension/email/user_edit.html.twig',
['changes' => $changedValues]
),
'text/html'
);
$this->getContainer()->get('mailer')->send($message);
} | [
"protected",
"function",
"sendNotification",
"(",
"$",
"to",
",",
"array",
"$",
"changedValues",
")",
"{",
"$",
"message",
"=",
"\\",
"Swift_Message",
"::",
"newInstance",
"(",
")",
"->",
"setSubject",
"(",
"'User details updated'",
")",
"->",
"setFrom",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"getParameter",
"(",
"'fos_user.resetting.email.from_email'",
")",
")",
"->",
"setTo",
"(",
"$",
"to",
")",
"->",
"setBody",
"(",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'twig'",
")",
"->",
"render",
"(",
"'@WebtownKunstmaanExtension/email/user_edit.html.twig'",
",",
"[",
"'changes'",
"=>",
"$",
"changedValues",
"]",
")",
",",
"'text/html'",
")",
";",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'mailer'",
")",
"->",
"send",
"(",
"$",
"message",
")",
";",
"}"
] | Send email notification about changes
@param $to
@param array $changedValues | [
"Send",
"email",
"notification",
"about",
"changes"
] | train | https://github.com/webtown-php/KunstmaanExtensionBundle/blob/86c656c131295fe1f3f7694fd4da1e5e454076b9/src/Command/UserEditCommand.php#L189-L203 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.