コード例 #1
0
 /**
  * getSignature
  *
  * Compute a unique signature upon entity's values in its primary key. If
  * an empty primary key is provided, null is returned.
  *
  * @static
  * @access public
  * @param  FlexibleEntityInterface  $entity
  * @param  array                    $primary_key
  * @return string
  */
 public static function getSignature(FlexibleEntityInterface $entity, array $primary_key)
 {
     if (count($primary_key) === 0) {
         return null;
     }
     return sha1(sprintf("%s|%s", serialize($entity->fields($primary_key)), get_class($entity)));
 }
コード例 #2
0
ファイル: WriteQueries.php プロジェクト: npanau/ModelManager
 /**
  * insertOne
  *
  * Insert a new entity in the database. The entity is passed by reference.
  * It is updated with values returned by the database (ie, default values).
  *
  * @access public
  * @param  FlexibleEntityInterface  $entity
  * @return Model                    $this
  */
 public function insertOne(FlexibleEntityInterface &$entity)
 {
     $values = $entity->fields(array_intersect(array_keys($this->getStructure()->getDefinition()), array_keys($entity->extract())));
     $sql = strtr("insert into :relation (:fields) values (:values) returning :projection", [':relation' => $this->getStructure()->getRelation(), ':fields' => $this->getEscapedFieldList(array_keys($values)), ':projection' => $this->createProjection()->formatFieldsWithFieldAlias(), ':values' => join(',', $this->getParametersList($values))]);
     $entity = $this->query($sql, array_values($values))->current()->status(FlexibleEntityInterface::STATUS_EXIST);
     return $this;
 }