示例#1
0
 public function testUnderscore()
 {
     $result = Inflector::underscore('BankAccount');
     $this->assertEquals('bank_account', $result);
     $result = Inflector::underscore('PHPDeveloper');
     $this->assertEquals('php_developer', $result);
     $result = Inflector::underscore('ICountable');
     $this->assertEquals('i_countable', $result);
 }
示例#2
0
	/**
	 * Handles Model::findBy* Model::findAll* magic
	 *
	 * @param string $method 
	 * @param string $args 
	 * @return mixed
	 * @throws \mongo_model\Exception
	 */
	public static function __callStatic($method, $args) {
		if (strpos($method, 'findBy') === 0) {
			$key = Inflector::underscore(substr($method, 6));
			return static::findFirst(array('conditions' => array($key => $args[0])));
		}

		if (strpos($method, 'findAllBy') === 0) {
			$key = Inflector::underscore(substr($method, 9));
			return static::findAll(array('conditions' => array($key => $args[0])));
		}

		throw new Exception('Undefined method ' . get_called_class() . '::' . $method . '()');
	}
示例#3
0
	public function __call($method, $args) {
		if (strpos($method, 'set') === 0) {
			$key = Inflector::underscore(substr($method, 3));
			return $this->setReference($key, $args[0]);
		}

		$key = Inflector::underscore($method);
		if (in_array($key, static::$_references)) {			
			return $this->getReference($key);
		}

		throw new Exception('Undefined method ' . get_called_class() . '::' . $method . '()');
	}
示例#4
0
 public function generate($name, $colDefs = array())
 {
     $name = Inflector::underscore($name);
     $version = gmdate('YmdHis');
     foreach (glob(ROX_APP_PATH . '/config/migrations/*.php') as $file) {
         if (preg_match("/([0-9]+)_{$name}.php/", $file) == 1) {
             throw new Exception("A migration named {$name} already exists");
         }
     }
     $type = static::inferMigrationType($name);
     $class = Inflector::camelize($name);
     $table = static::inferTableName($name);
     $columns = static::parseColumnDefinitions($colDefs);
     $indexes = static::extractIndexes($columns);
     $vars = compact('type', 'class', 'table', 'columns', 'indexes');
     $data = $this->_renderTemplate('migration', $vars, true);
     $this->_writeFile("/config/migrations/{$version}_{$name}.php", $data);
 }
示例#5
0
 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);
 }
示例#6
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];
	}
示例#7
0
	/**
	 * 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;
	}
示例#8
0
文件: Gen.php 项目: radius/roxphp
	protected function _generateMigration($name) {
		$name = Inflector::underscore($name);

		foreach (glob(ROX_APP_PATH . '/config/migrations/*.php') as $file) {
			if (preg_match("/([0-9]+)_{$name}.php/", $file) == 1) {
				throw new Exception("A migration named {$name} already exists");
			}
		}

		$version = gmdate('YmdHis');

		$data = $this->_renderTemplate('migration', array(
			'class_name' => Inflector::camelize($name),
			'year' => date('Y')
		));

		$this->_writeFile("/config/migrations/{$version}_{$name}.php", $data);
	}
示例#9
0
 public function setModel($model)
 {
     $validModel = is_string($model) || is_object($model) && $model instanceof ActiveModel;
     if (!$validModel) {
         throw new Exception('Model should be string or a \\rox\\ActiveModel');
     }
     $modelName = Inflector::underscore(is_object($model) ? get_class($model) : $model);
     $this->_currentModel = $modelName;
     if (is_object($model)) {
         $this->_data = array_merge($this->_data, array($modelName => $model->getData()));
         $this->_validationErrors[$modelName] = $model->getValidationErrors();
     }
 }