Skip to content

Commit

Permalink
Merge branch 'master' into dk/madness
Browse files Browse the repository at this point in the history
  • Loading branch information
luceos committed Jul 1, 2019
2 parents 38a691b + 4d878d1 commit e20557f
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/tenancy-split.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ git subsplit publish --heads="master" src/Affects/Filesystem:git@github.com:tena
git subsplit publish --heads="master" src/Affects/Logs:git@github.com:tenancy/affects-logs.git
git subsplit publish --heads="master" src/Affects/Models:git@github.com:tenancy/affects-models.git
git subsplit publish --heads="master" src/Affects/Routes:git@github.com:tenancy/affects-routes.git
git subsplit publish --heads="master" src/Affects/URL:git@github.com:tenancy/affects-url.git
git subsplit publish --heads="master" src/Affects/Views:git@github.com:tenancy/affects-views.git

# Lifecycle Hooks
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"tenancy/affects-logs": "self.version",
"tenancy/affects-models": "self.version",
"tenancy/affects-routes": "self.version",
"tenancy/affects-url": "self.version",
"tenancy/affects-views": "self.version",
"tenancy/database-driver-mysql": "self.version",
"tenancy/database-driver-sqlite": "self.version",
Expand Down Expand Up @@ -73,6 +74,7 @@
"Tenancy\\Affects\\Logs\\Provider",
"Tenancy\\Affects\\Models\\Provider",
"Tenancy\\Affects\\Routes\\Provider",
"Tenancy\\Affects\\URL\\Provider",
"Tenancy\\Affects\\Views\\Provider",
"Tenancy\\Identification\\Drivers\\Console\\Providers\\IdentificationProvider",
"Tenancy\\Identification\\Drivers\\Environment\\Providers\\IdentificationProvider",
Expand Down
38 changes: 38 additions & 0 deletions src/Affects/URL/ConfiguresURL.php
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;
}
}
46 changes: 46 additions & 0 deletions src/Affects/URL/Events/ConfigureURL.php
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);
}
}
23 changes: 23 additions & 0 deletions src/Affects/URL/Provider.php
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];
}
33 changes: 33 additions & 0 deletions src/Affects/URL/composer.json
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"
]
}
}
}
71 changes: 71 additions & 0 deletions tests/unit/Affects/URL/ConfiguresURLTest.php
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()
);
}
}

0 comments on commit e20557f

Please sign in to comment.