Skip to content

Commit

Permalink
Move everything to src/ and use lowercase dir names
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-schindler committed May 11, 2023
1 parent 62080f8 commit 4b5ebd8
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 21 deletions.
5 changes: 2 additions & 3 deletions .phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
parameters:
level: 8
excludePaths:
- Backend/Libraries/vendor/*
- vendor/*
paths:
- index.php
- Backend
- src
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"editor.useTabStops": true,
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"phpstan.binPath": "Backend/Libraries/vendor/bin/phpstan",
"phpstan.binPath": "vendor/bin/phpstan",
"phpstan.configFile": ".phpstan.neon",
"phpstan.enabled": true,
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SecondHome extends Controller
class ArticleController extends Controller
{
protected array $paths = ['/article/:id'];

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions Backend/Core/ClassLoader.php → src/core/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ClassLoader
*/
public static function 파람(): void
{
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Backend'), RecursiveIteratorIterator::SELF_FIRST);
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'src'), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file)
if (pathinfo($file->getFileName(), PATHINFO_EXTENSION) == 'php' && !str_contains($file->getPathname(), 'vendor'))
self::$classes[strval(str_replace('.php', '', $file->getFileName()))] = $file->getPathname();
Expand All @@ -37,7 +37,7 @@ public static function 파람(): void
private static function initControllers(): void
{
foreach (self::$classes as $name => $path) {
if (str_contains(str_replace('\\', '/', $path), '/Controllers/')) { // Replace \ with / for windows users
if (str_contains(str_replace('\\', '/', $path), '/controllers/')) { // Replace \ with / for windows users
$controller = new $name();
if ($controller instanceof Controller)
$controller->initRoutes();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract protected function execute(): View;
*/
protected function param(string $var): ?string
{
if (isset($this->params[$var]) && is_string($this->params[$var]))
if (isset($this->params[$var]))
return htmlspecialchars(urldecode(strval($this->params[$var])));
return null;
}
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 24 additions & 1 deletion Backend/Core/System/View.php → src/core/system/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ public function addChild(View $child): View
return $this;
}

/**
* Add multiple children
*
* @param View ...$children Children
* @return View Current view
*/
public function addChildren(View ...$children): View
{
$this->children = array_merge($this->children, $children);
return $this;
}

/**
* Get all children
*
* @return array<View> Children
* @see View::$children
*/
public function getChildren(): array
{
return $this->children;
}

/**
* Render children
*/
Expand All @@ -41,7 +64,7 @@ public function renderChildren(?string $element = null): void
}

/**
* Get rendered HTML as string
* Get rendered (HTML) View as string
*/
public function __toString(): string
{
Expand Down
4 changes: 2 additions & 2 deletions index.php → src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
const TITLE = 'sample'; // Title of project

// Require autoloaders
require_once('./Backend/Core/ClassLoader.php'); // Load classes
require_once('./vendor/autoload.php'); // Composer autoloader
require_once('./core/ClassLoader.php'); // Load classes
require_once('../vendor/autoload.php'); // Composer autoloader

// Application start
// session_start(); // Start PHP Session
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public function render(): void
(new APIView([$this->code => $this->message]))->render(); // Render error as JSON
} else {
(new LayoutView())
->addChild(new HeadingView("{$this->code} &middot; {$this->message}"))
->addChild(new HeadingView("{$this->code} - {$this->message}"))
->addChildren(...$this->getChildren())
->render(); // Render error as HTML
$this->renderChildren();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,18 @@ public function render(): void
<body>
<header>
<a href="/">Home</a>
<a href="/article/2">Other one</a>
<a href="/article/321">Should not be called</a>
<a href="/article/2">Article</a>
<a href="/article/321">Still article</a>
<a href="/api/sample">API</a>
<a href="/err">Error</a>
<a href="/err">404</a>
</header>

<main>
<?php foreach ($_SERVER as $key => $value) : ?>
<p><?= $key ?>: <?= $value ?></p>
<?php endforeach; ?>

<?php $this->renderChildren(); ?>
</main>

<footer>
<p>This page was generated in <?= (microtime(true) - $GLOBALS['start']) * 1000 ?> ms</p>
<p>generated in <?= number_format((microtime(true) - $GLOBALS['start']) * 1000, 2) ?> ms</p>
</footer>
</body>

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 4b5ebd8

Please sign in to comment.