| Total Complexity | 9 |
| Total Lines | 68 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | abstract class Storable |
||
| 12 | { |
||
| 13 | const REGEXP_PATH = '@^(([a-zA-Z0-9._\-][\/]?))+$@'; |
||
| 14 | const REGEXP_NAME = '@^(([a-zA-Z0-9._\-]?))+$@'; |
||
| 15 | const DS = DIRECTORY_SEPARATOR; |
||
| 16 | |||
| 17 | /** @var string */ |
||
| 18 | private $path; |
||
| 19 | |||
| 20 | /** @var Directory */ |
||
| 21 | private $directory; |
||
| 22 | |||
| 23 | /** @return string */ |
||
| 24 | public function __toString() |
||
| 25 | { |
||
| 26 | return $this->getPath(); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** @return string */ |
||
| 30 | public function getPath() |
||
| 33 | } |
||
| 34 | |||
| 35 | /** @return string */ |
||
| 36 | public function getAbsolutePath() |
||
| 37 | { |
||
| 38 | return BASE_PATH . static::DS . $this->path; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Retorna o diretório pai |
||
| 43 | * @return Directory |
||
| 44 | */ |
||
| 45 | public function getDirectory() |
||
| 46 | { |
||
| 47 | if (is_null($this->directory)) { |
||
| 48 | $path = pathinfo($this->getPath(), PATHINFO_DIRNAME); |
||
| 49 | $this->directory = new Directory($path); |
||
| 50 | } |
||
| 51 | |||
| 52 | return $this->directory; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** @return string */ |
||
| 56 | public function getName() |
||
| 57 | { |
||
| 58 | return pathinfo($this->getAbsolutePath(), PATHINFO_FILENAME); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** @return string */ |
||
| 62 | public function getBaseName() |
||
| 65 | } |
||
| 66 | |||
| 67 | /** @return DateTime */ |
||
| 68 | public function getLastModifiedDate() |
||
| 69 | { |
||
| 70 | $ts = filemtime($this->getAbsolutePath()); |
||
| 71 | |||
| 72 | return new DateTime("@$ts"); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** @param string $path */ |
||
| 76 | protected function setPath($path) |
||
| 79 | } |
||
| 80 | } |
||
| 81 |