Skip to content

Commit 01a2cf0

Browse files
committed
Remove database fetch duplication and frontpage updates. Updated local.php.dist with my new routes
1 parent dc53f53 commit 01a2cf0

10 files changed

Lines changed: 1181 additions & 489 deletions

File tree

config/autoload/local.php.dist

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,36 @@
99

1010
declare(strict_types=1);
1111

12-
$baseUrl = 'http://light.dotkernel.localhost';
13-
12+
$baseUrl = 'light-blog.localhost';
13+
$databases = [
14+
'default' => [
15+
'host' => 'db_host',
16+
'dbname' => 'db_name',
17+
'user' => 'db_user',
18+
'password' => 'db_password',
19+
'port' => 3306,
20+
'driver' => 'pdo_mysql',
21+
'collate' => 'utf8mb4_general_ci',
22+
],
23+
];
1424
return [
1525
'application' => [
1626
'url' => $baseUrl,
1727
],
28+
'databases' => $databases,
29+
'doctrine' => [
30+
'connection' => [
31+
'orm_default' => [
32+
'params' => $databases['default'],
33+
],
34+
],
35+
],
1836
'routes' => [
1937
'page' => [
20-
'about' => 'about',
21-
'who-we-are' => 'who-we-are',
38+
'about' => 'about',
39+
'who-we-are' => 'who-we-are',
40+
'contact' => 'contact',
41+
'dotkernel-packages-oss-lifecycle' => 'dotkernel-packages-oss-lifecycle',
2242
],
2343
],
2444
];

public/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App/assets/scss/components/_general.scss

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ label {
7979
background: var(--color-bg);
8080
}
8181

