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

View file

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

View file

@ -1,7 +1,7 @@
<?php <?php
// MemcachedProvider.php // MemcachedProvider.php
// Created: 2024-04-10 // Created: 2024-04-10
// Updated: 2024-10-02 // Updated: 2024-10-19
namespace Index\Cache\Memcached; 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 touch(string $key, int $ttl = 0): void;
public abstract function increment(string $key, int $amount = 1): int; public abstract function increment(string $key, int $amount = 1): int;
public abstract function decrement(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 <?php
// MemcachedProviderLegacy.php // MemcachedProviderLegacy.php
// Created: 2024-04-10 // Created: 2024-04-10
// Updated: 2024-10-02 // Updated: 2024-10-19
namespace Index\Cache\Memcached; namespace Index\Cache\Memcached;
@ -91,7 +91,7 @@ class MemcachedProviderLegacy extends MemcachedProvider {
return $result; return $result;
} }
public function close(): void { public function __destruct() {
if(!$this->persistent) if(!$this->persistent)
$this->memcache->close(); $this->memcache->close();
} }

View file

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

View file

@ -1,7 +1,7 @@
<?php <?php
// ValkeyProvider.php // ValkeyProvider.php
// Created: 2024-04-10 // Created: 2024-04-10
// Updated: 2024-10-02 // Updated: 2024-10-19
namespace Index\Cache\Valkey; namespace Index\Cache\Valkey;
@ -72,12 +72,8 @@ class ValkeyProvider implements CacheProvider {
return is_int($result) ? $result : 0; return is_int($result) ? $result : 0;
} }
public function close(): void { public function __destruct() {
if(!$this->persist) if(!$this->persist)
$this->redis->close(); $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; namespace Index\Db;
use RuntimeException; use RuntimeException;
use Index\Closeable;
/** /**
* Represents a connection to a database service. * Represents a connection to a database service.
*/ */
interface DbConnection extends Closeable { interface DbConnection {
/** /**
* Returns the ID of the last inserted row. * Returns the ID of the last inserted row.
* *

View file

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

View file

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

View file

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

View file

@ -6,12 +6,11 @@
namespace Index\Db; namespace Index\Db;
use RuntimeException; use RuntimeException;
use Index\Closeable;
/** /**
* Represents a transaction to be performed on the database. * 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. * Commits the actions done during a transaction and ends the transaction.
* A new transaction will be started if auto-commit is disabled. * 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. * Closes the connection and associated resources.
*/ */
public function close(): void { public function __destruct() {
try { try {
$this->connection->close(); $this->connection->close();
} catch(\Error $ex) {} } catch(\Error $ex) {}
} }
/**
* Closes the connection and associated resources.
*/
public function __destruct() {
$this->close();
}
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
<?php <?php
// NullDbStatement.php // NullDbStatement.php
// Created: 2021-05-02 // Created: 2021-05-02
// Updated: 2024-10-04 // Updated: 2024-10-19
namespace Index\Db\NullDb; namespace Index\Db\NullDb;
@ -32,6 +32,4 @@ class NullDbStatement implements DbStatement {
} }
public function reset(): void {} 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 release(string $name): void {}
public function rollback(?string $name = null): 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); return new SqliteTransaction($this);
} }
public function close(): void { public function __destruct() {
$this->connection->close(); $this->connection->close();
} }
/**
* Closes the connection and associated resources.
*/
public function __destruct() {
$this->close();
}
} }

View file

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

View file

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