Пример #1
0
 /**
  * Get or set the relation identified by its name.
  *
  * If second parameter is null, it works like a getter.
  * It works like a setter if second parameter is not null.
  *
  * @param $name     The name of the relation.
  * @param $relation The relation to set instead
  *
  * @return object A Relation object.
  * @throw SimpleAR\Exception if used as getter and $relationName is unknown.
  */
 public static function relation($name, Relation $relation = null)
 {
     if ($relation === null) {
         if (!isset(static::$_relations[$name])) {
             throw new Exception('Relation "' . $name . '" does not exist for class "' . get_called_class() . '".');
         }
         // Avoid array accesses.
         $val =& static::$_relations[$name];
         // If relation is not yet initlialized, do it.
         if (!$val instanceof Relation) {
             $val = Relation::forge($name, $val, get_called_class());
         }
         // Return the Relation object.
         return $val;
     } else {
         static::$_relations[$name] = $relation;
     }
 }