Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"openclassrooms/doctrine-cache-extension": "1.0.*@dev",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-strict-rules": "^1.4",
"phpstan/phpstan-deprecation-rules": "^1.1",
Expand Down
36 changes: 10 additions & 26 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1732025403,
"lastModified": 1738414267,
"owner": "cachix",
"repo": "devenv",
"rev": "6473534b5f3a7ae956ee751084bc4bf2391ccc28",
"rev": "3f49b4afbb9a80b1e81fb6071f59dac152177efa",
"type": "github"
},
"original": {
Expand All @@ -19,10 +19,10 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"lastModified": 1733328505,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"type": "github"
},
"original": {
Expand All @@ -37,14 +37,13 @@
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
]
},
"locked": {
"lastModified": 1732021966,
"lastModified": 1737465171,
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "3308484d1a443fc5bc92012435d79e80458fe43c",
"rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17",
"type": "github"
},
"original": {
Expand Down Expand Up @@ -75,30 +74,15 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1716977621,
"owner": "cachix",
"repo": "devenv-nixpkgs",
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
"type": "github"
},
"original": {
"owner": "cachix",
"ref": "rolling",
"repo": "devenv-nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1731797254,
"lastModified": 1738739810,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59",
"rev": "0a9533e00b72a74d4c69cf1dbb36d5cac7477ea7",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"ref": "nixpkgs-24.11-darwin",
"repo": "nixpkgs",
"type": "github"
}
Expand Down
21 changes: 20 additions & 1 deletion devenv.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
{ pkgs, lib, config, inputs, ... }:

{
languages.php.enable = true;
languages.php = {
enable = true;

ini = ''
memory_limit = -1
'';
};

pre-commit.hooks = {
phpstan = {
enable = true;
entry = "vendor/phpstan/phpstan/phpstan analyze -c phpstan.neon";
pass_filenames = false;
};
phpunit = {
enable = true;
entry = "vendor/phpunit/phpunit/phpunit";
pass_filenames = false;
};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might want to add ecs also (without the auto fix)

}
2 changes: 1 addition & 1 deletion devenv.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
inputs:
nixpkgs:
url: github:cachix/devenv-nixpkgs/rolling
url: github:NixOS/nixpkgs/nixpkgs-24.11-darwin

# If you're using non-OSS software, you can set allowUnfree to true.
# allowUnfree: true
Expand Down
25 changes: 13 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false"
colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
57 changes: 43 additions & 14 deletions src/Handler/Impl/Cache/DoctrineCacheHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

namespace OpenClassrooms\ServiceProxy\Handler\Impl\Cache;

use Doctrine\Common\Cache\Psr6\CacheItem;
use OpenClassrooms\DoctrineCacheExtension\CacheProviderDecorator;
use OpenClassrooms\ServiceProxy\Handler\Contract\CacheHandler;
use OpenClassrooms\ServiceProxy\Handler\Impl\ConfigurableHandler;
use OpenClassrooms\ServiceProxy\Util\ArrayCache;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;

/**
* @deprecated use SymfonyCacheHandler instead
Expand All @@ -18,11 +17,11 @@ final class DoctrineCacheHandler implements CacheHandler
{
use ConfigurableHandler;

private CacheProviderDecorator $cacheProvider;
private CacheItemPoolInterface $pool;

public function __construct(?CacheProviderDecorator $cacheProvider = null, ?string $name = null)
public function __construct(CacheItemPoolInterface $pool = null, ?string $name = null)
{
$this->cacheProvider = $cacheProvider ?? new CacheProviderDecorator(new ArrayCache());
$this->pool = $pool ?? new ArrayAdapter(storeSerialized: false);
$this->name = $name;
}

Expand All @@ -31,19 +30,31 @@ public function fetch(string $poolName, string $id): CacheItemInterface
$tags = explode('|', $id);
$id = array_shift($tags);

$value = $this->cacheProvider->fetchWithNamespace($id, $tags[0] ?? null);

return new CacheItem($id, $value, $value !== false);
return $this->fetchWithNamespace($id, $tags[0] ?? null);
}

public function save(string $poolName, string $id, $data, ?int $lifeTime = null, array $tags = []): void
{
$this->cacheProvider->saveWithNamespace($id, $data, $tags[0] ?? null, $lifeTime);
}
$namespaceId = $tags[0] ?? null;

public function contains(string $poolName, string $id): bool
{
return $this->cacheProvider->contains($id);
if ($namespaceId !== null) {
$namespace = $this->doFetch($namespaceId);
if (!$namespace->isHit()) {
$namespace->set($namespaceId . '_' . mt_rand(0, 1000000))
// 7 days as no expiration can prevent cache eviction forever (like redis)
->expiresAfter(7 * 24 * 60 * 60);

$this->pool->save($namespace);
}
$id = $namespace->get() . $id;
}

$item = $this->doFetch($id);

$item->set($data)
->expiresAfter($lifeTime ?? 3600);

$this->pool->save($item);
}

public function invalidateTags(string $poolName, array $tags): void
Expand All @@ -55,4 +66,22 @@ public function getName(): string
{
return $this->name ?? 'doctrine_array';
}

private function fetchWithNamespace(string $id, string $namespaceId = null): CacheItemInterface
{
if ($namespaceId !== null) {
$namespace = $this->doFetch($namespaceId);

if ($namespace->isHit()) {
$id = $namespace->get() . $id;
}
}

return $this->doFetch($id);
}

private function doFetch(string $id): CacheItemInterface
{
return $this->pool->getItem(rawurlencode($id));
}
}
6 changes: 0 additions & 6 deletions src/Handler/Impl/Cache/SymfonyCacheHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ public function save(string $poolName, string $id, $data, ?int $ttl = null, arra
$pool->save($item);
}

public function contains(string $poolName, string $id): bool
{
return $this->getPool($poolName)
->hasItem($id);
}

public function invalidateTags(string $poolName, array $tags): void
{
$this->getPool($poolName)
Expand Down
110 changes: 0 additions & 110 deletions src/Util/ArrayCache.php

This file was deleted.

Loading