Inheritance: extends CI_Controller
Exemple #1
0
 public static function init($args)
 {
     try {
         if (!isset($args[1])) {
             static::help();
             return;
         }
         switch ($args[1]) {
             case 'g':
             case 'generate':
                 switch ($args[2]) {
                     case 'controller':
                     case 'model':
                     case 'view':
                     case 'views':
                     case 'migration':
                         call_user_func('Oil\\Generate::' . $args[2], array_slice($args, 3));
                         break;
                     case 'scaffold':
                         call_user_func('Oil\\Scaffold::generate', array_slice($args, 3));
                         break;
                     default:
                         Generate::help();
                 }
                 break;
             case 'c':
             case 'console':
                 new Console();
             case 'r':
             case 'refine':
                 $task = isset($args[2]) ? $args[2] : null;
                 call_user_func('Oil\\Refine::run', $task, array_slice($args, 3));
                 break;
             case 'p':
             case 'package':
                 switch ($args[2]) {
                     case 'install':
                     case 'uninstall':
                         call_user_func_array('Oil\\Package::' . $args[2], array_slice($args, 3));
                         break;
                     default:
                         Package::help();
                 }
                 break;
             case '-v':
             case '--version':
                 \Cli::write('Fuel: ' . \Fuel::VERSION);
                 break;
             case 'test':
                 \Fuel::add_package('octane');
                 call_user_func('\\Fuel\\Octane\\Tests::run_' . $args[2], array_slice($args, 3));
                 break;
             default:
                 static::help();
         }
     } catch (Exception $e) {
         \Cli::write(\Cli::color('Error: ' . $e->getMessage(), 'light_red'));
         \Cli::beep();
     }
 }
 public static function generate($args, $subfolder = 'default')
 {
     $subfolder = trim($subfolder, '/');
     if (!is_dir(PKGPATH . 'oil/views/' . $subfolder)) {
         throw new Exception('The subfolder for scaffolding templates doesn\'t exist or is spelled wrong: ' . $subfolder . ' ');
     }
     // Do this first as there is the largest chance of error here
     Generate::model($args, false);
     // Go through all arguments after the first and make them into field arrays
     $fields = array();
     foreach (array_slice($args, 1) as $arg) {
         // Parse the argument for each field in a pattern of name:type[constraint]
         preg_match('/([a-z0-9_]+):([a-z0-9_]+)(\\[([0-9]+)\\])?/i', $arg, $matches);
         $fields[] = array('name' => strtolower($matches[1]), 'type' => isset($matches[2]) ? $matches[2] : 'string', 'constraint' => isset($matches[4]) ? $matches[4] : null);
     }
     $data['singular'] = $singular = strtolower(array_shift($args));
     $data['model'] = $model_name = 'Model_' . Generate::class_name($singular);
     $data['plural'] = $plural = \Inflector::pluralize($singular);
     $data['fields'] = $fields;
     $filepath = APPPATH . 'classes/controller/' . trim(str_replace(array('_', '-'), DS, $plural), DS) . '.php';
     $controller = \View::factory($subfolder . '/scaffold/controller', $data);
     $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::factory($subfolder . '/scaffold/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/view', $data)), array('name' => 'create', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/delete', $data)));
     // Write controller
     Generate::create($filepath, $controller, 'controller');
     // Create each of the views
     foreach (array('index', 'view', 'create', 'edit', '_form') as $view) {
         Generate::create(APPPATH . 'views/' . $plural . '/' . $view . '.php', \View::factory($subfolder . '/scaffold/views/' . $view, $data), 'view');
     }
     // Add the default template if it doesnt exist
     if (!file_exists($app_template = APPPATH . 'views/template.php')) {
         Generate::create($app_template, file_get_contents(PKGPATH . 'oil/views/default/template.php'), 'view');
     }
     Generate::build();
 }
Exemple #3
0
 /**
  * First function called to begin loading template
  * @param string  $template The template file to be loaded
  * @param array   $vars     Array of variables to be used in template
  * @param boolean $ajax     If true then echo the rendered template
  * @throws Exception
  * @return void
  */
 public static function load($template, $vars, $ajax = false)
 {
     //Get the location of the templates folder
     $setup['templates'] = file_get_contents(__DIR__ . '/setup.json');
     $setup['templates'] = json_decode($setup['templates']);
     $setup['templates'] = $setup['templates']->templates;
     $dir = explode('/', __DIR__);
     if ($dir[sizeof($dir) - 1] == "templator" && $dir[sizeof($dir) - 2] == "drroach" && $dir[sizeof($dir) - 3] == "vendor") {
         self::$templateLocation = dirname(dirname(dirname(__DIR__))) . $setup['templates'] . 'templates/' . $template . '.tpl';
     } else {
         self::$templateLocation = dirname(__DIR__) . '/templates/' . $template . '.tpl';
     }
     self::$definedVars = $vars;
     //Check to see if a cached file already exists
     if (Cache::cacheExists($template)) {
         $timedOut = Cache::cacheTimedOut($template);
         if (!$timedOut) {
             Cache::loadCacheFile($template, $vars);
             return;
         }
     }
     self::checkTemplateExists($template);
     $templateHtml = self::getTemplateHtml($template);
     if ($vars === null) {
         $vars = [];
     }
     extract($vars);
     include Generate::parse($templateHtml, $template);
 }
 public function createCustomName($ext)
 {
     // get the generate class
     $oGen = new Generate();
     # create a new custom name
     $newName = $oGen->randomString(20);
     self::getUser_directory();
     # the new file name with the extension and full path appended to it
     $fileName_and_path = UPLOAD_STORE_FOLDER . $newName . "." . $ext;
     # the new name with only the extension appended to it
     $fileName = $newName . "." . $ext;
     # check if the file already exist if exists call this function again
     if (file_exists($fileName_and_path)) {
         createCustomName($ext);
     } else {
         return $result = array('fileName' => $fileName, 'newName' => $newName);
     }
 }
