/** * 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); }
/** * 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); }
/** * 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; }
public function testApplyFunction() { $source = 'some-WORD'; isSame('some_WORD', Filter::_($source, function ($value) { $value = str_replace('-', '_', $value); return $value; })); }