Airship\Engine\Security\Filter\InputFilter::applyCallbacks PHP Method

applyCallbacks() public method

Apply all of the callbacks for this filter.
public applyCallbacks ( mixed $data = null, integer $offset ) : mixed
$data mixed
$offset integer
return mixed
    public function applyCallbacks($data = null, int $offset = 0)
    {
        if (empty($data)) {
            if ($this->type === 'bool') {
                return false;
            }
            return $this->default;
        }
        if ($offset >= \count($this->callbacks)) {
            return $data;
        }
        $func = $this->callbacks[$offset];
        if (\is_callable($func)) {
            $data = $func($data);
        }
        return $this->applyCallbacks($data, $offset + 1);
    }

Usage Example

Example #1
0
 /**
  * Apply all of the callbacks for this filter.
  *
  * @param mixed $data
  * @param int $offset
  * @return mixed
  * @throws \TypeError
  */
 public function applyCallbacks($data = null, int $offset = 0)
 {
     if ($offset === 0) {
         if (!empty($this->pattern)) {
             if (!\preg_match($this->pattern, $data)) {
                 throw new \TypeError(\sprintf('Pattern match failed (%s).', $this->index));
             }
         }
         return parent::applyCallbacks($data, 0);
     }
     return parent::applyCallbacks($data, $offset);
 }