/**
  * Merge the filter chain with the one given in parameter
  *
  * @param  FilterChain $filterChain
  * @return FilterChain
  */
 public function merge(FilterChain $filterChain)
 {
     foreach ($filterChain->getFilters() as $filter) {
         $this->attach($filter);
     }
     return $this;
 }
Example #2
0
 public function run(FilterChain $oFilterChain)
 {
     $aDb = Core::app()->config()->getCache();
     foreach ($aDb as $k => $val) {
         Manager::getInstance()->getCache()->add(Cache::factory($val['Driver'], $val['Params']), $k);
     }
     $oFilterChain->next();
 }
Example #3
0
 public function run(FilterChain $oFilterChain)
 {
     if (Core::app()->request()->isAjaxRequest()) {
         $oFilterChain->next();
     } else {
         throw new RxException('Your request is not valid.', 400);
     }
 }
 public function proceed($postInputs)
 {
     $response = $this->_proceed($postInputs);
     if ($this->next !== null) {
         $response = $this->next->proceed($postInputs);
     }
     return $response;
 }
 public function run(FilterChain $oFilterChain)
 {
     if (Toolkit::getInstance()->auth->checkAdminAccess()) {
         $oFilterChain->next();
     } else {
         header("Location: " . Toolkit::getInstance()->auth->loginUrl);
         Core::app()->hardEnd();
     }
 }
 public function run(FilterChain $oFilterChain)
 {
     $aDb = Core::app()->config()->getDb();
     foreach ($aDb as $k => $val) {
         $oDb = new Db($val['ConnectionString'], $val['Username'], $val['Password'], $val['Params']);
         $oDb->open();
         Manager::getInstance()->getDb()->add($oDb, $k);
     }
     $oFilterChain->next();
 }
Example #7
0
 public function testGetFilters()
 {
     $filter = new FilterChain();
     $filter1 = new StripUpperCase();
     $filter2 = new LowerCase();
     $filter->appendFilter($filter1)->prependFilter($filter2);
     $array = $filter->getFilters();
     $this->assertEquals($filter2, $array[0]);
     $this->assertEquals($filter1, $array[1]);
 }
 public function run(FilterChain $oFilterChain)
 {
     if (count($this->getParams())) {
         foreach ($this->getParams() as $key => $val) {
             $class_name = $val['class'];
             unset($val['class']);
             Toolkit::getInstance()->addToolkit($key, new $class_name($val));
         }
     }
     $oFilterChain->next();
 }
Example #9
0
 public function setOperatorName($name)
 {
     if ($this->count() > 1 && $name === 'NOT') {
         return Filter::not(clone $this);
     }
     return parent::setOperatorName($name);
 }
 /**
  * Normalize a value into an AttributeFilter instance
  *
  * @param  mixed $value Either a valid callback or an instance of AttributeFilter
  * @return \s9e\TextFormatter\Configurator\Items\AttributeFilter Normalized filter
  */
 public function normalizeValue($value)
 {
     if (is_string($value) && preg_match('(^#\\w+$)', $value)) {
         $value = AttributeFilterCollection::getDefaultFilter(substr($value, 1));
     }
     return parent::normalizeValue($value);
 }
 public function run($sAction, $aParams = array())
 {
     $sMethod = 'action' . $sAction;
     if (method_exists($this, $sMethod)) {
         $aFilters = $this->filters();
         $aActionFilters = array();
         if (is_array($aFilters) && count($aFilters)) {
             foreach ($aFilters as $key => $actions) {
                 if (is_array($actions)) {
                     foreach ($actions as $action) {
                         if (strcasecmp($sAction, $action) === 0) {
                             $aActionFilters[] = $key;
                             break;
                         }
                     }
                 } else {
                     if (strcasecmp($sAction, $actions) === 0) {
                         $aActionFilters[] = $key;
                     }
                 }
             }
             if (count($aActionFilters)) {
                 $oFilterChain = new FilterChain();
                 foreach ($aActionFilters as $filter) {
                     $sFilterClass = $filter . 'Filter';
                     $oFilterChain->registerFilter(new $sFilterClass());
                 }
                 $oFilterChain->process();
             }
         }
         $oAction = new Action($this, $sAction, $aParams);
         return $oAction->run();
     } else {
         $this->redirect('/site/404');
     }
 }
