diff --git a/Api/GenerateInterface.php b/Api/GenerateInterface.php
index 65a0c55..c82a849 100755
--- a/Api/GenerateInterface.php
+++ b/Api/GenerateInterface.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Api;
diff --git a/Api/ValidatorInterface.php b/Api/ValidatorInterface.php
index 09075ad..d013285 100644
--- a/Api/ValidatorInterface.php
+++ b/Api/ValidatorInterface.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Api;
diff --git a/Console/Command/Generate.php b/Console/Command/Generate.php
index c437774..9818ef9 100755
--- a/Console/Command/Generate.php
+++ b/Console/Command/Generate.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Console\Command;
@@ -859,7 +859,10 @@ public function addFormField($input, $output, $questionHelper)
}
if (!$input->getOption('field_type')) {
- $question = new Question('Enter Field Type (input/select/multiselect/imageUploader): ', 'input');
+ $question = new Question(
+ 'Enter Field Type (input/select/multiselect/imageUploader): ',
+ 'input'
+ );
$this->addNotEmptyValidator($question);
$input->setOption(
"field_type",
diff --git a/Model/Generate/Model.php b/Model/Generate/Model.php
index 536af1c..473152c 100755
--- a/Model/Generate/Model.php
+++ b/Model/Generate/Model.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Model\Generate;
@@ -17,6 +17,8 @@
use Laminas\Code\Generator\ParameterGenerator;
use Magento\Framework\Setup\Declaration\Schema\Declaration\ReaderComposite;
use Webkul\CodeGenerator\Model\Helper;
+use Magento\Framework\Simplexml\Config;
+use Webkul\CodeGenerator\Model\XmlGeneratorFactory;
/**
* Generate Model.php
@@ -38,10 +40,12 @@ class Model implements GenerateInterface
* __construct function
*
* @param ReaderComposite $readerComposite
+ * @param XmlGeneratorFactory $xmlGenerator
* @param Helper $helper
*/
public function __construct(
ReaderComposite $readerComposite,
+ protected XmlGeneratorFactory $xmlGenerator,
Helper $helper
) {
$this->readerComposite = $readerComposite;
@@ -89,10 +93,15 @@ public function execute($data)
$apiDataDirPath = $apiDataDirPath.DIRECTORY_SEPARATOR.'Data'
);
+ $this->helper->createDirectory(
+ $etcDirPath = $path.DIRECTORY_SEPARATOR.'etc'
+ );
+
$this->createApiClass($apiDataDirPath, $data, $columns);
$this->createModelClass($modelDirPath, $data, $columns);
$this->createResourceModelClass($rModelDirPath, $data, $identityColumn);
$this->createCollectionClass($collectionDirPath, $data, $identityColumn);
+ $this->addDiXmlData($etcDirPath, $data);
return ['status' => 'success', 'message' => "model generated successfully"];
}
@@ -205,8 +214,8 @@ public function createModelClass($dir, $data, $columns)
{
$moduleNamespace = explode('_', $data['module']);
$nameSpace = $moduleNamespace[0].'\\'.$moduleNamespace[1].'\\Model';
- $parentClass = "Magento\\Framework\\Model\\AbstractModel";
- $parentInterface = "Magento\\Framework\\DataObject\\IdentityInterface";
+ $parentClass = "Magento".'\\'."Framework\\Model\\AbstractModel";
+ $parentInterface = "Magento".'\\'."Framework\\DataObject\\IdentityInterface";
$apiInterface = $moduleNamespace[0].'\\'.$moduleNamespace[1].'\\Api\\Data\\'.$data['name'].'Interface';
$resourceClass = '\\'.$nameSpace.'\\ResourceModel\\'.$data['name'];
$modelClass = new ClassGenerator();
@@ -229,7 +238,8 @@ public function createModelClass($dir, $data, $columns)
// MethodGenerator::fromArray([
// 'name' => 'load',
// 'parameters' => ['id', 'field'],
- // 'body' => 'if ($id === null) {'. "\n". 'return $this->noRouteReasons();'. "\n". '}'. "\n". 'return parent::load($id, $field);',
+ // 'body' => 'if ($id === null) {'. "\n". 'return $this->noRouteReasons();'. "\n". '}'.
+ // "\n". 'return parent::load($id, $field);',
// 'docblock' => DocBlockGenerator::fromArray([
// 'shortDescription' => 'load model',
// 'longDescription' => "",
@@ -466,4 +476,29 @@ public function createCollectionClass($collectionDirPath, $data, $identityColumn
$file->generate()
);
}
+
+ /**
+ * Add di xml data
+ *
+ * @param string $etcDirPath
+ * @param array $data
+ * @return void
+ */
+ public function addDiXmlData($etcDirPath, $data)
+ {
+ $moduleName = $data['module'];
+ $data['model-class'] = str_replace('_', '\\', $moduleName).'\\'.'Model'.'\\'.$data['name'];
+ $data['api-class'] = str_replace('_', '\\', $moduleName).'\\'.'Api'.'\\'.$data['name'].'Interface';
+ $diXmlFile = $this->helper->getDiXmlFile($etcDirPath, $data);
+ $xmlObj = new Config($diXmlFile);
+ $diXml = $xmlObj->getNode();
+ $typeNode = $this->xmlGenerator->create()->addXmlNode(
+ $diXml,
+ 'preference',
+ '',
+ ['for' => $data['api-class'], 'type' => $data['model-class']]
+ );
+ $xmlData = $this->xmlGenerator->create()->formatXml($diXml->asXml());
+ $this->helper->saveFile($diXmlFile, $xmlData);
+ }
}
diff --git a/Model/Generate/Model/Validator.php b/Model/Generate/Model/Validator.php
index 9cd7aa0..0c80466 100644
--- a/Model/Generate/Model/Validator.php
+++ b/Model/Generate/Model/Validator.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Model\Generate\Model;
diff --git a/Model/Generate/Repository.php b/Model/Generate/Repository.php
index ede848d..3ac475f 100644
--- a/Model/Generate/Repository.php
+++ b/Model/Generate/Repository.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Model\Generate;
diff --git a/Model/Generate/Repository/Validator.php b/Model/Generate/Repository/Validator.php
index ca549c4..9af4322 100644
--- a/Model/Generate/Repository/Validator.php
+++ b/Model/Generate/Repository/Validator.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Model\Generate\Repository;
@@ -21,9 +21,9 @@ public function validate($data)
$module = $data['module'];
$type = $data['type'];
$name = $data['name'];
- $path = $data['path']??null;
- $modelClass = $data['model-class']??null;
- $collectionClass = $data['collection-class']??null;
+ $path = $data['path'] ?? null;
+ $modelClass = $data['model-class'] ?? null;
+ $collectionClass = $data['collection-class'] ?? null;
$response = [];
$response['type'] = $type;
if ($module) {
diff --git a/Model/GeneratorPool.php b/Model/GeneratorPool.php
index f279eae..6594065 100755
--- a/Model/GeneratorPool.php
+++ b/Model/GeneratorPool.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Model;
diff --git a/Model/Helper.php b/Model/Helper.php
index 98a64af..1336d07 100644
--- a/Model/Helper.php
+++ b/Model/Helper.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Model;
@@ -15,6 +15,16 @@
class Helper
{
+ /**
+ * __construct function
+ *
+ * @param \Magento\Framework\Filesystem\Driver\File $driverFile
+ */
+ public function __construct(
+ protected \Magento\Framework\Filesystem\Driver\File $driverFile
+ ) {
+ }
+
/**
* Save File
*
@@ -24,10 +34,7 @@ class Helper
*/
public function saveFile($path, $content)
{
- file_put_contents(
- $path,
- $content
- );
+ $this->driverFile->filePutContents($path, $content);
}
/**
@@ -46,7 +53,6 @@ public function getHeadDocBlock($moduleName)
new Tag\GenericTag('author', 'Webkul'),
new Tag\GenericTag('copyright', 'Copyright (c) Webkul Software Private Limited (https://webkul.com)'),
new Tag\LicenseTag('https://store.webkul.com/license.html', '')
-
],
]);
}
@@ -80,8 +86,8 @@ public function getReturnType($type = 'default')
*/
public function createDirectory($dirPath, $permission = 0777)
{
- if (!is_dir($dirPath)) {
- mkdir($dirPath, $permission, true);
+ if (!$this->driverFile->isDirectory($dirPath)) {
+ $this->driverFile->createDirectory($dirPath, $permission);
}
}
@@ -93,7 +99,11 @@ public function createDirectory($dirPath, $permission = 0777)
*/
public function getTemplatesFiles($template)
{
- return file_get_contents(dirname(dirname(__FILE__)). DIRECTORY_SEPARATOR. $template);
+ return $this->driverFile->fileGetContents(
+ $this->driverFile->getParentDirectory(
+ $this->driverFile->getParentDirectory(__FILE__)
+ ). DIRECTORY_SEPARATOR. $template
+ );
}
/**
@@ -108,7 +118,7 @@ public function getTemplatesFiles($template)
public function loadTemplateFile($path, $fileName, $templatePath, $replace = [])
{
$filePath = $path.DIRECTORY_SEPARATOR.$fileName;
- if (!file_exists($filePath)) {
+ if (!$this->driverFile->isExists($filePath)) {
$data = $this->getTemplatesFiles($templatePath);
if (!empty($replace) && is_array($replace)) {
foreach ($replace as $find => $value) {
diff --git a/Model/OptionsPool.php b/Model/OptionsPool.php
index 3db027a..e50dd4e 100644
--- a/Model/OptionsPool.php
+++ b/Model/OptionsPool.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
namespace Webkul\CodeGenerator\Model;
diff --git a/composer.json b/composer.json
index 5fe0f84..fe1e52e 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "webkul/code-generator",
"description": "module lets you generate models, controller, helpers in seconds so that you can focus more on application logic ",
"type": "magento2-module",
- "version": "2.0.7",
+ "version": "2.0.8",
"license": [
"proprietary"
],
diff --git a/etc/di.xml b/etc/di.xml
index 52a04e9..1b36752 100755
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -4,7 +4,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
-->
diff --git a/etc/module.xml b/etc/module.xml
index 35b0146..01ac693 100755
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -4,7 +4,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/ -->
diff --git a/registration.php b/registration.php
index 90a1da3..8ac0d2e 100755
--- a/registration.php
+++ b/registration.php
@@ -3,7 +3,7 @@
* Webkul Software.
*
* @package Webkul_CodeGenerator
- * @author Ashutosh Srivastva
+ * @author Webkul Software Pvt Ltd
*/
\Magento\Framework\Component\ComponentRegistrar::register(