mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 12:04:03 +00:00
writing storage drivers section
This commit is contained in:
parent
15ac61920d
commit
10365236f8
2 changed files with 74 additions and 0 deletions
|
|
@ -27,6 +27,7 @@ return [
|
||||||
'Custom Database Names' => 'docs/custom-database-names',
|
'Custom Database Names' => 'docs/custom-database-names',
|
||||||
'Tenancy Initialization' => 'docs/tenancy-initialization',
|
'Tenancy Initialization' => 'docs/tenancy-initialization',
|
||||||
'Filesystem Tenancy' => 'docs/filesystem-tenancy',
|
'Filesystem Tenancy' => 'docs/filesystem-tenancy',
|
||||||
|
'Writing Storage Drivers' => 'docs/writing-storage-drivers',
|
||||||
'Development' => 'docs/development',
|
'Development' => 'docs/development',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
|
||||||
73
source/docs/writing-storage-drivers.md
Normal file
73
source/docs/writing-storage-drivers.md
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
# Writing Storage Drivers
|
||||||
|
|
||||||
|
If you don't want to use the provided DB/Redis storage drivers, you can write your own driver.
|
||||||
|
|
||||||
|
To create a driver, create a class that implements the `Stancl\Tenancy\Interfaces\StorageDriver` interface.
|
||||||
|
|
||||||
|
For historical reasons, the `TenantManager` will try to json encode/decode data coming from the storage driver. If you want to avoid this, set `public $useJson = false;`. That will make `TenantManager` encode/decode only `put()` and `get()` data, so that data types can be stored correctly.
|
||||||
|
|
||||||
|
The DB storage driver has `public $useJson = false;`, while the Redis storage driver doesn't use this property, so it's false by default.
|
||||||
|
|
||||||
|
Here's an example:
|
||||||
|
|
||||||
|
```php
|
||||||
|
|
||||||
|
namespace App\StorageDrivers\MongoDBStorageDriver;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\Interfaces\StorageDriver;
|
||||||
|
|
||||||
|
class MongoDBStorageDriver implements StorageDriver
|
||||||
|
{
|
||||||
|
public $useJson = false;
|
||||||
|
|
||||||
|
public function identifyTenant(string $domain): array
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllTenants(array $uuids = []): array
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTenantById(string $uuid, array $fields = []): array
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTenantIdByDomain(string $domain): ?string
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createTenant(string $domain, string $uuid): array
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteTenant(string $uuid): bool
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(string $uuid, string $key)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMany(string $uuid, array $keys): array
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function put(string $uuid, string $key, $value)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putMany(string $uuid, array $values): array
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
Loading…
Add table
Add a link
Reference in a new issue