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


PHP fGrammar::pluralize方法代码示例

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


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

示例1: populateRelated

 protected function populateRelated($recursive = false)
 {
     if ($recursive) {
         $one_to_many_relationships = $schema->getRelationships($table, 'one-to-many');
         foreach ($one_to_many_relationships as $relationship) {
             $route_name = fORMSchema::getRouteNameFromRelationship('one-to-many', $relationship);
             $related_class = fORM::classize($relationship['related_table']);
             $method = 'populate' . fGrammar::pluralize($related_class);
             $this->{$method}(TRUE, $route_name);
         }
         $one_to_one_relationships = $schema->getRelationships($table, 'one-to-one');
         foreach ($one_to_one_relationships as $relationship) {
             $route_name = fORMSchema::getRouteNameFromRelationship('one-to-one', $relationship);
             $related_class = fORM::classize($relationship['related_table']);
             $this->__call('populate' . $related_class, array(TRUE, $route_name));
         }
     }
     return $this;
 }
开发者ID:pmanterys,项目名称:wp-mw-newsletter,代码行数:19,代码来源:AbstractModel.php

示例2: 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

示例3: reflect


//.........这里部分代码省略.........
         $related_class = fORM::classize($relationship['related_table']);
         $related_class = fORM::getRelatedClass($class, $related_class);
         if (isset($to_many_created[$related_class])) {
             continue;
         }
         $routes = fORMSchema::getRoutes($schema, $table, $relationship['related_table'], '*-to-many');
         $route_names = array();
         $many_to_many_route_names = array();
         $one_to_many_route_names = array();
         foreach ($routes as $route) {
             if (isset($route['join_table'])) {
                 $route_name = fORMSchema::getRouteNameFromRelationship('many-to-many', $route);
                 $route_names[] = $route_name;
                 $many_to_many_route_names[] = $route_name;
             } else {
                 $route_name = fORMSchema::getRouteNameFromRelationship('one-to-many', $route);
                 $route_names[] = $route_name;
                 $one_to_many_route_names[] = $route_name;
             }
         }
         if ($one_to_many_route_names) {
             $signature = '';
             if ($include_doc_comments) {
                 $related_table = fORM::tablize($related_class);
                 $signature .= "/**\n";
                 $signature .= " * Calls the ::populate() method for multiple child " . $related_class . " records. Uses request value arrays in the form " . $related_table . "::{column_name}[].\n";
                 $signature .= " * \n";
                 if (sizeof($one_to_many_route_names) > 1) {
                     $signature .= " * @param  string \$route  The route to the related class. Must be one of: '" . join("', '", $one_to_many_route_names) . "'.\n";
                 }
                 $signature .= " * @return fActiveRecord  The record object, to allow for method chaining\n";
                 $signature .= " */\n";
             }
             $populate_related_method = 'populate' . fGrammar::pluralize($related_class);
             $signature .= 'public function ' . $populate_related_method . '(';
             if (sizeof($one_to_many_route_names) > 1) {
                 $signature .= '$route';
             }
             $signature .= ')';
             $signatures[$populate_related_method] = $signature;
         }
         if ($many_to_many_route_names) {
             $signature = '';
             if ($include_doc_comments) {
                 $related_table = fORM::tablize($related_class);
                 $signature .= "/**\n";
                 $signature .= " * Creates entries in the appropriate joining table to create associations with the specified " . $related_class . " records. Uses request value array(s) in the form " . $related_table . "::{primary_key_column_name(s)}[].\n";
                 $signature .= " * \n";
                 if (sizeof($many_to_many_route_names) > 1) {
                     $signature .= " * @param  string \$route  The route to the related class. Must be one of: '" . join("', '", $many_to_many_route_names) . "'.\n";
                 }
                 $signature .= " * @return fActiveRecord  The record object, to allow for method chaining\n";
                 $signature .= " */\n";
             }
             $link_related_method = 'link' . fGrammar::pluralize($related_class);
             $signature .= 'public function ' . $link_related_method . '(';
             if (sizeof($many_to_many_route_names) > 1) {
                 $signature .= '$route';
             }
             $signature .= ')';
             $signatures[$link_related_method] = $signature;
             $signature = '';
             if ($include_doc_comments) {
                 $related_table = fORM::tablize($related_class);
                 $signature .= "/**\n";
                 $signature .= " * Creates entries in the appropriate joining table to create associations with the specified " . $related_class . " records\n";
开发者ID:alandsidel,项目名称:flourish-classes,代码行数:67,代码来源:fORMRelated.php

示例4: tossIfEmpty

 /**
  * Throws an fEmptySetException if the record set is empty
  * 
  * @throws fEmptySetException  When there are no record in the set
  * 
  * @param  string $message  The message to use for the exception if there are no records in this set
  * @return fRecordSet  The record set object, to allow for method chaining
  */
 public function tossIfEmpty($message = NULL)
 {
     if ($this->records) {
         return $this;
     }
     if ($message === NULL) {
         if (is_array($this->class)) {
             $names = array_map(array('fORM', 'getRecordName'), $this->class);
             $names = array_map(array('fGrammar', 'pluralize'), $names);
             $name = join(', ', $names);
         } else {
             $name = fGrammar::pluralize(fORM::getRecordName($this->class));
         }
         $message = self::compose('No %s could be found', $name);
     }
     throw new fEmptySetException($message);
 }
开发者ID:JhunCabas,项目名称:material-management,代码行数:25,代码来源:fRecordSet.php

示例5: checkRelatedOneOrMoreRule

 /**
  * Validates against a *-to-many one or more rule
  *
  * @param  fActiveRecord $object            The object being checked
  * @param  array         &$values           The values for the object
  * @param  array         &$related_records  The related records for the object
  * @param  string        $related_class     The name of the related class
  * @param  string        $route             The name of the route from the class to the related class
  * @return string  An error message for the rule
  */
 private static function checkRelatedOneOrMoreRule($object, &$values, &$related_records, $related_class, $route)
 {
     $related_table = fORM::tablize($related_class);
     $class = get_class($object);
     $exists = $object->exists();
     $records_are_set = isset($related_records[$related_table][$route]);
     $has_records = $records_are_set && $related_records[$related_table][$route]['count'];
     if ($exists && (!$records_are_set || $has_records)) {
         return;
     }
     if (!$exists && $has_records) {
         return;
     }
     return self::compose('%sPlease select at least one', fValidationException::formatField(fGrammar::pluralize(fORMRelated::getRelatedRecordName($class, $related_class, $route))));
 }
开发者ID:alandsidel,项目名称:flourish-classes,代码行数:25,代码来源:fORMValidation.php

示例6: tablize

 /**
  * Takes a class name (or class) and turns it into a table name - Uses custom mapping if set
  *
  * @param  string $class  The class name
  * @return string  The table name
  */
 public static function tablize($class)
 {
     if (!isset(self::$class_table_map[$class])) {
         self::$class_table_map[$class] = fGrammar::underscorize(fGrammar::pluralize(preg_replace('#^.*\\\\#', '', $class)));
     }
     return self::$class_table_map[$class];
 }
开发者ID:gopalgrover23,项目名称:flourish-classes,代码行数:13,代码来源:fORM.php

示例7: testPluralizer

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

示例8: tablize

 /**
  * Takes a class name (or class) and turns it into a table name - Uses custom mapping if set
  * 
  * @param  mixed $class  he class name or instance of the class
  * @return string  The table name
  */
 public static function tablize($class)
 {
     if (!isset(self::$class_table_map[$class])) {
         self::$class_table_map[$class] = fGrammar::underscorize(fGrammar::pluralize($class));
     }
     return self::$class_table_map[$class];
 }
开发者ID:jsuarez,项目名称:MyDesign,代码行数:13,代码来源:fORM.php


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