Example #1
0
 /**
  * getFilter
  *
  * @return  InputFilter
  */
 protected static function getFilter()
 {
     if (!static::$filter) {
         static::$filter = new InputFilter();
     }
     return static::$filter;
 }
Example #2
0
 /**
  * returns an array of Block Types used in the concrete5 Dashboard
  * @return BlockType[]
  */
 public static function getDashboardBlockTypes()
 {
     $btl = new static();
     $btl->filter(false, 'btHandle like \'dashboard_%\'');
     $blockTypes = $btl->get();
     return $blockTypes;
 }
 /**
  * Filter and returns those models that has not been found into another model.
  *
  * @param  PullAutomaticallyGalleries\Support\Collection|PullAutomaticallyGalleries\Database\Eloquent\Collection $items
  * @param  string $key
  * @return PullAutomaticallyGalleries\Database\Eloquent\Collection;
  */
 public function diffByKey($items, $key = 'id')
 {
     $diff = new static($this->items);
     $keyValues = $items->lists($key);
     return $diff->filter(function ($model) use($key, $keyValues) {
         return !in_array($model[$key], $keyValues);
     });
 }
Example #4
0
 /**
  * Returns true if and only if $value only contains digit characters
  *
  * @param  string $value
  * @return bool
  */
 public function isValid($value)
 {
     if (!is_string($value) && !is_int($value) && !is_float($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $this->setValue((string) $value);
     if ('' === $this->getValue()) {
         $this->error(self::STRING_EMPTY);
         return false;
     }
     if (null === static::$filter) {
         static::$filter = new DigitsFilter();
     }
     if ($this->getValue() !== static::$filter->filter($this->getValue())) {
         $this->error(self::NOT_DIGITS);
         return false;
     }
     return true;
 }
Example #5
0
 /**
  * Returns true if and only if $value contains only alphabetic characters
  *
  * @param  string $value
  * @return bool
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $this->setValue($value);
     if ('' === $value) {
         $this->error(self::STRING_EMPTY);
         return false;
     }
     if (null === static::$filter) {
         static::$filter = new AlphaFilter();
     }
     //static::$filter->setAllowWhiteSpace($this->allowWhiteSpace);
     static::$filter->setAllowWhiteSpace($this->options['allowWhiteSpace']);
     if ($value !== static::$filter->filter($value)) {
         $this->error(self::NOT_ALPHA);
         return false;
     }
     return true;
 }
Example #6
0
 /**
  * Static function to execute filter
  * 
  * @param int $value
  * @param array $options
  * @return mixed
  */
 public static function inline($value, $options = array())
 {
     $filter = new static();
     $filter->setOptions($options);
     return $filter->filter($value);
 }
Example #7
0
 /**
  * Filters a value.
  *
  * @param mixed $value Input value
  * @return mixed
  */
 public static function filtrate($value)
 {
     $filter = new static();
     return $filter->filter($value);
 }
Example #8
0
 /**
  * Scans a given directory for files.
  *
  * @param  string    $path    Path or paths to scan.
  * @param  array     $options Scanning options. Possible values are:
  *                            -`'iterator'`       _integer_     : The iterator mode.
  *                            -`'skipDots'`       _boolean_     : Keeps '.' and '..' if `true`.
  *                            -`'leavesOnly'`     _boolean_     : Keeps only leaves if `true`.
  *                            -`'followSymlinks'` _boolean_     : Follows Symlinks if `true`.
  *                            -`'recursive'`      _boolean_     : Scans recursively if `true`.
  *                            -`'include'`        _string|array_: An array of includes.
  *                            -`'exclude'`        _string|array_: An array of excludes.
  *                            -`'type'`           _string|array_: An array of types.
  * @return array
  */
 protected static function _scan($path, $options, $dirFlags, $iteratorFlags)
 {
     if (!file_exists($path)) {
         throw new Exception("Unexisting path `{$path}`.");
     }
     if (!is_dir($path)) {
         return [$path];
     }
     $worker = new RecursiveDirectoryIterator($path, $dirFlags);
     if ($options['recursive']) {
         $worker = new RecursiveIteratorIterator($worker, $iteratorFlags);
     }
     $filter = new static($worker);
     $filter->filter($options);
     $result = [];
     foreach ($filter as $key => $value) {
         $result[] = $key;
     }
     return $result;
 }
Example #9
0
 /**
  * Pull changes from Active Directory for a given query
  *
  * Use this method to set up a search query and later get all changed objects
  * for that query. This method returns a special {@link Delta} object that preserves
  * your search configuration and you use this object for consequent
  * searches. It also contains your search results. When you run the method for the first time,
  * it behaves as if you performed just an ordinary search, but on consequent searches,
  * it only returns objects that were modified or deleted since you last ran the search query.
  *
  * <br>
  *
  * <p class='alert'>Note that due to the way this feature is implemented it is impossible to
  * search for objects where only specific attributes have been modified - the method returns all objects
  * that were modified in any way since your last execution and it is your task to determine if
  * the changes happened on attributes that you are interested in.</p>
  * <br>
  *
  * This method takes two possible forms of arguments:<br>
  * When you run it for the first time, you pass the search parameters
  * as for any other ldap search query - the search filter, the list of attributes to be
  * returned and a fully configured {@link Link} instance.
  *
  * <br>
  *
  * For all consecutive executions, you only pass the {@link Delta} instance
  * that you got when you ran the method for the first time and, again, a configured {@link Link}
  * instance.
  *
  * <h2>Example:</h2>
  * To watch for changes on all users in your domain:
  * <code>
  * // Establish connection to your directory server
  * $link = new Link( 'example.com' );
  * $link->bind( '*****@*****.**', 'SecretPwd' );
  *
  * // When called for the first time for a particular query, you get
  * // an instance of Delta class - this instance contains the results
  * // of your query as well as all the information/state necessary
  * // to perform subsequent queries to get all changes for that resultset
  * $delta = Task::changes( '(objectcategory=person)', ['mail', 'name', 'memberof'], $link );
  * $result = $delta->result;	// Here's where the actual data is
  * // Do something with result...
  *
  * // Now it's time to store the $delta instance someplace safe so we can get
  * // changes for this query at a later time - you should serialise the instance
  * // and store it somewhere - i.e. in a database or on disk
  * file_put_contents( 'my_query_state.txt', serialize( $delta ) );	// Always serialise!
  *
  * // Many moments pass...
  * // In another script, far, far away...
  *
  * // It's time to see which objects have been modified since our last run
  * // Connect to ldap again
  * $link = new Link( 'example.com' );
  * $link->bind( '*****@*****.**', 'SecretPwd' );
  *
  * // Get the previous query state from the file
  * $delta = unserialize( file_get_contents( 'my_query_state.txt' ) );
  * // And get all the objects that have been changed since we last
  * // run the changes method, but this time we only pass in
  * // the instance of Delta class - it contains all the information
  * // about our previous query so we don't have to configure it again
  * $delta = Task::changes( $delta, $link );
  * $result = $delta->result;	// Changed objects are here again!
  *
  * // Notice that now we have a new instance of the Delta class in the
  * // $class variable - reflecting the fact that we just ran the query again
  *
  * // And so the story continues on and on...
  * </code>
  *
  * <h2>Things you should know</h2>
  * <ul>
  * <li>You must always connect to the same domain controller for a particular query,
  * otherwise you will receive the full resultset on each run</li>
  * <li>To track deleted objects, all returned objects have an <i>isDeleted</i>
  * {@link Attribute} automatically that you can use to check if that object has been deleted</li>
  * <li>You cannot use BaseDN overrides with this feature at this time
  * ( this might be implemented in the future )</li>
  * </ul>
  *
  * @return		Delta		Object containing the state and data of the changes
  *
  * @see			<a href="http://msdn.microsoft.com/en-us/library/ms677627.aspx">MSDN - Polling for changes using usnChanged</a>
  */
 public static function changes()
 {
     $args = func_get_args();
     $link = array_pop($args);
     // Link is always last
     $rootDSE = $link->rootDSE;
     $server = $rootDSE->dnsHostName(0);
     // We will only be able to get a diff when talking to the same server next time
     if ($args[0] instanceof Delta) {
         $last_delta = $args[0];
         $filter = $last_delta->filter;
         $attributes = $last_delta->attributes;
         $boundaryUSN = $last_delta->server == $server ? $last_delta->cookie + 1 : 0;
         // Pull all data if we are dealing with a different server
         // Include deleted objects in the resultset
         $link->show_deleted(true);
         // Also make this control extension critical
     } else {
         $filter = $args[0];
         $attributes = $args[1];
         $boundaryUSN = 0;
     }
     $task = new static(Enums\Operation::OpSearch, $link);
     $task->filter(q::a("(usnChanged>={$boundaryUSN})", $filter))->attributes(array_merge($attributes, ['isDeleted']));
     // Include isDeleted to help identifying deleted objects
     // Run, Forest, run!
     $result = $task->run_paged();
     return new Delta($result, $filter, $attributes, $server, $rootDSE->highestCommittedUSN(0));
 }
Example #10
0
 /**
  * @param string $uri
  * @param Route  $route
  * @param Router $router
  * @return bool
  */
 public function __invoke($uri, $route, $router)
 {
     static::$instance or static::instance();
     return static::$instance->filter($uri, $route, $router);
 }
Example #11
0
 /**
  * getFileFilter
  *
  * @return  FileFilter
  */
 public static function getFileFilter()
 {
     if (!static::$filter) {
         static::$filter = new FileFilter(static::getIgnores());
     }
     return static::$filter;
 }
Example #12
0
 /**
  * Provides a static interface for functional use
  *
  * @param string $value
  * 
  * @return string String filtered  
  */
 public static function apply($value)
 {
     $filter = new static();
     return $filter->filter($value);
 }
 /**
  * Register a filter method.
  * 
  * @access public
  * @static
  * @param mixed $action
  * @return void
  */
 public static function register($type, $method)
 {
     static::$filter = $method;
     static::$filters[$method] = array('event' => $type, 'action' => $method);
     return static::$instance;
 }
Example #14
0
 public static function make($html)
 {
     $filter = new static($html);
     return $filter->filter();
 }