Skip to content

Commit

Permalink
Merge pull request #32 from ashutoshwebkul/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Ashutosh Srivastva authored Mar 29, 2023
2 parents 233eb02 + 1b5791e commit 2295fb0
Show file tree
Hide file tree
Showing 19 changed files with 131 additions and 67 deletions.
10 changes: 8 additions & 2 deletions Console/Command/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function configure()
);
parent::configure();
}

/**
* {@inheritdoc}
*/
Expand All @@ -62,18 +63,21 @@ protected function execute(InputInterface $input, OutputInterface $output)

if (isset($this->validators[$data['type']])) {
$data = $this->validators[$data['type']]->validate($data);
$this->generate($data, $output);
if ($this->generate($data, $output)){
return 0;
}
} else {
throw new \InvalidArgumentException(__("invalid type"));
}
exit;
}

/**
* generate code
*
* @param [] $data
* @param Output $output
* @return void
* @return bool
*/
private function generate($data, $output)
{
Expand All @@ -88,10 +92,12 @@ private function generate($data, $output)
$output->writeln("<error>====> ".$response['message'].'</error>');
} else {
$output->writeln("<info>====> ".$response['message'].'</info>');
return true;
}
} catch (\Exception $e) {
$output->writeln("<error>====> ".$e->getMessage().'</error>');
}
return false;
}
}

2 changes: 1 addition & 1 deletion Model/Generate/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Command implements GenerateInterface
{
protected $helper;

protected $xmlGeneratorFactory;
protected $xmlGenerator;

/**
* Constructor
Expand Down
43 changes: 26 additions & 17 deletions Model/Generate/Controller.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Webkul Software.
*
Expand All @@ -19,9 +20,17 @@
*/
class Controller implements GenerateInterface
{
protected $helper;

/**
* @var \Magento\Framework\Filesystem\Driver\File
*/
protected $fileDriver;

protected $helper;
/**
* @var Webkul\CodeGenerator\Model\XmlGenerator
*/
protected $xmlGenerator;

public function __construct(
CodeHelper $helper,
Expand All @@ -41,18 +50,18 @@ public function execute($data)
$modelName = $data['name'];
$path = $data['path'];
$area = $data['area'];

CodeHelper::createDirectory(
$controllerPath = $path
);

if ($area == 'frontend') {
$this->createFrontController($controllerPath, $data);
$this->createFrontController($controllerPath, $data);
} else {
$this->createAdminController($controllerPath, $data);
}
CodeHelper::createDirectory(
$etcDirPath = $data['module_path'].DIRECTORY_SEPARATOR.'etc'.DIRECTORY_SEPARATOR.$area
$etcDirPath = $data['module_path'] . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . $area
);
$this->createRoutesXmlFile($etcDirPath, $data);

Expand All @@ -75,15 +84,15 @@ public function createFrontController($dir, $data)
$nameArray = explode("_", $nameSpace);
$nameSpace = implode("\\", $nameArray);
$actionPath = explode("/", $pathParts[1]);
$nameSpace = $nameSpace."\\Controller\\".implode("\\", $actionPath);

$nameSpace = $nameSpace . "\\Controller\\" . implode("\\", $actionPath);

$controllerFile = $this->helper->getTemplatesFiles('templates/controller/controller_front.php.dist');
$controllerFile = str_replace('%module_name%', $data['module'], $controllerFile);
$controllerFile = str_replace('%class_name%', $fileName, $controllerFile);
$controllerFile = str_replace('%namespace%', $nameSpace, $controllerFile);
$this->helper->saveFile(
$dir.DIRECTORY_SEPARATOR.$fileName.'.php',
$dir . DIRECTORY_SEPARATOR . $fileName . '.php',
$controllerFile
);
}
Expand All @@ -99,22 +108,22 @@ public function createAdminController($dir, $data)
{
$fileName = ucfirst($data['name']);
$nameSpace = $data['module'];
$resource = $data['resource'];
$resource = $data['module'] . ":" . $data['router'];
$pathParts = explode("Controller/", $data['path']);

$nameArray = explode("_", $nameSpace);
$nameSpace = implode("\\", $nameArray);
$actionPath = explode("/", $pathParts[1]);
$nameSpace = $nameSpace."\\Controller\\Adminhtml\\".implode("\\", $actionPath);

$nameSpace = $nameSpace . "\\Controller\\Adminhtml\\" . implode("\\", $actionPath);

$controllerFile = $this->helper->getTemplatesFiles('templates/controller/controller_admin.php.dist');
$controllerFile = str_replace('%module_name%', $data['module'], $controllerFile);
$controllerFile = str_replace('%class_name%', $fileName, $controllerFile);
$controllerFile = str_replace('%namespace%', $nameSpace, $controllerFile);
$controllerFile = str_replace('%resource_name%', $resource, $controllerFile);
$this->helper->saveFile(
$dir.DIRECTORY_SEPARATOR.$fileName.'.php',
$dir . DIRECTORY_SEPARATOR . $fileName . '.php',
$controllerFile
);
}
Expand All @@ -131,19 +140,19 @@ private function createRoutesXmlFile($etcDirPath, $data)
$controllerName = $data['name'];
$module = $data['module'];
$area = $data['area'];

$xmlFilePath = $this->getRoutesXmlFilePath($etcDirPath);
if ($this->fileDriver->isExists($xmlFilePath)) {
return true;
}

if (!isset($data['router']) || !$data['router']) {
throw new \RuntimeException(
__('Please provide router name')
);
}
$routeName = $data['router'];

$xmlData = $this->helper->getTemplatesFiles('templates/routes.xml.dist');
$this->helper->saveFile($xmlFilePath, $xmlData);

Expand Down Expand Up @@ -191,6 +200,6 @@ private function createRoutesXmlFile($etcDirPath, $data)
*/
private function getRoutesXmlFilePath($etcDirPath)
{
return $etcDirPath.DIRECTORY_SEPARATOR.'routes.xml';
return $etcDirPath . DIRECTORY_SEPARATOR . 'routes.xml';
}
}
2 changes: 1 addition & 1 deletion Model/Generate/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Cron implements GenerateInterface
{
protected $helper;

protected $xmlGeneratorFactory;
protected $xmlGenerator;

/**
* Constructor
Expand Down
2 changes: 1 addition & 1 deletion Model/Generate/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Email implements GenerateInterface
{
protected $helper;

protected $xmlGeneratorFactory;
protected $xmlGenerator;

/**
* Constructor
Expand Down
2 changes: 1 addition & 1 deletion Model/Generate/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Logger implements GenerateInterface
{
protected $helper;

protected $xmlGeneratorFactory;
protected $xmlGenerator;

/**
* Constructor
Expand Down
20 changes: 10 additions & 10 deletions Model/Generate/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function createApiClass($dir, $data, $columns)
null,
DocBlockGenerator::fromArray([
'shortDescription' => 'Set '.$fieldName,
'longDescription' => null,
'longDescription' => "",
'tags' => [
new Tag\ParamTag($camelCase, [$this->helper->getReturnType($column['type'])]),
new Tag\ReturnTag([
Expand All @@ -141,7 +141,7 @@ public function createApiClass($dir, $data, $columns)
null,
'docblock' => DocBlockGenerator::fromArray([
'shortDescription' => 'Get '.$fieldName,
'longDescription' => null,
'longDescription' => "",
'tags' => [
new Tag\ReturnTag([
'datatype' => $this->helper->getReturnType($column['type']),
Expand Down Expand Up @@ -209,7 +209,7 @@ public function createModelClass($dir, $data, $columns)
'body' => '$this->_init('.$resourceClass.'::class);',
'docblock' => DocBlockGenerator::fromArray([
'shortDescription' => 'set resource model',
'longDescription' => null,
'longDescription' => "",
]),
]),
// MethodGenerator::fromArray([
Expand All @@ -218,7 +218,7 @@ public function createModelClass($dir, $data, $columns)
// 'body' => 'if ($id === null) {'. "\n". 'return $this->noRouteReasons();'. "\n". '}'. "\n". 'return parent::load($id, $field);',
// 'docblock' => DocBlockGenerator::fromArray([
// 'shortDescription' => 'load model',
// 'longDescription' => null,
// 'longDescription' => "",
// 'tags' => [
// new Tag\ParamTag('id', ['int']),
// new Tag\ParamTag('field', ['string']),
Expand All @@ -234,7 +234,7 @@ public function createModelClass($dir, $data, $columns)
'body' => 'return $this->load(self::NOROUTE_ENTITY_ID, $this->getIdFieldName());',
'docblock' => DocBlockGenerator::fromArray([
'shortDescription' => 'Load No-Route Indexer.',
'longDescription' => null,
'longDescription' => "",
'tags' => [
new Tag\ReturnTag([
'datatype' => '$this',
Expand All @@ -248,7 +248,7 @@ public function createModelClass($dir, $data, $columns)
'body' => 'return [self::CACHE_TAG.\'_\'.$this->getId()];',
'docblock' => DocBlockGenerator::fromArray([
'shortDescription' => 'Get identities.',
'longDescription' => null,
'longDescription' => "",
'tags' => [
new Tag\ReturnTag([
'datatype' => '[]',
Expand Down Expand Up @@ -281,7 +281,7 @@ public function createModelClass($dir, $data, $columns)
'return $this->setData(self::'.strtoupper($field).', $'.$camelCase.');',
DocBlockGenerator::fromArray([
'shortDescription' => 'Set '.$fieldName,
'longDescription' => null,
'longDescription' => "",
'tags' => [
new Tag\ParamTag($camelCase, [$this->helper->getReturnType($column['type'])]),
new Tag\ReturnTag([
Expand All @@ -297,7 +297,7 @@ public function createModelClass($dir, $data, $columns)
'return parent::getData(self::'.strtoupper($field).');',
'docblock' => DocBlockGenerator::fromArray([
'shortDescription' => 'Get '.$fieldName,
'longDescription' => null,
'longDescription' => "",
'tags' => [
new Tag\ReturnTag([
'datatype' => $this->helper->getReturnType($column['type']),
Expand Down Expand Up @@ -358,7 +358,7 @@ public function createResourceModelClass($rModelDirPath, $data, $identityColumn)
'body' => '$this->_init("'.$data['table'].'", "'.$identityColumn.'");',
'docblock' => DocBlockGenerator::fromArray([
'shortDescription' => 'Initialize resource model',
'longDescription' => null,
'longDescription' => "",
'tags' => [
new Tag\ReturnTag([
'datatype' => 'void',
Expand Down Expand Up @@ -414,7 +414,7 @@ public function createCollectionClass($collectionDirPath, $data, $identityColumn
'body' => '$this->_init("'.$modelClass.'", "'.$resourceModel.'");'."\n".'$this->_map[\'fields\'][\'entity_id\'] = \'main_table.'.$identityColumn.'\';',
'docblock' => DocBlockGenerator::fromArray([
'shortDescription' => 'Initialize resource model',
'longDescription' => null,
'longDescription' => "",
'tags' => [
new Tag\ReturnTag([
'datatype' => 'void',
Expand Down
11 changes: 11 additions & 0 deletions Model/Generate/NewModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class NewModule implements GenerateInterface

protected $helper;

/**
* @var \Magento\Framework\Module\Status
*/
protected $moduleStatus;

/**
* Construct
*
* @param Helper $helper
* @param StatusFactory $moduleStatusFactory
*/
public function __construct(
Helper $helper,
StatusFactory $moduleStatusFactory
Expand Down
2 changes: 1 addition & 1 deletion Model/Generate/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Observer implements GenerateInterface
{
protected $helper;

protected $xmlGeneratorFactory;
protected $xmlGenerator;
/**
* Constructor
*
Expand Down
20 changes: 20 additions & 0 deletions Model/Generate/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ class Payment implements GenerateInterface

protected $helper;

/**
* @var \Magento\Framework\Filesystem\Driver\File
*/
protected $fileDriver;

/**
* @var \Magento\Framework\Filesystem\Io\File
*/
protected $file;

/**
* @var Json
*/
protected $jsonHelper;

/**
* @var Webkul\CodeGenerator\Model\XmlGenerator
*/
protected $xmlGenerator;

/**
* Default xml node attributes
*
Expand Down
7 changes: 5 additions & 2 deletions Model/Generate/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
class Plugin implements GenerateInterface
{
protected $helper;

protected $xmlGeneratorFactory;

/**
* @var Webkul\CodeGenerator\Model\XmlGenerator
*/
protected $xmlGenerator;

/**
* Constructor
Expand Down
Loading

0 comments on commit 2295fb0

Please sign in to comment.