/** * Creates a new \mongo_model\embedded\Many collection from MogoDB document data * * @param Base $parent document who owns the collection * @param string $name name/class of embedded documents * @param array $data MongoDB data * @return Many */ public static function fromMongoData(Base $parent, $name, $data) { $class = Inflector::classify($name); $objects = array_map(function($objectData) use ($class) { return $class::fromMongoData($objectData); }, $data); return new Many($parent, $objects); }
public function getReference($name) { if (array_key_exists($name, $this->_referenced)) { return $this->_referenced[$name]; } if (empty($this->_data[$name])) { return null; } $class = Inflector::classify($name); $this->_referenced[$name] = $class::find($this->_data[$name]['$id']); return $this->_referenced[$name]; }
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); }
/** * undocumented function * * @return array */ protected static function _normalizeAssociations() { $associations = array('belongs_to' => array(), 'has_many' => array(), 'has_one' => array()); $rels = array('belongs_to' => '_belongsTo', 'has_many' => '_hasMany', 'has_one' => '_hasOne'); foreach ($rels as $type => $property) { foreach (static::$$property as $name => $options) { if (is_int($name) && is_string($options)) { $name = $options; $options = array(); } $keyClass = ($type == 'belongs_to') ? $name : get_called_class(); $defaults = array( 'class' => Inflector::classify($name), 'key' => Inflector::underscore($keyClass) . '_id' ); $options += $defaults; $associations[$type][$name] = $options; } } return $associations; }
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); } }
public function generate($name) { $vars = array('class_name' => Inflector::classify($name), 'friendly_model_name' => Inflector::humanize(Inflector::classify($name)), 'package_name' => 'App', 'year' => date('Y')); $data = $this->_renderTemplate('model', $vars); $this->_writeFile('/models/' . Inflector::classify($name) . '.php', $data); }
public function testClassify() { $result = Inflector::classify('user_accounts'); $this->assertEquals('UserAccount', $result); }