From 990ac85aed44b3735fe60bd07d3470f9d0ce1103 Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione <18699708+giuscris@users.noreply.github.com> Date: Fri, 18 Dec 2020 15:46:58 +0100 Subject: [PATCH] Extract scheme logic from templates one and normalize structure --- admin/schemes/roles.yml | 32 +- admin/schemes/site.yml | 170 ++--- admin/schemes/system.yml | 700 +++++++++--------- admin/schemes/user.yml | 226 +++--- formwork/src/Admin/AdminTrait.php | 4 +- formwork/src/Admin/Controllers/Options.php | 5 +- formwork/src/Admin/Controllers/Users.php | 3 +- formwork/src/Admin/Users/Users.php | 3 +- formwork/src/{Template => Schemes}/Scheme.php | 14 +- formwork/src/Template/Layout.php | 1 + formwork/src/Template/Template.php | 3 +- 11 files changed, 587 insertions(+), 574 deletions(-) rename formwork/src/{Template => Schemes}/Scheme.php (77%) diff --git a/admin/schemes/roles.yml b/admin/schemes/roles.yml index ccbb0bbe..9b7578d7 100644 --- a/admin/schemes/roles.yml +++ b/admin/schemes/roles.yml @@ -1,16 +1,18 @@ -admin: - title: '{{user.role.admin}}' - permissions: - dashboard: true - cache: true - backup: true - pages: true - options: true - updates: true - users: true +title: Roles +data: + admin: + title: '{{user.role.admin}}' + permissions: + dashboard: true + cache: true + backup: true + pages: true + options: true + updates: true + users: true -user: - title: '{{user.role.user}}' - permissions: - dashboard: true - pages: true + user: + title: '{{user.role.user}}' + permissions: + dashboard: true + pages: true diff --git a/admin/schemes/site.yml b/admin/schemes/site.yml index 3d48f54c..33d447a4 100644 --- a/admin/schemes/site.yml +++ b/admin/schemes/site.yml @@ -1,89 +1,91 @@ -section1: - type: header - label: '{{options.site.info}}' +title: Site +fields: + section1: + type: header + label: '{{options.site.info}}' -rows1: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.site.info.title}}' - column2: - type: column - width: 2-3 - fields: - title: - type: text - required: true + rows1: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.site.info.title}}' + column2: + type: column + width: 2-3 + fields: + title: + type: text + required: true - row2: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.site.info.author}}' - column2: - type: column - width: 2-3 - fields: - author: - type: text + row2: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.site.info.author}}' + column2: + type: column + width: 2-3 + fields: + author: + type: text - row3: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.site.info.description}}' - column2: - type: column - width: 2-3 - fields: - description: - type: textarea + row3: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.site.info.description}}' + column2: + type: column + width: 2-3 + fields: + description: + type: textarea -section2: - type: header - label: '{{options.site.advanced}}' + section2: + type: header + label: '{{options.site.advanced}}' -rows2: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.site.advanced.metadata}}' - column2: - type: column - width: 2-3 - fields: - metadata: - type: array - associative: true - placeholder_key: '{{options.site.advanced.metadata.name}}' - placeholder_value: '{{options.site.advanced.metadata.content}}' - row2: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.site.advanced.aliases}}' - column2: - type: column - width: 2-3 - fields: - aliases: - type: array - associative: true - placeholder_key: '{{options.site.advanced.aliases.alias}}' - placeholder_value: '{{options.site.advanced.aliases.route}}' + rows2: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.site.advanced.metadata}}' + column2: + type: column + width: 2-3 + fields: + metadata: + type: array + associative: true + placeholder_key: '{{options.site.advanced.metadata.name}}' + placeholder_value: '{{options.site.advanced.metadata.content}}' + row2: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.site.advanced.aliases}}' + column2: + type: column + width: 2-3 + fields: + aliases: + type: array + associative: true + placeholder_key: '{{options.site.advanced.aliases.alias}}' + placeholder_value: '{{options.site.advanced.aliases.route}}' diff --git a/admin/schemes/system.yml b/admin/schemes/system.yml index 213d8324..9f02f157 100644 --- a/admin/schemes/system.yml +++ b/admin/schemes/system.yml @@ -1,362 +1,364 @@ -section1: - type: header - label: '{{options.system.date-and-time}}' +title: System +fields: + section1: + type: header + label: '{{options.system.date-and-time}}' -rows1: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.date-and-time.date-format}}' - column2: - type: column - width: 2-3 - fields: - date.format: - type: select - import: - options: 'Formwork\Admin\Utils\DateFormats::date' - row2: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.date-and-time.hour-format}}' - column2: - type: column - width: 2-3 - fields: - date.hour_format: - type: select - import: - options: 'Formwork\Admin\Utils\DateFormats::hour' - row3: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.date-and-time.timezone}}' - column2: - type: column - width: 2-3 - fields: - date.timezone: - type: select - import: - options: 'Formwork\Admin\Utils\DateFormats::timezones' - row4: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.date-and-time.first-weekday}}' - column2: - type: column - width: 2-3 - fields: - date.week_starts: - type: select - options: - 0: '{{options.system.date-and-time.first-weekday.sunday}}' - 1: '{{options.system.date-and-time.first-weekday.monday}}' + rows1: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.date-and-time.date-format}}' + column2: + type: column + width: 2-3 + fields: + date.format: + type: select + import: + options: 'Formwork\Admin\Utils\DateFormats::date' + row2: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.date-and-time.hour-format}}' + column2: + type: column + width: 2-3 + fields: + date.hour_format: + type: select + import: + options: 'Formwork\Admin\Utils\DateFormats::hour' + row3: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.date-and-time.timezone}}' + column2: + type: column + width: 2-3 + fields: + date.timezone: + type: select + import: + options: 'Formwork\Admin\Utils\DateFormats::timezones' + row4: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.date-and-time.first-weekday}}' + column2: + type: column + width: 2-3 + fields: + date.week_starts: + type: select + options: + 0: '{{options.system.date-and-time.first-weekday.sunday}}' + 1: '{{options.system.date-and-time.first-weekday.monday}}' -section2: - type: header - label: '{{options.system.languages}}' + section2: + type: header + label: '{{options.system.languages}}' -rows2: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.languages.available-languages}}' - column2: - type: column - width: 2-3 - fields: - languages.available: - type: tags - placeholder: '{{options.system.languages.available-languages.no-languages}}' - pattern: '^[a-z]{2,3}$' - translate: [placeholder] - import: - options: 'Formwork\Languages\LanguageCodes::names' - row2: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.languages.preferred-language}}' - column2: - type: column - width: 2-3 - fields: - languages.http_preferred: - type: togglegroup - options: - 1: '{{options.system.languages.preferred-language.enabled}}' - 0: '{{options.system.languages.preferred-language.disabled}}' + rows2: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.languages.available-languages}}' + column2: + type: column + width: 2-3 + fields: + languages.available: + type: tags + placeholder: '{{options.system.languages.available-languages.no-languages}}' + pattern: '^[a-z]{2,3}$' + translate: [placeholder] + import: + options: 'Formwork\Languages\LanguageCodes::names' + row2: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.languages.preferred-language}}' + column2: + type: column + width: 2-3 + fields: + languages.http_preferred: + type: togglegroup + options: + 1: '{{options.system.languages.preferred-language.enabled}}' + 0: '{{options.system.languages.preferred-language.disabled}}' -section3: - type: header - label: '{{options.system.files}}' + section3: + type: header + label: '{{options.system.files}}' -rows3: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.files.allowed-extensions}}' - column2: - type: column - width: 2-3 - fields: - files.allowed_extensions: - type: tags - pattern: '^\.[a-zA-Z0-9]+$' - required: true + rows3: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.files.allowed-extensions}}' + column2: + type: column + width: 2-3 + fields: + files.allowed_extensions: + type: tags + pattern: '^\.[a-zA-Z0-9]+$' + required: true -section4: - type: header - label: '{{options.system.cache}}' + section4: + type: header + label: '{{options.system.cache}}' -rows4: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.cache}}' - column2: - type: column - width: 2-3 - fields: - cache.enabled: - type: togglegroup - options: - 1: '{{options.system.cache.enabled}}' - 0: '{{options.system.cache.disabled}}' - row2: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.cache.time}}' - column2: - type: column - width: 2-3 - fields: - cache.time: - type: duration - min: 900 - step: 900 - intervals: [weeks, days, hours, minutes] - translate: false - required: true + rows4: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.cache}}' + column2: + type: column + width: 2-3 + fields: + cache.enabled: + type: togglegroup + options: + 1: '{{options.system.cache.enabled}}' + 0: '{{options.system.cache.disabled}}' + row2: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.cache.time}}' + column2: + type: column + width: 2-3 + fields: + cache.time: + type: duration + min: 900 + step: 900 + intervals: [weeks, days, hours, minutes] + translate: false + required: true -section5: - type: header - label: '{{options.system.admin-panel}}' + section5: + type: header + label: '{{options.system.admin-panel}}' -rows5: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.admin-panel.default-language}}' - column2: - type: column - width: 2-3 - fields: - admin.lang: - type: select - translate: false - import: - options: 'Formwork\Admin\Translation::availableLanguages' - row2: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.admin-panel.logout-redirects-to}}' - column2: - type: column - width: 2-3 - fields: - admin.logout_redirect: - type: togglegroup - options: - login: '{{options.system.admin-panel.logout-redirects-to.login}}' - home: '{{options.system.admin-panel.logout-redirects-to.home}}' - row3: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.admin-panel.session-timeout}}' - column2: - type: column - width: 2-3 - fields: - admin.session_timeout: - type: duration - min: 0 - unit: minutes - intervals: [hours, minutes] - translate: false - required: true - row4: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.admin-panel.default-color-scheme}}' - column2: - type: column - width: 2-3 - fields: - admin.color_scheme: - type: togglegroup - options: - light: '{{options.system.admin-panel.default-color-scheme.light}}' - dark: '{{options.system.admin-panel.default-color-scheme.dark}}' + rows5: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.admin-panel.default-language}}' + column2: + type: column + width: 2-3 + fields: + admin.lang: + type: select + translate: false + import: + options: 'Formwork\Admin\Translation::availableLanguages' + row2: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.admin-panel.logout-redirects-to}}' + column2: + type: column + width: 2-3 + fields: + admin.logout_redirect: + type: togglegroup + options: + login: '{{options.system.admin-panel.logout-redirects-to.login}}' + home: '{{options.system.admin-panel.logout-redirects-to.home}}' + row3: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.admin-panel.session-timeout}}' + column2: + type: column + width: 2-3 + fields: + admin.session_timeout: + type: duration + min: 0 + unit: minutes + intervals: [hours, minutes] + translate: false + required: true + row4: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.admin-panel.default-color-scheme}}' + column2: + type: column + width: 2-3 + fields: + admin.color_scheme: + type: togglegroup + options: + light: '{{options.system.admin-panel.default-color-scheme.light}}' + dark: '{{options.system.admin-panel.default-color-scheme.dark}}' -section6: - type: header - label: '{{options.system.images}}' + section6: + type: header + label: '{{options.system.images}}' -rows6: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.images.jpeg-quality}}' - column2: - type: column - width: 2-3 - fields: - images.jpeg_quality: - type: range - min: 0 - max: 100 - step: 5 - row2: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.images.png-compression-level}}' - column2: - type: column - width: 2-3 - fields: - images.png_compression: - type: range - min: 0 - max: 9 - row3: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.images.webp-quality}}' - column2: - type: column - width: 2-3 - fields: - images.webp_quality: - type: range - min: 0 - max: 100 - step: 5 - row4: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.images.jpeg-save-progressive}}' - column2: - type: column - width: 2-3 - fields: - images.jpeg_progressive: - type: togglegroup - options: - 1: '{{options.system.images.jpeg-save-progressive.enabled}}' - 0: '{{options.system.images.jpeg-save-progressive.disabled}}' - row5: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.images.process-uploads}}' - column2: - type: column - width: 2-3 - fields: - images.process_uploads: - type: togglegroup - options: - 1: '{{options.system.images.process-uploads.enabled}}' - 0: '{{options.system.images.process-uploads.disabled}}' + rows6: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.images.jpeg-quality}}' + column2: + type: column + width: 2-3 + fields: + images.jpeg_quality: + type: range + min: 0 + max: 100 + step: 5 + row2: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.images.png-compression-level}}' + column2: + type: column + width: 2-3 + fields: + images.png_compression: + type: range + min: 0 + max: 9 + row3: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.images.webp-quality}}' + column2: + type: column + width: 2-3 + fields: + images.webp_quality: + type: range + min: 0 + max: 100 + step: 5 + row4: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.images.jpeg-save-progressive}}' + column2: + type: column + width: 2-3 + fields: + images.jpeg_progressive: + type: togglegroup + options: + 1: '{{options.system.images.jpeg-save-progressive.enabled}}' + 0: '{{options.system.images.jpeg-save-progressive.disabled}}' + row5: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.images.process-uploads}}' + column2: + type: column + width: 2-3 + fields: + images.process_uploads: + type: togglegroup + options: + 1: '{{options.system.images.process-uploads.enabled}}' + 0: '{{options.system.images.process-uploads.disabled}}' -section7: - type: header - label: '{{options.system.backup}}' + section7: + type: header + label: '{{options.system.backup}}' -rows7: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{options.system.backup.backup-files-to-keep}}' - column2: - type: column - width: 2-3 - fields: - backup.max_files: - type: select - options: - 5: 5 - 10: 10 - 15: 15 - 20: 20 + rows7: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{options.system.backup.backup-files-to-keep}}' + column2: + type: column + width: 2-3 + fields: + backup.max_files: + type: select + options: + 5: 5 + 10: 10 + 15: 15 + 20: 20 diff --git a/admin/schemes/user.yml b/admin/schemes/user.yml index c825118b..6a32f908 100644 --- a/admin/schemes/user.yml +++ b/admin/schemes/user.yml @@ -1,118 +1,120 @@ -rows1: - type: rows - fields: - row1: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{user.fullname}}' - column2: - type: column - width: 2-3 - fields: - fullname: - type: text - required: true +title: User +fields: + rows1: + type: rows + fields: + row1: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{user.fullname}}' + column2: + type: column + width: 2-3 + fields: + fullname: + type: text + required: true - row2: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{user.email}}' - column2: - type: column - width: 2-3 - fields: - email: - type: email - required: true + row2: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{user.email}}' + column2: + type: column + width: 2-3 + fields: + email: + type: email + required: true - row3: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{user.password}}' - column2: - type: column - width: 2-3 - fields: - password: - type: password - placeholder: '{{user.password.type-new-password}}' - disabled: true - pattern: '^.{8,}$' - autocomplete: new-password + row3: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{user.password}}' + column2: + type: column + width: 2-3 + fields: + password: + type: password + placeholder: '{{user.password.type-new-password}}' + disabled: true + pattern: '^.{8,}$' + autocomplete: new-password - row4: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{user.language}}' - column2: - type: column - width: 2-3 - fields: - language: - type: select - required: true - translate: false - import: - options: 'Formwork\Admin\Translation::availableLanguages' + row4: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{user.language}}' + column2: + type: column + width: 2-3 + fields: + language: + type: select + required: true + translate: false + import: + options: 'Formwork\Admin\Translation::availableLanguages' - row5: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{user.role}}' - column2: - type: column - width: 2-3 - fields: - role: - type: select - disabled: true - import: - options: 'Formwork\Admin\Users\Users::availableRoles' + row5: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{user.role}}' + column2: + type: column + width: 2-3 + fields: + role: + type: select + disabled: true + import: + options: 'Formwork\Admin\Users\Users::availableRoles' - row6: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{user.color-scheme}}' - column2: - type: column - width: 2-3 - fields: - color-scheme: - type: togglegroup - options: - light: '{{user.color-scheme.light}}' - dark: '{{user.color-scheme.dark}}' - auto: '{{user.color-scheme.auto}}' + row6: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{user.color-scheme}}' + column2: + type: column + width: 2-3 + fields: + color-scheme: + type: togglegroup + options: + light: '{{user.color-scheme.light}}' + dark: '{{user.color-scheme.dark}}' + auto: '{{user.color-scheme.auto}}' - row7: - type: row - fields: - column1: - type: column - width: 1-3 - label: '{{user.avatar}}' - column2: - type: column - width: 2-3 - fields: - avatar: - type: file - accept: .jpg, .jpeg, .png, .gif + row7: + type: row + fields: + column1: + type: column + width: 1-3 + label: '{{user.avatar}}' + column2: + type: column + width: 2-3 + fields: + avatar: + type: file + accept: .jpg, .jpeg, .png, .gif diff --git a/formwork/src/Admin/AdminTrait.php b/formwork/src/Admin/AdminTrait.php index e931c90a..1f53a803 100644 --- a/formwork/src/Admin/AdminTrait.php +++ b/formwork/src/Admin/AdminTrait.php @@ -7,7 +7,7 @@ use Formwork\Utils\Notification; use Formwork\Utils\Registry; use Formwork\Core\Formwork; use Formwork\Core\Page; -use Formwork\Template\Scheme; +use Formwork\Schemes\Scheme; use Formwork\Utils\Header; use Formwork\Utils\HTTPRequest; use Formwork\Utils\Str; @@ -130,7 +130,7 @@ trait AdminTrait */ protected function scheme(string $template): Scheme { - return new Scheme($template); + return new Scheme(Formwork::instance()->config()->get('templates.path') . 'schemes' . DS . $template . '.yml'); } /** diff --git a/formwork/src/Admin/Controllers/Options.php b/formwork/src/Admin/Controllers/Options.php index 4c11e910..4e750acf 100644 --- a/formwork/src/Admin/Controllers/Options.php +++ b/formwork/src/Admin/Controllers/Options.php @@ -9,6 +9,7 @@ use Formwork\Core\Formwork; use Formwork\Data\DataGetter; use Formwork\Parsers\JSON; use Formwork\Parsers\YAML; +use Formwork\Schemes\Scheme; use Formwork\Utils\FileSystem; use Formwork\Utils\HTTPRequest; use Formwork\Utils\HTTPResponse; @@ -38,7 +39,7 @@ class Options extends AbstractController { $this->ensurePermission('options.system'); - $fields = new Fields(YAML::parseFile(Admin::SCHEMES_PATH . 'system.yml')); + $fields = new Fields((new Scheme(Admin::SCHEMES_PATH . 'system.yml'))->get('fields')); if (HTTPRequest::method() === 'POST') { $data = new DataGetter(HTTPRequest::postData()); @@ -78,7 +79,7 @@ class Options extends AbstractController { $this->ensurePermission('options.site'); - $fields = new Fields(YAML::parseFile(Admin::SCHEMES_PATH . 'site.yml')); + $fields = new Fields((new Scheme(Admin::SCHEMES_PATH . 'site.yml'))->get('fields')); if (HTTPRequest::method() === 'POST') { $data = new DataGetter(HTTPRequest::postData()); diff --git a/formwork/src/Admin/Controllers/Users.php b/formwork/src/Admin/Controllers/Users.php index a96ed896..aa72d825 100644 --- a/formwork/src/Admin/Controllers/Users.php +++ b/formwork/src/Admin/Controllers/Users.php @@ -14,6 +14,7 @@ use Formwork\Data\DataSetter; use Formwork\Files\Image; use Formwork\Parsers\YAML; use Formwork\Router\RouteParams; +use Formwork\Schemes\Scheme; use Formwork\Utils\FileSystem; use Formwork\Utils\HTTPRequest; @@ -111,7 +112,7 @@ class Users extends AbstractController */ public function profile(RouteParams $params): void { - $fields = new Fields(YAML::parseFile(Admin::SCHEMES_PATH . 'user.yml')); + $fields = new Fields((new Scheme(Admin::SCHEMES_PATH . 'user.yml'))->get('fields')); $user = Admin::instance()->users()->get($params->get('user')); diff --git a/formwork/src/Admin/Users/Users.php b/formwork/src/Admin/Users/Users.php index a6f82905..07b3bc1b 100644 --- a/formwork/src/Admin/Users/Users.php +++ b/formwork/src/Admin/Users/Users.php @@ -5,6 +5,7 @@ namespace Formwork\Admin\Users; use Formwork\Admin\Admin; use Formwork\Data\AssociativeCollection; use Formwork\Parsers\YAML; +use Formwork\Schemes\Scheme; use Formwork\Utils\FileSystem; class Users extends AssociativeCollection @@ -21,7 +22,7 @@ class Users extends AssociativeCollection */ public static function load(): self { - static::$roles = YAML::parseFile(Admin::SCHEMES_PATH . 'roles.yml'); + static::$roles = (new Scheme(Admin::SCHEMES_PATH . 'roles.yml'))->get('data'); $users = []; foreach (FileSystem::listFiles(Admin::ACCOUNTS_PATH) as $file) { $parsedData = YAML::parseFile(Admin::ACCOUNTS_PATH . $file); diff --git a/formwork/src/Template/Scheme.php b/formwork/src/Schemes/Scheme.php similarity index 77% rename from formwork/src/Template/Scheme.php rename to formwork/src/Schemes/Scheme.php index 60a50a2e..35e1d27a 100644 --- a/formwork/src/Template/Scheme.php +++ b/formwork/src/Schemes/Scheme.php @@ -1,11 +1,11 @@ path = Formwork::instance()->config()->get('templates.path') . 'schemes' . DS; - $this->name = $name; + $this->path = $path; + $this->name = FileSystem::name($path); - parent::__construct(YAML::parseFile($this->path . $this->name . '.yml')); + parent::__construct(YAML::parseFile($this->path)); if ($this->has('extend') && $this->get('extend') !== $this->name) { - $parent = new static($this->get('extend')); + $parent = new static(dirname($this->path) . DS . $this->get('extend') . '.yml'); $this->data = Arr::appendMissing($this->data, $parent->toArray()); } diff --git a/formwork/src/Template/Layout.php b/formwork/src/Template/Layout.php index 3de1e97e..218fdaf2 100644 --- a/formwork/src/Template/Layout.php +++ b/formwork/src/Template/Layout.php @@ -3,6 +3,7 @@ namespace Formwork\Template; use Formwork\Core\Page; +use Formwork\Schemes\Scheme; class Layout extends Template { diff --git a/formwork/src/Template/Template.php b/formwork/src/Template/Template.php index 4f23ce42..8d892375 100644 --- a/formwork/src/Template/Template.php +++ b/formwork/src/Template/Template.php @@ -5,6 +5,7 @@ namespace Formwork\Template; use Formwork\Core\Assets; use Formwork\Core\Formwork; use Formwork\Core\Page; +use Formwork\Schemes\Scheme; use Formwork\Utils\FileSystem; use BadMethodCallException; use RuntimeException; @@ -112,7 +113,7 @@ class Template if ($this->scheme !== null) { return $this->scheme; } - return $this->scheme = new Scheme($this->name); + return $this->scheme = new Scheme($this->path() . 'schemes' . DS . $this->name . '.yml'); } /**