Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/Illuminate/Foundation/Console/EnumMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Concerns\CreatesMatchingTest;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'make:enum')]
class EnumMakeCommand extends GeneratorCommand
{
use CreatesMatchingTest;

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new enum';

/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'make:enum';

/**
* The type of file being generated.
*
* @var string
*/
protected $type = 'Enum';

/**
* Get the desired view name from the input.
*
* @return string
*/
protected function getNameInput()
{
$name = trim($this->argument('name'));

$name = str_replace(['\\', '.'], '/', $this->argument('name'));

return $name;
}

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return $this->resolveStubPath(
'/stubs/enum.stub',
);
}

/**
* Get the default namespace for the generator.
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Enums';
}

protected function replaceClass($stub, $name)
{
$class = str_replace($this->getNamespace($name).'\\', '', $name);

return str_replace('{{enum_name}}', $class, $stub);
}
}
8 changes: 8 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/enum.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Enums;

enum {{enum_name}}: int
{
case Example = 1;
}