Skip to content

Commit

Permalink
feat: introduce PSR-6 cache support (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal authored Sep 8, 2022
1 parent e891eff commit 5ca4b29
Show file tree
Hide file tree
Showing 24 changed files with 458 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
working-directory: playground/symfony-${{ matrix.config.PLAYGROUND_VERSION }}

- name: Run PHPStan
run: symfony php vendor/bin/phpstan analyze --configuration ${{ matrix.config.STABILITY == 'dev' && 'phpstan.dev.neon || 'phpstan.neon }}
run: symfony php vendor/bin/phpstan analyze

- name: Run PHPUnit
run: symfony php vendor/bin/phpunit
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,35 @@ The CKFinder bundle provides two extra options:
- `authenticationClass` – the name of the CKFinder authentication service class (defaults to `CKSource\Bundle\CKFinderBundle\Authentication\Authentication`)
- `connectorClass` – the name of the CKFinder connector service class (defaults to `CKSource\CKFinder\CKFinder`)

### Using the PSR-6 Cache

In order to improve performances, especially if you use an external backend (like AWS S3), you can use the PSR-6 cache.

1. You must configure a caching pool in Symfony:
```yaml
# config/packages/cache.yaml
framework:
cache:
pools:
cache.ckfinder:
adapter: cache.adapter.filesystem # or "cache.adapter.redis", if your app lives on multiple servers
```
2. Then you must configure the CKFinder bundle to use it:
```yaml
# config/packages/ckfinder.yaml
ckfinder:
connector:
backends:
my_backend:
# ...
cache:
type: 'psr6'
args:
pool: 'cache.ckfinder' # the name of the pool you configured in step 1
key: 'ckfinder' # optional
```

## Usage

The bundle code contains a few usage examples that you may find useful. To enable them uncomment the `ckfinder_examples`
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"require": {
"php": ">=8.0",
"ext-zip": "*",
"psr/cache": "^2.0 || ^3.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/framework-bundle": "^5.4 || ^6.0",
"symfony/form": "^5.4 || ^6.0",
"symfony/finder": "^5.4 || ^6.0",
Expand All @@ -36,7 +38,7 @@
"symplify/easy-coding-standard": "^10.1",
"symfony/yaml": "^5.4 || ^6.0",
"rector/rector": "^0.12.17",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"aws/aws-sdk-php": "^3.222"
Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$item of method Psr\\\\Cache\\\\CacheItemPoolInterface\\:\\:save\\(\\) expects Psr\\\\Cache\\\\CacheItemInterface, _CKFinder_Vendor_Prefix\\\\Psr\\\\Cache\\\\CacheItemInterface\\|Psr\\\\Cache\\\\CacheItemInterface given\\.$#"
count: 1
path: src/Cache/Psr6/CacheItemPoolCompatibilityBridge.php

-
message: "#^Parameter \\#1 \\$item of method Psr\\\\Cache\\\\CacheItemPoolInterface\\:\\:saveDeferred\\(\\) expects Psr\\\\Cache\\\\CacheItemInterface, _CKFinder_Vendor_Prefix\\\\Psr\\\\Cache\\\\CacheItemInterface\\|Psr\\\\Cache\\\\CacheItemInterface given\\.$#"
count: 1
path: src/Cache/Psr6/CacheItemPoolCompatibilityBridge.php

-
message: "#^Call to an undefined method object\\:\\:createBuilder\\(\\)\\.$#"
count: 1
Expand Down
5 changes: 0 additions & 5 deletions phpstan.dev.neon

This file was deleted.

1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ includes:

parameters:
level: max
reportUnmatchedIgnoredErrors: false

paths:
- src
Expand Down
2 changes: 1 addition & 1 deletion scoped-dependencies/build/.scoped/vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
exit(1);
}
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit5bac73d37c6d5769fef37a24e3f8f219::getLoader();
return ComposerAutoloaderInit64a95ceb6068dc507cbdf34013b4601c::getLoader();
2 changes: 1 addition & 1 deletion scoped-dependencies/build/.scoped/vendor/bin/jp.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function url_stat($path, $flags)
}
}
}
if (\function_exists('stream_wrapper_register') && \stream_wrapper_register('phpvfscomposer', '_CKFinder_Vendor_Prefix\\Composer\\BinProxyWrapper')) {
if (\function_exists('stream_get_wrappers') && \in_array('phpvfscomposer', \stream_get_wrappers(), \true) || \function_exists('stream_wrapper_register') && \stream_wrapper_register('phpvfscomposer', '_CKFinder_Vendor_Prefix\\Composer\\BinProxyWrapper')) {
include "phpvfscomposer://" . __DIR__ . '/..' . '/mtdowling/jmespath.php/bin/jp.php';
exit(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InstalledVersions
{
/**
* @var mixed[]|null
* @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
*/
private static $installed;
/**
Expand All @@ -35,7 +35,7 @@ class InstalledVersions
private static $canGetVendors;
/**
* @var array[]
* @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
* @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
private static $installedByVendor = array();
/**
Expand Down Expand Up @@ -209,7 +209,7 @@ public static function getInstallPath($packageName)
}
/**
* @return array
* @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
* @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
*/
public static function getRootPackage()
{
Expand All @@ -221,7 +221,7 @@ public static function getRootPackage()
*
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
* @return array[]
* @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
* @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
*/
public static function getRawData()
{
Expand All @@ -241,7 +241,7 @@ public static function getRawData()
* Returns the raw data of all installed.php which are currently loaded for custom implementations
*
* @return array[]
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
public static function getAllRawData()
{
Expand All @@ -263,7 +263,7 @@ public static function getAllRawData()
* @param array[] $data A vendor/composer/installed.php data set
* @return void
*
* @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
* @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
*/
public static function reload($data)
{
Expand All @@ -272,7 +272,7 @@ public static function reload($data)
}
/**
* @return array[]
* @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
private static function getInstalled()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace _CKFinder_Vendor_Prefix;

// autoload_real.php @generated by Composer
class ComposerAutoloaderInit5bac73d37c6d5769fef37a24e3f8f219
class ComposerAutoloaderInit64a95ceb6068dc507cbdf34013b4601c
{
private static $loader;
public static function loadClassLoader($class)
Expand All @@ -21,28 +21,28 @@ public static function getLoader()
return self::$loader;
}
require __DIR__ . '/platform_check.php';
\spl_autoload_register(array('_CKFinder_Vendor_Prefix\\ComposerAutoloaderInit5bac73d37c6d5769fef37a24e3f8f219', 'loadClassLoader'), \true, \true);
\spl_autoload_register(array('_CKFinder_Vendor_Prefix\\ComposerAutoloaderInit64a95ceb6068dc507cbdf34013b4601c', 'loadClassLoader'), \true, \true);
self::$loader = $loader = new \_CKFinder_Vendor_Prefix\Composer\Autoload\ClassLoader(\dirname(__DIR__));
\spl_autoload_unregister(array('ComposerAutoloaderInit5bac73d37c6d5769fef37a24e3f8f219', 'loadClassLoader'));
\spl_autoload_unregister(array('ComposerAutoloaderInit64a95ceb6068dc507cbdf34013b4601c', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
\call_user_func(\_CKFinder_Vendor_Prefix\Composer\Autoload\ComposerStaticInit5bac73d37c6d5769fef37a24e3f8f219::getInitializer($loader));
\call_user_func(\_CKFinder_Vendor_Prefix\Composer\Autoload\ComposerStaticInit64a95ceb6068dc507cbdf34013b4601c::getInitializer($loader));
$loader->setClassMapAuthoritative(\true);
$loader->register(\true);
$includeFiles = \_CKFinder_Vendor_Prefix\Composer\Autoload\ComposerStaticInit5bac73d37c6d5769fef37a24e3f8f219::$files;
$includeFiles = \_CKFinder_Vendor_Prefix\Composer\Autoload\ComposerStaticInit64a95ceb6068dc507cbdf34013b4601c::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire5bac73d37c6d5769fef37a24e3f8f219($fileIdentifier, $file);
composerRequire64a95ceb6068dc507cbdf34013b4601c($fileIdentifier, $file);
}
return $loader;
}
}
// autoload_real.php @generated by Composer
\class_alias('_CKFinder_Vendor_Prefix\\ComposerAutoloaderInit5bac73d37c6d5769fef37a24e3f8f219', 'ComposerAutoloaderInit5bac73d37c6d5769fef37a24e3f8f219', \false);
\class_alias('_CKFinder_Vendor_Prefix\\ComposerAutoloaderInit64a95ceb6068dc507cbdf34013b4601c', 'ComposerAutoloaderInit64a95ceb6068dc507cbdf34013b4601c', \false);
/**
* @param string $fileIdentifier
* @param string $file
* @return void
*/
function composerRequire5bac73d37c6d5769fef37a24e3f8f219($fileIdentifier, $file)
function composerRequire64a95ceb6068dc507cbdf34013b4601c($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = \true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// autoload_static.php @generated by Composer
namespace _CKFinder_Vendor_Prefix\Composer\Autoload;

class ComposerStaticInit5bac73d37c6d5769fef37a24e3f8f219
class ComposerStaticInit64a95ceb6068dc507cbdf34013b4601c
{
public static $files = array('7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php', 'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php', '6e3fae29631ef280660b3cdad06f25a8' => __DIR__ . '/..' . '/symfony/deprecation-contracts/function.php', '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', '37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php', 'b067bc7112e384b61c701452d53a14a8' => __DIR__ . '/..' . '/mtdowling/jmespath.php/src/JmesPath.php', '8a9dc1de0ca7e01f3e08231539562f61' => __DIR__ . '/..' . '/aws/aws-sdk-php/src/functions.php');
public static $prefixLengthsPsr4 = array('S' => array('Symfony\\Polyfill\\Mbstring\\' => 26), 'P' => array('Psr\\Http\\Message\\' => 17, 'Psr\\Http\\Client\\' => 16, 'Psr\\Cache\\' => 10), 'L' => array('League\\MimeTypeDetection\\' => 25, 'League\\Flysystem\\Cached\\' => 24, 'League\\Flysystem\\AwsS3v3\\' => 25, 'League\\Flysystem\\' => 17), 'J' => array('JmesPath\\' => 9), 'G' => array('GuzzleHttp\\Psr7\\' => 16, 'GuzzleHttp\\Promise\\' => 19, 'GuzzleHttp\\' => 11), 'A' => array('Aws\\' => 4));
Expand All @@ -12,9 +12,9 @@ class ComposerStaticInit5bac73d37c6d5769fef37a24e3f8f219
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit5bac73d37c6d5769fef37a24e3f8f219::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit5bac73d37c6d5769fef37a24e3f8f219::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit5bac73d37c6d5769fef37a24e3f8f219::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit64a95ceb6068dc507cbdf34013b4601c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit64a95ceb6068dc507cbdf34013b4601c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit64a95ceb6068dc507cbdf34013b4601c::$classMap;
}, null, ClassLoader::class);
}
}
Loading

0 comments on commit 5ca4b29

Please sign in to comment.