示例#1
0
 public function testPluralize()
 {
     $result = Inflector::pluralize('client');
     $this->assertEquals('clients', $result);
     $result = Inflector::pluralize('Tomato');
     $this->assertEquals('Tomatoes', $result);
     $result = Inflector::pluralize('Metal Box');
     $this->assertEquals('Metal Boxes', $result);
     $result = Inflector::pluralize('fish');
     $this->assertEquals('fish', $result);
     $result = Inflector::pluralize('Database');
     $this->assertEquals('Databases', $result);
 }
示例#2
0
 /**
  * \rox\template\helper\Form::forModel()
  *
  * @param \rox\ActiveRecord|string $model 
  * @param array $options 
  * @return string
  */
 public function forModel($model, $options = array())
 {
     $options = array_merge(array('action' => null), $options);
     $this->setModel($model);
     $method = is_string($model) || $model->getId() === null ? 'POST' : 'PUT';
     if ($options['action'] === null) {
         $controller = Inflector::pluralize($this->_currentModel);
         $options['action'] = is_string($model) || $model->getId() === null ? "/{$controller}" : '/' . $controller . '/' . $model->getId();
     }
     $result = array();
     $result[] = $this->create($options['action'], $options);
     $result[] = sprintf('<input type="hidden" name="_method" value="%s">', $method);
     return implode('', $result);
 }
示例#3
0
 public function generate($name, $colDefs = array())
 {
     if (empty($colDefs)) {
         throw new Exception('Scaffold generator requires a list of columns/attributes');
     }
     $name = Inflector::pluralize($name);
     $migrationGen = new Migration($this->command);
     $migrationGen->generate("create_{$name}", $colDefs);
     $modelGen = new Model($this->command);
     $modelGen->generate($name);
     $controllerGen = new Controller($this->command);
     $controllerGen->generate($name);
     $viewsGen = new Views($this->command);
     $viewsGen->generate($name, $colDefs);
 }
示例#4
0
 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);
     }
 }
示例#5
0
文件: Html.php 项目: radius/roxphp
	/**
	 * Returns the controller name for a given ActiveModel instance.
	 *
	 * @param ActiveModel $object 
	 * @return string
	 */
	protected static function _controllerNameFromModel(ActiveModel $object) {
		static $results = array();
		$class = get_class($object);
		if (!isset($results[$class])) {
			$results[$class] = Inflector::underscore(Inflector::pluralize($class));
		}
		return $results[$class];
	}
示例#6
0
文件: Gen.php 项目: radius/roxphp
	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);
		}
	}