InMemoryPage
extends HydePage
in package
Extendable class for in-memory (or virtual) Hyde pages that are not based on any source files.
When used in a package, it's on the package developer to ensure that the virtual page is registered with Hyde, usually within the boot method of the package's service provider, or a page collection callback in an extension. This is because these pages cannot be discovered by the auto discovery process as there's no source files to parse.
This class is especially useful for one-off custom pages. But if your usage grows, or if you want to utilize Hyde autodiscovery, you may benefit from creating a custom page class instead, as that will give you full control.
Table of Contents
Properties
- $fileExtension : string
- $identifier : string
- $matter : FrontMatter
- $metadata : PageMetadataBag
- $navigation : NavigationData
- $outputDirectory : string
- $routeKey : string
- $sourceDirectory : string
- $template : string
- $title : string
- $contents : string
- $macros : array<string, callable>
- $view : string
Methods
- __call() : mixed
- Dynamically handle macro calls to the class.
- __construct() : mixed
- Create a new in-memory/virtual page instance.
- all() : PageCollection<string|int, static>
- Get a collection of all pages, parsed into page models.
- arraySerialize() : array<string|int, mixed>
- Recursively serialize Arrayables
- baseRouteKey() : string
- Get the route key base for the page model.
- compile() : string
- Get the contents that will be saved to disk for this page.
- data() : FrontMatter|mixed
- Get a value from the computed page data, or fallback to the page's front matter, then to the default value.
- fileExtension() : string
- Get the file extension of the source files for the page type.
- files() : array<string|int, string>
- Get an array of all the source file identifiers for the model.
- get() : static
- Get a page instance from the Kernel's page index by its identifier.
- getBladeView() : string
- Get the view key or Blade file for the view to use to render the page contents when this strategy is used.
- getCanonicalUrl() : string|null
- Get the canonical URL for the page to use in the `<link rel="canonical">` tag.
- getContents() : string
- Get the contents of the page. This will be saved as-is to the output file when this strategy is used.
- getIdentifier() : string
- Get the page model's identifier property.
- getLink() : string
- Format the page instance to a URL path, with support for pretty URLs if enabled.
- getOutputPath() : string
- Get the path where the compiled page will be saved.
- getRoute() : Route
- Get the route object for the page.
- getRouteKey() : string
- Get the route key for the page.
- getSourcePath() : string
- Get the path to the instance source file, relative to the project root.
- has() : bool
- See if a value exists in the computed page data or the front matter.
- hasMacro() : bool
- Determine if a macro with the given name is registered for the instance.
- isDiscoverable() : bool
- Returns whether the page type is discoverable through auto-discovery.
- jsonSerialize() : array<string|int, mixed>
- macro() : void
- Register a macro for the instance.
- make() : static
- Static alias for the constructor.
- matter() : FrontMatter|mixed
- Get the front matter object, or a value from within.
- metadata() : PageMetadataBag
- Get the generated metadata for the page.
- navigationMenuGroup() : string|null
- Get the group of the page in the navigation menu, if any.
- navigationMenuLabel() : string
- Get the label of the page in the navigation menu.
- navigationMenuPriority() : int
- Get the priority of the page in the navigation menu.
- outputDirectory() : string
- Get the output subdirectory to store compiled HTML files for the page type.
- outputPath() : string
- Qualify a page identifier into a target output file path, relative to the _site output directory.
- parse() : static
- Parse a source file into a new page model instance.
- path() : string
- Get an absolute file path to the page's source directory, or a file within it.
- pathToIdentifier() : string
- Format a filename to an identifier for a given model. Unlike the basename function, any nested paths within the source directory are retained in order to satisfy the page identifier definition.
- setFileExtension() : void
- Set the file extension for the page type.
- setOutputDirectory() : void
- Set the source directory for the page type.
- setSourceDirectory() : void
- Set the output directory for the page type.
- showInNavigation() : bool
- Can the page be shown in the navigation menu?
- sourceDirectory() : string
- Get the directory where source files are stored for the page type.
- sourcePath() : string
- Qualify a page identifier into file path to the source file, relative to the project root.
- title() : string
- Get the page title to display in HTML tags like `<title>` and `<meta>` tags.
- toArray() : array<string|int, mixed>
- Get the instance as an array.
- toCoreDataObject() : CoreDataObject
- toJson() : string
- assignFactoryData() : void
- automaticallySerialize() : array<string|int, mixed>
- Automatically serialize all public properties.
- callMacro() : mixed
- constructFactoryData() : void
- constructMetadata() : void
Properties
$fileExtension
public
static string
$fileExtension
$identifier read-only
public
string
$identifier
$matter
public
FrontMatter
$matter
$metadata
public
PageMetadataBag
$metadata
$navigation
public
NavigationData
$navigation
$outputDirectory
public
static string
$outputDirectory
$routeKey read-only
public
string
$routeKey
$sourceDirectory
public
static string
$sourceDirectory
$template
public
static string
$template
$title read-only
public
string
$title
$contents
protected
string
$contents
$macros
protected
array<string, callable>
$macros
= []
$view
protected
string
$view
Methods
__call()
Dynamically handle macro calls to the class.
public
__call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
__construct()
Create a new in-memory/virtual page instance.
public
__construct([string $identifier = '' ][, FrontMatter|array<string|int, mixed> $matter = [] ][, string $contents = '' ][, string $view = '' ]) : mixed
The in-memory page class offers two content options. You can either pass a string to the $contents parameter, Hyde will then save that literally as the page's contents. Alternatively, you can pass a view name to the $view parameter, and Hyde will use that view to render the page contents with the supplied front matter during the static site build process.
Note that $contents take precedence over $view, so if you pass both, only $contents will be used. You can also register a macro with the name 'compile' to overload the default compile method.
Parameters
- $identifier : string = ''
-
The identifier of the page. This is used to generate the route key which is used to create the output filename. If the identifier for an in-memory page is "foo/bar" the page will be saved to "_site/foo/bar.html". You can then also use the route helper to get a link to it by using the route key "foo/bar". Take note that the identifier must be unique to prevent overwriting other pages.
- $matter : FrontMatter|array<string|int, mixed> = []
-
The front matter of the page. When using the Blade view rendering option, all this data will be passed to the view rendering engine.
- $contents : string = ''
-
The contents of the page. This will be saved as-is to the output file.
- $view : string = ''
-
The view key or Blade file for the view to use to render the page contents.
all()
Get a collection of all pages, parsed into page models.
public
static all() : PageCollection<string|int, static>
Return values
PageCollection<string|int, static>arraySerialize()
Recursively serialize Arrayables
public
arraySerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>baseRouteKey()
Get the route key base for the page model.
public
static baseRouteKey() : string
This is the same value as the output directory.
Return values
stringcompile()
Get the contents that will be saved to disk for this page.
public
compile() : string
In order to make your virtual page easy to use we provide a few options for how the page can be compiled. If you want even more control, you can register a macro with the name 'compile' to overload the method, or simply extend the class and override the method yourself, either in a standard or anonymous class.
Return values
string —The compiled HTML for the page.
data()
Get a value from the computed page data, or fallback to the page's front matter, then to the default value.
public
data([string $key = null ][, mixed $default = null ]) : FrontMatter|mixed
Parameters
- $key : string = null
- $default : mixed = null
Return values
FrontMatter|mixedfileExtension()
Get the file extension of the source files for the page type.
public
static fileExtension() : string
Return values
stringfiles()
Get an array of all the source file identifiers for the model.
public
static files() : array<string|int, string>
Note that the values do not include the source directory or file extension.
Return values
array<string|int, string>get()
Get a page instance from the Kernel's page index by its identifier.
public
static get(string $identifier) : static
Parameters
- $identifier : string
Tags
Return values
staticgetBladeView()
Get the view key or Blade file for the view to use to render the page contents when this strategy is used.
public
getBladeView() : string
Return values
stringgetCanonicalUrl()
Get the canonical URL for the page to use in the `<link rel="canonical">` tag.
public
getCanonicalUrl() : string|null
It can be explicitly set in the front matter using the canonicalUrl
key,
otherwise it will be generated based on the site URL and the output path,
unless there is no configured base URL, leading to this returning null.
Return values
string|nullgetContents()
Get the contents of the page. This will be saved as-is to the output file when this strategy is used.
public
getContents() : string
Return values
stringgetIdentifier()
Get the page model's identifier property.
public
getIdentifier() : string
The identifier is the part between the source directory and the file extension. It may also be known as a 'slug', or previously 'basename', but it retains the nested path structure if the page is stored in a subdirectory.
For example, the identifier of a source file stored as '_pages/about/contact.md' would be 'about/contact', and 'pages/about.md' would simply be 'about'.
Return values
stringgetLink()
Format the page instance to a URL path, with support for pretty URLs if enabled.
public
getLink() : string
Note that the link is always relative to site root, and does not contain ../
segments.
Return values
stringgetOutputPath()
Get the path where the compiled page will be saved.
public
getOutputPath() : string
Return values
string —Path relative to the site output directory.
getRoute()
Get the route object for the page.
public
getRoute() : Route
Return values
RoutegetRouteKey()
Get the route key for the page.
public
getRouteKey() : string
The route key is the page URL path, relative to the site root, but without any file extensions.
For example, if the page will be saved to _site/docs/index.html
, the key is docs/index
.
Route keys are used to identify page routes, similar to how named routes work in Laravel,
only that here the name is not just arbitrary, but also defines the output location,
as the route key is used to determine the output path which is $routeKey.html
.
Return values
stringgetSourcePath()
Get the path to the instance source file, relative to the project root.
public
getSourcePath() : string
Return values
stringhas()
See if a value exists in the computed page data or the front matter.
public
has(string $key) : bool
Parameters
- $key : string
Return values
boolhasMacro()
Determine if a macro with the given name is registered for the instance.
public
hasMacro(string $method) : bool
Parameters
- $method : string
Return values
boolisDiscoverable()
Returns whether the page type is discoverable through auto-discovery.
public
static isDiscoverable() : bool
Return values
booljsonSerialize()
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>macro()
Register a macro for the instance.
public
macro(string $name, callable $macro) : void
Unlike most macros you might be used to, these are not static, meaning they belong to the instance. If you have the need for a macro to be used for multiple pages, you should create a custom page class instead.
Parameters
- $name : string
- $macro : callable
make()
Static alias for the constructor.
public
static make([string $identifier = '' ][, FrontMatter|array<string|int, mixed> $matter = [] ][, string $contents = '' ][, string $view = '' ]) : static
Parameters
- $identifier : string = ''
- $matter : FrontMatter|array<string|int, mixed> = []
- $contents : string = ''
- $view : string = ''
Return values
staticmatter()
Get the front matter object, or a value from within.
public
matter([string $key = null ][, mixed $default = null ]) : FrontMatter|mixed
Parameters
- $key : string = null
- $default : mixed = null
Return values
FrontMatter|mixedmetadata()
Get the generated metadata for the page.
public
metadata() : PageMetadataBag
Return values
PageMetadataBagnavigationMenuGroup()
Get the group of the page in the navigation menu, if any.
public
navigationMenuGroup() : string|null
Return values
string|nullnavigationMenuLabel()
Get the label of the page in the navigation menu.
public
navigationMenuLabel() : string
Return values
stringnavigationMenuPriority()
Get the priority of the page in the navigation menu.
public
navigationMenuPriority() : int
Return values
intoutputDirectory()
Get the output subdirectory to store compiled HTML files for the page type.
public
static outputDirectory() : string
Return values
stringoutputPath()
Qualify a page identifier into a target output file path, relative to the _site output directory.
public
static outputPath(string $identifier) : string
Parameters
- $identifier : string
Return values
stringparse()
Parse a source file into a new page model instance.
public
static parse(string $identifier) : static
Parameters
- $identifier : string
-
The identifier of the page to parse.
Tags
Return values
static —New page model instance for the parsed source file.
path()
Get an absolute file path to the page's source directory, or a file within it.
public
static path([string $path = '' ]) : string
Parameters
- $path : string = ''
Return values
stringpathToIdentifier()
Format a filename to an identifier for a given model. Unlike the basename function, any nested paths within the source directory are retained in order to satisfy the page identifier definition.
public
static pathToIdentifier(string $path) : string
Parameters
- $path : string
-
Example: index.blade.php
Return values
string —Example: index
setFileExtension()
Set the file extension for the page type.
public
static setFileExtension(string $fileExtension) : void
Parameters
- $fileExtension : string
setOutputDirectory()
Set the source directory for the page type.
public
static setOutputDirectory(string $outputDirectory) : void
Parameters
- $outputDirectory : string
setSourceDirectory()
Set the output directory for the page type.
public
static setSourceDirectory(string $sourceDirectory) : void
Parameters
- $sourceDirectory : string
showInNavigation()
Can the page be shown in the navigation menu?
public
showInNavigation() : bool
Return values
boolsourceDirectory()
Get the directory where source files are stored for the page type.
public
static sourceDirectory() : string
Return values
stringsourcePath()
Qualify a page identifier into file path to the source file, relative to the project root.
public
static sourcePath(string $identifier) : string
Parameters
- $identifier : string
Return values
stringtitle()
Get the page title to display in HTML tags like `<title>` and `<meta>` tags.
public
title() : string
Return values
stringtoArray()
Get the instance as an array.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>toCoreDataObject()
public
toCoreDataObject() : CoreDataObject
Return values
CoreDataObjecttoJson()
public
toJson([int $options = 0 ]) : string
Parameters
- $options : int = 0
Return values
stringassignFactoryData()
protected
assignFactoryData(PageDataFactory $factory) : void
Parameters
- $factory : PageDataFactory
automaticallySerialize()
Automatically serialize all public properties.
protected
automaticallySerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>callMacro()
protected
callMacro(callable $macro, array<string|int, mixed> $parameters) : mixed
Parameters
- $macro : callable
- $parameters : array<string|int, mixed>
constructFactoryData()
protected
constructFactoryData() : void
constructMetadata()
protected
constructMetadata() : void