Skip to content

Commit 2295fb0

Browse files
author
Ashutosh Srivastva
authored
Merge pull request #32 from ashutoshwebkul/dev
Dev
2 parents 233eb02 + 1b5791e commit 2295fb0

File tree

19 files changed

+131
-67
lines changed

19 files changed

+131
-67
lines changed

Console/Command/Generate.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected function configure()
5151
);
5252
parent::configure();
5353
}
54+
5455
/**
5556
* {@inheritdoc}
5657
*/
@@ -62,18 +63,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
6263

6364
if (isset($this->validators[$data['type']])) {
6465
$data = $this->validators[$data['type']]->validate($data);
65-
$this->generate($data, $output);
66+
if ($this->generate($data, $output)){
67+
return 0;
68+
}
6669
} else {
6770
throw new \InvalidArgumentException(__("invalid type"));
6871
}
72+
exit;
6973
}
7074

7175
/**
7276
* generate code
7377
*
7478
* @param [] $data
7579
* @param Output $output
76-
* @return void
80+
* @return bool
7781
*/
7882
private function generate($data, $output)
7983
{
@@ -88,10 +92,12 @@ private function generate($data, $output)
8892
$output->writeln("<error>====> ".$response['message'].'</error>');
8993
} else {
9094
$output->writeln("<info>====> ".$response['message'].'</info>');
95+
return true;
9196
}
9297
} catch (\Exception $e) {
9398
$output->writeln("<error>====> ".$e->getMessage().'</error>');
9499
}
100+
return false;
95101
}
96102
}
97103

