Spot\Mapper::save PHP Метод

save() публичный Метод

Save record Will update if primary key found, insert if not Performs validation automatically before saving record
public save ( EntityInterface $entity, array $options = [] )
$entity EntityInterface Entity object
$options array
    public function save(EntityInterface $entity, array $options = [])
    {
        // Check entity name
        $entityName = $this->entity();
        if (!$entity instanceof $entityName) {
            throw new \InvalidArgumentException("Provided entity must be instance of " . $entityName . ", instance of " . get_class($entity) . " given.");
        }
        if ($entity->isNew()) {
            $result = $this->insert($entity, $options);
        } else {
            $result = $this->update($entity, $options);
        }
        return $result;
    }

Usage Example

Пример #1
0
 /**
  * @param Talk $talk
  *
  * @return mixed
  */
 public function persist(Talk $talk)
 {
     $this->mapper->save($talk);
 }