Initial Commit
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Activators;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use mpba\Modules\Contracts\ActivatorInterface;
|
||||
use mpba\Modules\Module;
|
||||
|
||||
class DatabaseActivator implements ActivatorInterface
|
||||
{
|
||||
public function enable(Module $module): void
|
||||
{
|
||||
$this->setActive($module, true);
|
||||
}
|
||||
|
||||
public function disable(Module $module): void
|
||||
{
|
||||
$this->setActive($module, false);
|
||||
}
|
||||
|
||||
public function hasStatus(Module $module, bool $status): bool
|
||||
{
|
||||
return $this->getStatus($module, ! $status) === $status;
|
||||
}
|
||||
|
||||
public function setActive(Module $module, bool $active): void
|
||||
{
|
||||
$this->setActiveByName($module->getName(), $active);
|
||||
}
|
||||
|
||||
public function setActiveByName(string $name, bool $active): void
|
||||
{
|
||||
DB::table('module_statuses')->updateOrInsert(
|
||||
['module' => $name],
|
||||
['enabled' => $active]
|
||||
);
|
||||
}
|
||||
|
||||
public function delete(Module $module): void
|
||||
{
|
||||
DB::table('module_statuses')
|
||||
->where('module', $module->getName())
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
DB::table('module_statuses')->truncate();
|
||||
}
|
||||
|
||||
protected function getStatus(Module $module, bool $default = false): bool
|
||||
{
|
||||
$row = DB::table('module_statuses')
|
||||
->where('module', $module->getName())
|
||||
->first();
|
||||
|
||||
if ($row === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return (bool) $row->enabled;
|
||||
}
|
||||
}
|
||||
Executable
+206
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Activators;
|
||||
|
||||
use Illuminate\Cache\CacheManager;
|
||||
use Illuminate\Config\Repository as Config;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use mpba\Modules\Contracts\ActivatorInterface;
|
||||
use mpba\Modules\Module;
|
||||
|
||||
class FileActivator implements ActivatorInterface
|
||||
{
|
||||
/**
|
||||
* Laravel cache instance
|
||||
*
|
||||
* @var CacheManager
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* Laravel Filesystem instance
|
||||
*
|
||||
* @var Filesystem
|
||||
*/
|
||||
private $files;
|
||||
|
||||
/**
|
||||
* Laravel config instance
|
||||
*
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $cacheKey;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $cacheLifetime;
|
||||
|
||||
/**
|
||||
* Array of modules activation statuses
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $modulesStatuses;
|
||||
|
||||
/**
|
||||
* File used to store activation statuses
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $statusesFile;
|
||||
|
||||
public function __construct(Container $app)
|
||||
{
|
||||
$this->cache = $app['cache'];
|
||||
$this->files = $app['files'];
|
||||
$this->config = $app['config'];
|
||||
$this->statusesFile = $this->config('statuses-file');
|
||||
$this->cacheKey = $this->config('cache-key');
|
||||
$this->cacheLifetime = $this->config('cache-lifetime');
|
||||
$this->modulesStatuses = $this->getModulesStatuses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path of the file where statuses are stored
|
||||
*/
|
||||
public function getStatusesFilePath(): string
|
||||
{
|
||||
return $this->statusesFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function reset(): void
|
||||
{
|
||||
if ($this->files->exists($this->statusesFile)) {
|
||||
$this->files->delete($this->statusesFile);
|
||||
}
|
||||
$this->modulesStatuses = [];
|
||||
$this->flushCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function enable(Module $module): void
|
||||
{
|
||||
$this->setActiveByName($module->getName(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function disable(Module $module): void
|
||||
{
|
||||
$this->setActiveByName($module->getName(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function hasStatus(Module $module, bool $status): bool
|
||||
{
|
||||
if (! isset($this->modulesStatuses[$module->getName()])) {
|
||||
return $status === false;
|
||||
}
|
||||
|
||||
return $this->modulesStatuses[$module->getName()] === $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setActive(Module $module, bool $active): void
|
||||
{
|
||||
$this->setActiveByName($module->getName(), $active);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setActiveByName(string $name, bool $status): void
|
||||
{
|
||||
$this->modulesStatuses[$name] = $status;
|
||||
$this->writeJson();
|
||||
$this->flushCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete(Module $module): void
|
||||
{
|
||||
if (! isset($this->modulesStatuses[$module->getName()])) {
|
||||
return;
|
||||
}
|
||||
unset($this->modulesStatuses[$module->getName()]);
|
||||
$this->writeJson();
|
||||
$this->flushCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the activation statuses in a file, as json
|
||||
*/
|
||||
private function writeJson(): void
|
||||
{
|
||||
$this->files->put($this->statusesFile, json_encode($this->modulesStatuses, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the json file that contains the activation statuses.
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private function readJson(): array
|
||||
{
|
||||
if (! $this->files->exists($this->statusesFile)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return json_decode($this->files->get($this->statusesFile), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get modules statuses, either from the cache or from
|
||||
* the json statuses file if the cache is disabled.
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
private function getModulesStatuses(): array
|
||||
{
|
||||
if (! $this->config->get('modules.cache.enabled')) {
|
||||
return $this->readJson();
|
||||
}
|
||||
|
||||
return $this->cache->remember($this->cacheKey, $this->cacheLifetime, function () {
|
||||
return $this->readJson();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a config parameter under the 'activators.file' key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function config(string $key, $default = null)
|
||||
{
|
||||
return $this->config->get('modules.activators.file.'.$key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the modules activation statuses cache
|
||||
*/
|
||||
private function flushCache(): void
|
||||
{
|
||||
$this->cache->forget($this->cacheKey);
|
||||
}
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules;
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Collection as BaseCollection;
|
||||
|
||||
class Collection extends BaseCollection
|
||||
{
|
||||
/**
|
||||
* Get items collections.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the collection of items as a plain array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return array_map(function ($value) {
|
||||
if ($value instanceof Module) {
|
||||
$attributes = $value->json()->getAttributes();
|
||||
$attributes['path'] = $value->getPath();
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
return $value instanceof Arrayable ? $value->toArray() : $value;
|
||||
}, $this->items);
|
||||
}
|
||||
}
|
||||
Executable
+110
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class CommandMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The name of argument name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-command';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate new Artisan command for the specified module.';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.command.namespace') ?: $module->config('paths.generator.command.path', 'Console');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the command.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that should be assigned.', null],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/command.stub', [
|
||||
'COMMAND_NAME' => $this->getCommandName(),
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getCommandName()
|
||||
{
|
||||
return $this->option('command') ?: 'command:name';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$commandPath = GenerateConfigReader::read('command');
|
||||
|
||||
return $path.$commandPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
}
|
||||
Executable
+260
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ComponentMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
protected Filesystem $files;
|
||||
|
||||
protected $name = 'module:make-component';
|
||||
|
||||
protected $description = 'Generate a component for the specified module.';
|
||||
|
||||
protected $argumentName = 'module';
|
||||
|
||||
public function __construct(Filesystem $files)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->files = $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default namespace for the component
|
||||
*/
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.component.namespace') ?: $module->config('paths.generator.component.path', 'Component');
|
||||
}
|
||||
|
||||
/**
|
||||
* Recover the arguments
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected function getArguments(): array
|
||||
{
|
||||
return [
|
||||
['component', InputArgument::REQUIRED, 'The name of the component class.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Recover the options
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
['component', null, InputOption::VALUE_OPTIONAL, 'The name of the component', null],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the proper case and separated name
|
||||
*/
|
||||
public function to_snake_case(string $input): string
|
||||
{
|
||||
return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $input));
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
parent::handle();
|
||||
$this->createViewFile();
|
||||
$this->registerComponentNamespaceInServiceProvider();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recover the stub and provide the required replacements
|
||||
*/
|
||||
protected function getTemplateContents(): string
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub($this->getStubName(), [
|
||||
'MODULE' => $this->getModuleName(),
|
||||
'NAMESPACE' => $module->getStudlyName(),
|
||||
'CLASS_NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getControllerNameWithoutNamespace(),
|
||||
'VIEW_NAME' => $this->to_snake_case($this->getControllerNameWithoutNamespace()),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the view name as componentName.blade.php
|
||||
*/
|
||||
protected function getComponentView(): string
|
||||
{
|
||||
$base = Str::kebab($this->argument('component'));
|
||||
|
||||
// Strip "-component" if the user supplied "SomethingComponent"
|
||||
return 'components/'.Str::of($base)->replace('-component', '').'.blade.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the required view file
|
||||
*/
|
||||
protected function createViewFile(): void
|
||||
{
|
||||
$viewPath = module_path($this->getModuleName()).'/Resources/views';
|
||||
$viewFile = $viewPath.'/'.$this->getComponentView();
|
||||
|
||||
if (! $this->files->exists(dirname($viewFile))) {
|
||||
$this->files->makeDirectory(dirname($viewFile), 0755, true);
|
||||
}
|
||||
|
||||
if (! $this->files->exists($viewFile)) {
|
||||
$stub = new Stub($this->getStubName(true), [
|
||||
'COMPONENT' => $this->argument('component'),
|
||||
'MODULE' => $this->getModuleName(),
|
||||
'CLASS' => $this->getControllerNameWithoutNamespace(),
|
||||
]);
|
||||
$this->files->put($viewFile, $stub->render());
|
||||
$this->info("View created: {$viewFile}");
|
||||
} else {
|
||||
$this->warn("View already exists: {$viewFile}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recover the real controller name without the namespace
|
||||
*/
|
||||
private function getControllerNameWithoutNamespace(): array|string
|
||||
{
|
||||
return class_basename($this->getControllerName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the controller name to be used
|
||||
*/
|
||||
protected function getControllerName(): array|string
|
||||
{
|
||||
$controller = Str::studly($this->argument('component'));
|
||||
|
||||
if (Str::contains(strtolower($controller), 'component') === false) {
|
||||
$controller .= 'Component';
|
||||
}
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component name from the provided arguments
|
||||
*/
|
||||
protected function getComponentName(): array|string
|
||||
{
|
||||
$component = Str::studly($this->argument('component'));
|
||||
if (Str::contains(strtolower($component), 'component') === false) {
|
||||
$component .= 'Component';
|
||||
}
|
||||
|
||||
return $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination path from the entry in modules.config
|
||||
*/
|
||||
protected function getDestinationFilePath(): string
|
||||
{
|
||||
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
$helperPath = GenerateConfigReader::read('component');
|
||||
|
||||
return $path.$helperPath->getPath().'/'.$this->getComponentName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the view name
|
||||
*/
|
||||
protected function getFileName(): string
|
||||
{
|
||||
return 'view';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the view or controller stub based on a flag
|
||||
*/
|
||||
protected function getStubName($view = false): string
|
||||
{
|
||||
if ($view) {
|
||||
return '/component/view.stub';
|
||||
}
|
||||
|
||||
return '/component/controller.stub';
|
||||
}
|
||||
|
||||
/**
|
||||
* Recover the module name from the provided arguments
|
||||
*/
|
||||
protected function getModuleName(): string
|
||||
{
|
||||
return $this->argument('module');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the required use statement(s) and also the Blade definition to the
|
||||
* modules service provider.
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
protected function registerComponentNamespaceInServiceProvider(): void
|
||||
{
|
||||
$moduleName = $this->getModuleName();
|
||||
$namespace = "Modules\\$moduleName\\View\\Components";
|
||||
$alias = 'components';
|
||||
|
||||
$providerPath = module_path($moduleName)."/Providers/{$moduleName}ServiceProvider.php";
|
||||
|
||||
if (! $this->files->exists($providerPath)) {
|
||||
$this->warn("Service provider not found: $providerPath");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$contents = $this->files->get($providerPath);
|
||||
$registration = "Blade::componentNamespace('{$namespace}', '{$alias}');";
|
||||
$import = 'use Illuminate\\Support\\Facades\\Blade;';
|
||||
|
||||
// Insert 'use Blade' after the last existing use statements
|
||||
if (! Str::contains($contents, $import)) {
|
||||
$contents = preg_replace_callback(
|
||||
'/^(use .+?;\n)+/m',
|
||||
function ($matches) use ($import) {
|
||||
return $matches[0].$import."\n";
|
||||
},
|
||||
$contents,
|
||||
1
|
||||
);
|
||||
$this->info('Added Blade import to ServiceProvider.');
|
||||
}
|
||||
|
||||
// Add registration if not already present in the service provider
|
||||
if (! Str::contains($contents, $registration)) {
|
||||
$contents = preg_replace_callback(
|
||||
'/public function boot\(\): void\s*\{/',
|
||||
fn ($matches) => $matches[0]."\n {$registration}",
|
||||
$contents
|
||||
);
|
||||
$this->files->put($providerPath, $contents);
|
||||
$this->info("Registered Blade component namespace in {$moduleName} ServiceProvider.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Executable
+142
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ControllerMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The name of argument being used.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = 'controller';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-controller';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate new restful controller for the specified module.';
|
||||
|
||||
/**
|
||||
* Get controller name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$controllerPath = GenerateConfigReader::read('controller');
|
||||
|
||||
return $path.$controllerPath->getPath().'/'.$this->getControllerName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub($this->getStubName(), [
|
||||
'MODULENAME' => $module->getStudlyName(),
|
||||
'CONTROLLERNAME' => $this->getControllerName(),
|
||||
'NAMESPACE' => $module->getStudlyName(),
|
||||
'CLASS_NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getControllerNameWithoutNamespace(),
|
||||
'LOWER_NAME' => $module->getLowerName(),
|
||||
'MODULE' => $this->getModuleName(),
|
||||
'NAME' => $this->getModuleName(),
|
||||
'STUDLY_NAME' => $module->getStudlyName(),
|
||||
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['controller', InputArgument::REQUIRED, 'The name of the controller class.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['plain', 'p', InputOption::VALUE_NONE, 'Generate a plain controller', null],
|
||||
['api', null, InputOption::VALUE_NONE, 'Exclude the create and edit methods from the controller.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
protected function getControllerName()
|
||||
{
|
||||
$controller = Str::studly($this->argument('controller'));
|
||||
|
||||
if (Str::contains(strtolower($controller), 'controller') === false) {
|
||||
$controller .= 'Controller';
|
||||
}
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
private function getControllerNameWithoutNamespace()
|
||||
{
|
||||
return class_basename($this->getControllerName());
|
||||
}
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.controller.namespace') ?: $module->config('paths.generator.controller.path', 'Http/Controllers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stub file name based on the options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getStubName()
|
||||
{
|
||||
if ($this->option('plain') === true) {
|
||||
$stub = '/controller-plain.stub';
|
||||
} elseif ($this->option('api') === true) {
|
||||
$stub = '/controller-api.stub';
|
||||
} else {
|
||||
$stub = '/controller.stub';
|
||||
}
|
||||
|
||||
return $stub;
|
||||
}
|
||||
}
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Module;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class DisableCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:disable';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Disable the specified module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
/**
|
||||
* check if user entred an argument
|
||||
*/
|
||||
if ($this->argument('module') === null) {
|
||||
$this->disableAll();
|
||||
}
|
||||
|
||||
/** @var Module $module */
|
||||
$module = $this->laravel['modules']->findOrFail($this->argument('module'));
|
||||
|
||||
if ($module->isEnabled()) {
|
||||
$module->disable();
|
||||
|
||||
$this->info("Module [{$module}] disabled successful.");
|
||||
} else {
|
||||
$this->comment("Module [{$module}] has already disabled.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* disableAll
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function disableAll()
|
||||
{
|
||||
/** @var Modules $modules */
|
||||
$modules = $this->laravel['modules']->all();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if ($module->isEnabled()) {
|
||||
$module->disable();
|
||||
|
||||
$this->info("Module [{$module}] disabled successful.");
|
||||
} else {
|
||||
$this->comment("Module [{$module}] has already disabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'Module name.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class DumpCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:dump';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Dump-autoload the specified module or for all module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->info('Generating optimized autoload modules.');
|
||||
|
||||
if ($module = $this->argument('module')) {
|
||||
$this->dump($module);
|
||||
} else {
|
||||
foreach ($this->laravel['modules']->all() as $module) {
|
||||
$this->dump($module->getStudlyName());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function dump($module)
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($module);
|
||||
|
||||
$this->line("<comment>Running for module</comment>: {$module}");
|
||||
|
||||
chdir($module->getPath());
|
||||
|
||||
passthru('composer dump -o -n -q');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'Module name.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Module;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class EnableCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:enable';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Enable the specified module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
/**
|
||||
* check if user entred an argument
|
||||
*/
|
||||
if ($this->argument('module') === null) {
|
||||
$this->enableAll();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @var Module $module */
|
||||
$module = $this->laravel['modules']->findOrFail($this->argument('module'));
|
||||
|
||||
if ($module->isDisabled()) {
|
||||
$module->enable();
|
||||
|
||||
$this->info("Module [{$module}] enabled successful.");
|
||||
} else {
|
||||
$this->comment("Module [{$module}] has already enabled.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* enableAll
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function enableAll()
|
||||
{
|
||||
/** @var Modules $modules */
|
||||
$modules = $this->laravel['modules']->all();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if ($module->isDisabled()) {
|
||||
$module->enable();
|
||||
|
||||
$this->info("Module [{$module}] enabled successful.");
|
||||
} else {
|
||||
$this->comment("Module [{$module}] has already enabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'Module name.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class EventMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-event';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new event class for the specified module';
|
||||
|
||||
public function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/event.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
public function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$eventPath = GenerateConfigReader::read('event');
|
||||
|
||||
return $path.$eventPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.event.namespace') ?: $module->config('paths.generator.event.path', 'Events');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the event.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class FactoryMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The name of argument name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-factory';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new model factory for the specified module.';
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the factory.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
return (new Stub('/factory.stub'))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$factoryPath = GenerateConfigReader::read('factory');
|
||||
|
||||
return $path.$factoryPath->getPath().'/'.$this->getFileName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name')).'.php';
|
||||
}
|
||||
}
|
||||
Executable
+101
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Exceptions\FileAlreadyExistException;
|
||||
use mpba\Modules\Generators\FileGenerator;
|
||||
|
||||
abstract class GeneratorCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name of 'name' argument.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = '';
|
||||
|
||||
/**
|
||||
* Get template contents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getTemplateContents();
|
||||
|
||||
/**
|
||||
* Get the destination file path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getDestinationFilePath();
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$path = str_replace('\\', '/', $this->getDestinationFilePath());
|
||||
|
||||
if (! $this->laravel['files']->isDirectory($dir = dirname($path))) {
|
||||
$this->laravel['files']->makeDirectory($dir, 0777, true);
|
||||
}
|
||||
|
||||
$contents = $this->getTemplateContents();
|
||||
|
||||
try {
|
||||
$overwriteFile = $this->hasOption('force') ? $this->option('force') : false;
|
||||
(new FileGenerator($path, $contents))->withFileOverwrite($overwriteFile)->generate();
|
||||
|
||||
$this->info("Created : {$path}");
|
||||
} catch (FileAlreadyExistException $e) {
|
||||
$this->error("File : {$path} already exists.");
|
||||
|
||||
return E_ERROR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClass()
|
||||
{
|
||||
return class_basename($this->argument($this->argumentName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default namespace.
|
||||
*/
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class namespace.
|
||||
*
|
||||
* @param \mpba\Modules\Module $module
|
||||
* @return string
|
||||
*/
|
||||
public function getClassNamespace($module)
|
||||
{
|
||||
$extra = str_replace($this->getClass(), '', $this->argument($this->argumentName));
|
||||
|
||||
$extra = str_replace('/', '\\', $extra);
|
||||
|
||||
$namespace = $this->laravel['modules']->config('namespace');
|
||||
|
||||
$namespace .= '\\'.$module->getStudlyName();
|
||||
|
||||
$namespace .= '\\'.$this->getDefaultNamespace();
|
||||
|
||||
$namespace .= '\\'.$extra;
|
||||
|
||||
$namespace = str_replace('/', '\\', $namespace);
|
||||
|
||||
return trim($namespace, '\\');
|
||||
}
|
||||
}
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class HelperMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
protected $name = 'module:make-helper';
|
||||
|
||||
protected $description = 'Generate Helpers/helper.php for the specified module.';
|
||||
|
||||
protected $argumentName = 'module';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.helpers.namespace') ?: $module->config('paths.generator.helpers.path', 'Helpers');
|
||||
}
|
||||
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::REQUIRED, 'The name of module.'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['helper', null, InputOption::VALUE_OPTIONAL, 'Unused for now.', null],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
|
||||
return (new Stub($this->getStubName(), [
|
||||
'MODULE' => $this->getModuleName(),
|
||||
'MODULE_LOWER' => strtolower($this->getModuleName()),
|
||||
]))->render();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
protected function getHelperName()
|
||||
{
|
||||
$helper = Str::studly($this->option('helper'));
|
||||
|
||||
if (Str::contains(strtolower($helper), 'helper') === false) {
|
||||
$helper .= 'Helper';
|
||||
}
|
||||
|
||||
return $helper;
|
||||
}
|
||||
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
$helperPath = GenerateConfigReader::read('helper');
|
||||
|
||||
return $path.$helperPath->getPath().'/'.$this->getHelperName().'.php';
|
||||
}
|
||||
|
||||
protected function getFileName()
|
||||
{
|
||||
return 'helper';
|
||||
}
|
||||
|
||||
protected function getStubName()
|
||||
{
|
||||
return '/helper.stub';
|
||||
}
|
||||
|
||||
protected function getModuleName(): string
|
||||
{
|
||||
return $this->argument('module');
|
||||
}
|
||||
}
|
||||
Executable
+148
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Json;
|
||||
use mpba\Modules\Process\Installer;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class InstallCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:install';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Install the specified module by given package name (Vendors/name).';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if (is_null($this->argument('name'))) {
|
||||
return $this->installFromFile();
|
||||
}
|
||||
|
||||
$this->install(
|
||||
$this->argument('name'),
|
||||
$this->argument('version'),
|
||||
$this->option('type'),
|
||||
$this->option('tree')
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install modules from modules.json file.
|
||||
*/
|
||||
protected function installFromFile(): int
|
||||
{
|
||||
if (!file_exists($path = base_path('modules.json'))) {
|
||||
$this->error("File 'modules.json' does not exist in your project root.");
|
||||
|
||||
return E_ERROR;
|
||||
}
|
||||
|
||||
$modules = Json::make($path);
|
||||
|
||||
$dependencies = $modules->get('require', []);
|
||||
|
||||
foreach ($dependencies as $module) {
|
||||
$module = collect($module);
|
||||
|
||||
$this->install(
|
||||
$module->get('name'),
|
||||
$module->get('version'),
|
||||
$module->get('type')
|
||||
);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the specified module.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $version
|
||||
* @param string $type
|
||||
* @param bool $tree
|
||||
*/
|
||||
protected function install($name, $version = 'dev-master', $type = 'composer', $tree = false)
|
||||
{
|
||||
$installer = new Installer(
|
||||
$name,
|
||||
$version,
|
||||
$type ?: $this->option('type'),
|
||||
$tree ?: $this->option('tree')
|
||||
);
|
||||
|
||||
$installer->setRepository($this->laravel['modules']);
|
||||
|
||||
$installer->setConsole($this);
|
||||
|
||||
if ($timeout = $this->option('timeout')) {
|
||||
$installer->setTimeout($timeout);
|
||||
}
|
||||
|
||||
if ($path = $this->option('path')) {
|
||||
$installer->setPath($path);
|
||||
}
|
||||
|
||||
$installer->run();
|
||||
|
||||
if (!$this->option('no-update')) {
|
||||
$this->call('module:update', [
|
||||
'module' => $installer->getModuleName(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::OPTIONAL, 'The name of module will be installed.'],
|
||||
['version', InputArgument::OPTIONAL, 'The version of module will be installed.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['timeout', null, InputOption::VALUE_OPTIONAL, 'The process timeout.', null],
|
||||
['path', null, InputOption::VALUE_OPTIONAL, 'The installation path.', null],
|
||||
['type', null, InputOption::VALUE_OPTIONAL, 'The type of installation.', null],
|
||||
['tree', null, InputOption::VALUE_NONE, 'Install the module as a git subtree', null],
|
||||
['no-update', null, InputOption::VALUE_NONE, 'Disables the automatic update of the dependencies.', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class JobMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-job';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new job class for the specified module';
|
||||
|
||||
protected $argumentName = 'name';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.jobs.namespace') ?: $module->config('paths.generator.jobs.path', 'Jobs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the job.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template contents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub($this->getStubName(), [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination file path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$jobPath = GenerateConfigReader::read('jobs');
|
||||
|
||||
return $path.$jobPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
|
||||
protected function getStubName(): string
|
||||
{
|
||||
if ($this->option('sync')) {
|
||||
return '/job.stub';
|
||||
}
|
||||
|
||||
return '/job-queued.stub';
|
||||
}
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Contracts\RepositoryInterface;
|
||||
use mpba\Modules\Module;
|
||||
|
||||
class LaravelModulesV6Migrator extends Command
|
||||
{
|
||||
protected $name = 'module:v6:migrate';
|
||||
|
||||
protected $description = 'Migrate laravel-modules v5 modules statuses to v6.';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$moduleStatuses = [];
|
||||
/** @var mpba\Modules\Contracts\RepositoryInterface $modules */
|
||||
$modules = $this->laravel['modules'];
|
||||
|
||||
$modules = $modules->all();
|
||||
/** @var Module $module */
|
||||
foreach ($modules as $module) {
|
||||
if ($module->json()->get('active') === 1) {
|
||||
$module->enable();
|
||||
$moduleStatuses[] = [$module->getName(), 'Enabled'];
|
||||
}
|
||||
if ($module->json()->get('active') === 0) {
|
||||
$module->disable();
|
||||
$moduleStatuses[] = [$module->getName(), 'Disabled'];
|
||||
}
|
||||
}
|
||||
$this->info('All modules have been migrated.');
|
||||
$this->table(['Module name', 'Status'], $moduleStatuses);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Module;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ListCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:list';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Show list of all modules.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->table(['Name', 'Status', 'Order', 'Path'], $this->getRows());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table rows.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRows()
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
/** @var Module $module */
|
||||
foreach ($this->getModules() as $module) {
|
||||
$rows[] = [
|
||||
$module->getName(),
|
||||
$module->isEnabled() ? 'Enabled' : 'Disabled',
|
||||
$module->get('order'),
|
||||
$module->getPath(),
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function getModules()
|
||||
{
|
||||
switch ($this->option('only')) {
|
||||
case 'enabled':
|
||||
return $this->laravel['modules']->getByStatus(1);
|
||||
break;
|
||||
|
||||
case 'disabled':
|
||||
return $this->laravel['modules']->getByStatus(0);
|
||||
break;
|
||||
|
||||
case 'ordered':
|
||||
return $this->laravel['modules']->getOrdered($this->option('direction'));
|
||||
break;
|
||||
|
||||
default:
|
||||
return $this->laravel['modules']->all();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['only', 'o', InputOption::VALUE_OPTIONAL, 'Types of modules will be displayed.', null],
|
||||
['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+126
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Module;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ListenerMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-listener';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new event listener class for the specified module';
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the command.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['event', 'e', InputOption::VALUE_OPTIONAL, 'The event class being listened for.'],
|
||||
['queued', null, InputOption::VALUE_NONE, 'Indicates the event listener should be queued.'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub($this->getStubName(), [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'EVENTNAME' => $this->getEventName($module),
|
||||
'SHORTEVENTNAME' => $this->getShortEventName(),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.listener.namespace') ?: $module->config('paths.generator.listener.path', 'Listeners');
|
||||
}
|
||||
|
||||
protected function getEventName(Module $module)
|
||||
{
|
||||
$namespace = $this->laravel['modules']->config('namespace').'\\'.$module->getStudlyName();
|
||||
$eventPath = GenerateConfigReader::read('event');
|
||||
|
||||
$eventName = $namespace.'\\'.$eventPath->getPath().'\\'.$this->option('event');
|
||||
|
||||
return str_replace('/', '\\', $eventName);
|
||||
}
|
||||
|
||||
protected function getShortEventName()
|
||||
{
|
||||
return class_basename($this->option('event'));
|
||||
}
|
||||
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$listenerPath = GenerateConfigReader::read('listener');
|
||||
|
||||
return $path.$listenerPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
|
||||
protected function getStubName(): string
|
||||
{
|
||||
if ($this->option('queued')) {
|
||||
if ($this->option('event')) {
|
||||
return '/listener-queued.stub';
|
||||
}
|
||||
|
||||
return '/listener-queued-duck.stub';
|
||||
}
|
||||
|
||||
if ($this->option('event')) {
|
||||
return '/listener.stub';
|
||||
}
|
||||
|
||||
return '/listener-duck.stub';
|
||||
}
|
||||
}
|
||||
Executable
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class MailMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-mail';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new email class for the specified module';
|
||||
|
||||
protected $argumentName = 'name';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.emails.namespace') ?: $module->config('paths.generator.emails.path', 'Emails');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the mailable.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template contents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/mail.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination file path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$mailPath = GenerateConfigReader::read('emails');
|
||||
|
||||
return $path.$mailPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
}
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class MiddlewareMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The name of argument name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-middleware';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new middleware class for the specified module.';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.filter.namespace') ?: $module->config('paths.generator.filter.path', 'Http/Middleware');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the command.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/middleware.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$middlewarePath = GenerateConfigReader::read('filter');
|
||||
|
||||
return $path.$middlewarePath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
}
|
||||
Executable
+111
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Migrations\Migrator;
|
||||
use mpba\Modules\Module;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class MigrateCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:migrate';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Migrate the migrations from the specified module or from all modules.';
|
||||
|
||||
/**
|
||||
* @var mpba\Modules\Contracts\RepositoryInterface
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->module = $this->laravel['modules'];
|
||||
|
||||
$name = $this->argument('module');
|
||||
|
||||
if ($name) {
|
||||
$module = $this->module->findOrFail($name);
|
||||
|
||||
$this->migrate($module);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($this->module->getOrdered($this->option('direction')) as $module) {
|
||||
$this->line('Running for module: <info>'.$module->getName().'</info>');
|
||||
|
||||
$this->migrate($module);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migration from the specified module.
|
||||
*/
|
||||
protected function migrate(Module $module)
|
||||
{
|
||||
$path = str_replace(base_path(), '', (new Migrator($module, $this->getLaravel()))->getPath());
|
||||
|
||||
if ($this->option('subpath')) {
|
||||
$path = $path.'/'.$this->option('subpath');
|
||||
}
|
||||
|
||||
$this->call('migrate', [
|
||||
'--path' => $path,
|
||||
'--database' => $this->option('database'),
|
||||
'--pretend' => $this->option('pretend'),
|
||||
'--force' => $this->option('force'),
|
||||
]);
|
||||
|
||||
if ($this->option('seed')) {
|
||||
$this->call('module:seed', ['module' => $module->getName(), '--force' => $this->option('force')]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'],
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
|
||||
['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'],
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
|
||||
['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'],
|
||||
['subpath', null, InputOption::VALUE_OPTIONAL, 'Indicate a subpath to run your migrations from'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class MigrateRefreshCommand extends Command
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:migrate-refresh';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Rollback & re-migrate the modules migrations.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$module = $this->argument('module');
|
||||
|
||||
if ($module && ! $this->getModuleName()) {
|
||||
$this->error("Module [$module] does not exists.");
|
||||
|
||||
return E_ERROR;
|
||||
}
|
||||
|
||||
$this->call('module:migrate-reset', [
|
||||
'module' => $this->getModuleName(),
|
||||
'--database' => $this->option('database'),
|
||||
'--force' => $this->option('force'),
|
||||
]);
|
||||
|
||||
$this->call('module:migrate', [
|
||||
'module' => $this->getModuleName(),
|
||||
'--database' => $this->option('database'),
|
||||
'--force' => $this->option('force'),
|
||||
]);
|
||||
|
||||
if ($this->option('seed')) {
|
||||
$this->call('module:seed', [
|
||||
'module' => $this->getModuleName(),
|
||||
]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
|
||||
['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'],
|
||||
];
|
||||
}
|
||||
|
||||
public function getModuleName()
|
||||
{
|
||||
$module = $this->argument('module');
|
||||
|
||||
if (! $module) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$module = app('modules')->find($module);
|
||||
|
||||
return $module ? $module->getStudlyName() : null;
|
||||
}
|
||||
}
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Migrations\Migrator;
|
||||
use mpba\Modules\Traits\MigrationLoaderTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class MigrateResetCommand extends Command
|
||||
{
|
||||
use MigrationLoaderTrait;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:migrate-reset';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Reset the modules migrations.';
|
||||
|
||||
/**
|
||||
* @var mpba\Modules\Contracts\RepositoryInterface
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->module = $this->laravel['modules'];
|
||||
|
||||
$name = $this->argument('module');
|
||||
|
||||
if (! empty($name)) {
|
||||
$this->reset($name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($this->module->getOrdered($this->option('direction')) as $module) {
|
||||
$this->line('Running for module: <info>'.$module->getName().'</info>');
|
||||
|
||||
$this->reset($module);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback migration from the specified module.
|
||||
*/
|
||||
public function reset($module)
|
||||
{
|
||||
if (is_string($module)) {
|
||||
$module = $this->module->findOrFail($module);
|
||||
}
|
||||
|
||||
$migrator = new Migrator($module, $this->getLaravel());
|
||||
|
||||
$database = $this->option('database');
|
||||
|
||||
if (! empty($database)) {
|
||||
$migrator->setDatabase($database);
|
||||
}
|
||||
|
||||
$migrated = $migrator->reset();
|
||||
|
||||
if (count($migrated)) {
|
||||
foreach ($migrated as $migration) {
|
||||
$this->line("Rollback: <info>{$migration}</info>");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->comment('Nothing to rollback.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'desc'],
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
|
||||
['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Migrations\Migrator;
|
||||
use mpba\Modules\Traits\MigrationLoaderTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class MigrateRollbackCommand extends Command
|
||||
{
|
||||
use MigrationLoaderTrait;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:migrate-rollback';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Rollback the modules migrations.';
|
||||
|
||||
/**
|
||||
* @var mpba\Modules\Contracts\RepositoryInterface
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->module = $this->laravel['modules'];
|
||||
|
||||
$name = $this->argument('module');
|
||||
|
||||
if (! empty($name)) {
|
||||
$this->rollback($name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($this->module->getOrdered($this->option('direction')) as $module) {
|
||||
$this->line('Running for module: <info>'.$module->getName().'</info>');
|
||||
|
||||
$this->rollback($module);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback migration from the specified module.
|
||||
*/
|
||||
public function rollback($module)
|
||||
{
|
||||
if (is_string($module)) {
|
||||
$module = $this->module->findOrFail($module);
|
||||
}
|
||||
|
||||
$migrator = new Migrator($module, $this->getLaravel());
|
||||
|
||||
$database = $this->option('database');
|
||||
|
||||
if (! empty($database)) {
|
||||
$migrator->setDatabase($database);
|
||||
}
|
||||
|
||||
$migrated = $migrator->rollback();
|
||||
|
||||
if (count($migrated)) {
|
||||
foreach ($migrated as $migration) {
|
||||
$this->line("Rollback: <info>{$migration}</info>");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->comment('Nothing to rollback.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'desc'],
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
|
||||
['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Migrations\Migrator;
|
||||
use mpba\Modules\Module;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class MigrateStatusCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:migrate-status';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Status for all module migrations';
|
||||
|
||||
/**
|
||||
* @var mpba\Modules\Contracts\RepositoryInterface
|
||||
*/
|
||||
protected $module;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->module = $this->laravel['modules'];
|
||||
|
||||
$name = $this->argument('module');
|
||||
|
||||
if ($name) {
|
||||
$module = $this->module->findOrFail($name);
|
||||
|
||||
$this->migrateStatus($module);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($this->module->getOrdered($this->option('direction')) as $module) {
|
||||
$this->line('Running for module: <info>'.$module->getName().'</info>');
|
||||
$this->migrateStatus($module);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migration from the specified module.
|
||||
*/
|
||||
protected function migrateStatus(Module $module)
|
||||
{
|
||||
$path = str_replace(base_path(), '', (new Migrator($module, $this->getLaravel()))->getPath());
|
||||
|
||||
$this->call('migrate:status', [
|
||||
'--path' => $path,
|
||||
'--database' => $this->option('database'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'],
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+166
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Migrations\NameParser;
|
||||
use mpba\Modules\Support\Migrations\SchemaParser;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class MigrationMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-migration';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new migration for the specified module.';
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The migration name will be created.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be created.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['fields', null, InputOption::VALUE_OPTIONAL, 'The specified fields table.', null],
|
||||
['plain', null, InputOption::VALUE_NONE, 'Create plain migration.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get schema parser.
|
||||
*
|
||||
* @return SchemaParser
|
||||
*/
|
||||
public function getSchemaParser()
|
||||
{
|
||||
return new SchemaParser($this->option('fields'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$parser = new NameParser($this->argument('name'));
|
||||
|
||||
if ($parser->isCreate()) {
|
||||
return Stub::create('/migration/create.stub', [
|
||||
'class' => $this->getClass(),
|
||||
'table' => $parser->getTableName(),
|
||||
'fields' => $this->getSchemaParser()->render(),
|
||||
]);
|
||||
} elseif ($parser->isAdd()) {
|
||||
return Stub::create('/migration/add.stub', [
|
||||
'class' => $this->getClass(),
|
||||
'table' => $parser->getTableName(),
|
||||
'fields_up' => $this->getSchemaParser()->up(),
|
||||
'fields_down' => $this->getSchemaParser()->down(),
|
||||
]);
|
||||
} elseif ($parser->isDelete()) {
|
||||
return Stub::create('/migration/delete.stub', [
|
||||
'class' => $this->getClass(),
|
||||
'table' => $parser->getTableName(),
|
||||
'fields_down' => $this->getSchemaParser()->up(),
|
||||
'fields_up' => $this->getSchemaParser()->down(),
|
||||
]);
|
||||
} elseif ($parser->isDrop()) {
|
||||
return Stub::create('/migration/drop.stub', [
|
||||
'class' => $this->getClass(),
|
||||
'table' => $parser->getTableName(),
|
||||
'fields' => $this->getSchemaParser()->render(),
|
||||
]);
|
||||
}
|
||||
|
||||
return Stub::create('/migration/plain.stub', [
|
||||
'class' => $this->getClass(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$generatorPath = GenerateConfigReader::read('migration');
|
||||
|
||||
return $path.$generatorPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return date('Y_m_d_His_').$this->getSchemaName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
private function getSchemaName()
|
||||
{
|
||||
return $this->argument('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getClassName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
|
||||
public function getClass()
|
||||
{
|
||||
return $this->getClassName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if (parent::handle() === E_ERROR) {
|
||||
return E_ERROR;
|
||||
}
|
||||
|
||||
if (app()->environment() === 'testing') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Executable
+172
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ModelMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The name of argument name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = 'model';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-model';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new model for the specified module.';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
if (parent::handle() === E_ERROR) {
|
||||
return E_ERROR;
|
||||
}
|
||||
|
||||
$this->handleOptionalMigrationOption();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a proper migration name:
|
||||
* ProductDetail: product_details
|
||||
* Product: products
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function createMigrationName()
|
||||
{
|
||||
$pieces = preg_split('/(?=[A-Z])/', $this->argument('model'), -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$string = '';
|
||||
foreach ($pieces as $i => $piece) {
|
||||
if ($i + 1 < count($pieces)) {
|
||||
$string .= strtolower($piece).'_';
|
||||
} else {
|
||||
$string .= Str::plural(strtolower($piece));
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['model', InputArgument::REQUIRED, 'The name of model will be created.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['fillable', null, InputOption::VALUE_OPTIONAL, 'The fillable attributes.', null],
|
||||
['migration', 'm', InputOption::VALUE_NONE, 'Flag to create associated migrations', null],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the migration file with the given model if migration flag was used
|
||||
*/
|
||||
private function handleOptionalMigrationOption()
|
||||
{
|
||||
if ($this->option('migration') === true) {
|
||||
$migrationName = 'create_'.$this->createMigrationName().'_table';
|
||||
$this->call('module:make-migration', ['name' => $migrationName, 'module' => $this->argument('module')]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/model.stub', [
|
||||
'NAME' => $this->getModelName(),
|
||||
'FILLABLE' => $this->getFillable(),
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
'LOWER_NAME' => $module->getLowerName(),
|
||||
'MODULE' => $this->getModuleName(),
|
||||
'STUDLY_NAME' => $module->getStudlyName(),
|
||||
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$modelPath = GenerateConfigReader::read('model');
|
||||
|
||||
return $path.$modelPath->getPath().'/'.$this->getModelName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|string
|
||||
*/
|
||||
private function getModelName()
|
||||
{
|
||||
return Str::studly($this->argument('model'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFillable()
|
||||
{
|
||||
$fillable = $this->option('fillable');
|
||||
|
||||
if (! is_null($fillable)) {
|
||||
$arrays = explode(',', $fillable);
|
||||
|
||||
return json_encode($arrays);
|
||||
}
|
||||
|
||||
return '[]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default namespace.
|
||||
*/
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.model.namespace') ?: $module->config('paths.generator.model.path', 'Modles');
|
||||
}
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class ModuleDeleteCommand extends Command
|
||||
{
|
||||
protected $name = 'module:delete';
|
||||
|
||||
protected $description = 'Delete a module from the application';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$this->laravel['modules']->delete($this->argument('module'));
|
||||
|
||||
$this->info("Module {$this->argument('module')} has been deleted.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::REQUIRED, 'The name of module to delete.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Contracts\ActivatorInterface;
|
||||
use mpba\Modules\Generators\ModuleGenerator;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ModuleMakeCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$names = $this->argument('name');
|
||||
$success = true;
|
||||
|
||||
foreach ($names as $name) {
|
||||
$code = with(new ModuleGenerator($name))
|
||||
->setFilesystem($this->laravel['files'])
|
||||
->setModule($this->laravel['modules'])
|
||||
->setConfig($this->laravel['config'])
|
||||
->setActivator($this->laravel[ActivatorInterface::class])
|
||||
->setConsole($this)
|
||||
->setForce($this->option('force'))
|
||||
->setPlain($this->option('plain'))
|
||||
->setActive(! $this->option('disabled'))
|
||||
->generate();
|
||||
|
||||
if ($code === E_ERROR) {
|
||||
$success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $success ? 0 : E_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::IS_ARRAY, 'The names of modules will be created.'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['plain', 'p', InputOption::VALUE_NONE, 'Generate a plain module (without some resources).'],
|
||||
['disabled', 'd', InputOption::VALUE_NONE, 'Do not enable the module at creation.'],
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when the module already exists.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+87
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
final class NotificationMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-notification';
|
||||
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new notification class for the specified module.';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.notifications.namespace') ?: $module->config('paths.generator.notifications.path', 'Notifications');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template contents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/notification.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination file path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$notificationPath = GenerateConfigReader::read('notifications');
|
||||
|
||||
return $path.$notificationPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the notification class.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class PolicyMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The name of argument name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-policy';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new policy class for the specified module.';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.policies.namespace') ?: $module->config('paths.generator.policies.path', 'Policies');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the policy class.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/policy.plain.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$policyPath = GenerateConfigReader::read('policies');
|
||||
|
||||
return $path.$policyPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
}
|
||||
Executable
+115
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Module;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ProviderMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The name of argument name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-provider';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new service provider class for the specified module.';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.provider.namespace') ?: $module->config('paths.generator.provider.path', 'Providers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The service provider name.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['master', null, InputOption::VALUE_NONE, 'Indicates the master service provider', null],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$stub = $this->option('master') ? 'scaffold/provider' : 'provider';
|
||||
|
||||
/** @var Module $module */
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/'.$stub.'.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
'LOWER_NAME' => $module->getLowerName(),
|
||||
'MODULE' => $this->getModuleName(),
|
||||
'NAME' => $this->getFileName(),
|
||||
'STUDLY_NAME' => $module->getStudlyName(),
|
||||
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'),
|
||||
'PATH_VIEWS' => GenerateConfigReader::read('views')->getPath(),
|
||||
'PATH_LANG' => GenerateConfigReader::read('lang')->getPath(),
|
||||
'PATH_CONFIG' => GenerateConfigReader::read('config')->getPath(),
|
||||
'MIGRATIONS_PATH' => GenerateConfigReader::read('migration')->getPath(),
|
||||
'FACTORIES_PATH' => GenerateConfigReader::read('factory')->getPath(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$generatorPath = GenerateConfigReader::read('provider');
|
||||
|
||||
return $path.$generatorPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
}
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Module;
|
||||
use mpba\Modules\Publishing\AssetPublisher;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class PublishCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:publish';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Publish a module\'s assets to the application';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if ($name = $this->argument('module')) {
|
||||
$this->publish($name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->publishAll();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish assets from all modules.
|
||||
*/
|
||||
public function publishAll()
|
||||
{
|
||||
foreach ($this->laravel['modules']->allEnabled() as $module) {
|
||||
$this->publish($module);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish assets from the specified module.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function publish($name)
|
||||
{
|
||||
if ($name instanceof Module) {
|
||||
$module = $name;
|
||||
} else {
|
||||
$module = $this->laravel['modules']->findOrFail($name);
|
||||
}
|
||||
|
||||
with(new AssetPublisher($module))
|
||||
->setRepository($this->laravel['modules'])
|
||||
->setConsole($this)
|
||||
->publish();
|
||||
|
||||
$this->line("<info>Published</info>: {$module->getStudlyName()}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class PublishConfigurationCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:publish-config';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Publish a module\'s config files to the application';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if ($module = $this->argument('module')) {
|
||||
$this->publishConfiguration($module);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($this->laravel['modules']->allEnabled() as $module) {
|
||||
$this->publishConfiguration($module->getName());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $module
|
||||
* @return string
|
||||
*/
|
||||
private function getServiceProviderForModule($module)
|
||||
{
|
||||
$namespace = $this->laravel['config']->get('modules.namespace');
|
||||
$studlyName = Str::studly($module);
|
||||
|
||||
return "$namespace\\$studlyName\\Providers\\{$studlyName}ServiceProvider";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $module
|
||||
*/
|
||||
private function publishConfiguration($module)
|
||||
{
|
||||
$this->call('Vendors:publish', [
|
||||
'--provider' => $this->getServiceProviderForModule($module),
|
||||
'--force' => $this->option('force'),
|
||||
'--tag' => ['config'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module being used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['--force', '-f', InputOption::VALUE_NONE, 'Force the publishing of config files'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Migrations\Migrator;
|
||||
use mpba\Modules\Publishing\MigrationPublisher;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class PublishMigrationCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:publish-migration';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = "Publish a module's migrations to the application";
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if ($name = $this->argument('module')) {
|
||||
$module = $this->laravel['modules']->findOrFail($name);
|
||||
|
||||
$this->publish($module);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($this->laravel['modules']->allEnabled() as $module) {
|
||||
$this->publish($module);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish migration for the specified module.
|
||||
*
|
||||
* @param \mpba\Modules\Module $module
|
||||
*/
|
||||
public function publish($module)
|
||||
{
|
||||
with(new MigrationPublisher(new Migrator($module, $this->getLaravel())))
|
||||
->setRepository($this->laravel['modules'])
|
||||
->setConsole($this)
|
||||
->publish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module being used.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Module;
|
||||
use mpba\Modules\Publishing\LangPublisher;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class PublishTranslationCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:publish-translation';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Publish a module\'s translations to the application';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if ($name = $this->argument('module')) {
|
||||
$this->publish($name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->publishAll();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish assets from all modules.
|
||||
*/
|
||||
public function publishAll()
|
||||
{
|
||||
foreach ($this->laravel['modules']->allEnabled() as $module) {
|
||||
$this->publish($module);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish assets from the specified module.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function publish($name)
|
||||
{
|
||||
if ($name instanceof Module) {
|
||||
$module = $name;
|
||||
} else {
|
||||
$module = $this->laravel['modules']->findOrFail($name);
|
||||
}
|
||||
|
||||
with(new LangPublisher($module))
|
||||
->setRepository($this->laravel['modules'])
|
||||
->setConsole($this)
|
||||
->publish();
|
||||
|
||||
$this->line("<info>Published</info>: {$module->getStudlyName()}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class RequestMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The name of argument name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-request';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new form request class for the specified module.';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.request.namespace') ?: $module->config('paths.generator.request.path', 'Http/Requests');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the form request class.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/request.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$requestPath = GenerateConfigReader::read('request');
|
||||
|
||||
return $path.$requestPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
}
|
||||
Executable
+99
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class ResourceMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
protected $argumentName = 'name';
|
||||
|
||||
protected $name = 'module:make-resource';
|
||||
|
||||
protected $description = 'Create a new resource class for the specified module.';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.resource.namespace') ?: $module->config('paths.generator.resource.path', 'Transformers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the resource class.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['collection', 'c', InputOption::VALUE_NONE, 'Create a resource collection.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub($this->getStubName(), [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$resourcePath = GenerateConfigReader::read('resource');
|
||||
|
||||
return $path.$resourcePath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the command is generating a resource collection.
|
||||
*/
|
||||
protected function collection(): bool
|
||||
{
|
||||
return $this->option('collection') ||
|
||||
Str::endsWith($this->argument('name'), 'Collection');
|
||||
}
|
||||
|
||||
protected function getStubName(): string
|
||||
{
|
||||
if ($this->collection()) {
|
||||
return '/resource-collection.stub';
|
||||
}
|
||||
|
||||
return '/resource.stub';
|
||||
}
|
||||
}
|
||||
Executable
+122
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class RouteProviderMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
protected $argumentName = 'module';
|
||||
|
||||
/**
|
||||
* The command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:route-provider';
|
||||
|
||||
/**
|
||||
* The command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new route service provider for the specified module.';
|
||||
|
||||
/**
|
||||
* The command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when the file already exists.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template contents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/route-provider.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getFileName(),
|
||||
'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'),
|
||||
'MODULE' => $this->getModuleName(),
|
||||
'CONTROLLER_NAMESPACE' => $this->getControllerNameSpace(),
|
||||
'WEB_ROUTES_PATH' => $this->getWebRoutesPath(),
|
||||
'API_ROUTES_PATH' => $this->getApiRoutesPath(),
|
||||
'LOWER_NAME' => $module->getLowerName(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return 'RouteServiceProvider';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the destination file path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$generatorPath = GenerateConfigReader::read('provider');
|
||||
|
||||
return $path.$generatorPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getWebRoutesPath()
|
||||
{
|
||||
return '/'.$this->laravel['modules']->config('stubs.files.routes/web', 'Routes/web.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getApiRoutesPath()
|
||||
{
|
||||
return '/'.$this->laravel['modules']->config('stubs.files.routes/api', 'Routes/api.php');
|
||||
}
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.provider.namespace') ?: $module->config('paths.generator.provider.path', 'Providers');
|
||||
}
|
||||
|
||||
private function getControllerNameSpace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return str_replace('/', '\\', $module->config('paths.generator.controller.namespace') ?: $module->config('paths.generator.controller.path', 'Controller'));
|
||||
}
|
||||
}
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class RuleMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The name of argument name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-rule';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new validation rule for the specified module.';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.rules.namespace') ?: $module->config('paths.generator.rules.path', 'Rules');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the rule class.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/rule.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$rulePath = GenerateConfigReader::read('rules');
|
||||
|
||||
return $path.$rulePath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getFileName()
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
}
|
||||
Executable
+239
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Debug\ExceptionHandler;
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Contracts\RepositoryInterface;
|
||||
use mpba\Modules\Module;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class SeedCommand extends Command
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:seed';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Run database seeder from the specified module or from all modules.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
try {
|
||||
if ($name = $this->argument('module')) {
|
||||
$name = Str::studly($name);
|
||||
$this->moduleSeed($this->getModuleByName($name));
|
||||
} else {
|
||||
$modules = $this->getModuleRepository()->getOrdered();
|
||||
array_walk($modules, [$this, 'moduleSeed']);
|
||||
$this->info('All modules seeded.');
|
||||
}
|
||||
} catch (\Error $e) {
|
||||
$e = new ErrorException($e->getMessage(), $e->getCode(), 1, $e->getFile(), $e->getLine(), $e);
|
||||
$this->reportException($e);
|
||||
$this->renderException($this->getOutput(), $e);
|
||||
|
||||
return E_ERROR;
|
||||
} catch (\Exception $e) {
|
||||
$this->reportException($e);
|
||||
$this->renderException($this->getOutput(), $e);
|
||||
|
||||
return E_ERROR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function getModuleRepository(): RepositoryInterface
|
||||
{
|
||||
$modules = $this->laravel['modules'];
|
||||
if (! $modules instanceof RepositoryInterface) {
|
||||
throw new RuntimeException('Module repository not found!');
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Module
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function getModuleByName($name)
|
||||
{
|
||||
$modules = $this->getModuleRepository();
|
||||
if ($modules->has($name) === false) {
|
||||
throw new RuntimeException("Module [$name] does not exists.");
|
||||
}
|
||||
|
||||
return $modules->find($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function moduleSeed(Module $module)
|
||||
{
|
||||
$seeders = [];
|
||||
$name = $module->getName();
|
||||
$config = $module->get('migration');
|
||||
if (is_array($config) && array_key_exists('seeds', $config)) {
|
||||
foreach ((array) $config['seeds'] as $class) {
|
||||
if (class_exists($class)) {
|
||||
$seeders[] = $class;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$class = $this->getSeederName($name); // legacy support
|
||||
if (class_exists($class)) {
|
||||
$seeders[] = $class;
|
||||
} else {
|
||||
// look at other namespaces
|
||||
$classes = $this->getSeederNames($name);
|
||||
foreach ($classes as $class) {
|
||||
if (class_exists($class)) {
|
||||
$seeders[] = $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($seeders) > 0) {
|
||||
array_walk($seeders, [$this, 'dbSeed']);
|
||||
$this->info("Module [$name] seeded.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed the specified module.
|
||||
*
|
||||
* @param string $className
|
||||
*/
|
||||
protected function dbSeed($className)
|
||||
{
|
||||
if ($option = $this->option('class')) {
|
||||
$params['--class'] = Str::finish(substr($className, 0, strrpos($className, '\\')), '\\').$option;
|
||||
} else {
|
||||
$params = ['--class' => $className];
|
||||
}
|
||||
|
||||
if ($option = $this->option('database')) {
|
||||
$params['--database'] = $option;
|
||||
}
|
||||
|
||||
if ($option = $this->option('force')) {
|
||||
$params['--force'] = $option;
|
||||
}
|
||||
|
||||
$this->call('db:seed', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get master database seeder name for the specified module.
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function getSeederName($name)
|
||||
{
|
||||
$name = Str::studly($name);
|
||||
|
||||
$namespace = $this->laravel['modules']->config('namespace');
|
||||
$config = GenerateConfigReader::read('seeder');
|
||||
$seederPath = str_replace('/', '\\', $config->getPath());
|
||||
|
||||
return $namespace.'\\'.$name.'\\'.$seederPath.'\\'.$name.'DatabaseSeeder';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get master database seeder name for the specified module under a different namespace than Modules.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array $foundModules array containing namespace paths
|
||||
*/
|
||||
public function getSeederNames($name)
|
||||
{
|
||||
$name = Str::studly($name);
|
||||
|
||||
$seederPath = GenerateConfigReader::read('seeder');
|
||||
$seederPath = str_replace('/', '\\', $seederPath->getPath());
|
||||
|
||||
$foundModules = [];
|
||||
foreach ($this->laravel['modules']->config('scan.paths') as $path) {
|
||||
$namespace = array_slice(explode('/', $path), -1)[0];
|
||||
$foundModules[] = $namespace.'\\'.$name.'\\'.$seederPath.'\\'.$name.'DatabaseSeeder';
|
||||
}
|
||||
|
||||
return $foundModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report the exception to the exception handler.
|
||||
*
|
||||
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function renderException($output, \Exception $e)
|
||||
{
|
||||
$this->laravel[ExceptionHandler::class]->renderForConsole($output, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report the exception to the exception handler.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function reportException(\Exception $e)
|
||||
{
|
||||
$this->laravel[ExceptionHandler::class]->report($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder.'],
|
||||
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed.'],
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\CanClearModulesCache;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class SeedMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use CanClearModulesCache, ModuleCommandTrait;
|
||||
|
||||
protected $argumentName = 'name';
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:make-seed';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate new seeder for the specified module.';
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of seeder will be created.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'master',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Indicates the seeder will created is a master database seeder.',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/seeder.stub', [
|
||||
'NAME' => $this->getSeederName(),
|
||||
'MODULE' => $this->getModuleName(),
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
|
||||
]))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
$this->clearCache();
|
||||
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
$seederPath = GenerateConfigReader::read('seeder');
|
||||
|
||||
return $path.$seederPath->getPath().'/'.$this->getSeederName().'.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get seeder name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getSeederName()
|
||||
{
|
||||
$end = $this->option('master') ? 'DatabaseSeeder' : 'TableSeeder';
|
||||
|
||||
return Str::studly($this->argument('name')).$end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default namespace.
|
||||
*/
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.seeder.namespace') ?: $module->config('paths.generator.seeder.path', 'Database/Seeders');
|
||||
}
|
||||
}
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class SetupCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:setup';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Setting up modules folders for first use.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$code = $this->generateModulesFolder();
|
||||
|
||||
return $this->generateAssetsFolder() | $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the modules folder.
|
||||
*/
|
||||
public function generateModulesFolder()
|
||||
{
|
||||
return $this->generateDirectory(
|
||||
$this->laravel['modules']->config('paths.modules'),
|
||||
'Modules directory created successfully',
|
||||
'Modules directory already exist'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the assets folder.
|
||||
*/
|
||||
public function generateAssetsFolder()
|
||||
{
|
||||
return $this->generateDirectory(
|
||||
$this->laravel['modules']->config('paths.assets'),
|
||||
'Assets directory created successfully',
|
||||
'Assets directory already exist'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the specified directory by given $dir.
|
||||
*/
|
||||
protected function generateDirectory($dir, $success, $error): int
|
||||
{
|
||||
if (! $this->laravel['files']->isDirectory($dir)) {
|
||||
$this->laravel['files']->makeDirectory($dir, 0755, true, true);
|
||||
|
||||
$this->info($success);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->error($error);
|
||||
|
||||
return E_ERROR;
|
||||
}
|
||||
}
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class SupportMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
protected $name = 'module:make-support';
|
||||
|
||||
protected $description = 'Generate Support files for the specified module.';
|
||||
|
||||
protected $argumentName = 'module';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.support.namespace') ?: $module->config('paths.generator.support.path', 'Support');
|
||||
}
|
||||
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::REQUIRED, 'The name of module.'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['support', null, InputOption::VALUE_OPTIONAL, 'Unused for now.', null],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub('/moduleinfo.stub', [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'MODULE' => $this->getModuleName(),
|
||||
]))->render();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
protected function getPathName()
|
||||
{
|
||||
$pathName = Str::studly($this->option('support'));
|
||||
|
||||
if (Str::contains(strtolower($pathName), 'support') === false) {
|
||||
$pathName .= 'moduleInfo';
|
||||
}
|
||||
|
||||
return $pathName;
|
||||
}
|
||||
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
$helperPath = GenerateConfigReader::read('support');
|
||||
|
||||
return $path.$helperPath->getPath().'/'.$this->getPathName().'.php';
|
||||
}
|
||||
|
||||
protected function getFileName()
|
||||
{
|
||||
return 'moduleInfo';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class namespace.
|
||||
*
|
||||
* @param \mpba\Modules\Module $module
|
||||
* @return string
|
||||
*/
|
||||
public function getClassNamespace($module)
|
||||
{
|
||||
$extra = str_replace($this->getClass(), '', $this->argument($this->argumentName));
|
||||
|
||||
$extra = str_replace('/', '\\', $extra);
|
||||
|
||||
$namespace = $this->laravel['modules']->config('namespace');
|
||||
|
||||
$namespace .= '\\'.$module->getStudlyName();
|
||||
|
||||
$namespace .= '\\'.$this->getDefaultNamespace();
|
||||
|
||||
$namespace .= '\\'.$extra;
|
||||
|
||||
$namespace = str_replace('/', '\\', $namespace);
|
||||
|
||||
return trim($namespace, '\\');
|
||||
}
|
||||
}
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
class TestMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
protected $argumentName = 'name';
|
||||
|
||||
protected $name = 'module:make-test';
|
||||
|
||||
protected $description = 'Create a new test class for the specified module.';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
if ($this->option('feature')) {
|
||||
return $module->config('paths.generator.test-feature.namespace') ?: $module->config('paths.generator.test-feature.path', 'Tests/Feature');
|
||||
}
|
||||
|
||||
return $module->config('paths.generator.test.namespace') ?: $module->config('paths.generator.test.path', 'Tests/Unit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the form request class.'],
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['feature', null, InputOption::VALUE_NONE, 'Create a feature test.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
$stub = '/unit-test.stub';
|
||||
|
||||
if ($this->option('feature')) {
|
||||
$stub = '/feature-test.stub';
|
||||
}
|
||||
|
||||
return (new Stub($stub, [
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
'CLASS' => $this->getClass(),
|
||||
]))->render();
|
||||
}
|
||||
|
||||
protected function getDestinationFilePath(): string
|
||||
{
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
|
||||
if ($this->option('feature')) {
|
||||
$testPath = GenerateConfigReader::read('test-feature');
|
||||
} else {
|
||||
$testPath = GenerateConfigReader::read('test');
|
||||
}
|
||||
|
||||
return $path.$testPath->getPath().'/'.$this->getFileName().'.php';
|
||||
}
|
||||
|
||||
private function getFileName(): string
|
||||
{
|
||||
return Str::studly($this->argument('name'));
|
||||
}
|
||||
}
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use mpba\Modules\Support\Config\GenerateConfigReader;
|
||||
use mpba\Modules\Support\Stub;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class TraitMakeCommand extends GeneratorCommand
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
protected $name = 'module:make-trait';
|
||||
|
||||
protected $description = 'Generate a trait for the specified module.';
|
||||
|
||||
protected $argumentName = 'module';
|
||||
|
||||
public function getDefaultNamespace(): string
|
||||
{
|
||||
$module = $this->laravel['modules'];
|
||||
|
||||
return $module->config('paths.generator.trait.namespace') ?: $module->config('paths.generator.trait.path', 'Traits');
|
||||
}
|
||||
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['trait', InputArgument::REQUIRED, 'The name of the trait.'],
|
||||
['module', InputArgument::REQUIRED, 'The name of module.'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTemplateContents()
|
||||
{
|
||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||
|
||||
return (new Stub($this->getStubName(), [
|
||||
'TRAITNAME' => $this->getTraitName(),
|
||||
'NAMESPACE' => $this->getClassNamespace($module),
|
||||
]))->render();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string
|
||||
*/
|
||||
protected function getTraitName()
|
||||
{
|
||||
$trait = Str::studly($this->argument('trait'));
|
||||
|
||||
if (Str::contains(strtolower($trait), 'trait') === false) {
|
||||
$trait .= 'Trait';
|
||||
}
|
||||
|
||||
return $trait;
|
||||
}
|
||||
|
||||
protected function getDestinationFilePath()
|
||||
{
|
||||
|
||||
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||
$traitPath = GenerateConfigReader::read('trait');
|
||||
|
||||
return $path.$traitPath->getPath().'/'.$this->getTraitName().'.php';
|
||||
}
|
||||
|
||||
protected function getFileName()
|
||||
{
|
||||
return 'trait';
|
||||
}
|
||||
|
||||
protected function getStubName()
|
||||
{
|
||||
return '/trait.stub';
|
||||
}
|
||||
|
||||
protected function getModuleName(): string
|
||||
{
|
||||
return $this->argument('module');
|
||||
}
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class UnUseCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:unuse';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Forget the used module with module:use';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->laravel['modules']->forgetUsed();
|
||||
|
||||
$this->info('Previous module used successfully forgotten.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use mpba\Modules\Traits\ModuleCommandTrait;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class UpdateCommand extends Command
|
||||
{
|
||||
use ModuleCommandTrait;
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:update';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Update dependencies for the specified module or for all modules.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$name = $this->argument('module');
|
||||
|
||||
if ($name) {
|
||||
$this->updateModule($name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @var \mpba\Modules\Module $module */
|
||||
foreach ($this->laravel['modules']->getOrdered() as $module) {
|
||||
$this->updateModule($module->getName());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function updateModule($name)
|
||||
{
|
||||
$this->line('Running for module: <info>'.$name.'</info>');
|
||||
|
||||
$this->laravel['modules']->update($name);
|
||||
|
||||
$this->info("Module [{$name}] updated successfully.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::OPTIONAL, 'The name of module will be updated.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class UseCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'module:use';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Use the specified module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$module = Str::studly($this->argument('module'));
|
||||
|
||||
if (! $this->laravel['modules']->has($module)) {
|
||||
$this->error("Module [{$module}] does not exists.");
|
||||
|
||||
return E_ERROR;
|
||||
}
|
||||
|
||||
$this->laravel['modules']->setUsed($module);
|
||||
|
||||
$this->info("Module [{$module}] used successfully.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['module', InputArgument::REQUIRED, 'The name of module will be used.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
Executable
Executable
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class $CLASS$ extends Command
|
||||
{
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = '$COMMAND_NAME$';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['example', InputArgument::REQUIRED, 'An example argument.'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace $CLASS_NAMESPACE$;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class $CLASS$ extends Component
|
||||
{
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// this will need to be customised for your specific needs
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|\Closure|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('$MODULE$::components.$VIEW_NAME$');
|
||||
}
|
||||
}
|
||||
Executable
+3
@@ -0,0 +1,3 @@
|
||||
<div>
|
||||
<!-- Build Someting Amazing. -->
|
||||
</div>
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "$VENDOR$/$LOWER_NAME$",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "$AUTHOR_NAME$",
|
||||
"email": "$AUTHOR_EMAIL$"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [],
|
||||
"aliases": {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\": ""
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/",
|
||||
"Modules\\$STUDLY_NAME$\\Tests\\": "modules/$STUDLY_NAME$/Tests/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace $CLASS_NAMESPACE$;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class $CLASS$ extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace $CLASS_NAMESPACE$;
|
||||
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class $CLASS$ extends Controller
|
||||
{
|
||||
}
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace $CLASS_NAMESPACE$;
|
||||
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class $CLASS$ extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('$LOWER_NAME$::index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('$LOWER_NAME$::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('$LOWER_NAME$::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('$LOWER_NAME$::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class $CLASS$
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should be broadcast on.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
|
||||
$factory->define(Model::class, function (Faker $faker) {
|
||||
return [
|
||||
//
|
||||
];
|
||||
});
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class $CLASS$ extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
use Modules\$MODULE$\Support\ModuleInfo;
|
||||
|
||||
if (! function_exists('$MODULE_LOWER$_feature_enabled')) {
|
||||
/**
|
||||
* Check if a feature is enabled in the config.
|
||||
*/
|
||||
function $MODULE_LOWER$_feature_enabled(string $key): bool
|
||||
{
|
||||
return (bool) config(ModuleInfo::nameLower().".features.{$key}", false);
|
||||
}
|
||||
}
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class $CLASS$ implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
||||
class $CLASS$ implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, Queueable;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "$STUDLY_NAME$",
|
||||
"alias": "$LOWER_NAME$",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"$MODULE_NAMESPACE$\\$STUDLY_NAME$\\$PROVIDER_NAMESPACE$\\$STUDLY_NAME$ServiceProvider"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": []
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class $CLASS$
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class $CLASS$ implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue;
|
||||
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use $EVENTNAME$;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class $CLASS$ implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue;
|
||||
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $SHORTEVENTNAME$ $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($SHORTEVENTNAME$ $event)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use $EVENTNAME$;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class $CLASS$
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $SHORTEVENTNAME$ $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($SHORTEVENTNAME$ $event)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class $CLASS$ extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->view('view.name');
|
||||
}
|
||||
}
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class $CLASS$
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class $CLASS$ extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('$TABLE$', function (Blueprint $table) {
|
||||
$FIELDS_UP$
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('$TABLE$', function (Blueprint $table) {
|
||||
$FIELDS_DOWN$
|
||||
});
|
||||
}
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class $CLASS$ extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('$TABLE$', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$FIELDS$
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('$TABLE$');
|
||||
}
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class $CLASS$ extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('$TABLE$', function (Blueprint $table) {
|
||||
$FIELDS_UP$
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('$TABLE$', function (Blueprint $table) {
|
||||
$FIELDS_DOWN$
|
||||
});
|
||||
}
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class $CLASS$ extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('$TABLE$');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::create('$TABLE$', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$FIELDS$
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class $CLASS$ extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class $CLASS$ extends Model
|
||||
{
|
||||
protected $fillable = $FILLABLE$;
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
class moduleInfo
|
||||
{
|
||||
protected static string $moduleName = '$MODULE$';
|
||||
|
||||
/**
|
||||
* defines the Module Name
|
||||
* @return string
|
||||
*/
|
||||
public static function name(): string
|
||||
{
|
||||
return static::$moduleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* define the lowercase version
|
||||
* @return string
|
||||
*/
|
||||
public static function nameLower(): string
|
||||
{
|
||||
return strtolower(static::$moduleName);
|
||||
}
|
||||
}
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class $CLASS$ extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage)
|
||||
->line('The introduction to the notification.')
|
||||
->action('Notification Action', 'https://laravel.com')
|
||||
->line('Thank you for using our application!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "npm run development",
|
||||
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
|
||||
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
|
||||
"watch-poll": "npm run watch -- --watch-poll",
|
||||
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
|
||||
"prod": "npm run production",
|
||||
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"cross-env": "^7.0",
|
||||
"laravel-mix": "^5.0.1",
|
||||
"laravel-mix-merge-manifest": "^0.1.2"
|
||||
}
|
||||
}
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class $CLASS$
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class $CLASS$ extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class $CLASS$ extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class $CLASS$ extends ResourceCollection
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class $CLASS$ extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class $CLASS$ extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The module namespace to assume when generating URLs to actions.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $moduleNamespace = '$MODULE_NAMESPACE$\$MODULE$\$CONTROLLER_NAMESPACE$';
|
||||
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapWebRoutes()
|
||||
{
|
||||
Route::middleware('web')
|
||||
->namespace($this->moduleNamespace)
|
||||
->group(module_path('$MODULE$', '$WEB_ROUTES_PATH$'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapApiRoutes()
|
||||
{
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->moduleNamespace)
|
||||
->group(module_path('$MODULE$', '$API_ROUTES_PATH$'));
|
||||
}
|
||||
}
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register API routes for your application. These
|
||||
| routes are loaded by the RouteServiceProvider within a group which
|
||||
| is assigned the "api" middleware group. Enjoy building your API!
|
||||
|
|
||||
*/
|
||||
|
||||
Route::middleware('auth:api')->get('/$LOWER_NAME$', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Web Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register web routes for your application. These
|
||||
| routes are loaded by the RouteServiceProvider within a group which
|
||||
| contains the "web" middleware group. Now create something great!
|
||||
|
|
||||
*/
|
||||
|
||||
Route::prefix('$LOWER_NAME$')->group(function() {
|
||||
Route::get('/', '$STUDLY_NAME$Controller@index');
|
||||
});
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class $CLASS$ implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'The validation error message.';
|
||||
}
|
||||
}
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => '$STUDLY_NAME$',
|
||||
'features' =>
|
||||
[
|
||||
],
|
||||
];
|
||||
Executable
+155
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Database\Eloquent\Factory;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Modules\$MODULE$\Support\ModuleInfo;
|
||||
use Config;
|
||||
|
||||
class $CLASS$ extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* @var string $moduleName
|
||||
*/
|
||||
protected string $moduleName = '$MODULE$';
|
||||
|
||||
/**
|
||||
* @var string $moduleNameLower
|
||||
*/
|
||||
protected string $moduleNameLower = '$LOWER_NAME$';
|
||||
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides():array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot() : void
|
||||
{
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->registerHelpers();
|
||||
$this->registerCommands();
|
||||
$this->loadMigrationsFrom(module_path(ModuleInfo::name(), '$MIGRATIONS_PATH$'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the helpers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerHelpers(): void
|
||||
{
|
||||
foreach (glob(__DIR__.'/../Helpers/*.php') as $filename) {
|
||||
require_once $filename;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically Register Commands.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerCommands(): void
|
||||
{
|
||||
if (!$this->app->runningInConsole()) {
|
||||
return;
|
||||
}
|
||||
$commandPath = __DIR__ . '/../Console';
|
||||
$commands = collect(File::allFiles($commandPath))
|
||||
->map(function ($file) {
|
||||
$class = 'Modules\\' . $this->moduleName . '\\Console\\' . $file->getFilenameWithoutExtension();
|
||||
return $class;
|
||||
})
|
||||
->filter(function ($class) {
|
||||
return class_exists($class);
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
$this->commands($commands);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$this->publishes([
|
||||
module_path(ModuleInfo::name(), '$PATH_CONFIG$/config.php') => config_path( ModuleInfo::nameLower(). '.php'),
|
||||
], 'config');
|
||||
$this->mergeConfigFrom(
|
||||
module_path(ModuleInfo::name(), '$PATH_CONFIG$/config.php'), ModuleInfo::nameLower()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/' . ModuleInfo::nameLower());
|
||||
$sourcePath = module_path(ModuleInfo::name(), '$PATH_VIEWS$');
|
||||
$this->publishes([
|
||||
$sourcePath => $viewPath
|
||||
], ['views', ModuleInfo::nameLower() . '-module-views']);
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), ModuleInfo::nameLower());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/' . ModuleInfo::nameLower());
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, ModuleInfo::nameLower());
|
||||
} else {
|
||||
$this->loadTranslationsFrom(module_path(ModuleInfo::name(), '$PATH_LANG$'), ModuleInfo::nameLower());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regsiter View Paths
|
||||
* @return array
|
||||
*/
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (Config::get('view.paths') as $path) {
|
||||
if (is_dir($path . '/modules/' . ModuleInfo::nameLower())) {
|
||||
$paths[] = $path . '/modules/' . ModuleInfo::nameLower();
|
||||
}
|
||||
}
|
||||
return $paths;
|
||||
}
|
||||
}
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class $NAME$ extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Model::unguard();
|
||||
|
||||
// $this->call("OthersTableSeeder");
|
||||
}
|
||||
}
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
trait $TRAITNAME$
|
||||
{
|
||||
//
|
||||
}
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace $NAMESPACE$;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class $CLASS$ extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic unit test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExample()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
@extends('$LOWER_NAME$::layouts.master')
|
||||
|
||||
@section('content')
|
||||
<h1>Hello World</h1>
|
||||
|
||||
<p>
|
||||
This view is loaded from module: {!! config('$LOWER_NAME$.name') !!}
|
||||
</p>
|
||||
@endsection
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Module $STUDLY_NAME$</title>
|
||||
|
||||
{{-- Laravel Mix - CSS File --}}
|
||||
{{-- <link rel="stylesheet" href="{{ mix('css/$LOWER_NAME$.css') }}"> --}}
|
||||
|
||||
</head>
|
||||
<body>
|
||||
@yield('content')
|
||||
|
||||
{{-- Laravel Mix - JS File --}}
|
||||
{{-- <script src="{{ mix('js/$LOWER_NAME$.js') }}"></script> --}}
|
||||
</body>
|
||||
</html>
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
const dotenvExpand = require('dotenv-expand');
|
||||
dotenvExpand(require('dotenv').config({ path: '../../.env'/*, debug: true*/}));
|
||||
|
||||
const mix = require('laravel-mix');
|
||||
|
||||
mix.js(__dirname + '/Resources/assets/js/app.js', 'js/$LOWER_NAME$.js')
|
||||
.sass( __dirname + '/Resources/assets/sass/app.scss', 'css/$LOWER_NAME$.css');
|
||||
|
||||
if (mix.inProduction()) {
|
||||
mix.version();
|
||||
}
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Contracts;
|
||||
|
||||
use mpba\Modules\Module;
|
||||
|
||||
interface ActivatorInterface
|
||||
{
|
||||
/**
|
||||
* Enables a module
|
||||
*/
|
||||
public function enable(Module $module): void;
|
||||
|
||||
/**
|
||||
* Disables a module
|
||||
*/
|
||||
public function disable(Module $module): void;
|
||||
|
||||
/**
|
||||
* Determine whether the given status same with a module status.
|
||||
*/
|
||||
public function hasStatus(Module $module, bool $status): bool;
|
||||
|
||||
/**
|
||||
* Set active state for a module.
|
||||
*/
|
||||
public function setActive(Module $module, bool $active): void;
|
||||
|
||||
/**
|
||||
* Sets a module status by its name
|
||||
*/
|
||||
public function setActiveByName(string $name, bool $active): void;
|
||||
|
||||
/**
|
||||
* Deletes a module activation status
|
||||
*/
|
||||
public function delete(Module $module): void;
|
||||
|
||||
/**
|
||||
* Deletes any module activation statuses created by this class.
|
||||
*/
|
||||
public function reset(): void;
|
||||
}
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace mpba\Modules\Contracts;
|
||||
|
||||
interface PublisherInterface
|
||||
{
|
||||
/**
|
||||
* Publish something.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function publish();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user