Extending functionality

This commit is contained in:
Dennis Eichhorn 2016-03-12 15:22:57 +01:00
parent cd4f9c3027
commit dbf7e34de9
3 changed files with 42 additions and 5 deletions

View File

@ -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)) {

View File

@ -42,6 +42,8 @@ class File extends FileAbstract
public function index()
{
parent::index();
$this->size = filesize($this->path);
}
}

View File

@ -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);
}
}