1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Developer\Console; |
4
|
|
|
|
5
|
|
|
use Magento\Framework\Code\Generator\InterfaceGenerator; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Zend\Code\Generator\FileGenerator; |
10
|
|
|
|
11
|
|
|
class MakeInterfaceCommand extends AbstractGeneratorCommand |
12
|
|
|
{ |
13
|
|
|
const CLASSPATH = 'classpath'; |
14
|
|
|
|
15
|
|
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
$this |
18
|
|
|
->setName('make:interface') |
19
|
|
|
->addArgument(self::CLASSPATH, InputArgument::REQUIRED) |
20
|
|
|
->setDescription('Creates a generic interface'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param InputInterface $input |
25
|
|
|
* @param OutputInterface $output |
26
|
|
|
* |
27
|
|
|
* @return int|void |
28
|
|
|
*/ |
29
|
|
|
protected function catchedExecute(InputInterface $input, OutputInterface $output) |
30
|
|
|
{ |
31
|
|
|
$classFileName = $this->getNormalizedPathByArgument($input->getArgument(self::CLASSPATH)); |
32
|
|
|
|
33
|
|
|
$classNameToGenerate = $this->getCurrentModuleNamespace() |
34
|
|
|
. '\\' |
35
|
|
|
. $this->getNormalizedClassnameByArgument($input->getArgument(self::CLASSPATH)); |
36
|
|
|
|
37
|
|
|
$filePathToGenerate = $classFileName . '.php'; |
38
|
|
|
|
39
|
|
|
/** @var $classGenerator InterfaceGenerator */ |
40
|
|
|
$classGenerator = $this->create(InterfaceGenerator::class); |
41
|
|
|
$classGenerator->setName($classNameToGenerate); |
42
|
|
|
|
43
|
|
|
$fileGenerator = FileGenerator::fromArray([ |
44
|
|
|
'classes' => [$classGenerator], |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
$directoryWriter = $this->getCurrentModuleDirectoryWriter(); |
48
|
|
|
$directoryWriter->writeFile($filePathToGenerate, $fileGenerator->generate()); |
49
|
|
|
|
50
|
|
|
$output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>'); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|