1 | <?php |
||
7 | trait Art |
||
8 | { |
||
9 | /** |
||
10 | * The directories we should be looking for art in |
||
11 | * |
||
12 | * @var array $art_dirs |
||
13 | */ |
||
14 | protected $art_dirs = []; |
||
15 | |||
16 | /** |
||
17 | * The default art if we can't find what the user requested |
||
18 | * |
||
19 | * @var string $default_art |
||
20 | */ |
||
21 | protected $default_art = '404'; |
||
22 | |||
23 | /** |
||
24 | * The art requested by the user |
||
25 | * |
||
26 | * @var string $art |
||
27 | */ |
||
28 | protected $art = ''; |
||
29 | |||
30 | /** |
||
31 | * Specify which settings Draw needs to import |
||
32 | * |
||
33 | * @return array |
||
34 | */ |
||
35 | 84 | public function settings() |
|
36 | { |
||
37 | 84 | return ['Art']; |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * Import the Art setting (any directories the user added) |
||
42 | * |
||
43 | * @param \League\CLImate\Settings\Art $setting |
||
44 | */ |
||
45 | 48 | public function importSettingArt($setting) |
|
51 | |||
52 | /** |
||
53 | * Add a directory to search for art in |
||
54 | * |
||
55 | * @param string $dir |
||
56 | */ |
||
57 | 84 | protected function addDir($dir) |
|
58 | { |
||
59 | // Add any additional directories to the top of the array |
||
60 | // so that the user can override art |
||
61 | 84 | array_unshift($this->art_dirs, rtrim($dir, '/')); |
|
62 | |||
63 | // Keep the array clean |
||
64 | 84 | $this->art_dirs = array_unique($this->art_dirs); |
|
65 | 84 | $this->art_dirs = array_filter($this->art_dirs); |
|
66 | 84 | $this->art_dirs = array_values($this->art_dirs); |
|
67 | 84 | } |
|
68 | |||
69 | /** |
||
70 | * Find a valid art path |
||
71 | * |
||
72 | * @param string $art |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | 4 | protected function artDir($art) |
|
77 | { |
||
78 | 4 | return $this->fileSearch($art, '/*.*'); |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * Find a valid art path |
||
83 | * |
||
84 | * @param string $art |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | 80 | protected function artFile($art) |
|
103 | |||
104 | /** |
||
105 | * Find a set of files in the current art directories |
||
106 | * based on a pattern |
||
107 | * |
||
108 | * @param string $art |
||
109 | * @param string $pattern |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | 84 | protected function fileSearch($art, $pattern) |
|
142 | |||
143 | /** |
||
144 | * Parse the contents of the file and return each line |
||
145 | * |
||
146 | * @param string $path |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | 80 | protected function parse($path) |
|
158 | } |
||
159 |