当前位置: 首页>>代码示例>>PHP>>正文


PHP KInflector::getPart方法代码示例

本文整理汇总了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;
 }
开发者ID:janssit,项目名称:www.gincoprojects.be,代码行数:12,代码来源:default.php

示例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;
 }
开发者ID:janssit,项目名称:www.reliancelaw.be,代码行数:81,代码来源:input.php


注:本文中的KInflector::getPart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。