Esempio n. 1
0
 /**
  * @param  array|string $identifier
  * @param  array|string $oldIdentifier
  * @throws Record\RecordException
  */
 public function assignIdentifier($identifier, $oldIdentifier = null)
 {
     $identifierFields = $this->_table->getIdentifierFields();
     $identifier = array_combine($identifierFields, (array) $identifier);
     if (count($identifier) != count($identifierFields)) {
         throw new RecordException("Identifier '" . implode(self::COMPOSITE_ID_SEPARATOR, $identifier) . "' does not match table identifier!");
     }
     foreach ($identifier as $fieldName => $id) {
         $this->_data[$fieldName] = $id;
     }
     $newIdentifierAsString = implode(self::COMPOSITE_ID_SEPARATOR, $identifier);
     $oldIdentifierAsString = is_string($oldIdentifier) ? $oldIdentifier : implode(self::COMPOSITE_ID_SEPARATOR, $oldIdentifier);
     $relations = $this->_table->getRelations();
     foreach ($relations as $relationName => $relation) {
         $relation->updateRecordIdentifier($this, $relationName, $newIdentifierAsString, $oldIdentifierAsString);
     }
     $this->_modifiedFields = array();
     $this->_exists = true;
     $repository = $this->_table->getRepository();
     $repository->refreshIdentity($this, $oldIdentifierAsString);
 }
Esempio n. 2
0
 /**
  * @param  Table $table
  * @param  array $identifier
  * @throws InvalidArgumentException
  */
 private static function throwExceptionIfIdentifierDoesNotMatchTableIdentifier(Table $table, array $identifier)
 {
     $identifierFields = $table->getIdentifierFields();
     if (count($identifierFields) != count($identifier)) {
         throw new InvalidArgumentException("Identifier '" . implode(',', $identifier) . "'" . ' does not match table identifier (' . implode(', ', $identifierFields) . ')');
     }
 }