Skip to content

Commit fb3b9fb

Browse files
committed
Remove doctrine extension deps
2 parents 2bfa3eb + 6bd2923 commit fb3b9fb

8 files changed

Lines changed: 73 additions & 160 deletions

File tree

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
},
3939
"require-dev": {
4040
"phpunit/phpunit": "^9.5",
41-
"openclassrooms/doctrine-cache-extension": "dev-dcotrine_cache_two",
4241
"phpstan/phpstan": "^1.9",
4342
"phpstan/phpstan-strict-rules": "^1.4",
4443
"phpstan/phpstan-deprecation-rules": "^1.1",

devenv.lock

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"devenv": {
44
"locked": {
55
"dir": "src/modules",
6-
"lastModified": 1732025403,
6+
"lastModified": 1738414267,
77
"owner": "cachix",
88
"repo": "devenv",
9-
"rev": "6473534b5f3a7ae956ee751084bc4bf2391ccc28",
9+
"rev": "3f49b4afbb9a80b1e81fb6071f59dac152177efa",
1010
"type": "github"
1111
},
1212
"original": {
@@ -19,10 +19,10 @@
1919
"flake-compat": {
2020
"flake": false,
2121
"locked": {
22-
"lastModified": 1696426674,
22+
"lastModified": 1733328505,
2323
"owner": "edolstra",
2424
"repo": "flake-compat",
25-
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
25+
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
2626
"type": "github"
2727
},
2828
"original": {
@@ -37,14 +37,13 @@
3737
"gitignore": "gitignore",
3838
"nixpkgs": [
3939
"nixpkgs"
40-
],
41-
"nixpkgs-stable": "nixpkgs-stable"
40+
]
4241
},
4342
"locked": {
44-
"lastModified": 1732021966,
43+
"lastModified": 1737465171,
4544
"owner": "cachix",
4645
"repo": "git-hooks.nix",
47-
"rev": "3308484d1a443fc5bc92012435d79e80458fe43c",
46+
"rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17",
4847
"type": "github"
4948
},
5049
"original": {
@@ -75,30 +74,15 @@
7574
},
7675
"nixpkgs": {
7776
"locked": {
78-
"lastModified": 1716977621,
79-
"owner": "cachix",
80-
"repo": "devenv-nixpkgs",
81-
"rev": "4267e705586473d3e5c8d50299e71503f16a6fb6",
82-
"type": "github"
83-
},
84-
"original": {
85-
"owner": "cachix",
86-
"ref": "rolling",
87-
"repo": "devenv-nixpkgs",
88-
"type": "github"
89-
}
90-
},
91-
"nixpkgs-stable": {
92-
"locked": {
93-
"lastModified": 1731797254,
77+
"lastModified": 1738739810,
9478
"owner": "NixOS",
9579
"repo": "nixpkgs",
96-
"rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59",
80+
"rev": "0a9533e00b72a74d4c69cf1dbb36d5cac7477ea7",
9781
"type": "github"
9882
},
9983
"original": {
10084
"owner": "NixOS",
101-
"ref": "nixos-24.05",
85+
"ref": "nixpkgs-24.11-darwin",
10286
"repo": "nixpkgs",
10387
"type": "github"
10488
}

devenv.nix

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
{ pkgs, lib, config, inputs, ... }:
22

33
{
4-
languages.php.enable = true;
4+
languages.php = {
5+
enable = true;
6+
7+
ini = ''
8+
memory_limit = -1
9+
'';
10+
};
11+
12+
pre-commit.hooks = {
13+
phpstan = {
14+
enable = true;
15+
entry = "vendor/phpstan/phpstan/phpstan analyze -c phpstan.neon";
16+
pass_filenames = false;
17+
};
18+
phpunit = {
19+
enable = true;
20+
entry = "vendor/phpunit/phpunit/phpunit";
21+
pass_filenames = false;
22+
};
23+
};
524
}

devenv.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
22
inputs:
33
nixpkgs:
4-
url: github:cachix/devenv-nixpkgs/rolling
4+
url: github:NixOS/nixpkgs/nixpkgs-24.11-darwin
55

66
# If you're using non-OSS software, you can set allowUnfree to true.
77
# allowUnfree: true

src/Handler/Impl/Cache/DoctrineCacheHandler.php

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
namespace OpenClassrooms\ServiceProxy\Handler\Impl\Cache;
66

7-
use Doctrine\Common\Cache\Psr6\CacheItem;
8-
use OpenClassrooms\DoctrineCacheExtension\CacheProviderDecorator;
97
use OpenClassrooms\ServiceProxy\Handler\Contract\CacheHandler;
108
use OpenClassrooms\ServiceProxy\Handler\Impl\ConfigurableHandler;
119
use Psr\Cache\CacheItemInterface;
10+
use Psr\Cache\CacheItemPoolInterface;
1211
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1312

1413
/**
@@ -18,11 +17,11 @@ final class DoctrineCacheHandler implements CacheHandler
1817
{
1918
use ConfigurableHandler;
2019

21-
private CacheProviderDecorator $cacheProvider;
20+
private CacheItemPoolInterface $pool;
2221

23-
public function __construct(?CacheProviderDecorator $cacheProvider = null, ?string $name = null)
22+
public function __construct(CacheItemPoolInterface $pool = null, ?string $name = null)
2423
{
25-
$this->cacheProvider = $cacheProvider ?? new CacheProviderDecorator(new ArrayAdapter(storeSerialized: false));
24+
$this->pool = $pool ?? new ArrayAdapter(storeSerialized: false);
2625
$this->name = $name;
2726
}
2827

@@ -31,26 +30,56 @@ public function fetch(string $poolName, string $id): CacheItemInterface
3130
$tags = explode('|', $id);
3231
$id = array_shift($tags);
3332

34-
$value = $this->cacheProvider->fetchWithNamespace($id, $tags[0] ?? null);
35-
36-
return new CacheItem($id, $value, $value !== false);
33+
return $this->fetchWithNamespace($id, $tags[0] ?? null);
3734
}
3835

39-
public function save(string $poolName, string $id, $data, ?int $lifeTime = null, array $tags = []): void
36+
private function fetchWithNamespace(string $id, string $namespaceId = null): CacheItemInterface
4037
{
41-
$this->cacheProvider->saveWithNamespace($id, $data, $tags[0] ?? null, $lifeTime);
38+
if (null !== $namespaceId) {
39+
$namespace = $this->doFetch($namespaceId);
40+
41+
if ($namespace->isHit()) {
42+
$id = $namespace->get().$id;
43+
}
44+
}
45+
46+
return $this->doFetch($id);
4247
}
4348

44-
public function contains(string $poolName, string $id): bool
49+
public function save(string $poolName, string $id, $data, ?int $lifeTime = null, array $tags = []): void
4550
{
46-
return $this->cacheProvider->contains($id);
51+
$namespaceId = $tags[0] ?? null;
52+
53+
if (null !== $namespaceId) {
54+
$namespace = $this->doFetch($namespaceId);
55+
if (! $namespace->isHit()) {
56+
$namespace->set($namespaceId.'_'.rand(0, 1000000))
57+
// 7 days as no expiration can prevent cache eviction forever (like redis)
58+
->expiresAfter(7 * 24 * 60 * 60);
59+
60+
$this->pool->save($namespace);
61+
}
62+
$id = $namespace->get().$id;
63+
}
64+
65+
$item = $this->doFetch($id);
66+
67+
$item->set($data)
68+
->expiresAfter($lifeTime ?? 3600);
69+
70+
$this->pool->save($item);
4771
}
4872

4973
public function invalidateTags(string $poolName, array $tags): void
5074
{
5175
throw new \BadMethodCallException('Cache provider does not support tags invalidation');
5276
}
5377

78+
private function doFetch(string $id): CacheItemInterface
79+
{
80+
return $this->pool->getItem(rawurlencode($id));
81+
}
82+
5483
public function getName(): string
5584
{
5685
return $this->name ?? 'doctrine_array';

src/Handler/Impl/Cache/SymfonyCacheHandler.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ public function save(string $poolName, string $id, $data, ?int $ttl = null, arra
4646
$pool->save($item);
4747
}
4848

49-
public function contains(string $poolName, string $id): bool
50-
{
51-
return $this->getPool($poolName)
52-
->hasItem($id);
53-
}
54-
5549
public function invalidateTags(string $poolName, array $tags): void
5650
{
5751
$this->getPool($poolName)

src/Util/ArrayCache.php

Lines changed: 0 additions & 110 deletions
This file was deleted.

tests/Double/Mock/Cache/DoctrineCacheHandlerMock.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace OpenClassrooms\ServiceProxy\Tests\Double\Mock\Cache;
66

7-
use OpenClassrooms\DoctrineCacheExtension\CacheProviderDecorator;
87
use OpenClassrooms\ServiceProxy\Handler\Contract\CacheHandler;
98
use OpenClassrooms\ServiceProxy\Handler\Impl\Cache\DoctrineCacheHandler;
109
use Psr\Cache\CacheItemInterface;
@@ -25,8 +24,7 @@ public function __construct(?string $name = null, bool $default = true)
2524
$this->name = $name ?? 'array';
2625
$this->default = $default;
2726

28-
$cacheProvider = new CacheProviderDecorator(new ArrayAdapter());
29-
$this->wrappedHandler = new DoctrineCacheHandler($cacheProvider, $name);
27+
$this->wrappedHandler = new DoctrineCacheHandler(new ArrayAdapter(storeSerialized: false), $name);
3028
}
3129

3230
public function fetch(string $poolName, string $id): CacheItemInterface

0 commit comments

Comments
 (0)