1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-05 20:57:41 +02:00

feat(core): use Atomastic Components #478

This commit is contained in:
Awilum
2020-10-16 14:20:27 +03:00
parent 78e8d92a4d
commit e2d25f1737
12 changed files with 50 additions and 39 deletions

View File

@@ -27,10 +27,14 @@
"doctrine/collections": "~1.6.7",
"flextype-components/arrays" : "3.0.1",
"flextype-components/strings" : "1.2.0",
"flextype-components/filesystem" : "2.0.8",
"flextype-components/i18n" : "1.3.0",
"flextype-components/registry" : "3.0.0",
"atomastic/session": "^1.0.0",
"atomastic/arrays": "^1.0.0",
"atomastic/filesystem": "^1.0.0",
"atomastic/registry": "^1.0.0",
"atomastic/strings": "^1.0.0",
"slim/slim": "~3.12.3",
@@ -83,9 +87,10 @@
]
},
"require-dev": {
"doctrine/coding-standard": "8.1.0",
"victorjonsson/markdowndocs": "~1.3.8",
"phpstan/phpstan": "~0.12.42",
"doctrine/coding-standard": "8.1.0",
"pestphp/pest": "^0.3.3",
"phpstan/phpstan": "^0.12.42",
"symfony/var-dumper": "~5.1.5"
}
}

View File

