本文整理汇总了PHP中KInflector::getPart方法的典型用法代码示例。如果您正苦于以下问题:PHP KInflector::getPart方法的具体用法?PHP KInflector::getPart怎么用?PHP KInflector::getPart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KInflector
的用法示例。
在下文中一共展示了KInflector::getPart方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setFilter
/**
* Set a scalar filter to use for the FilterArray
*
* @param KFilterInterface $filter
* @return this
*/
public function setFilter(KFilterInterface $filter)
{
$this->_filter = $filter;
$this->setClassName(array('prefix' => KInflector::getPart($filter, 0), 'base' => 'FilterArray', 'suffix' => KInflector::getPart($filter, 1)));
return $this;
}
示例2: get
/**
* Get a validated and optionally sanitized variable from the request.
*
* When an array of hashes is supplied, the hash will be prioritized in the
* same order. Eg. array('post', 'get'). Use this (if you really have to) as
* a safer equivalent for $_REQUEST
*
* When no sanitizers are supplied, the same filters as the validators will
* be used.
*
* @param string Variable name eg 'foo[bar]'
* @param string|array Hash(es) [COOKIE|ENV|FILES|GET|POST|SERVER]
* @param mixed Validator(s), can be a KFilterInterface object, or array of objects
* @param mixed Sanitizer(s), can be a KFilterInterface object, or array of objects
* @param mixed Default value when the variable doesn't exist
* @throws KInputException When the variable doesn't validate
* @return mixed (Sanitized) variable
*/
public static function get($var, $hashes, $validators, $sanitizers = array(), $default = null)
{
settype($hashes, 'array');
// Is the hash in our list?
foreach ($hashes as $k => $hash) {
$hashes[$k] = strtoupper($hash);
if (!in_array($hashes[$k], self::$_hashes)) {
throw new KInputException('Unknown hash: ' . $hash);
}
}
// find $var in the hashes
$result = null;
foreach ($hashes as $hash) {
if ($result = self::_getNested($GLOBALS['_' . $hash], self::_split($var))) {
break;
}
}
// return the default value if $var wasn't set in any of the hashes
if (is_null($result)) {
return $default;
}
// trim values
if (is_scalar($result)) {
$result = trim($result);
} else {
array_walk_recursive($result, 'trim');
}
// Handle magic quotes compatability
if (get_magic_quotes_gpc() && $hash != 'FILES') {
$result = self::_stripSlashes($result);
}
// if $validators or $sanitizers is an object, turn it into an array of objects
// don't use settype because it will convert objects to arrays
$validators = is_array($validators) ? $validators : (empty($validators) ? array() : array($validators));
// if no sanitizers are given, use the validators
$sanitizers = empty($sanitizers) ? $validators : (is_array($sanitizers) ? $sanitizers : array($sanitizers));
// validate the variable
foreach ($validators as $filter) {
//Create the filter if needed
if (is_string($filter)) {
$filter = KFactory::tmp('lib.koowa.filter.' . $filter);
}
if (!$filter instanceof KFilterInterface) {
throw new KInputException('Invalid filter passed: ' . get_class($filter));
}
if (!$filter->validate($result)) {
$filtername = KInflector::getPart(get_class($filter), -1);
throw new KInputException('Input is not a valid ' . $filtername);
}
}
// sanitize the variable
foreach ($sanitizers as $filter) {
//Create the filter if needed
if (is_string($filter)) {
$filter = KFactory::tmp('lib.koowa.filter.' . $filter);
}
if (!$filter instanceof KFilterInterface) {
throw new KInputException('Invalid filter passed: ' . get_class($filter));
}
$result = $filter->sanitize($result);
}
return $result;
}