Advertisement
koki2000

artisan 1.2

Oct 14th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.02 KB | None | 0 0
  1. <?php
  2. if( PHP_SAPI !== 'cli') echo 'csak konzolbol';
  3. define('DS', DIRECTORY_SEPARATOR);
  4.  
  5. class Artisan {
  6.     private $application_folder = 'application';
  7.    
  8.     private $commands = [
  9.         'make' => [
  10.             'controller' => 'controller name',
  11.             'model' => 'controller name',
  12.             'library' => 'library name',
  13.             'helper' => 'helper name'
  14.         ]
  15.     ];
  16.    
  17.     private $argv = '';
  18.     private $types = ['controller', 'model', 'helper', 'library'];
  19.    
  20.     public function __construct($argv)
  21.     {
  22.         $this->argv = $argv;
  23.         $this->index();
  24.        
  25.     }
  26.    
  27.     public function index()
  28.     {
  29.         if( !isset($this->argv[1]) ){
  30.             return $this->list_commands(null);
  31.         }elseif($this->argv[1] === 'list') {
  32.             return $this->list_commands();
  33.         }elseif($this->argv[1] === 'make') {
  34.             if( !isset($this->argv[2]) ) { return $this->list_commands('make'); }
  35.             if(!in_array($this->argv[2], $this->types)) {
  36.                 echo " I DOES NOT EXITS METHOD \r \n";
  37.                 return $this->list_commands();
  38.             }
  39.             $type = $this->argv[2];
  40.             $this->$type($this->argv[3]);
  41.            
  42.             //print_r($this->argv[2]);
  43.         }
  44.     }
  45.    
  46.     public function list_commands($cmd)
  47.     {
  48.         $output = '';
  49.        
  50.         foreach($this->commands as $key => $value)
  51.         {
  52.             if($cmd == null) {
  53.                 $output .=  " " . $key . " \r \n";
  54.             } else if($cmd == 'make') {
  55.                 $output .= " " . $key . "\r \n";
  56.                 foreach($value as $command => $operation)
  57.                 {
  58.                     $output .=  "  " . $key . " " . $command . " " .$operation. " \r \n";
  59.                 }
  60.             }
  61.         }
  62.         echo $output;
  63.     }
  64.    
  65.     public function string_helper(string $string)
  66.     {
  67.         //$out = preg_replace('/^0/', '', $in);
  68.         $name = strtolower($string);
  69.         return ucfirst($name);
  70.     }
  71.    
  72.     function controller($classname)
  73.     {
  74.     $classname = $this->string_helper($classname);
  75.     $content = "<?php
  76. defined('BASEPATH') OR exit('No direct script access allowed');
  77.    
  78. class $classname extends MY_Controller {
  79.     public function __construct()
  80.     {
  81.         parent::__construct();
  82.     }
  83.    
  84.     public function index()
  85.     {
  86.         \$this->page_title = \"\";
  87.        
  88.         \$this->css_files = array(
  89.         );
  90.        \$this->js_files = array(
  91.        );
  92.        
  93.         \$view_data = array();
  94.         \$this->view = \$this->load->view(\$this->getSide() . \"/container/\", \$view_data, true);
  95.         parent::index();
  96.     }
  97. }
  98. ?>";
  99.        
  100.         $dir = dirname(__FILE__) . DS . $this->application_folder . DS . 'controllers';
  101.         file_put_contents( $dir . DS . $classname . '.php', $content);
  102.         echo "$classname controller created";
  103.     }
  104.    
  105.     function model($classname)
  106.     {
  107.     $classname = $this->string_helper($classname);
  108.     $classname = $classname.'_model';
  109.     $content = "<?php
  110. defined('BASEPATH') OR exit('No direct script access allowed');
  111.    
  112. class $classname extends MY_Model {
  113.     public function __construct()
  114.     {
  115.         parent::__construct();
  116.     }
  117.    
  118.     public function ()
  119.     {
  120.         \$this->db->select();
  121.         \$this->db->from();
  122.         \$this->db->get()->result();
  123.     }
  124. }
  125. ?>";
  126.        
  127.         $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->application_folder . DS . 'models';
  128.         file_put_contents( $dir . DS . $classname . '.php', $content);
  129.         echo "$classname controller created";
  130.     }
  131.    
  132.     function library($classname)
  133.     {
  134.         $classname = $this->string_helper($classname);
  135.     $content = "<?php
  136. defined('BASEPATH') OR exit('No direct script access allowed');
  137.    
  138. class $classname {
  139.    
  140.     public \$CI;
  141.    
  142.     public function __construct()
  143.     {
  144.         \$this->CI =& get_instance();
  145.     }
  146.    
  147.     public function index()
  148.     {
  149.        
  150.     }
  151. }
  152. ?>";
  153.        
  154.         $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->application_folder . DS . 'libraries';
  155.         file_put_contents( $dir . DS . $classname . '.php', $content);
  156.         echo "$classname library created";
  157.     }
  158.    
  159.     function helper($classname)
  160.     {
  161.         $classname = strtolower($classname);
  162.     $content = "<?php
  163. defined('BASEPATH') OR exit('No direct script access allowed');
  164.    
  165. if ( ! function_exists('element'))
  166. {
  167.     function element()
  168.     {
  169.        
  170.     }
  171. }
  172. ?>";
  173.        
  174.         $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'application' . DS . 'helpers';
  175.         file_put_contents( $this->application_folder . DS .'helpers' . DS . $classname . '_helper.php', $content);
  176.         echo "$classname helper created";
  177.     }
  178.    
  179. }
  180.  
  181. $args = $_SERVER['argv'];
  182. $artisan = new Artisan($args);
  183.  
  184. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement