Skip to content

Commit c526dcc

Browse files
committed
implemented a cache and a cache clearer in tdbm bundle
1 parent e4f6c91 commit c526dcc

File tree

7 files changed

+49
-6
lines changed

7 files changed

+49
-6
lines changed

.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/Tests export-ignore
2+
/phpstan.neon export-ignore
3+
/phpcs.xml.dist export-ignore
4+
/phpcs.xml export-ignore
5+
/.gitignore export-ignore
6+
/.travis.yml export-ignore

Resources/config/container/tdbm.xml

+11
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,19 @@
1515
<argument key="$codeGeneratorListeners" type="collection">
1616
<argument type="service" id="TheCodingMachine\TDBM\Bundle\Utils\SymfonyCodeGeneratorListener"/>
1717
</argument>
18+
<argument key="$cache" type="service" id="tdbm.cache"></argument>
1819
</service>
1920

21+
<service id="tdbm.cache" class="Doctrine\Common\Cache\FilesystemCache">
22+
<argument>%kernel.project_dir%/var/cache/tdbm</argument>
23+
</service>
24+
25+
26+
<service id="tdbm.cacheclearer" class="TheCodingMachine\TDBM\Bundle\Utils\DoctrineCacheClearer">
27+
<argument type="service" id="tdbm.cache" />
28+
<tag name="kernel.cache_clearer"/>
29+
</service>
30+
2031
<service id="TheCodingMachine\TDBM\ConfigurationInterface" alias="TheCodingMachine\TDBM\Configuration">
2132
</service>
2233

Tests/Fixtures/config/services.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313

1414
# makes classes in src/ available to be used as services
1515
# this creates a service per class whose id is the fully-qualified class name
16-
TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\:
16+
TheCodingMachine\TDBM\Bundle\Tests\Fixtures\:
1717
resource: '../*'
1818
exclude: '../{Entities}'
1919

Tests/FunctionalTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Symfony\Component\HttpFoundation\Request;
7-
use TheCodingMachine\GraphQLite\Schema;
87
use TheCodingMachine\TDBM\TDBMService;
98

109
class FunctionalTest extends TestCase

Tests/TdbmTestingKernel.php

-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
use Symfony\Component\DependencyInjection\ContainerBuilder;
1111
use Symfony\Component\HttpKernel\Kernel;
1212
use Symfony\Component\Routing\RouteCollectionBuilder;
13-
use TheCodingMachine\Graphqlite\Bundle\GraphqliteBundle;
1413
use TheCodingMachine\TDBM\Bundle\TdbmBundle;
15-
use TheCodingMachine\TDBM\Bundle\TdbmGraphqlBundle;
1614

1715
class TdbmTestingKernel extends Kernel
1816
{

Utils/DoctrineCacheClearer.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\TDBM\Bundle\Utils;
5+
6+
use Doctrine\Common\Cache\FlushableCache;
7+
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
8+
9+
class DoctrineCacheClearer implements CacheClearerInterface
10+
{
11+
/**
12+
* @var FlushableCache
13+
*/
14+
private $cache;
15+
16+
public function __construct(FlushableCache $cache)
17+
{
18+
$this->cache = $cache;
19+
}
20+
21+
/**
22+
* Clears any caches necessary.
23+
*/
24+
public function clear($cacheDir)
25+
{
26+
$this->cache->flushAll();
27+
}
28+
}

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"php" : ">=7.1",
2525
"thecodingmachine/tdbm" : "~5.1.0",
2626
"doctrine/doctrine-bundle": "^1.9 || ^2",
27-
"doctrine/orm": "^1 || ^2"
27+
"doctrine/orm": "^1 || ^2",
28+
"symfony/http-kernel": "^4.1.9 || ^5"
2829
},
2930
"require-dev": {
3031
"roave/security-advisories": "dev-master",
@@ -34,7 +35,7 @@
3435
"phpstan/phpstan-shim": "^0.11.4"
3536
},
3637
"scripts": {
37-
"phpstan": "phpstan analyse TdbmBundle.php DependencyInjection/ Resources/ -c phpstan.neon --level=7 --no-progress"
38+
"phpstan": "phpstan analyse TdbmBundle.php DependencyInjection/ Resources/ Utils/ -c phpstan.neon --level=7 --no-progress"
3839
},
3940
"autoload" : {
4041
"psr-4" : {

0 commit comments

Comments
 (0)