orbito/render-client

HTTP Client for Orbito Render

0.0.2 2022-08-06 00:45 UTC

This package is auto-updated.

Last update: 2024-11-06 05:38:25 UTC


README

Latest Stable Version Latest Unstable Version codecov Total Downloads Github actions Build PHP Version Require

HTTP client to use with Orbito Render.

composer require orbito/render-client
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Log\LoggerInterface;
use Orbito\RenderClient\RenderClient;
use Orbito\RenderClient\TemplateRef;
use Orbito\RenderClient\TemplateOptimize;

$render_client = new RenderClient(
    [
        'default' => 'http://localhost:4250',
    ],
    ClientInterface         $http_client,
    RequestFactoryInterface $request_factory,
    StreamFactoryInterface  $stream_factory,
    LoggerInterface         $logger,
);
$content = $this->renderer->render(
    'default', 'en', 'main',
    new TemplateRef('my-tpl', 'pages/default'),
    TemplateOptimize::makeFor('html'),
    [],// data
    [],// styleVars
    ['renderText' => true],// optional, options
    null|string,// optional, trace for logging
);
if(!$content) {
    return;
}
error_log('Rendered in ' . $content->renderTime . 'ms');
$html = $content->rendered;

$style = $this->renderer->style(
    'default', 'main', 'my-tpl',
    ['nanoCss' => true, 'cssAutoPrefix' => false],
    [],// styleVars
);
if(!$style) {
    return;
}
error_log('Generated style in ' . $style->styleTime . 'ms');
$css = $style->style;

Dev Notices

Commands to set up and run e.g. tests:

# on windows:
docker run -it --rm -v %cd%:/app composer install

docker run -it --rm -v %cd%:/var/www/html php:8-cli-alpine sh

docker run --rm -v %cd%:/var/www/html php:8-cli-alpine sh -c "cd /var/www/html && ./vendor/bin/phpunit --testdox -c phpunit-ci.xml --bootstrap vendor/autoload.php"

# on unix:
docker run -it --rm -v `pwd`:/app composer install

docker run -it --rm -v `pwd`:/var/www/html php:8-cli-alpine sh

docker run --rm -v `pwd`:/var/www/html php:8-cli-alpine sh -c "cd /var/www/html && ./vendor/bin/phpunit --testdox -c phpunit-ci.xml --bootstrap vendor/autoload.php"

Versions

This project adheres to semver, until 1.0.0 and beginning with 0.1.0: all 0.x.0 releases are like MAJOR releases and all 0.0.x like MINOR or PATCH, modules below 0.1.0 should be considered experimental.

License

This project is free software distributed under the MIT LICENSE.

MIT License

© 2022 bemit

Contributors

By committing your code to the code repository you agree to release the code under the MIT License attached to the repository.