private function parseFile($filepath, &$allglobs) { $lines = file($filepath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!$lines) { return $allglobs; } foreach ($lines as $line) { if ($line[0] === '#') { // Comment continue; } $fields = explode(':', $line); $weight = (int) $fields[0]; $type = $fields[1]; $pattern = $fields[2]; if ($pattern === '__NOGLOBS__') { // This signals to discard any previous globs unset($allglobs[$type]); continue; } $flags = empty($fields[3]) ? [] : explode(',', $fields[3]); $mime = MimeType::create($type); $glob = new Glob($weight, $pattern, $mime, in_array('cs', $flags)); $allglobs[$type][] = $glob; } }
private function parseFile($path) { $aliases = []; $lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!$lines) { return $aliases; } foreach ($lines as $line) { list($alias, $canonical) = explode(' ', $line, 2); $aliases[$alias] = MimeType::create($canonical); } return $aliases; }
public function build(array $files) { $db = new SubclassesDatabase(); foreach ($files as $path) { $lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!$lines) { continue; } foreach ($lines as $line) { list($subclass, $parent) = explode(' ', $line, 2); $db->add(MimeType::create($subclass), MimeType::create($parent)); } } return $db; }
public function testThatMimeTypesAreCaseInsensitive() { $type = MimeType::create('image/JPEG'); $this->assertEquals('image', $type->getMedia()); $this->assertEquals('jpeg', $type->getSubtype()); }
private function guessTypeByStat($mode) { switch ($mode & self::STAT_IFMT) { case self::STAT_IFDIR: return MimeType::directory(); case self::STAT_IFLNK: return MimeType::symlink(); case self::STAT_IFCHR: return MimeType::characterDevice(); case self::STAT_IFBLK: return MimeType::blockDevice(); case self::STAT_IFIFO: return MimeType::fifo(); case self::STAT_IFSOCK: return MimeType::socket(); default: return MimeType::door(); } }