-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(overrides): Refactor service overrides to allow for more com…
…plexity (#89) * chore: Add new overrides config file * feat(tenancies): Introduce tenancy option config * chore: Add overrides tenancy option with sensible default * chore: Add generics to setup and cleanup on ServiceOverride * refactor: Add a constructor to the ServiceOverride interface * chore: Add config publishing for new overrides config file * feat(overrides): Add new service override manager with base functionality * chore: Add override.all tenancy option * chore: Remove services config from sprout config * chore: Add manager to option to override filesystem manager to overrides config * chore: Updated compatibility check on session and cookie resolvers * refactor: Update service overrides to use new approach * chore: Remove HandlesServiceOverrides and DeferrableServiceOverride * chore: Tidy up service override manager * chore: Remove old unused tests * chore: Default tenancy to have all overrides * fix: Initialise tenancy options with an empty array to prevent errors * fix: Change overrides config file location because Laravel no longer supports nested directories * fix: Add missing negation that was breaking everything * chore: Updates for new config location * tests: Update tests for changes * chore: Migrate the core sprout config to sprout/core * fix: Update to understand new config structure * chore: Renaming and tidying up of service override components * test(overrides): Added tests for the new service override manager * test(resolvers): Add compatibility exception cases to cookie and session identity resolver tests * test(overrides): Fix skipped tests for auth and session service overrides * chore: Ignore service override exceptions from code coverage * feat: Add method for checking whether a tenancy has had their service overrides setup * fix: Fix two issues with the cache override The sprout driver for the cache manager wasn't added if the cache manager had already been resolved, and because the driver creation method was bound to the manager, it wasn't able to access $this->drivers * fix: Fix two issues with the filesystem override The sprout driver for the cache manager wasn't added if the cache manager had already been resolved, and because the driver creation method was bound to the manager, it wasn't able to access $this->drivers * test(overrides): Add cache override test * chore: Add tenant aware contract and default trait implementation * chore: Add functionality to refresh tenant-aware dependencies when the tenancy and/or tenant changes * refactor: Update session handler overrides to be persistent and tenant-aware * chore: Make override filesystem manager aware of whether it override an existing original * chore: Single for tenancy generic with phpstan and tenant-aware implementation * test(overrides): Completed the tests of the session service override * test(overrides): A few QOL fixes for the session override tests * test(overrides): Fix database session handler test to account for updated Laravel core * chore(overrides): Fix static analysis issue with overridden DatabaseSessionHandler::performInsert * test(overrides): Further tests for auth and session overrides * test(overrides): Add more tests for auth and adjust existing ones * chore: Remove unneeded phpstan error silencing * test(overrides): Added a test for the filesystem manager * test(overrides): Complete the service override tests * chore: Remove Laravel pint config * chore: Ignore ServiceOverrideManager::hasTenancyBeenSetup for code coverage
- Loading branch information
Showing
88 changed files
with
6,194 additions
and
4,492 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ composer.lock | |
/wiki/ | ||
/build/ | ||
.phpunit.result.cache | ||
/tests/_Original |
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
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,50 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Service Overrides | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This config file provides the config for the different service overrides | ||
| registered by Sprout. | ||
| Service overrides are registered against a "service", which is an arbitrary | ||
| string value, used to prevent multiple overrides for a single service. | ||
| | ||
| All services overrides should have a "driver" which should contain an FQN | ||
| for a class that implements the ServiceOverride interface. | ||
| Any other config options will depend on the individual service override | ||
| driver. | ||
| | ||
*/ | ||
|
||
return [ | ||
|
||
'filesystem' => [ | ||
'driver' => \Sprout\Overrides\FilesystemOverride::class, | ||
// This config option defines whether the filesystem override will | ||
// override the filesystem manager with a Sprout version. | ||
// The default value is 'true' | ||
'manager' => true, | ||
], | ||
|
||
'job' => [ | ||
'driver' => \Sprout\Overrides\JobOverride::class, | ||
], | ||
|
||
'cache' => [ | ||
'driver' => \Sprout\Overrides\CacheOverride::class, | ||
], | ||
|
||
'auth' => [ | ||
'driver' => \Sprout\Overrides\AuthOverride::class, | ||
], | ||
|
||
'cookie' => [ | ||
'driver' => \Sprout\Overrides\CookieOverride::class, | ||
], | ||
|
||
'session' => [ | ||
'driver' => \Sprout\Overrides\SessionOverride::class, | ||
'database' => false, | ||
], | ||
]; |
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,102 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sprout\Concerns; | ||
|
||
use Sprout\Contracts\Tenancy; | ||
use Sprout\Contracts\Tenant; | ||
|
||
/** | ||
* @phpstan-require-implements \Sprout\Contracts\TenantAware | ||
*/ | ||
trait AwareOfTenant | ||
{ | ||
/** | ||
* @var \Sprout\Contracts\Tenant|null | ||
*/ | ||
private ?Tenant $tenant; | ||
|
||
/** | ||
* @var \Sprout\Contracts\Tenancy<*>|null | ||
*/ | ||
private ?Tenancy $tenancy; | ||
|
||
/** | ||
* Should the tenancy and tenant be refreshed when they change? | ||
* | ||
* @return bool | ||
*/ | ||
public function shouldBeRefreshed(): bool | ||
{ | ||
return true; // @codeCoverageIgnore | ||
} | ||
|
||
/** | ||
* Get the tenant if there is one | ||
* | ||
* @return \Sprout\Contracts\Tenant|null | ||
*/ | ||
public function getTenant(): ?Tenant | ||
{ | ||
return $this->tenant ?? null; | ||
} | ||
|
||
/** | ||
* Check if there is a tenant | ||
* | ||
* @return bool | ||
*/ | ||
public function hasTenant(): bool | ||
{ | ||
return $this->getTenant() !== null; | ||
} | ||
|
||
/** | ||
* Set the tenant | ||
* | ||
* @param \Sprout\Contracts\Tenant|null $tenant | ||
* | ||
* @return static | ||
*/ | ||
public function setTenant(?Tenant $tenant): static | ||
{ | ||
$this->tenant = $tenant; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the tenancy if there is one | ||
* | ||
* @return \Sprout\Contracts\Tenancy<*>|null | ||
*/ | ||
public function getTenancy(): ?Tenancy | ||
{ | ||
return $this->tenancy ?? null; | ||
} | ||
|
||
/** | ||
* Check if there is a tenancy | ||
* | ||
* @return bool | ||
*/ | ||
public function hasTenancy(): bool | ||
{ | ||
return $this->getTenancy() !== null; | ||
} | ||
|
||
/** | ||
* Set the tenancy | ||
* | ||
* @template TenantClass of \Sprout\Contracts\Tenant | ||
* @param \Sprout\Contracts\Tenancy<TenantClass>|null $tenancy | ||
* | ||
* @return static | ||
*/ | ||
public function setTenancy(?Tenancy $tenancy): static | ||
{ | ||
$this->tenancy = $tenancy; | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.