From 84496795d767d573332ca23fc5d849e2423c8efc Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Sat, 26 Aug 2023 16:48:33 +0800 Subject: [PATCH] Switch to permanent caching and remove ttl option --- composer.json | 3 +- composer.lock | 623 ++++++++++++++++++++--------------- src/Command/BuildCommand.php | 1 - src/Command/CommandBase.php | 3 +- src/Site.php | 30 +- src/Twig.php | 109 +++--- 6 files changed, 434 insertions(+), 335 deletions(-) diff --git a/composer.json b/composer.json index 92a2aa8..9e6ba65 100644 --- a/composer.json +++ b/composer.json @@ -9,18 +9,17 @@ "addwiki/mediawiki-api-base": "^2.7", "endroid/qr-code": "^4.1", "getdkan/lunr.php": "^1.0", - "kevinrob/guzzle-cache-middleware": "^3.3", "league/flysystem": "^1.0", "myclabs/php-enum": "^1.5", "samwilson/commonmark-latex": "^0.3", "samwilson/commonmark-shortcodes": "^0.3", "samwilson/phpflickr": "^4.13", + "symfony/cache": "^5.0", "symfony/console": "^5.0", "symfony/filesystem": "^5.4", "symfony/finder": "^5.0", "symfony/process": "^5.0", "symfony/yaml": "^5.0", - "tedivm/stash": "^0.16", "twig/intl-extra": "^3.3", "twig/twig": "^3.0" }, diff --git a/composer.lock b/composer.lock index 5a016fb..c3647aa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b75cbb989890df981c864de564acba08", + "content-hash": "b8152dbd73b051c41c6dedadff8d49f7", "packages": [ { "name": "addwiki/mediawiki-api-base", @@ -623,16 +623,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.5.0", + "version": "2.6.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "b635f279edd83fc275f822a1188157ffea568ff6" + "reference": "8bd7c33a0734ae1c5d074360512beb716bef3f77" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/b635f279edd83fc275f822a1188157ffea568ff6", - "reference": "b635f279edd83fc275f822a1188157ffea568ff6", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/8bd7c33a0734ae1c5d074360512beb716bef3f77", + "reference": "8bd7c33a0734ae1c5d074360512beb716bef3f77", "shasum": "" }, "require": { @@ -719,7 +719,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.5.0" + "source": "https://github.com/guzzle/psr7/tree/2.6.0" }, "funding": [ { @@ -735,90 +735,7 @@ "type": "tidelift" } ], - "time": "2023-04-17T16:11:26+00:00" - }, - { - "name": "kevinrob/guzzle-cache-middleware", - "version": "v3.5.0", - "source": { - "type": "git", - "url": "https://github.com/Kevinrob/guzzle-cache-middleware.git", - "reference": "c699f4623a7be6c92468876a1b2404d499a4f22f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Kevinrob/guzzle-cache-middleware/zipball/c699f4623a7be6c92468876a1b2404d499a4f22f", - "reference": "c699f4623a7be6c92468876a1b2404d499a4f22f", - "shasum": "" - }, - "require": { - "guzzlehttp/guzzle": "^6.0 || ^7.0", - "guzzlehttp/psr7": "^1.7.0 || ^2.0.0", - "php": ">=5.5.0" - }, - "require-dev": { - "cache/array-adapter": "^0.4 || ^0.5 || ^1.0", - "cache/simple-cache-bridge": "^0.1 || ^1.0", - "doctrine/cache": "^1.0", - "illuminate/cache": "^5.0", - "league/flysystem": "^1.0", - "phpunit/phpunit": "^4.8.36 || ^5.0", - "psr/cache": "^1.0", - "symfony/phpunit-bridge": "^4.4 || ^5.0" - }, - "suggest": { - "doctrine/cache": "This library has a lot of ready-to-use cache storage (to be used with Kevinrob\\GuzzleCache\\Storage\\DoctrineCacheStorage).", - "guzzlehttp/guzzle": "For using this library. It was created for Guzzle6 (but you can use it with any PSR-7 HTTP client).", - "laravel/framework": "To be used with Kevinrob\\GuzzleCache\\Storage\\LaravelCacheStorage", - "league/flysystem": "To be used with Kevinrob\\GuzzleCache\\Storage\\FlysystemStorage", - "psr/cache": "To be used with Kevinrob\\GuzzleCache\\Storage\\Psr6CacheStorage", - "psr/simple-cache": "To be used with Kevinrob\\GuzzleCache\\Storage\\Psr16CacheStorage" - }, - "type": "library", - "autoload": { - "psr-4": { - "Kevinrob\\GuzzleCache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kevin Robatel", - "email": "kevinrob2@gmail.com", - "homepage": "https://github.com/Kevinrob" - } - ], - "description": "A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)", - "homepage": "https://github.com/Kevinrob/guzzle-cache-middleware", - "keywords": [ - "Etag", - "Flysystem", - "Guzzle", - "cache", - "cache-control", - "doctrine", - "expiration", - "guzzle6", - "handler", - "http", - "http 1.1", - "middleware", - "performance", - "php", - "promise", - "psr6", - "psr7", - "rfc7234", - "validation" - ], - "support": { - "issues": "https://github.com/Kevinrob/guzzle-cache-middleware/issues", - "source": "https://github.com/Kevinrob/guzzle-cache-middleware/tree/v3.5.0" - }, - "time": "2022-01-04T16:40:46+00:00" + "time": "2023-08-03T15:06:02+00:00" }, { "name": "league/commonmark", @@ -1104,26 +1021,26 @@ }, { "name": "league/mime-type-detection", - "version": "1.11.0", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/thephpleague/mime-type-detection.git", - "reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd" + "reference": "a6dfb1194a2946fcdc1f38219445234f65b35c96" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/ff6248ea87a9f116e78edd6002e39e5128a0d4dd", - "reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd", + "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/a6dfb1194a2946fcdc1f38219445234f65b35c96", + "reference": "a6dfb1194a2946fcdc1f38219445234f65b35c96", "shasum": "" }, "require": { "ext-fileinfo": "*", - "php": "^7.2 || ^8.0" + "php": "^7.4 || ^8.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.2", "phpstan/phpstan": "^0.12.68", - "phpunit/phpunit": "^8.5.8 || ^9.3" + "phpunit/phpunit": "^8.5.8 || ^9.3 || ^10.0" }, "type": "library", "autoload": { @@ -1144,7 +1061,7 @@ "description": "Mime-type detection for Flysystem", "support": { "issues": "https://github.com/thephpleague/mime-type-detection/issues", - "source": "https://github.com/thephpleague/mime-type-detection/tree/1.11.0" + "source": "https://github.com/thephpleague/mime-type-detection/tree/1.13.0" }, "funding": [ { @@ -1156,7 +1073,7 @@ "type": "tidelift" } ], - "time": "2022-04-17T13:12:02+00:00" + "time": "2023-08-05T12:09:49+00:00" }, { "name": "markfullmer/porter2", @@ -1266,21 +1183,21 @@ }, { "name": "nette/schema", - "version": "v1.2.3", + "version": "v1.2.4", "source": { "type": "git", "url": "https://github.com/nette/schema.git", - "reference": "abbdbb70e0245d5f3bf77874cea1dfb0c930d06f" + "reference": "c9ff517a53903b3d4e29ec547fb20feecb05b8ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/schema/zipball/abbdbb70e0245d5f3bf77874cea1dfb0c930d06f", - "reference": "abbdbb70e0245d5f3bf77874cea1dfb0c930d06f", + "url": "https://api.github.com/repos/nette/schema/zipball/c9ff517a53903b3d4e29ec547fb20feecb05b8ab", + "reference": "c9ff517a53903b3d4e29ec547fb20feecb05b8ab", "shasum": "" }, "require": { "nette/utils": "^2.5.7 || ^3.1.5 || ^4.0", - "php": ">=7.1 <8.3" + "php": "7.1 - 8.3" }, "require-dev": { "nette/tester": "^2.3 || ^2.4", @@ -1322,26 +1239,26 @@ ], "support": { "issues": "https://github.com/nette/schema/issues", - "source": "https://github.com/nette/schema/tree/v1.2.3" + "source": "https://github.com/nette/schema/tree/v1.2.4" }, - "time": "2022-10-13T01:24:26+00:00" + "time": "2023-08-05T18:56:25+00:00" }, { "name": "nette/utils", - "version": "v3.2.9", + "version": "v3.2.10", "source": { "type": "git", "url": "https://github.com/nette/utils.git", - "reference": "c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c" + "reference": "a4175c62652f2300c8017fb7e640f9ccb11648d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/utils/zipball/c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c", - "reference": "c91bac3470c34b2ecd5400f6e6fdf0b64a836a5c", + "url": "https://api.github.com/repos/nette/utils/zipball/a4175c62652f2300c8017fb7e640f9ccb11648d2", + "reference": "a4175c62652f2300c8017fb7e640f9ccb11648d2", "shasum": "" }, "require": { - "php": ">=7.2 <8.3" + "php": ">=7.2 <8.4" }, "conflict": { "nette/di": "<3.0.6" @@ -1408,9 +1325,9 @@ ], "support": { "issues": "https://github.com/nette/utils/issues", - "source": "https://github.com/nette/utils/tree/v3.2.9" + "source": "https://github.com/nette/utils/tree/v3.2.10" }, - "time": "2023-01-18T03:26:20+00:00" + "time": "2023-07-30T15:38:18+00:00" }, { "name": "psr/cache", @@ -1950,18 +1867,194 @@ }, "time": "2022-07-05T06:07:52+00:00" }, + { + "name": "symfony/cache", + "version": "v5.4.25", + "source": { + "type": "git", + "url": "https://github.com/symfony/cache.git", + "reference": "e2013521c0f07473ae69a01fce0af78fc3ec0f23" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/cache/zipball/e2013521c0f07473ae69a01fce0af78fc3ec0f23", + "reference": "e2013521c0f07473ae69a01fce0af78fc3ec0f23", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "psr/cache": "^1.0|^2.0", + "psr/log": "^1.1|^2|^3", + "symfony/cache-contracts": "^1.1.7|^2", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-php73": "^1.9", + "symfony/polyfill-php80": "^1.16", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/var-exporter": "^4.4|^5.0|^6.0" + }, + "conflict": { + "doctrine/dbal": "<2.13.1", + "symfony/dependency-injection": "<4.4", + "symfony/http-kernel": "<4.4", + "symfony/var-dumper": "<4.4" + }, + "provide": { + "psr/cache-implementation": "1.0|2.0", + "psr/simple-cache-implementation": "1.0|2.0", + "symfony/cache-implementation": "1.0|2.0" + }, + "require-dev": { + "cache/integration-tests": "dev-master", + "doctrine/cache": "^1.6|^2.0", + "doctrine/dbal": "^2.13.1|^3.0", + "predis/predis": "^1.1", + "psr/simple-cache": "^1.0|^2.0", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/filesystem": "^4.4|^5.0|^6.0", + "symfony/http-kernel": "^4.4|^5.0|^6.0", + "symfony/messenger": "^4.4|^5.0|^6.0", + "symfony/var-dumper": "^4.4|^5.0|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Cache\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides extended PSR-6, PSR-16 (and tags) implementations", + "homepage": "https://symfony.com", + "keywords": [ + "caching", + "psr6" + ], + "support": { + "source": "https://github.com/symfony/cache/tree/v5.4.25" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-06-22T08:06:06+00:00" + }, + { + "name": "symfony/cache-contracts", + "version": "v2.5.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/cache-contracts.git", + "reference": "64be4a7acb83b6f2bf6de9a02cee6dad41277ebc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/cache-contracts/zipball/64be4a7acb83b6f2bf6de9a02cee6dad41277ebc", + "reference": "64be4a7acb83b6f2bf6de9a02cee6dad41277ebc", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "psr/cache": "^1.0|^2.0|^3.0" + }, + "suggest": { + "symfony/cache-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Cache\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to caching", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/cache-contracts/tree/v2.5.2" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:53:40+00:00" + }, { "name": "symfony/console", - "version": "v5.4.24", + "version": "v5.4.26", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8" + "reference": "b504a3d266ad2bb632f196c0936ef2af5ff6e273" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", - "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", + "url": "https://api.github.com/repos/symfony/console/zipball/b504a3d266ad2bb632f196c0936ef2af5ff6e273", + "reference": "b504a3d266ad2bb632f196c0936ef2af5ff6e273", "shasum": "" }, "require": { @@ -2031,7 +2124,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.24" + "source": "https://github.com/symfony/console/tree/v5.4.26" }, "funding": [ { @@ -2047,7 +2140,7 @@ "type": "tidelift" } ], - "time": "2023-05-26T05:13:16+00:00" + "time": "2023-07-19T20:11:33+00:00" }, { "name": "symfony/deprecation-contracts", @@ -2182,16 +2275,16 @@ }, { "name": "symfony/finder", - "version": "v5.4.21", + "version": "v5.4.27", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "078e9a5e1871fcfe6a5ce421b539344c21afef19" + "reference": "ff4bce3c33451e7ec778070e45bd23f74214cd5d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/078e9a5e1871fcfe6a5ce421b539344c21afef19", - "reference": "078e9a5e1871fcfe6a5ce421b539344c21afef19", + "url": "https://api.github.com/repos/symfony/finder/zipball/ff4bce3c33451e7ec778070e45bd23f74214cd5d", + "reference": "ff4bce3c33451e7ec778070e45bd23f74214cd5d", "shasum": "" }, "require": { @@ -2225,7 +2318,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v5.4.21" + "source": "https://github.com/symfony/finder/tree/v5.4.27" }, "funding": [ { @@ -2241,20 +2334,20 @@ "type": "tidelift" } ], - "time": "2023-02-16T09:33:00+00:00" + "time": "2023-07-31T08:02:31+00:00" }, { "name": "symfony/intl", - "version": "v5.4.25", + "version": "v5.4.26", "source": { "type": "git", "url": "https://github.com/symfony/intl.git", - "reference": "4c4cbf57c9623b55e7d19479488bd93fee68450a" + "reference": "c26c40b64ecdc056810e294ea67ac5b34182cd69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/intl/zipball/4c4cbf57c9623b55e7d19479488bd93fee68450a", - "reference": "4c4cbf57c9623b55e7d19479488bd93fee68450a", + "url": "https://api.github.com/repos/symfony/intl/zipball/c26c40b64ecdc056810e294ea67ac5b34182cd69", + "reference": "c26c40b64ecdc056810e294ea67ac5b34182cd69", "shasum": "" }, "require": { @@ -2263,7 +2356,8 @@ "symfony/polyfill-php80": "^1.16" }, "require-dev": { - "symfony/filesystem": "^4.4|^5.0|^6.0" + "symfony/filesystem": "^4.4|^5.0|^6.0", + "symfony/var-exporter": "^5.4|^6.0" }, "type": "library", "autoload": { @@ -2313,7 +2407,7 @@ "localization" ], "support": { - "source": "https://github.com/symfony/intl/tree/v5.4.25" + "source": "https://github.com/symfony/intl/tree/v5.4.26" }, "funding": [ { @@ -2329,7 +2423,7 @@ "type": "tidelift" } ], - "time": "2023-06-19T09:28:43+00:00" + "time": "2023-07-13T09:02:54+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2825,16 +2919,16 @@ }, { "name": "symfony/process", - "version": "v5.4.24", + "version": "v5.4.26", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "e3c46cc5689c8782944274bb30702106ecbe3b64" + "reference": "1a44dc377ec86a50fab40d066cd061e28a6b482f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/e3c46cc5689c8782944274bb30702106ecbe3b64", - "reference": "e3c46cc5689c8782944274bb30702106ecbe3b64", + "url": "https://api.github.com/repos/symfony/process/zipball/1a44dc377ec86a50fab40d066cd061e28a6b482f", + "reference": "1a44dc377ec86a50fab40d066cd061e28a6b482f", "shasum": "" }, "require": { @@ -2867,7 +2961,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v5.4.24" + "source": "https://github.com/symfony/process/tree/v5.4.26" }, "funding": [ { @@ -2883,7 +2977,7 @@ "type": "tidelift" } ], - "time": "2023-05-17T11:26:05+00:00" + "time": "2023-07-12T15:44:31+00:00" }, { "name": "symfony/service-contracts", @@ -2970,16 +3064,16 @@ }, { "name": "symfony/string", - "version": "v5.4.22", + "version": "v5.4.26", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "8036a4c76c0dd29e60b6a7cafcacc50cf088ea62" + "reference": "1181fe9270e373537475e826873b5867b863883c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/8036a4c76c0dd29e60b6a7cafcacc50cf088ea62", - "reference": "8036a4c76c0dd29e60b6a7cafcacc50cf088ea62", + "url": "https://api.github.com/repos/symfony/string/zipball/1181fe9270e373537475e826873b5867b863883c", + "reference": "1181fe9270e373537475e826873b5867b863883c", "shasum": "" }, "require": { @@ -3036,7 +3130,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.22" + "source": "https://github.com/symfony/string/tree/v5.4.26" }, "funding": [ { @@ -3052,43 +3146,33 @@ "type": "tidelift" } ], - "time": "2023-03-14T06:11:53+00:00" + "time": "2023-06-28T12:46:07+00:00" }, { - "name": "symfony/yaml", - "version": "v5.4.23", + "name": "symfony/var-exporter", + "version": "v5.4.26", "source": { "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "4cd2e3ea301aadd76a4172756296fe552fb45b0b" + "url": "https://github.com/symfony/var-exporter.git", + "reference": "11401fe94f960249b3c63a488c63ba73091c1e4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/4cd2e3ea301aadd76a4172756296fe552fb45b0b", - "reference": "4cd2e3ea301aadd76a4172756296fe552fb45b0b", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/11401fe94f960249b3c63a488c63ba73091c1e4a", + "reference": "11401fe94f960249b3c63a488c63ba73091c1e4a", "shasum": "" }, "require": { "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1|^3", - "symfony/polyfill-ctype": "^1.8" - }, - "conflict": { - "symfony/console": "<5.3" + "symfony/polyfill-php80": "^1.16" }, "require-dev": { - "symfony/console": "^5.3|^6.0" - }, - "suggest": { - "symfony/console": "For validating YAML files using the lint command" + "symfony/var-dumper": "^4.4.9|^5.0.9|^6.0" }, - "bin": [ - "Resources/bin/yaml-lint" - ], "type": "library", "autoload": { "psr-4": { - "Symfony\\Component\\Yaml\\": "" + "Symfony\\Component\\VarExporter\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -3100,18 +3184,26 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "name": "Nicolas Grekas", + "email": "p@tchwork.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], - "description": "Loads and dumps YAML files", + "description": "Allows exporting any serializable PHP data structure to plain PHP code", "homepage": "https://symfony.com", + "keywords": [ + "clone", + "construct", + "export", + "hydrate", + "instantiate", + "serialize" + ], "support": { - "source": "https://github.com/symfony/yaml/tree/v5.4.23" + "source": "https://github.com/symfony/var-exporter/tree/v5.4.26" }, "funding": [ { @@ -3127,81 +3219,86 @@ "type": "tidelift" } ], - "time": "2023-04-23T19:33:36+00:00" + "time": "2023-07-20T07:21:16+00:00" }, { - "name": "tedivm/stash", - "version": "v0.16.0", + "name": "symfony/yaml", + "version": "v5.4.23", "source": { "type": "git", - "url": "https://github.com/tedious/Stash.git", - "reference": "7d42f58e4f395397d7c76d4eff55eb56aacadc34" + "url": "https://github.com/symfony/yaml.git", + "reference": "4cd2e3ea301aadd76a4172756296fe552fb45b0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tedious/Stash/zipball/7d42f58e4f395397d7c76d4eff55eb56aacadc34", - "reference": "7d42f58e4f395397d7c76d4eff55eb56aacadc34", + "url": "https://api.github.com/repos/symfony/yaml/zipball/4cd2e3ea301aadd76a4172756296fe552fb45b0b", + "reference": "4cd2e3ea301aadd76a4172756296fe552fb45b0b", "shasum": "" }, "require": { - "php": ">7.0", - "psr/cache": "~1.0" + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-ctype": "^1.8" }, - "provide": { - "psr/cache-implementation": "1.0.0" + "conflict": { + "symfony/console": "<5.3" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.8", - "phpunit/phpunit": "^6", - "satooshi/php-coveralls": "1.0.*" + "symfony/console": "^5.3|^6.0" }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "bin": [ + "Resources/bin/yaml-lint" + ], "type": "library", "autoload": { "psr-4": { - "Stash\\": "src/Stash/" - } + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Robert Hafner", - "email": "tedivm@tedivm.com" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, { - "name": "Josh Hall-Bachner", - "email": "charlequin@gmail.com" + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "The place to keep your cache.", - "homepage": "http://github.com/tedious/Stash", - "keywords": [ - "apc", - "cache", - "caching", - "memcached", - "psr-6", - "psr6", - "redis", - "sessions" - ], + "description": "Loads and dumps YAML files", + "homepage": "https://symfony.com", "support": { - "issues": "https://github.com/tedious/Stash/issues", - "source": "https://github.com/tedious/Stash/tree/v0.16.0" + "source": "https://github.com/symfony/yaml/tree/v5.4.23" }, "funding": [ { - "url": "https://tidelift.com/funding/github/packagist/tedivm/stash", + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", "type": "tidelift" } ], - "time": "2021-01-18T04:06:48+00:00" + "time": "2023-04-23T19:33:36+00:00" }, { "name": "twig/intl-extra", - "version": "v3.6.0", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/twigphp/intl-extra.git", @@ -3249,7 +3346,7 @@ "twig" ], "support": { - "source": "https://github.com/twigphp/intl-extra/tree/v3.6.0" + "source": "https://github.com/twigphp/intl-extra/tree/v3.7.0" }, "funding": [ { @@ -3265,16 +3362,16 @@ }, { "name": "twig/twig", - "version": "v3.6.1", + "version": "v3.7.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd" + "reference": "5cf942bbab3df42afa918caeba947f1b690af64b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", - "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/5cf942bbab3df42afa918caeba947f1b690af64b", + "reference": "5cf942bbab3df42afa918caeba947f1b690af64b", "shasum": "" }, "require": { @@ -3320,7 +3417,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.6.1" + "source": "https://github.com/twigphp/Twig/tree/v3.7.0" }, "funding": [ { @@ -3332,7 +3429,7 @@ "type": "tidelift" } ], - "time": "2023-06-08T12:52:13+00:00" + "time": "2023-07-26T07:16:09+00:00" } ], "packages-dev": [ @@ -4349,16 +4446,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.16.0", + "version": "v4.17.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17" + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", "shasum": "" }, "require": { @@ -4399,9 +4496,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" }, - "time": "2023-06-25T14:52:30+00:00" + "time": "2023-08-13T19:53:39+00:00" }, { "name": "phan/phan", @@ -4863,16 +4960,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.7.2", + "version": "1.7.3", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "b2fe4d22a5426f38e014855322200b97b5362c0d" + "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b2fe4d22a5426f38e014855322200b97b5362c0d", - "reference": "b2fe4d22a5426f38e014855322200b97b5362c0d", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", + "reference": "3219c6ee25c9ea71e3d9bbaf39c67c9ebd499419", "shasum": "" }, "require": { @@ -4915,22 +5012,22 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.2" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.3" }, - "time": "2023-05-30T18:13:47+00:00" + "time": "2023-08-12T11:01:26+00:00" }, { "name": "phpstan/phpdoc-parser", - "version": "1.22.0", + "version": "1.23.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c" + "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", - "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/846ae76eef31c6d7790fac9bc399ecee45160b26", + "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26", "shasum": "" }, "require": { @@ -4962,22 +5059,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.1" }, - "time": "2023-06-01T12:35:21+00:00" + "time": "2023-08-03T16:32:59+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.26", + "version": "9.2.27", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1" + "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", - "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/b0a88255cb70d52653d80c890bd7f38740ea50d1", + "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1", "shasum": "" }, "require": { @@ -5033,7 +5130,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.26" + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.27" }, "funding": [ { @@ -5041,7 +5139,7 @@ "type": "github" } ], - "time": "2023-03-06T12:58:08+00:00" + "time": "2023-07-26T13:44:30+00:00" }, { "name": "phpunit/php-file-iterator", @@ -5286,16 +5384,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.9", + "version": "9.6.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a9aceaf20a682aeacf28d582654a1670d8826778" + "reference": "810500e92855eba8a7a5319ae913be2da6f957b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a9aceaf20a682aeacf28d582654a1670d8826778", - "reference": "a9aceaf20a682aeacf28d582654a1670d8826778", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/810500e92855eba8a7a5319ae913be2da6f957b0", + "reference": "810500e92855eba8a7a5319ae913be2da6f957b0", "shasum": "" }, "require": { @@ -5369,7 +5467,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.9" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.11" }, "funding": [ { @@ -5385,7 +5483,7 @@ "type": "tidelift" } ], - "time": "2023-06-11T06:13:56+00:00" + "time": "2023-08-19T07:10:56+00:00" }, { "name": "roslov/psr12ext", @@ -6000,16 +6098,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bde739e7565280bda77be70044ac1047bc007e34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", "shasum": "" }, "require": { @@ -6052,7 +6150,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" }, "funding": [ { @@ -6060,7 +6158,7 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2023-08-02T09:26:13+00:00" }, { "name": "sebastian/lines-of-code", @@ -6460,32 +6558,32 @@ }, { "name": "slevomat/coding-standard", - "version": "8.13.1", + "version": "8.13.4", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "a13c15e20f2d307a1ca8dec5313ec462a4466470" + "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/a13c15e20f2d307a1ca8dec5313ec462a4466470", - "reference": "a13c15e20f2d307a1ca8dec5313ec462a4466470", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/4b2af2fb17773656d02fbfb5d18024ebd19fe322", + "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.22.0", + "phpstan/phpdoc-parser": "^1.23.0", "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { "phing/phing": "2.17.4", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.10.21", + "phpstan/phpstan": "1.10.26", "phpstan/phpstan-deprecation-rules": "1.1.3", "phpstan/phpstan-phpunit": "1.3.13", "phpstan/phpstan-strict-rules": "1.5.1", - "phpunit/phpunit": "7.5.20|8.5.21|9.6.8|10.2.2" + "phpunit/phpunit": "7.5.20|8.5.21|9.6.8|10.2.6" }, "type": "phpcodesniffer-standard", "extra": { @@ -6509,7 +6607,7 @@ ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/8.13.1" + "source": "https://github.com/slevomat/coding-standard/tree/8.13.4" }, "funding": [ { @@ -6521,7 +6619,7 @@ "type": "tidelift" } ], - "time": "2023-06-25T12:52:34+00:00" + "time": "2023-07-25T10:28:55+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -6582,16 +6680,16 @@ }, { "name": "symfony/var-dumper", - "version": "v5.4.25", + "version": "v5.4.26", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "82269f73c0f0f9859ab9b6900eebacbe54954ede" + "reference": "e706c99b4a6f4d9383b52b80dd8c74880501e314" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/82269f73c0f0f9859ab9b6900eebacbe54954ede", - "reference": "82269f73c0f0f9859ab9b6900eebacbe54954ede", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/e706c99b4a6f4d9383b52b80dd8c74880501e314", + "reference": "e706c99b4a6f4d9383b52b80dd8c74880501e314", "shasum": "" }, "require": { @@ -6605,6 +6703,7 @@ "require-dev": { "ext-iconv": "*", "symfony/console": "^4.4|^5.0|^6.0", + "symfony/http-kernel": "^4.4|^5.0|^6.0", "symfony/process": "^4.4|^5.0|^6.0", "symfony/uid": "^5.1|^6.0", "twig/twig": "^2.13|^3.0.4" @@ -6650,7 +6749,7 @@ "dump" ], "support": { - "source": "https://github.com/symfony/var-dumper/tree/v5.4.25" + "source": "https://github.com/symfony/var-dumper/tree/v5.4.26" }, "funding": [ { @@ -6666,7 +6765,7 @@ "type": "tidelift" } ], - "time": "2023-06-20T20:56:26+00:00" + "time": "2023-07-13T07:32:46+00:00" }, { "name": "theseer/tokenizer", diff --git a/src/Command/BuildCommand.php b/src/Command/BuildCommand.php index edc5abf..46e3f0b 100644 --- a/src/Command/BuildCommand.php +++ b/src/Command/BuildCommand.php @@ -26,7 +26,6 @@ protected function configure(): void $this->setName('build'); $this->setDescription('Build a website.'); $this->addOption('lunr', 'l', InputOption::VALUE_NONE, 'Build Lunr index?'); - $this->addOption('ttl', 't', InputOption::VALUE_REQUIRED, 'Set the cache TTL in seconds.', (string) (60 * 5)); $this->addOption( 'page', 'p', diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index ea0b851..da5650a 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -39,7 +39,6 @@ protected function getSite(InputInterface $input): ?Site self::$io->error('Directory not found: ' . $input->getArgument('dir')); return null; } - $ttl = $input->hasOption('ttl') ? (int) $input->getOption('ttl') : null; - return new Site($dir, $ttl); + return new Site($dir); } } diff --git a/src/Site.php b/src/Site.php index 1fce726..b878434 100644 --- a/src/Site.php +++ b/src/Site.php @@ -5,12 +5,6 @@ namespace App; use Exception; -use GuzzleHttp\Client; -use GuzzleHttp\HandlerStack; -use Kevinrob\GuzzleCache\CacheMiddleware; -use Kevinrob\GuzzleCache\Storage\FlysystemStorage; -use Kevinrob\GuzzleCache\Strategy\GreedyCacheStrategy; -use League\Flysystem\Adapter\Local; use Mediawiki\Api\MediawikiApi; use stdClass; use Symfony\Component\Finder\Finder; @@ -27,13 +21,9 @@ final class Site /** @var Page[] */ protected $pages; - /** @var int Cache TTL in seconds. */ - protected $ttl; - - public function __construct(string $dir, ?int $cacheTtl = null) + public function __construct(string $dir) { $this->dir = rtrim($dir, '/'); - $this->ttl = $cacheTtl ?? 60; } /** @@ -46,11 +36,6 @@ public function getDir(): string return $this->dir; } - public function getTtl(): int - { - return $this->ttl; - } - /** * @return Page[] Array of Pages indexed by page ID. */ @@ -157,17 +142,6 @@ public function getLang(): string */ public function getMediawikiApi(string $apiUrl): MediawikiApi { - $stack = HandlerStack::create(); - $cacheDir = $this->getDir() . '/cache/mediawikiapi/' . preg_replace('/[^a-z0-9]/', '', $apiUrl); - $stack->push( - new CacheMiddleware( - new GreedyCacheStrategy( - new FlysystemStorage(new Local($cacheDir)), - $this->ttl - ) - ), - 'mediawiki-api-cache' - ); - return new MediawikiApi($apiUrl, new Client(['handler' => $stack])); + return new MediawikiApi($apiUrl); } } diff --git a/src/Twig.php b/src/Twig.php index 039c0fa..0c43e75 100644 --- a/src/Twig.php +++ b/src/Twig.php @@ -20,14 +20,14 @@ use League\CommonMark\Extension\Footnote\FootnoteExtension; use League\CommonMark\MarkdownConverter; use Mediawiki\Api\FluentRequest; +use Psr\Cache\CacheItemPoolInterface; use Samwilson\CommonMarkLatex\LatexRendererExtension; use Samwilson\CommonMarkShortcodes\Shortcode; use Samwilson\CommonMarkShortcodes\ShortcodeExtension; use Samwilson\PhpFlickr\PhotosApi; use Samwilson\PhpFlickr\PhpFlickr; -use Stash\Driver\FileSystem; -use Stash\Pool; -use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; +use Symfony\Component\Cache\Adapter\FilesystemAdapter; +use Symfony\Component\Filesystem\Filesystem; use Throwable; use Twig\Environment; use Twig\Extension\AbstractExtension; @@ -107,7 +107,7 @@ public function filterMarkdownToLatex(string $input): string $environment->addExtension(new LatexRendererExtension()); $environment->addExtension(new AutolinkExtension()); $environment->addEventListener(DocumentPreRenderEvent::class, function (DocumentPreRenderEvent $event): void { - $filesystem = new SymfonyFilesystem(); + $filesystem = new Filesystem(); foreach ($event->getDocument()->iterator() as $node) { if (!$node instanceof Image) { continue; @@ -166,31 +166,26 @@ public function functionInstanceof($a, string $b): bool */ public function functionTexUrl(string $url): string { - CommandBase::writeln('TeX file download: ' . basename($url)); - // Set up file and directory names. $filename = md5($url) . '.' . pathinfo($url, PATHINFO_EXTENSION); $outputFilepath = $this->site->getDir() . '/cache/tex/_urls/' . $filename; - // Check cache and return if the file exists and was modified within the permitted time-frame. - $minCacheTime = time() - $this->site->getTtl(); - if (file_exists($outputFilepath) && filemtime($outputFilepath) >= $minCacheTime) { - return $outputFilepath; - } - - Util::mkdir(dirname($outputFilepath)); + if (!file_exists($outputFilepath)) { + CommandBase::writeln('TeX file download: ' . basename($url)); + Util::mkdir(dirname($outputFilepath)); - // Download to a local directory if it's not already there. - if (!file_exists($outputFilepath) || !filesize($outputFilepath)) { - try { - (new Client())->get($url, [RequestOptions::SINK => fopen($outputFilepath, 'w+')]); - } catch (Throwable $exception) { - throw new Exception("Unable to download: $url"); + // Download to a local directory if it's not already there. + if (!file_exists($outputFilepath) || !filesize($outputFilepath)) { + try { + (new Client())->get($url, [RequestOptions::SINK => fopen($outputFilepath, 'w+')]); + } catch (Throwable $exception) { + throw new Exception("Unable to download: $url"); + } } - } - if (!file_exists($outputFilepath) || !filesize($outputFilepath)) { - throw new Exception("Download failed: $url"); + if (!file_exists($outputFilepath) || !filesize($outputFilepath)) { + throw new Exception("Download failed: $url"); + } } // Return the relative path to the downloaded file. @@ -206,6 +201,11 @@ public function functionWikidata(string $wikidataId): array if (isset(self::$data['wikidata'][$wikidataId])) { return self::$data['wikidata'][$wikidataId]; } + $cache = $this->getCachePool('wikidata'); + $cacheItem = $cache->getItem('wikidata' . $wikidataId); + if ($cacheItem->isHit()) { + return $cacheItem->get(); + } $api = $this->site->getMediawikiApi('https://www.wikidata.org/w/api.php'); $request = FluentRequest::factory() ->setAction('wbgetentities') @@ -213,6 +213,8 @@ public function functionWikidata(string $wikidataId): array CommandBase::writeln('Wikidata fetch info: ' . $wikidataId); $result = $api->getRequest($request); self::$data['wikidata'][$wikidataId] = $result['entities'][$wikidataId]; + $cacheItem->set(self::$data['wikidata'][$wikidataId]); + $cache->save($cacheItem); return self::$data['wikidata'][$wikidataId]; } @@ -234,24 +236,32 @@ public function functionFlickr(string $photoId): array } $config = $this->site->getConfig()->flickr; $flickr = new PhpFlickr($config->api_key, $config->api_secret); - $pool = new Pool(new FileSystem(['path' => $this->site->getDir() . '/cache/flickr'])); - $flickr->setCache($pool); - $shortUrl = $flickr->urls()->getShortUrl($photoId); - CommandBase::writeln("Flickr fetch info: $photoId $shortUrl"); - $info = $flickr->photos()->getInfo($photoId); - self::$data['flickr'][$photoId] = [ - 'id' => $info['id'], - 'title' => $info['title'], - 'description' => $info['description'], - 'urls' => [ - 'photopage' => $info['urls']['url'][0]['_content'], - 'short' => $shortUrl, - 'medium_image' => $flickr->urls()->getImageUrl($info, PhotosApi::SIZE_MEDIUM_800), - ], - 'dates' => $info['dates'], - 'owner' => $info['owner'], - 'license' => $flickr->photosLicenses()->getInfo()[$info['license']], - ]; + $cache = $this->getCachePool('flickr'); + $cacheItem = $cache->getItem('flickr' . $photoId); + if ($cacheItem->isHit()) { + self::$data['flickr'][$photoId] = $cacheItem->get(); + } else { + $flickr->setCache($cache); + $shortUrl = $flickr->urls()->getShortUrl($photoId); + CommandBase::writeln("Flickr fetch info: $photoId $shortUrl"); + $info = $flickr->photos()->getInfo($photoId); + self::$data['flickr'][$photoId] = [ + 'id' => $info['id'], + 'title' => $info['title'], + 'description' => $info['description'], + 'urls' => [ + 'photopage' => $info['urls']['url'][0]['_content'], + 'short' => $shortUrl, + 'medium_image' => $flickr->urls()->getImageUrl($info, PhotosApi::SIZE_MEDIUM_800), + ], + 'dates' => $info['dates'], + 'owner' => $info['owner'], + 'license' => $flickr->photosLicenses()->getInfo()[$info['license']], + ]; + $cacheItem->set(self::$data['flickr'][$photoId]); + $cache->save($cacheItem); + } + return self::$data['flickr'][$photoId]; } @@ -263,6 +273,11 @@ public function functionCommons(string $filename): array if (isset(self::$data['commons'][$filename])) { return self::$data['commons'][$filename]; } + $cache = $this->getCachePool('commons'); + $cacheItem = $cache->getItem('commons' . $filename); + if ($cacheItem->isHit()) { + return $cacheItem->get(); + } $api = $this->site->getMediawikiApi('https://commons.wikimedia.org/w/api.php'); $fileInfoResponse = $api->getRequest(FluentRequest::factory() ->setAction('query') @@ -283,6 +298,8 @@ public function functionCommons(string $filename): array ->addParams(['ids' => 'M' . $fileInfo['pageid']])); $mediaInfo = array_shift($mediaInfoResponse['entities']); self::$data['commons'][$filename] = array_merge($fileInfo, $mediaInfo); + $cacheItem->set(self::$data['commons'][$filename]); + $cache->save($cacheItem); return self::$data['commons'][$filename]; } @@ -291,6 +308,11 @@ public function functionWikipedia(string $lang, string $articleTitle): string if (isset(self::$data['wikipedia'][$articleTitle])) { return self::$data['wikipedia'][$articleTitle]; } + $cache = $this->getCachePool('wikipedia'); + $cacheItem = $cache->getItem('wikipedia' . $articleTitle); + if ($cacheItem->isHit()) { + return $cacheItem->get(); + } CommandBase::writeln("Wikipedia fetch extract: $articleTitle"); $url = "https://$lang.wikipedia.org/api/rest_v1/page/summary/" . str_replace(' ', '_', $articleTitle); $json = (new Client())->get($url)->getBody()->getContents(); @@ -299,6 +321,8 @@ public function functionWikipedia(string $lang, string $articleTitle): string throw new Exception("Unable to get extract of Wikipedia article: $articleTitle"); } self::$data['commons'][$articleTitle] = $response['extract_html']; + $cacheItem->set(self::$data['commons'][$articleTitle]); + $cache->save($cacheItem); return self::$data['commons'][$articleTitle]; } @@ -418,4 +442,9 @@ private function getCommonMarkEnvironment(string $format): CommonMarkEnvironment $environment->addExtension(new ShortcodeExtension()); return $environment; } + + private function getCachePool(string $subdir): CacheItemPoolInterface + { + return new FilesystemAdapter($subdir, 0, $this->site->getDir() . '/cache/'); + } }