├── .github ├── .kodiak.toml └── workflows │ ├── codesniffer.yml │ ├── coverage.yml │ ├── phpstan.yml │ └── tests.yml ├── LICENSE ├── composer.json └── src └── DI └── CacheExtension.php /.github/.kodiak.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [merge] 4 | automerge_label = "automerge" 5 | blacklist_title_regex = "^WIP.*" 6 | blacklist_labels = ["WIP"] 7 | method = "rebase" 8 | delete_branch_on_merge = true 9 | notify_on_conflict = true 10 | optimistic_updates = false 11 | -------------------------------------------------------------------------------- /.github/workflows/codesniffer.yml: -------------------------------------------------------------------------------- 1 | name: "Codesniffer" 2 | 3 | on: 4 | pull_request: 5 | workflow_dispatch: 6 | 7 | push: 8 | branches: ["*"] 9 | 10 | schedule: 11 | - cron: "0 8 * * 1" 12 | 13 | jobs: 14 | codesniffer: 15 | name: "Codesniffer" 16 | uses: contributte/.github/.github/workflows/codesniffer.yml@master 17 | with: 18 | php: "8.3" 19 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: "Coverage" 2 | 3 | on: 4 | pull_request: 5 | workflow_dispatch: 6 | 7 | push: 8 | branches: ["*"] 9 | 10 | schedule: 11 | - cron: "0 8 * * 1" 12 | 13 | jobs: 14 | coverage: 15 | name: "Nette Tester" 16 | uses: contributte/.github/.github/workflows/nette-tester-coverage-v2.yml@master 17 | with: 18 | php: "8.3" 19 | -------------------------------------------------------------------------------- /.github/workflows/phpstan.yml: -------------------------------------------------------------------------------- 1 | name: "Phpstan" 2 | 3 | on: 4 | pull_request: 5 | workflow_dispatch: 6 | 7 | push: 8 | branches: ["*"] 9 | 10 | schedule: 11 | - cron: "0 8 * * 1" 12 | 13 | jobs: 14 | phpstan: 15 | name: "Phpstan" 16 | uses: contributte/.github/.github/workflows/phpstan.yml@master 17 | with: 18 | php: "8.3" 19 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: "Nette Tester" 2 | 3 | on: 4 | pull_request: 5 | workflow_dispatch: 6 | 7 | push: 8 | branches: [ "*" ] 9 | 10 | schedule: 11 | - cron: "0 8 * * 1" 12 | 13 | jobs: 14 | test84: 15 | name: "Nette Tester" 16 | uses: contributte/.github/.github/workflows/nette-tester.yml@master 17 | with: 18 | php: "8.4" 19 | 20 | test83: 21 | name: "Nette Tester" 22 | uses: contributte/.github/.github/workflows/nette-tester.yml@master 23 | with: 24 | php: "8.3" 25 | 26 | test82: 27 | name: "Nette Tester" 28 | uses: contributte/.github/.github/workflows/nette-tester.yml@master 29 | with: 30 | php: "8.2" 31 | 32 | testlower: 33 | name: "Nette Tester" 34 | uses: contributte/.github/.github/workflows/nette-tester.yml@master 35 | with: 36 | php: "8.2" 37 | composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Nettrine 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nettrine/cache", 3 | "description": "Doctrine Cache for Nette Framework", 4 | "keywords": [ 5 | "nettrine", 6 | "nette", 7 | "doctrine", 8 | "cache" 9 | ], 10 | "type": "library", 11 | "license": "MIT", 12 | "homepage": "https://github.com/contributte/doctrine-cache", 13 | "authors": [ 14 | { 15 | "name": "Milan Felix Šulc", 16 | "homepage": "https://f3l1x.io" 17 | } 18 | ], 19 | "require": { 20 | "php": ">=8.2", 21 | "nette/di": "^3.2.4", 22 | "doctrine/cache": "^2.2.0", 23 | "symfony/cache": "^7.2.1" 24 | }, 25 | "require-dev": { 26 | "contributte/qa": "^0.4", 27 | "contributte/tester": "^0.3", 28 | "contributte/phpstan": "^0.2", 29 | "tracy/tracy": "^2.10.9" 30 | }, 31 | "autoload": { 32 | "psr-4": { 33 | "Nettrine\\Cache\\": "src/" 34 | } 35 | }, 36 | "autoload-dev": { 37 | "psr-4": { 38 | "Tests\\": "tests" 39 | } 40 | }, 41 | "minimum-stability": "dev", 42 | "prefer-stable": true, 43 | "config": { 44 | "sort-packages": true, 45 | "allow-plugins": { 46 | "dealerdirect/phpcodesniffer-composer-installer": true 47 | } 48 | }, 49 | "extra": { 50 | "branch-alias": { 51 | "dev-master": "0.6.x-dev" 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/DI/CacheExtension.php: -------------------------------------------------------------------------------- 1 | debugMode === null) { 28 | $this->debugMode = class_exists(Debugger::class) && Debugger::$productionMode === false; 29 | } 30 | } 31 | 32 | public function getConfigSchema(): Schema 33 | { 34 | return Expect::structure([ 35 | 'adapter' => Expect::anyOf( 36 | Expect::string(), 37 | Expect::type(Statement::class) 38 | )->nullable(), 39 | ]); 40 | } 41 | 42 | public function loadConfiguration(): void 43 | { 44 | $builder = $this->getContainerBuilder(); 45 | $config = $this->config; 46 | 47 | if ($config->adapter === null) { 48 | // auto choose 49 | $adapterDefinition = $builder->addDefinition($this->prefix('adapter')) 50 | ->setType(AdapterInterface::class); 51 | 52 | if ($this->debugMode === true) { 53 | $adapterDefinition->setFactory(ArrayAdapter::class); 54 | } elseif (isset($builder->parameters['tempDir'])) { 55 | $adapterDefinition->setFactory(FilesystemAdapter::class, [ 56 | 'directory' => $builder->parameters['tempDir'] . '/cache/nettrine.cache', 57 | ]); 58 | } elseif (function_exists('apcu_exists')) { 59 | $adapterDefinition->setFactory(ApcuAdapter::class); 60 | } else { 61 | throw new InvalidStateException(sprintf( 62 | 'Unable to find an available cache adapter, please provide one via \'%s\' configuration.', 63 | sprintf('%s > adapter', $this->name) 64 | )); 65 | } 66 | 67 | $builder->addDefinition($this->prefix('driver')) 68 | ->setType(Cache::class) 69 | ->setFactory(DoctrineProvider::class . '::wrap', [ 70 | new Statement($adapterDefinition), 71 | ]); 72 | } else { 73 | $adapterDefinition = $builder->addDefinition($this->prefix('adapter')) 74 | ->setFactory($config->adapter) 75 | ->setType(AdapterInterface::class); 76 | 77 | $builder->addDefinition($this->prefix('driver')) 78 | ->setType(Cache::class) 79 | ->setFactory(DoctrineProvider::class . '::wrap', [ 80 | new Statement($adapterDefinition), 81 | ]); 82 | } 83 | } 84 | 85 | } 86 | --------------------------------------------------------------------------------