Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| PublishesHomepageView | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Hyde\Framework\Actions; |
| 4 | |
| 5 | use Hyde\Framework\Contracts\ActionContract; |
| 6 | use Hyde\Framework\Hyde; |
| 7 | |
| 8 | /** |
| 9 | * Publish one of the Hyde homepages. |
| 10 | * |
| 11 | * @see \Tests\Feature\Actions\PublishesHomepageViewTest |
| 12 | */ |
| 13 | class PublishesHomepageView implements ActionContract |
| 14 | { |
| 15 | public static array $homePages = [ |
| 16 | 'welcome' => [ |
| 17 | 'name' => 'Welcome', |
| 18 | 'path' => 'resources/views/homepages/welcome.blade.php', |
| 19 | 'description' => 'The default welcome page.', |
| 20 | ], |
| 21 | 'posts' => [ |
| 22 | 'name' => 'Posts Feed', |
| 23 | 'path' => 'resources/views/homepages/post-feed.blade.php', |
| 24 | 'description' => 'A feed of your latest posts. Perfect for a blog site!', |
| 25 | ], |
| 26 | 'blank' => [ |
| 27 | 'name' => 'Blank Starter', |
| 28 | 'path' => 'resources/views/homepages/blank.blade.php', |
| 29 | 'description' => 'A blank Blade template with just the base layout.', |
| 30 | ], |
| 31 | ]; |
| 32 | |
| 33 | protected string $selected; |
| 34 | protected bool $force = false; |
| 35 | |
| 36 | public function __construct(string $selected, bool $force = false) |
| 37 | { |
| 38 | $this->force = $force; |
| 39 | $this->selected = $selected; |
| 40 | } |
| 41 | |
| 42 | public function execute(): bool|int |
| 43 | { |
| 44 | if (! array_key_exists($this->selected, self::$homePages)) { |
| 45 | return 404; |
| 46 | } |
| 47 | |
| 48 | return Hyde::copy( |
| 49 | Hyde::vendorPath(static::$homePages[$this->selected]['path']), |
| 50 | Hyde::getBladePagePath('index.blade.php'), |
| 51 | $this->force |
| 52 | ); |
| 53 | } |
| 54 | } |