-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek.php
54 lines (45 loc) · 1.15 KB
/
week.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace KVSun\WP_E_Edition;
final class Week extends \DateTime
{
const DIR = 'Y m d';
private $_root;
public $path;
public function __construct($root, $date = null)
{
if ($date instanceof \DateTimeInterface) {
$date = $date->format(self::W3C);
}
if (! is_dir($root)) {
throw new \InvalidArgumentException("{$root} is not a directory.", 500);
}
$this->_root = rtrim($root, DIRECTORY_SEPARATOR);
parent::__construct($date);
if ($this->getTimestamp() > time()) {
throw new \InvalidArgumentException('Request made for future date', 404);
}
$this->path = $this->_root . DIRECTORY_SEPARATOR . $this;
}
public function __isset($section)
{
return file_exists($this->path . DIRECTORY_SEPARATOR . $section . '.pdf');
}
public function __get($section)
{
if ($this->__isset($section))
{
return new Issue($this, $section);
} else {
throw new \Exception("$section not found in $week.", 500);
}
}
public function scan($ext = '.pdf')
{
return new Scanner($this, $this->_root, $ext);
}
public function __toString()
{
$format = str_replace(' ', DIRECTORY_SEPARATOR, self::DIR);
return $this->format($format);
}
}