From 77f23fb8c2edcf4b78f9cbf95c4ce853d5f8e659 Mon Sep 17 00:00:00 2001 From: aB0t Date: Mon, 16 Dec 2024 18:31:01 +0200 Subject: [PATCH] Update 2024-12-16 18:30:48 --- README.md | 7 +- .../README.md | 8 +- .../code.php | 9 +- .../code.power | 2 +- .../settings.json | 8 +- .../README.md | 59 +- .../code.php | 81 ++- .../code.power | 79 ++- .../settings.json | 10 +- .../code.php | 1 + .../settings.json | 4 +- .../README.md | 2 +- .../code.php | 2 +- .../code.power | 2 +- .../README.md | 259 ++++++- .../code.php | 325 ++++++++- .../code.power | 322 ++++++++- .../settings.json | 2 +- .../README.md | 6 +- .../code.php | 9 +- .../code.power | 6 +- .../settings.json | 6 +- .../README.md | 1 + .../code.php | 19 +- .../code.power | 19 +- .../README.md | 8 +- .../code.php | 11 +- .../code.power | 4 +- .../settings.json | 8 +- .../README.md | 314 ++++++++- .../code.php | 665 +++++++++++++++++- .../code.power | 659 ++++++++++++++++- .../settings.json | 10 +- .../README.md | 54 ++ .../code.php | 61 ++ .../code.power | 30 + .../settings.json | 28 + .../code.php | 8 +- .../README.md | 16 + .../code.php | 21 +- .../code.power | 18 +- .../settings.json | 7 +- .../code.php | 12 +- .../code.power | 12 +- .../code.php | 6 +- .../code.power | 6 +- .../README.md | 1 + .../code.php | 10 + .../code.power | 10 + .../code.php | 1 + .../settings.json | 10 +- .../README.md | 37 +- .../code.php | 74 +- .../code.power | 66 +- .../settings.json | 15 +- super-powers.json | 17 +- 56 files changed, 3188 insertions(+), 259 deletions(-) create mode 100644 src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/README.md create mode 100644 src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.php create mode 100644 src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.power create mode 100644 src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/settings.json diff --git a/README.md b/README.md index d5b4002..dc43258 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ This repository contains an index (see below) of all the approved powers within - **Namespace**: [VDM\Joomla\Abstraction](#vdm-joomla-abstraction) - **abstract class ActiveRegistry** | [Details](src/43134867-5cb8-4280-9be8-309fd2fd135f) | [Code](src/43134867-5cb8-4280-9be8-309fd2fd135f/code.php) | [Settings](src/43134867-5cb8-4280-9be8-309fd2fd135f/settings.json) | SPK: `Super---43134867_5cb8_4280_9be8_309fd2fd135f---Power` - - **abstract class BaseConfig** | [Details](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319) | [Code](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.php) | [Settings](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/settings.json) | SPK: `Super---ffbd4e1f_a342_4080_ab7d_1de3741bf319---Power` - **abstract class BaseTable** | [Details](src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6) | [Code](src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php) | [Settings](src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/settings.json) | SPK: `Super---e0f6ddbe_2a35_4537_942c_faff2ebd04f6---Power` - **abstract class Database** | [Details](src/6cbef8f8-4813-48e3-b05a-65e1aea95171) | [Code](src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php) | [Settings](src/6cbef8f8-4813-48e3-b05a-65e1aea95171/settings.json) | SPK: `Super---6cbef8f8_4813_48e3_b05a_65e1aea95171---Power` - **abstract class Factory** | [Details](src/2e5bf608-de5c-4b00-a20d-47c26aa350d9) | [Code](src/2e5bf608-de5c-4b00-a20d-47c26aa350d9/code.php) | [Settings](src/2e5bf608-de5c-4b00-a20d-47c26aa350d9/settings.json) | SPK: `Super---2e5bf608_de5c_4b00_a20d_47c26aa350d9---Power` + - **abstract class FunctionRegistry** | [Details](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319) | [Code](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.php) | [Settings](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/settings.json) | SPK: `Super---ffbd4e1f_a342_4080_ab7d_1de3741bf319---Power` - **abstract class Grep** | [Details](src/1401a167-0ce4-4f4a-afee-2d8b02ed339b) | [Code](src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.php) | [Settings](src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/settings.json) | SPK: `Super---1401a167_0ce4_4f4a_afee_2d8b02ed339b---Power` - **abstract class Model** | [Details](src/584747d1-3a86-453d-b7a3-a2219de8d777) | [Code](src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php) | [Settings](src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json) | SPK: `Super---584747d1_3a86_453d_b7a3_a2219de8d777---Power` - **abstract class PHPConfigurationChecker** | [Details](src/900456a2-feb5-48b9-9f05-c5a032a32c59) | [Code](src/900456a2-feb5-48b9-9f05-c5a032a32c59/code.php) | [Settings](src/900456a2-feb5-48b9-9f05-c5a032a32c59/settings.json) | SPK: `Super---900456a2_feb5_48b9_9f05_c5a032a32c59---Power` @@ -109,6 +109,7 @@ This repository contains an index (see below) of all the approved powers within - **Namespace**: [VDM\Joomla\Componentbuilder\Abstraction](#vdm-joomla-componentbuilder-abstraction) - **abstract class BaseRegistry** | [Details](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c) | [Code](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/code.php) | [Settings](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/settings.json) | SPK: `Super---b84e947d_2a13_44f7_ac0f_3902ae55ae0c---Power` + - **abstract class ComponentConfig** | [Details](src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36) | [Code](src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.php) | [Settings](src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/settings.json) | SPK: `Super---9769f3b2_17bf_4f20_b54b_3a4ebe572b36---Power` - **Namespace**: [VDM\Joomla\Componentbuilder\File](#vdm-joomla-componentbuilder-file) - **abstract class Factory** | [Details](src/884eca78-281f-4eab-b962-d97e355af16d) | [Code](src/884eca78-281f-4eab-b962-d97e355af16d/code.php) | [Settings](src/884eca78-281f-4eab-b962-d97e355af16d/settings.json) | SPK: `Super---884eca78_281f_4eab_b962_d97e355af16d---Power` @@ -193,12 +194,12 @@ This repository contains an index (see below) of all the approved powers within - **abstract class TypeHelper** | [Details](src/a8935cbe-7701-40dc-bfd5-675f2d600954) | [Code](src/a8935cbe-7701-40dc-bfd5-675f2d600954/code.php) | [Settings](src/a8935cbe-7701-40dc-bfd5-675f2d600954/settings.json) | SPK: `Super---a8935cbe_7701_40dc_bfd5_675f2d600954---Power` - **Namespace**: [VDM\Joomla\Abstraction\Registry\Traits](#vdm-joomla-abstraction-registry-traits) - - **trait Count** | [Details](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8) | [Code](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.php) | [Settings](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/settings.json) | SPK: `Super---11572d9b_e3d5_4b29_904c_9618d8f2bfd8---Power` - **trait GetString** | [Details](src/59b1a2ea-d77e-4040-ac8c-e65cd8743e9b) | [Code](src/59b1a2ea-d77e-4040-ac8c-e65cd8743e9b/code.php) | [Settings](src/59b1a2ea-d77e-4040-ac8c-e65cd8743e9b/settings.json) | SPK: `Super---59b1a2ea_d77e_4040_ac8c_e65cd8743e9b---Power` - **trait InArray** | [Details](src/215b35ac-1b26-4838-bbcf-d1fdbbd9353f) | [Code](src/215b35ac-1b26-4838-bbcf-d1fdbbd9353f/code.php) | [Settings](src/215b35ac-1b26-4838-bbcf-d1fdbbd9353f/settings.json) | SPK: `Super---215b35ac_1b26_4838_bbcf_d1fdbbd9353f---Power` - **trait IsArray** | [Details](src/c09e8968-c767-4175-bb3d-8432f206a2c7) | [Code](src/c09e8968-c767-4175-bb3d-8432f206a2c7/code.php) | [Settings](src/c09e8968-c767-4175-bb3d-8432f206a2c7/settings.json) | SPK: `Super---c09e8968_c767_4175_bb3d_8432f206a2c7---Power` - **trait IsString** | [Details](src/ff7d0111-8f79-42aa-ac14-b53ba2c49369) | [Code](src/ff7d0111-8f79-42aa-ac14-b53ba2c49369/code.php) | [Settings](src/ff7d0111-8f79-42aa-ac14-b53ba2c49369/settings.json) | SPK: `Super---ff7d0111_8f79_42aa_ac14_b53ba2c49369---Power` - - **trait ToString** | [Details](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e) | [Code](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.php) | [Settings](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/settings.json) | SPK: `Super---7d494d91_ab60_43cd_aecf_d50e07f7f30e---Power` + - **trait PathCount** | [Details](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8) | [Code](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.php) | [Settings](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/settings.json) | SPK: `Super---11572d9b_e3d5_4b29_904c_9618d8f2bfd8---Power` + - **trait PathToString** | [Details](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e) | [Code](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.php) | [Settings](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/settings.json) | SPK: `Super---7d494d91_ab60_43cd_aecf_d50e07f7f30e---Power` - **trait VarExport** | [Details](src/52a1d14f-304a-431c-8fa4-411179942db5) | [Code](src/52a1d14f-304a-431c-8fa4-411179942db5/code.php) | [Settings](src/52a1d14f-304a-431c-8fa4-411179942db5/settings.json) | SPK: `Super---52a1d14f_304a_431c_8fa4_411179942db5---Power` - **Namespace**: [VDM\Joomla\Componentbuilder\File\Service](#vdm-joomla-componentbuilder-file-service) diff --git a/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/README.md b/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/README.md index 1bfcce9..0654204 100644 --- a/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/README.md +++ b/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/README.md @@ -6,16 +6,16 @@ ██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ ``` -# trait Count (Details) +# trait PathCount (Details) > namespace: **VDM\Joomla\Abstraction\Registry\Traits** ```uml @startuml -class Count << (T,Orange) >> #Turquoise { - + count(string $path) : int +class PathCount << (T,Orange) >> #Turquoise { + + pathCount(string $path) : int } -note right of Count::count +note right of PathCount::pathCount Retrieves number of values (or sub-array) from the storage using multiple keys. since: 3.2.0 diff --git a/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.php b/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.php index 5584a9f..9d65954 100644 --- a/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.php +++ b/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.php @@ -13,11 +13,12 @@ namespace VDM\Joomla\Abstraction\Registry\Traits; /** - * Count Values + * Count Values in a Path * - * @since 3.2.0 + * @since 3.2.0 + * @since 5.0.2 name changed to PathCount to avoid collusion in core registry class */ -trait Count +trait PathCount { /** * Retrieves number of values (or sub-array) from the storage using multiple keys. @@ -28,7 +29,7 @@ trait Count * @return int The number of values * @since 3.2.0 */ - public function count(string $path): int + public function pathCount(string $path): int { if (($values = $this->get($path)) === null) { diff --git a/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.power b/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.power index 9f6ecec..25dce18 100644 --- a/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.power +++ b/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.power @@ -7,7 +7,7 @@ * @return int The number of values * @since 3.2.0 */ - public function count(string $path): int + public function pathCount(string $path): int { if (($values = $this->get($path)) === null) { diff --git a/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/settings.json b/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/settings.json index 6ecbace..4edd55d 100644 --- a/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/settings.json +++ b/src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/settings.json @@ -5,14 +5,14 @@ "guid": "11572d9b-e3d5-4b29-904c-9618d8f2bfd8", "implements": null, "load_selection": null, - "name": "Count", + "name": "PathCount", "power_version": "1.0.0", - "system_name": "VDM.Abstraction.Registry.Traits.Count", + "system_name": "VDM.Abstraction.Registry.Traits.PathCount", "type": "trait", "use_selection": null, "extendsinterfaces": null, - "namespace": "[[[NamespacePrefix]]]\\Joomla\\Abstraction.Registry.Traits.Count", - "description": "Count Values\r\n\r\n@since 3.2.0", + "namespace": "[[[NamespacePrefix]]]\\Joomla\\Abstraction.Registry.Traits.PathCount", + "description": "Count Values in a Path\r\n\r\n@since 3.2.0\r\n@since 5.0.2 name changed to PathCount to avoid collusion in core registry class", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", "head": "", "composer": "" diff --git a/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/README.md b/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/README.md index 891988b..16d22a9 100644 --- a/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/README.md +++ b/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/README.md @@ -14,10 +14,12 @@ abstract Grep #Orange { + ?string $path + ?array $paths + # ?string $target # array $order # Contents $contents + # Resolve $resolve # CMSApplication $app - + __construct(Contents $contents, array $paths, ...) + + __construct(Contents $contents, Resolve $resolve, ...) + get(string $guid, ?array $order = null, ...) : ?object + exists(string $guid, ?object $repo = null, ...) : bool + getRemoteGuid() : ?array @@ -25,6 +27,7 @@ abstract Grep #Orange { + setBranchDefaultName(?string $name) : void + setIndexPath(string $indexPath) : void + getRemoteIndex(string $guid) : ?object + + loadApi(Api $api, ?string $base, ...) : void # {abstract} setRemoteIndexMessage(string $message, string $path, ...) : void # getFunctionName(string $name, string $type = 'search') : ?string # searchSingleRepo(string $guid, array $order, ...) : ?object @@ -53,6 +56,7 @@ note right of Grep::__construct arguments: Contents $contents + Resolve $resolve array $paths ?string $path = null ?CMSApplication $app = null @@ -117,7 +121,22 @@ note left of Grep::getRemoteIndex return: ?object end note -note right of Grep::setRemoteIndexMessage +note right of Grep::loadApi + Loads API config using the provided base URL and token. +This method checks if the base URL contains 'https://git.vdm.dev/'. +If it does, it uses the token as is (which may be null). +If not, it ensures the token is not null by defaulting to an empty string. + + since: 5.0.4 + return: void + + arguments: + Api $api + ?string $base + ?string $token +end note + +note left of Grep::setRemoteIndexMessage Set repository messages and errors based on given conditions. since: 3.2.0 @@ -131,14 +150,14 @@ note right of Grep::setRemoteIndexMessage ?string $base end note -note left of Grep::getFunctionName +note right of Grep::getFunctionName Get function name since: 3.2.0 return: ?string end note -note right of Grep::searchSingleRepo +note left of Grep::searchSingleRepo Search a single repository for an item since: 3.2.2 @@ -150,14 +169,14 @@ note right of Grep::searchSingleRepo object $repo end note -note left of Grep::searchAllRepos +note right of Grep::searchAllRepos Search all repositories for an item since: 3.2.2 return: ?object end note -note right of Grep::itemExistsInRepo +note left of Grep::itemExistsInRepo Check if an item exists in a specific repository. since: 3.2.2 @@ -169,42 +188,42 @@ note right of Grep::itemExistsInRepo array $order end note -note left of Grep::itemExistsInAllRepos +note right of Grep::itemExistsInAllRepos Check if an item exists in any of the repositories. since: 3.2.2 return: bool end note -note right of Grep::getBranchField +note left of Grep::getBranchField Get the branch field since: 3.2.2 return: string end note -note left of Grep::getBranchDefaultName +note right of Grep::getBranchDefaultName Get the branch default name since: 3.2.2 return: ?string end note -note right of Grep::getBranchName +note left of Grep::getBranchName Get the branch name since: 3.2.2 return: ?string end note -note left of Grep::getIndexPath +note right of Grep::getIndexPath Get the index path since: 3.2.2 return: string end note -note right of Grep::itemExists +note left of Grep::itemExists Check if an item exists in a specific repo and target. since: 3.2.2 @@ -216,56 +235,56 @@ note right of Grep::itemExists string $target end note -note left of Grep::existsLocally +note right of Grep::existsLocally Check if item exists locally since: 3.2.2 return: ?object end note -note right of Grep::existsRemotely +note left of Grep::existsRemotely Check if item exists remotely since: 3.2.2 return: ?object end note -note left of Grep::existsLocal +note right of Grep::existsLocal Check if item exists locally since: 3.2.2 return: bool end note -note right of Grep::existsRemote +note left of Grep::existsRemote Check if item exists remotely since: 3.2.2 return: bool end note -note left of Grep::indexRemote +note right of Grep::indexRemote Load the remote repository index of powers since: 3.2.0 return: void end note -note right of Grep::indexLocal +note left of Grep::indexLocal Load the local repository index of powers since: 3.2.0 return: void end note -note left of Grep::initializeInstances +note right of Grep::initializeInstances Set path details since: 3.2.0 return: void end note -note right of Grep::loadRemoteFile +note left of Grep::loadRemoteFile Load the remote file since: 3.2.0 diff --git a/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.php b/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.php index 8cac2a3..3730873 100644 --- a/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.php +++ b/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.php @@ -17,6 +17,8 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Application\CMSApplication; use VDM\Joomla\Gitea\Repository\Contents; +use VDM\Joomla\Interfaces\Git\ApiInterface as Api; +use VDM\Joomla\Componentbuilder\Network\Resolve; use VDM\Joomla\Utilities\FileHelper; use VDM\Joomla\Utilities\JsonHelper; use VDM\Joomla\Interfaces\GrepInterface; @@ -50,6 +52,14 @@ abstract class Grep implements GrepInterface **/ public ?array $paths; + /** + * The Grep target [network] + * + * @var string + * @since 5.0.4 + **/ + protected ?string $target = null; + /** * Order of global search * @@ -82,6 +92,14 @@ abstract class Grep implements GrepInterface */ protected string $index_path = 'index.json'; + /** + * The VDM global API base + * + * @var string + * @since 5.0.4 + **/ + protected string $api_base = '//git.vdm.dev/'; + /** * Gitea Repository Contents * @@ -90,6 +108,14 @@ abstract class Grep implements GrepInterface **/ protected Contents $contents; + /** + * The Resolve Class. + * + * @var Resolve + * @since 5.0.4 + */ + protected Resolve $resolve; + /** * Joomla Application object * @@ -101,17 +127,22 @@ abstract class Grep implements GrepInterface /** * Constructor. * - * @param Contents $contents The Gitea Repository Contents object. - * @param array $paths The approved paths - * @param string|null $path The local path - * @param CMSApplication|null $app The CMS Application object. + * @param Contents $contents The Gitea Repository Contents object. + * @param Resolve $resolve The Resolve Class. + * @param array $paths The approved paths + * @param string|null $path The local path + * @param CMSApplication|null $app The CMS Application object. * * @throws \Exception * @since 3.2.0 */ - public function __construct(Contents $contents, array $paths, ?string $path = null, ?CMSApplication $app = null) + public function __construct( + Contents $contents, Resolve $resolve, + array $paths, ?string $path = null, + ?CMSApplication $app = null) { $this->contents = $contents; + $this->resolve = $resolve; $this->paths = $paths; $this->path = $path; $this->app = $app ?: Factory::getApplication(); @@ -264,6 +295,38 @@ abstract class Grep implements GrepInterface return null; } + /** + * Loads API config using the provided base URL and token. + * + * This method checks if the base URL contains 'https://git.vdm.dev/'. + * If it does, it uses the token as is (which may be null). + * If not, it ensures the token is not null by defaulting to an empty string. + * + * @param Api $api The api object with a load_ method. + * @param string|null $base The base URL path. + * @param string|null $token The token for authentication (can be null). + * + * @return void + * @since 5.0.4 + */ + public function loadApi(Api $api, ?string $base, ?string $token): void + { + // Determine the token to use based on the base URL + if ($base && strpos($base, $this->api_base) !== false) + { + // If base contains $this->api_base = https://git.vdm.dev/, use the token as is + $tokenToUse = $token; + } + else + { + // Otherwise, ensure the token is not null (use empty string if null) + $tokenToUse = $token ?? ''; + } + + // Load the content with the determined base and token + $api->load_($base, $tokenToUse); + } + /** * Set repository messages and errors based on given conditions. * @@ -584,7 +647,7 @@ abstract class Grep implements GrepInterface try { // load the base and token if set - $this->contents->load_($path->base ?? null, $path->token ?? null); + $this->loadApi($this->contents, $path->base ?? null, $path->token ?? null); $path->index = $this->contents->get($path->organisation, $path->repository, $this->getIndexPath(), $this->getBranchName($path)); } catch (\Exception $e) @@ -640,6 +703,12 @@ abstract class Grep implements GrepInterface if (isset($path->organisation) && strlen($path->organisation) > 1 && isset($path->repository) && strlen($path->repository) > 1) { + // resolve API if needed + if (!empty($path->base)) + { + $this->resolve->api($this->target ?? $path->repository, $path->base, $path->organisation, $path->repository); + } + // build the path $path->path = trim($path->organisation) . '/' . trim($path->repository); diff --git a/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.power b/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.power index 25fec34..992e4f7 100644 --- a/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.power +++ b/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.power @@ -14,6 +14,14 @@ **/ public ?array $paths; + /** + * The Grep target [network] + * + * @var string + * @since 5.0.4 + **/ + protected ?string $target = null; + /** * Order of global search * @@ -46,6 +54,14 @@ */ protected string $index_path = 'index.json'; + /** + * The VDM global API base + * + * @var string + * @since 5.0.4 + **/ + protected string $api_base = '//git.vdm.dev/'; + /** * Gitea Repository Contents * @@ -54,6 +70,14 @@ **/ protected Contents $contents; + /** + * The Resolve Class. + * + * @var Resolve + * @since 5.0.4 + */ + protected Resolve $resolve; + /** * Joomla Application object * @@ -65,17 +89,22 @@ /** * Constructor. * - * @param Contents $contents The Gitea Repository Contents object. - * @param array $paths The approved paths - * @param string|null $path The local path - * @param CMSApplication|null $app The CMS Application object. + * @param Contents $contents The Gitea Repository Contents object. + * @param Resolve $resolve The Resolve Class. + * @param array $paths The approved paths + * @param string|null $path The local path + * @param CMSApplication|null $app The CMS Application object. * * @throws \Exception * @since 3.2.0 */ - public function __construct(Contents $contents, array $paths, ?string $path = null, ?CMSApplication $app = null) + public function __construct( + Contents $contents, Resolve $resolve, + array $paths, ?string $path = null, + ?CMSApplication $app = null) { $this->contents = $contents; + $this->resolve = $resolve; $this->paths = $paths; $this->path = $path; $this->app = $app ?: Factory::getApplication(); @@ -228,6 +257,38 @@ return null; } + /** + * Loads API config using the provided base URL and token. + * + * This method checks if the base URL contains 'https://git.vdm.dev/'. + * If it does, it uses the token as is (which may be null). + * If not, it ensures the token is not null by defaulting to an empty string. + * + * @param Api $api The api object with a load_ method. + * @param string|null $base The base URL path. + * @param string|null $token The token for authentication (can be null). + * + * @return void + * @since 5.0.4 + */ + public function loadApi(Api $api, ?string $base, ?string $token): void + { + // Determine the token to use based on the base URL + if ($base && strpos($base, $this->api_base) !== false) + { + // If base contains $this->api_base = https://git.vdm.dev/, use the token as is + $tokenToUse = $token; + } + else + { + // Otherwise, ensure the token is not null (use empty string if null) + $tokenToUse = $token ?? ''; + } + + // Load the content with the determined base and token + $api->load_($base, $tokenToUse); + } + /** * Set repository messages and errors based on given conditions. * @@ -548,7 +609,7 @@ try { // load the base and token if set - $this->contents->load_($path->base ?? null, $path->token ?? null); + $this->loadApi($this->contents, $path->base ?? null, $path->token ?? null); $path->index = $this->contents->get($path->organisation, $path->repository, $this->getIndexPath(), $this->getBranchName($path)); } catch (\Exception $e) @@ -604,6 +665,12 @@ if (isset($path->organisation) && strlen($path->organisation) > 1 && isset($path->repository) && strlen($path->repository) > 1) { + // resolve API if needed + if (!empty($path->base)) + { + $this->resolve->api($this->target ?? $path->repository, $path->base, $path->organisation, $path->repository); + } + // build the path $path->path = trim($path->organisation) . '/' . trim($path->repository); diff --git a/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/settings.json b/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/settings.json index 9f82307..ae14bb8 100644 --- a/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/settings.json +++ b/src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/settings.json @@ -17,10 +17,18 @@ "as": "default" }, "use_selection1": { + "use": "17ed2fec-49d6-4731-92c3-f9cd78fb6273", + "as": "Api" + }, + "use_selection2": { + "use": "a0c143af-3d7d-4c19-91c4-f72060b4c361", + "as": "default" + }, + "use_selection3": { "use": "a223b31e-ea1d-4cdf-92ae-5f9becffaff0", "as": "default" }, - "use_selection2": { + "use_selection4": { "use": "4b225c51-d293-48e4-b3f6-5136cf5c3f18", "as": "default" } diff --git a/src/19a66b48-620c-439b-ab8a-3c0d43e040c3/code.php b/src/19a66b48-620c-439b-ab8a-3c0d43e040c3/code.php index aed6cae..bb98674 100644 --- a/src/19a66b48-620c-439b-ab8a-3c0d43e040c3/code.php +++ b/src/19a66b48-620c-439b-ab8a-3c0d43e040c3/code.php @@ -12,6 +12,7 @@ namespace VDM\Joomla\Componentbuilder\Import; +use Joomla\CMS\Language\Text; use VDM\Joomla\Componentbuilder\Import\Data; use VDM\Joomla\Componentbuilder\Interfaces\ImportStatusInterface as Status; use VDM\Joomla\Componentbuilder\Interfaces\ImportMessageInterface as Message; diff --git a/src/19a66b48-620c-439b-ab8a-3c0d43e040c3/settings.json b/src/19a66b48-620c-439b-ab8a-3c0d43e040c3/settings.json index 7081628..bf10d36 100644 --- a/src/19a66b48-620c-439b-ab8a-3c0d43e040c3/settings.json +++ b/src/19a66b48-620c-439b-ab8a-3c0d43e040c3/settings.json @@ -1,5 +1,5 @@ { - "add_head": "0", + "add_head": "1", "add_licensing_template": "2", "extends": "", "guid": "19a66b48-620c-439b-ab8a-3c0d43e040c3", @@ -29,6 +29,6 @@ "namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Import.Assessor", "description": "Import Assessor Class\r\n\r\n@since 4.0.3", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", - "head": "", + "head": "use Joomla\\CMS\\Language\\Text;", "composer": "" } \ No newline at end of file diff --git a/src/584747d1-3a86-453d-b7a3-a2219de8d777/README.md b/src/584747d1-3a86-453d-b7a3-a2219de8d777/README.md index 3ad9612..7aa75d3 100644 --- a/src/584747d1-3a86-453d-b7a3-a2219de8d777/README.md +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/README.md @@ -67,7 +67,7 @@ end note note left of Model::values Model a value of multiple items -Example: $this->items(Array, 'value_key', 'table_name'); +Example: $this->values(Array, 'value_key', 'table_name'); since: 3.2.2 return: ?array diff --git a/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php index 1f6606c..d695f6e 100644 --- a/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php @@ -109,7 +109,7 @@ abstract class Model implements ModelInterface /** * Model a value of multiple items - * Example: $this->items(Array, 'value_key', 'table_name'); + * Example: $this->values(Array, 'value_key', 'table_name'); * * @param array|null $items The array of values * @param string $field The field key diff --git a/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.power b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.power index dc2d8b9..15f6419 100644 --- a/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.power +++ b/src/584747d1-3a86-453d-b7a3-a2219de8d777/code.power @@ -82,7 +82,7 @@ /** * Model a value of multiple items - * Example: $this->items(Array, 'value_key', 'table_name'); + * Example: $this->values(Array, 'value_key', 'table_name'); * * @param array|null $items The array of values * @param string $field The field key diff --git a/src/64e291c2-11f1-423d-a44d-837cc12cc017/README.md b/src/64e291c2-11f1-423d-a44d-837cc12cc017/README.md index 04c5640..3f44f9c 100644 --- a/src/64e291c2-11f1-423d-a44d-837cc12cc017/README.md +++ b/src/64e291c2-11f1-423d-a44d-837cc12cc017/README.md @@ -13,14 +13,125 @@ ```uml @startuml interface Registryinterface #Lavender { + + __get(string $name) : mixed + + __set(string $name, mixed $value) : void + + __isset(string $name) : bool + + __unset(string $name) : void + + __clone() : void + + __toString() : string + + loadString(string $data, string $format = 'JSON', ...) : self + + loadObject(object $object) : self + + loadArray(array $array) : self + + loadFile(string $path, string $format = 'json') : self + set(string $path, mixed $value) : self + add(string $path, mixed $value, ...) : self + get(string $path, mixed $default = null) : mixed + remove(string $path) : self + exists(string $path) : bool + + jsonSerialize() : mixed + + count() : int + + offsetExists(mixed $offset) : bool + + offsetGet(mixed $offset) : mixed + + offsetSet(mixed $offset, mixed $value) : void + + offsetUnset(mixed $offset) : void + + getIterator() : \Traversable + + toArray() : array + + toObject() : object + + toString(string $format = 'JSON', array $options = []) : string + + flatten(?string $separator = null, bool $full = false) : array + + def(string $path, mixed $default) : mixed + + merge(Registryinterface $source) : self + + clear() : self + + extract(string $path, mixed $default = null, ...) : self + + append(string $path, mixed $value) : self + + getName() : ?string + + setName(?string $name) : self + setSeparator(?string $value) : self + + getSeparator() : ?string } +note right of Registryinterface::__get + Magic method to get a value from the registry. +Allows for accessing registry data using object property syntax. + + since: 5.0.4 + return: mixed +end note + +note left of Registryinterface::__set + Magic method to set a value in the registry. +Allows for setting registry data using object property syntax. + + since: 5.0.4 + return: void +end note + +note right of Registryinterface::__isset + Magic method to check if a property is set in the registry. +Allows for using isset() on registry properties. + + since: 5.0.4 + return: bool +end note + +note left of Registryinterface::__unset + Magic method to unset a property in the registry. +Allows for using unset() on registry properties. + + since: 5.0.4 + return: void +end note + +note right of Registryinterface::__clone + Magic method to clone the registry. +Performs a deep copy of the registry data. + + since: 5.0.4 + return: void +end note + +note left of Registryinterface::__toString + Magic method to convert the registry to a string. +Returns the registry data in JSON format. + + since: 5.0.4 + return: string +end note + +note right of Registryinterface::loadString + Loads data into the registry from a string using Joomla's format classes. + + since: 5.0.4 + return: self + + arguments: + string $data + string $format = 'JSON' + array $options = [] +end note + +note left of Registryinterface::loadObject + Loads data into the registry from an object. + + since: 5.0.4 + return: self +end note + +note right of Registryinterface::loadArray + Loads data into the registry from an array. +The loaded data will be merged into the registry's existing data. + + since: 5.0.4 + return: self +end note + +note left of Registryinterface::loadFile + Loads data into the registry from a file. + + since: 5.0.4 + return: self +end note + note right of Registryinterface::set Sets a value into the registry using multiple keys. @@ -28,7 +139,7 @@ note right of Registryinterface::set return: self end note -note right of Registryinterface::add +note left of Registryinterface::add Adds content into the registry. If a key exists, it either appends or concatenates based on $asArray switch. Default is $addAsArray = false (if null) in base class. @@ -50,7 +161,7 @@ note right of Registryinterface::get return: mixed end note -note right of Registryinterface::remove +note left of Registryinterface::remove Removes a value (or sub-array) from the registry using multiple keys. since: 3.2.0 @@ -64,12 +175,154 @@ note right of Registryinterface::exists return: bool end note -note right of Registryinterface::setSeparator +note left of Registryinterface::jsonSerialize + Specify data which should be serialized to JSON. +which is a value of any type other than a resource. + + since: 5.0.4 + return: mixed +end note + +note right of Registryinterface::count + Count elements of the registry. + + since: 5.0.4 + return: int +end note + +note left of Registryinterface::offsetExists + Whether a given offset exists in the registry. + + since: 5.0.4 + return: bool +end note + +note right of Registryinterface::offsetGet + Retrieve the value at a given offset. + + since: 5.0.4 + return: mixed +end note + +note left of Registryinterface::offsetSet + Set the value at a given offset. + + since: 5.0.4 + return: void +end note + +note right of Registryinterface::offsetUnset + Unset the value at a given offset. + + since: 5.0.4 + return: void +end note + +note left of Registryinterface::getIterator + Retrieve an external iterator for the registry. + + since: 5.0.4 + return: \Traversable +end note + +note right of Registryinterface::toArray + Get the registry data as an associative array. + + since: 5.0.4 + return: array +end note + +note left of Registryinterface::toObject + Get the registry data as an object. + + since: 5.0.4 + return: object +end note + +note right of Registryinterface::toString + Converts the registry data to a string in the specified format. + + since: 5.0.4 + return: string +end note + +note left of Registryinterface::flatten + Flattens the registry data into a one-dimensional array. + + since: 5.0.4 + return: array +end note + +note right of Registryinterface::def + Sets a default value if not already set. + + since: 5.0.4 + return: mixed +end note + +note left of Registryinterface::merge + Merges another registry into this one. +The data from the source registry will be merged into this registry, +overwriting any existing values with the same keys. + + since: 5.0.4 + return: self +end note + +note right of Registryinterface::clear + Clears all data from the registry. + + since: 5.0.4 + return: self +end note + +note left of Registryinterface::extract + Extracts a subset of the registry data based on a given path. + + since: 5.0.4 + return: self + + arguments: + string $path + mixed $default = null + ?string $separator = null +end note + +note right of Registryinterface::append + Appends content into the registry. +If a key exists, the value will be appended to the existing value. + + since: 5.0.4 + return: self +end note + +note left of Registryinterface::getName + Gets the name of the registry. + + since: 5.0.4 + return: ?string +end note + +note right of Registryinterface::setName + Sets the name of the registry. + + since: 5.0.4 + return: self +end note + +note left of Registryinterface::setSeparator Sets a separator value since: 3.2.0 return: self end note + +note right of Registryinterface::getSeparator + Gets the current path separator used in registry paths. + + since: 5.0.4 + return: ?string +end note @enduml ``` diff --git a/src/64e291c2-11f1-423d-a44d-837cc12cc017/code.php b/src/64e291c2-11f1-423d-a44d-837cc12cc017/code.php index 58aae26..272dedf 100644 --- a/src/64e291c2-11f1-423d-a44d-837cc12cc017/code.php +++ b/src/64e291c2-11f1-423d-a44d-837cc12cc017/code.php @@ -18,10 +18,128 @@ use VDM\Joomla\Interfaces\Activeregistryinterface; /** * The Registry Interface * - * @since 3.2.0 + * @since 3.2.0 + * @since 5.0.4 Joomla Registry Compatible */ interface Registryinterface extends Activeregistryinterface { + /** + * Magic method to get a value from the registry. + * + * Allows for accessing registry data using object property syntax. + * + * @param string $name The name of the property to get. + * + * @return mixed The value of the property, or null if not found. + * @since 5.0.4 + */ + public function __get($name); + + /** + * Magic method to set a value in the registry. + * + * Allows for setting registry data using object property syntax. + * + * @param string $name The name of the property to set. + * @param mixed $value The value to set. + * + * @return void + * @since 5.0.4 + */ + public function __set($name, $value); + + /** + * Magic method to check if a property is set in the registry. + * + * Allows for using isset() on registry properties. + * + * @param string $name The name of the property to check. + * + * @return bool True if the property is set, false otherwise. + * @since 5.0.4 + */ + public function __isset($name); + + /** + * Magic method to unset a property in the registry. + * + * Allows for using unset() on registry properties. + * + * @param string $name The name of the property to unset. + * + * @return void + * @since 5.0.4 + */ + public function __unset($name); + + /** + * Magic method to clone the registry. + * + * Performs a deep copy of the registry data. + * + * @return void + * @since 5.0.4 + */ + public function __clone(); + + /** + * Magic method to convert the registry to a string. + * + * Returns the registry data in JSON format. + * + * @return string The registry data in JSON format. + * @since 5.0.4 + */ + public function __toString(); + + /** + * Loads data into the registry from a string using Joomla's format classes. + * + * @param string $data The data string to load. + * @param string $format The format of the data string. Supported formats: 'json', 'ini', 'xml', 'php'. + * @param array $options Options used by the formatter + * + * @return self + * @throws \InvalidArgumentException If the format is not supported. + * @since 5.0.4 + */ + public function loadString(string $data, string $format = 'JSON', array $options = []): self; + + /** + * Loads data into the registry from an object. + * + * @param object $object The data object to load. + * + * @return self + * @since 5.0.4 + */ + public function loadObject(object $object): self; + + /** + * Loads data into the registry from an array. + * + * The loaded data will be merged into the registry's existing data. + * + * @param array $array The array of data to load into the registry. + * + * @return self + * @since 5.0.4 + */ + public function loadArray(array $array): self; + + /** + * Loads data into the registry from a file. + * + * @param string $path The path to the file to load. + * @param string $format The format of the file. Supported formats: 'json', 'ini', 'xml', 'php'. + * + * @return self + * @throws \InvalidArgumentException If the file does not exist or is not readable. + * @throws \RuntimeException If the file cannot be read. + * @since 5.0.4 + */ + public function loadFile(string $path, string $format = 'json'): self; + /** * Sets a value into the registry using multiple keys. * @@ -30,7 +148,7 @@ interface Registryinterface extends Activeregistryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function set(string $path, $value): self; @@ -46,7 +164,7 @@ interface Registryinterface extends Activeregistryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function add(string $path, $value, ?bool $asArray = null): self; @@ -58,9 +176,9 @@ interface Registryinterface extends Activeregistryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return mixed The value or sub-array from the storage. Null if the location doesn't exist. - * @since 3.2.0 + * @since 3.2.0 */ - public function get(string $path, $default = null); + public function get(string $path, $default = null): mixed; /** * Removes a value (or sub-array) from the registry using multiple keys. @@ -69,7 +187,7 @@ interface Registryinterface extends Activeregistryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function remove(string $path): self; @@ -80,18 +198,207 @@ interface Registryinterface extends Activeregistryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return bool True if the location exists, false otherwise. - * @since 3.2.0 + * @since 3.2.0 */ public function exists(string $path): bool; + /** + * Specify data which should be serialized to JSON. + * + * @return mixed Data which can be serialized by json_encode(), + * which is a value of any type other than a resource. + * @since 5.0.4 + */ + public function jsonSerialize(): mixed; + + /** + * Count elements of the registry. + * + * @return int The number of elements in the registry. + * @since 5.0.4 + */ + public function count(): int; + + /** + * Whether a given offset exists in the registry. + * + * @param mixed $offset An offset to check for. + * + * @return bool True if the offset exists, false otherwise. + * @since 5.0.4 + */ + public function offsetExists(mixed $offset): bool; + + /** + * Retrieve the value at a given offset. + * + * @param mixed $offset The offset to retrieve. + * + * @return mixed The value at the specified offset. + * @since 5.0.4 + */ + public function offsetGet(mixed $offset): mixed; + + /** + * Set the value at a given offset. + * + * @param mixed $offset The offset to assign the value to. + * @param mixed $value The value to set. + * + * @return void + * @since 5.0.4 + */ + public function offsetSet(mixed $offset, mixed $value): void; + + /** + * Unset the value at a given offset. + * + * @param mixed $offset The offset to unset. + * + * @return void + * @since 5.0.4 + */ + public function offsetUnset(mixed $offset): void; + + /** + * Retrieve an external iterator for the registry. + * + * @return \Traversable An instance of an object implementing Iterator or Traversable. + * @since 5.0.4 + */ + public function getIterator(): \Traversable; + + /** + * Get the registry data as an associative array. + * + * @return array The registry data. + * @since 5.0.4 + */ + public function toArray(): array; + + /** + * Get the registry data as an object. + * + * @return object The registry data converted to an object. + * @since 5.0.4 + */ + public function toObject(); + + /** + * Converts the registry data to a string in the specified format. + * + * @param string $format The format to output the string in. Supported formats: 'json', 'ini', 'xml', 'php'. + * @param array $options Options used by the formatter. + * + * @return string The registry data in the specified format. + * + * @throws \InvalidArgumentException If the format is not supported. + * @since 5.0.4 + */ + public function toString(string $format = 'JSON', array $options = []): string; + + /** + * Flattens the registry data into a one-dimensional array. + * + * @param string|null $separator The separator for the key names. + * @param bool $full True to include the full path as keys. + * + * @return array The flattened data array. + * @since 5.0.4 + */ + public function flatten(?string $separator = null, bool $full = false): array; + + /** + * Sets a default value if not already set. + * + * @param string $path The registry path (e.g., 'vdm.content.builder'). + * @param mixed $default The default value to set if the path does not exist. + * + * @return mixed The value of the path after the method call. + * @since 5.0.4 + */ + public function def(string $path, $default); + + /** + * Merges another registry into this one. + * + * The data from the source registry will be merged into this registry, + * overwriting any existing values with the same keys. + * + * @param Registryinterface $source The registry to merge with this one. + * + * @return self + * @since 5.0.4 + */ + public function merge(Registryinterface $source): self; + + /** + * Clears all data from the registry. + * + * @return self + * @since 5.0.4 + */ + public function clear(): self; + + /** + * Extracts a subset of the registry data based on a given path. + * + * @param string $path The registry path to extract. + * @param mixed $default Optional default value, returned if the path does not exist. + * @param string|null $separator The path separator. + * + * @return self A new Registry instance with the extracted data. + * @since 5.0.4 + */ + public function extract(string $path, $default = null, ?string $separator = null): self; + + /** + * Appends content into the registry. + * + * If a key exists, the value will be appended to the existing value. + * + * @param string $path The registry path (e.g., 'vdm.content.builder'). + * @param mixed $value The value to append. + * + * @return self + * @since 5.0.4 + */ + public function append(string $path, $value): self; + + /** + * Gets the name of the registry. + * + * @return string|null The name of the registry. + * @since 5.0.4 + */ + public function getName(): ?string; + + /** + * Sets the name of the registry. + * + * @param string|null $name The name to set. + * + * @return self + * @since 5.0.4 + */ + public function setName(?string $name): self; + /** * Sets a separator value * * @param string|null $value The value to set. * * @return self - * @since 3.2.0 + * @since 3.2.0 */ - public function setSeparator(?string $value): self; + public function setSeparator(?string $value): self; + + /** + * Gets the current path separator used in registry paths. + * + * @return string|null The path separator. + * @since 5.0.4 + */ + public function getSeparator(): ?string; } diff --git a/src/64e291c2-11f1-423d-a44d-837cc12cc017/code.power b/src/64e291c2-11f1-423d-a44d-837cc12cc017/code.power index d049af7..f9ab1f4 100644 --- a/src/64e291c2-11f1-423d-a44d-837cc12cc017/code.power +++ b/src/64e291c2-11f1-423d-a44d-837cc12cc017/code.power @@ -1,3 +1,120 @@ + /** + * Magic method to get a value from the registry. + * + * Allows for accessing registry data using object property syntax. + * + * @param string $name The name of the property to get. + * + * @return mixed The value of the property, or null if not found. + * @since 5.0.4 + */ + public function __get($name); + + /** + * Magic method to set a value in the registry. + * + * Allows for setting registry data using object property syntax. + * + * @param string $name The name of the property to set. + * @param mixed $value The value to set. + * + * @return void + * @since 5.0.4 + */ + public function __set($name, $value); + + /** + * Magic method to check if a property is set in the registry. + * + * Allows for using isset() on registry properties. + * + * @param string $name The name of the property to check. + * + * @return bool True if the property is set, false otherwise. + * @since 5.0.4 + */ + public function __isset($name); + + /** + * Magic method to unset a property in the registry. + * + * Allows for using unset() on registry properties. + * + * @param string $name The name of the property to unset. + * + * @return void + * @since 5.0.4 + */ + public function __unset($name); + + /** + * Magic method to clone the registry. + * + * Performs a deep copy of the registry data. + * + * @return void + * @since 5.0.4 + */ + public function __clone(); + + /** + * Magic method to convert the registry to a string. + * + * Returns the registry data in JSON format. + * + * @return string The registry data in JSON format. + * @since 5.0.4 + */ + public function __toString(); + + /** + * Loads data into the registry from a string using Joomla's format classes. + * + * @param string $data The data string to load. + * @param string $format The format of the data string. Supported formats: 'json', 'ini', 'xml', 'php'. + * @param array $options Options used by the formatter + * + * @return self + * @throws \InvalidArgumentException If the format is not supported. + * @since 5.0.4 + */ + public function loadString(string $data, string $format = 'JSON', array $options = []): self; + + /** + * Loads data into the registry from an object. + * + * @param object $object The data object to load. + * + * @return self + * @since 5.0.4 + */ + public function loadObject(object $object): self; + + /** + * Loads data into the registry from an array. + * + * The loaded data will be merged into the registry's existing data. + * + * @param array $array The array of data to load into the registry. + * + * @return self + * @since 5.0.4 + */ + public function loadArray(array $array): self; + + /** + * Loads data into the registry from a file. + * + * @param string $path The path to the file to load. + * @param string $format The format of the file. Supported formats: 'json', 'ini', 'xml', 'php'. + * + * @return self + * @throws \InvalidArgumentException If the file does not exist or is not readable. + * @throws \RuntimeException If the file cannot be read. + * @since 5.0.4 + */ + public function loadFile(string $path, string $format = 'json'): self; + /** * Sets a value into the registry using multiple keys. * @@ -6,7 +123,7 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function set(string $path, $value): self; @@ -22,7 +139,7 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function add(string $path, $value, ?bool $asArray = null): self; @@ -34,9 +151,9 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return mixed The value or sub-array from the storage. Null if the location doesn't exist. - * @since 3.2.0 + * @since 3.2.0 */ - public function get(string $path, $default = null); + public function get(string $path, $default = null): mixed; /** * Removes a value (or sub-array) from the registry using multiple keys. @@ -45,7 +162,7 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function remove(string $path): self; @@ -56,16 +173,205 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return bool True if the location exists, false otherwise. - * @since 3.2.0 + * @since 3.2.0 */ public function exists(string $path): bool; + /** + * Specify data which should be serialized to JSON. + * + * @return mixed Data which can be serialized by json_encode(), + * which is a value of any type other than a resource. + * @since 5.0.4 + */ + public function jsonSerialize(): mixed; + + /** + * Count elements of the registry. + * + * @return int The number of elements in the registry. + * @since 5.0.4 + */ + public function count(): int; + + /** + * Whether a given offset exists in the registry. + * + * @param mixed $offset An offset to check for. + * + * @return bool True if the offset exists, false otherwise. + * @since 5.0.4 + */ + public function offsetExists(mixed $offset): bool; + + /** + * Retrieve the value at a given offset. + * + * @param mixed $offset The offset to retrieve. + * + * @return mixed The value at the specified offset. + * @since 5.0.4 + */ + public function offsetGet(mixed $offset): mixed; + + /** + * Set the value at a given offset. + * + * @param mixed $offset The offset to assign the value to. + * @param mixed $value The value to set. + * + * @return void + * @since 5.0.4 + */ + public function offsetSet(mixed $offset, mixed $value): void; + + /** + * Unset the value at a given offset. + * + * @param mixed $offset The offset to unset. + * + * @return void + * @since 5.0.4 + */ + public function offsetUnset(mixed $offset): void; + + /** + * Retrieve an external iterator for the registry. + * + * @return \Traversable An instance of an object implementing Iterator or Traversable. + * @since 5.0.4 + */ + public function getIterator(): \Traversable; + + /** + * Get the registry data as an associative array. + * + * @return array The registry data. + * @since 5.0.4 + */ + public function toArray(): array; + + /** + * Get the registry data as an object. + * + * @return object The registry data converted to an object. + * @since 5.0.4 + */ + public function toObject(); + + /** + * Converts the registry data to a string in the specified format. + * + * @param string $format The format to output the string in. Supported formats: 'json', 'ini', 'xml', 'php'. + * @param array $options Options used by the formatter. + * + * @return string The registry data in the specified format. + * + * @throws \InvalidArgumentException If the format is not supported. + * @since 5.0.4 + */ + public function toString(string $format = 'JSON', array $options = []): string; + + /** + * Flattens the registry data into a one-dimensional array. + * + * @param string|null $separator The separator for the key names. + * @param bool $full True to include the full path as keys. + * + * @return array The flattened data array. + * @since 5.0.4 + */ + public function flatten(?string $separator = null, bool $full = false): array; + + /** + * Sets a default value if not already set. + * + * @param string $path The registry path (e.g., 'vdm.content.builder'). + * @param mixed $default The default value to set if the path does not exist. + * + * @return mixed The value of the path after the method call. + * @since 5.0.4 + */ + public function def(string $path, $default); + + /** + * Merges another registry into this one. + * + * The data from the source registry will be merged into this registry, + * overwriting any existing values with the same keys. + * + * @param Registryinterface $source The registry to merge with this one. + * + * @return self + * @since 5.0.4 + */ + public function merge(Registryinterface $source): self; + + /** + * Clears all data from the registry. + * + * @return self + * @since 5.0.4 + */ + public function clear(): self; + + /** + * Extracts a subset of the registry data based on a given path. + * + * @param string $path The registry path to extract. + * @param mixed $default Optional default value, returned if the path does not exist. + * @param string|null $separator The path separator. + * + * @return self A new Registry instance with the extracted data. + * @since 5.0.4 + */ + public function extract(string $path, $default = null, ?string $separator = null): self; + + /** + * Appends content into the registry. + * + * If a key exists, the value will be appended to the existing value. + * + * @param string $path The registry path (e.g., 'vdm.content.builder'). + * @param mixed $value The value to append. + * + * @return self + * @since 5.0.4 + */ + public function append(string $path, $value): self; + + /** + * Gets the name of the registry. + * + * @return string|null The name of the registry. + * @since 5.0.4 + */ + public function getName(): ?string; + + /** + * Sets the name of the registry. + * + * @param string|null $name The name to set. + * + * @return self + * @since 5.0.4 + */ + public function setName(?string $name): self; + /** * Sets a separator value * * @param string|null $value The value to set. * * @return self - * @since 3.2.0 + * @since 3.2.0 */ - public function setSeparator(?string $value): self; \ No newline at end of file + public function setSeparator(?string $value): self; + + /** + * Gets the current path separator used in registry paths. + * + * @return string|null The path separator. + * @since 5.0.4 + */ + public function getSeparator(): ?string; \ No newline at end of file diff --git a/src/64e291c2-11f1-423d-a44d-837cc12cc017/settings.json b/src/64e291c2-11f1-423d-a44d-837cc12cc017/settings.json index f4f1253..555bedb 100644 --- a/src/64e291c2-11f1-423d-a44d-837cc12cc017/settings.json +++ b/src/64e291c2-11f1-423d-a44d-837cc12cc017/settings.json @@ -14,7 +14,7 @@ "af0eedbe-603b-4671-8e5a-28165d88254b" ], "namespace": "[[[NamespacePrefix]]]\\Joomla\\Interfaces.Registryinterface", - "description": "The Registry Interface\r\n\r\n@since 3.2.0", + "description": "The Registry Interface\r\n\r\n@since 3.2.0\r\n@since 5.0.4 Joomla Registry Compatible", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", "head": "", "composer": "" diff --git a/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/README.md b/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/README.md index 18cd6ba..07cf933 100644 --- a/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/README.md +++ b/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/README.md @@ -13,9 +13,9 @@ @startuml class Item << (F,LightGreen) >> #RoyalBlue { # Validator $validator - # Item $item + # DataItem $item # Row $row - + __construct(Validator $validator, Item $item, ...) + + __construct(Validator $validator, DataItem $item, ...) + get(string $table, array $columns) : ?array - getImportValue(mixed $value, string $field, ...) : mixed - validImportValue(mixed $value, string $field, ...) : mixed @@ -33,7 +33,7 @@ note right of Item::__construct arguments: Validator $validator - Item $item + DataItem $item Row $row end note diff --git a/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/code.php b/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/code.php index 692e35b..b41fbe3 100644 --- a/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/code.php +++ b/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/code.php @@ -13,8 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Import; use VDM\Joomla\Interfaces\TableValidatorInterface as Validator; -use VDM\Joomla\Interfaces\Data\ItemInterface as Item; +use VDM\Joomla\Interfaces\Data\ItemInterface as DataItem; use VDM\Joomla\Componentbuilder\Interfaces\ImportRowInterface as Row; +use VDM\Joomla\Utilities\GuidHelper; use VDM\Joomla\Componentbuilder\Interfaces\ImportItemInterface; @@ -39,7 +40,7 @@ final class Item implements ImportItemInterface * @var Item * @since 4.0.3 */ - protected Item $item; + protected DataItem $item; /** * The Import Row Class. @@ -53,12 +54,12 @@ final class Item implements ImportItemInterface * Constructor. * * @param Validator $validator The Table ValidatorI Class. - * @param Item $item The Item Class. + * @param DataItem $item The Item Class. * @param Row $row The Import Row Class. * * @since 4.0.3 */ - public function __construct(Validator $validator, Item $item, Row $row) + public function __construct(Validator $validator, DataItem $item, Row $row) { $this->validator = $validator; $this->item = $item; diff --git a/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/code.power b/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/code.power index 2036c53..5bcab11 100644 --- a/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/code.power +++ b/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/code.power @@ -12,7 +12,7 @@ * @var Item * @since 4.0.3 */ - protected Item $item; + protected DataItem $item; /** * The Import Row Class. @@ -26,12 +26,12 @@ * Constructor. * * @param Validator $validator The Table ValidatorI Class. - * @param Item $item The Item Class. + * @param DataItem $item The Item Class. * @param Row $row The Import Row Class. * * @since 4.0.3 */ - public function __construct(Validator $validator, Item $item, Row $row) + public function __construct(Validator $validator, DataItem $item, Row $row) { $this->validator = $validator; $this->item = $item; diff --git a/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/settings.json b/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/settings.json index f53b834..c4e7bae 100644 --- a/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/settings.json +++ b/src/68a0f9af-265a-4db1-bae9-a4e4531f94d7/settings.json @@ -18,11 +18,15 @@ }, "use_selection1": { "use": "05744dd3-4030-4cf8-8dda-a93ab809b473", - "as": "Item" + "as": "DataItem" }, "use_selection2": { "use": "3d3ec064-9867-41e6-a48a-964c15d753aa", "as": "Row" + }, + "use_selection3": { + "use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0", + "as": "default" } }, "extendsinterfaces": null, diff --git a/src/79fd4f39-824d-4ab6-936d-959705ff24ec/README.md b/src/79fd4f39-824d-4ab6-936d-959705ff24ec/README.md index 79932c0..c6f1c24 100644 --- a/src/79fd4f39-824d-4ab6-936d-959705ff24ec/README.md +++ b/src/79fd4f39-824d-4ab6-936d-959705ff24ec/README.md @@ -15,6 +15,7 @@ class Validator << (F,LightGreen) >> #RoyalBlue { # Table $table # array $validators # array $defaults + # array $datatypes + __construct(Table $table) + getValid(mixed $value, string $field, ...) : mixed - validate(mixed $value, array $dbField) : bool diff --git a/src/79fd4f39-824d-4ab6-936d-959705ff24ec/code.php b/src/79fd4f39-824d-4ab6-936d-959705ff24ec/code.php index d56dd9d..05a553f 100644 --- a/src/79fd4f39-824d-4ab6-936d-959705ff24ec/code.php +++ b/src/79fd4f39-824d-4ab6-936d-959705ff24ec/code.php @@ -40,13 +40,21 @@ final class Validator implements TableValidatorInterface protected array $validators = []; /** - * A map of defauts for the respective datatypes. + * A map of defaults for the respective datatypes. * * @var array * @since 5.3.0 */ protected array $defaults = []; + /** + * Cache of the parsed datatype details + * + * @var array + * @since 5.3.0 + */ + protected array $datatypes = []; + /** * Constructor. * @@ -162,14 +170,21 @@ final class Validator implements TableValidatorInterface */ private function parseDataType(string $datatype): array { + if (isset($this->datatypes[$datatype])) + { + return $this->datatypes[$datatype]; + } + $pattern = '/(?\w+)(\((?\d+)(,\s*(?\d+))?\))?/i'; preg_match($pattern, $datatype, $matches); - return [ + $result = [ 'type' => isset($matches['type']) ? strtolower($matches['type']) : strtolower($datatype), 'size' => $matches['size'] ?? null, 'precision' => $matches['precision'] ?? null, ]; + + return $this->datatypes[$datatype] = $result; } /** diff --git a/src/79fd4f39-824d-4ab6-936d-959705ff24ec/code.power b/src/79fd4f39-824d-4ab6-936d-959705ff24ec/code.power index c0ee52c..821f088 100644 --- a/src/79fd4f39-824d-4ab6-936d-959705ff24ec/code.power +++ b/src/79fd4f39-824d-4ab6-936d-959705ff24ec/code.power @@ -15,13 +15,21 @@ protected array $validators = []; /** - * A map of defauts for the respective datatypes. + * A map of defaults for the respective datatypes. * * @var array * @since 5.3.0 */ protected array $defaults = []; + /** + * Cache of the parsed datatype details + * + * @var array + * @since 5.3.0 + */ + protected array $datatypes = []; + /** * Constructor. * @@ -137,14 +145,21 @@ */ private function parseDataType(string $datatype): array { + if (isset($this->datatypes[$datatype])) + { + return $this->datatypes[$datatype]; + } + $pattern = '/(?\w+)(\((?\d+)(,\s*(?\d+))?\))?/i'; preg_match($pattern, $datatype, $matches); - return [ + $result = [ 'type' => isset($matches['type']) ? strtolower($matches['type']) : strtolower($datatype), 'size' => $matches['size'] ?? null, 'precision' => $matches['precision'] ?? null, ]; + + return $this->datatypes[$datatype] = $result; } /** diff --git a/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/README.md b/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/README.md index 3fa2191..3d80cf3 100644 --- a/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/README.md +++ b/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/README.md @@ -6,16 +6,16 @@ ██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ ``` -# trait ToString (Details) +# trait PathToString (Details) > namespace: **VDM\Joomla\Abstraction\Registry\Traits** ```uml @startuml -class ToString << (T,Orange) >> #Turquoise { - + toString(string $path, string $separator = '') : string +class PathToString << (T,Orange) >> #Turquoise { + + pathToString(string $path, string $separator = '') : string } -note right of ToString::toString +note right of PathToString::pathToString Convert an array of values to a string (or return string) since: 3.2.0 diff --git a/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.php b/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.php index 285f709..de81af0 100644 --- a/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.php +++ b/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.php @@ -13,11 +13,12 @@ namespace VDM\Joomla\Abstraction\Registry\Traits; /** - * To String Values + * Path To String Values * - * @since 3.2.0 + * @since 3.2.0 + * @since 5.0.2 name changed to PathToString to avoid collusion in core registry class */ -trait ToString +trait PathToString { /** * Convert an array of values to a string (or return string) @@ -26,9 +27,9 @@ trait ToString * @param string $seperator Return string separator * * @return string - * @since 3.2.0 + * @since 3.2.0 */ - public function toString(string $path, string $separator = ''): string + public function pathToString(string $path, string $separator = ''): string { // Return default value if path is empty if (empty($path)) diff --git a/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.power b/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.power index 90e68f7..3673b54 100644 --- a/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.power +++ b/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.power @@ -5,9 +5,9 @@ * @param string $seperator Return string separator * * @return string - * @since 3.2.0 + * @since 3.2.0 */ - public function toString(string $path, string $separator = ''): string + public function pathToString(string $path, string $separator = ''): string { // Return default value if path is empty if (empty($path)) diff --git a/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/settings.json b/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/settings.json index b46475d..777eba1 100644 --- a/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/settings.json +++ b/src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/settings.json @@ -5,14 +5,14 @@ "guid": "7d494d91-ab60-43cd-aecf-d50e07f7f30e", "implements": null, "load_selection": null, - "name": "ToString", + "name": "PathToString", "power_version": "1.0.0", - "system_name": "VDM.Abstraction.Registry.Traits.ToString", + "system_name": "VDM.Abstraction.Registry.Traits.PathToString", "type": "trait", "use_selection": null, "extendsinterfaces": null, - "namespace": "[[[NamespacePrefix]]]\\Joomla\\Abstraction.Registry.Traits.ToString", - "description": "To String Values\r\n\r\n@since 3.2.0", + "namespace": "[[[NamespacePrefix]]]\\Joomla\\Abstraction.Registry.Traits.PathToString", + "description": "Path To String Values\r\n\r\n@since 3.2.0\r\n@since 5.0.2 name changed to PathToString to avoid collusion in core registry class", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", "head": "", "composer": "" diff --git a/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/README.md b/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/README.md index 7a7f510..ab68128 100644 --- a/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/README.md +++ b/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/README.md @@ -14,16 +14,141 @@ @startuml abstract Registry #Orange { # ?string $separator + # ?string $name + + __construct(mixed $data = null, ?string $separator = null) + + __get(string $name) : mixed + + __set(string $name, mixed $value) : void + + __isset(string $name) : bool + + __unset(string $name) : void + + __clone() : void + + __toString() : string + + loadString(string $data, string $format = 'JSON', ...) : self + + loadObject(object $object) : self + + loadArray(array $array) : self + + loadFile(string $path, string $format = 'json') : self + set(string $path, mixed $value) : self + add(string $path, mixed $value, ...) : self + get(string $path, mixed $default = null) : mixed + remove(string $path) : self + exists(string $path) : bool + + jsonSerialize() : mixed + + count() : int + + offsetExists(mixed $offset) : bool + + offsetGet(mixed $offset) : mixed + + offsetSet(mixed $offset, mixed $value) : void + + offsetUnset(mixed $offset) : void + + getIterator() : \Traversable + + toArray() : array + + toObject() : object + + toString(string $format = 'JSON', array $options = []) : string + + flatten(?string $separator = null, bool $full = false) : array + + def(string $path, mixed $default) : mixed + + merge(Registryinterface $source) : self + + clear() : self + + extract(string $path, mixed $default = null, ...) : self + + append(string $path, mixed $value) : self + + getName() : ?string + + setName(?string $name) : self + setSeparator(?string $value) : self + + getSeparator() : ?string + # arrayToObject(mixed $data) : mixed + # objectToArray(mixed $data) : mixed + # arrayMergeRecursive(array $array1, array $array2) : array + # flattenArray(array $array, string $separator, ...) : array # getActiveKeys(string $path) : ?array } -note right of Registry::set +note right of Registry::__construct + Constructor. +Initializes the Registry object with optional data. +Can be an array, string, or object. + + since: 5.0.4 +end note + +note left of Registry::__get + Magic method to get a value from the registry. +Allows for accessing registry data using object property syntax. + + since: 5.0.4 + return: mixed +end note + +note right of Registry::__set + Magic method to set a value in the registry. +Allows for setting registry data using object property syntax. + + since: 5.0.4 + return: void +end note + +note left of Registry::__isset + Magic method to check if a property is set in the registry. +Allows for using isset() on registry properties. + + since: 5.0.4 + return: bool +end note + +note right of Registry::__unset + Magic method to unset a property in the registry. +Allows for using unset() on registry properties. + + since: 5.0.4 + return: void +end note + +note left of Registry::__clone + Magic method to clone the registry. +Performs a deep copy of the registry data. + + since: 5.0.4 + return: void +end note + +note right of Registry::__toString + Magic method to convert the registry to a string. +Returns the registry data in JSON format. + + since: 5.0.4 + return: string +end note + +note left of Registry::loadString + Loads data into the registry from a string using Joomla's format classes. + + since: 5.0.4 + return: self + + arguments: + string $data + string $format = 'JSON' + array $options = [] +end note + +note right of Registry::loadObject + Loads data into the registry from an object. + + since: 5.0.4 + return: self +end note + +note left of Registry::loadArray + Loads data into the registry from an array. +The loaded data will be merged into the registry's existing data. + + since: 5.0.4 + return: self +end note + +note right of Registry::loadFile + Loads data into the registry from a file. + + since: 5.0.4 + return: self +end note + +note left of Registry::set Sets a value into the registry using multiple keys. since: 3.2.0 @@ -45,7 +170,7 @@ Override in child class allowed set class property $addAsArray = true. ?bool $asArray = null end note -note right of Registry::get +note left of Registry::get Retrieves a value (or sub-array) from the registry using multiple keys. since: 3.2.0 @@ -59,13 +184,148 @@ note right of Registry::remove return: self end note -note right of Registry::exists +note left of Registry::exists Checks the existence of a particular location in the registry using multiple keys. since: 3.2.0 return: bool end note +note right of Registry::jsonSerialize + Specify data which should be serialized to JSON. +which is a value of any type other than a resource. + + since: 5.0.4 + return: mixed +end note + +note left of Registry::count + Count elements of the registry. + + since: 5.0.4 + return: int +end note + +note right of Registry::offsetExists + Whether a given offset exists in the registry. + + since: 5.0.4 + return: bool +end note + +note left of Registry::offsetGet + Retrieve the value at a given offset. + + since: 5.0.4 + return: mixed +end note + +note right of Registry::offsetSet + Set the value at a given offset. + + since: 5.0.4 + return: void +end note + +note left of Registry::offsetUnset + Unset the value at a given offset. + + since: 5.0.4 + return: void +end note + +note right of Registry::getIterator + Retrieve an external iterator for the registry. + + since: 5.0.4 + return: \Traversable +end note + +note left of Registry::toArray + Get the registry data as an associative array. + + since: 5.0.4 + return: array +end note + +note right of Registry::toObject + Get the registry data as an object. + + since: 5.0.4 + return: object +end note + +note left of Registry::toString + Converts the registry data to a string in the specified format. + + since: 5.0.4 + return: string +end note + +note right of Registry::flatten + Flattens the registry data into a one-dimensional array. + + since: 5.0.4 + return: array +end note + +note left of Registry::def + Sets a default value if not already set. + + since: 5.0.4 + return: mixed +end note + +note right of Registry::merge + Merges another registry into this one. +The data from the source registry will be merged into this registry, +overwriting any existing values with the same keys. + + since: 5.0.4 + return: self +end note + +note left of Registry::clear + Clears all data from the registry. + + since: 5.0.4 + return: self +end note + +note right of Registry::extract + Extracts a subset of the registry data based on a given path. + + since: 5.0.4 + return: self + + arguments: + string $path + mixed $default = null + ?string $separator = null +end note + +note left of Registry::append + Appends content into the registry. +If a key exists, the value will be appended to the existing value. + + since: 5.0.4 + return: self +end note + +note right of Registry::getName + Gets the name of the registry. + + since: 5.0.4 + return: ?string +end note + +note left of Registry::setName + Sets the name of the registry. + + since: 5.0.4 + return: self +end note + note right of Registry::setSeparator Sets a separator value @@ -73,6 +333,54 @@ note right of Registry::setSeparator return: self end note +note left of Registry::getSeparator + Gets the current path separator used in registry paths. + + since: 5.0.4 + return: ?string +end note + +note right of Registry::arrayToObject + Recursively converts an array to an object. +This method is used to convert the internal array data into an object +structure suitable for serialization or other operations that require objects. + + since: 5.0.4 + return: mixed +end note + +note left of Registry::objectToArray + Recursively converts an object to an array. +This method is used to convert data loaded from formats that produce objects +(e.g., JSON, XML) into an array structure for internal storage. + + since: 5.0.4 + return: mixed +end note + +note right of Registry::arrayMergeRecursive + Recursively merges two arrays. +This method merges the elements of two arrays together so that the values of one +are appended to the end of the previous one. It preserves numeric keys. + + since: 5.0.4 + return: array +end note + +note left of Registry::flattenArray + Helper function to recursively flatten the array. + + since: 5.0.4 + return: array + + arguments: + array $array + string $separator + bool $full + array $flattened = [] + string $path = '' +end note + note right of Registry::getActiveKeys Get that the active keys from a path diff --git a/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.php b/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.php index 903fd91..a9456c6 100644 --- a/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.php +++ b/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.php @@ -12,6 +12,7 @@ namespace VDM\Joomla\Abstraction; +use Joomla\Registry\Factory as FormatFactory; use VDM\Joomla\Interfaces\Registryinterface; use VDM\Joomla\Abstraction\ActiveRegistry; @@ -21,18 +22,238 @@ use VDM\Joomla\Abstraction\ActiveRegistry; * * Don't use this beyond 10 dimensional depth for best performance. * - * @since 3.2.0 + * @since 3.2.0 + * @since 5.0.4 Joomla Registry Compatible */ -abstract class Registry extends ActiveRegistry implements Registryinterface +abstract class Registry extends ActiveRegistry implements Registryinterface, \JsonSerializable, \ArrayAccess, \IteratorAggregate, \Countable { /** * Path separator * * @var string|null - * @since 3.2.0 + * @since 3.2.0 */ protected ?string $separator = '.'; + /** + * The name of the registry. + * + * @var string|null + * @since 5.0.4 + */ + protected ?string $name = null; + + /** + * Constructor. + * + * Initializes the Registry object with optional data. + * + * @param mixed $data Optional data to load into the registry. + * Can be an array, string, or object. + * @param string|null $separator The path separator, and empty string will flatten the registry. + * @since 5.0.4 + */ + public function __construct($data = null, ?string $separator = null) + { + // we don't allow null on initialization (default is a dot) + // so that all class inheritance can override the separator property + // use an empty string if you want to flatten the registry + if ($separator !== null) + { + $this->setSeparator($separator); + } + + if ($data !== null) + { + if (is_array($data)) + { + $this->loadArray($data); + } + elseif (is_string($data)) + { + $this->loadString($data); + } + elseif (is_object($data)) + { + $this->loadObject($data); + } + } + } + + /** + * Magic method to get a value from the registry. + * + * Allows for accessing registry data using object property syntax. + * + * @param string $name The name of the property to get. + * + * @return mixed The value of the property, or null if not found. + * @since 5.0.4 + */ + public function __get($name) + { + return $this->get($name); + } + + /** + * Magic method to set a value in the registry. + * + * Allows for setting registry data using object property syntax. + * + * @param string $name The name of the property to set. + * @param mixed $value The value to set. + * + * @return void + * @since 5.0.4 + */ + public function __set($name, $value) + { + $this->set($name, $value); + } + + /** + * Magic method to check if a property is set in the registry. + * + * Allows for using isset() on registry properties. + * + * @param string $name The name of the property to check. + * + * @return bool True if the property is set, false otherwise. + * @since 5.0.4 + */ + public function __isset($name) + { + return $this->exists($name); + } + + /** + * Magic method to unset a property in the registry. + * + * Allows for using unset() on registry properties. + * + * @param string $name The name of the property to unset. + * + * @return void + * @since 5.0.4 + */ + public function __unset($name) + { + $this->remove($name); + } + + /** + * Magic method to clone the registry. + * + * Performs a deep copy of the registry data. + * + * @return void + * @since 5.0.4 + */ + public function __clone() + { + $this->active = unserialize(serialize($this->active)); + } + + /** + * Magic method to convert the registry to a string. + * + * Returns the registry data in JSON format. + * + * @return string The registry data in JSON format. + * @since 5.0.4 + */ + public function __toString() + { + return $this->toString(); + } + + /** + * Loads data into the registry from a string using Joomla's format classes. + * + * @param string $data The data string to load. + * @param string $format The format of the data string. Supported formats: 'json', 'ini', 'xml', 'php'. + * @param array $options Options used by the formatter + * + * @return self + * @throws \InvalidArgumentException If the format is not supported. + * @since 5.0.4 + */ + public function loadString(string $data, string $format = 'JSON', array $options = []): self + { + // Load a string into the given namespace [or default namespace if not given] + $object = FormatFactory::getFormat($format, $options)->stringToObject($data, $options); + + // Merge the object into the registry + $this->loadObject($object); + + return $this; + } + + /** + * Loads data into the registry from an object. + * + * @param object $object The data object to load. + * + * @return self + * @since 5.0.4 + */ + public function loadObject(object $object): self + { + // Convert the object to an array + $array = $this->objectToArray($object); + + // Merge the array into the registry + $this->loadArray($array); + + return $this; + } + + /** + * Loads data into the registry from an array. + * + * The loaded data will be merged into the registry's existing data. + * + * @param array $array The array of data to load into the registry. + * + * @return self + * @since 5.0.4 + */ + public function loadArray(array $array): self + { + $this->active = $this->arrayMergeRecursive($this->active, $array); + return $this; + } + + /** + * Loads data into the registry from a file. + * + * @param string $path The path to the file to load. + * @param string $format The format of the file. Supported formats: 'json', 'ini', 'xml', 'php'. + * + * @return self + * @throws \InvalidArgumentException If the file does not exist or is not readable. + * @throws \RuntimeException If the file cannot be read. + * @since 5.0.4 + */ + public function loadFile(string $path, string $format = 'json'): self + { + if (!file_exists($path) || !is_readable($path)) + { + throw new \InvalidArgumentException("File does not exist or is not readable: {$path}"); + } + + $data = file_get_contents($path); + + if ($data === false) + { + throw new \RuntimeException("Failed to read file: {$path}"); + } + + $this->loadString($data, $format); + + return $this; + } + /** * Sets a value into the registry using multiple keys. * @@ -41,7 +262,7 @@ abstract class Registry extends ActiveRegistry implements Registryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function set(string $path, $value): self { @@ -67,7 +288,7 @@ abstract class Registry extends ActiveRegistry implements Registryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function add(string $path, $value, ?bool $asArray = null): self { @@ -89,9 +310,9 @@ abstract class Registry extends ActiveRegistry implements Registryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return mixed The value or sub-array from the storage. Null if the location doesn't exist. - * @since 3.2.0 + * @since 3.2.0 */ - public function get(string $path, $default = null) + public function get(string $path, $default = null): mixed { if (($keys = $this->getActiveKeys($path)) === null) { @@ -108,7 +329,7 @@ abstract class Registry extends ActiveRegistry implements Registryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function remove(string $path): self { @@ -129,7 +350,7 @@ abstract class Registry extends ActiveRegistry implements Registryinterface * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return bool True if the location exists, false otherwise. - * @since 3.2.0 + * @since 3.2.0 */ public function exists(string $path): bool { @@ -141,13 +362,308 @@ abstract class Registry extends ActiveRegistry implements Registryinterface return $this->existsActive(...$keys); } + /** + * Specify data which should be serialized to JSON. + * + * @return mixed Data which can be serialized by json_encode(), + * which is a value of any type other than a resource. + * @since 5.0.4 + */ + public function jsonSerialize(): mixed + { + return $this->active; + } + + /** + * Count elements of the registry. + * + * @return int The number of elements in the registry. + * @since 5.0.4 + */ + public function count(): int + { + return count($this->active); + } + + /** + * Whether a given offset exists in the registry. + * + * @param mixed $offset An offset to check for. + * + * @return bool True if the offset exists, false otherwise. + * @since 5.0.4 + */ + public function offsetExists(mixed $offset): bool + { + if (!is_string($offset)) + { + return false; + } + return $this->exists($offset); + } + + /** + * Retrieve the value at a given offset. + * + * @param mixed $offset The offset to retrieve. + * + * @return mixed The value at the specified offset. + * @since 5.0.4 + */ + public function offsetGet(mixed $offset): mixed + { + if (!is_string($offset)) + { + return null; + } + return $this->get($offset); + } + + /** + * Set the value at a given offset. + * + * @param mixed $offset The offset to assign the value to. + * @param mixed $value The value to set. + * + * @return void + * @since 5.0.4 + */ + public function offsetSet(mixed $offset, mixed $value): void + { + if (!is_string($offset)) + { + return; + } + $this->set($offset, $value); + } + + /** + * Unset the value at a given offset. + * + * @param mixed $offset The offset to unset. + * + * @return void + * @since 5.0.4 + */ + public function offsetUnset(mixed $offset): void + { + if (!is_string($offset)) + { + return; + } + $this->remove($offset); + } + + /** + * Retrieve an external iterator for the registry. + * + * @return \Traversable An instance of an object implementing Iterator or Traversable. + * @since 5.0.4 + */ + public function getIterator(): \Traversable + { + return new \ArrayIterator($this->active); + } + + /** + * Get the registry data as an associative array. + * + * @return array The registry data. + * @since 5.0.4 + */ + public function toArray(): array + { + return $this->active; + } + + /** + * Get the registry data as an object. + * + * @return object The registry data converted to an object. + * @since 5.0.4 + */ + public function toObject() + { + return $this->arrayToObject($this->active); + } + + /** + * Converts the registry data to a string in the specified format. + * + * @param string $format The format to output the string in. Supported formats: 'json', 'ini', 'xml', 'php'. + * @param array $options Options used by the formatter. + * + * @return string The registry data in the specified format. + * + * @throws \InvalidArgumentException If the format is not supported. + * @since 5.0.4 + */ + public function toString(string $format = 'JSON', array $options = []): string + { + // Convert the internal array to an object + $object = $this->arrayToObject($this->active); + + return FormatFactory::getFormat($format, $options)->objectToString($object, $options); + } + + /** + * Flattens the registry data into a one-dimensional array. + * + * @param string|null $separator The separator for the key names. + * @param bool $full True to include the full path as keys. + * + * @return array The flattened data array. + * @since 5.0.4 + */ + public function flatten(?string $separator = null, bool $full = false): array + { + // we use default separator + if ($separator === null) + { + $separator = $this->separator; + } + + return $this->flattenArray($this->active, $separator, $full); + } + + /** + * Sets a default value if not already set. + * + * @param string $path The registry path (e.g., 'vdm.content.builder'). + * @param mixed $default The default value to set if the path does not exist. + * + * @return mixed The value of the path after the method call. + * @since 5.0.4 + */ + public function def(string $path, $default) + { + if (!$this->exists($path)) + { + $this->set($path, $default); + return $default; + } + return $this->get($path); + } + + /** + * Merges another registry into this one. + * + * The data from the source registry will be merged into this registry, + * overwriting any existing values with the same keys. + * + * @param Registryinterface $source The registry to merge with this one. + * + * @return self + * @since 5.0.4 + */ + public function merge(Registryinterface $source): self + { + $this->active = $this->arrayMergeRecursive($this->active, $source->toArray()); + return $this; + } + + /** + * Clears all data from the registry. + * + * @return self + * @since 5.0.4 + */ + public function clear(): self + { + $this->active = []; + return $this; + } + + /** + * Extracts a subset of the registry data based on a given path. + * + * @param string $path The registry path to extract. + * @param mixed $default Optional default value, returned if the path does not exist. + * @param string|null $separator The path separator. + * + * @return self A new Registry instance with the extracted data. + * @since 5.0.4 + */ + public function extract(string $path, $default = null, ?string $separator = null): self + { + $originalSeparator = $this->getSeparator(); + if ($separator !== null) + { + $this->setSeparator($separator); + } + + $data = $this->get($path, $default); + + if ($separator !== null) + { + $this->setSeparator($originalSeparator); + } + + $newRegistry = new static(); + + if ($data !== $default) + { + if (is_array($data)) + { + $newRegistry->loadArray($data); + } + else + { + $newRegistry->set('value', $data); + } + } + + return $newRegistry; + } + + /** + * Appends content into the registry. + * + * If a key exists, the value will be appended to the existing value. + * + * @param string $path The registry path (e.g., 'vdm.content.builder'). + * @param mixed $value The value to append. + * + * @return self + * @since 5.0.4 + */ + public function append(string $path, $value): self + { + return $this->add($path, $value, false); + } + + /** + * Gets the name of the registry. + * + * @return string|null The name of the registry. + * @since 5.0.4 + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * Sets the name of the registry. + * + * @param string|null $name The name to set. + * + * @return self + * @since 5.0.4 + */ + public function setName(?string $name): self + { + $this->name = $name; + return $this; + } + /** * Sets a separator value * * @param string|null $value The value to set. * * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function setSeparator(?string $value): self { @@ -156,13 +672,140 @@ abstract class Registry extends ActiveRegistry implements Registryinterface return $this; } + /** + * Gets the current path separator used in registry paths. + * + * @return string|null The path separator. + * @since 5.0.4 + */ + public function getSeparator(): ?string + { + return $this->separator; + } + + /** + * Recursively converts an array to an object. + * + * This method is used to convert the internal array data into an object + * structure suitable for serialization or other operations that require objects. + * + * @param mixed $data The data to convert. + * + * @return mixed The converted object, or the original data if not an array. + * @since 5.0.4 + */ + protected function arrayToObject($data) + { + if (is_array($data)) + { + $object = new \stdClass(); + foreach ($data as $key => $value) + { + // Handle numeric keys for object properties + if (is_numeric($key)) + { + $key = 'item' . $key; + } + $object->{$key} = $this->arrayToObject($value); + } + return $object; + } + else + { + return $data; + } + } + + /** + * Recursively converts an object to an array. + * + * This method is used to convert data loaded from formats that produce objects + * (e.g., JSON, XML) into an array structure for internal storage. + * + * @param mixed $data The data to convert. + * + * @return mixed The converted array, or the original data if not an object. + * @since 5.0.4 + */ + protected function objectToArray($data) + { + return json_decode(json_encode($data), true); + } + + /** + * Recursively merges two arrays. + * + * This method merges the elements of two arrays together so that the values of one + * are appended to the end of the previous one. It preserves numeric keys. + * + * @param array $array1 The array to merge into. + * @param array $array2 The array to merge from. + * + * @return array The merged array. + * @since 5.0.4 + */ + protected function arrayMergeRecursive(array $array1, array $array2): array + { + foreach ($array2 as $key => $value) + { + // If the value is an array and the key exists in both arrays, merge recursively + if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) + { + $array1[$key] = $this->arrayMergeRecursive($array1[$key], $value); + } + else + { + // Otherwise, replace or set the value + $array1[$key] = $value; + } + } + return $array1; + } + + /** + * Helper function to recursively flatten the array. + * + * @param array $array The array to flatten. + * @param string $separator The separator for the key names. + * @param bool $full True to include the full path as keys. + * @param array $flattened The flattened array (used internally for recursion). + * @param string $path The current path (used internally for recursion). + * + * @return array The flattened array. + * @since 5.0.4 + */ + protected function flattenArray(array $array, string $separator, bool $full, array $flattened = [], string $path = ''): array + { + foreach ($array as $key => $value) + { + if ($full) + { + $newPath = $path === '' ? $key : $path . $separator . $key; + } + else + { + $newPath = $key; + } + + if (is_array($value)) + { + $flattened = $this->flattenArray($value, $separator, $full, $flattened, $newPath); + } + else + { + $flattened[$newPath] = $value; + } + } + return $flattened; + } + /** * Get that the active keys from a path * * @param string $path The path to determine the location registry. * * @return array|null The valid array of keys - * @since 3.2.0 + * @since 3.2.0 */ protected function getActiveKeys(string $path): ?array { diff --git a/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.power b/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.power index 22746d1..26ec70b 100644 --- a/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.power +++ b/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.power @@ -2,10 +2,229 @@ * Path separator * * @var string|null - * @since 3.2.0 + * @since 3.2.0 */ protected ?string $separator = '.'; + /** + * The name of the registry. + * + * @var string|null + * @since 5.0.4 + */ + protected ?string $name = null; + + /** + * Constructor. + * + * Initializes the Registry object with optional data. + * + * @param mixed $data Optional data to load into the registry. + * Can be an array, string, or object. + * @param string|null $separator The path separator, and empty string will flatten the registry. + * @since 5.0.4 + */ + public function __construct($data = null, ?string $separator = null) + { + // we don't allow null on initialization (default is a dot) + // so that all class inheritance can override the separator property + // use an empty string if you want to flatten the registry + if ($separator !== null) + { + $this->setSeparator($separator); + } + + if ($data !== null) + { + if (is_array($data)) + { + $this->loadArray($data); + } + elseif (is_string($data)) + { + $this->loadString($data); + } + elseif (is_object($data)) + { + $this->loadObject($data); + } + } + } + + /** + * Magic method to get a value from the registry. + * + * Allows for accessing registry data using object property syntax. + * + * @param string $name The name of the property to get. + * + * @return mixed The value of the property, or null if not found. + * @since 5.0.4 + */ + public function __get($name) + { + return $this->get($name); + } + + /** + * Magic method to set a value in the registry. + * + * Allows for setting registry data using object property syntax. + * + * @param string $name The name of the property to set. + * @param mixed $value The value to set. + * + * @return void + * @since 5.0.4 + */ + public function __set($name, $value) + { + $this->set($name, $value); + } + + /** + * Magic method to check if a property is set in the registry. + * + * Allows for using isset() on registry properties. + * + * @param string $name The name of the property to check. + * + * @return bool True if the property is set, false otherwise. + * @since 5.0.4 + */ + public function __isset($name) + { + return $this->exists($name); + } + + /** + * Magic method to unset a property in the registry. + * + * Allows for using unset() on registry properties. + * + * @param string $name The name of the property to unset. + * + * @return void + * @since 5.0.4 + */ + public function __unset($name) + { + $this->remove($name); + } + + /** + * Magic method to clone the registry. + * + * Performs a deep copy of the registry data. + * + * @return void + * @since 5.0.4 + */ + public function __clone() + { + $this->active = unserialize(serialize($this->active)); + } + + /** + * Magic method to convert the registry to a string. + * + * Returns the registry data in JSON format. + * + * @return string The registry data in JSON format. + * @since 5.0.4 + */ + public function __toString() + { + return $this->toString(); + } + + /** + * Loads data into the registry from a string using Joomla's format classes. + * + * @param string $data The data string to load. + * @param string $format The format of the data string. Supported formats: 'json', 'ini', 'xml', 'php'. + * @param array $options Options used by the formatter + * + * @return self + * @throws \InvalidArgumentException If the format is not supported. + * @since 5.0.4 + */ + public function loadString(string $data, string $format = 'JSON', array $options = []): self + { + // Load a string into the given namespace [or default namespace if not given] + $object = FormatFactory::getFormat($format, $options)->stringToObject($data, $options); + + // Merge the object into the registry + $this->loadObject($object); + + return $this; + } + + /** + * Loads data into the registry from an object. + * + * @param object $object The data object to load. + * + * @return self + * @since 5.0.4 + */ + public function loadObject(object $object): self + { + // Convert the object to an array + $array = $this->objectToArray($object); + + // Merge the array into the registry + $this->loadArray($array); + + return $this; + } + + /** + * Loads data into the registry from an array. + * + * The loaded data will be merged into the registry's existing data. + * + * @param array $array The array of data to load into the registry. + * + * @return self + * @since 5.0.4 + */ + public function loadArray(array $array): self + { + $this->active = $this->arrayMergeRecursive($this->active, $array); + return $this; + } + + /** + * Loads data into the registry from a file. + * + * @param string $path The path to the file to load. + * @param string $format The format of the file. Supported formats: 'json', 'ini', 'xml', 'php'. + * + * @return self + * @throws \InvalidArgumentException If the file does not exist or is not readable. + * @throws \RuntimeException If the file cannot be read. + * @since 5.0.4 + */ + public function loadFile(string $path, string $format = 'json'): self + { + if (!file_exists($path) || !is_readable($path)) + { + throw new \InvalidArgumentException("File does not exist or is not readable: {$path}"); + } + + $data = file_get_contents($path); + + if ($data === false) + { + throw new \RuntimeException("Failed to read file: {$path}"); + } + + $this->loadString($data, $format); + + return $this; + } + /** * Sets a value into the registry using multiple keys. * @@ -14,7 +233,7 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function set(string $path, $value): self { @@ -40,7 +259,7 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function add(string $path, $value, ?bool $asArray = null): self { @@ -62,9 +281,9 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return mixed The value or sub-array from the storage. Null if the location doesn't exist. - * @since 3.2.0 + * @since 3.2.0 */ - public function get(string $path, $default = null) + public function get(string $path, $default = null): mixed { if (($keys = $this->getActiveKeys($path)) === null) { @@ -81,7 +300,7 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function remove(string $path): self { @@ -102,7 +321,7 @@ * * @throws \InvalidArgumentException If any of the path values are not a number or string. * @return bool True if the location exists, false otherwise. - * @since 3.2.0 + * @since 3.2.0 */ public function exists(string $path): bool { @@ -114,13 +333,308 @@ return $this->existsActive(...$keys); } + /** + * Specify data which should be serialized to JSON. + * + * @return mixed Data which can be serialized by json_encode(), + * which is a value of any type other than a resource. + * @since 5.0.4 + */ + public function jsonSerialize(): mixed + { + return $this->active; + } + + /** + * Count elements of the registry. + * + * @return int The number of elements in the registry. + * @since 5.0.4 + */ + public function count(): int + { + return count($this->active); + } + + /** + * Whether a given offset exists in the registry. + * + * @param mixed $offset An offset to check for. + * + * @return bool True if the offset exists, false otherwise. + * @since 5.0.4 + */ + public function offsetExists(mixed $offset): bool + { + if (!is_string($offset)) + { + return false; + } + return $this->exists($offset); + } + + /** + * Retrieve the value at a given offset. + * + * @param mixed $offset The offset to retrieve. + * + * @return mixed The value at the specified offset. + * @since 5.0.4 + */ + public function offsetGet(mixed $offset): mixed + { + if (!is_string($offset)) + { + return null; + } + return $this->get($offset); + } + + /** + * Set the value at a given offset. + * + * @param mixed $offset The offset to assign the value to. + * @param mixed $value The value to set. + * + * @return void + * @since 5.0.4 + */ + public function offsetSet(mixed $offset, mixed $value): void + { + if (!is_string($offset)) + { + return; + } + $this->set($offset, $value); + } + + /** + * Unset the value at a given offset. + * + * @param mixed $offset The offset to unset. + * + * @return void + * @since 5.0.4 + */ + public function offsetUnset(mixed $offset): void + { + if (!is_string($offset)) + { + return; + } + $this->remove($offset); + } + + /** + * Retrieve an external iterator for the registry. + * + * @return \Traversable An instance of an object implementing Iterator or Traversable. + * @since 5.0.4 + */ + public function getIterator(): \Traversable + { + return new \ArrayIterator($this->active); + } + + /** + * Get the registry data as an associative array. + * + * @return array The registry data. + * @since 5.0.4 + */ + public function toArray(): array + { + return $this->active; + } + + /** + * Get the registry data as an object. + * + * @return object The registry data converted to an object. + * @since 5.0.4 + */ + public function toObject() + { + return $this->arrayToObject($this->active); + } + + /** + * Converts the registry data to a string in the specified format. + * + * @param string $format The format to output the string in. Supported formats: 'json', 'ini', 'xml', 'php'. + * @param array $options Options used by the formatter. + * + * @return string The registry data in the specified format. + * + * @throws \InvalidArgumentException If the format is not supported. + * @since 5.0.4 + */ + public function toString(string $format = 'JSON', array $options = []): string + { + // Convert the internal array to an object + $object = $this->arrayToObject($this->active); + + return FormatFactory::getFormat($format, $options)->objectToString($object, $options); + } + + /** + * Flattens the registry data into a one-dimensional array. + * + * @param string|null $separator The separator for the key names. + * @param bool $full True to include the full path as keys. + * + * @return array The flattened data array. + * @since 5.0.4 + */ + public function flatten(?string $separator = null, bool $full = false): array + { + // we use default separator + if ($separator === null) + { + $separator = $this->separator; + } + + return $this->flattenArray($this->active, $separator, $full); + } + + /** + * Sets a default value if not already set. + * + * @param string $path The registry path (e.g., 'vdm.content.builder'). + * @param mixed $default The default value to set if the path does not exist. + * + * @return mixed The value of the path after the method call. + * @since 5.0.4 + */ + public function def(string $path, $default) + { + if (!$this->exists($path)) + { + $this->set($path, $default); + return $default; + } + return $this->get($path); + } + + /** + * Merges another registry into this one. + * + * The data from the source registry will be merged into this registry, + * overwriting any existing values with the same keys. + * + * @param Registryinterface $source The registry to merge with this one. + * + * @return self + * @since 5.0.4 + */ + public function merge(Registryinterface $source): self + { + $this->active = $this->arrayMergeRecursive($this->active, $source->toArray()); + return $this; + } + + /** + * Clears all data from the registry. + * + * @return self + * @since 5.0.4 + */ + public function clear(): self + { + $this->active = []; + return $this; + } + + /** + * Extracts a subset of the registry data based on a given path. + * + * @param string $path The registry path to extract. + * @param mixed $default Optional default value, returned if the path does not exist. + * @param string|null $separator The path separator. + * + * @return self A new Registry instance with the extracted data. + * @since 5.0.4 + */ + public function extract(string $path, $default = null, ?string $separator = null): self + { + $originalSeparator = $this->getSeparator(); + if ($separator !== null) + { + $this->setSeparator($separator); + } + + $data = $this->get($path, $default); + + if ($separator !== null) + { + $this->setSeparator($originalSeparator); + } + + $newRegistry = new static(); + + if ($data !== $default) + { + if (is_array($data)) + { + $newRegistry->loadArray($data); + } + else + { + $newRegistry->set('value', $data); + } + } + + return $newRegistry; + } + + /** + * Appends content into the registry. + * + * If a key exists, the value will be appended to the existing value. + * + * @param string $path The registry path (e.g., 'vdm.content.builder'). + * @param mixed $value The value to append. + * + * @return self + * @since 5.0.4 + */ + public function append(string $path, $value): self + { + return $this->add($path, $value, false); + } + + /** + * Gets the name of the registry. + * + * @return string|null The name of the registry. + * @since 5.0.4 + */ + public function getName(): ?string + { + return $this->name; + } + + /** + * Sets the name of the registry. + * + * @param string|null $name The name to set. + * + * @return self + * @since 5.0.4 + */ + public function setName(?string $name): self + { + $this->name = $name; + return $this; + } + /** * Sets a separator value * * @param string|null $value The value to set. * * @return self - * @since 3.2.0 + * @since 3.2.0 */ public function setSeparator(?string $value): self { @@ -129,13 +643,140 @@ return $this; } + /** + * Gets the current path separator used in registry paths. + * + * @return string|null The path separator. + * @since 5.0.4 + */ + public function getSeparator(): ?string + { + return $this->separator; + } + + /** + * Recursively converts an array to an object. + * + * This method is used to convert the internal array data into an object + * structure suitable for serialization or other operations that require objects. + * + * @param mixed $data The data to convert. + * + * @return mixed The converted object, or the original data if not an array. + * @since 5.0.4 + */ + protected function arrayToObject($data) + { + if (is_array($data)) + { + $object = new \stdClass(); + foreach ($data as $key => $value) + { + // Handle numeric keys for object properties + if (is_numeric($key)) + { + $key = 'item' . $key; + } + $object->{$key} = $this->arrayToObject($value); + } + return $object; + } + else + { + return $data; + } + } + + /** + * Recursively converts an object to an array. + * + * This method is used to convert data loaded from formats that produce objects + * (e.g., JSON, XML) into an array structure for internal storage. + * + * @param mixed $data The data to convert. + * + * @return mixed The converted array, or the original data if not an object. + * @since 5.0.4 + */ + protected function objectToArray($data) + { + return json_decode(json_encode($data), true); + } + + /** + * Recursively merges two arrays. + * + * This method merges the elements of two arrays together so that the values of one + * are appended to the end of the previous one. It preserves numeric keys. + * + * @param array $array1 The array to merge into. + * @param array $array2 The array to merge from. + * + * @return array The merged array. + * @since 5.0.4 + */ + protected function arrayMergeRecursive(array $array1, array $array2): array + { + foreach ($array2 as $key => $value) + { + // If the value is an array and the key exists in both arrays, merge recursively + if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) + { + $array1[$key] = $this->arrayMergeRecursive($array1[$key], $value); + } + else + { + // Otherwise, replace or set the value + $array1[$key] = $value; + } + } + return $array1; + } + + /** + * Helper function to recursively flatten the array. + * + * @param array $array The array to flatten. + * @param string $separator The separator for the key names. + * @param bool $full True to include the full path as keys. + * @param array $flattened The flattened array (used internally for recursion). + * @param string $path The current path (used internally for recursion). + * + * @return array The flattened array. + * @since 5.0.4 + */ + protected function flattenArray(array $array, string $separator, bool $full, array $flattened = [], string $path = ''): array + { + foreach ($array as $key => $value) + { + if ($full) + { + $newPath = $path === '' ? $key : $path . $separator . $key; + } + else + { + $newPath = $key; + } + + if (is_array($value)) + { + $flattened = $this->flattenArray($value, $separator, $full, $flattened, $newPath); + } + else + { + $flattened[$newPath] = $value; + } + } + return $flattened; + } + /** * Get that the active keys from a path * * @param string $path The path to determine the location registry. * * @return array|null The valid array of keys - * @since 3.2.0 + * @since 3.2.0 */ protected function getActiveKeys(string $path): ?array { diff --git a/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/settings.json b/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/settings.json index b1ebdec..0c32bd3 100644 --- a/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/settings.json +++ b/src/7e822c03-1b20-41d1-9427-f5b8d5836af7/settings.json @@ -1,10 +1,11 @@ { - "add_head": "0", + "add_head": "1", "add_licensing_template": "2", "extends": "43134867-5cb8-4280-9be8-309fd2fd135f", "guid": "7e822c03-1b20-41d1-9427-f5b8d5836af7", "implements": [ - "64e291c2-11f1-423d-a44d-837cc12cc017" + "64e291c2-11f1-423d-a44d-837cc12cc017", + "-1" ], "load_selection": null, "name": "Registry", @@ -14,8 +15,9 @@ "use_selection": null, "extendsinterfaces": null, "namespace": "[[[NamespacePrefix]]]\\Joomla\\Abstraction.Registry", - "description": "VDM Basic Registry.\r\n\r\nDon't use this beyond 10 dimensional depth for best performance.\r\n\r\n@since 3.2.0", + "description": "VDM Basic Registry.\r\n\r\nDon't use this beyond 10 dimensional depth for best performance.\r\n\r\n@since 3.2.0\r\n@since 5.0.4 Joomla Registry Compatible", + "implements_custom": " \\JsonSerializable, \\ArrayAccess, \\IteratorAggregate, \\Countable", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", - "head": "", + "head": "use Joomla\\Registry\\Factory as FormatFactory;", "composer": "" } \ No newline at end of file diff --git a/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/README.md b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/README.md new file mode 100644 index 0000000..880cd43 --- /dev/null +++ b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/README.md @@ -0,0 +1,54 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class ComponentConfig (Details) +> namespace: **VDM\Joomla\Componentbuilder\Abstraction** +> extends: **FunctionRegistry** + +```uml +@startuml +abstract ComponentConfig #Orange { + # Input $input + # JoomlaRegistry $params + + __construct(?Input $input = null, ?JoomlaRegistry $params = null) +} + +note right of ComponentConfig::__construct + Constructor + + since: 3.2.0 +end note + +@enduml +``` + +The Power feature in JCB allows you to write PHP classes and their implementations, making it easy to include them in your Joomla project. JCB handles linking, autoloading, namespacing, and folder structure creation for you. + +By using the SPK (Super Power Key) in your custom code (replacing the class name in your code with the SPK), JCB will automatically pull the power from the repository into your project. This makes it available in your JCB instance, allowing you to edit it and include the class in your generated Joomla component. + +JCB uses placeholders like [[[`NamespacePrefix`]]] and [[[`ComponentNamespace`]]] in namespacing to prevent collisions and improve reusability across different JCB systems. You can also set the **JCB powers path** globally or per component under the **Dynamic Integration** tab, providing flexibility and easy maintainability. + +To add this specific Power to your project in JCB: + +> simply use this SPK +``` +Super---9769f3b2_17bf_4f20_b54b_3a4ebe572b36---Power +``` +> remember to replace the `---` with `___` to activate this Power in your code + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.php b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.php new file mode 100644 index 0000000..d60509e --- /dev/null +++ b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.php @@ -0,0 +1,61 @@ + + * @git Joomla Component Builder + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\Componentbuilder\Abstraction; + + +use Joomla\Registry\Registry as JoomlaRegistry; +use Joomla\CMS\Factory; +use Joomla\Input\Input; +use VDM\Joomla\Utilities\Component\Helper; +use VDM\Joomla\Utilities\String\ClassfunctionHelper; +use VDM\Joomla\Abstraction\FunctionRegistry; + + +/** + * Component Configurations + * + * @since 3.2.0 + */ +abstract class ComponentConfig extends FunctionRegistry +{ + /** + * Hold a Input object for easier access to the input variables. + * + * @var Input + * @since 3.2.0 + */ + protected Input $input; + + /** + * The Params + * + * @var JoomlaRegistry + * @since 3.2.0 + */ + protected JoomlaRegistry $params; + + /** + * Constructor + * + * @param Input|null $input Input + * @param Registry|null $params The component parameters + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Input $input = null, ?JoomlaRegistry $params = null) + { + $this->input = $input ?: Factory::getApplication()->input; + $this->params = $params ?: Helper::getParams('com_componentbuilder'); + } +} + diff --git a/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.power b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.power new file mode 100644 index 0000000..b772571 --- /dev/null +++ b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/code.power @@ -0,0 +1,30 @@ + /** + * Hold a Input object for easier access to the input variables. + * + * @var Input + * @since 3.2.0 + */ + protected Input $input; + + /** + * The Params + * + * @var JoomlaRegistry + * @since 3.2.0 + */ + protected JoomlaRegistry $params; + + /** + * Constructor + * + * @param Input|null $input Input + * @param Registry|null $params The component parameters + * + * @throws \Exception + * @since 3.2.0 + */ + public function __construct(?Input $input = null, ?JoomlaRegistry $params = null) + { + $this->input = $input ?: Factory::getApplication()->input; + $this->params = $params ?: Helper::getParams('com_###component###'); + } \ No newline at end of file diff --git a/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/settings.json b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/settings.json new file mode 100644 index 0000000..f1cad36 --- /dev/null +++ b/src/9769f3b2-17bf-4f20-b54b-3a4ebe572b36/settings.json @@ -0,0 +1,28 @@ +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "ffbd4e1f-a342-4080-ab7d-1de3741bf319", + "guid": "9769f3b2-17bf-4f20-b54b-3a4ebe572b36", + "implements": null, + "load_selection": null, + "name": "ComponentConfig", + "power_version": "1.0.0", + "system_name": "JCB.Abstraction.ComponentConfig", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "640b5352-fb09-425f-a26e-cd44eda03f15", + "as": "default" + }, + "use_selection1": { + "use": "30c5b4c2-f75f-4d15-869a-f8bfedd87358", + "as": "default" + } + }, + "extendsinterfaces": null, + "namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Abstraction.ComponentConfig", + "description": "Component Configurations\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "use Joomla\\Registry\\Registry as JoomlaRegistry;\r\nuse Joomla\\CMS\\Factory;\r\nuse Joomla\\Input\\Input;", + "composer": "" +} \ No newline at end of file diff --git a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.php b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.php index 6e4222d..12b96ae 100644 --- a/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.php +++ b/src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.php @@ -109,8 +109,8 @@ final class Table extends BaseTable implements TableInterface 'tab_name' => 'publishing', 'db' => [ 'type' => 'DATETIME', - 'default' => '0000-00-00 00:00:00', - 'null_switch' => 'NOT NULL', + 'default' => 'CURRENT_TIMESTAMP', + 'null_switch' => 'NULL', 'unique_key' => false, 'key' => false, ], @@ -1626,8 +1626,8 @@ final class Table extends BaseTable implements TableInterface 'tab_name' => 'publishing', 'db' => [ 'type' => 'DATETIME', - 'default' => '0000-00-00 00:00:00', - 'null_switch' => 'NOT NULL', + 'default' => 'EMPTY', + 'null_switch' => 'NULL', 'unique_key' => false, 'key' => false, ], diff --git a/src/c182506a-ab84-439c-b962-1e606b58d545/README.md b/src/c182506a-ab84-439c-b962-1e606b58d545/README.md index 20f1863..788144d 100644 --- a/src/c182506a-ab84-439c-b962-1e606b58d545/README.md +++ b/src/c182506a-ab84-439c-b962-1e606b58d545/README.md @@ -18,6 +18,7 @@ interface GrepInterface #Lavender { + setBranchDefaultName(?string $name) : void + setIndexPath(string $indexPath) : void + getRemoteIndex(string $guid) : ?object + + loadApi(Api $api, ?string $base, ...) : void } note right of GrepInterface::get @@ -66,6 +67,21 @@ note right of GrepInterface::getRemoteIndex since: 3.2.2 return: ?object end note + +note right of GrepInterface::loadApi + Loads API config using the provided base URL and token. +This method checks if the base URL contains 'https://git.vdm.dev/'. +If it does, it uses the token as is (which may be null). +If not, it ensures the token is not null by defaulting to an empty string. + + since: 5.0.4 + return: void + + arguments: + Api $api + ?string $base + ?string $token +end note @enduml ``` diff --git a/src/c182506a-ab84-439c-b962-1e606b58d545/code.php b/src/c182506a-ab84-439c-b962-1e606b58d545/code.php index d3199d5..013f7f0 100644 --- a/src/c182506a-ab84-439c-b962-1e606b58d545/code.php +++ b/src/c182506a-ab84-439c-b962-1e606b58d545/code.php @@ -12,6 +12,9 @@ namespace VDM\Joomla\Interfaces; +use VDM\Joomla\Interfaces\Git\ApiInterface as Api; + + /** * Global Resource Empowerment Platform * @@ -77,6 +80,22 @@ interface GrepInterface * @return object|null * @since 3.2.2 */ - public function getRemoteIndex(string $guid): ?object; + public function getRemoteIndex(string $guid): ?object; + + /** + * Loads API config using the provided base URL and token. + * + * This method checks if the base URL contains 'https://git.vdm.dev/'. + * If it does, it uses the token as is (which may be null). + * If not, it ensures the token is not null by defaulting to an empty string. + * + * @param Api $api The api object with a load_ method. + * @param string|null $base The base URL path. + * @param string|null $token The token for authentication (can be null). + * + * @return void + * @since 5.0.4 + */ + public function loadApi(Api $api, ?string $base, ?string $token): void; } diff --git a/src/c182506a-ab84-439c-b962-1e606b58d545/code.power b/src/c182506a-ab84-439c-b962-1e606b58d545/code.power index 3403999..6f0df70 100644 --- a/src/c182506a-ab84-439c-b962-1e606b58d545/code.power +++ b/src/c182506a-ab84-439c-b962-1e606b58d545/code.power @@ -56,4 +56,20 @@ * @return object|null * @since 3.2.2 */ - public function getRemoteIndex(string $guid): ?object; \ No newline at end of file + public function getRemoteIndex(string $guid): ?object; + + /** + * Loads API config using the provided base URL and token. + * + * This method checks if the base URL contains 'https://git.vdm.dev/'. + * If it does, it uses the token as is (which may be null). + * If not, it ensures the token is not null by defaulting to an empty string. + * + * @param Api $api The api object with a load_ method. + * @param string|null $base The base URL path. + * @param string|null $token The token for authentication (can be null). + * + * @return void + * @since 5.0.4 + */ + public function loadApi(Api $api, ?string $base, ?string $token): void; \ No newline at end of file diff --git a/src/c182506a-ab84-439c-b962-1e606b58d545/settings.json b/src/c182506a-ab84-439c-b962-1e606b58d545/settings.json index a9a1495..6aa6303 100644 --- a/src/c182506a-ab84-439c-b962-1e606b58d545/settings.json +++ b/src/c182506a-ab84-439c-b962-1e606b58d545/settings.json @@ -9,7 +9,12 @@ "power_version": "1.0.0", "system_name": "VDM.Interfaces.GrepInterface", "type": "interface", - "use_selection": null, + "use_selection": { + "use_selection0": { + "use": "17ed2fec-49d6-4731-92c3-f9cd78fb6273", + "as": "Api" + } + }, "extendsinterfaces": null, "namespace": "[[[NamespacePrefix]]]\\Joomla\\Interfaces.GrepInterface", "description": "Global Resource Empowerment Platform\r\n\r\n@since 3.2.1", diff --git a/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php index 7f48355..7a0919d 100644 --- a/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php +++ b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php @@ -108,8 +108,7 @@ abstract class BaseTable implements TableInterface 'store' => NULL, 'tab_name' => NULL, 'db' => [ - 'type' => 'INT(10) unsigned', - 'default' => '0', + 'type' => 'INT unsigned', 'null_switch' => 'NULL', 'key' => true, 'key_name' => 'modifiedby' @@ -125,7 +124,6 @@ abstract class BaseTable implements TableInterface 'tab_name' => NULL, 'db' => [ 'type' => 'DATETIME', - 'default' => '0000-00-00 00:00:00', 'null_switch' => 'NULL' ] ], @@ -138,7 +136,7 @@ abstract class BaseTable implements TableInterface 'store' => NULL, 'tab_name' => NULL, 'db' => [ - 'type' => 'INT(10) unsigned', + 'type' => 'INT unsigned', 'default' => '0', 'null_switch' => 'NULL', 'key' => true, @@ -155,7 +153,7 @@ abstract class BaseTable implements TableInterface 'tab_name' => NULL, 'db' => [ 'type' => 'DATETIME', - 'default' => '0000-00-00 00:00:00', + 'default' => 'CURRENT_TIMESTAMP', 'null_switch' => 'NULL' ] ], @@ -168,8 +166,7 @@ abstract class BaseTable implements TableInterface 'store' => NULL, 'tab_name' => NULL, 'db' => [ - 'type' => 'INT(10) unsigned', - 'default' => '0', + 'type' => 'INT unsigned', 'null_switch' => 'NULL', 'key' => true, 'key_name' => 'checkout' @@ -185,7 +182,6 @@ abstract class BaseTable implements TableInterface 'tab_name' => NULL, 'db' => [ 'type' => 'DATETIME', - 'default' => '0000-00-00 00:00:00', 'null_switch' => 'NULL' ] ], diff --git a/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power index f2b516a..920bb06 100644 --- a/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power +++ b/src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.power @@ -84,8 +84,7 @@ 'store' => NULL, 'tab_name' => NULL, 'db' => [ - 'type' => 'INT(10) unsigned', - 'default' => '0', + 'type' => 'INT unsigned', 'null_switch' => 'NULL', 'key' => true, 'key_name' => 'modifiedby' @@ -101,7 +100,6 @@ 'tab_name' => NULL, 'db' => [ 'type' => 'DATETIME', - 'default' => '0000-00-00 00:00:00', 'null_switch' => 'NULL' ] ], @@ -114,7 +112,7 @@ 'store' => NULL, 'tab_name' => NULL, 'db' => [ - 'type' => 'INT(10) unsigned', + 'type' => 'INT unsigned', 'default' => '0', 'null_switch' => 'NULL', 'key' => true, @@ -131,7 +129,7 @@ 'tab_name' => NULL, 'db' => [ 'type' => 'DATETIME', - 'default' => '0000-00-00 00:00:00', + 'default' => 'CURRENT_TIMESTAMP', 'null_switch' => 'NULL' ] ], @@ -144,8 +142,7 @@ 'store' => NULL, 'tab_name' => NULL, 'db' => [ - 'type' => 'INT(10) unsigned', - 'default' => '0', + 'type' => 'INT unsigned', 'null_switch' => 'NULL', 'key' => true, 'key_name' => 'checkout' @@ -161,7 +158,6 @@ 'tab_name' => NULL, 'db' => [ 'type' => 'DATETIME', - 'default' => '0000-00-00 00:00:00', 'null_switch' => 'NULL' ] ], diff --git a/src/eb7d69c2-4ee9-4bd0-aacc-ab51a12be895/code.php b/src/eb7d69c2-4ee9-4bd0-aacc-ab51a12be895/code.php index 039a8d8..5c96122 100644 --- a/src/eb7d69c2-4ee9-4bd0-aacc-ab51a12be895/code.php +++ b/src/eb7d69c2-4ee9-4bd0-aacc-ab51a12be895/code.php @@ -416,6 +416,8 @@ abstract class Set implements SetInterface $settings = $this->mergeIndexSettings($repoGuid, $settings); + $this->grep->loadApi($this->git, $repo->base ?? null, $repo->token ?? null); + $this->updateIndexMainFile( $repo, $this->getIndexSettingsPath(), @@ -429,6 +431,8 @@ abstract class Set implements SetInterface $this->mainReadme->get($settings), 'Update main readme file' ); + + $this->git->reset_(); } /** @@ -580,7 +584,7 @@ abstract class Set implements SetInterface $this->setRepoPlaceholders($repo); - $this->git->load_($repo->base ?? null, $repo->token ?? null); + $this->grep->loadApi($this->git, $repo->base ?? null, $repo->token ?? null); if (($existing = $this->grep->get($item->guid, ['remote'], $repo)) !== null) { diff --git a/src/eb7d69c2-4ee9-4bd0-aacc-ab51a12be895/code.power b/src/eb7d69c2-4ee9-4bd0-aacc-ab51a12be895/code.power index 64a76b1..26905f2 100644 --- a/src/eb7d69c2-4ee9-4bd0-aacc-ab51a12be895/code.power +++ b/src/eb7d69c2-4ee9-4bd0-aacc-ab51a12be895/code.power @@ -386,6 +386,8 @@ $settings = $this->mergeIndexSettings($repoGuid, $settings); + $this->grep->loadApi($this->git, $repo->base ?? null, $repo->token ?? null); + $this->updateIndexMainFile( $repo, $this->getIndexSettingsPath(), @@ -399,6 +401,8 @@ $this->mainReadme->get($settings), 'Update main readme file' ); + + $this->git->reset_(); } /** @@ -550,7 +554,7 @@ $this->setRepoPlaceholders($repo); - $this->git->load_($repo->base ?? null, $repo->token ?? null); + $this->grep->loadApi($this->git, $repo->base ?? null, $repo->token ?? null); if (($existing = $this->grep->get($item->guid, ['remote'], $repo)) !== null) { diff --git a/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/README.md b/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/README.md index baef041..e647ce3 100644 --- a/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/README.md +++ b/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/README.md @@ -15,6 +15,7 @@ class Message << (F,LightGreen) >> #RoyalBlue { # Update $update # Insert $insert - array $success + - array $info - array $error - ?string $guid - ?string $entity diff --git a/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/code.php b/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/code.php index 30c313b..43cd7be 100644 --- a/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/code.php +++ b/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/code.php @@ -49,6 +49,14 @@ final class Message implements ImportMessageInterface */ private array $success = []; + /** + * The info message bus. + * + * @var array + * @since 5.0.2 + */ + private array $info = []; + /** * The error message bus. * @@ -117,6 +125,8 @@ final class Message implements ImportMessageInterface $this->guid = $guid; $this->entity = $entity; $this->table = $table; + + return $this; } /** diff --git a/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/code.power b/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/code.power index 1cdb0a3..2d4c6bf 100644 --- a/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/code.power +++ b/src/eef6ffc2-2af0-4336-958f-e0b9cf7c4ad0/code.power @@ -22,6 +22,14 @@ */ private array $success = []; + /** + * The info message bus. + * + * @var array + * @since 5.0.2 + */ + private array $info = []; + /** * The error message bus. * @@ -90,6 +98,8 @@ $this->guid = $guid; $this->entity = $entity; $this->table = $table; + + return $this; } /** diff --git a/src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/code.php b/src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/code.php index f28526a..95237bc 100644 --- a/src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/code.php +++ b/src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/code.php @@ -12,6 +12,7 @@ namespace VDM\Joomla\Componentbuilder\Import; +use Joomla\DI\Container; use VDM\Joomla\Service\Table; use VDM\Joomla\Service\Database; use VDM\Joomla\Service\Model; diff --git a/src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/settings.json b/src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/settings.json index 360f3d6..672b508 100644 --- a/src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/settings.json +++ b/src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/settings.json @@ -1,5 +1,5 @@ { - "add_head": "0", + "add_head": "1", "add_licensing_template": "2", "extends": "2e5bf608-de5c-4b00-a20d-47c26aa350d9", "guid": "ff8d5fdb-2d1f-4178-bd18-a43b8efd1068", @@ -28,15 +28,15 @@ "use": "a5daf189-3345-4b13-8716-c51f686f545b", "as": "default" }, - "use_selection6": { + "use_selection4": { "use": "21754a8b-2323-4a77-8459-378a74c1ec97", "as": "default" }, - "use_selection4": { + "use_selection5": { "use": "202ccd9e-dfcf-4cde-a0ce-bde1fd27f088", "as": "default" }, - "use_selection5": { + "use_selection6": { "use": "c4a188de-ad78-4a6d-9d5b-01866846d701", "as": "default" } @@ -45,6 +45,6 @@ "namespace": "[[[NamespacePrefix]]]\\Joomla\\[[[ComponentNamespace]]].Import.Factory", "description": "Import Factory\r\n\r\n@since 3.2.2", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", - "head": "", + "head": "use Joomla\\DI\\Container;", "composer": "" } \ No newline at end of file diff --git a/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/README.md b/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/README.md index 89d7d07..b7b8b64 100644 --- a/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/README.md +++ b/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/README.md @@ -6,51 +6,48 @@ ██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ ``` -# abstract class BaseConfig (Details) +# abstract class FunctionRegistry (Details) > namespace: **VDM\Joomla\Abstraction** -> extends: **JoomlaRegistry** +> extends: **Registry** ```uml @startuml -abstract BaseConfig #Orange { - + __construct() - + __set(string $key, mixed $value) +abstract FunctionRegistry #Orange { + __get(string $key) + get(string $path, mixed $default = null) : mixed + appendArray(string $path, mixed $value) : mixed + # isCallableMethod(string $method) : bool } -note right of BaseConfig::__construct - Constructor - - since: 3.2.0 -end note - -note right of BaseConfig::__set - setting any config value - - since: 3.2.0 -end note - -note right of BaseConfig::__get +note right of FunctionRegistry::__get getting any valid value since: 3.2.0 end note -note right of BaseConfig::get +note right of FunctionRegistry::get Get a config value. since: 3.2.0 return: mixed end note -note right of BaseConfig::appendArray +note right of FunctionRegistry::appendArray Append value to a path in registry of an array since: 3.2.0 return: mixed end note + +note right of FunctionRegistry::isCallableMethod + Determines if a method is callable on this object, excluding certain methods. +This method checks if a method exists on this object and is callable, but excludes +certain methods to prevent unintended access or recursion. It helps to safely determine +if a dynamic getter method can be invoked without interfering with core methods. + + since: 5.0.4 + return: bool +end note @enduml ``` diff --git a/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.php b/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.php index c4debc2..708a0b3 100644 --- a/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.php +++ b/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.php @@ -12,41 +12,17 @@ namespace VDM\Joomla\Abstraction; -use Joomla\Registry\Registry as JoomlaRegistry; use VDM\Joomla\Utilities\String\ClassfunctionHelper; +use VDM\Joomla\Abstraction\Registry; /** - * Config + * A Dynamic Function Registry * - * @since 3.2.0 + * @since 5.0.4 */ -abstract class BaseConfig extends JoomlaRegistry +abstract class FunctionRegistry extends Registry { - /** - * Constructor - * - * @since 3.2.0 - */ - public function __construct() - { - // Instantiate the internal data object. - $this->data = new \stdClass(); - } - - /** - * setting any config value - * - * @param string $key The value's key/path name - * @param mixed $value Optional default value, returned if the internal value is null. - * - * @since 3.2.0 - */ - public function __set($key, $value) - { - $this->set($key, $value); - } - /** * getting any valid value * @@ -76,7 +52,7 @@ abstract class BaseConfig extends JoomlaRegistry * * @since 3.2.0 */ - public function get($path, $default = null) + public function get(string $path, $default = null): mixed { // function name with no underscores $method = 'get' . ucfirst((string) ClassfunctionHelper::safe(str_replace('_', '', $path))); @@ -86,7 +62,8 @@ abstract class BaseConfig extends JoomlaRegistry { return $value; } - elseif (method_exists($this, $method)) + // Use the method if it's callable and not excluded + elseif ($this->isCallableMethod($method)) { $value = $this->{$method}($default); @@ -104,19 +81,46 @@ abstract class BaseConfig extends JoomlaRegistry * @param string $path Parent registry Path (e.g. joomla.content.showauthor) * @param mixed $value Value of entry * - * @return mixed The value of the that has been set. + * @return mixed The values of the path that has been set. * * @since 3.2.0 */ public function appendArray(string $path, $value) { - // check if it does not exist - if (!$this->exists($path)) + return $this->add($path, $value, true)->get($path); + } + + /** + * Determines if a method is callable on this object, excluding certain methods. + * + * This method checks if a method exists on this object and is callable, but excludes + * certain methods to prevent unintended access or recursion. It helps to safely determine + * if a dynamic getter method can be invoked without interfering with core methods. + * + * @param string $method The method name to check. + * + * @return bool True if the method is callable and not excluded, false otherwise. + * @since 5.0.4 + */ + protected function isCallableMethod(string $method): bool + { + // List of methods to exclude from dynamic access + $excludedMethods = [ + 'getActive', + 'get', + 'getSeparator', + 'getIterator', + 'getName', + 'getActiveKeys' + ]; + + // Check if the method exists and is not excluded + if (method_exists($this, $method) && !in_array($method, $excludedMethods, true)) { - $this->set($path, []); + return true; } - return $this->append($path, $value); + return false; } } diff --git a/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.power b/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.power index 9afb467..644dde1 100644 --- a/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.power +++ b/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.power @@ -1,27 +1,3 @@ - /** - * Constructor - * - * @since 3.2.0 - */ - public function __construct() - { - // Instantiate the internal data object. - $this->data = new \stdClass(); - } - - /** - * setting any config value - * - * @param string $key The value's key/path name - * @param mixed $value Optional default value, returned if the internal value is null. - * - * @since 3.2.0 - */ - public function __set($key, $value) - { - $this->set($key, $value); - } - /** * getting any valid value * @@ -51,7 +27,7 @@ * * @since 3.2.0 */ - public function get($path, $default = null) + public function get(string $path, $default = null): mixed { // function name with no underscores $method = 'get' . ucfirst((string) ClassfunctionHelper::safe(str_replace('_', '', $path))); @@ -61,7 +37,8 @@ { return $value; } - elseif (method_exists($this, $method)) + // Use the method if it's callable and not excluded + elseif ($this->isCallableMethod($method)) { $value = $this->{$method}($default); @@ -79,17 +56,44 @@ * @param string $path Parent registry Path (e.g. joomla.content.showauthor) * @param mixed $value Value of entry * - * @return mixed The value of the that has been set. + * @return mixed The values of the path that has been set. * * @since 3.2.0 */ public function appendArray(string $path, $value) { - // check if it does not exist - if (!$this->exists($path)) + return $this->add($path, $value, true)->get($path); + } + + /** + * Determines if a method is callable on this object, excluding certain methods. + * + * This method checks if a method exists on this object and is callable, but excludes + * certain methods to prevent unintended access or recursion. It helps to safely determine + * if a dynamic getter method can be invoked without interfering with core methods. + * + * @param string $method The method name to check. + * + * @return bool True if the method is callable and not excluded, false otherwise. + * @since 5.0.4 + */ + protected function isCallableMethod(string $method): bool + { + // List of methods to exclude from dynamic access + $excludedMethods = [ + 'getActive', + 'get', + 'getSeparator', + 'getIterator', + 'getName', + 'getActiveKeys' + ]; + + // Check if the method exists and is not excluded + if (method_exists($this, $method) && !in_array($method, $excludedMethods, true)) { - $this->set($path, []); + return true; } - return $this->append($path, $value); + return false; } \ No newline at end of file diff --git a/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/settings.json b/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/settings.json index 315a0c3..103efb8 100644 --- a/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/settings.json +++ b/src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/settings.json @@ -1,13 +1,13 @@ { - "add_head": "1", + "add_head": "0", "add_licensing_template": "2", - "extends": "-1", + "extends": "7e822c03-1b20-41d1-9427-f5b8d5836af7", "guid": "ffbd4e1f-a342-4080-ab7d-1de3741bf319", "implements": null, "load_selection": null, - "name": "BaseConfig", + "name": "FunctionRegistry", "power_version": "1.0.0", - "system_name": "VDM.Abstraction.BaseConfig", + "system_name": "VDM.Abstraction.FunctionRegistry", "type": "abstract class", "use_selection": { "use_selection0": { @@ -16,10 +16,9 @@ } }, "extendsinterfaces": null, - "namespace": "[[[NamespacePrefix]]]\\Joomla\\Abstraction.BaseConfig", - "description": "Config\r\n\r\n@since 3.2.0", - "extends_custom": "JoomlaRegistry", + "namespace": "[[[NamespacePrefix]]]\\Joomla\\Abstraction.FunctionRegistry", + "description": "A Dynamic Function Registry\r\n\r\n@since 5.0.4", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", - "head": "use Joomla\\Registry\\Registry as JoomlaRegistry;", + "head": "", "composer": "" } \ No newline at end of file diff --git a/super-powers.json b/super-powers.json index 4114f8a..1cfbd76 100644 --- a/super-powers.json +++ b/super-powers.json @@ -88,7 +88,7 @@ "guid": "0f3f7188-3e0d-4d1a-8dee-7f8026cb65a9" }, "11572d9b-e3d5-4b29-904c-9618d8f2bfd8": { - "name": "Count", + "name": "PathCount", "type": "trait", "namespace": "VDM\\Joomla\\Abstraction\\Registry\\Traits", "code": "src\/11572d9b-e3d5-4b29-904c-9618d8f2bfd8\/code.php", @@ -770,7 +770,7 @@ "guid": "7c1fb50f-8fb1-4627-8705-6fedf7182ca5" }, "7d494d91-ab60-43cd-aecf-d50e07f7f30e": { - "name": "ToString", + "name": "PathToString", "type": "trait", "namespace": "VDM\\Joomla\\Abstraction\\Registry\\Traits", "code": "src\/7d494d91-ab60-43cd-aecf-d50e07f7f30e\/code.php", @@ -912,6 +912,17 @@ "spk": "Super---95c02df3_fe0a_405b_b506_b7a5b8605b66---Power", "guid": "95c02df3-fe0a-405b-b506-b7a5b8605b66" }, + "9769f3b2-17bf-4f20-b54b-3a4ebe572b36": { + "name": "ComponentConfig", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Componentbuilder\\Abstraction", + "code": "src\/9769f3b2-17bf-4f20-b54b-3a4ebe572b36\/code.php", + "power": "src\/9769f3b2-17bf-4f20-b54b-3a4ebe572b36\/code.power", + "settings": "src\/9769f3b2-17bf-4f20-b54b-3a4ebe572b36\/settings.json", + "path": "src\/9769f3b2-17bf-4f20-b54b-3a4ebe572b36", + "spk": "Super---9769f3b2_17bf_4f20_b54b_3a4ebe572b36---Power", + "guid": "9769f3b2-17bf-4f20-b54b-3a4ebe572b36" + }, "993fe913-8e36-4800-a5f7-544aa728ee48": { "name": "DateHelper", "type": "abstract class", @@ -1441,7 +1452,7 @@ "guid": "ff8d5fdb-2d1f-4178-bd18-a43b8efd1068" }, "ffbd4e1f-a342-4080-ab7d-1de3741bf319": { - "name": "BaseConfig", + "name": "FunctionRegistry", "type": "abstract class", "namespace": "VDM\\Joomla\\Abstraction", "code": "src\/ffbd4e1f-a342-4080-ab7d-1de3741bf319\/code.php",