{@inheritdoc}
@throws \Gamegos\NoSql\Storage\Exception\InvalidKeyException
340081
public function increment($key, $offset = 1, $initial = 0, $expiry = 0)
    {
        $operation = __FUNCTION__;
        $arguments = (new OperationArguments($operation))->setKey($key);
        if (func_num_args() > 1) {
            $arguments->setOffset($offset);
            if (func_num_args() > 2) {
                $arguments->setInitial($initial);
                if (func_num_args() > 3) {
                    $arguments->setExpiry($expiry);
                }
            }
        }
        return $this->doOperation($operation, $arguments);
    }
693966
public function open()
    {
        if ($this->pdo !== null) {
            return;
        }

        if (!empty($this->masters)) {
            $db = $this->getMaster();
            if ($db !== null) {
                $this->pdo = $db->pdo;
                return;
            }

            throw new InvalidConfigException('None of the master DB servers is available.');
        }

        if (empty($this->dsn)) {
            throw new InvalidConfigException('Connection::dsn cannot be empty.');
        }

        $token = 'Opening DB connection: ' . $this->dsn;
        $enableProfiling = $this->enableProfiling;
        try {
            /*Zilf::info($token, __METHOD__);
            if ($enableProfiling) {
                Zilf::beginProfile($token, __METHOD__);
            }*/

            $this->pdo = $this->createPdoInstance();
            $this->initConnection();

            /* if ($enableProfiling) {
                 Zilf::endProfile($token, __METHOD__);
             }*/
        } catch (\PDOException $e) {
            /* if ($enableProfiling) {
                 Zilf::endProfile($token, __METHOD__);
             }*/

            throw new Exception($e->getMessage(), $e->errorInfo, (int)$e->getCode(), $e);
        }
    }
464911
public function validate()
    {
        foreach (func_get_args() as $key) {
            $value = $this->parameters->get($key);
            if (empty($value) && $value !== '0' && $value !== false) {
                throw new InvalidRequestException("The $key parameter is required");
            }
        }
    }
999749
public static function find(...$keys): array
    {
        $keyNames = array_values(static::getInstance()->getPrimaryKey());
        $whereList = [];

        foreach ($keys as $keyValues) {
            $keyValues = (array)$keyValues;
            if (\count($keyValues) !== \count($keyNames)) {
                throw new InvalidPrimaryKeyException(
                    "Invalid columns for the primary key.\n" .
                    "Please check " . static::class . " initialization or usage.\n" .
                    "Settings described at https://github.com/bluzphp/framework/wiki/Db-Table"
                );
            }

            if (array_keys($keyValues)[0] === 0) {
                // for numerical array
                $whereList[] = array_combine($keyNames, $keyValues);
            } else {
                // for assoc array
                $whereList[] = $keyValues;
            }
        }
        return static::findWhere(...$whereList);
    }
677913
private function isValidConfigs(array $configs): void
    {
        $allowedConfigKeys = $this->getAllowedConfigKeys();
        if (!empty($configs)) {
            foreach ($configs as $key => $value) {
                if (!\in_array($key, $allowedConfigKeys, true)) {
                    throw new InvalidKeyException(sprintf(
                        '%s is not a valid key. configs must only contain "%s".',
                        $key,
                        implode(', ', $allowedConfigKeys)
                    ));
                }

                $this->isBool($key, $value);
                $this->isString($key, $value);
                $this->isValidNBest($key, $value);
            }
        }
    }
1184425
public function setType($type = 'string')
    {
        if (!\in_array($type, $this->validTypes, true)) {
            throw new InvalidQueryParameterTypeException($type, $this->validTypes);
        }

        $this->type = $type;
    }
275265
public function validate(...$args)
    {
        foreach ($args as $key) {
            $value = $this->getParameter($key);
            if (!isset($value)) {
                throw new InvalidRequestException("The $key parameter is required");
            }
        }
    }
458299
public function useKeyAsIndexAttribute($key, $normalize = false)
    {
        if (null === $key) {
            $this->indexAttrKey = null;
            return;
        }

        if (true !== $normalize && !$this->isValidNodeName($key)) {
            throw new \InvalidArgumentException(sprintf('%s is an invalid attribute name', $key));
        }

        $this->indexAttrKey = $normalize ? $this->normalizer->normalize($key) : $key;
    }
399601
public function has($key, $mode = self::HAS_EXISTS)
    {
        $key = $this->normalizeKey($key);

        switch ($mode) {
            case self::HAS_EXISTS:
                return array_key_exists($key, $this->data);

            case self::HAS_ISSET:
                return isset($this->data[$key]);

            case self::HAS_NONEMPTY:
                return !empty($this->data[$key]);

            case self::HAS_LENGTH:
                return isset($this->data[$key]) && strlen($this->data[$key]);

            default:
                throw new InvalidArgumentException("Mode {$mode} not supported");
        }
    }
134435
public function getConfig($key = '')
    {
        if (empty($key)) {
            return $this->_config;
        }

        if (!\array_key_exists($key, $this->_config)) {
            throw new InvalidException('Config key is not set: '.$key);
        }

        return $this->_config[$key];
    }
