1 | <?php |
||
9 | class App |
||
10 | { |
||
11 | |||
12 | public static function name() |
||
13 | { |
||
14 | return 'Tagged Files'; |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * Get the application's version. |
||
19 | * |
||
20 | * Conforms to Semantic Versioning guidelines. |
||
21 | * @link http://semver.org |
||
22 | * @return string |
||
23 | */ |
||
24 | public static function version() |
||
25 | { |
||
26 | return '0.1.0'; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Turn a spaced or underscored string to camelcase (with no spaces or underscores). |
||
31 | * |
||
32 | * @param string $str |
||
33 | * @return string |
||
34 | */ |
||
35 | 11 | public static function camelcase($str) |
|
36 | { |
||
37 | 11 | return str_replace(' ', '', ucwords(str_replace('_', ' ', $str))); |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * Get the filesystem manager. |
||
42 | * |
||
43 | * @return MountManager |
||
44 | * @throws Exception |
||
45 | */ |
||
46 | 11 | public static function getFilesystem() |
|
47 | { |
||
48 | 11 | $config = new Config(); |
|
49 | 11 | $manager = new MountManager(); |
|
50 | 11 | foreach ($config->filesystems() as $name => $fsConfig) { |
|
51 | 11 | $adapterName = '\\League\\Flysystem\\Adapter\\' . self::camelcase($fsConfig['type']); |
|
52 | 11 | $adapter = new $adapterName($fsConfig['root']); |
|
53 | 11 | $fs = new Filesystem($adapter); |
|
54 | 11 | $manager->mountFilesystem($name, $fs); |
|
55 | } |
||
56 | 11 | return $manager; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Show an exception/error with the error template. |
||
61 | * @param Exception|\Error $exception |
||
62 | */ |
||
63 | public static function exceptionHandler($exception) |
||
64 | { |
||
65 | $template = new Template('error.twig'); |
||
66 | $template->title = 'Error'; |
||
67 | $template->exception = $exception; |
||
68 | $template->render(true); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Delete a directory and its contents. |
||
73 | * @link http://stackoverflow.com/a/8688278/99667 |
||
74 | * @param $path |
||
75 | * @return bool |
||
76 | */ |
||
77 | 18 | public static function deleteDir($path) |
|
78 | { |
||
79 | 18 | if (empty($path)) { |
|
80 | return false; |
||
81 | } |
||
82 | 18 | return is_file($path) ? |
|
83 | 11 | @unlink($path) : |
|
84 | 18 | array_map([__CLASS__, __FUNCTION__], glob($path . '/*')) == @rmdir($path); |
|
85 | } |
||
86 | } |
||
87 |