_() public static method

Apply custom filter to variable
public static _ ( mixed $value, string | Closure $filters = 'raw' ) : mixed
$value mixed
$filters string | Closure
return mixed
Example #1
0
 /**
  * Get array variable from request
  *
  * @param string          $name
  * @param mixed           $default
  * @param string|\Closure $filters
  * @return mixed
  */
 public function getArray($name, $default = null, $filters = null)
 {
     $value = $this->_get($name, $default, true);
     if ($filters) {
         $value = Filter::_($value, $filters);
     }
     return new Data($value);
 }
Example #2
0
/**
 * Normilize paths and compare them
 *
 * @param string $expected
 * @param string $actual
 * @param string $message
 * @throws Exception
 */
function isSamePath($expected, $actual, $message = null)
{
    if (!class_exists('\\JBZoo\\Utils\\Filter')) {
        throw new Exception('jbzoo/utils required for isSamePath() function');
    }
    $cleanFunc = function ($paths) {
        $return = array();
        $paths = (array) $paths;
        foreach ($paths as $key => $path) {
            $return[$key] = FS::clean($path, '/');
        }
        return $return;
    };
    $expected = Filter::_($expected, $cleanFunc);
    $actual = Filter::_($actual, $cleanFunc);
    isSame($expected, $actual, $message);
}
Example #3
0
File: Data.php Project: jbzoo/data
 /**
  * Filter value before return
  *
  * @param mixed $value
  * @param mixed $filter
  * @return mixed
  * @throws \JBZoo\Utils\Exception
  */
 protected function _filter($value, $filter)
 {
     if (null !== $filter) {
         $value = Filter::_($value, $filter);
     }
     return $value;
 }
Example #4
0
 public function testApplyFunction()
 {
     $source = 'some-WORD';
     isSame('some_WORD', Filter::_($source, function ($value) {
         $value = str_replace('-', '_', $value);
         return $value;
     }));
 }