@@ -267,13 +267,10 @@ class Entries
$entry_dir = $this->getDirLocation($this->storage['create']['id']);
if (! Filesystem::has($entry_dir)) {
// Try to create directory for new entry
if (Filesystem::createDir($entry_dir)) {
// Check if new entry file exists
if (! Filesystem::has($entry_file = $entry_dir . '/entry' . '.' . flextype('registry')->get('flextype.settings.entries.extension'))) {
// Create a new entry!
return Filesystem::write($entry_file, flextype('frontmatter')->encode($this->storage['create']['data']));
if (! flextype('filesystem')->directory($entry_dir)->exists()) {
if (flextype('filesystem')->directory($entry_dir)->create()) {
if (! flextype('filesystem')->file($entry_file = $entry_dir . '/entry' . '.' . flextype('registry')->get('flextype.settings.entries.extension'))->exists()) {
return (bool) flextype('filesystem')->file($entry_file)->put(flextype('frontmatter')->encode($this->storage['create']['data']));
}
return false;

View File

@@ -8,7 +8,7 @@ declare(strict_types=1);
*/
use Flextype\Component\Filesystem\Filesystem;
use Flextype\Component\Strings\Strings;
use Atomastic\Strings\Strings;
if (flextype('registry')->get('flextype.settings.entries.fields.created_at.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {

View File

@@ -7,12 +7,12 @@ declare(strict_types=1);
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
use Flextype\Component\Strings\Strings;
use Atomastic\Strings\Strings;
if (flextype('registry')->get('flextype.settings.entries.fields.id.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
if (flextype('entries')->getStorage('fetch_single.data.id') == null) {
flextype('entries')->setStorage('fetch_single.data.id', (string) Strings::trimSlashes(flextype('entries')->getStorage('fetch_single.id')));
flextype('entries')->setStorage('fetch_single.data.id', (string) Strings::create(flextype('entries')->getStorage('fetch_single.id'))->trimSlashes());
}
});
}

View File

@@ -7,12 +7,12 @@ declare(strict_types=1);
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
use Flextype\Component\Strings\Strings;
use Atomastic\Strings\Strings;
if (flextype('registry')->get('flextype.settings.entries.fields.slug.enabled')) {
flextype('emitter')->addListener('onEntryAfterInitialized', static function (): void {
if (flextype('entries')->getStorage('fetch_single.data.slug') == null) {
$parts = Strings::segments(Strings::trimSlashes(flextype('entries')->getStorage('fetch_single.id')), '/');
$parts = Strings::create(flextype('entries')->getStorage('fetch_single.id'))->trimSlashes()->segments();
flextype('entries')->setStorage('fetch_single.data.slug', (string) end($parts));
}
});

View File

@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Flextype\Support\Parsers;
use Flextype\Component\Strings\Strings;
use Atomastic\Strings\Strings;
class Markdown
{
@@ -74,6 +74,6 @@ class Markdown
public function getCacheID($input): string
{
return Strings::hash('markdown' . $input);
return Strings::create('markdown' . $input)->hash()->toString();
}
}

View File

@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Flextype\Support\Parsers;
use Flextype\Component\Strings\Strings;
use Atomastic\Strings\Strings;
class Shortcode
{
@@ -113,6 +113,6 @@ class Shortcode
*/
public function getCacheID(string $input): string
{
return Strings::hash('shortcode' . $input);
return Strings::create('shortcode' . $input)->hash()->toString();
}
}

View File

@@ -10,7 +10,7 @@ declare(strict_types=1);
namespace Flextype\Support\Serializers;
use Flextype\Component\Arrays\Arrays;
use Flextype\Component\Strings\Strings;
use Atomastic\Strings\Strings;
use function array_slice;
use function count;
@@ -93,17 +93,17 @@ class Frontmatter
$input = (string) preg_replace("/(\r\n|\r)/", "\n", $input);
// Parse Frontmatter and Body
$parts = preg_split('/^[\s\r\n]?---[\s\r\n]?$/sm', PHP_EOL . Strings::trimLeft($input));
$parts = preg_split('/^[\s\r\n]?---[\s\r\n]?$/sm', PHP_EOL . Strings::create($input)->trimLeft()->toString());
if (count($parts) < 3) {
return ['content' => Strings::trim($input)];
return ['content' => Strings::create($input)->trim()->toString()];
}
return flextype('yaml')->decode(Strings::trim($parts[1]), false) + ['content' => Strings::trim(implode(PHP_EOL . '---' . PHP_EOL, array_slice($parts, 2)))];
return flextype('yaml')->decode(Strings::create($parts[1])->trim()->toString(), false) + ['content' => Strings::create(implode(PHP_EOL . '---' . PHP_EOL, array_slice($parts, 2)))->trim()->toString()];
}
protected function getCacheID($input): string
{
return Strings::hash('frontmatter' . $input);
return Strings::create('frontmatter' . $input)->hash()->toString();
}
}

View File

@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Flextype\Support\Serializers;
use Flextype\Component\Strings\Strings;
use Atomastic\Strings\Strings;
use RuntimeException;
use function defined;
@@ -109,6 +109,6 @@ class Json
protected function getCacheID($input): string
{
return Strings::hash('json' . $input);
return Strings::create('json' . $input)->hash()->toString();
}
}

View File

@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Flextype\Support\Serializers;
use Flextype\Component\Strings\Strings;
use Atomastic\Strings\Strings;
use RuntimeException;
use Symfony\Component\Yaml\Exception\DumpException as SymfonyYamlDumpException;
use Symfony\Component\Yaml\Exception\ParseException as SymfonyYamlParseException;
@@ -142,6 +142,6 @@ class Yaml
protected function getCacheID($input): string
{
return Strings::hash('yaml' . $input);
return Strings::create('yaml' . $input)->hash()->toString();
}
}

View File

@@ -9,7 +9,7 @@ declare(strict_types=1);
namespace Flextype;
use Flextype\Component\Registry\Registry;
use Atomastic\Registry\Registry;
use Flextype\Foundation\Flextype;
use Slim\Http\Environment;
use Slim\Http\Uri;
@@ -32,7 +32,7 @@ use function ucwords;
/**
* Init Registry
*/
$registry = new Registry();
$registry = Registry::getInstance();
/**
* Preflight the Flextype

View File

@@ -11,8 +11,9 @@ namespace Flextype;
use Bnf\Slim3Psr15\CallableResolver;
use Cocur\Slugify\Slugify;
use Flextype\Component\Strings\Strings;
use Odan\Session\PhpSession;
use Atomastic\Strings\Strings;
use Atomastic\Session\Session;
use Atomastic\Filesystem\Filesystem;
use Flextype\Foundation\Cors;
use Flextype\Foundation\Entries\Entries;
use Flextype\Foundation\Media\MediaFiles;
@@ -28,7 +29,7 @@ use Flextype\Support\Serializers\Yaml;
use Intervention\Image\ImageManager;
use League\Event\Emitter;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use League\Flysystem\Filesystem as Flysystem;
use League\Glide\Api\Api;
use League\Glide\Manipulators\Background;
use League\Glide\Manipulators\Blur;
@@ -58,11 +59,19 @@ use function extension_loaded;
use function in_array;
use function sys_get_temp_dir;
/**
* Add filesystem service to Flextype container
*/
flextype()->container()['filesystem'] = static function () {
return new Filesystem();
};
/**
* Create a standard session hanndler
*/
flextype()->container()['session'] = static function () {
return new PhpSession();
return new Session();
};
/**
@@ -124,7 +133,7 @@ flextype()->container()['cache'] = static function () {
if ($key === 'path' && in_array($driver_name, ['files', 'sqlite', 'leveldb'])) {
$config['path'] = ! empty($value) ? PATH['tmp'] . '/' . $value : sys_get_temp_dir();
} else {
$config[Strings::camel($key)] = $value;
$config[Strings::create($key)->camel()->toString()] = $value;
}
}
@@ -267,17 +276,17 @@ flextype()->container()['images'] = static function () {
$imagesSettings = ['driver' => flextype('registry')->get('flextype.settings.image.driver')];
// Set source filesystem
$source = new Filesystem(
$source = new Flysystem(
new Local(PATH['project'] . '/uploads/entries/')
);
// Set cache filesystem
$cache = new Filesystem(
$cache = new Flysystem(
new Local(PATH['tmp'] . '/glide')
);
// Set watermarks filesystem
$watermarks = new Filesystem(
$watermarks = new Flysystem(
new Local(PATH['project'] . '/watermarks')
);