Exemple #5
0
 public static function parseForeach($line)
 {
     $echo = FindForeach::run($line);
     if (is_array($echo)) {
         self::$inForeach = self::$line;
         self::$foreachVar = $echo['array'];
         $line = ParseForeach::run($echo);
     }
     return $line;
 }
Exemple #6
0
 public static function forge($args, $subfolder)
 {
     $default_files = array(array('source' => $subfolder . '/controllers/base.php', 'location' => 'classes/controller/base.php', 'type' => 'controller'), array('source' => $subfolder . '/controllers/admin.php', 'location' => 'classes/controller/admin.php', 'type' => 'controller'), array('source' => $subfolder . '/views/template.php', 'location' => 'views/admin/template.php', 'type' => 'views'), array('source' => 'dashboard.php', 'location' => 'views/admin/dashboard.php', 'type' => 'views'), array('source' => 'login.php', 'location' => 'views/admin/login.php', 'type' => 'views'));
     foreach ($default_files as $file) {
         if (!file_exists($content = APPPATH . $file['location'])) {
             Generate::create($content, file_get_contents(PKGPATH . 'oil/views/' . static::$view_subdir . $file['source']), $file['type']);
         }
     }
     parent::forge($args, $subfolder);
 }
Exemple #7
0
    public function generate($args)
    {
        $g = new Generate();
        $g->model($args);
        $singular = strtolower(array_shift($args));
        $model_name = ucfirst($singular);
        $plural = \Inflector::pluralize($singular);
        $filepath = APPPATH . 'classes/controller/' . $plural . '.php';
        $controller = new \View('scaffold/controller');
        $controller->name = $plural;
        $controller->model = $model_name;
        $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => '		$this->template->title = "' . ucfirst($plural) . '";
		$this->template->' . strtolower($plural) . ' = ' . $model_name . '::find(\'all\');'), array('name' => 'view', 'params' => '$id = 0', 'code' => '		$this->template->title = "' . ucfirst($plural) . '";
		$this->template->' . strtolower($singular) . ' = ' . $model_name . '::find($id);'));
        // Write controller
        if (self::write($filepath, $controller)) {
            \Cli::write('Created controller');
        }
    }
 public function deleteEntry($fid, $pid)
 {
     $rules = ['id' => 'required|integer'];
     $inputs = ['id' => $pid];
     $deleted = $this->doDelete($pid, $inputs, $rules);
     if ($deleted['status'] == 1) {
         return Redirect::to('/crm/feature/' . $fid)->withMessage(Generate::message('SUCCESS', $deleted['message']));
     }
     return Redirect::to('/crm/feature/' . $fid)->withMessage(Generate::message('FAILED', $deleted['message']));
 }
 public static function run($line)
 {
     //Check to make sure we're not in a foreach else
     if (Generate::$elseExists) {
         Generate::$elseExists = false;
         return $line['start'] . '<?php endif; ?>' . $line['end'];
     } else {
         Generate::$inForeach = 0;
         return $line['start'] . '<?php endforeach; ?>' . $line['end'];
     }
 }
Exemple #10
0
 public static function run($line)
 {
     if (Generate::$inForeach && Generate::$inForeach > Generate::$inIf) {
         Generate::$elseExists = true;
         //Foreach else
         return $line['start'] . '<?php endforeach; if(empty($' . Generate::$foreachVar . ')) : ?>' . $line['end'];
     }
     if (Generate::$inIf && Generate::$inIf > Generate::$inForeach) {
         //If else
         return $line['start'] . '<?php else : ?>' . $line['end'];
     }
 }
Exemple #11
0
 public static function forge($args, $subfolder)
 {
     $default_files = array(array('source' => $subfolder . '/controllers/base.php', 'location' => 'classes/controller/base.php', 'type' => 'controller'), array('source' => $subfolder . '/controllers/admin.php', 'location' => 'classes/controller/admin.php', 'type' => 'controller'), array('source' => '/template.php', 'location' => 'views/admin/template.php', 'type' => 'views'), array('source' => 'dashboard.php', 'location' => 'views/admin/dashboard.php', 'type' => 'views'), array('source' => 'login.php', 'location' => 'views/admin/login.php', 'type' => 'views'));
     foreach ($default_files as $file) {
         // check if there's a template in app, and if so, use that
         if (is_file(APPPATH . 'views/' . static::$view_subdir . $file['source'])) {
             Generate::create(APPPATH . $file['location'], file_get_contents(APPPATH . 'views/' . static::$view_subdir . $file['source']), $file['type']);
         } else {
             Generate::create(APPPATH . $file['location'], file_get_contents(\Package::exists('oil') . 'views/' . static::$view_subdir . $file['source']), $file['type']);
         }
     }
     parent::forge($args, $subfolder);
 }
Exemple #12
0
 public function generate($args, $subfolder = 'default')
 {
     $subfolder = trim($subfolder, '/');
     if (!is_dir(PKGPATH . 'oil/views/' . $subfolder)) {
         throw new Exception('The subfolder for scaffolding templates doesn\'t exist or is spelled wrong: ' . $subfolder . ' ');
     }
     // Do this first as there is the largest chance of error here
     Generate::model($args);
     // Go through all arguments after the first and make them into field arrays
     $fields = array();
     foreach (array_slice($args, 1) as $arg) {
         // Parse the argument for each field in a pattern of name:type[constraint]
         preg_match('/([a-z0-9_]+):([a-z0-9_]+)(\\[([0-9]+)\\])?/i', $arg, $matches);
         $fields[] = array('name' => strtolower($matches[1]), 'type' => $matches[2], 'constraint' => isset($matches[4]) ? $matches[4] : null);
     }
     $data['singular'] = $singular = strtolower(array_shift($args));
     $data['model'] = $model_name = 'Model_' . ucfirst($singular);
     $data['plural'] = $plural = \Inflector::pluralize($singular);
     $data['fields'] = $fields;
     $filepath = APPPATH . 'classes/controller/' . $plural . '.php';
     $controller = \View::factory($subfolder . '/scaffold/controller', $data);
     $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::factory($subfolder . '/scaffold/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/view', $data)), array('name' => 'create', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/delete', $data)));
     // Write controller
     if (self::write($filepath, $controller)) {
         \Cli::write('Created controller: ' . \Fuel::clean_path($filepath));
     }
     // Add the default template if it doesnt exist
     if (!file_exists($app_template = APPPATH . 'views/template.php')) {
         copy(PKGPATH . 'oil/views/' . $subfolder . '/template.php', $app_template);
         chmod($app_template, 0666);
     }
     // Create view folder if not already there
     if (!is_dir($view_folder = APPPATH . 'views/' . $plural . '/')) {
         mkdir(APPPATH . 'views/' . $plural, 0755);
     }
     // Create each of the views
     foreach (array('index', 'view', 'create', 'edit', '_form') as $view) {
         static::write($view_file = $view_folder . $view . '.php', \View::factory($subfolder . '/scaffold/views/' . $view, $data));
         \Cli::write('Created view: ' . \Fuel::clean_path($view_file));
     }
 }
Exemple #13
0
 public static function init($args)
 {
     // Remove flag options from the main argument list
     $args = self::_clear_args($args);
     try {
         if (!isset($args[1])) {
             if (\Cli::option('v', \Cli::option('version'))) {
                 \Cli::write('Fuel: ' . \Fuel::VERSION);
                 return;
             }
             static::help();
             return;
         }
         switch ($args[1]) {
             case 'g':
             case 'generate':
                 $action = isset($args[2]) ? $args[2] : 'help';
                 $subfolder = 'orm';
                 if (is_int(strpos($action, '/'))) {
                     list($action, $subfolder) = explode('/', $action);
                 }
                 switch ($action) {
                     case 'config':
                     case 'controller':
                     case 'model':
                     case 'migration':
                         call_user_func('Oil\\Generate::' . $action, array_slice($args, 3));
                         break;
                     case 'views':
                         call_user_func('Oil\\Generate::views', array_slice($args, 3), $subfolder);
                         break;
                     case 'admin':
                         call_user_func('Oil\\Generate_Admin::forge', array_slice($args, 3), $subfolder);
                         break;
                     case 'scaffold':
                         call_user_func('Oil\\Generate_Scaffold::forge', array_slice($args, 3), $subfolder);
                         break;
                     default:
                         Generate::help();
                 }
                 break;
             case 'c':
             case 'console':
                 new Console();
             case 'r':
             case 'refine':
                 // Developers of third-party tasks may not be displaying PHP errors. Report any error and quit
                 set_error_handler(function ($errno, $errstr, $errfile, $errline) {
                     if (!error_reporting()) {
                         return;
                     }
                     // If the error was supressed with an @ then we ignore it!
                     \Cli::error("Error: {$errstr} in {$errfile} on {$errline}");
                     \Cli::beep();
                     exit;
                 });
                 $task = isset($args[2]) ? $args[2] : null;
                 call_user_func('Oil\\Refine::run', $task, array_slice($args, 3));
                 break;
             case 'cell':
             case 'cells':
                 $action = isset($args[2]) ? $args[2] : 'help';
                 switch ($action) {
                     case 'list':
                         call_user_func('Oil\\Cell::all');
                         break;
                     case 'search':
                     case 'install':
                     case 'upgrade':
                     case 'uninstall':
                         call_user_func_array('Oil\\Cell::' . $action, array_slice($args, 3));
                         break;
                     case 'info':
                     case 'details':
                         call_user_func_array('Oil\\Cell::info', array_slice($args, 3));
                         break;
                     default:
                         Cell::help();
                 }
                 break;
             case 't':
             case 'test':
                 // Suppressing this because if the file does not exist... well thats a bad thing and we can't really check
                 // I know that supressing errors is bad, but if you're going to complain: shut up. - Phil
                 @(include_once 'PHPUnit/Autoload.php');
                 // Attempt to load PHUnit.  If it fails, we are done.
                 if (!class_exists('PHPUnit_Framework_TestCase')) {
                     throw new Exception('PHPUnit does not appear to be installed.' . PHP_EOL . PHP_EOL . "\tPlease visit http://phpunit.de and install.");
                 }
                 // CD to the root of Fuel and call up phpunit with a path to our config
                 $command = 'cd ' . DOCROOT . '; phpunit -c "' . COREPATH . 'phpunit.xml"';
                 // Respect the group option
                 \Cli::option('group') and $command .= ' --group ' . \Cli::option('group');
                 // Respect the coverage-html option
                 \Cli::option('coverage-html') and $command .= ' --coverage-html ' . \Cli::option('coverage-html');
                 \Cli::write('Tests Running...This may take a few moments.', 'green');
                 foreach (explode(';', $command) as $c) {
                     passthru($c);
                 }
                 break;
             default:
                 static::help();
         }
     } catch (Exception $e) {
         \Cli::error('Error: ' . $e->getMessage());
         \Cli::beep();
         \Cli::option('speak') and `say --voice="Trinoids" "{$e->getMessage()}"`;
     }
 }
Exemple #14
0
 private function generate_controller()
 {
     $action = $this->input->post('action');
     if ($action == 'controller') {
         require CORE_DIR . 'generate.php';
         $generate = new Generate();
         $name = $this->input->post('name');
         $genview = $this->input->post('genview');
         $subdir = $this->input->post('subdir');
         $options = array('name' => ucfirst($name), 'view' => ($subdir ? $subdir . '/' : '') . strtolower($name), 'genview' => $genview ? true : false, 'subdir' => $subdir);
         if ($generate->controller($name, $options)) {
             $this->session->set('result', 'The controller ' . strtolower($name) . '.php was created successfully.');
             redirect('admin');
         } else {
             redirect('admin/controller');
         }
     } else {
         if ($action == 'display') {
             $name = $this->input->post('name');
             $data = array('name' => $name, 'title' => 'Generate Controller');
             $template = $this->load->view('admin/controller');
             $template->render($data);
         }
     }
 }
 public function indexAction()
 {
     $generator = new Generate();
     $generator->run();
 }
Exemple #16
0
	public static function init($args)
	{
		if ( ! isset($args[1]))
		{
			static::help();
			return;
		}

		switch ($args[1])
		{
			case 'g':
			case 'generate':

				switch ($args[2])
				{
					case 'controller':
					case 'model':
					case 'view':
					case 'views':
					case 'migration':

						call_user_func('Oil\Generate::'.$args[2], array_slice($args, 3));

					break;

					case 'scaffold':
						call_user_func('Oil\Scaffold::generate', array_slice($args, 3));
					break;

					default:
						Generate::help();
				}
			break;

			case 'c':
			case 'console':
				new Console;

			case 'r':
			case 'refine':

				if ( ! isset($args[2]) OR $args[2] == 'help')
				{
					Refine::help();
					return;
				}

				call_user_func('Oil\Refine::run', $args[2], array_slice($args, 3));
			break;

			case 'install':
			case 'uninstall':
				call_user_func('Oil\Package::'.$args[1], $args[2]);
			break;

			case '-v':
			case '--version':
				\Cli::write('Fuel: ' . \Fuel::VERSION);
			break;

			case 'test':
				\Fuel::add_package('octane');
				call_user_func('\\Fuel\\Octane\\Tests::run_'.$args[2], array_slice($args, 3));
			break;

			default:
				static::help();
		}
	}
Exemple #17
0
 public static function run($line)
 {
     //Create variables
     $echo = Generate::echoParseExpr($line['statement']);
     return $line['start'] . '<?php if(' . $echo . '): ?>' . $line['end'];
 }
Exemple #18
0
 public static function run($line)
 {
     Generate::$inIf = 0;
     return $line['start'] . '<?php endif; ?>' . $line['end'];
 }
            }
        } else {
            trigger_error("Permission denied");
        }
    }
    /**
     * @param array  $lines
     */
    public function createGoogleExclude(array $lines)
    {
        $file = __DIR__ . '/../google-exclude.txt';
        $reqexLines = [];
        foreach ($lines as $line) {
            $reqexLines[] = preg_quote($line);
        }
        $data = implode('|', $reqexLines);
        if (is_readable($file) && is_writable($file)) {
            file_put_contents($file, $data);
        } else {
            trigger_error("Permission denied");
        }
    }
}
date_default_timezone_set('UTC');
$date = date('Y-m-d H:i:s');
$generator = new Generate();
require __DIR__ . '/vendor/autoload.php';
$lines = $generator->domainWorker();
$generator->createApache($date, $lines);
$generator->createNginx($date, $lines);
$generator->createGoogleExclude($lines);
Exemple #20
0
 /**
  * GenerateItau constructor.
  * @param $pathfolder
  */
 public function __construct($pathfolder = false)
 {
     parent::__construct($pathfolder, '341');
 }
Exemple #21
0
 public static function run($line)
 {
     $echo = Generate::echoParseExpr($line['expr']);
     return $line['start'] . '<?php while(' . $echo . '): ?>' . $line['end'];
 }
        fclose($handle);
        $data .= "</IfModule>\n\n# Apache 2.2\n<IfModule !mod_authz_core.c>\n    <IfModule mod_authz_host.c>\n        Order allow,deny\n        Allow from all\n        Deny from env=spambot\n    </IfModule>\n</IfModule>\n\n# Apache 2.4\n<IfModule mod_authz_core.c>\n    <RequireAll>\n        Require all granted\n        Require not env spambot\n    </RequireAll>\n</IfModule>";
        // Write the contents back to the
        file_put_contents($file, $data);
    }
    public function createNginx()
    {
        date_default_timezone_set('UTC');
        $date = date('Y-m-d H:i:s');
        $file = '../referral-spam.conf';
        $data = "# https://github.com/Stevie-Ray/apache-nginx-referral-spam-blacklist\n# Updated " . $date . "\n#\n# /etc/nginx/referral-spam.conf\n#\n# With referral-spam.conf in /etc/nginx, include it globally from within /etc/nginx/nginx.conf:\n#\n#     include referral-spam.conf;\n#\n# Add the following to each /etc/nginx/site-available/your-site.conf that needs protection:\n#\n#     server {\n#       if (\$bad_referer) {\n#         return 444;\n#       }\n#     }\n#\nmap \$http_referer \$bad_referer {\n    default 0;\n\n";
        $handle = fopen(__DIR__ . "/domains.txt", "r");
        if (!$handle) {
            throw new \RuntimeException('Error opening file domains.txt');
        }
        while (($line = fgets($handle)) !== false) {
            $line = preg_quote(trim(preg_replace('/\\s\\s+/', ' ', $line)));
            if (empty($line)) {
                continue;
            }
            $data .= "\t\"~*" . $line . "\" 1;\n";
        }
        fclose($handle);
        $data .= "\n}";
        // Write the contents back to the
        file_put_contents($file, $data);
    }
}
$generator = new Generate();
$generator->createApache();
$generator->createNginx();
Exemple #23
0
 /**
  * Forge
  *
  * @param   array   Fields mainly
  * @param   string  Subfolder (or admin "theme") where views are held
  * @return	mixed
  */
 public static function forge($args, $subfolder)
 {
     $data = array();
     $subfolder = trim($subfolder, '/');
     if (!is_dir(\Package::exists('oil') . 'views/' . static::$view_subdir . $subfolder)) {
         throw new Exception('The subfolder for admin templates does not exist or is spelled wrong: ' . $subfolder . ' ');
     }
     // Go through all arguments after the first and make them into field arrays
     $data['fields'] = array();
     foreach (array_slice($args, 1) as $arg) {
         // Parse the argument for each field in a pattern of name:type[constraint]
         preg_match(static::$fields_regex, $arg, $matches);
         if (!isset($matches[1])) {
             throw new Exception('One or more fields were badly specified. Ensure they are name:type');
         }
         $data['fields'][] = array('name' => \Str::lower($matches[1]), 'type' => isset($matches[2]) ? $matches[2] : 'string', 'constraint' => isset($matches[4]) ? $matches[4] : null);
     }
     $name = array_shift($args);
     // Replace / with _ and classify the rest. DO NOT singularize
     $controller_name = \Inflector::classify(static::$controller_prefix . str_replace(DS, '_', $name), false);
     // Replace / with _ and classify the rest. Singularize
     $model_name = \Inflector::classify(static::$model_prefix . str_replace(DS, '_', $name), !\Cli::option('singular'));
     // Either foo or folder/foo
     $view_path = $controller_path = str_replace(array('_', '-'), DS, \Str::lower($controller_name));
     // Models are always singular, tough!
     $model_path = str_replace(array('_', '-'), DS, \Str::lower($model_name));
     // uri's have forward slashes, DS is a backslash on Windows
     $uri = str_replace(DS, '/', $controller_path);
     $data['include_timestamps'] = !\Cli::option('no-timestamp', false);
     // If a folder is used, the entity is the last part
     $name_parts = explode(DS, $name);
     $data['singular_name'] = \Cli::option('singular') ? end($name_parts) : \Inflector::singularize(end($name_parts));
     $data['plural_name'] = \Cli::option('singular') ? $data['singular_name'] : \Inflector::pluralize($data['singular_name']);
     $data['table'] = \Inflector::tableize($model_name);
     $data['controller_parent'] = static::$controller_parent;
     /** Generate the Migration **/
     $migration_args = $args;
     // add timestamps to the table if needded
     if ($data['include_timestamps']) {
         if (\Cli::option('mysql-timestamp', false)) {
             $migration_args[] = 'created_at:date:null[1]';
             $migration_args[] = 'updated_at:date:null[1]';
         } else {
             $migration_args[] = 'created_at:int:null[1]';
             $migration_args[] = 'updated_at:int:null[1]';
         }
     }
     $migration_name = \Cli::option('singular') ? \Str::lower($name) : \Inflector::pluralize(\Str::lower($name));
     array_unshift($migration_args, 'create_' . $migration_name);
     Generate::migration($migration_args, false);
     // Merge some other data in
     $data = array_merge(compact(array('controller_name', 'model_name', 'model_path', 'view_path', 'uri')), $data);
     /** Generate the Model **/
     $model = \View::forge(static::$view_subdir . $subfolder . '/model', $data);
     Generate::create(APPPATH . 'classes/model/' . $model_path . '.php', $model, 'model');
     /** Generate the Controller **/
     $controller = \View::forge(static::$view_subdir . $subfolder . '/controller', $data);
     $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/view', $data)), array('name' => 'create', 'params' => '', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/delete', $data)));
     Generate::create(APPPATH . 'classes/controller/' . $controller_path . '.php', $controller, 'controller');
     // Create each of the views
     foreach (array('index', 'view', 'create', 'edit', '_form') as $view) {
         Generate::create(APPPATH . 'views/' . $controller_path . '/' . $view . '.php', \View::forge(static::$view_subdir . $subfolder . '/views/actions/' . $view, $data), 'view');
     }
     // Add the default template if it doesnt exist
     if (!file_exists($app_template = APPPATH . 'views/template.php')) {
         // check if there's a template in app, and if so, use that
         if (file_exists(APPPATH . 'views/' . static::$view_subdir . $subfolder . '/views/template.php')) {
             Generate::create($app_template, file_get_contents(APPPATH . 'views/' . static::$view_subdir . $subfolder . '/views/template.php'), 'view');
         } else {
             Generate::create($app_template, file_get_contents(\Package::exists('oil') . 'views/' . static::$view_subdir . 'template.php'), 'view');
         }
     }
     Generate::build();
 }
Exemple #24
0
    public static function init($args)
    {
        \Config::load('oil', true);
        // Remove flag options from the main argument list
        $args = self::_clear_args($args);
        try {
            if (!isset($args[1])) {
                if (\Cli::option('v', \Cli::option('version'))) {
                    \Cli::write('Fuel: ' . \Fuel::VERSION . ' running in "' . \Fuel::$env . '" mode');
                    return;
                }
                static::help();
                return;
            }
            switch ($args[1]) {
                case 'g':
                case 'generate':
                    $action = isset($args[2]) ? $args[2] : 'help';
                    $subfolder = 'orm';
                    if (is_int(strpos($action, '/'))) {
                        list($action, $subfolder) = explode('/', $action);
                    }
                    switch ($action) {
                        case 'config':
                        case 'controller':
                        case 'model':
                        case 'module':
                        case 'migration':
                        case 'task':
                        case 'package':
                            call_user_func('Oil\\Generate::' . $action, array_slice($args, 3));
                            break;
                        case 'views':
                            call_user_func('Oil\\Generate::views', array_slice($args, 3), $subfolder);
                            break;
                        case 'admin':
                            call_user_func('Oil\\Generate_Admin::forge', array_slice($args, 3), $subfolder);
                            break;
                        case 'scaffold':
                            call_user_func('Oil\\Generate_Scaffold::forge', array_slice($args, 3), $subfolder);
                            break;
                        default:
                            Generate::help();
                    }
                    break;
                case 'c':
                case 'console':
                    if (isset($args[2]) and $args[2] == 'help') {
                        Console::help();
                    } else {
                        new Console();
                    }
                    break;
                case 'p':
                case 'package':
                    $action = isset($args[2]) ? $args[2] : 'help';
                    switch ($action) {
                        case 'install':
                        case 'uninstall':
                            call_fuel_func_array('Oil\\Package::' . $action, array_slice($args, 3));
                            break;
                        default:
                            Package::help();
                    }
                    break;
                case 'r':
                case 'refine':
                    $task = isset($args[2]) ? $args[2] : null;
                    call_user_func('Oil\\Refine::run', $task, array_slice($args, 3));
                    break;
                case 'cell':
                case 'cells':
                    $action = isset($args[2]) ? $args[2] : 'help';
                    switch ($action) {
                        case 'list':
                            call_user_func('Oil\\Cell::all');
                            break;
                        case 'search':
                        case 'install':
                        case 'upgrade':
                        case 'uninstall':
                            call_fuel_func_array('Oil\\Cell::' . $action, array_slice($args, 3));
                            break;
                        case 'info':
                        case 'details':
                            call_fuel_func_array('Oil\\Cell::info', array_slice($args, 3));
                            break;
                        default:
                            Cell::help();
                    }
                    break;
                case 't':
                case 'test':
                    if (isset($args[2]) and $args[2] == 'help') {
                        $output = <<<HELP

Usage:
  php oil [t|test]

Runtime options:
  --file=<file>              # Run a test on a specific file only.
  --group=<group>            # Only runs tests from the specified group(s).
  --exclude-group=<group>    # Exclude tests from the specified group(s).
  --testsuite=<testsuite>    # Only runs tests from the specified testsuite(s).
  --coverage-clover=<file>   # Generate code coverage report in Clover XML format.
  --coverage-html=<dir>      # Generate code coverage report in HTML format.
  --coverage-php=<file>      # Serialize PHP_CodeCoverage object to file.
  --coverage-text=<file>     # Generate code coverage report in text format.
  --log-junit=<file>         # Generate report of test execution in JUnit XML format to file.
  --debug                    # Display debugging information during test execution.

Description:
  Run phpunit on all or a subset of tests defined for the current application.

Examples:
  php oil test

Documentation:
  http://fuelphp.com/docs/packages/oil/test.html
HELP;
                        \Cli::write($output);
                    } else {
                        $phpunit_command = \Config::get('oil.phpunit.binary_path', 'phpunit');
                        // Check if we might be using the phar library
                        $is_phar = false;
                        foreach (explode(':', getenv('PATH')) as $path) {
                            if (is_file($path . DS . $phpunit_command)) {
                                $handle = fopen($path . DS . $phpunit_command, 'r');
                                $is_phar = fread($handle, 18) == '#!/usr/bin/env php';
                                fclose($handle);
                                if ($is_phar) {
                                    break;
                                }
                            }
                        }
                        // Suppressing this because if the file does not exist... well thats a bad thing and we can't really check
                        // I know that supressing errors is bad, but if you're going to complain: shut up. - Phil
                        $phpunit_autoload_path = \Config::get('oil.phpunit.autoload_path', 'PHPUnit/Autoload.php');
                        @(include_once $phpunit_autoload_path);
                        // Attempt to load PHUnit.  If it fails, we are done.
                        if (!$is_phar and !class_exists('PHPUnit_Framework_TestCase')) {
                            throw new Exception('PHPUnit does not appear to be installed.' . PHP_EOL . PHP_EOL . "\tPlease visit http://phpunit.de and install.");
                        }
                        // Check for a custom phpunit config, but default to the one from core
                        if (is_file(APPPATH . 'phpunit.xml')) {
                            $phpunit_config = APPPATH . 'phpunit.xml';
                        } else {
                            $phpunit_config = COREPATH . 'phpunit.xml';
                        }
                        // CD to the root of Fuel and call up phpunit with the path to our config
                        $command = 'cd ' . DOCROOT . '; ' . $phpunit_command . ' -c "' . $phpunit_config . '"';
                        // Respect the group options
                        \Cli::option('group') and $command .= ' --group ' . \Cli::option('group');
                        \Cli::option('exclude-group') and $command .= ' --exclude-group ' . \Cli::option('exclude-group');
                        // Respect the testsuite options
                        \Cli::option('testsuite') and $command .= ' --testsuite ' . \Cli::option('testsuite');
                        // Respect the debug options
                        \Cli::option('debug') and $command .= ' --debug';
                        // Respect the coverage-html option
                        \Cli::option('coverage-html') and $command .= ' --coverage-html ' . \Cli::option('coverage-html');
                        \Cli::option('coverage-clover') and $command .= ' --coverage-clover ' . \Cli::option('coverage-clover');
                        \Cli::option('coverage-text') and $command .= ' --coverage-text=' . \Cli::option('coverage-text');
                        \Cli::option('coverage-php') and $command .= ' --coverage-php ' . \Cli::option('coverage-php');
                        \Cli::option('log-junit') and $command .= ' --log-junit ' . \Cli::option('log-junit');
                        \Cli::option('file') and $command .= ' ' . \Cli::option('file');
                        \Cli::write('Tests Running...This may take a few moments.', 'green');
                        $return_code = 0;
                        foreach (explode(';', $command) as $c) {
                            passthru($c, $return_code_task);
                            // Return failure if any subtask fails
                            $return_code |= $return_code_task;
                        }
                        exit($return_code);
                    }
                    break;
                case 's':
                case 'server':
                    if (isset($args[2]) and $args[2] == 'help') {
                        $output = <<<HELP

Usage:
  php oil [s|server]

Runtime options:
  --php=<file>               # The full pathname of your PHP-CLI binary if it's not in the path.
  --port=<port>              # TCP port number the webserver should listen too. Defaults to 8000.
  --host=<host>              # Hostname the webserver should run at. Defaults to "localhost".
  --docroot=<dir>            # Your FuelPHP docroot. Defaults to "public".
  --router=<file>            # PHP router script. Defaults to "fuel/packages/oil/phpserver.php".

Description:
  Starts a local webserver to run your FuelPHP application, using PHP 5.4+ internal webserver.

Examples:
  php oil server -p=8080

Documentation:
  http://fuelphp.com/docs/packages/oil/server.html
HELP;
                        \Cli::write($output);
                    } else {
                        if (version_compare(PHP_VERSION, '5.4.0') < 0) {
                            \Cli::write('The PHP built-in webserver is only available on PHP 5.4+', 'red');
                            break;
                        }
                        $php = \Cli::option('php', 'php');
                        $port = \Cli::option('p', \Cli::option('port', '8000'));
                        $host = \Cli::option('h', \Cli::option('host', 'localhost'));
                        $docroot = \Cli::option('d', \Cli::option('docroot', 'public'));
                        $router = \Cli::option('r', \Cli::option('router', __DIR__ . DS . '..' . DS . 'phpserver.php'));
                        \Cli::write("Listening on http://{$host}:{$port}");
                        \Cli::write("Document root is {$docroot}");
                        \Cli::write("Press Ctrl-C to quit.");
                        passthru("{$php} -S {$host}:{$port} -t {$docroot} {$router}");
                    }
                    break;
                case 'create':
                    \Cli::write('You can not use "oil create", a valid FuelPHP installation already exists in this directory', 'red');
                    break;
                default:
                    static::help();
            }
        } catch (\Exception $e) {
            static::print_exception($e);
            exit(1);
        }
    }
 public function testGetUpperCaseLowerCaseLengthOfEight()
 {
     $string = Generate::randomString('uppercase', 8);
     $this->assertEquals(8, strlen($string));
     $this->assertEquals(1, preg_match('/^[a-zA-Z]/', $string));
 }
    /**
     * @param string $date
     * @param array $lines
     */
    public function createIIS($date, array $lines)
    {
        $file = __DIR__ . '/../web.config';
        $data = "<!-- " . $this->projectUrl . " -->\n<!-- Updated " . $date . " -->\n" . "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<configuration>\n\t<system.webServer>\n\t\t<rewrite>\n\t\t\t<rules>\n";
        foreach ($lines as $line) {
            $data .= "\t\t\t\t<rule name=\"Referrer Spam " . $line . "\" stopProcessing=\"true\">" . "<match url=\".*\" /><conditions><add input=\"{HTTP_REFERER}\" pattern=\"(" . preg_quote($line) . ")\"/></conditions><action type=\"AbortRequest\" /></rule>\n";
        }
        $data .= "\t\t\t</rules>\n\t\t</rewrite>\n\t</system.webServer>\n</configuration>";
        $this->writeToFile($file, $data);
    }
    /**
     * @param array $lines
     */
    public function createGoogleExclude(array $lines)
    {
        $file = __DIR__ . '/../google-exclude.txt';
        $regexLines = [];
        foreach ($lines as $line) {
            $regexLines[] = preg_quote($line);
        }
        $data = implode('|', $regexLines);
        $this->writeToFile($file, $data);
    }
}
require __DIR__ . '/vendor/autoload.php';
$generator = new Generate();
$generator->generateFiles();
Exemple #27
0
 public static function init($args)
 {
     \Config::load('oil', true);
     // Remove flag options from the main argument list
     $args = self::_clear_args($args);
     try {
         if (!isset($args[1])) {
             if (\Cli::option('v', \Cli::option('version'))) {
                 \Cli::write('Fuel: ' . \Fuel::VERSION . ' running in "' . \Fuel::$env . '" mode');
                 return;
             }
             static::help();
             return;
         }
         switch ($args[1]) {
             case 'g':
             case 'generate':
                 $action = isset($args[2]) ? $args[2] : 'help';
                 $subfolder = 'orm';
                 if (is_int(strpos($action, '/'))) {
                     list($action, $subfolder) = explode('/', $action);
                 }
                 switch ($action) {
                     case 'config':
                     case 'controller':
                     case 'model':
                     case 'migration':
                     case 'task':
                         call_user_func('Oil\\Generate::' . $action, array_slice($args, 3));
                         break;
                     case 'views':
                         call_user_func('Oil\\Generate::views', array_slice($args, 3), $subfolder);
                         break;
                     case 'admin':
                         call_user_func('Oil\\Generate_Admin::forge', array_slice($args, 3), $subfolder);
                         break;
                     case 'scaffold':
                         call_user_func('Oil\\Generate_Scaffold::forge', array_slice($args, 3), $subfolder);
                         break;
                     default:
                         Generate::help();
                 }
                 break;
             case 'c':
             case 'console':
                 new Console();
             case 'p':
             case 'package':
                 $action = isset($args[2]) ? $args[2] : 'help';
                 switch ($action) {
                     case 'install':
                     case 'uninstall':
                         call_user_func_array('Oil\\Package::' . $action, array_slice($args, 3));
                         break;
                     default:
                         Package::help();
                 }
                 break;
             case 'r':
             case 'refine':
                 $task = isset($args[2]) ? $args[2] : null;
                 call_user_func('Oil\\Refine::run', $task, array_slice($args, 3));
                 break;
             case 'cell':
             case 'cells':
                 $action = isset($args[2]) ? $args[2] : 'help';
                 switch ($action) {
                     case 'list':
                         call_user_func('Oil\\Cell::all');
                         break;
                     case 'search':
                     case 'install':
                     case 'upgrade':
                     case 'uninstall':
                         call_user_func_array('Oil\\Cell::' . $action, array_slice($args, 3));
                         break;
                     case 'info':
                     case 'details':
                         call_user_func_array('Oil\\Cell::info', array_slice($args, 3));
                         break;
                     default:
                         Cell::help();
                 }
                 break;
             case 't':
             case 'test':
                 // Suppressing this because if the file does not exist... well thats a bad thing and we can't really check
                 // I know that supressing errors is bad, but if you're going to complain: shut up. - Phil
                 $phpunit_autoload_path = \Config::get('oil.phpunit.autoload_path', 'PHPUnit/Autoload.php');
                 @(include_once $phpunit_autoload_path);
                 // Attempt to load PHUnit.  If it fails, we are done.
                 if (!class_exists('PHPUnit_Framework_TestCase')) {
                     throw new Exception('PHPUnit does not appear to be installed.' . PHP_EOL . PHP_EOL . "\tPlease visit http://phpunit.de and install.");
                 }
                 // Check for a custom phpunit config, but default to the one from core
                 if (file_exists(APPPATH . 'phpunit.xml')) {
                     $phpunit_config = APPPATH . 'phpunit.xml';
                 } else {
                     $phpunit_config = COREPATH . 'phpunit.xml';
                 }
                 // CD to the root of Fuel and call up phpunit with the path to our config
                 $phpunit_command = \Config::get('oil.phpunit.binary_path', 'phpunit');
                 $command = 'cd ' . DOCROOT . '; ' . $phpunit_command . ' -c "' . $phpunit_config . '"';
                 // Respect the group options
                 \Cli::option('group') and $command .= ' --group ' . \Cli::option('group');
                 \Cli::option('exclude-group') and $command .= ' --exclude-group ' . \Cli::option('exclude-group');
                 // Respect the coverage-html option
                 \Cli::option('coverage-html') and $command .= ' --coverage-html ' . \Cli::option('coverage-html');
                 \Cli::option('coverage-clover') and $command .= ' --coverage-clover ' . \Cli::option('coverage-clover');
                 \Cli::option('coverage-text') and $command .= ' --coverage-text=' . \Cli::option('coverage-text');
                 \Cli::option('coverage-php') and $command .= ' --coverage-php ' . \Cli::option('coverage-php');
                 \Cli::option('log-junit') and $command .= ' --log-junit ' . \Cli::option('log-junit');
                 \Cli::option('file') and $command .= ' ' . \Cli::option('file');
                 \Cli::write('Tests Running...This may take a few moments.', 'green');
                 $return_code = 0;
                 foreach (explode(';', $command) as $c) {
                     passthru($c, $return_code_task);
                     // Return failure if any subtask fails
                     $return_code |= $return_code_task;
                 }
                 exit($return_code);
                 break;
             case 's':
             case 'server':
                 if (version_compare(PHP_VERSION, '5.4.0') < 0) {
                     \Cli::write('The PHP built-in webserver is only available on PHP 5.4+', 'red');
                     break;
                 }
                 $php = \Cli::option('php', 'php');
                 $port = \Cli::option('p', \Cli::option('port', '8000'));
                 $host = \Cli::option('h', \Cli::option('host', 'localhost'));
                 $docroot = \Cli::option('d', \Cli::option('docroot', 'public/'));
                 $router = \Cli::option('r', \Cli::option('router', __DIR__ . DS . '..' . DS . 'phpserver.php'));
                 \Cli::write("Listening on http://{$host}:{$port}");
                 \Cli::write("Document root is {$docroot}");
                 \Cli::write("Press Ctrl-C to quit.");
                 passthru("{$php} -S {$host}:{$port} -t {$docroot} {$router}");
                 break;
             default:
                 static::help();
         }
     } catch (\Exception $e) {
         static::print_exception($e);
         exit(1);
     }
 }
 /**
  * Constructor, loads parent constructor.
  */
 protected function __construct()
 {
     parent::__construct();
 }
Exemple #29
0
 public static function init($args)
 {
     // Remove flag options from the main argument list
     for ($i = 0; $i < count($args); $i++) {
         if (strpos($args[$i], '-') === 0) {
             unset($args[$i]);
         }
     }
     try {
         if (!isset($args[1])) {
             if (\Cli::option('v', \Cli::option('version'))) {
                 \Cli::write('Fuel: ' . \Fuel::VERSION);
                 return;
             }
             static::help();
             return;
         }
         switch ($args[1]) {
             case 'g':
             case 'generate':
                 $action = isset($args[2]) ? $args[2] : 'help';
                 $subfolder = 'default';
                 if (is_int(strpos($action, 'scaffold/'))) {
                     $subfolder = str_replace('scaffold/', '', $action);
                     $action = 'scaffold';
                 }
                 switch ($action) {
                     case 'controller':
                     case 'model':
                     case 'views':
                     case 'migration':
                         call_user_func('Oil\\Generate::' . $action, array_slice($args, 3));
                         break;
                     case 'scaffold':
                         call_user_func('Oil\\Scaffold::generate', array_slice($args, 3), $subfolder);
                         break;
                     default:
                         Generate::help();
                 }
                 break;
             case 'c':
             case 'console':
                 new Console();
             case 'r':
             case 'refine':
                 // Developers of third-party tasks may not be displaying PHP errors. Report any error and quit
                 set_error_handler(function ($errno, $errstr, $errfile, $errline) {
                     \Cli::error("Error: {$errstr} in {$errfile} on {$errline}");
                     \Cli::beep();
                     exit;
                 });
                 $task = isset($args[2]) ? $args[2] : null;
                 call_user_func('Oil\\Refine::run', $task, array_slice($args, 3));
                 break;
             case 'p':
             case 'package':
                 $action = isset($args[2]) ? $args[2] : 'help';
                 switch ($action) {
                     case 'install':
                     case 'uninstall':
                         call_user_func_array('Oil\\Package::' . $action, array_slice($args, 3));
                         break;
                     default:
                         Package::help();
                 }
                 break;
             case 't':
             case 'test':
                 // Suppressing this because if the file does not exist... well thats a bad thing and we can't really check
                 // I know that supressing errors is bad, but if you're going to complain: shut up. - Phil
                 @(include_once 'PHPUnit/Autoload.php');
                 // Attempt to load PHUnit.  If it fails, we are done.
                 if (!class_exists('PHPUnit_Framework_TestCase')) {
                     throw new Exception('PHPUnit does not appear to be installed.' . PHP_EOL . PHP_EOL . "\tPlease visit http://phpunit.de and install.");
                 }
                 // CD to the root of Fuel and call up phpunit with a path to our config
                 $command = 'cd ' . DOCROOT . '; phpunit -c "' . COREPATH . 'phpunit.xml"';
                 // Respect the group option
                 \Cli::option('group') and $command .= ' --group ' . \Cli::option('group');
                 // Respect the coverage-html option
                 \Cli::option('coverage-html') and $command .= ' --coverage-html ' . \Cli::option('coverage-html');
                 passthru($command);
                 break;
             default:
                 static::help();
         }
     } catch (Exception $e) {
         \Cli::error('Error: ' . $e->getMessage());
         \Cli::beep();
     }
 }
Exemple #30
0
 /**
  * @param object $obj controller class
  * @param string $project project name
  * @param string $env env name
  * @param string $db db name
  * @param string $table table name
  */
 public function getModelCode($obj, $project, $env, $db, $table)
 {
     $obj->assign('model', Generate::service()->transName($table));
     $obj->assign('table', $table);
     $columns = $this->getColumns($project, $env, $db, $table);
     $obj->assign('columns', $columns);
     $obj->assign('pk', Generate::service()->getPk($columns));
     $html = $obj->fetch('template/model');
     return $html;
 }