From 9e400e3c378d70ad3da19ab20ef72bf35a9b72bd Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 14 Aug 2020 13:35:12 +0300 Subject: [PATCH] feat(core): Flextype Solid Core - next round #458 --- .../Foundation/Entries/Fields/CreatedAtField.php | 4 ++-- .../Foundation/Entries/Fields/CreatedByField.php | 2 +- .../app/Foundation/Entries/Fields/IdField.php | 2 +- .../Foundation/Entries/Fields/ModifiedAtField.php | 2 +- .../app/Foundation/Entries/Fields/ParsersField.php | 2 +- .../Foundation/Entries/Fields/PublishedAtField.php | 4 ++-- .../Foundation/Entries/Fields/PublishedByField.php | 2 +- .../Foundation/Entries/Fields/RoutableField.php | 4 ++-- .../app/Foundation/Entries/Fields/SlugField.php | 2 +- .../app/Foundation/Entries/Fields/UuidField.php | 2 +- .../Foundation/Entries/Fields/VisibilityField.php | 4 ++-- src/flextype/app/Foundation/Plugins.php | 2 +- src/flextype/app/Support/Parsers/Shortcode.php | 8 +------- .../Parsers/Shortcodes/EntriesShortcode.php | 2 +- .../Support/Parsers/Shortcodes/RawShortcode.php | 4 ++-- .../Parsers/Shortcodes/RegistryShortcode.php | 2 +- .../Support/Parsers/Shortcodes/UrlShortcode.php | 2 +- .../app/Support/Serializers/Frontmatter.php | 14 ++++---------- src/flextype/app/Support/Serializers/Json.php | 8 +------- src/flextype/app/Support/Serializers/Yaml.php | 6 ------ 20 files changed, 27 insertions(+), 51 deletions(-) diff --git a/src/flextype/app/Foundation/Entries/Fields/CreatedAtField.php b/src/flextype/app/Foundation/Entries/Fields/CreatedAtField.php index 48ed3da4..43ebfdd5 100644 --- a/src/flextype/app/Foundation/Entries/Fields/CreatedAtField.php +++ b/src/flextype/app/Foundation/Entries/Fields/CreatedAtField.php @@ -10,13 +10,13 @@ declare(strict_types=1); use Flextype\Component\Filesystem\Filesystem; if ($flextype->container('registry')->get('flextype.settings.entries.fields.created_at.enabled')) { - $flextype->emitter->addListener('onEntryAfterInitialized', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryAfterInitialized', function () use ($flextype) : void { $flextype->entries->entry['created_at'] = isset($flextype->entries->entry['created_at']) ? (int) strtotime($flextype->entries->entry['created_at']) : (int) Filesystem::getTimestamp($flextype->entries->getFileLocation($flextype->entries->entry_id)); }); - $flextype->emitter->addListener('onEntryCreate', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryCreate', function () use ($flextype) : void { if (isset($flextype->entries->entry_create_data['created_at'])) { $flextype->entries->entry_create_data['created_at'] = $flextype->entries->entry_create_data['created_at']; } else { diff --git a/src/flextype/app/Foundation/Entries/Fields/CreatedByField.php b/src/flextype/app/Foundation/Entries/Fields/CreatedByField.php index 255e5ef7..835ac322 100644 --- a/src/flextype/app/Foundation/Entries/Fields/CreatedByField.php +++ b/src/flextype/app/Foundation/Entries/Fields/CreatedByField.php @@ -8,7 +8,7 @@ declare(strict_types=1); */ if ($flextype->container('registry')->get('flextype.settings.entries.fields.created_by.enabled')) { - $flextype->emitter->addListener('onEntryCreate', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryCreate', function () use ($flextype) : void { if (isset($flextype->entries->entry_create_data['created_by'])) { $flextype->entries->entry_create_data['created_by'] = $flextype->entries->entry_create_data['created_by']; } else { diff --git a/src/flextype/app/Foundation/Entries/Fields/IdField.php b/src/flextype/app/Foundation/Entries/Fields/IdField.php index acbe88d6..ae4d7a87 100644 --- a/src/flextype/app/Foundation/Entries/Fields/IdField.php +++ b/src/flextype/app/Foundation/Entries/Fields/IdField.php @@ -8,7 +8,7 @@ declare(strict_types=1); */ if ($flextype->container('registry')->get('flextype.settings.entries.fields.id.enabled')) { - $flextype->emitter->addListener('onEntryAfterInitialized', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryAfterInitialized', function () use ($flextype) : void { $flextype->entries->entry['id'] = isset($flextype->entries->entry['id']) ? (string) $flextype->entries->entry['id'] : (string) ltrim(rtrim($flextype->entries->entry_id, '/'), '/'); }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/ModifiedAtField.php b/src/flextype/app/Foundation/Entries/Fields/ModifiedAtField.php index d3291f92..87118fed 100644 --- a/src/flextype/app/Foundation/Entries/Fields/ModifiedAtField.php +++ b/src/flextype/app/Foundation/Entries/Fields/ModifiedAtField.php @@ -10,7 +10,7 @@ declare(strict_types=1); use Flextype\Component\Filesystem\Filesystem; if ($flextype->container('registry')->get('flextype.settings.entries.fields.modified_at.enabled')) { - $flextype->emitter->addListener('onEntryAfterInitialized', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryAfterInitialized', function () use ($flextype) : void { $flextype->entries->entry['modified_at'] = (int) Filesystem::getTimestamp($flextype->entries->getFileLocation($flextype->entries->entry_id)); }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/ParsersField.php b/src/flextype/app/Foundation/Entries/Fields/ParsersField.php index 00d6cf3e..f9429432 100644 --- a/src/flextype/app/Foundation/Entries/Fields/ParsersField.php +++ b/src/flextype/app/Foundation/Entries/Fields/ParsersField.php @@ -10,7 +10,7 @@ declare(strict_types=1); use Flextype\Component\Arrays\Arrays; if ($flextype->container('registry')->get('flextype.settings.entries.fields.parsers.enabled')) { - $flextype->emitter->addListener('onEntryAfterInitialized', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryAfterInitialized', function () use ($flextype) : void { processParsersField($flextype); }); } diff --git a/src/flextype/app/Foundation/Entries/Fields/PublishedAtField.php b/src/flextype/app/Foundation/Entries/Fields/PublishedAtField.php index f1eaa0c3..6b2028e7 100644 --- a/src/flextype/app/Foundation/Entries/Fields/PublishedAtField.php +++ b/src/flextype/app/Foundation/Entries/Fields/PublishedAtField.php @@ -10,13 +10,13 @@ declare(strict_types=1); use Flextype\Component\Filesystem\Filesystem; if ($flextype->container('registry')->get('flextype.settings.entries.fields.published_at.enabled')) { - $flextype->emitter->addListener('onEntryAfterInitialized', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryAfterInitialized', function () use ($flextype) : void { $flextype->entries->entry['published_at'] = isset($flextype->entries->entry['published_at']) ? (int) strtotime($flextype->entries->entry['published_at']) : (int) Filesystem::getTimestamp($flextype->entries->getFileLocation($flextype->entries->entry_id)); }); - $flextype->emitter->addListener('onEntryCreate', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryCreate', function () use ($flextype) : void { if (isset($flextype->entries->entry_create_data['published_at'])) { $flextype->entries->entry_create_data['published_at'] = $flextype->entries->entry_create_data['published_at']; } else { diff --git a/src/flextype/app/Foundation/Entries/Fields/PublishedByField.php b/src/flextype/app/Foundation/Entries/Fields/PublishedByField.php index 0f083fdf..52543151 100644 --- a/src/flextype/app/Foundation/Entries/Fields/PublishedByField.php +++ b/src/flextype/app/Foundation/Entries/Fields/PublishedByField.php @@ -8,7 +8,7 @@ declare(strict_types=1); */ if ($flextype->container('registry')->get('flextype.settings.entries.fields.published_by.enabled')) { - $flextype->emitter->addListener('onEntryCreate', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryCreate', function () use ($flextype) : void { if (isset($flextype->entries->entry_create_data['published_by'])) { $flextype->entries->entry_create_data['published_by'] = $flextype->entries->entry_create_data['published_by']; } else { diff --git a/src/flextype/app/Foundation/Entries/Fields/RoutableField.php b/src/flextype/app/Foundation/Entries/Fields/RoutableField.php index 2b4eeb6e..fd04ae97 100644 --- a/src/flextype/app/Foundation/Entries/Fields/RoutableField.php +++ b/src/flextype/app/Foundation/Entries/Fields/RoutableField.php @@ -9,13 +9,13 @@ declare(strict_types=1); if ($flextype->container('registry')->get('flextype.settings.entries.fields.routable.enabled')) { - $flextype->emitter->addListener('onEntryAfterInitialized', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryAfterInitialized', function () use ($flextype) : void { $flextype->entries->entry['routable'] = isset($flextype->entries->entry['routable']) ? (bool) $flextype->entries->entry['routable'] : true; }); - $flextype->emitter->addListener('onEntryCreate', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryCreate', function () use ($flextype) : void { if (isset($flextype->entries->entry_create_data['routable']) && is_bool($flextype->entries->entry_create_data['routable'])) { $flextype->entries->entry_create_data['routable'] = $flextype->entries->entry_create_data['routable']; } else { diff --git a/src/flextype/app/Foundation/Entries/Fields/SlugField.php b/src/flextype/app/Foundation/Entries/Fields/SlugField.php index 4b36fc18..378d0c99 100644 --- a/src/flextype/app/Foundation/Entries/Fields/SlugField.php +++ b/src/flextype/app/Foundation/Entries/Fields/SlugField.php @@ -8,7 +8,7 @@ declare(strict_types=1); */ if ($flextype->container('registry')->get('flextype.settings.entries.fields.slug.enabled')) { - $flextype->emitter->addListener('onEntryAfterInitialized', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryAfterInitialized', function () use ($flextype) : void { $parts = explode('/', ltrim(rtrim($flextype->entries->entry_id, '/'), '/')); $flextype->entries->entry['slug'] = isset($flextype->entries->entry['slug']) ? (string) $flextype->entries->entry['slug'] : (string) end($parts); }); diff --git a/src/flextype/app/Foundation/Entries/Fields/UuidField.php b/src/flextype/app/Foundation/Entries/Fields/UuidField.php index f3bb92fb..8788f186 100644 --- a/src/flextype/app/Foundation/Entries/Fields/UuidField.php +++ b/src/flextype/app/Foundation/Entries/Fields/UuidField.php @@ -10,7 +10,7 @@ declare(strict_types=1); use Ramsey\Uuid\Uuid; if ($flextype->container('registry')->get('flextype.settings.entries.fields.uuid.enabled')) { - $flextype->emitter->addListener('onEntryCreate', function () use ($flextype) : void { + $flextype->container('emitter')->addListener('onEntryCreate', function () use ($flextype) : void { if (isset($flextype->entries->entry_create_data['uuid'])) { $flextype->entries->entry_create_data['uuid'] = $flextype->entries->entry_create_data['uuid']; } else { diff --git a/src/flextype/app/Foundation/Entries/Fields/VisibilityField.php b/src/flextype/app/Foundation/Entries/Fields/VisibilityField.php index 81e64aae..214ba2b1 100644 --- a/src/flextype/app/Foundation/Entries/Fields/VisibilityField.php +++ b/src/flextype/app/Foundation/Entries/Fields/VisibilityField.php @@ -14,7 +14,7 @@ if ($flextype->container('registry')->get('flextype.settings.entries.fields.visi 'visible' => 'visible', ]; - $flextype->emitter->addListener('onEntryAfterInitialized', function () use ($flextype, $visibility) : void { + $flextype->container('emitter')->addListener('onEntryAfterInitialized', function () use ($flextype, $visibility) : void { if (isset($flextype->entries->entry['visibility']) && in_array($flextype->entries->entry['visibility'], $visibility)) { $flextype->entries->entry['visibility'] = (string) $visibility[$flextype->entries->entry['visibility']]; } else { @@ -22,7 +22,7 @@ if ($flextype->container('registry')->get('flextype.settings.entries.fields.visi } }); - $flextype->emitter->addListener('onEntryCreate', function () use ($flextype, $visibility) : void { + $flextype->container('emitter')->addListener('onEntryCreate', function () use ($flextype, $visibility) : void { if (isset($flextype->entries->entry_create_data['visibility']) && in_array($flextype->entries->entry_create_data['visibility'], $visibility)) { $flextype->entries->entry_create_data['visibility'] = $flextype->entries->entry_create_data['visibility']; } else { diff --git a/src/flextype/app/Foundation/Plugins.php b/src/flextype/app/Foundation/Plugins.php index ad4be576..6d3d8004 100755 --- a/src/flextype/app/Foundation/Plugins.php +++ b/src/flextype/app/Foundation/Plugins.php @@ -373,7 +373,7 @@ class Plugins * * @access private */ - private function includeEnabledPlugins($flextype, $flextype) : void + private function includeEnabledPlugins($flextype) : void { if (! is_array($this->flextype->container('registry')->get('plugins')) || count($this->flextype->container('registry')->get('plugins')) <= 0) { return; diff --git a/src/flextype/app/Support/Parsers/Shortcode.php b/src/flextype/app/Support/Parsers/Shortcode.php index e9637c31..d392de81 100644 --- a/src/flextype/app/Support/Parsers/Shortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcode.php @@ -18,11 +18,6 @@ class Shortcode */ protected $flextype; - /** - * Application - */ - protected $flextype; - /** * Shortcode Fasade */ @@ -35,8 +30,7 @@ class Shortcode */ public function __construct($flextype, $shortcode) { - $this->flextype = $flextype; - $this->container = $flextype->getContainer(); + $this->flextype = $flextype; $this->shortcode = $shortcode; } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php index ca519a76..390978a3 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php @@ -13,7 +13,7 @@ use Flextype\Component\Arrays\Arrays; if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.entries.enabled')) { // Shortcode: [entries_fetch id="entry-id" field="field-name" default="default-value"] - $flextype['shortcode']->addHandler('entries_fetch', function (ShortcodeInterface $s) use ($flextype) { + $flextype->container('shortcode')->addHandler('entries_fetch', function (ShortcodeInterface $s) use ($flextype) { return Arrays::get($flextype['entries']->fetch($s->getParameter('id')), $s->getParameter('field'), $s->getParameter('default')); }); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php index f819103c..14d44309 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php @@ -14,9 +14,9 @@ use Thunder\Shortcode\Events; if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.raw.enabled')) { // Shortcode: [raw] - $flextype['shortcode']->addHandler('raw', function (ShortcodeInterface $s) use ($flextype) { + $flextype->container('shortcode')->addHandler('raw', function (ShortcodeInterface $s) use ($flextype) { return $s->getContent(); }); - $flextype['shortcode']->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(['raw'])); + $flextype->container('shortcode')->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(['raw'])); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php index c47f69d2..fcc3c3b9 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php @@ -12,7 +12,7 @@ use Thunder\Shortcode\Shortcode\ShortcodeInterface; if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.registry.enabled')) { // Shortcode: [registry_get name="item-name" default="default-value"] - $flextype['shortcode']->addHandler('registry_get', function (ShortcodeInterface $s) use ($flextype) { + $flextype->container('shortcode')->addHandler('registry_get', function (ShortcodeInterface $s) use ($flextype) { return $flextype['registry']->get($s->getParameter('name'), $s->getParameter('default')); }); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php index 37a14096..53e2aa45 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php @@ -13,7 +13,7 @@ use Slim\Http\Uri; if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.url.enabled')) { // Shortcode: [url] - $flextype['shortcode']->addHandler('url', function () use ($flextype) { + $flextype->container('shortcode')->addHandler('url', function () use ($flextype) { if ($flextype['registry']->has('flextype.settings.url') && $flextype['registry']->get('flextype.settings.url') !== '') { return $flextype['registry']->get('flextype.settings.url'); } diff --git a/src/flextype/app/Support/Serializers/Frontmatter.php b/src/flextype/app/Support/Serializers/Frontmatter.php index b4213e26..67208949 100644 --- a/src/flextype/app/Support/Serializers/Frontmatter.php +++ b/src/flextype/app/Support/Serializers/Frontmatter.php @@ -26,11 +26,6 @@ class Frontmatter */ protected $flextype; - /** - * Application - */ - protected $flextype; - /** * Constructor * @@ -38,8 +33,7 @@ class Frontmatter */ public function __construct($flextype) { - $this->flextype = $flextype; - $this->container = $flextype->getContainer(); + $this->flextype = $flextype; } /** @@ -88,10 +82,10 @@ class Frontmatter if (isset($input['content'])) { $content = $input['content']; Arrays::delete($input, 'content'); - $matter = $this->container['yaml']->encode($input); + $matter = $this->flextype->container('yaml')->encode($input); } else { $content = ''; - $matter = $this->container['yaml']->encode($input); + $matter = $this->flextype->container('yaml')->encode($input); } $encoded = '---' . "\n" . @@ -120,7 +114,7 @@ class Frontmatter return ['content' => trim($input)]; } - return $this->container['yaml']->decode(trim($parts[1]), false) + ['content' => trim(implode(PHP_EOL . '---' . PHP_EOL, array_slice($parts, 2)))]; + return $this->flextype->container('yaml')->decode(trim($parts[1]), false) + ['content' => trim(implode(PHP_EOL . '---' . PHP_EOL, array_slice($parts, 2)))]; } protected function getCacheID($input) diff --git a/src/flextype/app/Support/Serializers/Json.php b/src/flextype/app/Support/Serializers/Json.php index 682d36dc..88825298 100644 --- a/src/flextype/app/Support/Serializers/Json.php +++ b/src/flextype/app/Support/Serializers/Json.php @@ -32,11 +32,6 @@ class Json */ protected $flextype; - /** - * Application - */ - protected $flextype; - /** * Constructor * @@ -44,8 +39,7 @@ class Json */ public function __construct($flextype) { - $this->flextype = $flextype; - $this->container = $flextype->getContainer(); + $this->flextype = $flextype; } /** diff --git a/src/flextype/app/Support/Serializers/Yaml.php b/src/flextype/app/Support/Serializers/Yaml.php index 6db204a1..285d6d42 100644 --- a/src/flextype/app/Support/Serializers/Yaml.php +++ b/src/flextype/app/Support/Serializers/Yaml.php @@ -37,11 +37,6 @@ class Yaml */ protected $flextype; - /** - * Application - */ - protected $flextype; - /** * Constructor * @@ -50,7 +45,6 @@ class Yaml public function __construct($flextype) { $this->flextype = $flextype; - $this->container = $flextype->getContainer(); } /**