Example #12
0
 /**
  * Calls the action specified in the request object and returns a response
  * 
  * @return Response
  */
 public function run()
 {
     $this->initialize();
     $action = $this->getActionName();
     if (!$this->actionExists($action)) {
         throw new ActionNotFound($action);
     }
     $this->session->start();
     $this->flash = isset($this->session['__FLASH__']) ? $this->session['__FLASH__'] : new Flash();
     $beforeResult = $this->beforeFilters->process($this, $action, 'before');
     $this->aroundFilters->process($this, $action, 'before');
     if ($beforeResult !== false && !$this->performedRespond) {
         $content = $this->{$action}();
         if (!$this->performedRespond) {
             $this->respond($content);
         }
     }
     $this->aroundFilters->process($this, $action, 'after');
     $this->afterFilters->process($this, $action, 'after');
     $this->flash->discard();
     $this->session['__FLASH__'] = $this->flash;
     $this->session->store();
     return $this->response;
 }
 public function main()
 {
     if ($this->file === null && empty($this->filesets)) {
         throw new BuildException("You must specify a file or fileset(s) for the <ReplaceRegexp> task.");
     }
     // compile a list of all files to modify, both file attrib and fileset elements
     // can be used.
     $files = array();
     if ($this->file !== null) {
         $files[] = $this->file;
     }
     if (!empty($this->filesets)) {
         $filenames = array();
         foreach ($this->filesets as $fs) {
             try {
                 $ds = $fs->getDirectoryScanner($this->project);
                 $filenames = $ds->getIncludedFiles();
                 // get included filenames
                 $dir = $fs->getDir($this->project);
                 foreach ($filenames as $fname) {
                     $files[] = new PhingFile($dir, $fname);
                 }
             } catch (BuildException $be) {
                 $this->log($be->getMessage(), Project::MSG_WARN);
             }
         }
     }
     $this->log("Applying Regexp processing to " . count($files) . " files.");
     // These "slots" allow filters to retrieve information about the currently-being-process files
     $slot = $this->getRegisterSlot("currentFile");
     $basenameSlot = $this->getRegisterSlot("currentFile.basename");
     $filter = new FilterChain($this->project);
     $r = new ReplaceRegexp();
     $r->setRegexps(array($this->_regexp));
     $filter->addReplaceRegexp($r);
     $filters = array($filter);
     foreach ($files as $file) {
         // set the register slots
         $slot->setValue($file->getPath());
         $basenameSlot->setValue($file->getName());
         // 1) read contents of file, pulling through any filters
         $in = null;
         try {
             $contents = "";
             $in = FileUtils::getChainedReader(new FileReader($file), $filters, $this->project);
             while (-1 !== ($buffer = $in->read())) {
                 $contents .= $buffer;
             }
             $in->close();
         } catch (Exception $e) {
             if ($in) {
                 $in->close();
             }
             $this->log("Error reading file: " . $e->getMessage(), Project::MSG_WARN);
         }
         try {
             // now create a FileWriter w/ the same file, and write to the file
             $out = new FileWriter($file);
             $out->write($contents);
             $out->close();
             $this->log("Applying regexp processing to " . $file->getPath(), Project::MSG_VERBOSE);
         } catch (Exception $e) {
             if ($out) {
                 $out->close();
             }
             $this->log("Error writing file back: " . $e->getMessage(), Project::MSG_WARN);
         }
     }
 }
Example #14
0
 public function execute(&$request, &$response, FilterChain &$filterChain)
 {
     $this->_before($request, $response);
     $filterChain->execute($request, $response);
     $this->_after($request, $response);
 }
