Fixed regression in storage filename matching

This commit is contained in:
Matias Griese
2019-10-11 10:39:23 +03:00
parent f85c94b403
commit 90e55ead29
7 changed files with 22 additions and 24 deletions

View File

@@ -37,10 +37,10 @@ config:
templates:
collection:
paths:
- 'flex/{TYPE}/collection/{LAYOUT}{.EXT}'
- 'flex/{TYPE}/collection/{LAYOUT}{EXT}'
object:
paths:
- 'flex/{TYPE}/object/{LAYOUT}{.EXT}'
- 'flex/{TYPE}/object/{LAYOUT}{EXT}'
defaults:
type: accounts
layout: default
@@ -55,7 +55,7 @@ config:
formatter:
class: 'Grav\Framework\File\Formatter\YamlFormatter'
folder: 'account://'
pattern: '{FOLDER}/{KEY}{.EXT}'
pattern: '{FOLDER}/{KEY}{EXT}'
key: storage_key
indexed: true
search:

View File

@@ -95,10 +95,10 @@ config:
templates:
collection:
paths:
- 'flex/{TYPE}/collection/{LAYOUT}{.EXT}'
- 'flex/{TYPE}/collection/{LAYOUT}{EXT}'
object:
paths:
- 'flex/{TYPE}/object/{LAYOUT}{.EXT}'
- 'flex/{TYPE}/object/{LAYOUT}{EXT}'
defaults:
type: pages
layout: default

View File

@@ -94,7 +94,7 @@ class AccountsServiceProvider implements ServiceProviderInterface
'class' => FlexUser\Storage\UserFolderStorage::class,
'options' => [
'file' => 'user',
'pattern' => '{FOLDER}/{KEY:2}/{KEY}/{FILE}{.EXT}',
'pattern' => '{FOLDER}/{KEY:2}/{KEY}/{FILE}{EXT}',
'key' => 'username',
],
];

View File

@@ -559,10 +559,10 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface
$ext = $defaults['ext'] ?? '.html.twig';
$types = array_unique(array_merge([$type], (array)($defaults['type'] ?? null)));
$paths = $config['collection']['paths'] ?? [
'flex/{TYPE}/collection/{LAYOUT}{.EXT}',
'flex-objects/layouts/{TYPE}/collection/{LAYOUT}{.EXT}'
'flex/{TYPE}/collection/{LAYOUT}{EXT}',
'flex-objects/layouts/{TYPE}/collection/{LAYOUT}{EXT}'
];
$table = ['TYPE' => '%1$s', 'LAYOUT' => '%2$s', 'EXT' => '%3$s', '.EXT' => '%3$s'];
$table = ['TYPE' => '%1$s', 'LAYOUT' => '%2$s', 'EXT' => '%3$s'];
$lookups = [];
foreach ($paths as $path) {

View File

@@ -954,10 +954,10 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
$ext = $defaults['ext'] ?? '.html.twig';
$types = array_unique(array_merge([$type], (array)($defaults['type'] ?? null)));
$paths = $config['object']['paths'] ?? [
'flex/{TYPE}/object/{LAYOUT}{.EXT}',
'flex-objects/layouts/{TYPE}/object/{LAYOUT}{.EXT}'
'flex/{TYPE}/object/{LAYOUT}{EXT}',
'flex-objects/layouts/{TYPE}/object/{LAYOUT}{EXT}'
];
$table = ['TYPE' => '%1$s', 'LAYOUT' => '%2$s', 'EXT' => '%3$s', '.EXT' => '%3$s'];
$table = ['TYPE' => '%1$s', 'LAYOUT' => '%2$s', 'EXT' => '%3$s'];
$lookups = [];
foreach ($paths as $path) {

View File

@@ -25,7 +25,7 @@ class FileStorage extends FolderStorage
*/
public function __construct(array $options)
{
$this->dataPattern = '{FOLDER}/{KEY}{.EXT}';
$this->dataPattern = '{FOLDER}/{KEY}{EXT}';
if (!isset($options['formatter']) && isset($options['pattern'])) {
$options['formatter'] = $this->detectDataFormatter($options['pattern']);

View File

@@ -13,6 +13,7 @@ namespace Grav\Framework\Flex\Storage;
use Grav\Common\Filesystem\Folder;
use Grav\Common\Grav;
use Grav\Common\Utils;
use Grav\Framework\Flex\Interfaces\FlexStorageInterface;
use RocketTheme\Toolbox\File\File;
use InvalidArgumentException;
@@ -27,7 +28,7 @@ class FolderStorage extends AbstractFilesystemStorage
/** @var string Folder where all the data is stored. */
protected $dataFolder;
/** @var string Pattern to access an object. */
protected $dataPattern = '{FOLDER}/{KEY}/{FILE}{.EXT}';
protected $dataPattern = '{FOLDER}/{KEY}/{FILE}{EXT}';
/** @var string Filename for the object. */
protected $dataFile;
/** @var string File extension for the object. */
@@ -252,7 +253,7 @@ class FolderStorage extends AbstractFilesystemStorage
$parts['key'], // {KEY}
$parts['key:2'], // {KEY:2}
'***', // {FILE}
'***' // {.EXT}
'***' // {EXT}
];
$path = rtrim(explode('***', sprintf($this->dataPattern, ...$options))[0], '/');
@@ -284,7 +285,7 @@ class FolderStorage extends AbstractFilesystemStorage
$parts['key'], // {KEY}
$parts['key:2'], // {KEY:2}
$parts['file'], // {FILE}
$this->dataExt // {.EXT}
$this->dataExt // {EXT}
];
return sprintf($this->dataPattern, ...$options);
@@ -607,23 +608,20 @@ class FolderStorage extends AbstractFilesystemStorage
$this->dataFolder = $options['folder'];
$this->dataFile = $options['file'] ?? 'item';
$this->dataExt = $extension;
if (\mb_strpos($pattern, '{FILE}') === false && (\mb_strpos($pattern, '{EXT}') === false || \mb_strpos($pattern, '{.EXT}') === false)) {
if (\mb_strpos($pattern, '{FILE}') === false && \mb_strpos($pattern, '{EXT}') === false) {
if (isset($options['file'])) {
$pattern .= '/{FILE}{.EXT}';
$pattern .= '/{FILE}{EXT}';
} else {
$this->dataFile = \basename($pattern, $extension);
$pattern = \dirname($pattern) . '/{FILE}{.EXT}';
$pattern = \dirname($pattern) . '/{FILE}{EXT}';
}
}
$this->prefixed = (bool)($options['prefixed'] ?? strpos($pattern, '/{KEY:2}/'));
$this->indexed = (bool)($options['indexed'] ?? false);
$this->keyField = $options['key'] ?? 'storage_key';
$pattern = preg_replace(
['/{FOLDER}/', '/{KEY}/', '/{KEY:2}/', '/{FILE}/', '/{EXT}/', '/{\.EXT}/'],
['%1$s', '%2$s', '%3$s', '%4$s', '%5$s', '%5$s'],
$pattern
);
$variables = ['FOLDER' => '%1$s', 'KEY' => '%2$s', 'KEY:2' => '%3$s', 'FILE' => '%4$s', 'EXT' => '%5$s'];
$pattern = Utils::simpleTemplate($pattern, $variables);
if (!$pattern) {
throw new \RuntimeException('Bad storage folder pattern');