Итак, я пытаюсь использовать PHP Artisan на Laravel 5.3 для создания файла класса для каждой конфигурации Cron в моем проекте, я делаю это, потому что это возможно что я захочу создать эти файлы из отдельного графического интерфейса в будущем.Команда пользовательского генератора не останавливается при создании файла, который уже существует
Я могу создать файлы, и я использую заглушки, поэтому все генерируется, как и должно быть, проблема в том, что по какой-то причине, если файл, например, «cron_4» существует, и я вызываю свой пользовательский command php artisan make:cron cron_4
это позволит мне сделать это и просто перезаписать существующий файл.
Это мой код. Какие-нибудь идеи относительно того, что я могу делать неправильно здесь?
<?php
namespace App\Console\Commands;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;
class CronMakeCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:cron';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new Cron class';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Cron';
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/stubs/cron.stub';
}
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Crons';
}
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
if (! $this->option('id')) {
return $this->error('Missing required option: --id');
}
parent::fire();
}
/**
* Replace the class name for the given stub.
*
* @param string $stub
* @param string $name
* @return string
*/
protected function replaceClass($stub, $name)
{
$stub = parent::replaceClass($stub, $name);
return str_replace('dummy:cron', 'Cron_' . $this->option('id'), $stub);
}
/**
* Determine if the class already exists.
*
* @param string $rawName
* @return bool
*/
protected function alreadyExists($rawName)
{
return class_exists($rawName);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['id', null, InputOption::VALUE_REQUIRED, 'The ID of the Cron being Generated.'],
];
}
}