Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
No results found
Select Git revision
Show changes
Commits on Source (34)
This diff is collapsed.
......@@ -16,7 +16,7 @@ For example in crontab, every 5 minutes:
This cron job will regularly prune caches and dispatch a cron event which can be
handled by different bundles.
To get access to such an even you have to implement an event listener:
To get access to such an event you have to implement an event listener:
```yaml
Dbp\Relay\MyBundle\Cron\CleanupJob:
......
<?php
declare(strict_types=1);
namespace Dbp\Relay\CoreBundle\HealthCheck\Checks;
use Dbp\Relay\CoreBundle\HealthCheck\CheckInterface;
use Dbp\Relay\CoreBundle\HealthCheck\CheckOptions;
use Dbp\Relay\CoreBundle\HealthCheck\CheckResult;
use Symfony\Component\Lock\LockFactory;
class LockCheck implements CheckInterface
{
private $lockFactory;
public function __construct(LockFactory $lockFactory)
{
$this->lockFactory = $lockFactory;
}
public function getName(): string
{
return 'core.lock';
}
public function check(CheckOptions $options): array
{
$result = new CheckResult('Check if the locking works');
$result->set(CheckResult::STATUS_SUCCESS);
try {
$lock = $this->lockFactory->createLock('health-check');
$lock->acquire();
$lock->refresh();
$lock->release();
} catch (\Throwable $e) {
$result->set(CheckResult::STATUS_FAILURE, $e->getMessage(), ['exception' => $e]);
}
return [$result];
}
}
......@@ -10,5 +10,4 @@ namespace Dbp\Relay\CoreBundle\Helpers;
class ArrayFullPaginator extends ArrayPaginator
{
public const DEBUG = false;
}
......@@ -62,34 +62,42 @@ abstract class ArrayPaginator implements Iterator, PaginatorInterface
return $this->perPage;
}
public function count()
public function count(): int
{
$value = count($this->array);
return $value;
}
public function rewind()
public function rewind(): void
{
$this->position = ($this->page - 1) * $this->perPage;
}
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->array[$this->position];
}
/**
* @return bool|float|int|mixed|string|null
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->position;
}
public function next()
public function next(): void
{
++$this->position;
}
public function valid()
public function valid(): bool
{
$value = isset($this->array[$this->position]) &&
($this->position >= (($this->page - 1) * $this->perPage)) &&
......
......@@ -34,12 +34,12 @@ class ArrayPartPaginator extends ArrayPaginator
return $this->page;
}
public function rewind()
public function rewind(): void
{
$this->position = 0;
}
public function valid()
public function valid(): bool
{
$value = isset($this->array[$this->position]);
......
<?php
declare(strict_types=1);
namespace Dbp\Relay\CoreBundle\Tests\Helpers;
use Dbp\Relay\CoreBundle\Helpers\ArrayFullPaginator;
use Dbp\Relay\CoreBundle\Helpers\ArrayPartPaginator;
use Dbp\Relay\CoreBundle\Helpers\GuzzleTools;
use Dbp\Relay\CoreBundle\Helpers\MimeTools;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
class HelpersTest extends TestCase
{
public function testArrayFullPaginator()
{
$paginator = new ArrayFullPaginator([4, 5, 6], 1, 2);
$this->assertSame($paginator->getCurrentPage(), 1.0);
$this->assertSame($paginator->getItemsPerPage(), 2.0);
$this->assertSame($paginator->getTotalItems(), 3.0);
$this->assertSame($paginator->current(), 4);
$this->assertSame($paginator->key(), 0);
$this->assertTrue($paginator->valid());
$paginator->next();
$this->assertSame($paginator->current(), 5);
$this->assertSame($paginator->getLastPage(), 2.0);
}
public function testArrayPartPaginator()
{
$paginator = new ArrayPartPaginator([4, 5, 6], 3, 1, 2);
$this->assertSame($paginator->getCurrentPage(), 1.0);
$this->assertSame($paginator->getItemsPerPage(), 2.0);
$this->assertSame($paginator->getTotalItems(), 3.0);
$this->assertSame($paginator->current(), 4);
$this->assertSame($paginator->key(), 0);
$this->assertTrue($paginator->valid());
$paginator->next();
$this->assertSame($paginator->current(), 5);
$this->assertSame($paginator->getLastPage(), 2.0);
}
public function testGuzzleTools()
{
$middleware = GuzzleTools::createLoggerMiddleware(new NullLogger());
$this->assertNotNull($middleware);
}
public function testMimeTools()
{
$this->assertSame(MimeTools::getDataURI('foobar', 'text/html'), 'data:text/html;base64,Zm9vYmFy');
$this->assertSame(
MimeTools::getMimeType(base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVQI12Mo3CQPAALaAUMu4mcOAAAAAElFTkSuQmCC', true)),
'image/png');
$this->assertSame(MimeTools::getFileExtensionForMimeType('image/png'), 'png');
}
}