Example #1
0
 /**
  * Builds a mysqli table metadata from an entity class
  * @param $class string
  * @return Table
  */
 public function build($class)
 {
     $class = $this->trimClassName($class);
     if (!is_string($class)) {
         throw new \InvalidArgumentException("argument needs to be a class string");
     }
     if (array_key_exists($class, $this->tables)) {
         return $this->tables[$class];
     }
     $reflectedEntity = new ReflectionClass($class);
     $table = new Table($reflectedEntity, $this);
     $this->tables[$class] = $table;
     $table->setName($this->getTableName($reflectedEntity));
     $this->addTableFields($reflectedEntity, $table);
     return $table;
 }
 public function testGetDeleteSQLOnNotAnnotatedEntity()
 {
     $this->notAnnotatedTest->setId(1);
     $sql = $this->notAnnotatedTableData->getDeleteSQL($this->notAnnotatedTest);
     $this->assertEqualsFixture($sql, __FUNCTION__);
     $this->runQuery($sql);
 }
Example #3
0
 /**
  * @param $parentEntity object
  * @param $parentField TableField
  * @return bool
  */
 private function handleOneToManyChanges($parentEntity, $parentField)
 {
     $newEntityValues = $this->table->getPropertyValue($parentEntity, $parentField);
     if ($newEntityValues == null || $newEntityValues instanceof CollectionProxy) {
         $newEntityValues = array();
     }
     $buffer = array();
     foreach ($newEntityValues as $key => $child) {
         $id = $this->daoFactory->getDaoFromEntity($child)->getIdValue($child);
         if ($id == null) {
             $id = uniqid(self::TRANSIENT_PREFIX);
         }
         $buffer[$id] = $child;
     }
     $newEntityValues = $buffer;
     $oldEntityValues = $this->table->getPropertyValue($this->getCache($parentEntity), $parentField);
     if ($oldEntityValues == null) {
         $oldEntityValues = array();
     }
     $buffer = array();
     foreach ($oldEntityValues as $key => $child) {
         unset($oldEntityValues[$key]);
         if (!$child instanceof stdClass) {
             $child = $this->getCacheValue($child);
         }
         $buffer[$child->{Dao::ID}] = $child;
     }
     $oldEntityValues = $buffer;
     $valuesAdded = array_diff_key($newEntityValues, $oldEntityValues);
     $valuesDeleted = array_diff_key($oldEntityValues, $newEntityValues);
     foreach ($valuesAdded as $value) {
         $this->persistReferencedEntity($parentEntity, $value, $parentField);
     }
     foreach ($valuesDeleted as $value) {
         $dao = $this->daoFactory->getDaoFromEntity($value->{Dao::TYPE});
         $dao->delete($value->{Dao::ID});
     }
 }