60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
|
|
abstract class MediaListing_FileObject {
|
|
|
|
const TYPE_File = 1;
|
|
const TYPE_Directory = 2;
|
|
|
|
protected $type;
|
|
protected $basename;
|
|
protected $path;
|
|
|
|
public static function create($path, $parent = null, $scan = true) {
|
|
if ( ! file_exists($path)) {
|
|
throw new MediaListing_Exception_FileNotFound($path);
|
|
}
|
|
|
|
switch (filetype($path)) {
|
|
case "file": {
|
|
return new MediaListing_File($path);
|
|
} break;
|
|
|
|
case "dir": {
|
|
return new MediaListing_Directory($path, $parent, $scan);
|
|
} break;
|
|
}
|
|
}
|
|
|
|
protected function __construct($type, $path) {
|
|
$this->type = $type;
|
|
$this->path = $path;
|
|
$this->basename = basename($path);
|
|
}
|
|
|
|
public function isFile() {
|
|
return $this->type == self::TYPE_File;
|
|
}
|
|
|
|
public function isDirectory() {
|
|
return $this->type == self::TYPE_Directory;
|
|
}
|
|
|
|
public function size() {
|
|
return MediaListing_Main::recursiveFilesize($this->path);
|
|
}
|
|
|
|
public function type() {
|
|
return $this->type;
|
|
}
|
|
|
|
public function path() {
|
|
return $this->path;
|
|
}
|
|
|
|
public function basename() {
|
|
return $this->basename;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|