1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Developer\Console; |
4
|
|
|
|
5
|
|
|
use Magento\Framework\Code\Generator\ClassGenerator; |
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 MakeBlockCommand extends AbstractGeneratorCommand |
12
|
|
|
{ |
13
|
|
|
protected function configure() |
14
|
|
|
{ |
15
|
|
|
$this |
16
|
|
|
->setName('make:block') |
17
|
|
|
->addArgument('classpath', InputArgument::REQUIRED) |
18
|
|
|
->setDescription('Creates a generic block class'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param InputInterface $input |
23
|
|
|
* @param OutputInterface $output |
24
|
|
|
* |
25
|
|
|
* @return int|void |
26
|
|
|
*/ |
27
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
28
|
|
|
{ |
29
|
|
|
try { |
30
|
|
|
$this->createClassFile($input, $output); |
31
|
|
|
} catch (Exception $e) { |
|
|
|
|
32
|
|
|
$output->writeln('<error>' . $e->getMessage() . '</error>'); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param InputInterface $input |
38
|
|
|
* @param OutputInterface $output |
39
|
|
|
*/ |
40
|
|
|
private function createClassFile(InputInterface $input, OutputInterface $output) |
41
|
|
|
{ |
42
|
|
|
$blockFileName = $this->getNormalizedPathByArgument($input->getArgument('classpath')); |
43
|
|
|
$classNameToGenerate = $this->getCurrentModuleNamespace() |
44
|
|
|
. '\\Block\\' |
45
|
|
|
. $this->getNormalizedClassnameByArgument($input->getArgument('classpath')); |
46
|
|
|
$filePathToGenerate = 'Block/' . $blockFileName . '.php'; |
47
|
|
|
|
48
|
|
|
$classGenerator = $this->create(ClassGenerator::class); |
49
|
|
|
|
50
|
|
|
/** @var $classGenerator ClassGenerator */ |
51
|
|
|
$classGenerator->setExtendedClass('Template'); |
52
|
|
|
$classGenerator->addUse('Magento\Framework\View\Element\Template'); |
53
|
|
|
|
54
|
|
|
$classGenerator->setName($classNameToGenerate); |
55
|
|
|
|
56
|
|
|
$fileGenerator = FileGenerator::fromArray( |
57
|
|
|
[ |
58
|
|
|
'classes' => [$classGenerator], |
59
|
|
|
] |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$directoryWriter = $this->getCurrentModuleDirectoryWriter(); |
63
|
|
|
$directoryWriter->writeFile($filePathToGenerate, $fileGenerator->generate()); |
64
|
|
|
|
65
|
|
|
$output->writeln('<info>generated </info><comment>' . $filePathToGenerate . '</comment>'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.