-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored to support attributes and drop annotation support
- Loading branch information
Showing
7 changed files
with
112 additions
and
144 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Rentpost\Doctrine\MultiTenancy\Attribute; | ||
|
||
use Attribute; | ||
|
||
/** | ||
* Attribute service for Multi-tenancy | ||
* | ||
* @author Jacob Thomason <[email protected]> | ||
*/ | ||
#[Attribute(Attribute::TARGET_CLASS)] | ||
final class MultiTenancy | ||
{ | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param MultiTenancy\Filter[] $filters | ||
*/ | ||
public function __construct(protected array $filters = [], protected bool $enable = true) {} | ||
|
||
|
||
/** | ||
* Checks if MultiTenancy is enabled | ||
*/ | ||
public function isEnabled(): bool | ||
{ | ||
return $this->enable; | ||
} | ||
|
||
|
||
/** | ||
* Gets the filters associated with this attribute | ||
* | ||
* @return MultiTenancy\Filter[] | ||
*/ | ||
public function getFilters(): array | ||
{ | ||
return $this->filters; | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Rentpost\Doctrine\MultiTenancy\Attribute\MultiTenancy; | ||
|
||
use Attribute; | ||
|
||
/** | ||
* Attribute service for Multi-tenancy filters | ||
* | ||
* @author Jacob Thomason <[email protected]> | ||
*/ | ||
#[Attribute(Attribute::TARGET_CLASS|Attribute::IS_REPEATABLE)] | ||
final class Filter | ||
{ | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string[] $context | ||
*/ | ||
public function __construct(protected array $context = [], protected string $where = '') {} | ||
|
||
|
||
/** | ||
* Gets the filter context | ||
* | ||
* @return string[] | ||
*/ | ||
public function getContext(): array | ||
{ | ||
return $this->context; | ||
} | ||
|
||
|
||
/** | ||
* Gets the SQL where clause | ||
*/ | ||
public function getWhereClause(): string | ||
{ | ||
return $this->where; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,10 +5,10 @@ | |
namespace Rentpost\Doctrine\MultiTenancy; | ||
|
||
/** | ||
* Throw this exception when there is an issue with the MultiTenancy annotation. | ||
* Throw this exception when there is an issue with the MultiTenancy attribute. | ||
* | ||
* @author Jacob Thomason <[email protected]> | ||
*/ | ||
class AnnotationException extends \Exception | ||
class AttributeException extends \Exception | ||
{ | ||
} |
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