Skimia\Foundation
  • Namespace
  • Class
  • Tree
  • Todo
  • Download

Namespaces

  • None
  • PHP
  • Skimia
    • Foundation
      • Annotations
      • Exceptions
        • Fail
      • Providers
        • Traits
      • Support
        • Traits
      • Testing
        • Traits

Classes

  • Skimia\Foundation\Annotations\BaseServiceProvider
  • Skimia\Foundation\Annotations\Scanner
  • Skimia\Foundation\FoundationServiceProvider
  • Skimia\Foundation\Testing\CommandOutput

Interfaces

  • Skimia\Foundation\Testing\TestablePromptCommandInterface

Traits

  • Skimia\Foundation\Providers\Traits\CommandLoaderTrait
  • Skimia\Foundation\Support\Traits\NamespaceClassFinderTrait
  • Skimia\Foundation\Testing\Traits\CommandTrait
  • Skimia\Foundation\Testing\Traits\TestableCommandTrait

Exceptions

  • Exception
  • LogicException
  • Skimia\Foundation\Exceptions\Fail\InvalidSuperclassUsedForTraitException
  • Skimia\Foundation\Exceptions\Fail\IsNotASubclassOfException

Functions

  • ensure_trait_used_in_subclass_of_or_fail
  • is_subclass_of_or_fail
 1 <?php
 2 
 3 namespace Skimia\Foundation\Support\Traits;
 4 
 5 use Illuminate\Console\AppNamespaceDetectorTrait;
 6 
 7 /**
 8  * @codeCoverageIgnore
 9  */
10 trait NamespaceClassFinderTrait
11 {
12     use AppNamespaceDetectorTrait;
13 
14     /**
15      * Convert the given namespace to a file path.
16      *
17      * @param  string $namespace the namespace to convert
18      *
19      * @return string
20      */
21     public function convertNamespaceToPath($namespace)
22     {
23         // remove the app namespace from the namespace if it is there
24         $appNamespace = $this->getAppNamespace();
25 
26         if (substr($namespace, 0, strlen($appNamespace)) == $appNamespace) {
27             $namespace = substr($namespace, strlen($appNamespace));
28         }
29 
30         // trim and return the path
31         return str_replace('\\', '/', trim($namespace, ' \\'));
32     }
33 
34     /**
35      * Get a list of the classes in a namespace. Leaving the second argument
36      * will scan for classes within the project's app directory.
37      *
38      * @param string  $namespace the namespace to search
39      * @param null    $base
40      *
41      * @return array
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      * Get a list of classes in the root namespace.
52      *
53      * @return array
54      */
55     protected function getAllClasses()
56     {
57         return $this->getClassesFromNamespace($this->getAppNamespace());
58     }
59 }
60 
Skimia\Foundation API documentation generated by ApiGen