/** * Returns the name of db table * * @return string */ public static function _table() { if (static::$_table === null) { $table = Inflector::tableize(get_called_class()); static::$_table = &$table; } return static::$_table; }
/** * Returns the \MongoCollection for the model * * @return \MongoCollection */ public static function collection() { if (static::$_collection === null) { $collectionName = Inflector::tableize(get_called_class()); $db = ConnectionManager::getDataSource(static::$_dataSourceName); $collection = $db->selectCollection($collectionName); static::$_collection = &$collection; } return static::$_collection; }
public function testTableize() { $result = Inflector::tableize('Post'); $this->assertEquals('posts', $result); $result = Inflector::tableize('PageCategory'); $this->assertEquals('page_categories', $result); $result = Inflector::tableize('App_Model_Page'); $this->assertEquals('pages', $result); $result = Inflector::tableize('App_Forum_Model_Post'); $this->assertEquals('forum_posts', $result); }
public function generate($name, $colDefs = array()) { if (empty($colDefs)) { $tableName = Inflector::tableize($name); $datasource = ConnectionManager::getDataSource(); $attributes = $datasource->generateAttributeMapFromTable($tableName); } else { $columns = Migration::parseColumnDefinitions($colDefs); $names = array_map(function ($col) { return $col['name']; }, $columns); $types = array_map(function ($col) { return $col['type']; }, $columns); $attributes = array_combine($names, $types); } $templates = array('add', 'edit', 'index', 'view'); $vars = array('attributes' => $attributes, 'friendlyModelName' => Inflector::humanize(Inflector::classify($name)), 'modelVarName' => Inflector::lowerCamelize(Inflector::classify(Inflector::singularize($name))), 'pluralModelVarName' => Inflector::lowerCamelize(Inflector::pluralize($name)), 'controller' => Inflector::tableize($name)); foreach ($templates as $template) { $data = $this->_renderTemplate("views/{$template}", $vars, true); $folder = Inflector::tableize($name); $this->_writeFile("/views/{$folder}/{$template}.html.tpl", $data); } }
public function generate($name) { $vars = array('controller_name' => Inflector::tableize($name), 'controller_class' => Inflector::camelize(Inflector::tableize($name) . '_controller'), 'model_name' => Inflector::underscore(Inflector::singularize($name)), 'model_class' => Inflector::classify($name), 'model_var_name' => Inflector::lowerCamelize(Inflector::classify($name)), 'model_var_plural_name' => Inflector::lowerCamelize(Inflector::tableize($name)), 'friendly_model_name' => Inflector::humanize(Inflector::singularize($name)), 'friendly_controller_name' => Inflector::humanize(Inflector::tableize($name)), 'package_name' => 'App', 'year' => date('Y')); $data = $this->_renderTemplate('controller', $vars); $this->_writeFile('/controllers/' . $vars['controller_class'] . '.php', $data); }
private function _handleThrough($through, $model, $scope) { $model_var = Inflector::singularize(Inflector::tableize($model)); $assoc = array(); foreach ($through as $item) { $assoc[] = $model::find($item->{$model_var . '_id'}); } return $assoc; }
protected function _generateViews($name) { $tableName = Inflector::tableize($name); $datasource = ConnectionManager::getDataSource(); $attributes = $datasource->generateAttributeMapFromTable($tableName); $templates = array('add', 'edit', 'index', 'view'); $vars = array( 'attributes' => $attributes, 'friendlyModelName' => Inflector::humanize(Inflector::classify($name)), 'modelVarName' => Inflector::lowerCamelize(Inflector::classify(Inflector::singularize($name))), 'pluralModelVarName' => Inflector::lowerCamelize(Inflector::pluralize($name)), 'controller' => Inflector::tableize($name) ); foreach ($templates as $template) { $data = $this->_renderTemplate("views/{$template}", $vars, true); $folder = Inflector::tableize($name); $this->_writeFile("/views/{$folder}/{$template}.html.tpl", $data); } }