public function getParameterAsBool($key, $default = false) { if (!is_null($this->parameters)) { return ArrayUtils::getBool($this->parameters, $key, $default); } return Scalar::boolval(Request::query($key, $default)); }
/** * @param array $info * * @param bool $recursive * * @return array */ protected static function cleanPhpInfo($info, $recursive = false) { static $excludeKeys = ['directive', 'variable']; $clean = []; // Remove images and move nested args to root if (!$recursive && isset($info[0], $info[0][0]) && is_array($info[0])) { $info['general'] = []; foreach ($info[0] as $key => $value) { if (is_numeric($key) || in_array(strtolower($key), $excludeKeys)) { continue; } $info['general'][$key] = $value; unset($info[0][$key]); } unset($info[0]); } foreach ($info as $key => $value) { if (in_array(strtolower($key), $excludeKeys)) { continue; } $key = strtolower(str_replace(' ', '_', $key)); if (is_array($value) && 2 == count($value) && isset($value[0], $value[1])) { $v1 = ArrayUtils::get($value, 0); if ($v1 == '<i>no value</i>') { $v1 = null; } if (Scalar::in(strtolower($v1), 'on', 'off', '0', '1')) { $v1 = ArrayUtils::getBool($value, 0); } $value = $v1; } if (is_array($value)) { $value = static::cleanPhpInfo($value, true); } $clean[$key] = $value; } return $clean; }
public static function formatValue($value, $type) { $type = strtolower(strval($type)); switch ($type) { case 'int': case 'integer': return intval($value); case 'decimal': case 'double': case 'float': return floatval($value); case 'boolean': case 'bool': return Scalar::boolval($value); case 'string': return strval($value); case 'time': case 'date': case 'datetime': case 'timestamp': $cfgFormat = static::getDateTimeFormat($type); return static::formatDateTime($cfgFormat, $value); } return $value; }
/** * As found on php.net posted by: BigueNique at yahoo dot ca 20-Apr-2010 07:15 * A safe empowered glob(). * * Supported flags: GLOB_MARK, GLOB_NOSORT, GLOB_ONLYDIR * Additional flags: GlobFlags::GLOB_NODIR, GlobFlags::GLOB_PATH, GlobFlags::GLOB_NODOTS, GlobFlags::GLOB_RECURSE * (not original glob() flags, defined here) * * @author BigueNique AT yahoo DOT ca * * @param string $pattern * @param int $flags * * @return array|bool */ public static function glob($pattern, $flags = 0) { $pattern = static::normalizePath($pattern); $_split = explode(DIRECTORY_SEPARATOR, str_replace('\\', DIRECTORY_SEPARATOR, ltrim($pattern, DIRECTORY_SEPARATOR))); $_mask = array_pop($_split); $_leading = DIRECTORY_SEPARATOR == $pattern[0]; $_path = ($_leading ? DIRECTORY_SEPARATOR : null) . implode(DIRECTORY_SEPARATOR, $_split); $_glob = false; if (false !== ($_directory = opendir($_path))) { $_glob = []; while (false !== ($_file = readdir($_directory))) { $_fullPath = $_path . DIRECTORY_SEPARATOR . $_file; // Recurse directories if (is_dir($_fullPath) && $flags & GlobFlags::GLOB_RECURSE && in_array($_file, ['.', '..'])) { $_glob = array_merge($_glob, Scalar::array_prepend(static::glob($_fullPath . DIRECTORY_SEPARATOR . $_mask, $flags), $flags & GlobFlags::GLOB_PATH ? null : $_file . DIRECTORY_SEPARATOR)); } // Match file mask if (fnmatch($_mask, $_file)) { if ((!($flags & GLOB_ONLYDIR) || is_dir($_fullPath)) && (!($flags & GlobFlags::GLOB_NODIR) || !is_dir($_fullPath)) && (!($flags & GlobFlags::GLOB_NODOTS) || !in_array($_file, ['.', '..']))) { $_glob[] = ($flags & GlobFlags::GLOB_PATH ? $_path . '/' : null) . $_file . ($flags & GLOB_MARK ? '/' : ''); } } } closedir($_directory); if (!empty($_glob) && !($flags & GLOB_NOSORT)) { sort($_glob); } } return $_glob; }
/** * @param string|array $origin The parse_url value of origin * @param array $additional Additional origin(s) to allow * @param bool $isStar Set to true if the allowed origin is "*" * * @return bool|array false if not allowed, otherwise array of verbs allowed */ protected function _checkOrigin($origin, array $additional = [], &$isStar = false) { $_checklist = array_merge($this->_whitelist, $additional); foreach ($_checklist as $_hostInfo) { // Always start with defaults $_allowedVerbs = $this->_verbs; $_whiteGuy = $_hostInfo; if (is_array($_hostInfo)) { // If is_enabled prop not there, assuming enabled. if (!Scalar::boolval(IfSet::get($_hostInfo, 'is_enabled', true))) { continue; } if (null === ($_whiteGuy = IfSet::get($_hostInfo, 'host'))) { $this->_logger->error('whitelist entry missing "host" parameter'); continue; } if (isset($_hostInfo['verbs'])) { if (!in_array(Verbs::OPTIONS, $_hostInfo['verbs'])) { // add OPTION to allowed list $_hostInfo['verbs'][] = Verbs::OPTIONS; } $_allowedVerbs = $_hostInfo['verbs']; } } // All allowed? if (static::ALLOW_ALL == $_whiteGuy) { $isStar = true; return $_allowedVerbs; } if (false === ($_whiteParts = Uri::parse($_whiteGuy))) { $this->_logger->error('unable to parse "' . $_whiteGuy . '" whitelist entry'); continue; } $this->_logger->debug('whitelist "' . $_whiteGuy . '" > parts: ' . print_r($_whiteParts, true)); // Check for un-parsed origin, 'null' sent when testing js files locally if (is_array($origin) && Uri::compare($origin, $_whiteParts)) { // This origin is on the whitelist return $_allowedVerbs; } } return false; }