Skip to content

Commit

Permalink
Merge pull request #24 from BinarCode/2.4.1
Browse files Browse the repository at this point in the history
2.4.1
  • Loading branch information
binaryk authored Jul 11, 2023
2 parents dc7b041 + 05c4b03 commit 094cd6c
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0]
laravel: [8.*]
php: [8.1]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: ^6.6
- laravel: 10.*
testbench: 8.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.phpunit.cache
build
composer.lock
vendor
Expand Down
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
}
],
"require": {
"php": "^8.0",
"illuminate/contracts": "^8.37"
"php": "^8.1",
"illuminate/contracts": "^10.0"
},
"require-dev": {
"brianium/paratest": "^6.2",
"nunomaduro/collision": "^5.3",
"orchestra/testbench": "^6.15",
"phpunit/phpunit": "^9.3",
"brianium/paratest": "^6.3",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^9.3.3",
"spatie/laravel-ray": "^1.9",
"vimeo/psalm": "^4.4"
},
Expand Down
13 changes: 10 additions & 3 deletions config/tenantable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use BinarCode\Tenantable\Models\Tenant;

return [
/**
* The name of the table in the database.
Expand All @@ -13,15 +15,15 @@
*
* If the entry does have null tenant_id, it will be considered as a global entry.
*/
'allow_nullable_tenant' => env('ALLOW_NULLABLE_TENANT', true),
'allow_nullable_tenant' => env('ALLOW_NULLABLE_TENANT', false),

/**
* The base model for tenant.
*/
'model' => BinarCode\Tenantable\Models\TenantContract::class,
'model' => Tenant::class,

/*
* Domain for the maine application
* Domain for the main application
*/
'master_domain' => env('MASTER_DOMAIN', 'sample.test'),

Expand All @@ -30,6 +32,11 @@
*/
'master_fqdn' => env('MASTER_FQDN', 'admin.sample.test'),

/**
* The HTTP protocol.
*/
'protocol' => env('PROTOCOL', 'https'),

/*
* The connection name to reach the a tenant database.
*
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
findUnusedCode="false"
findUnusedBaselineEntry="true"
findUnusedVariablesAndParams="true"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down
32 changes: 31 additions & 1 deletion src/Models/Tenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use BinarCode\Tenantable\Models\Concerns\UsesMasterConnection;
use BinarCode\Tenantable\Tenant\Contracts\DatabaseConfig;
use BinarCode\Tenantable\Tenant\Contracts\Tenantable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -75,7 +76,7 @@ public function makeCurrentMaster()

public function isActive(): bool
{
return boolval($this->active);
return (bool) $this->active;
}

public function forget(): Tenantable
Expand All @@ -95,4 +96,33 @@ public function databaseConfig(): DatabaseConfig
{
return \BinarCode\Tenantable\Tenant\DatabaseConfig::make($this);
}

public function frontend(): Attribute
{
/**
* @psalm-suppress UndefinedFunction
*/
return new Attribute(
get: fn (
) => config('tenantable.protocol')."://{$this->subdomain}.".withoutProtocol(config('tenantable.master_domain')),
);
}

public function api(): Attribute
{
/**
* @psalm-suppress UndefinedFunction
*/
return new Attribute(
get: fn (
) => config('tenantable.protocol')."://{$this->subdomain}.".withoutProtocol(config('tenantable.master_domain')).'/api',
);
}

public function frontendRoute(string $route, array $query = []): string
{
$route = str($route)->whenStartsWith('/', fn ($str) => $str->replaceFirst('/', ''))->toString();

return "{$this->frontend}/{$route}".(count($query) ? '?'.http_build_query($query) : '');
}
}
1 change: 1 addition & 0 deletions src/Tenant/PendingNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use BinarCode\Tenantable\Models\Tenant;
use Illuminate\Contracts\Support\Arrayable;

/** @psalm-suppress MissingTemplateParam */
class PendingNew implements Arrayable
{
use Make;
Expand Down
7 changes: 7 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ function fromTenant($property = null)
{
return data_get(app(Tenantable::class), $property);
}

if (! function_exists('withoutProtocol')) {
function withoutProtocol(string $fqdn = ''): string
{
return str_replace(['https://', 'http://', 'www.'], ['https://' => '', 'http://' => '', 'www.' => ''], $fqdn);
}
}

0 comments on commit 094cd6c

Please sign in to comment.