diff --git a/System/File/Directory.php b/System/File/Directory.php index ee0072ffa..d581bbe27 100644 --- a/System/File/Directory.php +++ b/System/File/Directory.php @@ -30,10 +30,6 @@ namespace phpOMS\System; */ class Directory extends FileAbstract implements Iterator, ArrayAccess { - private $path = ''; - private $name = 'new_directory'; - private $count = 0; - private $size = 0; private $filter = '*'; private $nodes = []; @@ -41,6 +37,10 @@ class Directory extends FileAbstract implements Iterator, ArrayAccess { $this->filter = $filter; parent::__constrct($path); + + if(file_exists($this->path)) { + parent::index(); + } } public function create() @@ -77,6 +77,8 @@ class Directory extends FileAbstract implements Iterator, ArrayAccess public function index() { + parent::index(); + foreach (glob($this->path . DIRECTORY_SEPARATOR . $this->filter) as $filename) { // todo: handle . and ..???!!! if(is_dir($filename)) { diff --git a/System/File/File.php b/System/File/File.php index b6dedd0b9..ca17ee4de 100644 --- a/System/File/File.php +++ b/System/File/File.php @@ -42,6 +42,8 @@ class File extends FileAbstract public function index() { + parent::index(); + $this->size = filesize($this->path); } } \ No newline at end of file diff --git a/System/File/FileAbstract.php b/System/File/FileAbstract.php index 62da287db..fd7166f93 100644 --- a/System/File/FileAbstract.php +++ b/System/File/FileAbstract.php @@ -34,11 +34,18 @@ class FileAbstract private $name = 'new_directory'; private $count = 0; private $size = 0; + private $createdAt = null; + private $changedAt = null; + private $owner = ''; + private $permission = '0000'; public function __construct(string $path) { $this->path = $path; $this->name = basename($path); + + $this->createdAt = new \DateTime('now'); + $this->changedAt = new \DateTime('now'); } public function getCount() : int @@ -61,5 +68,31 @@ class FileAbstract return $this->path; } - abstract private function index(); + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } + + public function getChangedAt() : \DateTime + { + return $this->changedAt; + } + + public function getOwner() : string + { + return $this->owner; + } + + public function getPermission() : string + { + return $this->permission; + } + + public function index() + { + $this->createdAt->setTimestamp(filemtime($this->path)); + $this->changedAt->setTimestamp(filectime($this->path)); + $this->owner = fileowner($this->path); + $this->permission = substr(sprintf('%o', fileperms($this->path)), -4); + } } \ No newline at end of file