_() public static method

Apply custom filter to variable
public static _ ( mixed $value, string | Closure $filters = 'raw' ) : mixed
$value mixed
$filters string | Closure
return mixed
Esempio n. 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);
 }
Esempio n. 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);
}
Esempio n. 3
0
File: Data.php Progetto: 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;
 }
Esempio n. 4
0
 public function testApplyFunction()
 {
     $source = 'some-WORD';
     isSame('some_WORD', Filter::_($source, function ($value) {
         $value = str_replace('-', '_', $value);
         return $value;
     }));
 }