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)); }
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; }
/** * @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; }