BaseUseCaseFileGenerator.php 1.28 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace App\Console\Commands\UseCaseCommands;

use Illuminate\Console\GeneratorCommand;

abstract class BaseUseCaseFileGenerator extends GeneratorCommand
{
    /**
     * Get the default namespace for the class.
     *
     * @param  string  $rootNamespace
     * @return string
     */
    protected function getDefaultNamespace($rootNamespace)
    {
        $namespace = $rootNamespace.'\\UseCases';
        foreach (explode('/', $this->getNameInput()) as $folder) {
            $namespace .= '\\' . $folder;
        }
        return $namespace;
    }

    /**
     * Get the full namespace for a given class, without the class name.
     *
     * @param  string  $name
     * @return string
     */
    protected function getNamespace($name)
    {
        return $this->getDefaultNamespace($this->rootNamespace());
    }

    /**
     * Replace the class name for the given stub.
     *
     * @param  string  $stub
     * @param  string  $name
     * @return string
     */
    protected function replaceClass($stub, $name)
    {
        $name = last(explode('\\', $name));
        return parent::replaceClass($stub, $name);
    }

    /**
     * Get the root namespace for the class.
     *
     * @return string
     */
    public function rootNamespace()
    {
        return 'Source';
    }
}