1: <?php
2:
3: 4: 5: 6: 7: 8:
9:
10: namespace PhpOptions\Types;
11:
12: require_once __DIR__ . '/AType.php';
13:
14: 15: 16: 17: 18:
19: class FileType extends AType
20: {
21:
22: 23: 24: 25: 26:
27: private $base = NULL;
28:
29:
30: 31: 32: 33: 34: 35:
36: public function __construct($settings = array())
37: {
38: parent::__construct($settings);
39: if (isset($settings[0]))
40: {
41: $this->base = $settings[0];
42: }
43: }
44:
45:
46: 47: 48: 49: 50: 51: 52:
53: public function check($value)
54: {
55: $isDir = FALSE;
56: if (is_file($value))
57: {
58: $isDir = TRUE;
59: }
60: elseif ($this->base && is_file($this->base . DIRECTORY_SEPARATOR . $value))
61: {
62: $isDir = TRUE;
63: }
64: return $isDir;
65: }
66:
67:
68: 69: 70: 71: 72: 73: 74:
75: protected function useFilter($value)
76: {
77:
78: if ($this->base && !preg_match('/^([a-zA-Z]:\\\|\/)/', $value))
79: {
80: $value = $this->make($this->base, $value);
81: }
82: $value = $this->make($value);
83:
84: return $value;
85: }
86:
87:
88: 89: 90: 91: 92:
93: private function make()
94: {
95: $pathParts = func_get_args();
96:
97: $ds = DIRECTORY_SEPARATOR;
98: $path = implode($ds, $pathParts);
99:
100:
101: $path = str_replace('/', $ds, $path);
102: $path = str_replace('\\', $ds, $path);
103:
104:
105: while (strpos($path, $ds . '.' . $ds) !== FALSE || strpos($path, $ds . $ds) !== FALSE)
106: {
107: $path = str_replace($ds . $ds, $ds, $path);
108: $path = str_replace($ds . '.' . $ds, $ds, $path);
109: }
110:
111: return $path;
112: }
113:
114:
115: }
116: