1 <?php
2
3 namespace Skimia\Foundation\Support\Traits;
4
5 use Illuminate\Console\AppNamespaceDetectorTrait;
6
7 8 9
10 trait NamespaceClassFinderTrait
11 {
12 use AppNamespaceDetectorTrait;
13
14 15 16 17 18 19 20
21 public function convertNamespaceToPath($namespace)
22 {
23
24 $appNamespace = $this->getAppNamespace();
25
26 if (substr($namespace, 0, strlen($appNamespace)) == $appNamespace) {
27 $namespace = substr($namespace, strlen($appNamespace));
28 }
29
30
31 return str_replace('\\', '/', trim($namespace, ' \\'));
32 }
33
34 35 36 37 38 39 40 41 42
43 public function getClassesFromNamespace($namespace, $base = null)
44 {
45 $directory = ($base ?: app('path')).'/'.$this->convertNamespaceToPath($namespace);
46
47 return app('Illuminate\Filesystem\ClassFinder')->findClasses($directory);
48 }
49
50 51 52 53 54
55 protected function getAllClasses()
56 {
57 return $this->getClassesFromNamespace($this->getAppNamespace());
58 }
59 }
60