mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2024-12-04 23:17:19 +01:00
Implemented draft for parameters
This commit is contained in:
parent
cfc471b751
commit
fa7d6b0e31
@ -8,9 +8,11 @@ use Infinito\Exception\UnvalidParameterException;
|
||||
use Infinito\Exception\NotDefinedException;
|
||||
|
||||
/**
|
||||
* @todo Rename class!
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class OptionalGetParameterService implements OptionalGetParameterServiceInterface
|
||||
class OptionalGetParameterService implements OptionalGetParameterServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var Request
|
||||
|
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement\Parameter;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
abstract class AbstractParameter implements ParameterInterface
|
||||
{
|
||||
/**
|
||||
* Use Annotations in child classes for validation.
|
||||
*
|
||||
* @see https://symfony.com/doc/current/validation.html
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\ParameterManagement\Parameter\ParameterInterface::getValue()
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Infinito\Domain\ParameterManagement\Parameter\ParameterInterface::setValue()
|
||||
*/
|
||||
public function setValue($value): void
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the parameter key
|
||||
*/
|
||||
public static function getKey(): string
|
||||
{
|
||||
$className = get_called_class();
|
||||
$exploded = explode('\\', $className);
|
||||
$shortname = $exploded[count($exploded) - 1];
|
||||
$key = str_replace('Parameter', '', $shortname);
|
||||
$lower = strtolower($key);
|
||||
|
||||
return $lower;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement\Parameter;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class FrameParameter extends AbstractParameter
|
||||
{
|
||||
/**
|
||||
* @var int|null
|
||||
* @Assert\GreaterThan(0)
|
||||
*/
|
||||
protected $value;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement\Parameter;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface ParameterInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setValue($value): void;
|
||||
|
||||
/**
|
||||
* @return mixed The value
|
||||
*/
|
||||
public function getValue();
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement\Parameter;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class VersionParameter extends AbstractParameter
|
||||
{
|
||||
/**
|
||||
* @var int|null
|
||||
* @Assert\GreaterThan(0)
|
||||
*/
|
||||
protected $value;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface ValidGetParameterServiceInterface extends OptionalGetParameterServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param string $key
|
||||
*
|
||||
* @return bool checks if the parameter is valid
|
||||
*/
|
||||
public function isValid(string $key): bool;
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\ParameterManagement;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class ValidGetParametersService extends OptionalGetParameterService implements ValidGetParameterServiceInterface
|
||||
{
|
||||
public function isValid(string $key): bool
|
||||
{
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ use Infinito\Domain\RequestManagement\Action\RequestedActionInterface;
|
||||
use Infinito\Domain\ActionManagement\ActionServiceInterface;
|
||||
use Infinito\Domain\ActionManagement\ActionFactoryServiceInterface;
|
||||
use Infinito\Domain\TemplateManagement\TemplateNameServiceInterface;
|
||||
use Infinito\Domain\ParameterManagement\OptionalGetParameterServiceInterface;
|
||||
use Infinito\Domain\ParameterManagement\ValidGetParameterServiceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -45,7 +45,7 @@ final class ViewBuilder implements ViewBuilderInterface
|
||||
private $templateNameService;
|
||||
|
||||
/**
|
||||
* @var OptionalGetParameterServiceInterface
|
||||
* @var ValidGetParameterServiceInterface
|
||||
*/
|
||||
private $optionalGetParameterService;
|
||||
|
||||
@ -56,8 +56,8 @@ final class ViewBuilder implements ViewBuilderInterface
|
||||
*/
|
||||
private function checkLoadWithFrame(): bool
|
||||
{
|
||||
if ($this->optionalGetParameterService->hasParameter(OptionalGetParameterServiceInterface::FRAME_PARAMETER)) {
|
||||
return $this->optionalGetParameterService->getParameter(OptionalGetParameterServiceInterface::FRAME_PARAMETER);
|
||||
if ($this->optionalGetParameterService->hasParameter(ValidGetParameterServiceInterface::FRAME_PARAMETER)) {
|
||||
return $this->optionalGetParameterService->getParameter(ValidGetParameterServiceInterface::FRAME_PARAMETER);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -91,7 +91,7 @@ final class ViewBuilder implements ViewBuilderInterface
|
||||
* @param ActionServiceInterface $actionService
|
||||
* @param ActionFactoryServiceInterface $actionFactoryService
|
||||
*/
|
||||
public function __construct(ActionServiceInterface $actionService, ActionFactoryServiceInterface $actionFactoryService, TemplateNameServiceInterface $templateNameService, OptionalGetParameterServiceInterface $optionalGetParameterService)
|
||||
public function __construct(ActionServiceInterface $actionService, ActionFactoryServiceInterface $actionFactoryService, TemplateNameServiceInterface $templateNameService, ValidGetParameterServiceInterface $optionalGetParameterService)
|
||||
{
|
||||
$this->view = View::create();
|
||||
$this->actionService = $actionService;
|
||||
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Integration\Domain\ParameterManagement\Parameter;
|
||||
|
||||
class VersionParameterIntegrationTest
|
||||
{
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace tests\Unit\Domain\ParameterManagement\Parameter;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Infinito\Domain\ParameterManagement\Parameter\VersionParameter;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class VersionParameterTest extends TestCase
|
||||
{
|
||||
public function testKey(): void
|
||||
{
|
||||
$key = VersionParameter::getKey();
|
||||
$this->assertEquals('version', $key);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user