164775
public function delete($key = NULL) {
		$ownerTransaction = FALSE;
		try {
			if ($this->database->getConnection()->getPdo()->inTransaction() === FALSE) {
				$this->database->beginTransaction();
				$ownerTransaction = TRUE;
			}
			if (is_array($key)) {
				$this->buildSql()->wherePrimary($key)->delete();
			} else if (is_int($key)) {
				$row = $this->get($key);
				if ($row) {
					$row->toRow()->delete();
					unset($this->rows[$key]);
				} else {
					throw new \PDOException("Item with primary key " . $key . " not found.");
				}
			} else if ($key === NULL) {
				if ($this->selection) {
					$this->selection->delete();
					$this->rows = array();
				}
			}
			if ($this->database->getConnection()->getPdo()->inTransaction() === TRUE && $ownerTransaction === TRUE) {
				$this->database->commit();
			}
		} catch (\PDOException $e) {
			if ($this->database->getConnection()->getPdo()->inTransaction() === TRUE && $ownerTransaction === TRUE) {
				$this->database->rollBack();
			}
			throw new \PDOException($e->getMessage());
		}
	}
282007
public function execute()
    {
        $aggregate = $this->aggregate;

        $entity = $aggregate->getEntityObject();
        $wrappedEntity = $aggregate->getWrappedEntity();
        $mapper = $aggregate->getMapper();

        if ($mapper->fireEvent('deleting', $wrappedEntity) === false) {
            return false;
        }

        $keyName = $aggregate->getEntityMap()->getKeyName();

        $id = $this->aggregate->getEntityKeyValue();

        if (is_null($id)) {
            throw new MappingException('Executed a delete command on an entity with "null" as primary key');
        }

        $this->query->where($keyName, '=', $id)->delete();

        $mapper->fireEvent('deleted', $wrappedEntity, false);
    }
1036996
public function remove($key)
    {
        if (!$this->has($key)) {
            throw new InvalidException("Field {$key} does not exist");
        }
        unset($this->_data[$key]);

        return $this;
    }
13549
public function data( $key )
    {

        // string, key clause
        if( is_scalar( $key ) ) {

            $dataTypes = $this->dataTypesGet( DataType::PRIMARY_KEYS );
            try {
                $key = array_combine(
                    array_keys( $dataTypes ),
                    explode( Base::KEY_SEPARATOR, $key )
                );
            } catch ( \Exception $e ) {
                throw new BadKeyException(
                    sprintf(
                        "Passed key `%s` needs %d fragments; it has %d",
                        $key,
                        count( $dataTypes ),
                        count( explode( Base::KEY_SEPARATOR, $key ) )
                    )
                );
            }

        // is array
        } elseif( is_array( $key ) and count( $key ) > 0 ) {

            $dataTypes = $this->dataTypesGet( array_keys( $key ) );

        // bad argument
        } else {
            throw new \InvalidArgumentException("Can't lookup data for entity with this argument -> " . print_r( $key, true ) );
        }

        // we got the right amount of keyFragments?
        if( count($key) !== count($dataTypes) ) {
            throw new \InvalidArgumentException(
                sprintf(
                    "The passed key (%s) can't be married to the repository keys (%s). Epic fail.",
                    print_r($key, true),
                    implode(',', array_keys($dataTypes) )
                )
            );
        }

        // build where clause
        $where = array();
        foreach( $dataTypes as $name => $dataType ) {

            $where[] = sprintf(
                "%s = %s",
                $this->db->quoteIdent( $name ),
                $dataType->toQueryTag()
            );
            $data[$name] = $key[$name];

        }

        // build query
        $query = new Query(
            sprintf(
                "SELECT * FROM ONLY %s WHERE %s",
                $this->db->quoteIdent( $this->__get('table') ),
                implode( ' AND ', $where )
            ),
            $data
        );

        $result = $this->db->query( $query );
        $data = $result->fetch( Result::FETCH_SINGLE | Result::FLATTEN_PREVENT );

        return $data;

    }
1086171
protected function _setKeys($keys)
    {
        if (!is_array($keys)) {
            throw new Exception\InvalidArgumentException('Invalid options argument provided to filter');
        }

        foreach ($keys as $type => $key) {
            if (is_file($key) and is_readable($key)) {
                $file = fopen($key, 'r');
                $cert = fread($file, 8192);
                fclose($file);
            } else {
                $cert = $key;
                $key  = count($this->keys[$type]);
            }

            switch ($type) {
                case 'public':
                    $test = openssl_pkey_get_public($cert);
                    if ($test === false) {
                        throw new Exception\InvalidArgumentException("Public key '{$cert}' not valid");
                    }

                    openssl_free_key($test);
                    $this->keys['public'][$key] = $cert;
                    break;
                case 'private':
                    $test = openssl_pkey_get_private($cert, $this->passphrase);
                    if ($test === false) {
                        throw new Exception\InvalidArgumentException("Private key '{$cert}' not valid");
                    }

                    openssl_free_key($test);
                    $this->keys['private'][$key] = $cert;
                    break;
                case 'envelope':
                    $this->keys['envelope'][$key] = $cert;
                    break;
                default:
                    break;
            }
        }

        return $this;
    }
1367183
public function &__get($key)
    {
        $ret = null;

        if ($this->flag == self::ARRAY_AS_PROPS) {
            $ret =& $this->offsetGet($key);

            return $ret;
        }

        if (in_array($key, $this->protectedProperties)) {
            throw new \InvalidArgumentException('$key is a protected property, use a different key');
        }

        return $this->$key;
    }
655326
private function isValidRequestedUserInfo(array $requestedUserInfo): void
    {
        $allowedUserInfo = $this->getAllowedUserInfo();
        foreach ($requestedUserInfo as $userInfo) {
            if (!\in_array($userInfo, $allowedUserInfo, true)) {
                throw new InvalidKeyException(sprintf(
                    '%s is not a valid value. Valid values are "%s".',
                    $userInfo,
                    implode(', ', $allowedUserInfo)
                ));
            }
        }
    }