-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #631 from hydephp/refactor-to-use-factories
Refactor the page data factory pipeline
- Loading branch information
Showing
5 changed files
with
97 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/framework/src/Framework/Factories/Concerns/CoreDataObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyde\Framework\Factories\Concerns; | ||
|
||
use Hyde\Markdown\Models\FrontMatter; | ||
use Hyde\Markdown\Models\Markdown; | ||
use Hyde\Support\Concerns\JsonSerializesArrayable; | ||
use Illuminate\Contracts\Support\Arrayable; | ||
use JsonSerializable; | ||
|
||
/** | ||
* Experimental class to contain the core data for a page being constructed. | ||
* | ||
* It should contain immutable data known at the very start of construction. | ||
* In addition to the front matter and markdown, the data should contain | ||
* everything needed to identify the unique page being constructed. | ||
* | ||
* The benefit of using this class over passing around the page object when constructing a page is | ||
* that the latter's state is unpredictable due to the nature of the construction process continuously | ||
* mutating the page object. This class on the other hand is immutable, making it highly predictable. | ||
*/ | ||
final class CoreDataObject implements Arrayable, JsonSerializable | ||
{ | ||
use JsonSerializesArrayable; | ||
|
||
public function __construct( | ||
public readonly FrontMatter $matter, | ||
public readonly Markdown|false $markdown, | ||
public readonly string $pageClass, | ||
public readonly string $identifier, | ||
public readonly string $sourcePath, | ||
public readonly string $outputPath, | ||
public readonly string $routeKey, | ||
) { | ||
// | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'pageClass' => $this->pageClass, | ||
'identifier' => $this->identifier, | ||
'sourcePath' => $this->sourcePath, | ||
'outputPath' => $this->outputPath, | ||
'routeKey' => $this->routeKey, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters