Initial commit

This commit is contained in:
gmotov 2025-10-08 22:39:18 +03:00
commit 75a8dcaa3b
3 changed files with 45 additions and 0 deletions

0
README.md Normal file
View File

19
composer.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "drobnitsa/dictionary-yii2-generator",
"description": "Генератор справочников для проектов",
"type": "yii2-extension",
"authors": [
{
"name": "G.M.",
"email": "gmotov@gmail.com"
}
],
"require": {
"yiisoft/yii2": "~2.0.0"
},
"autoload": {
"psr-4": {
"drobnitsa\\DictionaryYii2Generator\\": "src/"
}
}
}

26
src/Generator.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace Drobnitsa\DictionaryYii2Generator;
class Generator
{
public function generate($params = [])
{
$namespace = $params['namespace'] ?? 'app\\controllers';
$basePath = $params['basePath'] ?? \Yii::getAlias('@app');
// пример генерации файла
$filePath = $basePath . '/controllers/' . ucfirst($params['name']) . 'Controller.php';
$content = "<?php\n\nnamespace {$namespace};\n\nclass " . ucfirst($params['name']) . "Controller extends \\yii\\web\\Controller\n{\n // ...\n}\n";
// создаем файл
if (!file_exists(dirname($filePath))) {
mkdir(dirname($filePath), 0777, true);
}
file_put_contents($filePath, $content);
return $filePath;
}
}