Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Created December 18, 2013 10:41
Show Gist options
  • Save hagbarddenstore/8020327 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/8020327 to your computer and use it in GitHub Desktop.
protected function getParameterAs($key, $type, $default = null, $validation = ValidationType::None, $validationData = null)
{
if (!isset($this->passedArgs[$key]))
{
return $default;
}
// NOTE: Not sure if this is needed, my PHP-fu is weak.
$value = null;
switch ($type)
{
case 'string':
$value = strval($this->passedArgs[$key]);
break;
case 'int':
$value = intval($this->passedArgs[$key]);
break;
default:
// TODO: Throw exception or do something else that's useful...
return $default;
break;
}
if ($this->validateParameter($value, $validation, $validationData))
{
return $value;
}
return $default;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment