本文整理汇总了PHP中Doctrine_Inflector::classify方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Inflector::classify方法的具体用法?PHP Doctrine_Inflector::classify怎么用?PHP Doctrine_Inflector::classify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Inflector
的用法示例。
在下文中一共展示了Doctrine_Inflector::classify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testClassifyTableize
public function testClassifyTableize() {
$name = "Forum_Category";
$this->assertEqual(Doctrine_Inflector::tableize($name), "forum__category");
$this->assertEqual(Doctrine_Inflector::classify(Doctrine_Inflector::tableize($name)), $name);
}
示例2: set
/**
* Set a record attribute. Allows overriding Doctrine record accessors with Propel style functions
*
* @param string $name
* @param string $value
* @param string $load
* @return void
*/
public function set($name, $value, $load = true)
{
$setter = 'set' . Doctrine_Inflector::classify($name);
if (method_exists($this, $setter)) {
return $this->{$setter}($value, $load);
}
return parent::set($name, $value, $load);
}
示例3: getShortPluginName
public static function getShortPluginName($name)
{
// Special shortening for non sympal plugins
if (substr($name, 0, 2) == 'sf' && !strstr($name, 'sfSympal')) {
return $name;
}
if (strstr($name, 'sfSympal')) {
return substr($name, 8, strlen($name) - 14);
} else {
return Doctrine_Inflector::classify(Doctrine_Inflector::tableize($name));
}
}
示例4: execute
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$tmpdir = sfConfig::get('sf_cache_dir') . '/models_tmp';
$ymlTmp = $tmpdir . '/yaml';
$modelTmp = $tmpdir . '/model';
$this->getFileSystem()->mkdirs($ymlTmp);
$this->getFileSystem()->mkdirs($modelTmp);
$migrationsPath = sfConfig::get('sf_data_dir') . '/migrations/generated';
$config = $this->getCliConfig();
$manager = Doctrine_Manager::getInstance();
$oldAttr = $manager->getAttribute(Doctrine::ATTR_MODEL_LOADING);
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_AGGRESSIVE);
sfSimpleAutoload::unregister();
Doctrine::generateYamlFromDb($ymlTmp . '/from.yml', array(), array('generateBaseClasses' => false));
sfSimpleAutoload::register();
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, $oldAttr);
$models = sfFinder::type('file')->name('*.php')->in($config['models_path']);
foreach ($models as $model) {
$dirname = basename(dirname($model));
$filename = basename($model);
if ('base' !== $dirname) {
continue;
}
$normalModelName = str_replace('Base', '', basename($model, '.class.php'));
$normalModelRefClass = new ReflectionClass($normalModelName);
if ($normalModelRefClass && $normalModelRefClass->isAbstract()) {
continue;
}
$content = file_get_contents($model);
$content = str_replace('abstract class Base', 'class ToPrfx', $content);
$content = str_replace('extends opDoctrineRecord', 'extends Doctrine_Record', $content);
$matches = array();
if (preg_match('/\\$this->setTableName\\(\'([^\']+)\'\\);/', $content, $matches)) {
$tableName = $matches[1];
$content = preg_replace('/class [a-zA-Z0-9_]+/', 'class ToPrfx' . Doctrine_Inflector::classify($tableName), $content);
file_put_contents($modelTmp . '/ToPrfx' . Doctrine_Inflector::classify($tableName) . '.class.php', $content);
} else {
file_put_contents($modelTmp . '/' . str_replace('Base', 'ToPrfx', $filename), $content);
}
}
$migration = new Doctrine_Migration($migrationsPath);
$diff = new opMigrationDiff($ymlTmp . '/from.yml', $modelTmp, $migration);
$changes = $diff->generateMigrationClasses();
$this->getFileSystem()->remove($ymlTmp);
$this->getFileSystem()->remove($modelTmp);
$numChanges = count($changes, true) - count($changes);
if (!$numChanges) {
throw new Doctrine_Task_Exception('Could not generate migration classes from difference');
} else {
$this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->formatSection('doctrine', 'Generated migration classes successfully from difference'))));
}
}
示例5: setTableDefinition
public function setTableDefinition()
{
$relations = $this->_options['relations'];
foreach ($relations as $relation) {
$this->_table->setColumn(self::getColumnName($relation, $this->_options['column_suffix']), 'varchar', 255, array('type' => 'varchar', 'length' => 255));
}
$format = Doctrine_Inflector::classify($this->_options['serialization_format']);
$listerner = "Doctrine_Template_Listener_{$format}Serializable";
if (!class_exists($listerner)) {
throw new Expection("The behavior '{$listerner}' does not exist.");
}
$this->addListener(new $listerner($this->_options));
}
示例6: postHydrate
/**
* Deserializes relationship(s)
*
* @param Doctrine_Event $event
* @return void
*/
public function postHydrate(Doctrine_Event $event)
{
$data = $event->data;
$relations = $this->_options['relations'];
foreach ($relations as $relation) {
$column = Doctrine_Template_Serializable::getColumnName($relation, $this->_options['column_suffix']);
$filter = $data[$column];
$model = Doctrine_Inflector::classify($relation['table']);
if (!isset($relation['table_method'])) {
$query = Doctrine_Core::getTable($model)->createQuery();
if (isset($relation['order_by'])) {
$order = $relation['order_by'];
$query->addOrderBy($order[0] . ' ' . $order[1]);
}
$query->setHydrationMode(Doctrine_Core::HYDRATE_ARRAY);
$objects = $query->execute();
} else {
$tableMethod = $relation['table_method'];
$results = Doctrine_Core::getTable($model)->{$tableMethod}();
if ($results instanceof Doctrine_Query) {
$objects = $results->execute();
} else {
if ($results instanceof Doctrine_Collection) {
$objects = $results;
} else {
if ($results instanceof Doctrine_Record) {
$objects = new Doctrine_Collection($model);
$objects[] = $results;
} else {
$objects = array();
}
}
}
}
// replace value of column
$data[$column] = $this->normalize($objects, $filter);
}
$event->data = $data;
}
示例7: doMigrate
/**
* doMigrate
*
* Perform migration for a migration class. Executes the up or down method then processes the changes
*
* @param string $direction
* @return void
*/
protected function doMigrate($direction)
{
$method = 'pre' . $direction;
$this->{$method}();
if (method_exists($this, $direction)) {
$this->{$direction}();
foreach ($this->_changes as $type => $changes) {
$process = new Doctrine_Migration_Process();
$funcName = 'process' . Doctrine_Inflector::classify($type);
if (!empty($changes)) {
$process->{$funcName}($changes);
}
}
}
$method = 'post' . $direction;
$this->{$method}();
}
示例8: _buildRelationships
/**
* buildRelationships
*
* Loop through an array of schema information and build all the necessary relationship information
* Will attempt to auto complete relationships and simplify the amount of information required
* for defining a relationship
*
* @param string $array
* @return void
*/
protected function _buildRelationships($array)
{
// Handle auto detecting relations by the names of columns
// User.contact_id will automatically create User hasOne Contact local => contact_id, foreign => id
foreach ($array as $className => $properties) {
if (isset($properties['columns']) && !empty($properties['columns']) && isset($properties['detect_relations']) && $properties['detect_relations']) {
foreach ($properties['columns'] as $column) {
// Check if the column we are inflecting has a _id on the end of it before trying to inflect it and find
// the class name for the column
if (strpos($column['name'], '_id')) {
$columnClassName = Doctrine_Inflector::classify(str_replace('_id', '', $column['name']));
if (isset($array[$columnClassName]) && !isset($array[$className]['relations'][$columnClassName])) {
$array[$className]['relations'][$columnClassName] = array();
// Set the detected foreign key type and length to the same as the primary key
// of the related table
$type = isset($array[$columnClassName]['columns']['id']['type']) ? $array[$columnClassName]['columns']['id']['type'] : 'integer';
$length = isset($array[$columnClassName]['columns']['id']['length']) ? $array[$columnClassName]['columns']['id']['length'] : 8;
$array[$className]['columns'][$column['name']]['type'] = $type;
$array[$className]['columns'][$column['name']]['length'] = $length;
}
}
}
}
}
foreach ($array as $name => $properties) {
if (!isset($properties['relations'])) {
continue;
}
$className = $properties['className'];
$relations = $properties['relations'];
foreach ($relations as $alias => $relation) {
$class = isset($relation['class']) ? $relation['class'] : $alias;
if (!isset($array[$class])) {
continue;
}
$relation['class'] = $class;
$relation['alias'] = isset($relation['alias']) ? $relation['alias'] : $alias;
// Attempt to guess the local and foreign
if (isset($relation['refClass'])) {
$relation['local'] = isset($relation['local']) ? $relation['local'] : Doctrine_Inflector::tableize($name) . '_id';
$relation['foreign'] = isset($relation['foreign']) ? $relation['foreign'] : Doctrine_Inflector::tableize($class) . '_id';
} else {
$relation['local'] = isset($relation['local']) ? $relation['local'] : Doctrine_Inflector::tableize($relation['class']) . '_id';
$relation['foreign'] = isset($relation['foreign']) ? $relation['foreign'] : 'id';
}
if (isset($relation['refClass'])) {
$relation['type'] = 'many';
}
if (isset($relation['type']) && $relation['type']) {
$relation['type'] = $relation['type'] === 'one' ? Doctrine_Relation::ONE : Doctrine_Relation::MANY;
} else {
$relation['type'] = Doctrine_Relation::ONE;
}
if (isset($relation['foreignType']) && $relation['foreignType']) {
$relation['foreignType'] = $relation['foreignType'] === 'one' ? Doctrine_Relation::ONE : Doctrine_Relation::MANY;
}
$relation['key'] = $this->_buildUniqueRelationKey($relation);
$this->_validateSchemaElement('relation', array_keys($relation), $className . '->relation->' . $relation['alias']);
$this->_relations[$className][$alias] = $relation;
}
}
// Now we auto-complete opposite ends of relationships
$this->_autoCompleteOppositeRelations();
// Make sure we do not have any duplicate relations
$this->_fixDuplicateRelations();
// Set the full array of relationships for each class to the final array
foreach ($this->_relations as $className => $relations) {
$array[$className]['relations'] = $relations;
}
return $array;
}
示例9: _processRow
/**
* Process a row and make all the appropriate relations between the imported data
*
* @param string $rowKey
* @param string $row
* @return void
*/
protected function _processRow($rowKey, $row)
{
$obj = $this->_importedObjects[$rowKey];
foreach ((array) $row as $key => $value) {
if (method_exists($obj, 'set' . Doctrine_Inflector::classify($key))) {
$func = 'set' . Doctrine_Inflector::classify($key);
$obj->{$func}($value);
} else {
if ($obj->getTable()->hasField($key)) {
if ($obj->getTable()->getTypeOf($key) == 'object') {
$value = unserialize($value);
}
$obj->set($key, $value);
} else {
if ($obj->getTable()->hasRelation($key)) {
if (is_array($value)) {
if (isset($value[0]) && !is_array($value[0])) {
foreach ($value as $link) {
if ($obj->getTable()->getRelation($key)->getType() === Doctrine_Relation::ONE) {
$obj->set($key, $this->_getImportedObject($link, $obj, $key, $rowKey));
} else {
if ($obj->getTable()->getRelation($key)->getType() === Doctrine_Relation::MANY) {
$relation = $obj->{$key};
$relation[] = $this->_getImportedObject($link, $obj, $key, $rowKey);
}
}
}
} else {
$obj->{$key}->fromArray($value);
}
} else {
$obj->set($key, $this->_getImportedObject($value, $obj, $key, $rowKey));
}
} else {
try {
$obj->{$key} = $value;
} catch (Exception $e) {
// used for Doctrine plugin methods (Doctrine_Template)
if (is_callable(array($obj, 'set' . Doctrine_Inflector::classify($key)))) {
$func = 'set' . Doctrine_Inflector::classify($key);
$obj->{$func}($value);
} else {
throw new Doctrine_Data_Exception('Invalid fixture element "' . $key . '" under "' . $rowKey . '"');
}
}
}
}
}
}
}
示例10: generateMigrationClass
/**
* generateMigrationClass
*
* @return void
*/
public function generateMigrationClass($className, $options = array(), $up = null, $down = null, $return = false)
{
$className = Doctrine_Inflector::urlize($className);
$className = str_replace('-', '_', $className);
$className = Doctrine_Inflector::classify($className);
if ($return || !$this->getMigrationsPath()) {
return $this->buildMigrationClass($className, null, $options, $up, $down);
} else {
if (!$this->getMigrationsPath()) {
throw new Doctrine_Migration_Exception('You must specify the path to your migrations.');
}
$next = (string) $this->migration->getNextVersion();
$fileName = str_repeat('0', 3 - strlen($next)) . $next . '_' . Doctrine_Inflector::tableize($className) . $this->suffix;
$class = $this->buildMigrationClass($className, $fileName, $options, $up, $down);
$path = $this->getMigrationsPath() . DIRECTORY_SEPARATOR . $fileName;
if (class_exists($className) || file_exists($path)) {
return false;
}
file_put_contents($path, $class);
return true;
}
}
示例11: set
/**
* set
* method for altering properties and Doctrine_Record references
* if the load parameter is set to false this method will not try to load uninitialized record data
*
* @param mixed $name name of the property or reference
* @param mixed $value value of the property or reference
* @param boolean $load whether or not to refresh / load the uninitialized record data
*
* @throws Doctrine_Record_Exception if trying to set a value for unknown property / related component
* @throws Doctrine_Record_Exception if trying to set a value of wrong type for related component
*
* @return Doctrine_Record
*/
public function set($fieldName, $value, $load = true)
{
if ($this->_table->getAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE)) {
$componentName = $this->_table->getComponentName();
$mutator = isset(self::$_customMutators[$componentName][$fieldName]) ? self::$_customMutators[$componentName][$fieldName] : 'set' . Doctrine_Inflector::classify($fieldName);
if (isset(self::$_customMutators[$componentName][$fieldName]) || method_exists($this, $mutator)) {
self::$_customMutators[$componentName][$fieldName] = $mutator;
return $this->{$mutator}($value, $load);
}
}
return $this->_set($fieldName, $value, $load);
}
示例12: _getTaskClassFromArgs
/**
* Old method retained for backwards compatibility
*
* @deprecated
*/
protected function _getTaskClassFromArgs(array $args)
{
return self::TASK_BASE_CLASS . '_' . Doctrine_Inflector::classify(str_replace('-', '_', $args[1]));
}
示例13: importSchema
/**
* importSchema
*
* method for importing existing schema to Doctrine_Record classes
*
* @param string $directory
* @param array $databases
* @return array the names of the imported classes
*/
public function importSchema($directory, array $databases = array(), array $options = array())
{
$options['singularize'] = !isset($options['singularize']) ? $this->conn->getAttribute('singularize_import') : $options['singularize'];
$connections = Doctrine_Manager::getInstance()->getConnections();
foreach ($connections as $name => $connection) {
// Limit the databases to the ones specified by $databases.
// Check only happens if array is not empty
if (!empty($databases) && !in_array($name, $databases)) {
continue;
}
$builder = new Doctrine_Import_Builder();
$builder->setTargetPath($directory);
$builder->setOptions($options);
$classes = array();
foreach ($connection->import->listTables() as $table) {
$definition = array();
$definition['tableName'] = $table;
// echo $table . "<br />\n";
if (!isset($options['singularize']) || $options['singularize'] !== false) {
$e = explode('_', Doctrine_Inflector::tableize($table));
foreach ($e as $k => $v) {
$e[$k] = Doctrine_Inflector::singularize($v);
}
$classTable = implode('_', $e);
} else {
$classTable = Doctrine_Inflector::tableize($table);
}
$definition['className'] = Doctrine_Inflector::classify($classTable);
$definition['columns'] = $connection->import->listTableColumns($table);
//var_dump ($definition);
$builder->buildRecord($definition);
$classes[] = $definition['className'];
}
}
return $classes;
}
示例14: getIssueFieldName
protected function getIssueFieldName($field)
{
return Doctrine_Inflector::classify(str_replace('_id', '', $field));
}
示例15: _processRow
/**
* Process a row and make all the appropriate relations between the imported data
*
* @param string $rowKey
* @param string $row
* @return void
*/
protected function _processRow($rowKey, $row)
{
$obj = $this->_importedObjects[$rowKey];
foreach ((array) $row as $key => $value) {
// The condition below causes a setter method on a field to be called always, no matter
// if it is really a mutator. I find this behaviour inconsistent/buggy. A corrected version
// of condition and code below closely resembles that of set() of Doctrine_Record.
// -- Jakub Argasiński (argasek@gmail.com):
//
// if (method_exists($obj, 'set' . Doctrine_Inflector::classify($key))) {
// $func = 'set' . Doctrine_Inflector::classify($key);
// $obj->$func($value);
if ($obj->getTable()->getAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE) || $obj->hasMutator($key)) {
$mutator = $obj->hasMutator($key) ? $obj->getMutator($key) : 'set' . Doctrine_Inflector::classify($key);
if ($obj->hasMutator($key) || method_exists($this, $key)) {
$obj->hasMutator($key, $mutator);
return $obj->$mutator($value);
}
} else if ($obj->getTable()->hasField($key)) {
if ($obj->getTable()->getTypeOf($key) == 'object') {
$value = unserialize($value);
}
$obj->set($key, $value);
} else if ($obj->getTable()->hasRelation($key)) {
if (is_array($value)) {
if (isset($value[0]) && ! is_array($value[0])) {
foreach ($value as $link) {
if ($obj->getTable()->getRelation($key)->getType() === Doctrine_Relation::ONE) {
$obj->set($key, $this->_getImportedObject($link, $obj, $key, $rowKey));
} else if ($obj->getTable()->getRelation($key)->getType() === Doctrine_Relation::MANY) {
$relation = $obj->$key;
$relation[] = $this->_getImportedObject($link, $obj, $key, $rowKey);
}
}
} else {
$obj->$key->fromArray($value);
}
} else {
$obj->set($key, $this->_getImportedObject($value, $obj, $key, $rowKey));
}
} else {
try {
$obj->$key = $value;
} catch (Exception $e) {
// used for Doctrine plugin methods (Doctrine_Template)
if (is_callable(array($obj, 'set' . Doctrine_Inflector::classify($key)))) {
$func = 'set' . Doctrine_Inflector::classify($key);
$obj->$func($value);
} else {
throw new Doctrine_Data_Exception('Invalid fixture element "'. $key . '" under "' . $rowKey . '"');
}
}
}
}
}