classify() public static method

Takes a under_scored table name and returns corresponding class name.
public static classify ( string $tableName ) : string
$tableName string Under_scored and plural table name (i.e. `'posts'`).
return string CamelCased class name (i.e. `'Post'`).
Ejemplo n.º 1
0
 /**
  * Get the class name for the mock.
  *
  * @param string $request
  * @return string
  */
 protected function _class($request)
 {
     $name = $request->action;
     $type = $request->command;
     if ($command = $this->_instance($type)) {
         $request->params['action'] = $name;
         $name = $command->invokeMethod('_class', array($request));
     }
     return Inflector::classify("Mock{$name}");
 }
Ejemplo n.º 2
0
 public function run($name = null, $null = null)
 {
     $library = Libraries::get($this->library);
     if (empty($library['prefix'])) {
         return false;
     }
     $model = Inflector::classify($name);
     $use = "\\{$library['prefix']}models\\{$model}";
     $params = array('namespace' => "{$library['prefix']}controllers", 'use' => $use, 'class' => "{$name}Controller", 'model' => $model, 'singular' => Inflector::singularize(Inflector::underscore($name)), 'plural' => Inflector::pluralize(Inflector::underscore($name)));
     if ($this->_save($this->template, $params)) {
         $this->out("{$params['class']} created in {$params['namespace']}.");
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Get the class name for the test case.
  *
  * @param string $request
  * @return string
  */
 protected function _class($request)
 {
     $name = $this->_name($request);
     return Inflector::classify("{$name}Test");
 }
Ejemplo n.º 4
0
 /**
  * Get the model class used in controller methods.
  *
  * @param string $request
  * @return string
  */
 protected function _model($request)
 {
     return Inflector::classify($request->action);
 }
Ejemplo n.º 5
0
 /**
  * Get the api for the class.
  *
  * @param string $class fully namespaced class in dot notation
  * @param string $type method|property
  * @param string $name the name of the method or property
  * @return array
  */
 public function api($class = null, $type = null, $name = null)
 {
     $class = str_replace(".", "\\", $class);
     switch ($type) {
         default:
             $info = Inspector::info($class);
             $result = array('class' => array('name' => Inflector::classify($info['shortName']), 'description' => $info['description']));
             break;
         case 'method':
             $result = $this->_methods($class, compact('name'));
             break;
         case 'property':
             $result = $this->_properties($class, compact('name'));
             break;
     }
     $this->_render($result);
 }
Ejemplo n.º 6
0
 /**
  * Run through the default set. model, controller, test model, test controller
  *
  * @param string $name class name to create
  * @return boolean
  */
 protected function _default($name)
 {
     $commands = array(array('model', Inflector::classify($name)), array('controller', Inflector::pluralize($name)), array('test', 'model', Inflector::classify($name)), array('test', 'controller', Inflector::pluralize($name)));
     foreach ($commands as $args) {
         $command = $this->template = $this->request->params['command'] = array_shift($args);
         $this->request->params['action'] = array_shift($args);
         $this->request->params['args'] = $args;
         if (!$this->_execute($command)) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 7
0
 /**
  * testClassNaming method
  *
  * @return void
  */
 public function testClassify()
 {
     $this->assertEqual(Inflector::classify('artists_genres'), 'ArtistsGenre');
     $this->assertEqual(Inflector::classify('file_systems'), 'FileSystem');
     $this->assertEqual(Inflector::classify('news'), 'News');
 }
Ejemplo n.º 8
0
 /**
  * fetches associated records
  *
  * {{{
  *   $post->resolve('user'); // returns user, as defined in $post->user_id
  * }}}
  *
  * @param object $entity current instance
  * @param string|array $fields name of model to load
  * @param array $options an array of options currently supported are
  *              - `resolver` : closure that takes $name as parameter and returns full qualified
  *                 model name.
  *              - `slug` : true or false. If set to true, model is resolving by slug, not by ID.
  *                 The slug has to be saved in a document schema key, named by the singular
  *                 version of the model to reslove.
  * @return array foreign object data
  */
 public function resolve($entity, $fields = null, array $options = array())
 {
     $resolver = function ($name) {
         $modelname = Inflector::pluralize(Inflector::classify($name));
         return Libraries::locate('models', $modelname);
     };
     $slug = false;
     $defaults = compact('resolver', 'slug');
     $options += $defaults;
     switch (true) {
         case is_string($fields) && $options['slug']:
             $fields = array($fields);
             break;
         case is_array($fields) && $options['slug']:
             break;
         case is_string($fields):
             $fields = array(stristr($fields, '_id') ? $fields : "{$fields}_id");
             break;
         case is_array($fields):
             $fields = array_map(function ($field) {
                 return stristr($field, '_id') ? $field : "{$field}_id";
             }, $fields);
             break;
         case empty($fields):
             $fields = self::fields();
             break;
     }
     $result = array();
     foreach ($fields as $field) {
         if (!$options['slug']) {
             if (!preg_match('/^(.+)_id$/', $field, $matches)) {
                 continue;
             }
             list($attribute, $name) = $matches;
         } else {
             $attribute = $field;
             $name = $field;
         }
         $model = $options['resolver']($name);
         if (empty($model)) {
             continue;
         }
         $foreign_id = (string) $entity->{$attribute};
         if (!$foreign_id) {
             continue;
         }
         $result[$name] = $model::load($foreign_id);
     }
     return count($fields) > 1 ? $result : array_shift($result);
 }
Ejemplo n.º 9
0
 /**
  * Generic delete() action.
  * The trick here is that $this->calling_class and $this->calling_method will hold a string
  * reference for which extended class called this delete() method. We need that in order to
  * get the proper records and access.
 */
 public function delete() {
     // get the "_type" ... page_type, user_type, or block_type
     $model = Inflector::classify(Inflector::singularize($this->request->params['controller']));
     $modelClass = 'minerva\models\\'.$model;
     
     $conditions = array();
     if(isset($this->request->params['id'])) {
         $conditions = array('id' => $this->request->params['id']);
     }
     if(isset($this->request->params['url'])) {
         $conditions = array('url' => $this->request->params['url']);
     }
     
     if(empty($conditions)) {
         $this->redirect(array('controller' => $this->request->params['controller'], 'action' => 'index'));
     }
     
     $document = $this->getDocument(array(
         'action' => __METHOD__,
         'request' => $this->request,
         'find_type' => 'first',
         'conditions' => $conditions
     ));
     
     if($document->delete()) {
         FlashMessage::set('The content has been deleted.', array('options' => array('type' => 'success', 'pnotify_title' => 'Success', 'pnotify_opacity' => .8)));
         $this->redirect(array('controller' => $this->request->params['controller'], 'action' => 'index'));
     } else {
         FlashMessage::set('The content could not be deleted, please try again.', array('options' => array('type' => 'error', 'pnotify_title' => 'Error', 'pnotify_opacity' => .8)));
         $this->redirect(array('controller' => $this->request->params['controller'], 'action' => 'index'));
     }
 }