/** * 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; } }
/** * Generate the body the the migration that will be generated * * @access private * @param string $class_name The name of the model * @param array $columns The list of columns with their attributes * @return string The migration's body * @author Aziz Light **/ private function generate_migration_statement($class_name, array $columns) { $extra = ''; foreach ($columns as $column => $attrs) { $args = array(); $args['column_name'] = $column; foreach ($attrs as $attr => $value) { $args['column_' . $attr] = $value; } $template = new TemplateScanner('migration_column', $args); $extra .= $template->parse(); } return trim($extra, PHP_EOL) . PHP_EOL; }