Skip to content

Commit

Permalink
Merge pull request #159 from bearsunday/fastly-module-optional
Browse files Browse the repository at this point in the history
Fix type casting and update dependencies
  • Loading branch information
koriym authored Jan 9, 2025
2 parents 7997435 + 2100303 commit 7c12d26
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"Attribute", "Memcached", "Redis", "RedisException",
"Doctrine\\Common\\Cache\\ArrayCache", "Doctrine\\Common\\Cache\\MemcachedCache", "Doctrine\\Common\\Cache\\RedisCache",
"BEAR\\FastlyModule\\FastlyCachePurgerInterface", "BEAR\\FastlyModule\\FastlyPurgeModule",
"Detection\\MobileDetect"
]
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
],
"require": {
"php": "^8.1",
"bear/fastly-module": "^1.0",
"bear/resource": "^1.16.1",
"bear/sunday": "^1.5",
"doctrine/annotations": "^1.8 || ^2.0",
Expand All @@ -24,6 +23,7 @@
},
"require-dev": {
"ext-redis": "*",
"bear/fastly-module": "^1.0",
"bamarni/composer-bin-plugin": "^1.8",
"koriym/attributes": "^1.0.1",
"madapaja/twig-module": "^2.3",
Expand Down
7 changes: 7 additions & 0 deletions src/Cdn/FastlyModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
use BEAR\FastlyModule\FastlyPurgeModule;
use BEAR\QueryRepository\CdnCacheControlHeaderSetterInterface;
use BEAR\QueryRepository\PurgerInterface;
use LogicException;
use Ray\Di\AbstractModule;

use function class_exists;

final class FastlyModule extends AbstractModule
{
public function __construct(
Expand All @@ -17,6 +20,10 @@ public function __construct(
AbstractModule|null $module = null,
) {
parent::__construct($module);

if (! class_exists(FastlyPurgeModule::class)) {
throw new LogicException('Install bear/fastly-module'); // @codeCoverageIgnore
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/QueryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function get(AbstractUri $uri): ResourceState|null
return null;
}

$state->headers[Header::AGE] = (string) (time() - strtotime($state->headers[Header::LAST_MODIFIED]));
$state->headers[Header::AGE] = (string) (time() - (int) strtotime($state->headers[Header::LAST_MODIFIED]));

return $state;
}
Expand Down Expand Up @@ -113,6 +113,6 @@ private function getExpiryAtSec(ResourceObject $ro, Cacheable $cacheable): int
/** @var string $expiryAt */
$expiryAt = $ro->body[$cacheable->expiryAt];

return strtotime($expiryAt) - time();
return (int) strtotime($expiryAt) - time();
}
}

0 comments on commit 7c12d26

Please sign in to comment.