예제 #1
0
 protected function structure()
 {
     foreach (new FilesystemIterator($this->migrationPath()) as $file) {
         $migration = basename($file->getFileName(), '.php');
         $this->log('Install ' . $migration . '...');
         $class = 'FluxBB_Install_' . Str::classify($migration);
         include_once $file;
         $instance = new $class();
         $instance->up();
     }
 }
예제 #2
0
 /**
  * This method is responsible for generation all
  * source from the templates, and populating the
  * files array.
  *
  * @return void
  */
 private function _view_generation()
 {
     $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_';
     $view_prefix = $this->bundle == DEFAULT_BUNDLE ? '' : $this->bundle . '::';
     // set up the markers for replacement within source
     $markers = array('#LOWERFULL#' => $view_prefix . Str::lower(str_replace('/', '.', $this->class_path) . $this->lower));
     // loud our view template
     $template = Common::load_template('view/view.tpl');
     // added the file to be created
     $this->writer->create_file('View', $this->class_path . $this->lower . EXT, $this->bundle_path . 'views/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template));
 }
예제 #3
0
파일: model.php 프로젝트: downleave/blog
 /**
  * This method is responsible for generation all
  * source from the templates, and populating the
  * files array.
  *
  * @return void
  */
 private function _model_generation()
 {
     $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_';
     // set up the markers for replacement within source
     $markers = array('#CLASS#' => $prefix . $this->class_prefix . $this->class, '#LOWER#' => $this->lower, '#TIMESTAMPS#' => $this->_timestamps);
     // loud our model template
     $template = Common::load_template('model/model.tpl');
     // holder for relationships source
     $relationships_source = '';
     // loop through our relationships
     foreach ($this->arguments as $relation) {
         // if we have a valid relation
         if (!strstr($relation, ':')) {
             continue;
         }
         // split
         $relation_parts = explode(':', Str::lower($relation));
         // we need two parts
         if (!count($relation_parts) == 2) {
             continue;
         }
         // markers for relationships
         $rel_markers = array('#SINGULAR#' => Str::lower(Str::singular($relation_parts[1])), '#PLURAL#' => Str::lower(Str::plural($relation_parts[1])), '#WORD#' => Str::classify(Str::singular($relation_parts[1])), '#WORDS#' => Str::classify(Str::plural($relation_parts[1])));
         // start with blank
         $relationship_template = '';
         // use switch to decide which template
         switch ($relation_parts[0]) {
             case "has_many":
             case "hm":
                 $relationship_template = Common::load_template('model/has_many.tpl');
                 break;
             case "belongs_to":
             case "bt":
                 $relationship_template = Common::load_template('model/belongs_to.tpl');
                 break;
             case "has_one":
             case "ho":
                 $relationship_template = Common::load_template('model/has_one.tpl');
                 break;
             case "has_and_belongs_to_many":
             case "hbm":
                 $relationship_template = Common::load_template('model/has_and_belongs_to_many.tpl');
                 break;
         }
         // add it to the source
         $relationships_source .= Common::replace_markers($rel_markers, $relationship_template);
     }
     // add a marker to replace the relationships stub
     // in the model template
     $markers['#RELATIONS#'] = $relationships_source;
     // add the generated model to the writer
     $this->writer->create_file('Model', $prefix . $this->class_prefix . $this->class, $this->bundle_path . 'models/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template));
 }
예제 #4
0
 /**
  * This method is responsible for generation all
  * source from the templates, and populating the
  * files array.
  *
  * @return void
  */
 private function _controller_generation()
 {
     $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_';
     $view_prefix = $this->bundle == DEFAULT_BUNDLE ? '' : $this->bundle . '::';
     // set up the markers for replacement within source
     $markers = array('#CLASS#' => $prefix . $this->class_prefix . $this->class, '#LOWER#' => $this->lower, '#LOWERFULL#' => $view_prefix . Str::lower(str_replace('/', '.', $this->class_path) . $this->lower));
     // loud our controller template
     $template = Common::load_template('controller/controller.tpl');
     // holder for actions source, and base templates for actions and views
     $actions_source = '';
     $action_template = Common::load_template('controller/action.tpl');
     $view_template = Common::load_template('controller/view.tpl');
     $restful = strstr(implode(' ', $this->arguments), ':') ? true : false;
     array_unshift($this->arguments, 'index');
     // loop through our actions
     foreach ($this->arguments as $action) {
         $verb = $restful ? 'get' : 'action';
         if (strstr($action, ':')) {
             $parts = explode(':', $action);
             if (count($parts) == 2) {
                 $verb = Str::lower($parts[0]);
                 $action = Str::lower($parts[1]);
             }
         }
         // add the current action to the markers
         $markers['#ACTION#'] = Str::lower($action);
         $markers['#VERB#'] = $verb;
         // append the replaces source
         $actions_source .= Common::replace_markers($markers, $action_template);
         $file_prefix = $restful ? $verb . '_' : '';
         // add the file to be created
         $this->writer->create_file('View', $this->class_path . $this->lower . '/' . $file_prefix . Str::lower($action) . $this->_view_extension, $this->bundle_path . 'views/' . $this->class_path . $this->lower . '/' . $file_prefix . Str::lower($action) . $this->_view_extension, Common::replace_markers($markers, $view_template));
     }
     // add a marker to replace the actions stub in the controller
     // template
     $markers['#ACTIONS#'] = $actions_source;
     $markers['#RESTFUL#'] = $restful ? "\n\tpublic \$restful = true;\n" : '';
     // added the file to be created
     $this->writer->create_file('Controller', $markers['#CLASS#'] . '_Controller', $this->bundle_path . 'controllers/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template));
     $this->writer->append_to_file($this->bundle_path . 'routes.php', "\n\n// Route for {$markers['#CLASS#']}_Controller\nRoute::controller('{$markers['#LOWERFULL#']}');");
 }
예제 #5
0
 /**
  * This method is responsible for generation all
  * source from the templates, and populating the
  * files array.
  *
  * @return void
  */
 private function _config_generation()
 {
     $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_';
     $view_prefix = $this->bundle == DEFAULT_BUNDLE ? '' : $this->bundle . '::';
     // loud our config template
     $template = Common::load_template('config/config.tpl');
     // holder for options source, and base template for options
     $options_source = '';
     $option_template = Common::load_template('config/option.tpl');
     // loop through our options
     foreach ($this->arguments as $option) {
         // add the current option to the markers
         $markers['#OPTION#'] = Str::lower($option);
         // append the replaces source
         $options_source .= Common::replace_markers($markers, $option_template);
     }
     // add a marker to replace the options stub in the config
     // template
     $markers['#OPTIONS#'] = $options_source;
     // added the file to be created
     $this->writer->create_file('Config', $this->lower . EXT, $this->bundle_path . 'config/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template));
 }
예제 #6
0
파일: task.php 프로젝트: gigikiri/masjid-l3
 /**
  * This method is responsible for generation all
  * source from the templates, and populating the
  * files array.
  *
  * @return void
  */
 private function _task_generation()
 {
     $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_';
     $view_prefix = $this->bundle == DEFAULT_BUNDLE ? '' : $this->bundle . '::';
     // set up the markers for replacement within source
     $markers = array('#CLASS#' => $prefix . $this->class_prefix . $this->class, '#LOWER#' => $this->lower, '#LOWERFULL#' => $view_prefix . Str::lower(str_replace('/', '.', $this->class_path) . $this->lower));
     // loud our task template
     $template = Common::load_template('task/task.tpl');
     // holder for methods source, and base template for methods
     $methods_source = '';
     $method_template = Common::load_template('task/method.tpl');
     // loop through our methods
     foreach ($this->arguments as $method) {
         // add the current method to the markers
         $markers['#METHOD#'] = Str::lower($method);
         // append the replaces source
         $methods_source .= Common::replace_markers($markers, $method_template);
     }
     // add a marker to replace the methods stub in the task
     // template
     $markers['#METHODS#'] = $methods_source;
     // added the file to be created
     $this->writer->create_file('Task', $markers['#CLASS#'] . '_Task', $this->bundle_path . 'tasks/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template));
 }
예제 #7
0
 /**
  * Determine class names, identifiers and arguments based on the args
  * passed by the build script.
  *
  * @param array Arguments to the build script.
  * @return void
  */
 public function __construct($args)
 {
     // we need a writer object for file system changes
     $this->writer = new Writer();
     // set default args
     $this->args = $args;
     // if we got an argument
     if (isset($args[0])) {
         // check to see if its bundle prefixed
         if (strstr($args[0], '::')) {
             $parts = explode('::', $args[0]);
             // if we have a bundle and a class
             if (count($parts) == 2 && $parts[0] !== '') {
                 $this->bundle = Str::lower($parts[0]);
                 if (!Bundle::exists($this->bundle)) {
                     Common::error('The specified bundle does not exist, or is not loaded.');
                 }
                 // remove the bundle section, we are done with that
                 $args[0] = $parts[1];
             }
         } else {
             // use the application folder if no bundle
             $this->bundle = DEFAULT_BUNDLE;
         }
         // set bundle path from bundle name
         $this->bundle_path = Bundle::path($this->bundle);
         // if we have a multi-level path
         if (strstr($args[0], '.')) {
             $parts = explode('.', $args[0]);
             // form the class prefix as in Folder_Folder_Folder_
             $this->class_prefix = Str::classify(implode('_', array_slice($parts, 0, -1)) . '_');
             // form the path to the class
             $this->class_path = Str::lower(implode('/', array_slice($parts, 0, -1)) . '/');
             // unaltered case class
             $this->standard = $parts[count($parts) - 1];
             // lowercase class
             $this->lower = Str::lower($parts[count($parts) - 1]);
             // get our class name
             $this->class = Str::classify($parts[count($parts) - 1]);
         } else {
             // unaltered case class
             $this->standard = $args[0];
             // lowercase class
             $this->lower = Str::lower($args[0]);
             // get our class name
             $this->class = Str::classify($args[0]);
         }
     }
     // pass remaining arguments
     $this->arguments = array_slice($args, 1);
 }
예제 #8
0
 /**
  * Test the Str::classify method.
  *
  * @group laravel
  */
 public function testStringsCanBeClassified()
 {
     $this->assertEquals('Something_Else', Str::classify('something.else'));
     $this->assertEquals('Something_Else', Str::classify('something_else'));
 }