|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* lime_registration class. |
|
5
|
|
|
* @package lime |
|
6
|
|
|
*/ |
|
7
|
|
|
class lime_registration |
|
8
|
|
|
{ |
|
9
|
|
|
public $files = array(); |
|
10
|
|
|
public $extension = '.php'; |
|
11
|
|
|
public $base_dir = ''; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @param $files_or_directories |
|
15
|
|
|
* @throws Exception |
|
16
|
|
|
*/ |
|
17
|
|
|
public function register($files_or_directories) |
|
18
|
|
|
{ |
|
19
|
|
|
foreach ((array)$files_or_directories as $f_or_d) { |
|
20
|
|
|
if (is_file($f_or_d)) { |
|
21
|
|
|
$this->files[] = realpath($f_or_d); |
|
22
|
|
|
} elseif (is_dir($f_or_d)) { |
|
23
|
|
|
$this->register_dir($f_or_d); |
|
24
|
|
|
} else { |
|
25
|
|
|
throw new Exception(sprintf('The file or directory "%s" does not exist.', $f_or_d)); |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param $glob |
|
32
|
|
|
*/ |
|
33
|
|
|
public function register_glob($glob) |
|
34
|
|
|
{ |
|
35
|
|
|
if ($dirs = glob($glob)) { |
|
36
|
|
|
foreach ($dirs as $file) { |
|
37
|
|
|
$this->files[] = realpath($file); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param $directory |
|
44
|
|
|
* @throws Exception |
|
45
|
|
|
*/ |
|
46
|
|
|
public function register_dir($directory) |
|
47
|
|
|
{ |
|
48
|
|
|
if (!is_dir($directory)) { |
|
49
|
|
|
throw new Exception(sprintf('The directory "%s" does not exist.', $directory)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$files = array(); |
|
53
|
|
|
|
|
54
|
|
|
$current_dir = opendir($directory); |
|
55
|
|
|
while ($entry = readdir($current_dir)) { |
|
56
|
|
|
if ($entry == '.' || $entry == '..') { |
|
57
|
|
|
continue; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if (is_dir($entry)) { |
|
61
|
|
|
$this->register_dir($entry); |
|
62
|
|
|
} elseif (preg_match('#' . $this->extension . '$#', $entry)) { |
|
63
|
|
|
$files[] = realpath($directory . DIRECTORY_SEPARATOR . $entry); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$this->files = array_merge($this->files, $files); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param $file |
|
72
|
|
|
* @return mixed |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function get_relative_file($file) |
|
75
|
|
|
{ |
|
76
|
|
|
return str_replace(DIRECTORY_SEPARATOR, '/', |
|
77
|
|
|
str_replace(array(realpath($this->base_dir) . DIRECTORY_SEPARATOR, $this->extension), '', $file)); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|