public static function filter($type, DirItem $item) { if (is_array($type)) { foreach ($type as $_type) { if (self::filter($_type, $item)) { return true; } } } /* * Обработаем callback */ if (is_callable($type)) { return !!call_user_func($type, $item); } $type = $type ? $type : self::ALL; switch ($type) { case self::ALL: return true; case self::IMAGES: return $item->isImg(); case self::DIRS: return $item->isDir(); case self::FILES: return $item->isFile(); case self::ARCHIVES: return $item->checkExtension(array(PsConst::EXT_RAR, PsConst::EXT_ZIP)); default: //Если ни один из фильтров не подошел, проверим, может мы фильтруем по расшерению? if (PsConst::hasExt($type)) { return $item->checkExtension($type); } raise_error("Unknown dir item filter type: [{$type}]."); } }
/** * @covers PsConst::hasPhpType */ public function testHasPhpType() { $this->assertTrue(PsConst::hasPhpType(PsConst::PHP_TYPE_ARRAY)); $this->assertFalse(PsConst::hasPhpType(self::NOT_ALLOWED_STR)); }
/** * Метод проверяет тип переденной переменной * * @param mixed $var * @param array $allowed - допустимые типы данных * @param array $denied - запрещённые типы данных * @return mixed */ public static function phpType($type, array $allowed = null, array $denied = null) { if (!PsConst::hasPhpType($type)) { self::raise('Ожидается зарегистрированный тип данных php', $type); } if (!empty($allowed) && !in_array($type, $allowed)) { self::raise('Ожидается один из типов данных: ' . array_to_string($allowed), $type); } if (!empty($denied) && in_array($type, $denied)) { self::raise('Не ожидается один из типов данных: ' . array_to_string($denied), $type); } return $type; }
/** * Все доступные фильтры */ public static function allPossibleFilters() { $FILTER[] = null; $FILTER[] = DirItemFilter::getFilters(); $FILTER[] = PsConst::getExts(); return array_unique(to_array_expand($FILTER, true)); }