예제 #1
0
 /**
  * Takes information from a method call and determines the subject, route and if subject was plural
  * 
  * @param string $class    The class the method was called on
  * @param string $subject  An underscore_notation subject - either a singular or plural class name
  * @param string $route    The route to the subject
  * @return array  An array with the structure: array(0 => $subject, 1 => $route, 2 => $plural)
  */
 private static function determineSubject($class, $subject, $route)
 {
     $schema = fORMSchema::retrieve($class);
     $table = fORM::tablize($class);
     $type = '*-to-many';
     $plural = FALSE;
     // one-to-many relationships need to use plural forms
     $singular_form = fGrammar::singularize($subject, TRUE);
     if ($singular_form && fORM::isClassMappedToTable($singular_form)) {
         $subject = $singular_form;
         $plural = TRUE;
     } elseif (!fORM::isClassMappedToTable($subject) && in_array(fGrammar::underscorize($subject), $schema->getTables())) {
         $subject = fGrammar::singularize($subject);
         $plural = TRUE;
     }
     $related_table = fORM::tablize($subject);
     $one_to_one = fORMSchema::isOneToOne($schema, $table, $related_table, $route);
     if ($one_to_one) {
         $type = 'one-to-one';
     }
     if ($one_to_one && $plural || !$plural && !$one_to_one) {
         throw new fProgrammerException('The table %1$s is not in a %2$srelationship with the table %3$s', $table, $type, $related_table);
     }
     $route = fORMSchema::getRouteName($schema, $table, $related_table, $route, $type);
     return array($subject, $route, $plural);
 }