Esempio n. 1
0
 /**
  * Resolves meta-aliases
  *
  * @param   mixed   $meta
  * @param   string  $field
  * @param   mixed   $value
  * @return  string
  */
 public static function meta_alias($meta, $field, $value = NULL)
 {
     // Allow passing the model name
     if (is_string($meta) or $meta instanceof Jelly_Model) {
         $meta = Jelly::meta($meta);
     }
     // Check for a model operator
     if (substr($field, 0, 1) !== ':') {
         list($model, $field) = explode(':', $field);
         // Append the : back onto $field, it's key for recognizing the alias below
         $field = ':' . $field;
         // We should be able to find a valid meta object here
         if (FALSE == ($meta = Jelly::meta($model))) {
             throw new Kohana_Exception('Meta data for :model was not found while trying to resolve :field', array(':model' => $model, ':field' => $field));
         }
     }
     switch ($field) {
         case ':primary_key':
             $field = $meta->primary_key();
             break;
         case ':name_key':
             $field = $meta->name_key();
             break;
         case ':foreign_key':
             $field = $meta->foreign_key();
             break;
         case ':unique_key':
             $field = Jelly::builder($meta->model())->unique_key($value);
             break;
         default:
             throw new Kohana_Exception('Unknown meta alias :field', array(':field' => $field));
     }
     return $field;
 }