Model/Generate/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Command implements GenerateInterface
2222
{
2323
protected $helper;
2424

25-
protected $xmlGeneratorFactory;
25+
protected $xmlGenerator;
2626

2727
/**
2828
* Constructor

Model/Generate/Controller.php

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Webkul Software.
45
*
@@ -19,9 +20,17 @@
1920
*/
2021
class Controller implements GenerateInterface
2122
{
23+
protected $helper;
24+
25+
/**
26+
* @var \Magento\Framework\Filesystem\Driver\File
27+
*/
2228
protected $fileDriver;
2329

24-
protected $helper;
30+
/**
31+
* @var Webkul\CodeGenerator\Model\XmlGenerator
32+
*/
33+
protected $xmlGenerator;
2534

2635
public function __construct(
2736
CodeHelper $helper,
@@ -41,18 +50,18 @@ public function execute($data)
4150
$modelName = $data['name'];
4251
$path = $data['path'];
4352
$area = $data['area'];
44-
53+
4554
CodeHelper::createDirectory(
4655
$controllerPath = $path
4756
);
4857

4958
if ($area == 'frontend') {
50-
$this->createFrontController($controllerPath, $data);
59+
$this->createFrontController($controllerPath, $data);
5160
} else {
5261
$this->createAdminController($controllerPath, $data);
5362
}
5463
CodeHelper::createDirectory(
55-
$etcDirPath = $data['module_path'].DIRECTORY_SEPARATOR.'etc'.DIRECTORY_SEPARATOR.$area
64+
$etcDirPath = $data['module_path'] . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . $area
5665
);
5766
$this->createRoutesXmlFile($etcDirPath, $data);
5867

@@ -75,15 +84,15 @@ public function createFrontController($dir, $data)
7584
$nameArray = explode("_", $nameSpace);
7685
$nameSpace = implode("\\", $nameArray);
7786
$actionPath = explode("/", $pathParts[1]);
78-
79-
$nameSpace = $nameSpace."\\Controller\\".implode("\\", $actionPath);
80-
87+
88+
$nameSpace = $nameSpace . "\\Controller\\" . implode("\\", $actionPath);
89+
8190
$controllerFile = $this->helper->getTemplatesFiles('templates/controller/controller_front.php.dist');
8291
$controllerFile = str_replace('%module_name%', $data['module'], $controllerFile);
8392
$controllerFile = str_replace('%class_name%', $fileName, $controllerFile);
8493
$controllerFile = str_replace('%namespace%', $nameSpace, $controllerFile);
8594
$this->helper->saveFile(
86-
$dir.DIRECTORY_SEPARATOR.$fileName.'.php',
95+
$dir . DIRECTORY_SEPARATOR . $fileName . '.php',
8796
$controllerFile
8897
);
8998
}
@@ -99,22 +108,22 @@ public function createAdminController($dir, $data)
99108
{
100109
$fileName = ucfirst($data['name']);
101110
$nameSpace = $data['module'];
102-
$resource = $data['resource'];
111+
$resource = $data['module'] . ":" . $data['router'];
103112
$pathParts = explode("Controller/", $data['path']);
104113

105114
$nameArray = explode("_", $nameSpace);
106115
$nameSpace = implode("\\", $nameArray);
107116
$actionPath = explode("/", $pathParts[1]);
108-
109-
$nameSpace = $nameSpace."\\Controller\\Adminhtml\\".implode("\\", $actionPath);
110-
117+
118+
$nameSpace = $nameSpace . "\\Controller\\Adminhtml\\" . implode("\\", $actionPath);
119+
111120
$controllerFile = $this->helper->getTemplatesFiles('templates/controller/controller_admin.php.dist');
112121
$controllerFile = str_replace('%module_name%', $data['module'], $controllerFile);
113122
$controllerFile = str_replace('%class_name%', $fileName, $controllerFile);
114123
$controllerFile = str_replace('%namespace%', $nameSpace, $controllerFile);
115124
$controllerFile = str_replace('%resource_name%', $resource, $controllerFile);
116125
$this->helper->saveFile(
117-
$dir.DIRECTORY_SEPARATOR.$fileName.'.php',
126+
$dir . DIRECTORY_SEPARATOR . $fileName . '.php',
118127
$controllerFile
119128
);
120129
}
@@ -131,19 +140,19 @@ private function createRoutesXmlFile($etcDirPath, $data)
131140
$controllerName = $data['name'];
132141
$module = $data['module'];
133142
$area = $data['area'];
134-
143+
135144
$xmlFilePath = $this->getRoutesXmlFilePath($etcDirPath);
136145
if ($this->fileDriver->isExists($xmlFilePath)) {
137146
return true;
138147
}
139-
148+
140149
if (!isset($data['router']) || !$data['router']) {
141150
throw new \RuntimeException(
142151
__('Please provide router name')
143152
);
144153
}
145154
$routeName = $data['router'];
146-
155+
147156
$xmlData = $this->helper->getTemplatesFiles('templates/routes.xml.dist');
148157
$this->helper->saveFile($xmlFilePath, $xmlData);
149158

@@ -191,6 +200,6 @@ private function createRoutesXmlFile($etcDirPath, $data)
191200
*/
192201
private function getRoutesXmlFilePath($etcDirPath)
193202
{
194-
return $etcDirPath.DIRECTORY_SEPARATOR.'routes.xml';
203+
return $etcDirPath . DIRECTORY_SEPARATOR . 'routes.xml';
195204
}
196205
}

Model/Generate/Cron.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Cron implements GenerateInterface
2222
{
2323
protected $helper;
2424

25-
protected $xmlGeneratorFactory;
25+
protected $xmlGenerator;
2626

2727
/**
2828
* Constructor

Model/Generate/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Email implements GenerateInterface
2222
{
2323
protected $helper;
2424

25-
protected $xmlGeneratorFactory;
25+
protected $xmlGenerator;
2626

2727
/**
2828
* Constructor

Model/Generate/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Logger implements GenerateInterface
2222
{
2323
protected $helper;
2424

25-
protected $xmlGeneratorFactory;
25+
protected $xmlGenerator;
2626

2727
/**
2828
* Constructor

Model/Generate/Model.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function createApiClass($dir, $data, $columns)
125125
null,
126126
DocBlockGenerator::fromArray([
127127
'shortDescription' => 'Set '.$fieldName,
128-
'longDescription' => null,
128+
'longDescription' => "",
129129
'tags' => [
130130
new Tag\ParamTag($camelCase, [$this->helper->getReturnType($column['type'])]),
131131
new Tag\ReturnTag([
@@ -141,7 +141,7 @@ public function createApiClass($dir, $data, $columns)
141141
null,
142142
'docblock' => DocBlockGenerator::fromArray([
143143
'shortDescription' => 'Get '.$fieldName,
144-
'longDescription' => null,
144+
'longDescription' => "",
145145
'tags' => [
146146
new Tag\ReturnTag([
147147
'datatype' => $this->helper->getReturnType($column['type']),
@@ -209,7 +209,7 @@ public function createModelClass($dir, $data, $columns)
209209
'body' => '$this->_init('.$resourceClass.'::class);',
210210
'docblock' => DocBlockGenerator::fromArray([
211211
'shortDescription' => 'set resource model',
212-
'longDescription' => null,
212+
'longDescription' => "",
213213
]),
214214
]),
215215
// MethodGenerator::fromArray([
@@ -218,7 +218,7 @@ public function createModelClass($dir, $data, $columns)
218218
// 'body' => 'if ($id === null) {'. "\n". 'return $this->noRouteReasons();'. "\n". '}'. "\n". 'return parent::load($id, $field);',
219219
// 'docblock' => DocBlockGenerator::fromArray([
220220
// 'shortDescription' => 'load model',
221-
// 'longDescription' => null,
221+
// 'longDescription' => "",
222222
// 'tags' => [
223223
// new Tag\ParamTag('id', ['int']),
224224
// new Tag\ParamTag('field', ['string']),
@@ -234,7 +234,7 @@ public function createModelClass($dir, $data, $columns)
234234
'body' => 'return $this->load(self::NOROUTE_ENTITY_ID, $this->getIdFieldName());',
235235
'docblock' => DocBlockGenerator::fromArray([
236236
'shortDescription' => 'Load No-Route Indexer.',
237-
'longDescription' => null,
237+
'longDescription' => "",
238238
'tags' => [
239239
new Tag\ReturnTag([
240240
'datatype' => '$this',
@@ -248,7 +248,7 @@ public function createModelClass($dir, $data, $columns)
248248
'body' => 'return [self::CACHE_TAG.\'_\'.$this->getId()];',
249249
'docblock' => DocBlockGenerator::fromArray([
250250
'shortDescription' => 'Get identities.',
251-
'longDescription' => null,
251+
'longDescription' => "",
252252
'tags' => [
253253
new Tag\ReturnTag([
254254
'datatype' => '[]',
@@ -281,7 +281,7 @@ public function createModelClass($dir, $data, $columns)
281281
'return $this->setData(self::'.strtoupper($field).', $'.$camelCase.');',
282282
DocBlockGenerator::fromArray([
283283
'shortDescription' => 'Set '.$fieldName,
284-
'longDescription' => null,
284+
'longDescription' => "",
285285
'tags' => [
286286
new Tag\ParamTag($camelCase, [$this->helper->getReturnType($column['type'])]),
287287
new Tag\ReturnTag([
@@ -297,7 +297,7 @@ public function createModelClass($dir, $data, $columns)
297297
'return parent::getData(self::'.strtoupper($field).');',
298298
'docblock' => DocBlockGenerator::fromArray([
299299
'shortDescription' => 'Get '.$fieldName,
300-
'longDescription' => null,
300+
'longDescription' => "",
301301
'tags' => [
302302
new Tag\ReturnTag([
303303
'datatype' => $this->helper->getReturnType($column['type']),
@@ -358,7 +358,7 @@ public function createResourceModelClass($rModelDirPath, $data, $identityColumn)
358358
'body' => '$this->_init("'.$data['table'].'", "'.$identityColumn.'");',
359359
'docblock' => DocBlockGenerator::fromArray([
360360
'shortDescription' => 'Initialize resource model',
361-
'longDescription' => null,
361+
'longDescription' => "",
362362
'tags' => [
363363
new Tag\ReturnTag([
364364
'datatype' => 'void',
@@ -414,7 +414,7 @@ public function createCollectionClass($collectionDirPath, $data, $identityColumn
414414
'body' => '$this->_init("'.$modelClass.'", "'.$resourceModel.'");'."\n".'$this->_map[\'fields\'][\'entity_id\'] = \'main_table.'.$identityColumn.'\';',
415415
'docblock' => DocBlockGenerator::fromArray([
416416
'shortDescription' => 'Initialize resource model',
417-
'longDescription' => null,
417+
'longDescription' => "",
418418
'tags' => [
419419
new Tag\ReturnTag([
420420
'datatype' => 'void',

Model/Generate/NewModule.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ class NewModule implements GenerateInterface
2929

3030
protected $helper;
3131

32+
/**
33+
* @var \Magento\Framework\Module\Status
34+
*/
35+
protected $moduleStatus;
36+
37+
/**
38+
* Construct
39+
*
40+
* @param Helper $helper
41+
* @param StatusFactory $moduleStatusFactory
42+
*/
3243
public function __construct(
3344
Helper $helper,
3445
StatusFactory $moduleStatusFactory

Model/Generate/Observer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Observer implements GenerateInterface
1919
{
2020
protected $helper;
2121

22-
protected $xmlGeneratorFactory;
22+
protected $xmlGenerator;
2323
/**
2424
* Constructor
2525
*

Model/Generate/Payment.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ class Payment implements GenerateInterface
2727

2828
protected $helper;
2929

30+
/**
31+
* @var \Magento\Framework\Filesystem\Driver\File
32+
*/
33+
protected $fileDriver;
34+
35+
/**
36+
* @var \Magento\Framework\Filesystem\Io\File
37+
*/
38+
protected $file;
39+
40+
/**
41+
* @var Json
42+
*/
43+
protected $jsonHelper;
44+
45+
/**
46+
* @var Webkul\CodeGenerator\Model\XmlGenerator
47+
*/
48+
protected $xmlGenerator;
49+
3050
/**
3151
* Default xml node attributes
3252
*

0 commit comments

Comments
 (0)