-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code Refactor: data resiliency improvements.
- Loading branch information
1 parent
98f9fe3
commit 7a07e1f
Showing
30 changed files
with
458 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Conveyor\Persistence\Abstracts; | ||
|
||
use Conveyor\Persistence\DTO\DatabaseConnectionDTO; | ||
use Conveyor\Persistence\Interfaces\GenericPersistenceInterface; | ||
|
||
abstract class GenericPersistence implements GenericPersistenceInterface | ||
{ | ||
/** | ||
* @param @param DatabaseConnectionDTO|array{driver:string,database:string,username:string,password:string,charset:string,collation:string,prefix:string} $databaseOptions | ||
*/ | ||
public function __construct( | ||
protected DatabaseConnectionDTO|array $databaseOptions = [ | ||
'driver' => 'sqlite', | ||
'database' => __DIR__ . '/../../../../../database/database.sqlite', | ||
'username' => null, | ||
'password' => null, | ||
'charset' => 'utf8', | ||
'collation' => 'utf8_unicode_ci', | ||
'prefix' => '', | ||
], | ||
) { | ||
if (is_array($this->databaseOptions)) { | ||
$this->databaseOptions = DatabaseConnectionDTO::fromArray($this->databaseOptions); | ||
} | ||
|
||
$this->refresh(true); | ||
} | ||
|
||
abstract public function refresh(bool $fresh = false): static; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Conveyor\Persistence\DTO; | ||
|
||
use ArrayAccess; | ||
|
||
class DatabaseConnectionDTO implements ArrayAccess | ||
{ | ||
public function __construct( | ||
public string $driver, | ||
public string $database, | ||
public ?string $username = null, | ||
public ?string $password = null, | ||
public string $charset = 'utf8', | ||
public string $collation = 'utf8_unicode_ci', | ||
public string $prefix = '', | ||
) {} | ||
|
||
public static function fromArray(array $data): self | ||
{ | ||
return new self( | ||
$data['driver'], | ||
$data['database'], | ||
$data['username'] ?? null, | ||
$data['password'] ?? null, | ||
$data['charset'] ?? 'utf8', | ||
$data['collation'] ?? 'utf8_unicode_ci', | ||
$data['prefix'] ?? '' | ||
); | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'driver' => $this->driver, | ||
'database' => $this->database, | ||
'username' => $this->username, | ||
'password' => $this->password, | ||
'charset' => $this->charset, | ||
'collation' => $this->collation, | ||
'prefix' => $this->prefix, | ||
]; | ||
} | ||
|
||
public function offsetExists($offset): bool | ||
{ | ||
return property_exists($this, $offset); | ||
} | ||
|
||
public function offsetGet($offset): mixed | ||
{ | ||
return $this->{$offset}; | ||
} | ||
|
||
public function offsetSet($offset, $value): void | ||
{ | ||
$this->{$offset} = $value; | ||
} | ||
|
||
public function offsetUnset($offset): void | ||
{ | ||
$this->{$offset} = null; | ||
} | ||
} |
Oops, something went wrong.