Skip to content

Commit

Permalink
fix: isolated namespace (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbreuss committed Mar 31, 2024
1 parent 5ece85f commit 16e7561
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Added or changed functionality in `tebe\pdo` over the native PDO includes:
Create a PDO instance representing a connection to a database.

```php
use tebe\PDO;
use tebe\pdo\PDO;
$db = new PDO('sqlite:database.sqlite');
```

Expand Down Expand Up @@ -100,11 +100,11 @@ This package requires PHP 8.1 or later; it has been tested on latest Linux, macO

## Documentation

### tebe\PDO
### tebe\pdo\PDO

The class `tebe\PDO` is a wrapper for the native `PDO` class and implements all methods of this class.
The class `tebe\pdo\PDO` is a wrapper for the native `PDO` class and implements all methods of this class.

The main differences are that some methods return `tebe\PDOStatement` instances and the `quote` method can also handle arrays.
The main differences are that some methods return `tebe\pdo\PDOStatement` instances and the `quote` method can also handle arrays.

In addition, the class contains a new method `run`, which executes a query with bound values and returns the resulting statement instance.

Expand All @@ -120,7 +120,7 @@ public PDO::getWrappedPdo(): \PDO

Prepares a statement for execution and returns a statement object.

This differs from `PDO::prepare` in that it will return a `tebe\PDOStatement` object.
This differs from `PDO::prepare` in that it will return a `tebe\pdo\PDOStatement` object.

```php
public PDO::prepare(string $query, array $options = []): PDOStatement|false
Expand All @@ -132,7 +132,7 @@ See [php.net](https://php.net/pdo.prepare)

Prepares and executes an SQL statement without placeholders.

This differs from `PDO::query` in that it will return a `tebe\PDOStatement` object.
This differs from `PDO::query` in that it will return a `tebe\pdo\PDOStatement` object.

```php
public PDO::query(string $query, mixed ...$fetchModeArgs): PDOStatement|false
Expand All @@ -154,7 +154,7 @@ See [php.net](https://php.net/pdo.quote)

#### run

Runs a query with bound values and returns the resulting `tebe\PDOStatement`.
Runs a query with bound values and returns the resulting `tebe\pdo\PDOStatement`.

Array values will be processed by the parser instance and placeholders are replaced.

Expand All @@ -164,7 +164,7 @@ public PDO::run(string $sql, ?array $args = null): PDOStatement|false

---

The remaining `tebe\PDO` methods are simple wrapper methods of the underlying `PDO` class.
The remaining `tebe\pdo\PDO` methods are simple wrapper methods of the underlying `PDO` class.
For more information, see [php.net](https://php.net/pdo).

- [beginTransaction](https://php.net/pdo.beginTransaction)
Expand All @@ -180,17 +180,17 @@ For more information, see [php.net](https://php.net/pdo).
- [rollBack](https://php.net/pdo.rollBack)
- [setAttribute](https://php.net/pdo.setAttribute)

### tebe\PDOStatement
### tebe\pdo\PDOStatement

The class `tebe\PDOStatement` is a wrapper for the native `PDOStatement` class and implements all methods of this class.
The class `tebe\pdo\PDOStatement` is a wrapper for the native `PDOStatement` class and implements all methods of this class.

The main difference is that the `execute` method returns a statement instance. This was done to allow method chaining aka fluent interface.

Besides that it contains several new `fetch*()` and `fetchAll*()` methodes for commonly-used fetch actions.

#### __construct

Creates a `tebe\PDOStatement` instance representing a query statement and wraps the original `PDOStatement`.
Creates a `tebe\pdo\PDOStatement` instance representing a query statement and wraps the original `PDOStatement`.

```php
public PDOStatement::__construct(\PDOStatement $stmt)
Expand All @@ -200,7 +200,7 @@ public PDOStatement::__construct(\PDOStatement $stmt)

Executes a prepared statement

This differs from `PDOStatement::execute` in that it will return a `tebe\PDOStatement` object.
This differs from `PDOStatement::execute` in that it will return a `tebe\pdo\PDOStatement` object.

```php
public PDOStatement::execute(?array $params = null): PDOStatement|false
Expand Down Expand Up @@ -349,7 +349,7 @@ public PDOStatement::fetchAllUnique(int $style = 0): array

---

The remaining `tebe\PDOStatement` methods are simple wrapper methods of the underlying `PDOStatement` class.
The remaining `tebe\pdo\PDOStatement` methods are simple wrapper methods of the underlying `PDOStatement` class.
For more information, see [php.net](https://php.net/pdostatement).

- [bindColumn](https://php.net/pdostatement.bindcolumn)
Expand All @@ -372,13 +372,13 @@ For more information, see [php.net](https://php.net/pdostatement).
- [setAttribute](https://php.net/pdostatement.setAttribute)
- [setFetchMode](https://php.net/pdostatement.setFetchMode)

### tebe\PDOParser
### tebe\pdo\PDOParser

Class `tebe\PDOParser` offers parsing and rebuilding functions for all drivers.
Class `tebe\pdo\PDOParser` offers parsing and rebuilding functions for all drivers.

#### __construct

Creates a `tebe\PDOParser` instance.
Creates a `tebe\pdo\PDOParser` instance.

```php
public PDOParser::__construct(string $driver)
Expand Down
2 changes: 1 addition & 1 deletion src/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace tebe;
namespace tebe\pdo;

/**
* Represents a connection between PHP and a database server.
Expand Down
2 changes: 1 addition & 1 deletion src/PDOParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace tebe;
namespace tebe\pdo;

use PDOException;

Expand Down
2 changes: 1 addition & 1 deletion src/PDOStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace tebe;
namespace tebe\pdo;

/**
* Represents a prepared statement and, after the statement is executed, an associated result set.
Expand Down
10 changes: 5 additions & 5 deletions tests/functional.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ function assert_instanceof(mixed $result, string $class, string $message)
_assert($result instanceof $class, $message);
}

function init_db(): \tebe\PDO
function init_db(): \tebe\pdo\PDO
{
// set options that are later used for tests
$db = new \tebe\PDO('sqlite::memory:', options: [
\tebe\PDO::ATTR_ERRMODE => \tebe\PDO::ERRMODE_SILENT,
\tebe\PDO::ATTR_PERSISTENT => true,
\tebe\PDO::ATTR_CASE => \tebe\PDO::CASE_LOWER,
$db = new \tebe\pdo\PDO('sqlite::memory:', options: [
\tebe\pdo\PDO::ATTR_ERRMODE => \tebe\pdo\PDO::ERRMODE_SILENT,
\tebe\pdo\PDO::ATTR_PERSISTENT => true,
\tebe\pdo\PDO::ATTR_CASE => \tebe\pdo\PDO::CASE_LOWER,
]);

$sql = "DROP TABLE IF EXISTS fruits";
Expand Down
2 changes: 1 addition & 1 deletion tests/pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function test_pdo_prepare(): void
$db = init_db();
$sql = "SELECT * FROM fruits WHERE id > ?";
$stmt = $db->prepare($sql);
assert_instanceof($stmt, \tebe\PDOStatement::class, 'Prepare returns PDOStatement');
assert_instanceof($stmt, \tebe\pdo\PDOStatement::class, 'Prepare returns PDOStatement');
assert_equal($stmt->queryString, $sql, 'Query string of PDOStatement');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/pdo_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace tebe\pdo\tests;

use tebe\PDOParser;
use tebe\pdo\PDOParser;

function test_pdo_parser_rebuild_with_positional_placeholders(): void
{
Expand Down

0 comments on commit 16e7561

Please sign in to comment.