This is the source code behind blog.returnnull.de.
- clone repository
- build images with
make build
or withdocker compose build
- use
make run
ordocker-compose up -d
to start the containers- to install the dependencies and to update the autoloader (do this everyime you add a new class)
make install
ordocker-compose -f docker/compose/docker-compose-cli.yml run --rm --no-deps php_cli php -d memory_limit=-1 /usr/local/bin/composer install
- to install the dependencies and to update the autoloader (do this everyime you add a new class)
- use
make stop
ordocker-compose down --remove-orphans
to stop the containers
- go to http://localhost/admin
- login with username
tolik518
and passwordtolik518
make unit_test
- if you want to see the coverage in PHPStorm then follow these steps:
- Go to the menu bar in PHPStorm at the top
- Go to
Run
->Show Coverage Data
or pressStrg + Alt + 6
->+
- then choose
(projectfolder)/code/tests/reports/phpunit.coverage.xml
and pressOK
andshow selected
Inside src/Page define a new class that implements Page interface, here minimal example:
<?php
// src/Page/HelloPage.php
namespace Returnnull;
class HelloPage implements Page
{
public function run(Request $request): Response
{
return new Response('Hello World!');
}
// define the regexes that should be supported by this page
public function getSupportedUrlRegexes(): array
{
return [
'/^\/hello$/',
];
}
// optional, define if this page should be protected by the login system, by default it is not protected
public function isProtected(): bool
{
return false;
}
}
Remeber to always run make install
or docker-compose -f docker/compose/docker-compose-cli.yml run --rm --no-deps php_cli php -d memory_limit=-1 /usr/local/bin/composer install
to update the autoloader.
If your page have dependencies, than you have to define creator function in the PageFactory
class. Here is an example:
First we create page with dependencies:
<?php
// src/Page/HelloPageWithDeps.php
namespace Returnnull;
class HelloPageWithDeps implements Page
{
public function __construct(
private SessionManager $sessionManager,
) {
}
...
}
then in PageFactory add support for the page:
<?php
// src/Factories/PageFactory.php
namespace Returnnull;
class PageFactory
{
...
public function create(string $pageClassName): Page
{
$pageName = $this->getPageNameFromClass($pageClassName);
switch ($pageName) {
case 'HelloPageWithDeps':
return $this->createHelloPageWithDeps();
default:
return $this->tryToGetFallbackPage($pageName);
}
}
...
private function createHelloPageWithDeps(): HelloPageWithDeps
{
return new HelloPageWithDeps(
$this->sessionManager,
);
}
}