Exemplo n.º 1
0
 /**
  * Removes a stored option.
  *
  * @param  string $name The name of the option to be removed.
  * @throws \InvalidArgumentException
  */
 public function remove($name)
 {
     $name = trim($name);
     if (in_array($name, $this->protected)) {
         throw new \InvalidArgumentException(sprintf('"%s" is a protected option and may not be modified.', $name));
     }
     if (!$this->connection->isConnected()) {
         throw new \RuntimeException('Database is not connected.');
     }
     $this->initialize(true);
     if ($this->connection->delete($this->table, ['name' => $name])) {
         unset($this->options[$name]);
         $this->cache->delete($this->prefix . (isset($this->autoload[$name]) ? 'Autoload' : $name));
     }
 }
Exemplo n.º 2
0
 /**
  * Deletes an entity.
  *
  * @param  object $entity
  * @throws \InvalidArgumentException
  */
 public function delete($entity)
 {
     $metadata = $this->getMetadata($entity);
     $identifier = $metadata->getIdentifier(true);
     switch ($state = $this->getEntityState($entity)) {
         case self::STATE_MANAGED:
             $this->dispatchEvent(Events::preDelete, $entity, $metadata);
             if (!($value = $metadata->getValue($entity, $identifier, true))) {
                 throw new \InvalidArgumentException("Can't remove entity with empty identifier value.");
             }
             $this->connection->delete($metadata->getTable(), [$identifier => $value]);
             $this->entities->remove($entity);
             $this->dispatchEvent(Events::postDelete, $entity, $metadata);
             $metadata->setValue($entity, $identifier, null, true);
             break;
         case self::STATE_DETACHED:
             throw new \InvalidArgumentException("Detached entity can not be removed");
         default:
             throw new \InvalidArgumentException(sprintf("Unexpected entity state: %s.", $state));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function write($id, $data)
 {
     try {
         $params = ['id' => $id, 'data' => base64_encode($data), 'time' => date('Y-m-d H:i:s')];
         if (null !== ($sql = $this->getMergeSql())) {
             $this->connection->executeQuery($sql, $params);
             return true;
         }
         $this->connection->beginTransaction();
         try {
             $this->connection->delete($this->table, ['id' => $id]);
             $this->connection->insert($this->table, $params);
             $this->connection->commit();
         } catch (ConnectionException $e) {
             $this->connection->rollback();
             throw $e;
         }
     } catch (\PDOException $e) {
         throw new \RuntimeException(sprintf('PDOException was thrown when trying to write the session data: %s', $e->getMessage()), 0, $e);
     }
     return true;
 }