Skip to content
Commits on Source (12)
......@@ -7343,16 +7343,16 @@
},
{
"name": "phpstan/phpstan",
"version": "1.6.3",
"version": "1.6.7",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "6128620b98292e0b69ea6d799871d77163681c8e"
"reference": "d41c39cb2e487663bce9bbd97c660e244b73abad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/6128620b98292e0b69ea6d799871d77163681c8e",
"reference": "6128620b98292e0b69ea6d799871d77163681c8e",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/d41c39cb2e487663bce9bbd97c660e244b73abad",
"reference": "d41c39cb2e487663bce9bbd97c660e244b73abad",
"shasum": ""
},
"require": {
......@@ -7378,7 +7378,7 @@
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/1.6.3"
"source": "https://github.com/phpstan/phpstan/tree/1.6.7"
},
"funding": [
{
......@@ -7398,7 +7398,7 @@
"type": "tidelift"
}
],
"time": "2022-04-28T11:27:53+00:00"
"time": "2022-05-04T22:55:41+00:00"
},
{
"name": "phpstan/phpstan-phpunit",
......@@ -9576,16 +9576,16 @@
},
{
"name": "vimeo/psalm",
"version": "4.22.0",
"version": "4.23.0",
"source": {
"type": "git",
"url": "https://github.com/vimeo/psalm.git",
"reference": "fc2c6ab4d5fa5d644d8617089f012f3bb84b8703"
"reference": "f1fe6ff483bf325c803df9f510d09a03fd796f88"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vimeo/psalm/zipball/fc2c6ab4d5fa5d644d8617089f012f3bb84b8703",
"reference": "fc2c6ab4d5fa5d644d8617089f012f3bb84b8703",
"url": "https://api.github.com/repos/vimeo/psalm/zipball/f1fe6ff483bf325c803df9f510d09a03fd796f88",
"reference": "f1fe6ff483bf325c803df9f510d09a03fd796f88",
"shasum": ""
},
"require": {
......@@ -9610,6 +9610,7 @@
"php": "^7.1|^8",
"sebastian/diff": "^3.0 || ^4.0",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0 || ^6.0",
"symfony/polyfill-php80": "^1.25",
"webmozart/path-util": "^2.3"
},
"provide": {
......@@ -9676,9 +9677,9 @@
],
"support": {
"issues": "https://github.com/vimeo/psalm/issues",
"source": "https://github.com/vimeo/psalm/tree/4.22.0"
"source": "https://github.com/vimeo/psalm/tree/4.23.0"
},
"time": "2022-02-24T20:34:05+00:00"
"time": "2022-04-28T17:35:49+00:00"
},
{
"name": "webmozart/path-util",
......
......@@ -9,6 +9,8 @@ dbp_relay_core:
build_info: ~ # Example: deadbeef
# Some URL identifying the current build (URL to the commit on some git web interface)
build_info_url: ~ # Example: 'https://gitlab.example.com/project/-/commit/deadbeef'
# Path to the logo (256x256) of the API frontend
logo_path: ~ # Example: 'bundles/dbprelaycore/logo.png'
# The title text of the API docs page
docs_title: 'Relay API Gateway'
# The description text of the API docs page (supports markdown)
......
......@@ -10,9 +10,11 @@ use Symfony\Component\DependencyInjection\Reference;
class CronCompilerPass implements CompilerPassInterface
{
private const TAG = 'dbp.relay.core.cron_job';
public static function register(ContainerBuilder $container): void
{
$container->registerForAutoconfiguration(CronJobInterface::class)->addTag('dbp.relay.cron_job');
$container->registerForAutoconfiguration(CronJobInterface::class)->addTag(self::TAG);
$container->addCompilerPass(new CronCompilerPass());
}
......@@ -22,7 +24,7 @@ class CronCompilerPass implements CompilerPassInterface
return;
}
$definition = $container->findDefinition(CronCommand::class);
$taggedServices = $container->findTaggedServiceIds('dbp.relay.cron_job');
$taggedServices = $container->findTaggedServiceIds(self::TAG);
foreach ($taggedServices as $id => $tags) {
$definition->addMethodCall('addJob', [new Reference($id)]);
}
......
......@@ -22,6 +22,10 @@ class Configuration implements ConfigurationInterface
->info('Some URL identifying the current build (URL to the commit on some git web interface)')
->example('https://gitlab.example.com/project/-/commit/deadbeef')
->end()
->scalarNode('logo_path')
->info('Path to the logo (256x256) of the API frontend')
->example('bundles/dbprelaycore/logo.png')
->end()
->scalarNode('docs_title')
->info('The title text of the API docs page')
->defaultValue('Relay API Gateway')
......
......@@ -137,6 +137,7 @@ class DbpRelayCoreExtension extends ConfigurableExtension implements PrependExte
// Apache returns with a 304 without cors headers, the browser serves the cached request with
// wrong 'access-control-allow-origin' and the fetch will fail with a CORS error.
// By always sending '*' the cached response still happens to be valid in that case.
// edit: this is fixed in Apache since 2.4.48, so we can drop this line once we require that version
'forced_allow_origin_value' => '*',
],
],
......@@ -161,6 +162,7 @@ class DbpRelayCoreExtension extends ConfigurableExtension implements PrependExte
'globals' => array_merge($twigGlobals, [
'app_buildinfo' => $config['build_info'] ?? '',
'app_buildinfo_url' => $config['build_info_url'] ?? '',
'logo_path' => $config['logo_path'] ?? 'bundles/dbprelaycore/logo.png',
'app_env' => '%kernel.environment%',
'app_debug' => '%kernel.debug%',
]),
......
......@@ -37,9 +37,9 @@ trait ExtensionTrait
}
/**
* Registers a specific message to be routed via the global async queue.
* Registers a specific message type to be routed via the global async queue.
*/
public function addQueueMessage(ContainerBuilder $container, string $messageClass)
public function addQueueMessageClass(ContainerBuilder $container, string $messageClass): void
{
$this->ensureInPrepend($container);
$this->extendArrayParameter($container, 'dbp_api.messenger_routing', [
......@@ -48,7 +48,9 @@ trait ExtensionTrait
}
/**
* Registers a specific message to be routed via the global async queue.
* Adds a header to Access-Control-Expose-Headers, so that scripts in browsers can access them.
*
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
*/
public function addExposeHeader(ContainerBuilder $container, string $headerName)
{
......@@ -59,7 +61,9 @@ trait ExtensionTrait
}
/**
* Registers a specific message to be routed via the global async queue.
* Adds a header to Access-Control-Allow-Headers, so that scripts in browsers can send those headers.
*
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
*/
public function addAllowHeader(ContainerBuilder $container, string $headerName)
{
......@@ -87,4 +91,12 @@ trait ExtensionTrait
assert(is_array($oldValues));
$container->setParameter($parameter, array_merge($oldValues, $values));
}
/**
* @deprecated use addQueueMessageClass instead
*/
public function addQueueMessage(ContainerBuilder $container, string $messageClass): void
{
$this->addQueueMessageClass($container, $messageClass);
}
}
......@@ -10,9 +10,11 @@ use Symfony\Component\DependencyInjection\Reference;
class HealthCheckCompilerPass implements CompilerPassInterface
{
private const TAG = 'dbp.relay.core.health_check';
public static function register(ContainerBuilder $container): void
{
$container->registerForAutoconfiguration(CheckInterface::class)->addTag('dbp.relay.health_check');
$container->registerForAutoconfiguration(CheckInterface::class)->addTag(self::TAG);
$container->addCompilerPass(new HealthCheckCompilerPass());
}
......@@ -22,7 +24,7 @@ class HealthCheckCompilerPass implements CompilerPassInterface
return;
}
$definition = $container->findDefinition(HealthCheckCommand::class);
$taggedServices = $container->findTaggedServiceIds('dbp.relay.health_check');
$taggedServices = $container->findTaggedServiceIds(self::TAG);
foreach ($taggedServices as $id => $tags) {
$definition->addMethodCall('addCheck', [new Reference($id)]);
}
......
<?php
declare(strict_types=1);
namespace Dbp\Relay\CoreBundle\Pagination;
use ApiPlatform\Core\DataProvider\PaginatorInterface;
class FullPaginator extends Paginator implements PaginatorInterface
{
/** @var int */
private $totalNumItems;
public function __construct(array $items, int $page, int $numItemsPerPage, int $totalNumItems)
{
parent::__construct($items, $page, $numItemsPerPage);
$this->totalNumItems = $totalNumItems;
}
/**
* Gets last page.
*/
public function getLastPage(): float
{
return ceil($this->getTotalItems() / $this->getItemsPerPage());
}
/**
* Gets the number of items in the whole collection.
*/
public function getTotalItems(): float
{
return $this->totalNumItems;
}
}
<?php
declare(strict_types=1);
namespace Dbp\Relay\CoreBundle\Pagination;
use ApiPlatform\Core\DataProvider\Pagination as ApiPlatformPagination;
class Pagination
{
private const PAGE_PARAMETER_NAME = 'page';
private const NUM_ITEMS_PER_PAGE_PARAMETER_NAME = 'perPage';
private const IS_PARTIAL_PAGINATION_PARAMETER_NAME = 'partialPagination';
private const IS_PARTIAL_PAGINATION_DEFAULT = false;
/** @var ApiPlatformPagination */
private $pagination;
public function __construct(ApiPlatformPagination $pagination)
{
$this->pagination = $pagination;
}
public function addPaginationOptions(array &$options, string $resourceClass, string $operationName, array $context)
{
$options[self::PAGE_PARAMETER_NAME] = $this->pagination->getPage($context);
$options[self::NUM_ITEMS_PER_PAGE_PARAMETER_NAME] = $this->pagination->getLimit($resourceClass, $operationName, $context);
$options[self::IS_PARTIAL_PAGINATION_PARAMETER_NAME] = $this->pagination->isPartialEnabled($resourceClass, $operationName, $context);
}
public static function isPartialPagination(array $options)
{
return $options[self::IS_PARTIAL_PAGINATION_PARAMETER_NAME] ?? self::IS_PARTIAL_PAGINATION_DEFAULT;
}
}
<?php
declare(strict_types=1);
/**
* This is a paginator for collection data providers to work with items from an array,
* that only contains a part of the result set.
*/
namespace Dbp\Relay\CoreBundle\Pagination;
use ApiPlatform\Core\DataProvider\PartialPaginatorInterface;
use Iterator;
abstract class Paginator implements Iterator, PartialPaginatorInterface
{
protected $position;
protected $items;
protected $numItemsPerPage;
protected $page;
protected function __construct(array $items, int $page, int $numItemsPerPage)
{
$this->position = 0;
$this->items = $items;
$this->page = $page;
$this->numItemsPerPage = $numItemsPerPage;
}
/**
* @return mixed
*/
public function current()
{
return $this->items[$this->position];
}
public function next(): void
{
++$this->position;
}
/**
* @return float|int|null
*/
public function key()
{
return $this->position;
}
public function valid(): bool
{
return isset($this->items[$this->position]);
}
public function rewind(): void
{
$this->position = 0;
}
public function getCurrentPage(): float
{
return $this->page;
}
public function getItemsPerPage(): float
{
return $this->numItemsPerPage;
}
public function count(): int
{
return count($this->items);
}
public function getItems(): array
{
return $this->items;
}
}
<?php
declare(strict_types=1);
namespace Dbp\Relay\CoreBundle\Pagination;
class PartialPaginator extends Paginator
{
public function __construct(array $items, int $page, int $numItemsPerPage)
{
parent::__construct($items, $page, $numItemsPerPage);
}
}
......@@ -12,7 +12,7 @@
<style>
#swagger-ui.api-platform .info .title {
background-image: url({{ asset('bundles/dbprelaycore/logo.png', assetPackage) }});
background-image: url({{ asset(logo_path, assetPackage) }});
background-repeat: no-repeat;
background-size: auto 100%;
padding-left: 60px
......
......@@ -72,3 +72,7 @@ services:
autoconfigure: true
arguments:
$env: ~
Dbp\Relay\CoreBundle\Pagination\Pagination:
autowire: true
autoconfigure: true
\ No newline at end of file
......@@ -16,7 +16,7 @@ class ExtensionTraitTest extends TestCase
{
$builder = new ContainerBuilder();
$params = $builder->getParameterBag();
$this->addQueueMessage($builder, 'foobar');
$this->addQueueMessageClass($builder, 'foobar');
$this->assertTrue($params->has('dbp_api.messenger_routing'));
$this->addResourceClassDirectory($builder, '.');
$this->assertTrue($params->has('api_platform.resource_class_directories'));
......@@ -35,6 +35,6 @@ class ExtensionTraitTest extends TestCase
$builder = new ContainerBuilder();
$builder->setParameter('dbp_api._prepend_done', true);
$this->expectException(\RuntimeException::class);
$this->addQueueMessage($builder, 'foobar');
$this->addQueueMessageClass($builder, 'foobar');
}
}