Skip to content

Static pages#9

Open
OStefan2001 wants to merge 1 commit into
developfrom
stefan-dev
Open

Static pages#9
OStefan2001 wants to merge 1 commit into
developfrom
stefan-dev

Conversation

@OStefan2001

Copy link
Copy Markdown
Collaborator

Static pages and generic route

</li>
<li class="nav-item">
<a class="nav-link px-3 fw-semibold fs-5 transition-all" href="{{ url('page::dotkernel-packages-oss-lifecycle') }}">Packages Lifecycle</a>
<a class="nav-link px-3 fw-semibold fs-5 transition-all" href="{{ url('page::static-page', {'static-page': 'dotkernel-packages-oss-lifecycle'}) }}">Packages Lifecycle</a>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why couldn't you reuse the already existing static page implementation for this?

If you look in config/autoload/local.php.dist you'll find an array where static page routes are defined (under routespage).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created new route because i wanted to use some data from database (recent posts or categories) and I didn't figured out how to send my data using routes from local.php for every static page(contact, about...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your surrent solution does not differ from the original one - it just moves the logic to a different place.
Injecting those dependencies should work the same way in both cases:

Your solution

Injects TemplateRendererInterface, PostRepository and CategoryRepository into src/Blog/src/Handler/GetStaticPageDataHandler.php via src/Blog/src/Factory/StaticPages/GetStaticPageDataFactory.php.

Original solution

Injects TemplateRendererInterface into src/Page/src/Handler/GetPageViewHandler.php via src/Page/src/Factory/GetPageViewHandlerFactory.php.

You should be able to reuse this factory to inject whatever you need into GetPageViewHandler via GetPageViewHandlerFactory.

After that, you can remove GetStaticPageDataHandler and GetStaticPageDataFactory.

</ul>
<div class="d-none d-lg-block">
<a href="{{ url('page::contact') }}" class="btn btn-primary rounded-pill px-4">Contact</a>
<a href="{{ url('page::static-page', {'static-page': 'contact'}) }}" class="btn btn-primary rounded-pill px-4">Contact</a>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the above comment.

</div>
</div>
</div>
{% if posts is defined and posts %}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{% if posts is defined and posts %}
{% if posts is defined and posts is iterable %}

'posts' => $posts,
]);
} catch (Throwable $e) {
return $this->notFound();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The notFound() method duplicates the database query behind this code:

$categories = $this->categoryRepository->getCategories();

Since the functionality of the notFound() method is not reused elsewhere, you could replace this live with its contents - solving this way for the code duplication.

$this->template->render('error::404', [
'categories' => $categories,
]),
404

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if you have vendor/fig/http-message-util/src/StatusCodeInterface.php; if it does not exist, skip the below.

You should avoid using numeric status codes and use the constants defined as standards.

They have the same effect, we just prefer to use standards when possible. It also helps readability when you see StatusCodeInterface::STATUS_NOT_FOUND instead of 404.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix this

$app->get('/author/{slug}/', [GetAuthorResourceHandler::class], 'page::author-resource');
$app->get('/{categorySlug}/{slug}/', [GetPostResourceHandler::class], 'page::blog-resource');

$app->get('/{static-page}/', [GetStaticPageDataHandler::class], 'page::static-page');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to my comments regarding the existing static pages implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants