1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 09:04:03 +00:00

WIP findBy()

This commit is contained in:
Samuel Štancl 2019-10-24 18:57:30 +02:00
parent 0e39bec265
commit 696863b1d4
3 changed files with 37 additions and 4 deletions

View file

@ -1,15 +1,14 @@
# Contributing # Contributing
## Code style ## Code style
StyleCI will flag code style violations in your pull requests.
StyleCI will automatically fix code style violations in your pull requests.
## Running tests ## Running tests
### With Docker ### With Docker
If you have Docker installed, simply run ./test. When you're done testing, run docker-compose down to shut down the containers. If you have Docker installed, simply run ./fulltest. When you're done testing, run docker-compose down to shut down the containers.
### Without Docker ### Without Docker
If you run the tests of this package, please make sure you don't store anything in Redis @ 127.0.0.1:6379 db#14. The contents of this database are flushed everytime the tests are run. If you run the tests of this package, please make sure you don't store anything in Redis @ 127.0.0.1:6379 db#14. The contents of this database are flushed everytime the tests are run.
Some tests are run only if the CI, TRAVIS and CONTINUOUS_INTEGRATION environment variables are set to true. This is to avoid things like bloating your MySQL instance with test databases. Some tests are run only if the `CONTINUOUS_INTEGRATION` or `DOCKER` environment variables are set to true. This is to avoid things like bloating your MySQL instance with test databases.

View file

@ -0,0 +1,13 @@
<?php
namespace Stancl\Tenancy\Exceptions;
use Exception;
class NotImplementedException extends Exception
{
public function __construct($class, $method, $extra)
{
parent::__construct("The $class class does not implement the $method method. $extra");
}
}

View file

@ -8,6 +8,7 @@ use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
use Illuminate\Foundation\Application; use Illuminate\Foundation\Application;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException; use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
use Stancl\Tenancy\Exceptions\NotImplementedException;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator; use Stancl\Tenancy\Jobs\QueuedTenantDatabaseMigrator;
use Stancl\Tenancy\Jobs\QueuedTenantDatabaseSeeder; use Stancl\Tenancy\Jobs\QueuedTenantDatabaseSeeder;
@ -200,6 +201,26 @@ class TenantManager
return $this->storage->findByDomain($domain); return $this->storage->findByDomain($domain);
} }
/**
* Find a tenant using an arbitrary key.
*
* @param string $key
* @param mixed $value
* @return Tenant
* @throws TenantCouldNotBeIdentifiedException
* @throws NotImplementedException
*/
public function findBy(string $key, $value): Tenant
{
if (! method_exists($this->storage, 'findBy')) {
throw new NotImplementedException(get_class($this->storage), 'findBy',
"This method was added to storage drivers provided by the package in 2.2.0 and will be part of the StorageDriver contract in 3.0.0."
);
}
return $this->storage->find($key, $value);
}
/** /**
* Get all tenants. * Get all tenants.
* *