-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dk/madness
- Loading branch information
Showing
7 changed files
with
214 additions
and
0 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 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,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the tenancy/tenancy package. | ||
* | ||
* (c) Daniël Klabbers <daniel@klabbers.email> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @see http://laravel-tenancy.com | ||
* @see https://github.com/tenancy | ||
*/ | ||
|
||
namespace Tenancy\Affects\URL\Listeners; | ||
|
||
use Tenancy\Concerns\DispatchesEvents; | ||
use Tenancy\Contracts\TenantAffectsApp; | ||
use Tenancy\Identification\Events\Switched; | ||
use Tenancy\Affects\URL\Events\ConfigureURL; | ||
use Illuminate\Contracts\Routing\UrlGenerator; | ||
|
||
class ConfiguresURL implements TenantAffectsApp | ||
{ | ||
use DispatchesEvents; | ||
|
||
public function handle(Switched $event): ?bool | ||
{ | ||
/** @var UrlGenerator $url */ | ||
$url = resolve(UrlGenerator::class); | ||
|
||
if ($event->tenant) { | ||
$this->events()->dispatch(new ConfigureURL($event, $url)); | ||
} | ||
|
||
return null; | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the tenancy/tenancy package. | ||
* | ||
* (c) Daniël Klabbers <daniel@klabbers.email> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @see http://laravel-tenancy.com | ||
* @see https://github.com/tenancy | ||
*/ | ||
|
||
namespace Tenancy\Affects\URL\Events; | ||
|
||
use Tenancy\Identification\Events\Switched; | ||
use Illuminate\Contracts\Routing\UrlGenerator; | ||
|
||
class ConfigureURL | ||
{ | ||
/** | ||
* @var Switched | ||
*/ | ||
public $event; | ||
/** | ||
* @var UrlGenerator | ||
*/ | ||
public $url; | ||
|
||
public function __construct(Switched $event, UrlGenerator $url) | ||
{ | ||
$this->event = $event; | ||
$this->url = $url; | ||
} | ||
|
||
public function changeRoot(string $url) | ||
{ | ||
return $this->url->forceRootUrl($url); | ||
} | ||
|
||
public function __call($name, $arguments) | ||
{ | ||
return call_user_func_array([$this->url, $name], $arguments); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the tenancy/tenancy package. | ||
* | ||
* (c) Daniël Klabbers <daniel@klabbers.email> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @see http://laravel-tenancy.com | ||
* @see https://github.com/tenancy | ||
*/ | ||
|
||
namespace Tenancy\Affects\URL\Providers; | ||
|
||
use Tenancy\Support\AffectsProvider; | ||
use Tenancy\Affects\URL\Listeners\ConfiguresURL; | ||
|
||
class ServiceProvider extends AffectsProvider | ||
{ | ||
protected $affects = [ConfiguresURL::class]; | ||
} |
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,33 @@ | ||
{ | ||
"name": "tenancy/affects-url", | ||
"description": "The tenancy/tenancy url mutations", | ||
"keywords": ["affects", "tenancy", "url"], | ||
"license": "MIT", | ||
"require": { | ||
"tenancy/framework": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Tenancy\\Affects\\URL\\": "" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Daniël Klabbers", | ||
"email": "daniel@klabbers.email", | ||
"homepage": "http://luceos.com" | ||
}, | ||
{ | ||
"name": "Arlon Antonius", | ||
"email": "opensource@arlonantonius.com", | ||
"homepage": "https://arlonantonius.com" | ||
} | ||
], | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Tenancy\\Affects\\URL\\Providers\\ServiceProvider" | ||
] | ||
} | ||
} | ||
} |
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,71 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the tenancy/tenancy package. | ||
* | ||
* (c) Daniël Klabbers <daniel@klabbers.email> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @see http://laravel-tenancy.com | ||
* @see https://github.com/tenancy | ||
*/ | ||
|
||
namespace Tenancy\Tests\Affects\URL; | ||
|
||
use Tenancy\Facades\Tenancy; | ||
use Tenancy\Testing\TestCase; | ||
use Tenancy\Testing\Mocks\Tenant; | ||
use Illuminate\Support\Facades\URL; | ||
use Tenancy\Affects\URL\Events\ConfigureURL; | ||
use Tenancy\Affects\URL\Providers\ServiceProvider; | ||
|
||
class ConfiguresURLTest extends TestCase | ||
{ | ||
protected $additionalProviders = [ServiceProvider::class]; | ||
|
||
/** | ||
* @var Tenant | ||
*/ | ||
protected $tenant; | ||
|
||
protected function afterSetUp() | ||
{ | ||
$this->tenant = $this->mockTenant(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function can_set_url() | ||
{ | ||
$this->events->listen(ConfigureURL::class, function (ConfigureURL $event) { | ||
$event->changeRoot('tenant.test'); | ||
}); | ||
|
||
Tenancy::setTenant($this->tenant); | ||
|
||
$this->assertEquals( | ||
'tenant.test', | ||
URL::current() | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function forwards_to_url_generator() | ||
{ | ||
$this->events->listen(ConfigureURL::class, function (ConfigureURL $event) { | ||
$event->forceRootUrl('tenant.test'); | ||
}); | ||
|
||
Tenancy::setTenant($this->tenant); | ||
|
||
$this->assertEquals( | ||
'tenant.test', | ||
URL::current() | ||
); | ||
} | ||
} |