mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-08 05:18:40 +00:00
Extending functionality
This commit is contained in:
parent
cd4f9c3027
commit
dbf7e34de9
|
|
@ -30,10 +30,6 @@ namespace phpOMS\System;
|
||||||
*/
|
*/
|
||||||
class Directory extends FileAbstract implements Iterator, ArrayAccess
|
class Directory extends FileAbstract implements Iterator, ArrayAccess
|
||||||
{
|
{
|
||||||
private $path = '';
|
|
||||||
private $name = 'new_directory';
|
|
||||||
private $count = 0;
|
|
||||||
private $size = 0;
|
|
||||||
private $filter = '*';
|
private $filter = '*';
|
||||||
private $nodes = [];
|
private $nodes = [];
|
||||||
|
|
||||||
|
|
@ -41,6 +37,10 @@ class Directory extends FileAbstract implements Iterator, ArrayAccess
|
||||||
{
|
{
|
||||||
$this->filter = $filter;
|
$this->filter = $filter;
|
||||||
parent::__constrct($path);
|
parent::__constrct($path);
|
||||||
|
|
||||||
|
if(file_exists($this->path)) {
|
||||||
|
parent::index();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create()
|
public function create()
|
||||||
|
|
@ -77,6 +77,8 @@ class Directory extends FileAbstract implements Iterator, ArrayAccess
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
parent::index();
|
||||||
|
|
||||||
foreach (glob($this->path . DIRECTORY_SEPARATOR . $this->filter) as $filename) {
|
foreach (glob($this->path . DIRECTORY_SEPARATOR . $this->filter) as $filename) {
|
||||||
// todo: handle . and ..???!!!
|
// todo: handle . and ..???!!!
|
||||||
if(is_dir($filename)) {
|
if(is_dir($filename)) {
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ class File extends FileAbstract
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
parent::index();
|
||||||
|
|
||||||
$this->size = filesize($this->path);
|
$this->size = filesize($this->path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -34,11 +34,18 @@ class FileAbstract
|
||||||
private $name = 'new_directory';
|
private $name = 'new_directory';
|
||||||
private $count = 0;
|
private $count = 0;
|
||||||
private $size = 0;
|
private $size = 0;
|
||||||
|
private $createdAt = null;
|
||||||
|
private $changedAt = null;
|
||||||
|
private $owner = '';
|
||||||
|
private $permission = '0000';
|
||||||
|
|
||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
$this->name = basename($path);
|
$this->name = basename($path);
|
||||||
|
|
||||||
|
$this->createdAt = new \DateTime('now');
|
||||||
|
$this->changedAt = new \DateTime('now');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCount() : int
|
public function getCount() : int
|
||||||
|
|
@ -61,5 +68,31 @@ class FileAbstract
|
||||||
return $this->path;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user