-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace File; | ||
|
||
use Exception; | ||
|
||
abstract class FileType { | ||
const Folder = 0; | ||
const File = 1; | ||
const Link = 2; | ||
} | ||
|
||
abstract class AbstractFile { | ||
|
||
protected $path; | ||
protected $_content; | ||
protected $_type; | ||
|
||
public function __construct($path, $create = false) { | ||
$this->path = $path; | ||
$this->_content = null; | ||
$this->getType(); | ||
|
||
if (!$create) { | ||
$this->exists($path); | ||
} | ||
} | ||
|
||
public function getPath() { | ||
return $this->path; | ||
} | ||
|
||
public function getType() { | ||
if (is_dir($this->path)) $this->_type = FileType::Folder; | ||
else if (is_link($this->path)) $this->_type = FileType::Link; | ||
else $this->_type = FileType::File; | ||
|
||
return $this->_type; | ||
} | ||
|
||
public function isFile() { return $this->_type === FileType::File; } | ||
public function isFolder() { return $this->_type === FileType::Folder; } | ||
public function isLink() { return $this->_type === FileType::Link; } | ||
|
||
private function exists() { | ||
if (!file_exists($this->path)) { | ||
throw new Exception("File not found"); | ||
} | ||
if (!is_readable($this->path)) { | ||
throw new Exception("File not readable"); | ||
} | ||
} | ||
|
||
abstract public function getContent(); | ||
abstract public function setContent($content); | ||
|
||
abstract public function read(); | ||
abstract public function save(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,30 @@ | ||
<?php | ||
|
||
class Folder { | ||
|
||
private $path; | ||
namespace File; | ||
|
||
public function __construct($folderPath) { | ||
$this->path = $folderPath; | ||
class Folder extends AbstractFile { | ||
|
||
public function getContent() { | ||
// NYI | ||
return null; | ||
} | ||
|
||
public function setContent($content) { | ||
// NYI | ||
return $this; | ||
} | ||
|
||
public function read() { | ||
|
||
$files = array_map(function($file) { | ||
return new File($file); | ||
}, glob($this->getPath() . DIRECTORY_SEPARATOR . "*")); | ||
|
||
return $files; | ||
} | ||
|
||
public function save() { | ||
// NYI | ||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters