Skip to content

Commit

Permalink
Merge pull request #429 from hydephp/organize-and-restructure-code
Browse files Browse the repository at this point in the history
Refactor HydeKernel code to organized single-used traits hydephp/develop@9f91a20
  • Loading branch information
github-actions committed Aug 26, 2022
1 parent ae75248 commit 4f4e75e
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 107 deletions.
71 changes: 71 additions & 0 deletions src/Foundation/Concerns/ForwardsFilesystem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Hyde\Framework\Foundation\Concerns;

/**
* @internal Single-use trait for the HydeKernel class.
*
* @see \Hyde\Framework\HydeKernel
*/
trait ForwardsFilesystem
{
public function path(string $path = ''): string
{
return $this->filesystem->path($path);
}

public function vendorPath(string $path = ''): string
{
return $this->filesystem->vendorPath($path);
}

public function copy(string $from, string $to): bool
{
return $this->filesystem->copy($from, $to);
}

public function touch(string|array $path): bool
{
return $this->filesystem->touch($path);
}

public function unlink(string|array $path): bool
{
return $this->filesystem->unlink($path);
}

public function getModelSourcePath(string $model, string $path = ''): string
{
return $this->filesystem->getModelSourcePath($model, $path);
}

public function getBladePagePath(string $path = ''): string
{
return $this->filesystem->getBladePagePath($path);
}

public function getMarkdownPagePath(string $path = ''): string
{
return $this->filesystem->getMarkdownPagePath($path);
}

public function getMarkdownPostPath(string $path = ''): string
{
return $this->filesystem->getMarkdownPostPath($path);
}

public function getDocumentationPagePath(string $path = ''): string
{
return $this->filesystem->getDocumentationPagePath($path);
}

public function getSiteOutputPath(string $path = ''): string
{
return $this->filesystem->getSiteOutputPath($path);
}

public function pathToRelative(string $path): string
{
return $this->filesystem->pathToRelative($path);
}
}
36 changes: 36 additions & 0 deletions src/Foundation/Concerns/ForwardsHyperlinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Hyde\Framework\Foundation\Concerns;

/**
* @internal Single-use trait for the HydeKernel class.
*
* @see \Hyde\Framework\HydeKernel
*/
trait ForwardsHyperlinks
{
public function formatHtmlPath(string $destination): string
{
return $this->hyperlinks->formatHtmlPath($destination);
}

public function relativeLink(string $destination): string
{
return $this->hyperlinks->relativeLink($destination);
}

public function image(string $name, bool $preferQualifiedUrl = false): string
{
return $this->hyperlinks->image($name, $preferQualifiedUrl);
}

public function hasSiteUrl(): bool
{
return $this->hyperlinks->hasSiteUrl();
}

public function url(string $path = '', ?string $default = null): string
{
return $this->hyperlinks->url($path, $default);
}
}
24 changes: 24 additions & 0 deletions src/Foundation/Concerns/ImplementsStringHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Hyde\Framework\Foundation\Concerns;

use Illuminate\Support\Str;

/**
* @internal Single-use trait for the HydeKernel class.
*
* @see \Hyde\Framework\HydeKernel
*/
trait ImplementsStringHelpers
{
public function makeTitle(string $slug): string
{
$alwaysLowercase = ['a', 'an', 'the', 'in', 'on', 'by', 'with', 'of', 'and', 'or', 'but'];

return ucfirst(str_ireplace(
$alwaysLowercase,
$alwaysLowercase,
Str::headline($slug)
));
}
}
122 changes: 15 additions & 107 deletions src/HydeKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Hyde\Framework\Helpers\Features;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;

/**
Expand All @@ -30,8 +29,12 @@
*/
class HydeKernel implements HydeKernelContract, Arrayable, \JsonSerializable
{
use Macroable;
use Foundation\Concerns\ImplementsStringHelpers;
use Foundation\Concerns\ForwardsHyperlinks;
use Foundation\Concerns\ForwardsFilesystem;

use JsonSerializesArrayable;
use Macroable;

protected static HydeKernel $instance;

Expand Down Expand Up @@ -109,127 +112,25 @@ public function currentRoute(): ?RouteContract

public function files(): FileCollection
{
if (! $this->booted) {
$this->boot();
}
$this->needsToBeBooted();

return $this->files;
}

public function pages(): PageCollection
{
if (! $this->booted) {
$this->boot();
}
$this->needsToBeBooted();

return $this->pages;
}

public function routes(): RouteCollection
{
if (! $this->booted) {
$this->boot();
}
$this->needsToBeBooted();

return $this->routes;
}

public function makeTitle(string $slug): string
{
$alwaysLowercase = ['a', 'an', 'the', 'in', 'on', 'by', 'with', 'of', 'and', 'or', 'but'];

return ucfirst(str_ireplace(
$alwaysLowercase,
$alwaysLowercase,
Str::headline($slug)
));
}

public function formatHtmlPath(string $destination): string
{
return $this->hyperlinks->formatHtmlPath($destination);
}

public function relativeLink(string $destination): string
{
return $this->hyperlinks->relativeLink($destination);
}

public function image(string $name, bool $preferQualifiedUrl = false): string
{
return $this->hyperlinks->image($name, $preferQualifiedUrl);
}

public function hasSiteUrl(): bool
{
return $this->hyperlinks->hasSiteUrl();
}

public function url(string $path = '', ?string $default = null): string
{
return $this->hyperlinks->url($path, $default);
}

public function path(string $path = ''): string
{
return $this->filesystem->path($path);
}

public function vendorPath(string $path = ''): string
{
return $this->filesystem->vendorPath($path);
}

public function copy(string $from, string $to): bool
{
return $this->filesystem->copy($from, $to);
}

public function touch(string|array $path): bool
{
return $this->filesystem->touch($path);
}

public function unlink(string|array $path): bool
{
return $this->filesystem->unlink($path);
}

public function getModelSourcePath(string $model, string $path = ''): string
{
return $this->filesystem->getModelSourcePath($model, $path);
}

public function getBladePagePath(string $path = ''): string
{
return $this->filesystem->getBladePagePath($path);
}

public function getMarkdownPagePath(string $path = ''): string
{
return $this->filesystem->getMarkdownPagePath($path);
}

public function getMarkdownPostPath(string $path = ''): string
{
return $this->filesystem->getMarkdownPostPath($path);
}

public function getDocumentationPagePath(string $path = ''): string
{
return $this->filesystem->getDocumentationPagePath($path);
}

public function getSiteOutputPath(string $path = ''): string
{
return $this->filesystem->getSiteOutputPath($path);
}

public function pathToRelative(string $path): string
{
return $this->filesystem->pathToRelative($path);
}

/**
* @inheritDoc
*
Expand All @@ -245,4 +146,11 @@ public function toArray(): array
'routes' => $this->routes(),
];
}

protected function needsToBeBooted(): void
{
if (! $this->booted) {
$this->boot();
}
}
}

0 comments on commit 4f4e75e

Please sign in to comment.