Exemplo n.º 1
0
 protected function filter($operator, $value)
 {
     if ($operator !== 'FIND_IN_SET') {
         throw new \BadMethodCallException('The CsvFilter can only filter for values contained in the field.');
     }
     parent::filter($operator, $value);
 }
Exemplo n.º 2
0
 private function doTest($initial, $filters, $expected)
 {
     $test = $initial;
     foreach ($filters as $filter) {
         $filter = new Filter($filter);
         $filter->filter($test);
     }
     $this->assertEquals($expected, $test);
 }
Exemplo n.º 3
0
 /**
  * Run the stored sequence of actions
  *
  * 
  * 
  * @param Filter $filter A filter to select actions from the saved sequence to
  *		be run (default: `null`)
  * @param bool $force Whether or not to force actions executed in previous runs
  *		to be executed again in this run (default: `false`)
  *
  * @return Result[] The responses generated by each action that was executed in
  *		this run, in the order executed
  *
  * @see BatchManager::preprocessAction() preprocessAction()
  * @see BatchManager::postprocessResult() postprocessResult()
  */
 public function run(Filter $filter = null, $force = false)
 {
     $id = md5(time());
     $environment = array();
     $sandbox = new Sandbox($id, $this->sequence, $filter, $force, $environment);
     foreach ($this->sequence as $action) {
         if ($filter === null || $filter->filter($action)) {
             try {
                 $result = $this->preprocessAction($action)->run($environment, $id, $force);
                 $sandbox->addResult($this->postprocessResults($result));
             } catch (Action_Exception $e) {
                 throw new BatchManager_Exception(($force ? 'Forced run' : 'Run') . " (ID {$id})" . (empty($tags) ? '' : ' with tags [' . implode(', ', $tags) . ']') . ' failed to complete: ' . $e->getMessage() . ' (Action_Exception ' . $e->getCode() . '), sandbox contents: ' . var_export($sandbox, true), BatchManager_Exception::ACTION_FAILED);
             }
         }
     }
     return $sandbox->getResults();
 }
Exemplo n.º 4
0
 /**
  *
  *
  * @param array $config
  * @param $key
  * @return Composite
  * @throws ErrorException
  * @throws Exception
  */
 protected function evaluateModel($config, $key)
 {
     $config['key'] = $key;
     if (array_key_exists('type', $config)) {
         $type = $config['type'];
     } else {
         throw new ErrorException('There is an error in the configuration file!');
     }
     switch (true) {
         case $type == 'TypedContainer':
             if (array_key_exists('leaf', $config)) {
                 $leaf = new $config['leaf']($config);
             } else {
                 throw new ErrorException('There is an error in the configuration file!');
             }
             $model = new TypedContainer($leaf, $config);
             self::addModel($model, $config);
             break;
         case !array_key_exists('path', $config):
         case $type == 'Container':
         case $type == 'Composite':
             // type should be Composite or Container
             $model = new $type($config);
             self::addModel($model, $config);
             break;
         case is_dir($config['path']) && $type != 'PhotoSwipe' && $type != 'Link':
             $filter = new Filter(new Collection($type, $config));
             $model = $filter->filter();
             break;
         case $type == 'Markdown':
         case $type == 'HyperTextMarkup':
         case $type == 'HypertextPreprocessor':
         case $type == 'Image':
         case $type == 'Remote':
         case $type == 'Link':
         case $type == 'PhotoSwipe':
             $model = new $type($config);
             break;
         default:
             throw new Exception('The requested URL is not available.');
     }
     return $model;
 }
 /**
  *
  *
  * @param array $config
  * @return Composite
  * @throws ErrorException
  * @throws Exception
  */
 protected function evaluateModel($config)
 {
     if (isset($config['type'])) {
         $type = $config['type'];
     } else {
         throw new ErrorException('There is an error in the configuration file!');
     }
     switch (true) {
         case !array_key_exists('path', $config):
         case $type == 'Container':
         case $type == 'Composite':
             // type should be Composite or Container
             $model = new $type($config);
             foreach ($config as $key => $value) {
                 if (is_array($value)) {
                     $model->addModel($this->evaluateModel($value), $key);
                 }
             }
             break;
         case is_dir($config['path']) && $type != 'OwlCarousel' && $type != 'Link':
             $filter = new Filter(new Collection($type, $config));
             $model = $filter->filter();
             break;
         case $type == 'Markdown':
         case $type == 'HyperTextMarkup':
         case $type == 'HypertextPreprocessor':
         case $type == 'Image':
         case $type == 'Remote':
         case $type == 'Link':
         case $type == 'OwlCarousel':
             $model = new $type($config);
             break;
         default:
             throw new Exception('The requested URL is not available.');
     }
     return $model;
 }
Exemplo n.º 6
0
<?php

// Namespaced classes do not recognize PHP 4 constructors
namespace PHP4CtorNS;

