~thirdplace/components

24f773960d0c239fc1d25f55dd2a9a29dc58378e — Dag 11 months ago 6a3766c
docs
M README.md => README.md +2 -2
@@ 7,9 7,9 @@ Mostly used in web applications.

Install:

    composer require thirdplace/components
    composer require thirdplace/components:dev-main

Run unit tests:
Run tests:

    ./vendor/bin/tunit


M composer.json => composer.json +0 -3
@@ 46,9 46,6 @@
        "ext-libxml": "*",
        "ext-simplexml": "*"
    },
    "require-dev": {
        "thirdplace/tunit": "dev-main"
    },
    "scripts": {
        "test": "./bin/tunit"
    }

M src/Application.php => src/Application.php +2 -1
@@ 18,7 18,7 @@ final class Application

        ErrorHandler::register($container['error_logger']);

        $this->addRoute('GET', '/',    fn() => response("Hello World!\n"));
        $this->addRoute('GET', '/',    fn() => response("Hello World!\n", 200));
        $this->addRoute('GET', '/404', fn() => response("404 Page Not Found\n", 404));
        $this->addRoute('GET', '/405', fn() => response("405 Method Not Allowed\n", 405));
    }


@@ 62,6 62,7 @@ final class Application
            $handler[0] = $this->container[$handler[0]];
        }

        // the following code is a bit too complex? don't like it but middleware processing is nice
        $middlewares = [
            ...$this->middlewares,
            ...array_pop($handler),

M src/Container.php => src/Container.php +3 -3
@@ 11,7 11,7 @@ final class Container implements \ArrayAccess
    public function offsetSet($offset, $value)
    {
        if (isset($this->values[$offset])) {
            throw new \Exception(sprintf('Key already exists "%s"', $offset));
            throw new \Exception(sprintf('Container key already exists "%s"', $offset));
        }

        if (! $value instanceof \Closure) {


@@ 24,7 24,7 @@ final class Container implements \ArrayAccess
    public function offsetGet($offset)
    {
        if (!isset($this->values[$offset])) {
            throw new \Exception(sprintf('Unknown key: "%s"', $offset));
            throw new \Exception(sprintf('Unknown container key: "%s"', $offset));
        }

        if (isset($this->resolved[$offset])) {


@@ 41,6 41,6 @@ final class Container implements \ArrayAccess

    public function offsetUnset($offset)
    {
        throw new \Exception('unset() not implemented');
        throw new \Exception('Container::unset() not implemented');
    }
}

M src/Session.php => src/Session.php +3 -0
@@ 3,6 3,9 @@ declare(strict_types=1);

namespace Thirdplace;

/**
 * Manipulates php's built-in $_SESSION
 */
final class Session
{
    private array $options;

M src/Url.php => src/Url.php +1 -0
@@ 190,6 190,7 @@ final class Url implements \JsonSerializable
            $this->host,
            $this->port === 80 ? '' : ":{$this->port}",
            $path,
            // todo: don't urlencode. it's not tje job of this class
            $this->query ? '?' . http_build_query($this->query) : '',
            $this->fragment ? "#$this->fragment" : ''
        );

M src/common.php => src/common.php +2 -1
@@ 7,11 7,12 @@ final class HttpException extends \Exception {}

function retry(int $times, \Closure $fn, int $sleep = 0)
{
    // todo
    // todo: retry helper
}

function create_sane_stacktrace(\Throwable $e)
{
    // todo: maybe accept trace instead of ex?
    $stackTrace[] = sprintf('%s:%s', $e->getFile(), $e->getLine());
    foreach ($e->getTrace() as $trace) {
        $stackTrace[] = sprintf(

M src/http/Request.php => src/http/Request.php +1 -0
@@ 97,6 97,7 @@ final class Request
        if (is_array($value) && $allowArray) {
            return $value;
        }
        // i think exception here?
        return $default;
    }


M src/logger/ErrorHandler.php => src/logger/ErrorHandler.php +1 -0
@@ 10,6 10,7 @@ final class ErrorHandler
    public static function register(Logger $logger): void
    {
        set_error_handler(function ($code, $message, $file, $line) {
            // todo: respect error_reporting();
            throw new \ErrorException($message, 0, $code, $file, $line);
        });


M src/logger/StreamHandler.php => src/logger/StreamHandler.php +1 -0
@@ 39,6 39,7 @@ final class StreamHandler
        }

        if (!fwrite($this->stream, $text)) {
            // Maybe drop this last effort to write to error log
            error_log('Unable to write log record');
        }
    }