当前位置: 首页>>代码示例>>PHP>>正文


PHP fGrammar::singularize方法代码示例

本文整理汇总了PHP中fGrammar::singularize方法的典型用法代码示例。如果您正苦于以下问题:PHP fGrammar::singularize方法的具体用法?PHP fGrammar::singularize怎么用?PHP fGrammar::singularize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fGrammar的用法示例。


在下文中一共展示了fGrammar::singularize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: replicate

 /**
  * Generates a clone of the current record, removing any auto incremented primary key value and allowing for replicating related records
  * 
  * This method will accept three different sets of parameters:
  * 
  *  - No parameters: this object will be cloned
  *  - A single `TRUE` value: this object plus all many-to-many associations and all child records (recursively) will be cloned
  *  - Any number of plural related record class names: the many-to-many associations or child records that correspond to the classes specified will be cloned
  * 
  * The class names specified can be a simple class name if there is only a
  * single route between the two corresponding database tables. If there is 
  * more than one route between the two tables, the class name should be
  * substituted with a string in the format `'RelatedClass{route}'`.
  * 
  * @param  string $related_class  The plural related class to replicate - see method description for details
  * @param  string ...
  * @return fActiveRecord  The cloned record
  */
 public function replicate($related_class = NULL)
 {
     fORM::callHookCallbacks($this, 'pre::replicate()', $this->values, $this->old_values, $this->related_records, $this->cache, fActiveRecord::$replicate_level);
     fActiveRecord::$replicate_level++;
     $class = get_class($this);
     $hash = self::hash($this->values, $class);
     $schema = fORMSchema::retrieve($class);
     $table = fORM::tablize($class);
     // If the object has not been replicated yet, do it now
     if (!isset(fActiveRecord::$replicate_map[$class])) {
         fActiveRecord::$replicate_map[$class] = array();
     }
     if (!isset(fActiveRecord::$replicate_map[$class][$hash])) {
         fActiveRecord::$replicate_map[$class][$hash] = clone $this;
         // We need the primary key to get a hash, otherwise certain recursive relationships end up losing members
         $pk_columns = $schema->getKeys($table, 'primary');
         if (sizeof($pk_columns) == 1 && $schema->getColumnInfo($table, $pk_columns[0], 'auto_increment')) {
             fActiveRecord::$replicate_map[$class][$hash]->values[$pk_columns[0]] = $this->values[$pk_columns[0]];
         }
     }
     $clone = fActiveRecord::$replicate_map[$class][$hash];
     $parameters = func_get_args();
     $recursive = FALSE;
     $many_to_many_relationships = $schema->getRelationships($table, 'many-to-many');
     $one_to_many_relationships = $schema->getRelationships($table, 'one-to-many');
     // When just TRUE is passed we recursively replicate all related records
     if (sizeof($parameters) == 1 && $parameters[0] === TRUE) {
         $parameters = array();
         $recursive = TRUE;
         foreach ($many_to_many_relationships as $relationship) {
             $parameters[] = fGrammar::pluralize(fORM::classize($relationship['related_table'])) . '{' . $relationship['join_table'] . '}';
         }
         foreach ($one_to_many_relationships as $relationship) {
             $parameters[] = fGrammar::pluralize(fORM::classize($relationship['related_table'])) . '{' . $relationship['related_column'] . '}';
         }
     }
     $record_sets = array();
     foreach ($parameters as $parameter) {
         // Parse the Class{route} strings
         if (strpos($parameter, '{') !== FALSE) {
             $brace = strpos($parameter, '{');
             $related_class = fGrammar::singularize(substr($parameter, 0, $brace));
             $related_class = fORM::getRelatedClass($class, $related_class);
             $related_table = fORM::tablize($related_class);
             $route = substr($parameter, $brace + 1, -1);
         } else {
             $related_class = fGrammar::singularize($parameter);
             $related_class = fORM::getRelatedClass($class, $related_class);
             $related_table = fORM::tablize($related_class);
             $route = fORMSchema::getRouteName($schema, $table, $related_table);
         }
         // Determine the kind of relationship
         $many_to_many = FALSE;
         $one_to_many = FALSE;
         foreach ($many_to_many_relationships as $relationship) {
             if ($relationship['related_table'] == $related_table && $relationship['join_table'] == $route) {
                 $many_to_many = TRUE;
                 break;
             }
         }
         foreach ($one_to_many_relationships as $relationship) {
             if ($relationship['related_table'] == $related_table && $relationship['related_column'] == $route) {
                 $one_to_many = TRUE;
                 break;
             }
         }
         if (!$many_to_many && !$one_to_many) {
             throw new fProgrammerException('The related class specified, %1$s, does not appear to be in a many-to-many or one-to-many relationship with %$2s', $parameter, get_class($this));
         }
         // Get the related records
         $record_set = fORMRelated::buildRecords($class, $this->values, $this->related_records, $related_class, $route);
         // One-to-many records need to be replicated, possibly recursively
         if ($one_to_many) {
             if ($recursive) {
                 $records = $record_set->call('replicate', TRUE);
             } else {
                 $records = $record_set->call('replicate');
             }
             $record_set = fRecordSet::buildFromArray($related_class, $records);
             $record_set->call('set' . fGrammar::camelize($route, TRUE), NULL);
         }
         // Cause the related records to be associated with the new clone
//.........这里部分代码省略.........
开发者ID:mrjwc,项目名称:printmaster,代码行数:101,代码来源:fActiveRecord.php

示例2: classize

 /**
  * Takes a table and turns it into a class name - uses custom mapping if set
  *
  * @param  string $table  The table name
  * @return string  The class name
  */
 public static function classize($table)
 {
     if (!($class = array_search($table, self::$class_table_map))) {
         $class = fGrammar::camelize(fGrammar::singularize($table), TRUE);
         self::$class_table_map[$class] = $table;
     }
     return $class;
 }
开发者ID:gopalgrover23,项目名称:flourish-classes,代码行数:14,代码来源:fORM.php

示例3: __call

 /**
  * Allows for preloading various data related to the record set in single database queries, as opposed to one query per record
  * 
  * This method will handle methods in the format `verbRelatedRecords()` for
  * the verbs `build`, `prebuild`, `precount` and `precreate`.
  * 
  * `build` calls `create{RelatedClass}()` on each record in the set and
  * returns the result as a new record set. The relationship route can be
  * passed as an optional parameter.
  * 
  * `prebuild` builds *-to-many record sets for all records in the record
  * set. `precount` will count records in *-to-many record sets for every
  * record in the record set. `precreate` will create a *-to-one record
  * for every record in the record set.
  *  
  * @param  string $method_name  The name of the method called
  * @param  string $parameters   The parameters passed
  * @return void
  */
 public function __call($method_name, $parameters)
 {
     if ($callback = fORM::getRecordSetMethod($method_name)) {
         return call_user_func_array($callback, array($this, $this->class, &$this->records, $method_name, $parameters));
     }
     list($action, $subject) = fORM::parseMethod($method_name);
     $route = $parameters ? $parameters[0] : NULL;
     // This check prevents fGrammar exceptions being thrown when an unknown method is called
     if (in_array($action, array('build', 'prebuild', 'precount', 'precreate'))) {
         $related_class = fGrammar::singularize($subject);
         $related_class_sans_namespace = $related_class;
         if (!is_array($this->class)) {
             $related_class = fORM::getRelatedClass($this->class, $related_class);
         }
     }
     switch ($action) {
         case 'build':
             if ($route) {
                 $this->precreate($related_class, $route);
                 return $this->buildFromCall('create' . $related_class_sans_namespace, $route);
             }
             $this->precreate($related_class);
             return $this->buildFromCall('create' . $related_class_sans_namespace);
         case 'prebuild':
             return $this->prebuild($related_class, $route);
         case 'precount':
             return $this->precount($related_class, $route);
         case 'precreate':
             return $this->precreate($related_class, $route);
     }
     throw new fProgrammerException('Unknown method, %s(), called', $method_name);
 }
开发者ID:JhunCabas,项目名称:material-management,代码行数:51,代码来源:fRecordSet.php

示例4: testSingularize

 /**
  * @dataProvider singularizePluralizeProvider
  */
 public function testSingularize($input, $output)
 {
     $this->assertEquals($output, fGrammar::singularize($input));
 }
开发者ID:nurulimamnotes,项目名称:flourish-old,代码行数:7,代码来源:fGrammarTest.php


注:本文中的fGrammar::singularize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。