Skip to content

The HydeKernel

Introduction

In the centre, or should I say core, of HydePHP is the HydeKernel. The kernel encapsulates a HydePHP project and provides helpful methods for interacting with it. You can think of it as the heart of HydePHP, if you're a romantic.

The HydeKernel is so important that you have probably used it already. The main entry point for the HydePHP API is the Hyde facade, which calls methods on the kernel.

1use Hyde\Hyde;
2use Hyde\Foundation\HydeKernel;
3 
4Hyde::version(); // calls $HydeKernel->version()

The kernel is created very early on in the application lifecycle, in the bootstrap.php file, where it is also bound as a singleton into the application service container.

Accessing the Kernel

The HydeKernel is stored as a singleton in a static property in its own class and can be accessed in a few ways.

Commonly, you'll use the Hyde facade which forwards calls to the singleton instance. You can also use the hyde() function to get the Kernel, and call methods on it.

Since the instance is also bound into the Laravel Application Service Container you can also use Dependency Injection by type-hinting the HydeKernel::class.

Here are some examples of how you can call methods on the Kernel. All methods call the same method on the same instance, so it's just a matter of preference.

1use Hyde\Hyde;
2use Hyde\Foundation\HydeKernel;
3 
4Hyde::version();
5Hyde::kernel()->version();
6HydeKernel::getInstance()->version();
7app(HydeKernel::class)->version();
8hyde()->version();

The Kernel instance is constructed in bootstrap.php, and is available globally as $hyde.

The Kernel Lifecycle

Whenever we talk about the kernel being "booted" we are talking about the kernel's role in the autodiscovery process.

You can read all about it in the Autodiscovery Documentation.

API Reference

Since the most common way to interact with the kernel is through the Hyde facade, we will use that for the examples. But you could just as well chain the methods on the accessed kernel singleton instance if you wanted.

version()

No description provided.

Hyde::version(): string

__construct()

No description provided.

$hyde = new HydeKernel(string $basePath): void

features()

No description provided.

Hyde::features(): Hyde\Facades\Features

hasFeature()

No description provided.

Hyde::hasFeature(string $feature): bool

toArray()

Get the instance as an array.

Hyde::toArray(): array<TKey, TValue>

files()

No description provided.

Hyde::files(): \Hyde\Foundation\Kernel\FileCollection<string, \Hyde\Support\Filesystem\ProjectFile>

pages()

No description provided.

Hyde::pages(): \Hyde\Foundation\Kernel\PageCollection<string, \Hyde\Pages\Concerns\HydePage>

routes()

No description provided.

Hyde::routes(): \Hyde\Foundation\Kernel\RouteCollection<string, \Hyde\Support\Models\Route>

makeTitle()

No description provided.

Hyde::makeTitle(string $value): string

normalizeNewlines()

No description provided.

Hyde::normalizeNewlines(string $string): string

stripNewlines()

No description provided.

Hyde::stripNewlines(string $string): string

trimSlashes()

No description provided.

Hyde::trimSlashes(string $string): string

markdown()

No description provided.

Hyde::markdown(string $text, bool $normalizeIndentation): Illuminate\Support\HtmlString

filesystem()

No description provided.

Hyde::filesystem(): Hyde\Foundation\Kernel\Filesystem

path()

No description provided.

Hyde::path(string $path): string

vendorPath()

No description provided.

Hyde::vendorPath(string $path, string $package): string

mediaPath()

No description provided.

Hyde::mediaPath(string $path): string

sitePath()

No description provided.

Hyde::sitePath(string $path): string

siteMediaPath()

No description provided.

Hyde::siteMediaPath(string $path): string

pathToAbsolute()

No description provided.

Hyde::pathToAbsolute(array|string $path): array|string

pathToRelative()

No description provided.

Hyde::pathToRelative(string $path): string

getInstance()

No description provided.

Hyde::getInstance(): Hyde\Foundation\HydeKernel

setInstance()

No description provided.

Hyde::setInstance(Hyde\Foundation\HydeKernel $instance): void

getBasePath()

No description provided.

Hyde::getBasePath(): string

setBasePath()

No description provided.

Hyde::setBasePath(string $basePath): void

getSourceRoot()

No description provided.

Hyde::getSourceRoot(): string

setSourceRoot()

No description provided.

Hyde::setSourceRoot(string $sourceRoot): void

getOutputDirectory()

No description provided.

Hyde::getOutputDirectory(): string

setOutputDirectory()

No description provided.

Hyde::setOutputDirectory(string $outputDirectory): void

getMediaDirectory()

No description provided.

Hyde::getMediaDirectory(): string

setMediaDirectory()

No description provided.

Hyde::setMediaDirectory(string $mediaDirectory): void

getMediaOutputDirectory()

No description provided.

Hyde::getMediaOutputDirectory(): string

registerExtension()

Register a HydePHP extension within the HydeKernel.

Typically, you would call this method in the register method of a service provider. If your package uses the standard Laravel (Composer) package discovery feature, the extension will automatically be enabled when the package is installed.

Hyde::registerExtension(class-string&lt;\Hyde\Foundation\Concerns\HydeExtension&gt; $extension): void

getExtension()

Get the singleton instance of the specified extension.

Hyde::getExtension(class-string&lt;T&gt; $extension): T

hasExtension()

Determine if the specified extension is registered.

Hyde::hasExtension(class-string&lt;\Hyde\Foundation\Concerns\HydeExtension&gt; $extension): bool

getExtensions()

No description provided.

Hyde::getExtensions(): array<\Hyde\Foundation\Concerns\HydeExtension>

getRegisteredExtensions()

No description provided.

Hyde::getRegisteredExtensions(): array<class-string<\Hyde\Foundation\Concerns\HydeExtension>>

getRegisteredPageClasses()

No description provided.

Hyde::getRegisteredPageClasses(): array<class-string<\Hyde\Pages\Concerns\HydePage>>

shareViewData()

Share data for the page being rendered.

Hyde::shareViewData(Hyde\Pages\Concerns\HydePage $page): void

currentRouteKey()

Get the route key for the page being rendered.

Hyde::currentRouteKey(): string

currentRoute()

Get the route for the page being rendered.

Hyde::currentRoute(): Hyde\Support\Models\Route

currentPage()

Get the page being rendered.

Hyde::currentPage(): Hyde\Pages\Concerns\HydePage

isBooted()

Determine if the Kernel has booted.

Hyde::isBooted(): bool

boot()

Boot the Hyde Kernel and run the Auto-Discovery Process.

Hyde::boot(): void

booting()

Register a new boot listener.

Your callback will be called before the kernel is booted. You can use this to register your own routes, pages, etc. The kernel instance will be passed to your callback.

/** @param callable(\Hyde\Foundation\HydeKernel): void $callback */
Hyde::booting(callable(\Hyde\Foundation\HydeKernel): void): void

booted()

Register a new "booted" listener.

Your callback will be called after the kernel is booted. You can use this to run any logic after discovery has completed. The kernel instance will be passed to your callback.

/** @param callable(\Hyde\Foundation\HydeKernel): void $callback */
Hyde::booted(callable(\Hyde\Foundation\HydeKernel): void): void