diff --git a/src/AppModuleContainer.php b/src/AppModuleContainer.php index ede2536..7f6e3d5 100644 --- a/src/AppModuleContainer.php +++ b/src/AppModuleContainer.php @@ -1,9 +1,9 @@ isBooted) { + if (!$this->isBooted) { $this->isBooted = true; } return $this; } - /** * @param \Illuminate\Foundation\Application $app * @@ -42,40 +40,37 @@ public function register($app) return $this; } - /** * @return string */ public function getRoutesPath() { - return $this->getPath([ 'app', 'Http', 'routes.php' ]); + return $this->getPath(['app', 'Http', 'routes.php']); } - /** * @return string */ public function getServiceProviderPath() { - return $this->getPath([ 'app', 'Providers', 'ModuleServiceProvider.php' ]); + return $this->getPath(['app', 'Providers', 'ModuleServiceProvider.php']); } - /** * Register a config file namespace. + * * @return void */ public function loadConfig() { - return [ ]; + return []; } - /** * @return array */ public function getPublishPath() { - return [ ]; + return []; } -} \ No newline at end of file +} diff --git a/src/Console/Commands/ModulesList.php b/src/Console/Commands/ModulesList.php index cec1586..421961f 100644 --- a/src/Console/Commands/ModulesList.php +++ b/src/Console/Commands/ModulesList.php @@ -1,4 +1,5 @@ getName() . ' [' . get_class($module) . ']', - '' + $module->getName().' ['.get_class($module).']', + '', ]; - $modules[] = new TableSeparator; + $modules[] = new TableSeparator(); foreach ($module->toArray() as $key => $value) { $modules[] = [ studly_case($key), - is_string($value) ? $value : stripslashes(json_encode($value)) + is_string($value) ? $value : stripslashes(json_encode($value)), ]; } - $modules[] = new TableSeparator; + $modules[] = new TableSeparator(); } $this->table($this->headers, $modules); diff --git a/src/Console/Commands/ModulesMigrateCommand.php b/src/Console/Commands/ModulesMigrateCommand.php index f036b96..0210ea7 100644 --- a/src/Console/Commands/ModulesMigrateCommand.php +++ b/src/Console/Commands/ModulesMigrateCommand.php @@ -1,4 +1,5 @@ confirmToProceed()) { + if (!$this->confirmToProceed()) { return; } @@ -54,7 +53,6 @@ public function fire() } } - /** * Get the console command options. * diff --git a/src/Console/Commands/ModulesSeedCommand.php b/src/Console/Commands/ModulesSeedCommand.php index 030068b..7aefe18 100644 --- a/src/Console/Commands/ModulesSeedCommand.php +++ b/src/Console/Commands/ModulesSeedCommand.php @@ -1,4 +1,5 @@ confirmToProceed()) { + if (!$this->confirmToProceed()) { return; } @@ -38,7 +37,6 @@ public function fire() } } - /** * Get the console command options. * diff --git a/src/Contracts/ModuleContainerInterface.php b/src/Contracts/ModuleContainerInterface.php index 146fa0e..cb4dad1 100644 --- a/src/Contracts/ModuleContainerInterface.php +++ b/src/Contracts/ModuleContainerInterface.php @@ -1,11 +1,11 @@ getDefaultModulePath($moduleName); } @@ -69,7 +68,6 @@ public function __construct($moduleName, $modulePath = null, $namespace = null) $this->setNamespace($namespace); } - /** * @param string $moduleName * @@ -77,10 +75,9 @@ public function __construct($moduleName, $modulePath = null, $namespace = null) */ protected function getDefaultModulePath($moduleName) { - return base_path('modules' . DIRECTORY_SEPARATOR . $moduleName); + return base_path('modules'.DIRECTORY_SEPARATOR.$moduleName); } - /** * @return string */ @@ -89,7 +86,6 @@ public function getName() return $this->name; } - /** * @return string */ @@ -98,7 +94,6 @@ public function getKey() return strtolower($this->getName()); } - /** * @return string */ @@ -107,16 +102,14 @@ public function getNamespace() return $this->namespace; } - /** * @return string */ public function getControllerNamespace() { - return $this->getNamespace() . '\\' . $this->controllerNamespacePrefix; + return $this->getNamespace().'\\'.$this->controllerNamespacePrefix; } - /** * @param strimg|array|null $sub * @@ -129,32 +122,29 @@ public function getPath($sub = null) } $path = $this->path; - if ( ! is_null($sub)) { - $path .= DIRECTORY_SEPARATOR . $sub; + if (!is_null($sub)) { + $path .= DIRECTORY_SEPARATOR.$sub; } return $path; } - /** * @return string */ public function getLocalePath() { - return $this->getPath([ 'resources', 'lang' ]); + return $this->getPath(['resources', 'lang']); } - /** * @return string */ public function getViewsPath() { - return $this->getPath([ 'resources', 'views' ]); + return $this->getPath(['resources', 'views']); } - /** * @return string */ @@ -163,25 +153,22 @@ public function getConfigPath() return $this->getPath('config'); } - /** * @return string */ public function getRoutesPath() { - return $this->getPath([ 'Http', 'routes.php' ]); + return $this->getPath(['Http', 'routes.php']); } - /** * @return string */ public function getServiceProviderPath() { - return $this->getPath([ 'Providers', 'ModuleServiceProvider.php' ]); + return $this->getPath(['Providers', 'ModuleServiceProvider.php']); } - /** * @param \Illuminate\Foundation\Application $app * @@ -189,7 +176,7 @@ public function getServiceProviderPath() */ public function boot($app) { - if ( ! $this->isBooted) { + if (!$this->isBooted) { $this->loadViews(); $this->loadTranslations(); $this->isBooted = true; @@ -198,7 +185,6 @@ public function boot($app) return $this; } - /** * @param \Illuminate\Foundation\Application $app * @@ -206,12 +192,12 @@ public function boot($app) */ public function register($app) { - if ( ! $this->isRegistered) { + if (!$this->isRegistered) { $this->loadSystemRoutes($app['router']); $serviceProviderPath = $this->getServiceProviderPath(); if (is_file($serviceProviderPath)) { - $app->register($this->getNamespace() . '\Providers\ModuleServiceProvider'); + $app->register($this->getNamespace().'\Providers\ModuleServiceProvider'); } $this->isRegistered = true; @@ -220,7 +206,6 @@ public function register($app) return $this; } - /** * @param Router $router */ @@ -229,27 +214,27 @@ public function loadRoutes(Router $router) $this->includeRoutes($router); } - /** * Register a config file namespace. + * * @return void */ public function loadConfig() { $path = $this->getConfigPath(); - if ( ! is_dir($path)) { - return [ ]; + if (!is_dir($path)) { + return []; } $configs = Cache::remember("moduleConfig::{$path}", Carbon::now()->addMinutes(10), function () use ($path) { - $configs = [ ]; + $configs = []; foreach (new \DirectoryIterator($path) as $file) { - if ($file->isDot() OR strpos($file->getFilename(), '.php') === false) { + if ($file->isDot() or strpos($file->getFilename(), '.php') === false) { continue; } - $key = $file->getBasename('.php'); - $configs[$key] = array_merge_recursive(require $file->getPathname(), app('config')->get($key, [ ])); + $key = $file->getBasename('.php'); + $configs[$key] = array_merge_recursive(require $file->getPathname(), app('config')->get($key, [])); } return $configs; @@ -258,22 +243,20 @@ public function loadConfig() return $configs; } - /** * @return array */ public function getPublishPath() { - if ( ! is_dir($this->getViewsPath())) { - return [ ]; + if (!is_dir($this->getViewsPath())) { + return []; } return [ - $this->getViewsPath() => $this->publishViewPath() + $this->getViewsPath() => $this->publishViewPath(), ]; } - /** * @return bool */ @@ -282,7 +265,6 @@ public function isPublishable() return $this->isPublishable; } - /** * Get the instance as an array. * @@ -302,11 +284,10 @@ public function toArray() ]; } - /** * Convert the object to its JSON representation. * - * @param int $options + * @param int $options * * @return string */ @@ -315,20 +296,18 @@ public function toJson($options = 0) return json_encode($this->toArray(), $options); } - /** * @param Router $router */ protected function includeRoutes(Router $router) { if (is_file($routesFile = $this->getRoutesPath())) { - $router->group([ 'namespace' => $this->getControllerNamespace() ], function ($router) use ($routesFile) { + $router->group(['namespace' => $this->getControllerNamespace()], function ($router) use ($routesFile) { require $routesFile; }); } } - /** * Register a view file namespace. * @@ -343,7 +322,6 @@ protected function loadViews() view()->addNamespace($this->getKey(), $this->getViewsPath()); } - /** * @return string */ @@ -352,7 +330,6 @@ protected function publishViewPath() return base_path(normalize_path("/resources/views/modules/{$this->getName()}")); } - /** * Register a translation file namespace. * @@ -363,27 +340,23 @@ protected function loadTranslations() app('translator')->addNamespace($this->getKey(), $this->getLocalePath()); } - /** * @param Router $router */ protected function loadSystemRoutes(Router $router) { - } - /** * @param string|null $namespace */ protected function setNamespace($namespace = null) { - if ( ! is_null($namespace)) { + if (!is_null($namespace)) { $this->namespace = $namespace; } } - /** * @return string */ @@ -391,4 +364,4 @@ public function __toString() { return (string) $this->getName(); } -} \ No newline at end of file +} diff --git a/src/ModulesFileSystem.php b/src/ModulesFileSystem.php index 879fba8..26dd20a 100644 --- a/src/ModulesFileSystem.php +++ b/src/ModulesFileSystem.php @@ -1,4 +1,5 @@ moduleLoader = $loader; - $this->filesystem = $filesystem; + $this->filesystem = $filesystem; } - /** * @param string|array|null $sub * @@ -59,15 +57,14 @@ public function getPaths($sub = null) return $paths; } - /** - * @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? + * @param string $dir directory name (views, i18n, classes, extensions, etc.) + * @param string $file filename with subdirectory + * @param string $ext extension to search for + * @param bool $array return an array of files? * - * @return array a list of files when $array is TRUE - * @return string single file path + * @return array a list of files when $array is TRUE + * @return string single file path */ public function findFile($dir, $file, $ext = null, $array = false) { @@ -85,9 +82,9 @@ public function findFile($dir, $file, $ext = null, $array = false) // Create a partial path of the filename $path = normalize_path("{$dir}/{$file}{$ext}"); - if (isset( $this->files[$path . ( $array ? '_array' : '_path' )] )) { + if (isset($this->files[$path.($array ? '_array' : '_path')])) { // This path has been cached - return $this->files[$path . ( $array ? '_array' : '_path' )]; + return $this->files[$path.($array ? '_array' : '_path')]; } if ($array) { @@ -95,11 +92,11 @@ public function findFile($dir, $file, $ext = null, $array = false) $found = []; foreach ($this->moduleLoader->getRegisteredModules() as $module) { - $dir = $module->getPath() . DIRECTORY_SEPARATOR; + $dir = $module->getPath().DIRECTORY_SEPARATOR; - if (is_file($dir . $path)) { + if (is_file($dir.$path)) { // This path has a file, add it to the list - $found[] = $dir . $path; + $found[] = $dir.$path; } } } else { @@ -107,11 +104,11 @@ public function findFile($dir, $file, $ext = null, $array = false) $found = false; foreach ($this->moduleLoader->getRegisteredModules() as $module) { - $dir = $module->getPath() . DIRECTORY_SEPARATOR; + $dir = $module->getPath().DIRECTORY_SEPARATOR; - if (is_file($dir . $path)) { + if (is_file($dir.$path)) { // A path has been found - $found = $dir . $path; + $found = $dir.$path; // Stop searching break; @@ -120,7 +117,7 @@ public function findFile($dir, $file, $ext = null, $array = false) } // Add the path to the cache - $this->files[$path . ( $array ? '_array' : '_path' )] = $found; + $this->files[$path.($array ? '_array' : '_path')] = $found; // Files have been changed $this->filesChanged = true; @@ -128,12 +125,11 @@ public function findFile($dir, $file, $ext = null, $array = false) return $found; } - /** - * @param string $directory directory name - * @param string|array $ext + * @param string $directory directory name + * @param string|array $ext * - * @return array + * @return array */ public function listFiles($directory = null, $ext = null) { @@ -153,18 +149,18 @@ public function listFiles($directory = null, $ext = null) $found = []; foreach ($paths as $moduleName => $path) { - if (is_dir($path = normalize_path($path . DIRECTORY_SEPARATOR . $directory))) { + if (is_dir($path = normalize_path($path.DIRECTORY_SEPARATOR.$directory))) { foreach ($this->filesystem->allFiles($path) as $file) { $fileExt = $file->getExtension(); // Relative filename is the array key $key = $file->getRelativePathname(); - if ( ! empty( $ext ) and is_array($ext) ? ! in_array($fileExt, $ext) : ( $fileExt != $ext )) { + if (!empty($ext) and is_array($ext) ? !in_array($fileExt, $ext) : ($fileExt != $ext)) { continue; } - if ( ! isset( $found[$key] )) { + if (!isset($found[$key])) { $found[$key] = $file; } } @@ -177,7 +173,6 @@ public function listFiles($directory = null, $ext = null) return $found; } - /** * @param string|null $namespace * @@ -186,9 +181,9 @@ public function listFiles($directory = null, $ext = null) public function getModuleNameByNamespace($namespace = null) { $defaultNamespace = 'app'; - $currentRoute = app('router')->getCurrentRoute(); + $currentRoute = app('router')->getCurrentRoute(); - if (is_null($namespace) and ! is_null($currentRoute)) { + if (is_null($namespace) and !is_null($currentRoute)) { $namespace = $currentRoute->getAction()['namespace']; } @@ -197,7 +192,7 @@ public function getModuleNameByNamespace($namespace = null) } foreach ($this->moduleLoader->getRegisteredModules() as $module) { - if ( ! empty( $moduleNamespace = $module->getNamespace() )) { + if (!empty($moduleNamespace = $module->getNamespace())) { if (strpos($namespace, $moduleNamespace) === 0) { return $module->getKey(); } @@ -207,17 +202,15 @@ public function getModuleNameByNamespace($namespace = null) return $defaultNamespace; } - public function getFoundFilesFromCache() { $this->files = Cache::get('ModulesFileSystem::findFile', []); } - public function cacheFoundFiles() { if ($this->filesChanged) { Cache::put('ModulesFileSystem::findFile', $this->files, Carbon::now()->addMinutes(10)); } } -} \ No newline at end of file +} diff --git a/src/ModulesFileSystemFacade.php b/src/ModulesFileSystemFacade.php index a9f2c96..8a88c56 100644 --- a/src/ModulesFileSystemFacade.php +++ b/src/ModulesFileSystemFacade.php @@ -1,11 +1,11 @@ modules = $modules; - $this->migrator = App::make('migrator'); + $this->modules = $modules; + $this->migrator = App::make('migrator'); $this->repository = App::make('migration.repository'); $this->init(); } - /** - * @param bool $pretend + * @param bool $pretend * * @return $this */ @@ -67,15 +65,14 @@ public function migrateModules($pretend = false) $this->migrator->runMigrationList(array_unique($this->migrations), $pretend); foreach ($this->migrator->getNotes() as $note) { - $this->output(' - ' . $note); + $this->output(' - '.$note); } return $this; } - /** - * Run migrations on a single module + * Run migrations on a single module. * * @param ModuleContainerInterface $module * @@ -83,7 +80,7 @@ public function migrateModules($pretend = false) */ public function migrateModule(ModuleContainerInterface $module) { - $path = $module->getPath(['database', 'migrations']); + $path = $module->getPath(['database', 'migrations']); $files = $this->migrator->getMigrationFiles($path); // Once we grab all of the migration files for the path, we will compare them @@ -101,7 +98,6 @@ public function migrateModule(ModuleContainerInterface $module) return $this; } - /** * @return $this */ @@ -116,9 +112,8 @@ public function resetModules() return $this->rollbackModules(); } - /** - * Reset migrations on a single module + * Reset migrations on a single module. * * @param ModuleContainerInterface $module * @@ -132,7 +127,6 @@ public function addModuleToReset(ModuleContainerInterface $module) return $this; } - /** * @return $this */ @@ -153,9 +147,7 @@ public function rollbackModules() return $this; } - /** - * * @param array $data * * @return $this @@ -169,9 +161,8 @@ public function seedModules(array $data = []) return $this; } - /** - * Run seeds on a module + * Run seeds on a module. * * @param ModuleContainerInterface $module * @param array $data @@ -180,9 +171,9 @@ public function seedModules(array $data = []) */ public function seedModule(ModuleContainerInterface $module, array $data = []) { - $className = $module->getNamespace() . '\\database\\seeds\\DatabaseSeeder'; + $className = $module->getNamespace().'\\database\\seeds\\DatabaseSeeder'; - if ( ! class_exists($className)) { + if (!class_exists($className)) { return false; } @@ -194,7 +185,6 @@ public function seedModule(ModuleContainerInterface $module, array $data = []) return $this; } - /** * @return array */ @@ -203,7 +193,6 @@ public function getOutputMessages() return $this->outputMessages; } - /** * @return $this */ @@ -214,24 +203,21 @@ public function cleanOutputMessages() return $this; } - protected function init() { - $firstUp = ! Schema::hasTable('migrations'); + $firstUp = !Schema::hasTable('migrations'); if ($firstUp) { $this->repository->createRepository(); $this->output('Migration table created successfully.'); } } - protected function deinit() { Schema::dropIfExists('migrations'); $this->output('Migration table dropped.'); } - /** * @param string $message * @@ -243,4 +229,4 @@ protected function output($message) return $this; } -} \ No newline at end of file +} diff --git a/src/ModulesLoader.php b/src/ModulesLoader.php index 397a973..0599039 100644 --- a/src/ModulesLoader.php +++ b/src/ModulesLoader.php @@ -1,4 +1,5 @@ $modulePath) { $moduleNamespace = null; if (is_array($modulePath)) { $moduleNamespace = array_get($modulePath, 'namespace'); - $modulePath = array_get($modulePath, 'path'); + $modulePath = array_get($modulePath, 'path'); } else { if (is_numeric($moduleName)) { $moduleName = $modulePath; @@ -49,7 +48,7 @@ public function __construct(array $modulesList) } if (is_null($modulePath)) { - $modulePath = base_path('modules' . DIRECTORY_SEPARATOR . $moduleName); + $modulePath = base_path('modules'.DIRECTORY_SEPARATOR.$moduleName); } $this->addModule($moduleName, $modulePath, $moduleNamespace); @@ -58,7 +57,6 @@ public function __construct(array $modulesList) $this->addModule('App', base_path(), '', \KodiCMS\ModulesLoader\AppModuleContainer::class); } - /** * @return array */ @@ -67,7 +65,6 @@ public function getRegisteredModules() return $this->registeredModules; } - /** * @param string $moduleName * @@ -78,7 +75,6 @@ public function getRegisteredModule($moduleName) return array_get($this->getRegisteredModules(), $moduleName); } - /** * @param string $moduleName * @param string|null $modulePath @@ -90,7 +86,7 @@ public function getRegisteredModule($moduleName) public function addModule($moduleName, $modulePath = null, $namespace = null, $moduleContainerClass = null) { if (is_null($namespace)) { - $namespace = 'Modules\\' . $moduleName; + $namespace = 'Modules\\'.$moduleName; } $namespace = trim($namespace, '\\'); @@ -105,7 +101,7 @@ public function addModule($moduleName, $modulePath = null, $namespace = null, $m $moduleContainerClass = $customModuleClass; } - if ( ! class_exists($moduleContainerClass)) { + if (!class_exists($moduleContainerClass)) { $moduleContainerClass = class_exists($this->defaultContainerClass) ? $this->defaultContainerClass : \KodiCMS\ModulesLoader\ModuleContainer::class; @@ -118,7 +114,6 @@ public function addModule($moduleName, $modulePath = null, $namespace = null, $m return $this; } - /** * @param ModuleContainerInterface $module */ @@ -127,7 +122,6 @@ public function registerModule(ModuleContainerInterface $module) $this->registeredModules[$module->getName()] = $module; } - /** * @param Application $app * @@ -142,7 +136,6 @@ public function registerModules(Application $app) return $this; } - /** * @param Application $app * @@ -157,7 +150,6 @@ public function bootModules(Application $app) return $this; } - /** * @param Closure $callback */ @@ -166,7 +158,6 @@ public function shutdown(Closure $callback) $this->shutdownCallbacks[] = $callback; } - public function shutdownHandler() { app('events')->fire('app.shutdown'); @@ -175,4 +166,4 @@ public function shutdownHandler() $this->call($callback); } } -} \ No newline at end of file +} diff --git a/src/ModulesLoaderFacade.php b/src/ModulesLoaderFacade.php index e2639e3..56d0edb 100644 --- a/src/ModulesLoaderFacade.php +++ b/src/ModulesLoaderFacade.php @@ -1,11 +1,11 @@ app['modules.loader']->registerModules($this->app); } - /** * Bootstrap any application services. * diff --git a/src/Providers/ConfigServiceProvider.php b/src/Providers/ConfigServiceProvider.php index 57f0321..4215317 100644 --- a/src/Providers/ConfigServiceProvider.php +++ b/src/Providers/ConfigServiceProvider.php @@ -1,11 +1,11 @@ app['modules.loader']->getRegisteredModules() as $module) { @@ -18,9 +18,7 @@ public function boot() $this->app['events']->fire('config.loaded'); } - public function register() { - } } diff --git a/src/Providers/ModuleServiceProvider.php b/src/Providers/ModuleServiceProvider.php index ff5d3c7..e625596 100644 --- a/src/Providers/ModuleServiceProvider.php +++ b/src/Providers/ModuleServiceProvider.php @@ -1,4 +1,5 @@ registerConsoleCommands(); } - /** - * Registers console (artisan) commands + * Registers console (artisan) commands. */ public function registerConsoleCommands() { @@ -70,9 +69,8 @@ public function registerConsoleCommands() } } - /** - * Register aliases + * Register aliases. */ protected function registerAliases() { @@ -82,9 +80,8 @@ protected function registerAliases() ]); } - /** - * Register providers + * Register providers. */ protected function registerProviders() { diff --git a/src/Providers/RouteServiceProvider.php b/src/Providers/RouteServiceProvider.php index 3cf4a02..bd128be 100644 --- a/src/Providers/RouteServiceProvider.php +++ b/src/Providers/RouteServiceProvider.php @@ -1,4 +1,5 @@ app['events']->fire('routes.loaded'); } - /** * Define the routes for the application. * - * @param \Illuminate\Routing\Router $router + * @param \Illuminate\Routing\Router $router * * @return void */ @@ -44,7 +42,7 @@ public function map(Router $router) $this->app['events']->fire('routes.loading'); foreach ($this->app['modules.loader']->getRegisteredModules() as $module) { - $this->app->call([ $module, 'loadRoutes' ], [ $router ]); + $this->app->call([$module, 'loadRoutes'], [$router]); } $this->app['events']->fire('routes.loaded'); diff --git a/src/helpers.php b/src/helpers.php index 80a4540..a74631e 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -1,6 +1,6 @@