DEV Community

Cover image for Internal Architecture of HydePHP - Part 2: Services
CodeWithCaen
CodeWithCaen

Posted on • Edited on • Originally published at hydephp.com

5 3

Internal Architecture of HydePHP - Part 2: Services

A Deep Dive into Services

Deep-Dives takes a closer look at the codebase and tries to explain what's going on.

This article is the second installation in my series on the internal architecture of HydePHP.
If you haven't read part one already, you should do that first. Here is a quick link Internal Architecture of HydePHP - Part 1: Introduction.

Taking a look at a Service

Let's take a look at a relatively new Service Class, the DocumentationSidebarService, to get a better understanding of how a Service is used through practical examples.

Here is a link to the source code on GitHub.

This Service is as you may have guessed used to manage the sidebar in documentation pages!

When using sidebar data in the Blade views, we interact with the Service to get the data we need.

You are of course free to take a look at the source code to get a better understanding of how it all fits together, however here are some examples loosely plucked from the code.

$sidebar = Hyde\Framework\Services\DocumentationSidebarService::create();

@if($sidebar->hasCategories())
    @foreach ($sidebar->getCategories() as $category)
        @foreach ($sidebar->getItemsInCategory($category) as $item)

@else
    @foreach ($sidebar->getSidebar() as $item)
Enter fullscreen mode Exit fullscreen mode

As you can see, the Service gives access to a lot of data and logic.
However, the Service does not do much of the heavy lifting. True, the Service contains methods to create and modify data,
and while it is responsible for generating the sidebar, it actually leverages other components to do the heavy lifting.

For example, the DocumentationSidebarService::create() method is used to create a new instance of the Service containing
a freshly generated sidebar, but the fetching of items to put in the sidebar is done by the CollectionService, the
actual parsing to get front matter data is done in the sidebar item model. The categorization is handled in a Concern.

/**
 * @example Hyde\Framework\Services\DocumentationSidebarService::create()
 **/
public static function create(): static
{
    return (new static)->createSidebar()->withoutIndex()->withoutHidden();
}
Enter fullscreen mode Exit fullscreen mode

Next Up

Make sure to check out the How Hyde knows what to do with your Markdown post (launching tomorrow).

Image of Bright Data

High-Quality Data for AI – Access diverse datasets ready for your ML models.

Browse our extensive library of pre-collected datasets tailored for various AI and ML projects.

Explore Datasets

Top comments (0)

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay