Initial commit
This commit is contained in:
		
						commit
						75a8dcaa3b
					
				
							
								
								
									
										19
									
								
								composer.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								composer.json
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										26
									
								
								src/Generator.php
									
									
									
									
									
										Normal 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;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user