Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if( PHP_SAPI !== 'cli') echo 'csak konzolbol';
- define('DS', DIRECTORY_SEPARATOR);
- class Artisan {
- private $application_folder = 'application';
- private $commands = [
- 'make' => [
- 'controller' => 'controller name',
- 'model' => 'controller name',
- 'library' => 'library name',
- 'helper' => 'helper name'
- ]
- ];
- private $argv = '';
- private $types = ['controller', 'model', 'helper', 'library'];
- public function __construct($argv)
- {
- $this->argv = $argv;
- $this->index();
- }
- public function index()
- {
- if( !isset($this->argv[1]) ){
- return $this->list_commands(null);
- }elseif($this->argv[1] === 'list') {
- return $this->list_commands();
- }elseif($this->argv[1] === 'make') {
- if( !isset($this->argv[2]) ) { return $this->list_commands('make'); }
- if(!in_array($this->argv[2], $this->types)) {
- echo " I DOES NOT EXITS METHOD \r \n";
- return $this->list_commands();
- }
- $type = $this->argv[2];
- $this->$type($this->argv[3]);
- //print_r($this->argv[2]);
- }
- }
- public function list_commands($cmd)
- {
- $output = '';
- foreach($this->commands as $key => $value)
- {
- if($cmd == null) {
- $output .= " " . $key . " \r \n";
- } else if($cmd == 'make') {
- $output .= " " . $key . "\r \n";
- foreach($value as $command => $operation)
- {
- $output .= " " . $key . " " . $command . " " .$operation. " \r \n";
- }
- }
- }
- echo $output;
- }
- public function string_helper(string $string)
- {
- //$out = preg_replace('/^0/', '', $in);
- $name = strtolower($string);
- return ucfirst($name);
- }
- function controller($classname)
- {
- $classname = $this->string_helper($classname);
- $content = "<?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class $classname extends MY_Controller {
- public function __construct()
- {
- parent::__construct();
- }
- public function index()
- {
- \$this->page_title = \"\";
- \$this->css_files = array(
- );
- \$this->js_files = array(
- );
- \$view_data = array();
- \$this->view = \$this->load->view(\$this->getSide() . \"/container/\", \$view_data, true);
- parent::index();
- }
- }
- ?>";
- $dir = dirname(__FILE__) . DS . $this->application_folder . DS . 'controllers';
- file_put_contents( $dir . DS . $classname . '.php', $content);
- echo "$classname controller created";
- }
- function model($classname)
- {
- $classname = $this->string_helper($classname);
- $classname = $classname.'_model';
- $content = "<?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class $classname extends MY_Model {
- public function __construct()
- {
- parent::__construct();
- }
- public function ()
- {
- \$this->db->select();
- \$this->db->from();
- \$this->db->get()->result();
- }
- }
- ?>";
- $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->application_folder . DS . 'models';
- file_put_contents( $dir . DS . $classname . '.php', $content);
- echo "$classname controller created";
- }
- function library($classname)
- {
- $classname = $this->string_helper($classname);
- $content = "<?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class $classname {
- public \$CI;
- public function __construct()
- {
- \$this->CI =& get_instance();
- }
- public function index()
- {
- }
- }
- ?>";
- $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->application_folder . DS . 'libraries';
- file_put_contents( $dir . DS . $classname . '.php', $content);
- echo "$classname library created";
- }
- function helper($classname)
- {
- $classname = strtolower($classname);
- $content = "<?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- if ( ! function_exists('element'))
- {
- function element()
- {
- }
- }
- ?>";
- $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'application' . DS . 'helpers';
- file_put_contents( $this->application_folder . DS .'helpers' . DS . $classname . '_helper.php', $content);
- echo "$classname helper created";
- }
- }
- $args = $_SERVER['argv'];
- $artisan = new Artisan($args);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement