/** * The method that generates the controller * * @access private * @param array $force_views_creation : Should the method force the creation of views? Used in the scaffold method. * @return void * @author Aziz Light */ private function controller() { $args = array("class_name" => ApplicationHelpers::camelize($this->args['name']), "filename" => $this->args['filename'], "application_folder" => $this->args['application_folder'], "parent_class" => isset($this->args['parent']) ? $this->args['parent'] : $this->args['parent_controller'], "extra" => $this->extra); $template = new TemplateScanner("controller", $args); $controller = $template->parse(); $location = $this->args["location"] . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR; $filename = $location . $this->args['filename']; $message = "\t"; if (file_exists($filename)) { $message .= 'Controller already exists : '; if (php_uname("s") !== "Windows NT") { $message = ApplicationHelpers::colorize($message, 'light_blue'); } $message .= $this->args['application_folder'] . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $this->args['filename']; } elseif (file_put_contents($filename, $controller)) { $message .= 'Created controller: '; if (php_uname("s") !== "Windows NT") { $message = ApplicationHelpers::colorize($message, 'green'); } $message .= $this->args['application_folder'] . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $this->args['filename']; } else { $message .= 'Unable to create controller: '; if (php_uname("s") !== "Windows NT") { $message = ApplicationHelpers::colorize($message, 'red'); } $message .= $this->args['application_folder'] . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $this->args['filename']; } // The controller has been generated, output the confirmation message fwrite(STDOUT, $message . PHP_EOL); // Create the view files. $this->views(); return; }
public static function init(array $args) { if (!is_array($args)) { throw new InvalidArgumentException('Argument 1 passed to Inferno::init() must be an array'); } // First parse the options and remove them // from the $args array $options = self::parse_options($args); // Parse the arguments $args = self::parse($args); if ($args['command'] == 'new_project') { if (is_dir(getcwd() . DIRECTORY_SEPARATOR . $args['name'])) { throw new InvalidArgumentException('A folder with the same name already exists'); } $location = __DIR__ . DIRECTORY_SEPARATOR . $args['name']; } else { if ($args['command'] != 'bootstrap') { $location = FolderScanner::check_location(); } else { // FIXME: Find a better solution // Set the location so that we don't get errors $location = ""; } } if ($args['command'] != 'bootstrap' && !$location) { $error_message = "No CodeIgniter project detected at your location.\n" . "You must either be in the root or the application folder" . " of a CodeIgniter project!"; throw new RuntimeException($error_message); } // FIXME: Make this more generic // Get the config $config = parse_ini_file(BASE_PATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . "{$args["command"]}.ini"); // Add the location to the configuration array. $config["location"] = $location; // Merge the config and args arrays $args = array_merge($config, $args); // Merge the options and args arrays $args = array_merge($args, $options); // Example: new Generate() // Example: new NewCommand() $command_class = ApplicationHelpers::camelize($args['command']); // Remove the command from the array. unset($args["command"]); $klass = 'FIRE_' . $command_class; // Finally, call and run the command. $process = new $klass($args); return $process->run(); }
/** * Create the Migrate controller that * will be used to migrate the database * * @access private * @return void * @author Aziz Light **/ private function create_migration_controller() { $controller = $this->location . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . $this->controller_name . '.php'; if (is_file($controller)) { throw new RuntimeException('The ' . $this->controller_name . ' controller aleardy exists!'); } else { $template_name = "migration_controller"; $args = array('class_name' => ApplicationHelpers::camelize($this->controller_name)); if ($this->run_from_web === FALSE) { $args['extra'] = ' $this->input->is_cli_request() or exit("Execute via command line: php index.php migrate");'; } else { $args['extra'] = PHP_EOL; } $template = new TemplateScanner($template_name, $args); $controller_contents = $template->parse(); if (!file_put_contents($controller, $controller_contents)) { throw new RuntimeException('Could not create migration controller...' . PHP_EOL); } return TRUE; } }
/** * The method that generates the models * * @access private * @return void * @author Aziz Light */ private function model() { $location = $this->args["location"] . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR; $relative_location = $this->args['application_folder'] . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR; $class_name = ''; if (!empty($this->args['subdirectories'])) { $location .= $this->args['subdirectories'] . DIRECTORY_SEPARATOR; $relative_location .= $this->args['subdirectories'] . DIRECTORY_SEPARATOR; $tmp = explode(DIRECTORY_SEPARATOR, $this->args['subdirectories']); $tmp = join('_', $tmp); $class_name .= ApplicationHelpers::camelize($tmp); } if (!is_dir($location)) { mkdir($location, 0755, TRUE); } $relative_location .= $this->args['filename']; $filename = $location . $this->args['filename']; $class_name .= ucfirst(strtolower($this->args['name'])); $args = array("class_name" => ucfirst(strtolower($this->args['name'])), "filename" => $this->args['filename'], "application_folder" => $this->args['application_folder'], "parent_class" => isset($this->args['parent']) ? $this->args['parent'] : $this->args['parent_model'], "extra" => $this->extra, 'relative_location' => $relative_location); $template = new TemplateScanner("model", $args); $model = $template->parse(); $message = "\t"; if (file_exists($filename)) { $message .= 'Model already exists : '; if (php_uname("s") !== "Windows NT") { $message = ApplicationHelpers::colorize($message, 'light_blue'); } $message .= $relative_location; } elseif (file_put_contents($filename, $model)) { $message .= 'Created model: '; if (php_uname("s") !== "Windows NT") { $message = ApplicationHelpers::colorize($message, 'green'); } $message .= $relative_location; } else { $message .= 'Unable to create model: '; if (php_uname("s") !== "Windows NT") { $message = ApplicationHelpers::colorize($message, 'red'); } $message .= $relative_location; } fwrite(STDOUT, $message . PHP_EOL); // Create the migration for the new model $this->migration(); return; }