本文整理汇总了PHP中CFilterChain::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CFilterChain::add方法的具体用法?PHP CFilterChain::add怎么用?PHP CFilterChain::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFilterChain
的用法示例。
在下文中一共展示了CFilterChain::add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* CFilterChain factory method.
* This method creates a CFilterChain instance.
* @param CController the controller who executes the action.
* @param CAction the action being filtered by this chain.
* @param array list of filters to be applied to the action.
*/
public static function create($controller, $action, $filters)
{
$chain = new CFilterChain($controller, $action);
$actionID = $action->getId();
foreach ($filters as $filter) {
if (is_string($filter)) {
if (($pos = strpos($filter, '+')) !== false || ($pos = strpos($filter, '-')) !== false) {
$matched = preg_match("/\\b{$actionID}\\b/i", substr($filter, $pos + 1)) > 0;
if (($filter[$pos] === '+') === $matched) {
$chain->add(CInlineFilter::create($controller, trim(substr($filter, 0, $pos))));
}
} else {
$chain->add(CInlineFilter::create($controller, $filter));
}
} else {
if (is_array($filter)) {
if (!isset($filter[0])) {
throw new CException(Yii::t('yii', 'The first element in a filter configuration must be the filter class.'));
}
$filterClass = $filter[0];
unset($filter[0]);
if (($pos = strpos($filterClass, '+')) !== false || ($pos = strpos($filterClass, '-')) !== false) {
$matched = preg_match("/\\b{$actionID}\\b/i", substr($filterClass, $pos + 1)) > 0;
if (($filterClass[$pos] === '+') === $matched) {
$filterClass = trim(substr($filterClass, 0, $pos));
} else {
continue;
}
}
$filter['class'] = $filterClass;
$chain->add(Yii::createComponent($filter));
} else {
$chain->add($filter);
}
}
}
return $chain;
}
示例2: create
public static function create($controller, $action, $filters)
{
$chain = new CFilterChain($controller, $action);
$actionID = $action->getId();
foreach ($filters as $filter) {
if (is_string($filter)) {
if (($pos = strpos($filter, '+')) !== false || ($pos = strpos($filter, '-')) !== false) {
$matched = preg_match("/\\b{$actionID}\\b/i", substr($filter, $pos + 1)) > 0;
if (($filter[$pos] === '+') === $matched) {
$filter = CInlineFilter::create($controller, trim(substr($filter, 0, $pos)));
}
} else {
$filter = CInlineFilter::create($controller, $filter);
}
} elseif (is_array($filter)) {
$filterClass = $filter[0];
unset($filter[0]);
//开始解析过滤器配置
if (($pos = strpos($filterClass, '+')) !== false || ($pos = strpos($filterClass, '-')) !== false) {
preg_match("/\\b{$actionID}\\b/i", substr($filterClass, $pos + 1), $a);
$matched = preg_match("/\\b{$actionID}\\b/i", substr($filterClass, $pos + 1)) > 0;
//如果是filterName+action,创建一个过滤器,否则忽略
if (($filterClass[$pos] === '+') === $matched) {
//解析出过滤器的类名
$filterClass = trim(substr($filterClass, 0, $pos));
} else {
continue;
}
}
$filter['class'] = $filterClass;
$filter = Yii::createComponent($filter);
}
if (is_object($filter)) {
$filter->init();
$chain->add($filter);
//list添加过滤器
}
}
return $chain;
}
示例3: create
public static function create($controller,$action,$filters)
{
$chain=new CFilterChain($controller,$action);
$actionID=$action->getId();
foreach($filters as $filter)
{
if(is_string($filter)) // filterName [+|- action1 action2]
{
if(($pos=strpos($filter,'+'))!==false || ($pos=strpos($filter,'-'))!==false)
{
$matched=preg_match("/\b{$actionID}\b/i",substr($filter,$pos+1))>0;
if(($filter[$pos]==='+')===$matched)
$filter=CInlineFilter::create($controller,trim(substr($filter,0,$pos)));
}
else
$filter=CInlineFilter::create($controller,$filter);
}
else if(is_array($filter)) // array('path.to.class [+|- action1, action2]','param1'=>'value1',...)
{
if(!isset($filter[0]))
throw new CException(Yii::t('yii','The first element in a filter configuration must be the filter class.'));
$filterClass=$filter[0];
unset($filter[0]);
if(($pos=strpos($filterClass,'+'))!==false || ($pos=strpos($filterClass,'-'))!==false)
{
$matched=preg_match("/\b{$actionID}\b/i",substr($filterClass,$pos+1))>0;
if(($filterClass[$pos]==='+')===$matched)
$filterClass=trim(substr($filterClass,0,$pos));
else
continue;
}
$filter['class']=$filterClass;
$filter=Yii::createComponent($filter);
}
if(is_object($filter))
{
$filter->init();
$chain->add($filter);
}
}
return $chain;
}