mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2024-12-04 23:17:19 +01:00
Introduced class MethodPrefixType
This commit is contained in:
parent
6378c47f51
commit
d2b0cba30b
@ -3,13 +3,13 @@
|
||||
namespace Infinito\Domain\DomManagement;
|
||||
|
||||
use Infinito\Entity\EntityInterface;
|
||||
use Infinito\Domain\RightManagement\RightTransformerService;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Infinito\Domain\RequestManagement\Entity\RequestedEntityServiceInterface;
|
||||
use Infinito\DBAL\Types\Meta\Right\LayerType;
|
||||
use Infinito\Domain\LayerManagement\LayerInterfaceMap;
|
||||
use FOS\UserBundle\Model\UserInterface;
|
||||
use Infinito\Exception\Core\NotCorrectInstanceCoreException;
|
||||
use Infinito\Domain\MethodManagement\MethodPrefixType;
|
||||
|
||||
/**
|
||||
* This class is not ready and not tested!
|
||||
@ -22,16 +22,6 @@ use Infinito\Exception\Core\NotCorrectInstanceCoreException;
|
||||
*/
|
||||
final class EntityDomService implements EntityDomServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const GET_METHOD = RightTransformerService::GET_PREFIX;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const HAS_METHOD = RightTransformerService::HAS_PREFIX;
|
||||
|
||||
/**
|
||||
* @var RequestedEntityServiceInterface
|
||||
*/
|
||||
@ -102,11 +92,11 @@ final class EntityDomService implements EntityDomServiceInterface
|
||||
*/
|
||||
private function getPropertyValue(string $propertyName)
|
||||
{
|
||||
$hasMethod = $this->getMethodName(self::HAS_METHOD, $propertyName);
|
||||
$hasMethod = $this->getMethodName(MethodPrefixType::HAS, $propertyName);
|
||||
if ($this->methodExist($hasMethod) && !$this->getMethodResult($hasMethod)) {
|
||||
return null;
|
||||
}
|
||||
$getMethod = $this->getMethodName(self::GET_METHOD, $propertyName);
|
||||
$getMethod = $this->getMethodName(MethodPrefixType::GET, $propertyName);
|
||||
$result = $this->getMethodResult($getMethod);
|
||||
|
||||
return $result;
|
||||
@ -178,7 +168,7 @@ final class EntityDomService implements EntityDomServiceInterface
|
||||
*/
|
||||
private function isPropertyAccessible(string $propertyName): bool
|
||||
{
|
||||
$getMethod = $this->getMethodName(self::GET_METHOD, $propertyName);
|
||||
$getMethod = $this->getMethodName(MethodPrefixType::GET, $propertyName);
|
||||
|
||||
return $this->entityReflectionClass->hasMethod($getMethod);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ use Infinito\Entity\Meta\LawInterface;
|
||||
use Infinito\Domain\RightManagement\RightChecker;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Domain\SourceManagement\SourceMemberInformation;
|
||||
use Infinito\Domain\MethodManagement\MethodPrefixType;
|
||||
|
||||
/**
|
||||
* @todo Implement checking by operation sources
|
||||
@ -35,7 +36,7 @@ final class LawPermissionChecker implements LawPermissionCheckerInterface
|
||||
{
|
||||
$result = new ArrayCollection();
|
||||
foreach ($rights as $right) {
|
||||
if ($right->{'get'.$attribut}() === $value) {
|
||||
if ($right->{MethodPrefixType::GET.$attribut}() === $value) {
|
||||
$result->add($right);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Infinito\Domain\MethodManagement;
|
||||
|
||||
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
|
||||
|
||||
/**
|
||||
* Contains the possible prefixes for Methods.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class MethodPrefixType extends AbstractEnumType
|
||||
{
|
||||
/**
|
||||
* @var string Prefix for setter functions
|
||||
*/
|
||||
public const SET = 'set';
|
||||
|
||||
/**
|
||||
* @var string Prefix for getter functions
|
||||
*/
|
||||
public const GET = 'get';
|
||||
|
||||
/**
|
||||
* @var string Prefix for has functions
|
||||
*/
|
||||
public const HAS = 'has';
|
||||
|
||||
protected static $choices = [
|
||||
self::GET,
|
||||
self::HAS,
|
||||
self::SET,
|
||||
];
|
||||
}
|
@ -5,27 +5,13 @@ namespace Infinito\Domain\RightManagement;
|
||||
use Infinito\Entity\Meta\RightInterface;
|
||||
use Infinito\Domain\RequestManagement\Right\RequestedRightInterface;
|
||||
use Infinito\Entity\Meta\Right;
|
||||
use Infinito\Domain\MethodManagement\MethodPrefixType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class RightTransformerService implements RightTransformerServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var string Prefix for setter functions
|
||||
*/
|
||||
public const SET_PREFIX = 'set';
|
||||
|
||||
/**
|
||||
* @var string Prefix for getter functions
|
||||
*/
|
||||
public const GET_PREFIX = 'get';
|
||||
|
||||
/**
|
||||
* @var string Prefix for has functions
|
||||
*/
|
||||
public const HAS_PREFIX = 'has';
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
*
|
||||
@ -43,7 +29,7 @@ final class RightTransformerService implements RightTransformerServiceInterface
|
||||
*/
|
||||
private function isNameSetter(string $name): bool
|
||||
{
|
||||
return self::GET_PREFIX === substr($name, 0, 3);
|
||||
return MethodPrefixType::GET === substr($name, 0, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,9 +105,9 @@ final class RightTransformerService implements RightTransformerServiceInterface
|
||||
*/
|
||||
private function isAttributeGetPossible(string $attribute, object $object)
|
||||
{
|
||||
$has = $this->createMethod(self::HAS_PREFIX, $attribute);
|
||||
$has = $this->createMethod(MethodPrefixType::HAS, $attribute);
|
||||
if ($this->hasMethod($has, $object)) {
|
||||
$get = $this->createMethod(self::GET_PREFIX, $attribute);
|
||||
$get = $this->createMethod(MethodPrefixType::GET, $attribute);
|
||||
|
||||
return $object->{$get}();
|
||||
}
|
||||
@ -140,8 +126,8 @@ final class RightTransformerService implements RightTransformerServiceInterface
|
||||
$attributes = $this->getAttributesExistInBoth($right, $requestedRight);
|
||||
foreach ($attributes as $attribute) {
|
||||
if ($this->isAttributeGetPossible($attribute, $requestedRight)) {
|
||||
$get = $this->createMethod(self::GET_PREFIX, $attribute);
|
||||
$set = $this->createMethod(self::SET_PREFIX, $attribute);
|
||||
$get = $this->createMethod(MethodPrefixType::GET, $attribute);
|
||||
$set = $this->createMethod(MethodPrefixType::SET, $attribute);
|
||||
$origine = $requestedRight->{$get}();
|
||||
$right->{$set}($origine);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use Infinito\Entity\Meta\RightInterface;
|
||||
use Infinito\Entity\Source\SourceInterface;
|
||||
use Infinito\Domain\LawManagement\LawPermissionChecker;
|
||||
use Infinito\Exception\Permission\NoSourcePermissionException;
|
||||
use Infinito\Domain\MethodManagement\MethodPrefixType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -32,7 +33,7 @@ final class SecureSourceChecker implements SecureSourceCheckerInterface
|
||||
*/
|
||||
private function isGetter(string $methodName): bool
|
||||
{
|
||||
return 'get' === substr($methodName, 0, 3);
|
||||
return MethodPrefixType::GET === substr($methodName, 0, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Infinito\Exception\Attribut\AllreadyDefinedAttributException;
|
||||
use Infinito\Exception\Collection\ContainsElementException;
|
||||
use Infinito\Exception\Collection\NotSetElementException;
|
||||
use Infinito\Domain\MethodManagement\MethodPrefixType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@ -37,7 +38,7 @@ final class SourceRightManager implements SourceRightManagerInterface
|
||||
$attributes = ['source', 'law'];
|
||||
foreach ($attributes as $attribut) {
|
||||
try {
|
||||
$right->{'get'.ucfirst($attribut)}();
|
||||
$right->{MethodPrefixType::GET.ucfirst($attribut)}();
|
||||
throw new AllreadyDefinedAttributException("The attribut \"$attribut\" is allready defined!");
|
||||
} catch (\Error $error) {
|
||||
//Expected
|
||||
|
Loading…
Reference in New Issue
Block a user