Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2.x] Add CreateTenant command (#153)
* Add CreateTenant command, fix TenantList output * Create command test
- Loading branch information
Showing
7 changed files
with
69 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# for development | ||
docker-compose up -d | ||
./test "$@" | ||
docker-compose exec test vendor/bin/phpcov merge --clover clover.xml coverage/ |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Stancl\Tenancy\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Stancl\Tenancy\Tenant; | ||
|
||
class CreateTenant extends Command | ||
{ | ||
protected $signature = 'tenants:create | ||
{--d|domain=* : The tenant\'s domains.} | ||
{data?* : The tenant\'s data. Separate keys and values by `=`, e.g. `plan=free`.}'; | ||
|
||
protected $description = 'Create a tenant.'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$tenant = Tenant::new() | ||
->withDomains($this->getDomains()) | ||
->withData($this->getData()) | ||
->save(); | ||
|
||
$this->info($tenant->id); | ||
} | ||
|
||
public function getDomains(): array | ||
{ | ||
return $this->option('domain'); | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return array_reduce($this->argument('data'), function ($data, $pair) { | ||
[$key, $value] = explode('=', $pair, 2); | ||
$data[$key] = $value; | ||
|
||
return $data; | ||
}, []); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# for development | ||
docker-compose up -d | ||
printf "Variant 1\n\n" | ||
docker-compose exec test env TENANCY_TEST_STORAGE_DRIVER=db vendor/bin/phpunit --coverage-php coverage/2.cov "$@" | ||
printf "Variant 2\n\n" | ||
docker-compose exec test env TENANCY_TEST_STORAGE_DRIVER=redis vendor/bin/phpunit --coverage-php coverage/1.cov "$@" | ||
docker-compose exec test vendor/bin/phpcov merge --clover clover.xml coverage/ |
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