'controller', 'path' => 'classes/controller/admin/(:scaffold).php', ), array( 'type' => 'controller', 'path' => 'classes/controller/(:scaffold).php', ), array( 'type' => 'model', 'path' => 'classes/model/(:scaffold).php', ), array( 'type' => 'views', 'path' => 'views/admin/(:scaffold)', ), array( 'type' => 'views', 'path' => 'views/(:scaffold)', ), ); // Are we overriding existing files. static $force = false; static $folder_permissions = 0777; /** * Called by: php oil r movescaffoldtomodule * Moves scaffold files to module. */ public function run($args = NULL) { /* We handle here options: * * scaffold alias s: name of the scaffold to move * * module alias m: module to move the scaffold into * * force alias f: do we override existing files ? */ $scaffold = \Cli::option('scaffold', \Cli::option('s')); $module = \Cli::option('module', \Cli::option('m')); static::$force = \Cli::option('force', \Cli::option('f', false) ); // Checking if the scaffold and module options are // defined if (is_null($scaffold) || is_null($module)) { \Cli::error('Some parameters are missing.'); \Cli::error('Ex: php oil r moveScaffoldToModule'. ' -scaffold=category -module=blog'); return; } $module_path = \Module::exists($module); // Is the module found ? if ($module_path == null) { \Cli::error( 'The specified module doesn\'t exists!' ); return; } // Now processing each scaffold file / folders foreach (static::$files_to_move as $item) { $path = str_replace( '(:scaffold)', $scaffold, $item['path'] ); if (file_exists(APPPATH.$path)) { /* * As each file type must be processed * differently, a different method is called * depending on the type. For instance, if * the file type is controller, we will call * the process_controller method. */ static::{'process_'.$item['type']}( $path, $module, $module_path ); } } // Processing migration as it is a special cases. static::process_migration( $scaffold, $module, $module_path ); } // How do we process controller files ? protected static function process_controller( $path, $module, $module_path ) { $from_path = APPPATH.$path; $to_path = $module_path.$path; // If the necessary directory doesn't exist on the // module, we create it. if (!file_exists(dirname($to_path))) { mkdir( dirname($to_path), static::$folder_permissions, true ); } if (!file_exists($to_path) || static::$force) { // We do the changes we did earlier for the // post scaffold controller. $content = \File::read($from_path, true); $content = str_replace( '