Skip to content

Commit 72f15aa

Browse files
committed
changing way that Policies is registered
1 parent 926e986 commit 72f15aa

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

src/Builder.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ class Builder
2525
];
2626
private Collection $names;
2727

28-
public function __construct()
29-
{
30-
$this->createDomainsFile();
31-
}
32-
3328
public function prepare(): array
3429
{
3530
$exists = [];
@@ -177,17 +172,6 @@ public function createDomainFolder()
177172
File::ensureDirectoryExists($this->getDomainFolder());
178173
}
179174

180-
public function createDomainsFile()
181-
{
182-
$filePath = app_path('domains.php');
183-
$exists = File::exists($filePath);
184-
$stubFile = File::get(__DIR__.'/Stubs/domains.stub');
185-
186-
if (!$exists) {
187-
File::put($filePath, $stubFile);
188-
}
189-
}
190-
191175
public function insertDomain(): void
192176
{
193177
$path = app_path('domains.php');

src/ServiceProvider.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace LaravelDomainOriented;
44

5+
use Illuminate\Support\Facades\File;
56
use Illuminate\Support\Facades\Gate;
67
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
78
use LaravelDomainOriented\Commands\CreateDomain;
@@ -20,11 +21,14 @@ public function boot()
2021
CreateDomain::class,
2122
RemoveDomain::class,
2223
]);
24+
25+
$this->createDomainsFile();
26+
$this->registerPolicies();
2327
}
2428

2529
public function register()
2630
{
27-
$this->registerPolicies();
31+
//
2832
}
2933

3034
private function registerPolicies()
@@ -36,4 +40,15 @@ private function registerPolicies()
3640
Gate::policy('Illuminate\Database\Eloquent\Model', $policy);
3741
}
3842
}
43+
44+
private function createDomainsFile()
45+
{
46+
$filePath = app_path('domains.php');
47+
$exists = File::exists($filePath);
48+
$stubFile = File::get(__DIR__.'/Stubs/domains.stub');
49+
50+
if (!$exists) {
51+
File::put($filePath, $stubFile);
52+
}
53+
}
3954
}

tests/Unit/BuilderTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function setUp(): void
3232
$this->filesystem = new Filesystem();
3333
$this->builder = new Builder();
3434
$this->builder->setNames();
35+
$this->builder->createDomainFolder();
3536
}
3637

3738
/** @test **/
@@ -222,7 +223,6 @@ public function it_should_run_and_create_all_files()
222223
public function it_should_insert_domain_name_to_file()
223224
{
224225
$domainName = 'Test';
225-
$this->builder->createDomainsFile();
226226
$this->builder->setNames($domainName);
227227
$this->builder->insertDomain();
228228

@@ -236,7 +236,6 @@ public function it_should_insert_domain_name_to_file()
236236
public function it_should_remove_domain_name_to_file()
237237
{
238238
$domainName = 'Test';
239-
$this->builder->createDomainsFile();
240239
$this->builder->setNames($domainName);
241240
$this->builder->removeDomain();
242241

0 commit comments

Comments
 (0)