Skip to content

Commit 7fe075f

Browse files
authored
Merge pull request #1038 from hydephp/decouple-discovery-booting-from-foundation-collection-instantiation
Breaking: Decouple discovery booting from foundation collection instantiation
2 parents 58de4fd + 58c68ad commit 7fe075f

File tree

7 files changed

+41
-32
lines changed

7 files changed

+41
-32
lines changed

packages/framework/src/Foundation/Concerns/BaseFoundationCollection.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ abstract protected function runDiscovery(): self;
2424

2525
abstract protected function runExtensionCallbacks(): self;
2626

27-
public static function boot(HydeKernel $kernel): static
27+
public static function init(HydeKernel $kernel): static
2828
{
29-
return (new static())->setKernel($kernel)->runDiscovery();
29+
return (new static())->setKernel($kernel);
30+
}
31+
32+
public function boot(): static
33+
{
34+
return $this->runDiscovery();
3035
}
3136

3237
protected function __construct(array|Arrayable|null $items = [])

packages/framework/src/Foundation/Concerns/BootsHydeKernel.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ public function boot(): void
2626

2727
$this->booting = true;
2828

29-
$this->files = FileCollection::boot($this);
30-
$this->pages = PageCollection::boot($this);
31-
$this->routes = RouteCollection::boot($this);
29+
$this->files = FileCollection::init($this);
30+
$this->pages = PageCollection::init($this);
31+
$this->routes = RouteCollection::init($this);
32+
33+
$this->files->boot();
34+
$this->pages->boot();
35+
$this->routes->boot();
3236

3337
$this->booting = false;
3438
$this->booted = true;

packages/framework/tests/Feature/FileCollectionTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FileCollectionTest extends TestCase
2323
{
2424
public function test_boot_method_creates_new_page_collection_and_discovers_pages_automatically()
2525
{
26-
$collection = FileCollection::boot(Hyde::getInstance());
26+
$collection = FileCollection::init(Hyde::getInstance())->boot();
2727
$this->assertInstanceOf(FileCollection::class, $collection);
2828
$this->assertInstanceOf(Collection::class, $collection);
2929

@@ -36,7 +36,7 @@ public function test_boot_method_creates_new_page_collection_and_discovers_pages
3636

3737
public function test_get_source_files_returns_all_discovered_source_files_when_no_parameter_is_supplied()
3838
{
39-
$collection = FileCollection::boot(Hyde::getInstance());
39+
$collection = FileCollection::init(Hyde::getInstance())->boot();
4040

4141
$this->assertEquals([
4242
'_pages/404.blade.php' => new SourceFile('_pages/404.blade.php', BladePage::class),
@@ -49,15 +49,15 @@ public function test_get_source_files_does_not_include_non_page_source_files()
4949
$this->withoutDefaultPages();
5050
$this->file('_pages/foo.txt');
5151

52-
$collection = FileCollection::boot(Hyde::getInstance());
52+
$collection = FileCollection::init(Hyde::getInstance())->boot();
5353
$this->assertEquals([], $collection->getSourceFiles()->all());
5454

5555
$this->restoreDefaultPages();
5656
}
5757

5858
public function test_get_media_files_returns_all_discovered_media_files()
5959
{
60-
$collection = FileCollection::boot(Hyde::getInstance());
60+
$collection = FileCollection::init(Hyde::getInstance())->boot();
6161
$this->assertEquals([
6262
'_media/app.css' => new MediaFile('_media/app.css'),
6363
], $collection->getMediaFiles()->all());
@@ -66,7 +66,7 @@ public function test_get_media_files_returns_all_discovered_media_files()
6666
public function test_get_media_files_does_not_include_non_media_files()
6767
{
6868
$this->file('_media/foo.blade.php');
69-
$collection = FileCollection::boot(Hyde::getInstance());
69+
$collection = FileCollection::init(Hyde::getInstance())->boot();
7070
$this->assertEquals([
7171
'_media/app.css' => new MediaFile('_media/app.css'),
7272
], $collection->getMediaFiles()->all());
@@ -75,7 +75,7 @@ public function test_get_media_files_does_not_include_non_media_files()
7575
public function test_blade_pages_are_discovered()
7676
{
7777
$this->file('_pages/foo.blade.php');
78-
$collection = FileCollection::boot(Hyde::getInstance());
78+
$collection = FileCollection::init(Hyde::getInstance())->boot();
7979

8080
$this->assertArrayHasKey('_pages/foo.blade.php', $collection->toArray());
8181
$this->assertEquals(new SourceFile('_pages/foo.blade.php', BladePage::class), $collection->get('_pages/foo.blade.php'));
@@ -84,7 +84,7 @@ public function test_blade_pages_are_discovered()
8484
public function test_markdown_pages_are_discovered()
8585
{
8686
$this->file('_pages/foo.md');
87-
$collection = FileCollection::boot(Hyde::getInstance());
87+
$collection = FileCollection::init(Hyde::getInstance())->boot();
8888

8989
$this->assertArrayHasKey('_pages/foo.md', $collection->toArray());
9090
$this->assertEquals(new SourceFile('_pages/foo.md', MarkdownPage::class), $collection->get('_pages/foo.md'));
@@ -93,7 +93,7 @@ public function test_markdown_pages_are_discovered()
9393
public function test_markdown_posts_are_discovered()
9494
{
9595
$this->file('_posts/foo.md');
96-
$collection = FileCollection::boot(Hyde::getInstance());
96+
$collection = FileCollection::init(Hyde::getInstance())->boot();
9797

9898
$this->assertArrayHasKey('_posts/foo.md', $collection->toArray());
9999
$this->assertEquals(new SourceFile('_posts/foo.md', MarkdownPost::class), $collection->get('_posts/foo.md'));
@@ -102,7 +102,7 @@ public function test_markdown_posts_are_discovered()
102102
public function test_documentation_pages_are_discovered()
103103
{
104104
$this->file('_docs/foo.md');
105-
$collection = FileCollection::boot(Hyde::getInstance());
105+
$collection = FileCollection::init(Hyde::getInstance())->boot();
106106
$this->assertArrayHasKey('_docs/foo.md', $collection->toArray());
107107
$this->assertEquals(new SourceFile('_docs/foo.md', DocumentationPage::class), $collection->get('_docs/foo.md'));
108108
}

packages/framework/tests/Feature/HydeExtensionFeatureTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function test_register_extension_method_does_not_register_already_registe
174174
public function test_custom_registered_pages_are_discovered_by_the_file_collection_class()
175175
{
176176
app(HydeKernel::class)->registerExtension(TestPageExtension::class);
177-
FileCollection::boot(app(HydeKernel::class));
177+
FileCollection::init(app(HydeKernel::class))->boot();
178178

179179
$this->directory('foo');
180180
$this->file('foo/bar.txt');
@@ -189,7 +189,7 @@ public function test_custom_registered_pages_are_discovered_by_the_page_collecti
189189
$this->file('foo/bar.txt');
190190

191191
app(HydeKernel::class)->registerExtension(TestPageExtension::class);
192-
PageCollection::boot(app(HydeKernel::class));
192+
PageCollection::init(app(HydeKernel::class))->boot();
193193

194194
$this->assertArrayHasKey('foo/bar.txt', Pages::all());
195195
$this->assertEquals(new TestPageClass('bar'), Pages::get('foo/bar.txt'));
@@ -201,7 +201,7 @@ public function test_custom_registered_pages_are_discovered_by_the_route_collect
201201
$this->file('foo/bar.txt');
202202

203203
app(HydeKernel::class)->registerExtension(TestPageExtension::class);
204-
RouteCollection::boot(app(HydeKernel::class));
204+
RouteCollection::init(app(HydeKernel::class))->boot();
205205

206206
$this->assertArrayHasKey('foo/bar', Routes::all());
207207
$this->assertEquals(new Route(new TestPageClass('bar')), Routes::get('foo/bar'));

packages/framework/tests/Feature/PageCollectionTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class PageCollectionTest extends TestCase
2424
{
2525
public function test_boot_method_creates_new_page_collection_and_discovers_pages_automatically()
2626
{
27-
$collection = PageCollection::boot(Hyde::getInstance());
27+
$collection = PageCollection::init(Hyde::getInstance())->boot();
2828
$this->assertInstanceOf(PageCollection::class, $collection);
2929
$this->assertInstanceOf(Collection::class, $collection);
3030

@@ -37,7 +37,7 @@ public function test_boot_method_creates_new_page_collection_and_discovers_pages
3737
public function test_blade_pages_are_discovered()
3838
{
3939
$this->file('_pages/foo.blade.php');
40-
$collection = PageCollection::boot(Hyde::getInstance());
40+
$collection = PageCollection::init(Hyde::getInstance())->boot();
4141

4242
$this->assertArrayHasKey('_pages/foo.blade.php', $collection->toArray());
4343
$this->assertEquals(new BladePage('foo'), $collection->get('_pages/foo.blade.php'));
@@ -46,7 +46,7 @@ public function test_blade_pages_are_discovered()
4646
public function test_markdown_pages_are_discovered()
4747
{
4848
$this->file('_pages/foo.md');
49-
$collection = PageCollection::boot(Hyde::getInstance());
49+
$collection = PageCollection::init(Hyde::getInstance())->boot();
5050

5151
$this->assertArrayHasKey('_pages/foo.md', $collection->toArray());
5252
$this->assertEquals(new MarkdownPage('foo'), $collection->get('_pages/foo.md'));
@@ -55,7 +55,7 @@ public function test_markdown_pages_are_discovered()
5555
public function test_markdown_posts_are_discovered()
5656
{
5757
$this->file('_posts/foo.md');
58-
$collection = PageCollection::boot(Hyde::getInstance());
58+
$collection = PageCollection::init(Hyde::getInstance())->boot();
5959

6060
$this->assertArrayHasKey('_posts/foo.md', $collection->toArray());
6161
$this->assertEquals(new MarkdownPost('foo'), $collection->get('_posts/foo.md'));
@@ -64,15 +64,15 @@ public function test_markdown_posts_are_discovered()
6464
public function test_documentation_pages_are_discovered()
6565
{
6666
$this->file('_docs/foo.md');
67-
$collection = PageCollection::boot(Hyde::getInstance());
67+
$collection = PageCollection::init(Hyde::getInstance())->boot();
6868
$this->assertArrayHasKey('_docs/foo.md', $collection->toArray());
6969
$this->assertEquals(new DocumentationPage('foo'), $collection->get('_docs/foo.md'));
7070
}
7171

7272
public function test_get_page_returns_parsed_page_object_for_given_source_path()
7373
{
7474
$this->file('_pages/foo.blade.php');
75-
$collection = PageCollection::boot(Hyde::getInstance());
75+
$collection = PageCollection::init(Hyde::getInstance())->boot();
7676
$this->assertEquals(new BladePage('foo'), $collection->getPage('_pages/foo.blade.php'));
7777
}
7878

@@ -86,7 +86,7 @@ public function test_get_pages_returns_collection_of_pages_of_given_class()
8686
$this->file('_docs/foo.md');
8787
$this->file('_pages/foo.html');
8888

89-
$collection = PageCollection::boot(Hyde::getInstance());
89+
$collection = PageCollection::init(Hyde::getInstance())->boot();
9090
$this->assertCount(5, $collection);
9191

9292
$this->assertContainsOnlyInstancesOf(BladePage::class, $collection->getPages(BladePage::class));
@@ -114,7 +114,7 @@ public function test_get_pages_returns_all_pages_when_not_supplied_with_class_st
114114
$this->file('_docs/foo.md');
115115
$this->file('_pages/foo.html');
116116

117-
$collection = PageCollection::boot(Hyde::getInstance())->getPages();
117+
$collection = PageCollection::init(Hyde::getInstance())->boot()->getPages();
118118
$this->assertCount(5, $collection);
119119

120120
$this->assertEquals(new BladePage('foo'), $collection->get('_pages/foo.blade.php'));
@@ -129,7 +129,7 @@ public function test_get_pages_returns_all_pages_when_not_supplied_with_class_st
129129
public function test_get_pages_returns_empty_collection_when_no_pages_are_discovered()
130130
{
131131
$this->withoutDefaultPages();
132-
$collection = PageCollection::boot(Hyde::getInstance());
132+
$collection = PageCollection::init(Hyde::getInstance())->boot();
133133
$this->assertEmpty($collection->getPages());
134134
$this->restoreDefaultPages();
135135
}
@@ -145,7 +145,7 @@ public function test_pages_are_not_discovered_for_disabled_features()
145145
touch('_posts/post.md');
146146
touch('_docs/doc.md');
147147

148-
$this->assertEmpty(PageCollection::boot(Hyde::getInstance()));
148+
$this->assertEmpty(PageCollection::init(Hyde::getInstance())->boot());
149149

150150
unlink('_pages/blade.blade.php');
151151
unlink('_pages/markdown.md');
@@ -170,7 +170,7 @@ public function test_pages_with_custom_source_directories_are_discovered_properl
170170
touch(Hyde::path('.source/posts/foo.md'));
171171
touch(Hyde::path('.source/docs/foo.md'));
172172

173-
$collection = PageCollection::boot(Hyde::getInstance())->getPages();
173+
$collection = PageCollection::init(Hyde::getInstance())->boot()->getPages();
174174
$this->assertCount(4, $collection);
175175

176176
$this->assertEquals(new BladePage('foo'), $collection->get('.source/pages/foo.blade.php'));

packages/framework/tests/Feature/RouteCollectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class RouteCollectionTest extends TestCase
2323
{
2424
public function test_boot_method_discovers_all_pages()
2525
{
26-
$collection = RouteCollection::boot(Hyde::getInstance());
26+
$collection = RouteCollection::init(Hyde::getInstance())->boot();
2727

2828
$this->assertInstanceOf(RouteCollection::class, $collection);
2929
$this->assertInstanceOf(Collection::class, $collection);

packages/framework/tests/Unit/BaseFoundationCollectionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
*/
1414
class BaseFoundationCollectionTest extends TestCase
1515
{
16-
public function test_boot()
16+
public function test_init()
1717
{
18-
$booted = BaseFoundationCollectionTestClass::boot(HydeKernel::getInstance());
18+
$booted = BaseFoundationCollectionTestClass::init(HydeKernel::getInstance())->boot();
1919

2020
$this->assertInstanceOf(BaseFoundationCollection::class, $booted);
2121
$this->assertInstanceOf(BaseFoundationCollectionTestClass::class, $booted);
@@ -26,7 +26,7 @@ public function test_boot()
2626

2727
public function test_get_instance()
2828
{
29-
$booted = BaseFoundationCollectionTestClass::boot(HydeKernel::getInstance());
29+
$booted = BaseFoundationCollectionTestClass::init(HydeKernel::getInstance())->boot();
3030

3131
$this->assertSame($booted, $booted->getInstance());
3232
}

0 commit comments

Comments
 (0)