class Filter
{
    // HHVM (PHP 5 mode, PHP 7 mode), PHP 4, 5, 7, 8: filter is a constructor
    function filter($a)
    {
        echo "In Filter::filter method\n";
    }
}
$f = new Filter();
$f->filter(3);
Exemplo n.º 7
0
{
    // HHVM (PHP 5 mode), PHP 4, 5: filter is a constructor
    // HHVM (PHP 7 mode), PHP 7: filter is a constructor and
    //                           E_DEPRECATED is raised
    // PHP 8: filter is a normal method and is not a constructor;
    //        no E_DEPRECATED is raised
    function filter()
    {
        echo "In Filter PHP 4 style constructor\n";
    }
}
class Mapper
{
    // HHVM (PHP 5 mode), PHP 4, 5: filter is a constructor
    // HHVM (PHP 7 mode), PHP 7: filter is a constructor and
    //                           E_DEPRECATED is raised
    // PHP 8: filter is a normal method and is not a constructor;
    //        no E_DEPRECATED is raised
    function mapper()
    {
        echo "In Mapper PHP 4 style constructor\n";
    }
}
$f = new Filter();
// calls the PHP 4 style constructor
$f->filter();
// calls the method filter, which is also the PHP4 style ctor
$m = new Mapper();
// calls the PHP 4 style constructor
$m->mapper();
// calls the method mapper, which is also the PHP4 style ctor
Exemplo n.º 8
0
 /**
  * Lists all files and directories in a directory
  *
  * @param integer  $depth
  * @param mixed    $filter
  * @param string   $type
  * @param boolean  $asHandlers
  *
  * @return array
  */
 public function listContents($depth = 0, $filter = null, $type = 'all', $asHandlers = false)
 {
     $pattern = $this->path . '/*';
     if (is_array($filter)) {
         $filters = $filter;
         $filter = new Filter();
         foreach ($filters as $f => $type) {
             if (!is_int($f)) {
                 $f = $type;
                 $type = null;
             }
             $expected = true;
             if (strpos($f, '!') === 0) {
                 $f = substr($f, 1);
                 $expected = false;
             }
             $filter->addFilter($f, $expected, $type);
         }
     }
     if ($filter instanceof \Closure) {
         $callback = $filter;
         $filter = new Filter();
         $callback($filter);
     }
     if (!$filter) {
         $filter = new Filter();
     }
     $flags = GLOB_MARK;
     if ($type === 'file' and !pathinfo($pattern, PATHINFO_EXTENSION)) {
         // Add an extension wildcard
         $pattern .= '.*';
     } elseif ($type === 'dir') {
         $flags = GLOB_MARK | GLOB_ONLYDIR;
     }
     $contents = glob($pattern, $flags);
     // Filter the content.
     $contents = $filter->filter($contents);
     // Lower the depth for a recursive call
     if ($depth and $depth !== true) {
         $depth--;
     }
     $formatted = array();
     foreach ($contents as $item) {
         if ($filter->isCorrectType('dir', $item)) {
             $_contents = array();
             if (($depth === true or $depth === 0) and !$asHandlers) {
                 $dir = new Directory($item);
                 $_contents = $dir->listContents($item, $filter, $depth, $type);
             }
             if ($asHandlers) {
                 $formatted[] = new Directory($item);
             } else {
                 $formatted[$item] = $_contents;
             }
         } elseif ($filter->isCorrectType('file', $item)) {
             if ($asHandlers) {
                 $item = new File($item);
             }
             $formatted[] = $item;
         }
     }
     return $formatted;
 }
Exemplo n.º 9
0
 /**
  * get request parameters
  *
  * @param array $definition {key1:filter1, key2:filter2, ... }
  * @param int $method request method, self::M_GET / self::M_POST / self::M_COOKIE / self::M_REQUEST / self::M_FILE / self::M_ENV / self::M_SERVER
  * @param boolean $required
  * @param string $prefix
  *
  * @return void
  */
 protected function parameters($definition, $method = WebPage::M_GET, $required = false, $prefix = null)
 {
     switch ($method) {
         case null:
         case self::M_GET:
             $source = $_GET;
             break;
         case self::M_POST:
             $source = $_POST;
             break;
         case self::M_COOKIE:
             $source = $_COOKIE;
             break;
         case self::M_REQUEST:
             $source = $_REQUEST;
             break;
         case self::M_FILE:
             $source = $_FILES;
             break;
         case self::M_ENV:
             $source = $_ENV;
             break;
         case self::M_SERVER:
             $source = $_SERVER;
             break;
         default:
             return false;
     }
     $parameters = array();
     foreach ($definition as $key => $filter) {
         if (isset($source[$key])) {
             $result = Filter::filter($source[$key], $filter);
             if ($result === false) {
                 throw new Exception\Filter("Parameter '{$key}' is invalid", Errno::INPUT_PARAM_INVALID);
             }
         } else {
             if ($required) {
                 throw new Exception\Filter("Parameter '{$key}' is required", Errno::INPUT_PARAM_MISSED);
             }
             continue;
         }
         //parameter key prefix
         if ($prefix) {
             $key = $prefix . $key;
         }
         $parameters[$key] = $result;
     }
     return $parameters;
 }