Source for file File.php
Documentation is available at File.php
* "THE BEER-WARE LICENSE" (Revision 42):
* "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
* As long as you retain this notice you can do whatever you want with
* this stuff. If we meet some day, and you think this stuff is worth it,
* you can buy me a beer in return.
* @package MediaSearch_File
* @copyright Copyright (c) 2009 Sven Strittmatter
* @see MediaSearch_File_Abstract
require_once('MediaSearch/File/Abstract.php');
* Concrete implementation of a file. Objects of this type are leafes
* in a file tree. A file can have a type (see class constants). The
* type of a file is determined by its file name extension.
* @package MediaSearch_File
* @copyright Copyright (c) 2009 Sven Strittmatter
* File type movie: All files with the file name extensions:
* 'avi', 'mov', 'mpg', 'mpeg', 'mp4', 'mkv', 'wmv', 'rm',
* 'xvid', 'divx', 'mpa', 'm4v', 'ogm', 'sfv'.
* File type music: All files with the file name extensions:
* 'mp3', 'wav', 'ogg', 'm4a'.
* File type software: All files with the file name extensions:
* 'exe', 'dmg', 'pkg', 'dpkg', 'xpi'.
* File type image: All files with the file name extensions:
* 'jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif'.
* File type document: All files with the file name extensions:
* 'txt', 'pdf', 'odt', 'doc'.
* Maps the file types to the file name extensions.
private $typeExtensions = array(
self::TYPE_MOVIE => array(
'avi', 'mov', 'mpg', 'mpeg', 'mp4', 'mkv', 'wmv', 'rm',
'xvid', 'divx', 'mpa', 'm4v', 'ogm', 'sfv'),
self::TYPE_MUSIC => array('mp3', 'wav', 'ogg', 'm4a'),
self::TYPE_SOFTWARE => array('exe', 'dmg', 'pkg', 'dpkg', 'xpi'),
self::TYPE_IMAGE => array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif'),
self::TYPE_DOCUMENT => array('txt', 'pdf', 'odt', 'doc')
* The type of the file. One of the calls constants named TYPE_*
* @see MediaSearch_File_Abstract
* Additionaly discovers the type of the file.
* Discovers the file type depending on the file name extension.
private function discoverType() {
if ($this->isType(self::TYPE_MOVIE, $fileExtension)) {
$this->type = self::TYPE_MOVIE;
} else if ($this->isType(self::TYPE_MUSIC, $fileExtension)) {
$this->type = self::TYPE_MUSIC;
} else if ($this->isType(self::TYPE_SOFTWARE, $fileExtension)) {
$this->type = self::TYPE_SOFTWARE;
} else if ($this->isType(self::TYPE_IMAGE, $fileExtension)) {
$this->type = self::TYPE_IMAGE;
} else if ($this->isType(self::TYPE_DOCUMENT, $fileExtension)) {
$this->type = self::TYPE_DOCUMENT;
$this->type = self::TYPE_UNKNOW;
* Returns the type according to the class constants named by TYPE_*.
* This mthod provides two functions:
* <li>If only the type integer is given this method returns if the
* actual object is of this type.</li>
* <li>If you provide a file name extension like 'jpg' as second parameter
* this method tells you if files with this extension are from the type you
* passed as first argument.</li>
* Valid integers as type identifier are all class constants named
* @param string $extension An optional filename extension like 'jpg'.
public function isType($type, $extension = null) {
if (null === $extension) {
return in_array($extension, $this->typeExtensions[$type]);
return ($this->getType() === $type);
* Implements MediaSearch_Interface_Visitable.
* @param MediaSearch_Interface_Visitor $visitor
public function acceptVisitor(MediaSearch_File_Visitor $visitor) {
|