Removed Closeable interface.

This commit is contained in:
flash 2024-10-19 15:03:23 +00:00
parent 0dbe21683a
commit 010045b14a
27 changed files with 31 additions and 121 deletions

View file

@ -1 +1 @@
0.2410.191450
0.2410.191502

View file

@ -1,7 +1,7 @@
<?php
// ArrayCacheProvider.php
// Created: 2024-04-10
// Updated: 2024-10-02
// Updated: 2024-10-19
namespace Index\Cache\ArrayCache;
@ -74,6 +74,4 @@ class ArrayCacheProvider implements CacheProvider {
public function decrement(string $key, int $amount = 1): int {
return $this->increment($key, $amount * -1);
}
public function close(): void {}
}

View file

@ -1,16 +1,14 @@
<?php
// CacheProvider.php
// Created: 2024-04-10
// Updated: 2024-10-02
// Updated: 2024-10-19
namespace Index\Cache;
use Index\Closeable;
/**
* Represents a cache provider.
*/
interface CacheProvider extends Closeable {
interface CacheProvider {
/**
* Retrieve an item from the cache.
*

View file

@ -1,7 +1,7 @@
<?php
// MemcachedProvider.php
// Created: 2024-04-10
// Updated: 2024-10-02
// Updated: 2024-10-19
namespace Index\Cache\Memcached;
@ -19,9 +19,4 @@ abstract class MemcachedProvider implements CacheProvider {
public abstract function touch(string $key, int $ttl = 0): void;
public abstract function increment(string $key, int $amount = 1): int;
public abstract function decrement(string $key, int $amount = 1): int;
public abstract function close(): void;
public function __destruct() {
$this->close();
}
}

View file

@ -1,7 +1,7 @@
<?php
// MemcachedProviderLegacy.php
// Created: 2024-04-10
// Updated: 2024-10-02
// Updated: 2024-10-19
namespace Index\Cache\Memcached;
@ -91,7 +91,7 @@ class MemcachedProviderLegacy extends MemcachedProvider {
return $result;
}
public function close(): void {
public function __destruct() {
if(!$this->persistent)
$this->memcache->close();
}

View file

@ -1,7 +1,7 @@
<?php
// MemcachedProviderModern.php
// Created: 2024-04-10
// Updated: 2024-10-02
// Updated: 2024-10-19
namespace Index\Cache\Memcached;
@ -111,7 +111,7 @@ class MemcachedProviderModern extends MemcachedProvider {
return $result;
}
public function close(): void {
public function __destruct() {
if(!$this->memcached->isPersistent())
$this->memcached->quit();
}

View file

@ -1,7 +1,7 @@
<?php
// ValkeyProvider.php
// Created: 2024-04-10
// Updated: 2024-10-02
// Updated: 2024-10-19
namespace Index\Cache\Valkey;
@ -72,12 +72,8 @@ class ValkeyProvider implements CacheProvider {
return is_int($result) ? $result : 0;
}
public function close(): void {
public function __destruct() {
if(!$this->persist)
$this->redis->close();
}
public function __destruct() {
$this->close();
}
}

View file

@ -1,30 +0,0 @@
<?php
// Closeable.php
// Created: 2021-04-30
// Updated: 2024-10-02
namespace Index;
/**
* Provides an interface for releasing unmanaged resources.
*
* If Closeable is implemented __destruct() should also be added to the class and should call close in it:
*
* <code>
* public function close(): void {
* fclose($this->resource);
* }
*
* public function __destruct() {
* $this->close();
* }
* </code>
*
* However if close() is only implemented because a parent interface requires it, the __destruct() implementation may be omitted.
*/
interface Closeable {
/**
* Free, release or reset unmanaged resources.
*/
function close(): void;
}

View file

@ -6,12 +6,11 @@
namespace Index\Db;
use RuntimeException;
use Index\Closeable;
/**
* Represents a connection to a database service.
*/
interface DbConnection extends Closeable {
interface DbConnection {
/**
* Returns the ID of the last inserted row.
*

View file

@ -1,16 +1,14 @@
<?php
// DbResult.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db;
use Index\Closeable;
/**
* Represents a database result set.
*/
interface DbResult extends Closeable {
interface DbResult {
/**
* Fetches the next result set.
*

View file

@ -1,18 +1,17 @@
<?php
// DbStatement.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db;
use InvalidArgumentException;
use RuntimeException;
use Index\Closeable;
/**
* Represents a prepared database statement.
*/
interface DbStatement extends Closeable {
interface DbStatement {
/**
* Returns how many parameters there are.
*

View file

@ -1,7 +1,7 @@
<?php
// DbStatementCache.php
// Created: 2023-07-21
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db;
@ -54,8 +54,6 @@ class DbStatementCache {
* Closes all statement instances and resets the cache.
*/
public function clear(): void {
foreach($this->stmts as $stmt)
$stmt->close();
$this->stmts = [];
}
}

View file

@ -6,12 +6,11 @@
namespace Index\Db;
use RuntimeException;
use Index\Closeable;
/**
* Represents a transaction to be performed on the database.
*/
interface DbTransaction extends Closeable {
interface DbTransaction {
/**
* Commits the actions done during a transaction and ends the transaction.
* A new transaction will be started if auto-commit is disabled.

View file

@ -387,16 +387,9 @@ class MariaDbConnection implements DbConnection {
/**
* Closes the connection and associated resources.
*/
public function close(): void {
public function __destruct() {
try {
$this->connection->close();
} catch(\Error $ex) {}
}
/**
* Closes the connection and associated resources.
*/
public function __destruct() {
$this->close();
}
}

View file

@ -1,7 +1,7 @@
<?php
// MariaDbResult.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db\MariaDb;
@ -66,10 +66,4 @@ abstract class MariaDbResult implements DbResult {
public function getValue(int|string $index): mixed {
return $this->currentRow[$index] ?? null;
}
abstract function close(): void;
public function __destruct() {
$this->close();
}
}

View file

@ -1,7 +1,7 @@
<?php
// MariaDbResultLib.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db\MariaDb;
@ -54,7 +54,7 @@ class MariaDbResultLib extends MariaDbResult {
return true;
}
public function close(): void {
public function __destruct() {
try {
$this->result->free_result();
} catch(\Error $ex) {}

View file

@ -1,7 +1,7 @@
<?php
// MariaDbResultNative.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db\MariaDb;
@ -36,7 +36,7 @@ class MariaDbResultNative extends MariaDbResult {
return true;
}
public function close(): void {
public function __destruct() {
try {
$this->result->close();
} catch(\Error $ex) {}

View file

@ -1,7 +1,7 @@
<?php
// MariaDbStatement.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db\MariaDb;
@ -159,12 +159,8 @@ class MariaDbStatement implements DbStatement {
throw new RuntimeException($this->getLastErrorString(), $this->getLastErrorCode());
}
public function close(): void {
$this->statement->close();
}
public function __destruct() {
$this->close();
$this->statement->close();
}
}

View file

@ -40,6 +40,4 @@ class MariaDbTransaction implements DbTransaction {
if(!$this->connRaw->rollback(0, $name))
$this->conn->throwLastError();
}
public function close(): void {}
}

View file

@ -34,6 +34,4 @@ class NullDbConnection implements DbConnection {
public function beginTransaction(): DbTransaction {
return new NullDbTransaction;
}
public function close(): void {}
}

View file

@ -1,7 +1,7 @@
<?php
// NullDbResult.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db\NullDb;
@ -58,6 +58,4 @@ class NullDbResult implements DbResult {
public function getIterator(callable $construct): DbResultIterator {
return new DbResultIterator($this, $construct);
}
public function close(): void {}
}

View file

@ -1,7 +1,7 @@
<?php
// NullDbStatement.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db\NullDb;
@ -32,6 +32,4 @@ class NullDbStatement implements DbStatement {
}
public function reset(): void {}
public function close(): void {}
}

View file

@ -17,6 +17,4 @@ class NullDbTransaction implements DbTransaction {
public function release(string $name): void {}
public function rollback(?string $name = null): void {}
public function close(): void {}
}

View file

@ -526,14 +526,7 @@ class SqliteConnection implements DbConnection {
return new SqliteTransaction($this);
}
public function close(): void {
public function __destruct() {
$this->connection->close();
}
/**
* Closes the connection and associated resources.
*/
public function __destruct() {
$this->close();
}
}

View file

@ -1,7 +1,7 @@
<?php
// SqliteResult.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db\Sqlite;
@ -52,6 +52,4 @@ class SqliteResult implements DbResult {
public function getValue(int|string $index): mixed {
return $this->currentRow[$index] ?? null;
}
public function close(): void {}
}

View file

@ -1,7 +1,7 @@
<?php
// SqliteStatement.php
// Created: 2021-05-02
// Updated: 2024-10-04
// Updated: 2024-10-19
namespace Index\Db\Sqlite;
@ -99,6 +99,4 @@ class SqliteStatement implements DbStatement {
if(!$this->statement->reset())
throw new RuntimeException((string)$this->connection->getLastErrorString(), $this->connection->getLastErrorCode());
}
public function close(): void {}
}

View file

@ -38,6 +38,4 @@ class SqliteTransaction implements DbTransaction {
: sprintf('ROLLBACK TO SAVEPOINT %s;', SQLite3::escapeString($name))
);
}
public function close(): void {}
}