for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Rawilk\LaravelModules\Commands\Generators;
use Rawilk\LaravelModules\Support\Config\GenerateConfigReader;
use Rawilk\LaravelModules\Support\Stub;
use Rawilk\LaravelModules\Traits\ModuleCommands;
class PolicyMakeCommand extends GeneratorCommand
{
use ModuleCommands;
/** @var string */
protected $argumentName = 'name';
protected $signature = 'module:make-policy
{name : The name of the policy class}
{module? : The name of the module to create the policy for}';
protected $description = 'Create a new policy class for the specified module.';
protected function getDefaultNamespace(): string
/** @var \Rawilk\LaravelModules\Contracts\Repository $module */
$module = $this->laravel['modules'];
return $module->config('paths.generator.policies.namespace') ?: $module->config('paths.generator.policies.path', 'Policies');
}
protected function getDestinationFilePath(): string
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
$policyPath = GenerateConfigReader::read('policies');
return $path . $policyPath->getPath() . '/' . $this->getFileName() . '.php';
protected function getTemplateContents(): string
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
return (new Stub('/policy.stub', [
'NAMESPACE' => $this->getClassNamespace($module),
'CLASS' => $this->getClass(),
]))->render();