Example #15
0
 /**
  * Forward the request to another action.
  *
  * @param string A module name.
  * @param string An action name.
  *
  * @return void
  *
  * @throws <b>ConfigurationException</b> If an invalid configuration setting
  *                                       has been found.
  * @throws <b>ForwardException</b> If an error occurs while forwarding the
  *                                 request.
  * @throws <b>InitializationException</b> If the action could not be
  *                                        initialized.
  * @throws <b>SecurityException</b> If the action requires security but
  *                                  the user implementation is not of type
  *                                  SecurityUser.
  *
  * @author Sean Kerr (skerr@mojavi.org)
  * @since  1.0.0
  */
 public function forward($moduleName, $actionName)
 {
     // replace periods with slashes for action sub-directories
     $actionName = str_replace('.', '/', $actionName);
     // replace unwanted characters
     $moduleName = preg_replace('/[^a-z0-9\\-_]+/i', '', $moduleName);
     $actionName = preg_replace('/[^a-z0-9\\-_\\/]+/i', '', $actionName);
     if ($this->actionStack->getSize() >= $this->maxForwards) {
         // let's kill this party before it turns into cpu cycle hell
         $error = 'Too many forwards have been detected for this request';
         throw new ForwardException($error);
     }
     if (!MO_AVAILABLE) {
         // application is unavailable
         $moduleName = MO_UNAVAILABLE_MODULE;
         $actionName = MO_UNAVAILABLE_ACTION;
         if (!$this->actionExists($moduleName, $actionName)) {
             // cannot find unavailable module/action
             $error = 'Invalid configuration settings: ' . 'MO_UNAVAILABLE_MODULE "%s", ' . 'MO_UNAVAILABLE_ACTION "%s"';
             $error = sprintf($error, $moduleName, $actionName);
             throw new ConfigurationException($error);
         }
     } else {
         if (!$this->actionExists($moduleName, $actionName)) {
             // the requested action doesn't exist
             // track the requested module so we have access to the data
             // in the error 404 page
             $this->request->setAttribute('requested_action', $actionName);
             $this->request->setAttribute('requested_module', $moduleName);
             // switch to error 404 action
             $moduleName = MO_ERROR_404_MODULE;
             $actionName = MO_ERROR_404_ACTION;
             if (!$this->actionExists($moduleName, $actionName)) {
                 // cannot find unavailable module/action
                 $error = 'Invalid configuration settings: ' . 'MO_ERROR_404_MODULE "%s", ' . 'MO_ERROR_404_ACTION "%s"';
                 $error = sprintf($error, $moduleName, $actionName);
                 throw new ConfigurationException($error);
             }
         }
     }
     // create an instance of the action
     $actionInstance = $this->getAction($moduleName, $actionName);
     // add a new action stack entry
     $this->actionStack->addEntry($moduleName, $actionName, $actionInstance);
     // include the module configuration
     ConfigCache::import('modules/' . $moduleName . '/config/module.ini');
     if (constant('MOD_' . strtoupper($moduleName) . '_ENABLED')) {
         // module is enabled
         // check for a module config.php
         $moduleConfig = MO_MODULE_DIR . '/' . $moduleName . '/config.php';
         if (is_readable($moduleConfig)) {
             require_once $moduleConfig;
         }
         // initialize the action
         if ($actionInstance->initialize($this->context)) {
             // create a new filter chain
             $filterChain = new FilterChain();
             if (MO_AVAILABLE) {
                 // the application is available so we'll register
                 // global and module filters, otherwise skip them
                 // does this action require security?
                 if (MO_USE_SECURITY && $actionInstance->isSecure()) {
                     if (!$this->user instanceof SecurityUser) {
                         // we've got security on but the user implementation
                         // isn't a sub-class of SecurityUser
                         $error = 'Security is enabled, but your User ' . 'implementation isn\'t a sub-class of ' . 'SecurityUser';
                         throw new SecurityException($error);
                     }
                     // register security filter
                     $filterChain->register($this->securityFilter);
                 }
                 // load filters
                 $this->loadGlobalFilters($filterChain);
                 $this->loadModuleFilters($filterChain);
             }
             // register the execution filter
             $execFilter = new ExecutionFilter();
             $execFilter->initialize($this->context);
             $filterChain->register($execFilter);
             if ($moduleName == MO_ERROR_404_MODULE && $actionName == MO_ERROR_404_ACTION) {
                 header('HTTP/1.0 404 Not Found');
                 header('Status: 404 Not Found');
             }
             // process the filter chain
             $filterChain->execute();
         } else {
             // action failed to initialize
             $error = 'Action initialization failed for module "%s", ' . 'action "%s"';
             $error = sprintf($error, $moduleName, $actionName);
             throw new InitializationException($error);
         }
     } else {
         // module is disabled
         $moduleName = MO_MODULE_DISABLED_MODULE;
         $actionName = MO_MODULE_DISABLED_ACTION;
         if (!$this->actionExists($moduleName, $actionName)) {
             // cannot find mod disabled module/action
             $error = 'Invalid configuration settings: ' . 'MO_MODULE_DISABLED_MODULE "%s", ' . 'MO_MODULE_DISABLED_ACTION "%s"';
             $error = sprintf($error, $moduleName, $actionName);
             throw new ConfigurationException($error);
         }
         $this->forward($moduleName, $actionName);
     }
 }
Example #16
0
<?php

require_once './Filter.php';
require_once './HTMLFilter.php';
require_once './LengthFilter.php';
require_once './FilterChain.php';
require_once './MsgProcessor.php';
$msg = "<p>hello, i am tom.how are you?</p>";
$filter_chain = new FilterChain();
$filter_chain->addFilter(new HTMLFilter())->addFilter(new LengthFilter());
$msg_processor = new MsgProcessor($msg, $filter_chain);
echo $msg_processor->process() . "\n";
Example #17
0
 protected function composeFilters(FilterChain $oFilterChain)
 {
     $aFilters = $this->config()->getFilters();
     if (count($aFilters)) {
         foreach ($aFilters as $filter => $params) {
             $sFilterClass = $filter . 'Filter';
             $oFilterChain->registerFilter(new $sFilterClass($params));
         }
     }
     return $oFilterChain;
 }
 /**
  * Tests MvcLite\FilterChain::addFilter().
  *
  * @dataProvider provideAddFilter
  */
 public function testAddFilter($filter)
 {
     $sut = new FilterChain();
     $result = $sut->addFilter($filter);
     $this->assertSame($result, $sut);
 }
 /**
  * @return FilterChain
  **/
 public static function textImport()
 {
     return FilterChain::create()->add(Filter::stripTags())->add(Filter::trim());
 }
Example #20
0
 public function filter($data)
 {
     return $this->filterChain->filter($data);
 }
Example #21
0
 /**
  * 
  * @param FilterChain $filter_chain
  */
 function execute($filter_chain)
 {
     $filter_chain->execute();
 }
Example #22
0
 /**
  * Performs action
  * 
  * @access private
  */
 private function perform($action, $filters)
 {
     $fc = new FilterChain();
     $fc->addFilters($filters);
     $aw = new ActionWrapper($action[0], $action[1]);
     $fc->process($this->context, $aw);
     return $aw->mResult;
 }