Skip to content

Commit

Permalink
enable cache warmer; disable in-memory cache (#212)
Browse files Browse the repository at this point in the history
* refactoring: allow overwrite http status code for docs

* disable cache warmer

* disable cache warmer

* enable cache warmer
  • Loading branch information
troytft committed Jul 10, 2022
1 parent b6f048f commit b5bf3d1
Showing 1 changed file with 16 additions and 97 deletions.
113 changes: 16 additions & 97 deletions src/Helper/InterfaceChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,19 @@

use RestApiBundle;

use function array_key_exists;
use function class_exists;

final class InterfaceChecker
{
/**
* @var array<string, bool>
*/
private static array $responseModelCache = [];

/**
* @var array<string, bool>
*/
private static array $dateTimeCache = [
\DateTime::class => true,
];

/**
* @var array<string, bool>
*/
private static array $mapperDateCache = [
RestApiBundle\Mapping\Mapper\Date::class => true,
];

/**
* @var array<string, bool>
*/
private static array $responseModelEnumCache = [];

/**
* @var array<string, bool>
*/
private static array $mapperEnumCache = [];

/**
* @var array<string, bool>
*/
private static array $responseModelDateCache = [];

/**
* @var array<string, bool>
*/
private static array $mapperModelCache = [];

/**
* @var array<string, bool>
*/
private static array $requestModelCache = [];

public static function isResponseModel(string $class): bool
{
if (!class_exists($class)) {
return false;
}

if (!array_key_exists($class, static::$responseModelCache)) {
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

static::$responseModelCache[$class] = $reflectionClass->isInstantiable()
&& $reflectionClass->implementsInterface(RestApiBundle\Mapping\ResponseModel\ResponseModelInterface::class);
}
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

return static::$responseModelCache[$class];
return $reflectionClass->isInstantiable() && $reflectionClass->implementsInterface(RestApiBundle\Mapping\ResponseModel\ResponseModelInterface::class);
}

public static function isDateTime(string $class): bool
Expand All @@ -75,25 +25,16 @@ public static function isDateTime(string $class): bool
return false;
}

if (!array_key_exists($class, static::$dateTimeCache)) {
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

static::$dateTimeCache[$class] = $reflectionClass->isInstantiable()
&& $reflectionClass->implementsInterface(\DateTimeInterface::class);
}
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

return static::$dateTimeCache[$class];
return $reflectionClass->isInstantiable() && $reflectionClass->implementsInterface(\DateTimeInterface::class);
}

public static function isMapperDate(string $class): bool
{
if (!array_key_exists($class, static::$mapperDateCache)) {
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

static::$mapperDateCache[$class] = $reflectionClass->isInstantiable() && $reflectionClass->implementsInterface(RestApiBundle\Mapping\Mapper\DateInterface::class);
}

return static::$mapperDateCache[$class];
return $reflectionClass->isInstantiable() && $reflectionClass->implementsInterface(RestApiBundle\Mapping\Mapper\DateInterface::class);
}

public static function isResponseModelEnum(string $class): bool
Expand All @@ -102,13 +43,9 @@ public static function isResponseModelEnum(string $class): bool
return false;
}

if (!array_key_exists($class, static::$responseModelEnumCache)) {
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

static::$responseModelEnumCache[$class] = $reflectionClass->implementsInterface(RestApiBundle\Mapping\ResponseModel\EnumInterface::class);
}
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

return static::$responseModelEnumCache[$class];
return $reflectionClass->implementsInterface(RestApiBundle\Mapping\ResponseModel\EnumInterface::class);
}

public static function isMapperEnum(string $class): bool
Expand All @@ -117,13 +54,9 @@ public static function isMapperEnum(string $class): bool
return false;
}

if (!array_key_exists($class, static::$mapperEnumCache)) {
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

static::$mapperEnumCache[$class] = $reflectionClass->implementsInterface(RestApiBundle\Mapping\Mapper\EnumInterface::class);
}

return static::$mapperEnumCache[$class];
return $reflectionClass->implementsInterface(RestApiBundle\Mapping\Mapper\EnumInterface::class);
}

public static function isResponseModelDate(string $class): bool
Expand All @@ -132,13 +65,9 @@ public static function isResponseModelDate(string $class): bool
return false;
}

if (!array_key_exists($class, static::$responseModelDateCache)) {
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

static::$responseModelDateCache[$class] = $reflectionClass->implementsInterface(RestApiBundle\Mapping\ResponseModel\DateInterface::class);
}
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

return static::$responseModelDateCache[$class];
return $reflectionClass->implementsInterface(RestApiBundle\Mapping\ResponseModel\DateInterface::class);
}

public static function isMapperModel(string $class): bool
Expand All @@ -147,14 +76,9 @@ public static function isMapperModel(string $class): bool
return false;
}

if (!array_key_exists($class, static::$mapperModelCache)) {
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

static::$mapperModelCache[$class] = $reflectionClass->isInstantiable()
&& $reflectionClass->implementsInterface(RestApiBundle\Mapping\Mapper\ModelInterface::class);
}

return static::$mapperModelCache[$class];
return $reflectionClass->isInstantiable() && $reflectionClass->implementsInterface(RestApiBundle\Mapping\Mapper\ModelInterface::class);
}

public static function isRequestModel(string $class): bool
Expand All @@ -163,13 +87,8 @@ public static function isRequestModel(string $class): bool
return false;
}

if (!array_key_exists($class, static::$requestModelCache)) {
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

static::$requestModelCache[$class] = $reflectionClass->isInstantiable()
&& $reflectionClass->implementsInterface(RestApiBundle\Mapping\RequestModel\RequestModelInterface::class);
}
$reflectionClass = RestApiBundle\Helper\ReflectionClassStore::get($class);

return static::$requestModelCache[$class];
return $reflectionClass->isInstantiable() && $reflectionClass->implementsInterface(RestApiBundle\Mapping\RequestModel\RequestModelInterface::class);
}
}

0 comments on commit b5bf3d1

Please sign in to comment.