/**
  * @param   string $dir directory name (views, i18n, classes, extensions, etc.)
  * @param   string $file filename with subdirectory
  * @param   string $ext extension to search for
  * @param   boolean $array return an array of files?
  * @return  array   a list of files when $array is TRUE
  * @return  string  single file path
  */
 public function findFile($dir, $file, $ext = null, $array = false)
 {
     if ($ext === null) {
         // Use the default extension
         $ext = '.php';
     } elseif ($ext) {
         // Prefix the extension with a period
         $ext = ".{$ext}";
     } else {
         // Use no extension
         $ext = '';
     }
     // Create a partial path of the filename
     $path = normalize_path("{$dir}/{$file}{$ext}");
     if (isset($this->files[$path . ($array ? '_array' : '_path')])) {
         // This path has been cached
         return $this->files[$path . ($array ? '_array' : '_path')];
     }
     if ($array) {
         // Array of files that have been found
         $found = [];
         foreach ($this->moduleLoader->getRegisteredModules() as $module) {
             $dir = $module->getPath() . DIRECTORY_SEPARATOR;
             if (is_file($dir . $path)) {
                 // This path has a file, add it to the list
                 $found[] = $dir . $path;
             }
         }
     } else {
         // The file has not been found yet
         $found = false;
         foreach ($this->moduleLoader->getRegisteredModules() as $module) {
             $dir = $module->getPath() . DIRECTORY_SEPARATOR;
             if (is_file($dir . $path)) {
                 // A path has been found
                 $found = $dir . $path;
                 // Stop searching
                 break;
             }
         }
     }
     // Add the path to the cache
     $this->files[$path . ($array ? '_array' : '_path')] = $found;
     // Files have been changed
     $this->filesChanged = true;
     return $found;
 }
 /**
  * @param string|null $namespace
  *
  * @return string
  */
 public function getModuleNameByNamespace($namespace = null)
 {
     $defaultNamespace = 'app';
     $currentRoute = app('router')->getCurrentRoute();
     if (is_null($namespace) and !is_null($currentRoute)) {
         $namespace = $currentRoute->getAction()['namespace'];
     }
     if (is_null($namespace)) {
         return $defaultNamespace;
     }
     foreach ($this->moduleLoader->getRegisteredModules() as $module) {
         if (!empty($moduleNamespace = $module->getNamespace())) {
             if (strpos($namespace, $moduleNamespace) === 0) {
                 return $module->getKey();
             }
         }
     }
     return $defaultNamespace;
 }