예제 #1
0
파일: PerfORM.php 프로젝트: Edke/PerfORM
 /**
  * Getter for field with name $name
  * @return Field
  */
 public function getField($name, $includeExtends = false)
 {
     if (key_exists($name, $this->fields)) {
         return $this->fields[$name];
     } elseif ($this->isExtended() and $includeExtends) {
         $result = $this->extends->getField($name, true);
         return $result;
     } else {
         throw new Exception("field '{$name}' does not exists");
     }
 }
예제 #2
0
파일: QuerySet.php 프로젝트: Edke/PerfORM
 /**
  * Finds field object from relation notation
  * @param string $sourceField
  * @return Field
  */
 protected function fieldLookup($sourceField)
 {
     if (preg_match("#^(id|pk)\$#i", $sourceField, $_match)) {
         if ($this->model->getPrimaryKey() or $this->model->hasField('id')) {
             return $_match[1] == 'pk' ? $this->model->getField($this->getModel()->getPrimaryKey()) : $this->model->getField($_match[1]);
         } else {
             throw new Exception('Model does not have primary key nor id field');
         }
     } elseif (preg_match("#^[a-z0-9]+(__([a-z0-9_]+))+\$#i", $sourceField, $_match)) {
         return $this->getModel()->pathLookup($sourceField);
     } elseif (!preg_match("#__#", $sourceField) && $this->getModel()->hasField($sourceField)) {
         return $this->getModel()->getField($sourceField, true);
     } else {
         throw new Exception("Unable to translate field '{$sourceField}'.");
     }
 }