Skip to content

tolik518/blog.returnnull.de

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

blog.returnnull.de

This is the source code behind blog.returnnull.de.

Tech Stack

php PHPUnit Composer MySQL HTML SASS Docker Docker-Compose Nginx PHPStorm Git

How to Start Development

  • clone repository
  • build images with make build or with docker compose build
  • use make run or docker-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 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
  • use make stop or docker-compose down --remove-orphans to stop the containers

Access Admin Panel

How to execute PHPUnit-Tests

  • 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 press Strg + Alt + 6 -> +
    • then choose (projectfolder)/code/tests/reports/phpunit.coverage.xml and press OK and show selected

Defining new page in the app

Add a new page class

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.

Page with dependencies

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,
        );
    }
}