BaseUseCaseFileGenerator.php 1.27 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
5
6
<?php

namespace App\Console\Commands\UseCaseCommands;

use Illuminate\Console\GeneratorCommand;

Jacob Priddy's avatar
Jacob Priddy committed
7
8
abstract class BaseUseCaseFileGenerator extends GeneratorCommand
{
Jacob Priddy's avatar
Jacob Priddy committed
9
10
11
    /**
     * Get the default namespace for the class.
     *
12
     * @param string $rootNamespace
Jacob Priddy's avatar
Jacob Priddy committed
13
14
     * @return string
     */
Jacob Priddy's avatar
Jacob Priddy committed
15
16
    protected function getDefaultNamespace($rootNamespace)
    {
17
        $namespace = $rootNamespace . '\\UseCases';
Jacob Priddy's avatar
Jacob Priddy committed
18
19
20
21
22
23
24
25
26
        foreach (explode('/', $this->getNameInput()) as $folder) {
            $namespace .= '\\' . $folder;
        }
        return $namespace;
    }

    /**
     * Get the full namespace for a given class, without the class name.
     *
27
     * @param string $name
Jacob Priddy's avatar
Jacob Priddy committed
28
29
     * @return string
     */
Jacob Priddy's avatar
Jacob Priddy committed
30
31
    protected function getNamespace($name)
    {
Jacob Priddy's avatar
Jacob Priddy committed
32
33
34
35
36
37
        return $this->getDefaultNamespace($this->rootNamespace());
    }

    /**
     * Replace the class name for the given stub.
     *
38
39
     * @param string $stub
     * @param string $name
Jacob Priddy's avatar
Jacob Priddy committed
40
41
     * @return string
     */
Jacob Priddy's avatar
Jacob Priddy committed
42
43
    protected function replaceClass($stub, $name)
    {
Jacob Priddy's avatar
Jacob Priddy committed
44
45
46
47
48
49
50
51
52
        $name = last(explode('\\', $name));
        return parent::replaceClass($stub, $name);
    }

    /**
     * Get the root namespace for the class.
     *
     * @return string
     */
Jacob Priddy's avatar
Jacob Priddy committed
53
54
    public function rootNamespace()
    {
Jacob Priddy's avatar
Jacob Priddy committed
55
56
57
        return 'Source';
    }
}