public static function getValueFromEnvironment(array $collection) { foreach ($collection as &$value) { //check for sobstitution if (is_string($value) && (strpos($value, '{{@') === 0 && strpos($value, '}}') !== false)) { if (($toReplace = Manipulation::getBetween($value, '{{@', '}}')) != '') { $value = getenv($toReplace); if ($value !== false) { $value = $value; } elseif (defined($toReplace)) { $value = constant($toReplace); } } } elseif (is_array($value)) { $value = self::getValueFromEnvironment($value); } elseif ($value instanceof GenericCollection) { $value = self::getValueFromEnvironment($value->all()); } } return $collection; }
/** * build a regex out of the URI of the current Route and adds name of * regex placeholders. * * Example: * <code> * array( * "regex" => "...", * "params" => array("name", "surname") * ) * </code> * * __Note:__ if the regex field of the returned array is an empty string, * then the router is a special callback * * @return array the regex version of the URI and additional info */ public function getRegex() { //fix the URI $regexURI = null; $paramArray = []; $paramSkip = []; $paramTypes = []; if ($this->isSpecialCallback() === false) { //start building the regex $regexURI = '/^' . preg_quote($this->URI, '/') . '$/'; //this will contain the matched expressions placeholders $params = []; //detect if regex are involved in the furnished URI if (preg_match_all("/\\\\{([a-zA-Z]|\\d|\\_|\\.|\\:|\\\\)+\\\\}/", $regexURI, $params)) { //substitute a regex for each matching group: foreach ($params[0] as $mathingGroup) { //extract the regex to be used $param = Manipulation::getBetween($mathingGroup, '\\{', '\\}'); $regexId = explode('\\:', $param, 2); $currentRegex = ''; if (count($regexId) == 2) { $currentRegex = strval($regexId[1]); } $param = $regexId[0]; $regexTableId = 'default'; switch (strtolower($currentRegex)) { case 'mail': case 'email': $regexTableId = 'email'; break; case 'number': case 'integer': case 'signed_integer': $regexTableId = 'signed_integer'; break; default: $regexTableId = 'default'; } $regexURI = str_replace($mathingGroup, '(' . self::$regexTable[$regexTableId][0] . ')', $regexURI); $paramArray[] = $param; $paramTypes[] = $regexTableId; $paramSkip[] = self::$regexTable[$regexTableId][1]; } } } //return the built regex + additionals info return ['regex' => !is_null($regexURI) ? $regexURI : '', 'params' => $paramArray, 'param_types' => $paramTypes, 'skipping_params' => $paramSkip]; }