/**
  * @dataProvider providerSetWillBlockDeleteWhenUsedThrowsExceptionWhenNoBooleanPassed
  * @expectedException zibo\ZiboException
  */
 public function testSetWillBlockDeleteWhenUsedThrowsExceptionWhenNoBooleanPassed($flag)
 {
     $table = new ModelTable('table');
     $table->setWillBlockDeleteWhenUsed($flag);
 }
 /**
  * Copies a model table into another
  * @param zibo\library\orm\definition\ModelTable $source
  * @param zibo\library\orm\definition\ModelTable $destination
  * @return null
  */
 private function copyModel(ModelTable $source, ModelTable $destination)
 {
     $destination->setWillBlockDeleteWhenUsed($source->willBlockDeleteWhenUsed);
     $fields = $source->getFields();
     foreach ($fields as $field) {
         if ($field->getName() == ModelTable::PRIMARY_KEY) {
             continue;
         }
         $destination->addField($field);
     }
     $indexes = $source->getIndexes();
     foreach ($indexes as $index) {
         $destination->addIndex($index);
     }
     $dataFormats = $source->getDataFormats();
     foreach ($dataFormats as $name => $format) {
         $destination->setDataFormat($name, $format);
     }
 }
Beispiel #3
0
 /**
  * Get the model from the model element
  * @param DOMElement $modelElement model element in the xml root element
  * @param zibo\library\filesystem\File $file the file which is being read
  * @return zibo\library\orm\Model Model instance created from the read model definition
  * @throws zibo\library\orm\exception\OrmException when the model element has no name attribute
  */
 protected function getModelFromElement(DOMElement $modelElement, File $file)
 {
     $modelName = $modelElement->getAttribute(self::ATTRIBUTE_NAME);
     if ($modelName == null) {
         throw new OrmException('No ' . self::ATTRIBUTE_NAME . ' attribute found for ' . self::TAG_MODEL . ' tag in ' . $file->getPath());
     }
     $group = $modelElement->getAttribute(self::ATTRIBUTE_GROUP) ? $modelElement->getAttribute(self::ATTRIBUTE_GROUP) : null;
     $modelClassName = $modelElement->hasAttribute(self::ATTRIBUTE_MODEL_CLASS) ? $modelElement->getAttribute(self::ATTRIBUTE_MODEL_CLASS) : ModelManager::DEFAULT_MODEL;
     $dataClassName = $modelElement->hasAttribute(self::ATTRIBUTE_DATA_CLASS) ? $modelElement->getAttribute(self::ATTRIBUTE_DATA_CLASS) : ModelMeta::CLASS_DATA;
     $isLogged = $modelElement->getAttribute(self::ATTRIBUTE_LOG) ? Boolean::getBoolean($modelElement->getAttribute(self::ATTRIBUTE_LOG)) : false;
     $willBlockDeleteWhenUsed = $modelElement->getAttribute(self::ATTRIBUTE_WILL_BLOCK_DELETE) ? Boolean::getBoolean($modelElement->getAttribute(self::ATTRIBUTE_WILL_BLOCK_DELETE)) : false;
     $modelTable = new ModelTable($modelName, $isLogged);
     $modelTable->setGroup($group);
     $modelTable->setWillBlockDeleteWhenUsed($willBlockDeleteWhenUsed);
     $fields = $this->getFieldsFromElement($modelElement, $file, $modelName);
     foreach ($fields as $field) {
         $modelTable->addField($field);
     }
     $this->setIndexesFromElement($modelElement, $modelTable);
     $this->setFormatsFromElement($modelElement, $modelTable);
     $modelMeta = new ModelMeta($modelTable, $dataClassName);
     $objectFactory = new ObjectFactory();
     return $objectFactory->create($modelClassName, ModelManager::INTERFACE_MODEL, array($modelMeta));
 }