コード例 #1
0
 /**
  * Get the ModelField from a relation field element
  * @param DOMElement $fieldElement field element in the model element
  * @param zibo\library\filesystem\File $file the file which is being read
  * @param string $modelName the model which is currently being processed
  * @param string $fieldName the field which is currently being processed
  * @param string $relationModelName the name of the model for which this field is a relation
  * @return zibo\library\orm\definition\field\ModelField
  * @throws zibo\library\orm\exception\OrmException when an invalid relation type has been defined
  */
 protected function getRelationFieldFromElement(DOMElement $fieldElement, File $file, $modelName, $fieldName, $relationModelName)
 {
     $relationType = $fieldElement->hasAttribute(self::ATTRIBUTE_RELATION) ? $fieldElement->getAttribute(self::ATTRIBUTE_RELATION) : self::DEFAULT_FIELD_RELATION;
     switch ($relationType) {
         case self::RELATION_BELONGS_TO:
             $field = new BelongsToField($fieldName, $relationModelName);
             break;
         case self::RELATION_HAS_ONE:
             $field = new HasOneField($fieldName, $relationModelName);
             break;
         case self::RELATION_HAS_MANY:
             $field = new HasManyField($fieldName, $relationModelName);
             $relationOrder = $fieldElement->hasAttribute(self::ATTRIBUTE_RELATION_ORDER) ? $fieldElement->getAttribute(self::ATTRIBUTE_RELATION_ORDER) : null;
             $field->setRelationOrder($relationOrder);
             $indexOn = $fieldElement->hasAttribute(self::ATTRIBUTE_INDEX_ON) ? $fieldElement->getAttribute(self::ATTRIBUTE_INDEX_ON) : null;
             $field->setIndexOn($indexOn);
             $linkModelName = $fieldElement->hasAttribute(self::ATTRIBUTE_LINK_MODEL) ? $fieldElement->getAttribute(self::ATTRIBUTE_LINK_MODEL) : null;
             $field->setLinkModelName($linkModelName);
             break;
         default:
             throw new OrmException("{$fieldName} of {$modelName} has an invalid relation ({$relationType}) in {$file->getPath()}");
             break;
     }
     $dependant = $fieldElement->hasAttribute(self::ATTRIBUTE_DEPENDANT) ? Boolean::getBoolean($fieldElement->getAttribute(self::ATTRIBUTE_DEPENDANT)) : false;
     $field->setIsDependant($dependant);
     $foreignKey = $fieldElement->hasAttribute(self::ATTRIBUTE_FOREIGN_KEY) ? $fieldElement->getAttribute(self::ATTRIBUTE_FOREIGN_KEY) : null;
     if ($foreignKey) {
         $field->setForeignKeyName($foreignKey);
     }
     return $field;
 }
コード例 #2
0
 /**
  * @dataProvider providerSetIndexOnThrowsExceptionWhenIndexIsInvalid
  * @expectedException zibo\ZiboException
  */
 public function testSetIndexOnThrowsExceptionWhenIndexIsInvalid($value)
 {
     $field = new HasManyField('name', 'model');
     $field->setIndexOn($value);
 }