82-
#push,
83-
.app-footer {
84-
height: 115px;
85-
}
86-
8782
.navbar {
8883
margin-bottom: 0;
8984
background-color: var(--color-surface);
@@ -111,7 +106,7 @@ label {
111106

112107
.app-footer {
113108
padding: 30px 50px;
114-
background: var(--color-surface);
109+
background-color: #1c1f2b;
115110
border-top: 1px solid var(--color-border);
116111
}
117112

src/App/src/Factory/GetIndexViewHandlerFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Light\App\Factory;
66

77
use Light\App\Handler\GetIndexViewHandler;
8+
use Light\Blog\Repository\PostRepository;
89
use Mezzio\Template\TemplateRendererInterface;
910
use Psr\Container\ContainerExceptionInterface;
1011
use Psr\Container\ContainerInterface;
@@ -21,9 +22,10 @@ class GetIndexViewHandlerFactory
2122
*/
2223
public function __invoke(ContainerInterface $container, string $requestedName): GetIndexViewHandler
2324
{
24-
$template = $container->get(TemplateRendererInterface::class);
25+
$postRepository = $container->get(PostRepository::class);
26+
$template = $container->get(TemplateRendererInterface::class);
2527
assert($template instanceof TemplateRendererInterface);
2628

27-
return new GetIndexViewHandler($template);
29+
return new GetIndexViewHandler($template, $postRepository);
2830
}
2931
}

src/App/src/Handler/GetIndexViewHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Light\App\Handler;
66

77
use Laminas\Diactoros\Response\HtmlResponse;
8+
use Light\Blog\Repository\PostRepository;
89
use Mezzio\Template\TemplateRendererInterface;
910
use Psr\Http\Message\ResponseInterface;
1011
use Psr\Http\Message\ServerRequestInterface;
@@ -13,14 +14,16 @@
1314
class GetIndexViewHandler implements RequestHandlerInterface
1415
{
1516
public function __construct(
16-
protected TemplateRendererInterface $template
17+
protected TemplateRendererInterface $template,
18+
protected PostRepository $postRepository,
1719
) {
1820
}
1921

2022
public function handle(ServerRequestInterface $request): ResponseInterface
2123
{
24+
$posts = $this->postRepository->getRecentPosts(3);
2225
return new HtmlResponse(
23-
$this->template->render('app::index')
26+
$this->template->render('app::index', ['posts' => $posts])
2427
);
2528
}
2629
}

src/App/templates/app/index.html.twig

Lines changed: 376 additions & 7 deletions
Large diffs are not rendered by default.

src/App/templates/layout/default.html.twig

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,46 @@
6363
</section>
6464
</div>
6565
</main>
66-
<footer class="app-footer bg-white border-top py-4 mt-auto text-muted">
67-
<div class="container d-flex flex-column flex-md-row justify-content-between align-items-center gap-2">
68-
<p class="enjoy text-uppercase tracking-wider small fw-bold text-primary mb-0">
69-
enjoy dotkernel
70-
</p>
71-
<p class="mb-0 small">
72-
&copy; 2024 - {{ 'now'|date('Y') }} Dotkernel by Apidemia
73-
</p>
66+
<footer class="app-footer border-top py-4 mt-auto text-muted">
67+
<div class="container">
68+
<div class="d-flex flex-column flex-md-row justify-content-between align-items-center gap-2 mb-3">
69+
<p class="enjoy text-uppercase tracking-wider small fw-bold text-primary mb-0">
70+
enjoy dotkernel
71+
</p>
72+
<p class="mb-0 small">
73+
&copy; 2024 - {{ 'now'|date('Y') }} Dotkernel by Apidemia
74+
</p>
75+
</div>
76+
77+
<hr class="my-3">
78+
79+
<div class="row gy-3 align-items-center">
80+
<div class="col-md-6">
81+
<p class="small mb-2">
82+
&copy; 2009 - 2016 Dotboost Technologies Inc.<br>
83+
&copy; 2017 - {{ 'now'|date('Y') }} Apidemia Inc.<br>
84+
The Laminas logo is copyright of the
85+
<a href="https://getlaminas.org/about/foundation" target="_blank" rel="noopener" class="text-primary">Laminas Foundation</a>
86+
</p>
87+
<div class="d-flex align-items-center gap-3">
88+
<a href="https://github.com/dotkernel" target="_blank" rel="noopener">
89+
<img src="https://www.dotkernel.com/wp-content/uploads/2025/01/icon_git.svg" alt="GitHub" style="height: 24px; width: auto;">
90+
</a>
91+
<a href="https://dotkernel.slack.com/" target="_blank" rel="noopener">
92+
<img src="https://www.dotkernel.com/wp-content/uploads/2025/01/icon_slack.svg" alt="Slack" style="height: 24px; width: auto;">
93+
</a>
94+
<a href="https://www.dotkernel.com/feed/" target="_blank" rel="noopener">
95+
<img src="https://www.dotkernel.com/wp-content/uploads/2025/01/icon_feed.svg" alt="RSS Feed" style="height: 24px; width: auto;">
96+
</a>
97+
</div>
98+
</div>
99+
100+
<div class="col-md-6 text-md-end">
101+
<a href="https://jb.gg/OpenSourceSupport" target="_blank" rel="noopener" class="d-inline-block">
102+
<img src="https://www.dotkernel.com/wp-content/uploads/2025/03/jetbrains-mono-white.svg" alt="JetBrains" style="width: 150px; height: auto;">
103+
</a>
104+
</div>
105+
</div>
74106
</div>
75107
</footer>
76108
<script src="{{ asset('js/app.js') }}"></script>

src/Blog/src/Handler/GetCategoryResourceHandler.php

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
use Fig\Http\Message\StatusCodeInterface;
88
use Laminas\Diactoros\Response\HtmlResponse;
9+
use Light\Blog\Entity\Category;
910
use Light\Blog\Repository\CategoryRepository;
1011
use Mezzio\Template\TemplateRendererInterface;
1112
use Psr\Http\Message\ResponseInterface;
1213
use Psr\Http\Message\ServerRequestInterface;
1314
use Psr\Http\Server\RequestHandlerInterface;
15+
use Throwable;
1416

1517
class GetCategoryResourceHandler implements RequestHandlerInterface
1618
{
@@ -23,21 +25,40 @@ public function __construct(
2325
public function handle(ServerRequestInterface $request): ResponseInterface
2426
{
2527
$categorySlug = $request->getAttribute('slug');
28+
$categories = $this->categoryRepository->getCategories();
2629
$category = $this->categoryRepository->getCategoryResource($categorySlug);
27-
$meta = $category;
28-
29-
if (! $category) {
30-
return new HtmlResponse('Category not found', StatusCodeInterface::STATUS_NOT_FOUND);
30+
if ($category === null) {
31+
return $this->notFound($categories);
3132
}
32-
$categories = $this->categoryRepository->getCategories();
33+
$meta = $category;
3334
$categoryArticles = $this->categoryRepository->getCategoryPost($category);
35+
36+
try {
37+
$html = $this->template->render(
38+
'page::category-resource',
39+
[
40+
'categories' => $categories,
41+
'category' => $category,
42+
'meta' => $meta,
43+
'categoryArticles' => $categoryArticles,
44+
]
45+
);
46+
} catch (Throwable $e) {
47+
return $this->notFound($categories);
48+
}
49+
return new HtmlResponse($html);
50+
}
51+
52+
/**
53+
* @param Category[] $categories
54+
*/
55+
private function notFound(array $categories): HtmlResponse
56+
{
3457
return new HtmlResponse(
35-
$this->template->render('page::category-resource', [
36-
'categories' => $categories,
37-
'category' => $category,
38-
'meta' => $meta,
39-
'categoryArticles' => $categoryArticles,
40-
])
58+
$this->template->render('error::404', [
59+
'categories' => $categories,
60+
]),
61+
StatusCodeInterface::STATUS_NOT_FOUND
4162
);
4263
}
4364
}

src/Blog/src/Handler/GetPostResourceHandler.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Fig\Http\Message\StatusCodeInterface;
88
use Laminas\Diactoros\Response\HtmlResponse;
9+
use Light\Blog\Entity\Category;
910
use Light\Blog\Repository\CategoryRepository;
1011
use Light\Blog\Repository\PostRepository;
1112
use Mezzio\Template\TemplateRendererInterface;
@@ -27,15 +28,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface
2728
{
2829
$slug = $request->getAttribute('slug');
2930
$categorySlug = $request->getAttribute('categorySlug');
31+
$categories = $this->categoryRepository->getCategories();
3032
$article = $this->articleRepository->getArticleResource($slug, $categorySlug);
31-
3233
if ($article === null) {
33-
return $this->notFound($categorySlug);
34+
return $this->notFound($categories);
3435
}
35-
36-
$categories = $this->categoryRepository->getCategories();
37-
$meta = $article;
38-
36+
$meta = $article;
3937
try {
4038
$html = $this->template->render(
4139
'page::blog-resource/' . $article->getCategory()->getSlug() . '/' . $slug,
@@ -46,15 +44,17 @@ public function handle(ServerRequestInterface $request): ResponseInterface
4644
]
4745
);
4846
} catch (Throwable $e) {
49-
return $this->notFound($categorySlug);
47+
return $this->notFound($categories);
5048
}
5149

5250
return new HtmlResponse($html);
5351
}
5452

55-
private function notFound(?string $categorySlug): HtmlResponse
53+
/**
54+
* @param Category[] $categories
55+
*/
56+
private function notFound(array $categories): HtmlResponse
5657
{
57-
$categories = $this->categoryRepository->getCategories();
5858
return new HtmlResponse(
5959
$this->template->render('error::404', [
6060
'categories' => $categories,

0 commit comments

Comments
 (0)