mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-04-16 10:16:22 +02:00
Formated code
This commit is contained in:
parent
a931d7aebc
commit
6fb99c2f1a
@ -1,75 +1,77 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Infinito\Domain\ParameterManagement;
|
namespace Infinito\Domain\ParameterManagement;
|
||||||
|
|
||||||
use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface;
|
use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface;
|
||||||
use HaydenPierce\ClassFinder\ClassFinder;
|
use HaydenPierce\ClassFinder\ClassFinder;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use PhpCollection\CollectionInterface;
|
use PhpCollection\CollectionInterface;
|
||||||
use Doctrine\Migrations\Configuration\Exception\ParameterIncompatibleWithFinder;
|
|
||||||
use PhpParser\ErrorHandler\Collecting;
|
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Infinito\Domain\ParameterManagement\Parameter\AbstractParameter;
|
use Infinito\Domain\ParameterManagement\Parameter\AbstractParameter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
final class ParameterFactory implements ParameterFactoryInterface
|
final class ParameterFactory implements ParameterFactoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var string Namespace under which the parameters are stored
|
* @var string Namespace under which the parameters are stored
|
||||||
*/
|
*/
|
||||||
const PARAMETER_NAMESPACE = 'Infinito\Domain\ParameterManagement\Parameter';
|
const PARAMETER_NAMESPACE = 'Infinito\Domain\ParameterManagement\Parameter';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ArrayCollection|CollectionInterface|ParameterInterface[]
|
* @var ArrayCollection|CollectionInterface|ParameterInterface[]
|
||||||
*/
|
*/
|
||||||
private $parameters;
|
private $parameters;
|
||||||
|
|
||||||
private function initPossible(string $class){
|
private function initPossible(string $class)
|
||||||
if($class === AbstractParameter::class){
|
{
|
||||||
return false;
|
if (AbstractParameter::class === $class) {
|
||||||
}
|
|
||||||
$reflectionClass = new \ReflectionClass($class);
|
|
||||||
if($reflectionClass->isInterface()){
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$reflectionClass = new \ReflectionClass($class);
|
||||||
|
if ($reflectionClass->isInterface()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private function initParameters():void{
|
|
||||||
|
private function initParameters(): void
|
||||||
|
{
|
||||||
$this->parameters = new ArrayCollection();
|
$this->parameters = new ArrayCollection();
|
||||||
$classFinder = new ClassFinder();
|
$classFinder = new ClassFinder();
|
||||||
$parameterClasses = $classFinder->getClassesInNamespace(self::PARAMETER_NAMESPACE);
|
$parameterClasses = $classFinder->getClassesInNamespace(self::PARAMETER_NAMESPACE);
|
||||||
foreach ($parameterClasses as $parameterClass){
|
foreach ($parameterClasses as $parameterClass) {
|
||||||
if($this->initPossible($parameterClass)){
|
if ($this->initPossible($parameterClass)) {
|
||||||
$parameter = new $parameterClass();
|
$parameter = new $parameterClass();
|
||||||
$this->parameters->set($parameter::getKey(),$parameter);
|
$this->parameters->set($parameter::getKey(), $parameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(){
|
public function __construct()
|
||||||
$this->initParameters();
|
{
|
||||||
|
$this->initParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* {@inheritdoc}
|
||||||
* {@inheritDoc}
|
*
|
||||||
* @see \Infinito\Domain\ParameterManagement\ParameterFactoryInterface::getParameter()
|
* @see \Infinito\Domain\ParameterManagement\ParameterFactoryInterface::getParameter()
|
||||||
*/
|
*/
|
||||||
public function getParameter(string $key): ParameterInterface
|
public function getParameter(string $key): ParameterInterface
|
||||||
{
|
{
|
||||||
return $this->parameters->get($key);
|
return $this->parameters->get($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
* @see \Infinito\Domain\ParameterManagement\ParameterFactoryInterface::getAllParameters()
|
* @see \Infinito\Domain\ParameterManagement\ParameterFactoryInterface::getAllParameters()
|
||||||
*/
|
*/
|
||||||
public function getAllParameters():Collection{
|
public function getAllParameters(): Collection
|
||||||
|
{
|
||||||
return $this->parameters;
|
return $this->parameters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Infinito\Domain\ParameterManagement;
|
namespace Infinito\Domain\ParameterManagement;
|
||||||
|
|
||||||
use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface;
|
use Infinito\Domain\ParameterManagement\Parameter\ParameterInterface;
|
||||||
@ -6,17 +7,15 @@ use Doctrine\Common\Collections\Collection;
|
|||||||
|
|
||||||
interface ParameterFactoryInterface
|
interface ParameterFactoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param string $key
|
* @param string $key
|
||||||
|
*
|
||||||
* @return ParameterInterface
|
* @return ParameterInterface
|
||||||
*/
|
*/
|
||||||
public function getParameter(string $key): ParameterInterface;
|
public function getParameter(string $key): ParameterInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection|ParameterInterface[]
|
* @return Collection|ParameterInterface[]
|
||||||
*/
|
*/
|
||||||
public function getAllParameters():Collection;
|
public function getAllParameters(): Collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace tests\Unit\Domain\ParameterManagement;
|
|
||||||
|
|
||||||
|
namespace tests\Unit\Domain\ParameterManagement;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Infinito\Domain\ParameterManagement\ParameterFactory;
|
use Infinito\Domain\ParameterManagement\ParameterFactory;
|
||||||
use Infinito\Domain\ParameterManagement\Parameter\VersionParameter;
|
use Infinito\Domain\ParameterManagement\Parameter\VersionParameter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class ParameterFactoryTest extends TestCase
|
class ParameterFactoryTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testAllParameters():void{
|
public function testAllParameters(): void
|
||||||
|
{
|
||||||
$parameterFactory = new ParameterFactory();
|
$parameterFactory = new ParameterFactory();
|
||||||
$allParameters = $parameterFactory->getAllParameters();
|
$allParameters = $parameterFactory->getAllParameters();
|
||||||
var_dump($allParameters);
|
var_dump($allParameters);
|
||||||
@ -22,4 +21,3 @@ class ParameterFactoryTest extends TestCase
|
|||||||
$this->assertEquals($versionParameter, $parameterFactory->getParameter('version'));
|
$this->assertEquals($versionParameter, $parameterFactory->getParameter('version'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user