本文整理匯總了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;
}