Skip to content

Commit

Permalink
Merge pull request #981 from hydephp/rename-foundation-collection-fac…
Browse files Browse the repository at this point in the history
…ades

Rename foundation collection facades
  • Loading branch information
caendesilva authored Feb 12, 2023
2 parents 8cb6a7e + 8f68520 commit c430ff2
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Exception;
use Hyde\Console\Concerns\Command;
use Hyde\Foundation\Facades\PageCollection;
use Hyde\Foundation\Facades\Pages;
use Hyde\Framework\Features\BuildTasks\BuildTask;
use Hyde\Framework\Services\BuildService;
use Hyde\Framework\Services\RebuildService;
Expand Down Expand Up @@ -73,7 +73,7 @@ public function run(): void
public function then(): void
{
$this->createdSiteFile(Command::createClickableFilepath(
PageCollection::getPage($this->path)->getOutputPath()
Pages::getPage($this->path)->getOutputPath()
))->withExecutionTime();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
namespace Hyde\Foundation\Facades;

use Hyde\Foundation\HydeKernel;
use Hyde\Foundation\Kernel\FileCollection;
use Illuminate\Support\Facades\Facade;

/**
* @mixin \Hyde\Foundation\Kernel\FileCollection
*/
class FileCollection extends Facade
class Files extends Facade
{
public static function getFacadeRoot(): \Hyde\Foundation\Kernel\FileCollection
public static function getFacadeRoot(): FileCollection
{
return HydeKernel::getInstance()->files();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
namespace Hyde\Foundation\Facades;

use Hyde\Foundation\HydeKernel;
use Hyde\Foundation\Kernel\PageCollection;
use Illuminate\Support\Facades\Facade;

/**
* @mixin \Hyde\Foundation\Kernel\PageCollection
*/
class PageCollection extends Facade
class Pages extends Facade
{
public static function getFacadeRoot(): \Hyde\Foundation\Kernel\PageCollection
public static function getFacadeRoot(): PageCollection
{
return HydeKernel::getInstance()->pages();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @mixin \Hyde\Foundation\Kernel\RouteCollection
*/
class Router extends Facade
class Routes extends Facade
{
public static function getFacadeRoot(): RouteCollection
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* This class is stored as a singleton in the HydeKernel.
* You would commonly access it via one of the facades:
*
* @see \Hyde\Foundation\Facades\FileCollection
* @see \Hyde\Foundation\Facades\Files
* @see \Hyde\Hyde::files()
*/
final class FileCollection extends BaseFoundationCollection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use function collect;
use function config;
use Hyde\Foundation\Facades\Router;
use Hyde\Foundation\Facades\Routes;
use Hyde\Support\Models\Route;
use Illuminate\Support\Collection;

Expand All @@ -30,7 +30,7 @@ public static function create(): static
/** @return $this */
public function generate(): static
{
Router::each(function (Route $route): void {
Routes::each(function (Route $route): void {
$this->items->put($route->getRouteKey(), NavItem::fromRoute($route));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Hyde\Framework\Features\Navigation;

use Hyde\Foundation\Facades\Router;
use Hyde\Foundation\Facades\Routes;
use Hyde\Pages\DocumentationPage;
use Hyde\Support\Models\Route;
use Illuminate\Support\Collection;
Expand All @@ -18,7 +18,7 @@ class DocumentationSidebar extends BaseNavigationMenu
/** @return $this */
public function generate(): static
{
Router::getRoutes(DocumentationPage::class)->each(function (Route $route): void {
Routes::getRoutes(DocumentationPage::class)->each(function (Route $route): void {
$this->items->put($route->getRouteKey(), NavItem::fromRoute($route));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use function class_exists;
use function config;
use function glob;
use Hyde\Foundation\Facades\FileCollection;
use Hyde\Foundation\Facades\Files;
use Hyde\Framework\Exceptions\UnsupportedPageTypeException;
use Hyde\Hyde;
use Hyde\Pages\BladePage;
Expand Down Expand Up @@ -74,7 +74,7 @@ public static function getSourceFileListForModel(string $model): array
throw new UnsupportedPageTypeException($model);
}

return FileCollection::getSourceFiles($model)->flatten()->map(function (SourceFile $file) use ($model): string {
return Files::getSourceFiles($model)->flatten()->map(function (SourceFile $file) use ($model): string {
return static::pathToIdentifier($model, $file->withoutDirectoryPrefix());
})->toArray();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/src/Framework/Services/RebuildService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Hyde\Framework\Services;

use Hyde\Foundation\Facades\PageCollection;
use Hyde\Foundation\Facades\Pages;
use Hyde\Framework\Actions\StaticPageBuilder;

/**
Expand Down Expand Up @@ -42,7 +42,7 @@ public function __construct(string $filepath)
public function execute(): StaticPageBuilder
{
return $this->builder = (new StaticPageBuilder(
PageCollection::getPage($this->filepath),
Pages::getPage($this->filepath),
true
));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/src/Pages/Concerns/HydePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static function files(): array
*/
public static function all(): PageCollection
{
return Facades\PageCollection::getPages(static::class);
return Facades\Pages::getPages(static::class);
}

// Section: Filesystem
Expand Down
6 changes: 3 additions & 3 deletions packages/framework/src/Support/Models/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Hyde\Support\Models;

use Hyde\Foundation\Facades\Router;
use Hyde\Foundation\Facades\Routes;
use Hyde\Foundation\Kernel\RouteCollection;
use Hyde\Framework\Exceptions\RouteNotFoundException;
use Hyde\Hyde;
Expand Down Expand Up @@ -112,7 +112,7 @@ public function toArray(): array

public static function get(string $routeKey): ?Route
{
return Router::get(str_replace('.', '/', $routeKey));
return Routes::get(str_replace('.', '/', $routeKey));
}

public static function getOrFail(string $routeKey): Route
Expand All @@ -132,6 +132,6 @@ public static function current(): ?Route

public static function exists(string $routeKey): bool
{
return Router::has($routeKey);
return Routes::has($routeKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ public function test_custom_registered_pages_are_discovered_by_the_file_collecti
$this->file('foo/bar.txt');
app(HydeKernel::class)->registerPageClass(TestPageClassWithSourceInformation::class);

$this->assertArrayHasKey('foo/bar.txt', Facades\FileCollection::all());
$this->assertEquals(new SourceFile('foo/bar.txt', TestPageClassWithSourceInformation::class), Facades\FileCollection::get('foo/bar.txt'));
$this->assertArrayHasKey('foo/bar.txt', Facades\Files::all());
$this->assertEquals(new SourceFile('foo/bar.txt', TestPageClassWithSourceInformation::class), Facades\Files::get('foo/bar.txt'));
}

public function test_custom_registered_pages_are_discovered_by_the_page_collection_class()
{
$this->directory('foo');
$this->file('foo/bar.txt');
app(HydeKernel::class)->registerPageClass(TestPageClassWithSourceInformation::class);
$this->assertArrayHasKey('foo/bar.txt', Facades\PageCollection::all());
$this->assertEquals(new TestPageClassWithSourceInformation('bar'), Facades\PageCollection::get('foo/bar.txt'));
$this->assertArrayHasKey('foo/bar.txt', Facades\Pages::all());
$this->assertEquals(new TestPageClassWithSourceInformation('bar'), Facades\Pages::get('foo/bar.txt'));
}

public function test_custom_registered_pages_are_discovered_by_the_route_collection_class()
{
$this->directory('foo');
$this->file('foo/bar.txt');
app(HydeKernel::class)->registerPageClass(TestPageClassWithSourceInformation::class);
$this->assertArrayHasKey('foo/bar', Facades\Router::all());
$this->assertEquals(new Route(new TestPageClassWithSourceInformation('bar')), Facades\Router::get('foo/bar'));
$this->assertArrayHasKey('foo/bar', Facades\Routes::all());
$this->assertEquals(new Route(new TestPageClassWithSourceInformation('bar')), Facades\Routes::get('foo/bar'));
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/framework/tests/Feature/NavigationMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use BadMethodCallException;
use function collect;
use function config;
use Hyde\Foundation\Facades\Router;
use Hyde\Foundation\Facades\Routes;
use Hyde\Framework\Features\Navigation\DropdownNavItem;
use Hyde\Framework\Features\Navigation\NavigationMenu;
use Hyde\Framework\Features\Navigation\NavItem;
Expand Down Expand Up @@ -393,8 +393,8 @@ public function test_pages_in_dropdowns_do_not_get_added_to_the_main_navigation(
{
config(['hyde.navigation.subdirectories' => 'dropdown']);

Router::push((new MarkdownPage('foo'))->getRoute());
Router::push((new MarkdownPage('bar/baz'))->getRoute());
Routes::push((new MarkdownPage('foo'))->getRoute());
Routes::push((new MarkdownPage('bar/baz'))->getRoute());
$menu = NavigationMenu::create();

$this->assertCount(3, $menu->items);
Expand Down
28 changes: 15 additions & 13 deletions packages/framework/tests/Unit/FoundationFacadesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,63 @@

namespace Hyde\Framework\Testing\Unit;

use Hyde\Foundation\Facades\FileCollection;
use Hyde\Foundation\Facades\PageCollection;
use Hyde\Foundation\Facades\Router;
use Hyde\Foundation\Facades\Files;
use Hyde\Foundation\Facades\Pages;
use Hyde\Foundation\Facades\Routes;
use Hyde\Foundation\HydeKernel;
use Hyde\Hyde;
use Hyde\Testing\TestCase;

/**
* @covers \Hyde\Foundation\Facades\FileCollection
* @covers \Hyde\Foundation\Facades\Files
* @covers \Hyde\Foundation\Facades\Pages
* @covers \Hyde\Foundation\Facades\Routes
*/
class FoundationFacadesTest extends TestCase
{
public function test_file_collection_facade()
{
$this->assertSame(
HydeKernel::getInstance()->files(),
FileCollection::getInstance()
Files::getInstance()
);

$this->assertEquals(
Hyde::files()->getSourceFiles(),
FileCollection::getSourceFiles()
Files::getSourceFiles()
);
}

public function test_page_collection_facade()
{
$this->assertSame(
HydeKernel::getInstance()->pages(),
PageCollection::getInstance()
Pages::getInstance()
);

$this->assertEquals(
Hyde::pages()->getPages(),
PageCollection::getPages()
Pages::getPages()
);
}

public function test_route_collection_facade()
{
$this->assertSame(
HydeKernel::getInstance()->routes(),
Router::getInstance()
Routes::getInstance()
);

$this->assertEquals(
Hyde::routes()->getRoutes(),
Router::getRoutes()
Routes::getRoutes()
);
}

public function test_facade_roots()
{
$this->assertSame(FileCollection::getInstance(), FileCollection::getFacadeRoot());
$this->assertSame(PageCollection::getInstance(), PageCollection::getFacadeRoot());
$this->assertSame(Router::getInstance(), Router::getFacadeRoot());
$this->assertSame(Files::getInstance(), Files::getFacadeRoot());
$this->assertSame(Pages::getInstance(), Pages::getFacadeRoot());
$this->assertSame(Routes::getInstance(), Routes::getFacadeRoot());
}
}

0 comments on commit c430ff2

Please sign in to comment.