From 428bbdc503d07ce7ee7e83969d76561084c50a74 Mon Sep 17 00:00:00 2001 From: aB0t Date: Sat, 25 May 2024 20:54:21 +0200 Subject: [PATCH] update 2024-05-25 20:54:21 --- README.md | 2 +- .../README.md | 37 +-- .../code.php | 127 ++++++---- .../code.power | 122 +++++---- .../settings.json | 6 +- .../code.php | 2 +- .../README.md | 74 +----- .../code.php | 234 +++--------------- .../code.power | 225 +++-------------- .../settings.json | 12 +- super-powers.json | 2 +- 11 files changed, 255 insertions(+), 588 deletions(-) diff --git a/README.md b/README.md index 74fc8ad..4e4c3ac 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ This repository contains an index (see below) of all the approved powers within - **abstract class Factory** | [Details](src/a5734b9e-a72d-494c-bc72-c3bc7506015f) | [Code](src/a5734b9e-a72d-494c-bc72-c3bc7506015f/code.php) | [Settings](src/a5734b9e-a72d-494c-bc72-c3bc7506015f/settings.json) | Super__a5734b9e_a72d_494c_bc72_c3bc7506015f__Power - **final class Generator** | [Details](src/505801ac-d3e2-44c6-a300-9a57a96170c6) | [Code](src/505801ac-d3e2-44c6-a300-9a57a96170c6/code.php) | [Settings](src/505801ac-d3e2-44c6-a300-9a57a96170c6/settings.json) | Super__505801ac_d3e2_44c6_a300_9a57a96170c6__Power + - **final class Grep** | [Details](src/6784dd52-0909-451a-a872-9a942a023c68) | [Code](src/6784dd52-0909-451a-a872-9a942a023c68/code.php) | [Settings](src/6784dd52-0909-451a-a872-9a942a023c68/settings.json) | Super__6784dd52_0909_451a_a872_9a942a023c68__Power - **class Config** | [Details](src/be4ccfae-65a9-401e-bdbe-637d8c226954) | [Code](src/be4ccfae-65a9-401e-bdbe-637d8c226954/code.php) | [Settings](src/be4ccfae-65a9-401e-bdbe-637d8c226954/settings.json) | Super__be4ccfae_65a9_401e_bdbe_637d8c226954__Power - - **class Grep** | [Details](src/6784dd52-0909-451a-a872-9a942a023c68) | [Code](src/6784dd52-0909-451a-a872-9a942a023c68/code.php) | [Settings](src/6784dd52-0909-451a-a872-9a942a023c68/settings.json) | Super__6784dd52_0909_451a_a872_9a942a023c68__Power - **class Super** | [Details](src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff) | [Code](src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff/code.php) | [Settings](src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff/settings.json) | Super__3ab0eba9_f37b_4b37_aec1_2e78067f2aff__Power - **Namespace**: [VDM\Joomla\Componentbuilder\Service](#vdm-joomla-componentbuilder-service) diff --git a/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/README.md b/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/README.md index 9db14d2..c09270f 100644 --- a/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/README.md +++ b/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/README.md @@ -12,14 +12,22 @@ ```uml @startuml class Grep << (F,LightGreen) >> #RoyalBlue { - - getLocal(object $path, string $guid) : ?object + # array $order + # remoteIndex(object $path) : void + - searchRemote(string $guid) : ?object - getRemote(object $path, string $guid) : ?object - - localIndex(object $path) : void - - remoteIndex(object $path) : void + - loadRemoteFile(string $owner, string $repo, ...) : mixed } -note right of Grep::getLocal - Get a local power +note right of Grep::remoteIndex + Load the remote repository index of powers + + since: 3.2.0 + return: void +end note + +note right of Grep::searchRemote + Search for a remote power since: 3.2.0 return: ?object @@ -32,18 +40,17 @@ note right of Grep::getRemote return: ?object end note -note right of Grep::localIndex - Load the local repository index of powers +note right of Grep::loadRemoteFile + Load the remote file since: 3.2.0 - return: void -end note - -note right of Grep::remoteIndex - Load the remote repository index of powers - - since: 3.2.0 - return: void + return: mixed + + arguments: + string $owner + string $repo + string $path + ?string $branch end note @enduml diff --git a/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/code.php b/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/code.php index 1c0b0ed..54d2898 100644 --- a/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/code.php +++ b/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/code.php @@ -12,10 +12,11 @@ namespace VDM\Joomla\Componentbuilder\JoomlaPower; +use Joomla\CMS\Language\Text; use VDM\Joomla\Utilities\FileHelper; use VDM\Joomla\Utilities\JsonHelper; -use VDM\Joomla\Componentbuilder\Interfaces\GrepInterface; -use VDM\Joomla\Componentbuilder\Power\Grep as ExtendingGrep; +use VDM\Joomla\Interfaces\GrepInterface; +use VDM\Joomla\Abstraction\Grep as ExtendingGrep; /** @@ -31,30 +32,65 @@ use VDM\Joomla\Componentbuilder\Power\Grep as ExtendingGrep; final class Grep extends ExtendingGrep implements GrepInterface { /** - * Get a local power + * Order of global search + * + * @var array + * @since 3.2.1 + **/ + protected array $order = ['remote']; + + /** + * Load the remote repository index of powers * * @param object $path The repository path details + * + * @return void + * @since 3.2.0 + */ + protected function remoteIndex(object &$path): void + { + if (isset($path->index)) + { + return; + } + + try + { + $path->index = $this->contents->get($path->owner, $path->repo, 'joomla-powers.json', $path->branch); + } + catch (\Exception $e) + { + $this->app->enqueueMessage( + Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path->path, $e->getMessage()), + 'Error' + ); + + $path->index = null; + } + } + + /** + * Search for a remote power + * * @param string $guid The global unique id of the power * * @return object|null * @since 3.2.0 */ - private function getLocal(object $path, string $guid): ?object + private function searchRemote(string $guid): ?object { - if (empty($path->local->{$guid}->settings)) + // we can only search if we have paths + if ($this->path && $this->paths) { - return null; - } - - // get the settings - if (($settings = FileHelper::getContent($path->full_path . '/' . $path->local->{$guid}->settings, null)) !== null && - JsonHelper::check($settings)) - { - $power = json_decode($settings); - - if (isset($power->guid)) + foreach ($this->paths as $path) { - return $power; + // get local index + $this->remoteIndex($path); + + if (!empty($path->index) && isset($path->index->{$guid})) + { + return $this->getRemote($path, $guid); + } } } @@ -81,6 +117,15 @@ final class Grep extends ExtendingGrep implements GrepInterface if (($power = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->settings, $path->branch)) !== null && isset($power->guid)) { + // set the git details in params + $power->params = (object) [ + 'git' => [ + 'owner' => $path->owner, + 'repo' => $path->repo, + 'branch' => $path->branch + ] + ]; + return $power; } @@ -88,59 +133,33 @@ final class Grep extends ExtendingGrep implements GrepInterface } /** - * Load the local repository index of powers + * Load the remote file * - * @param object $path The repository path details + * @param string $owner The repository owner + * @param string $repo The repository name + * @param string $path The repository path to file + * @param string|null $branch The repository branch name * - * @return void + * @return mixed * @since 3.2.0 */ - private function localIndex(object &$path) + private function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch) { - if (isset($path->local) || !isset($path->full_path)) - { - return; - } - - if (($content = FileHelper::getContent($path->full_path . '/joomla-powers.json', null)) !== null && - JsonHelper::check($content)) - { - $path->local = json_decode($content); - - return; - } - - $path->local = null; - } - - /** - * Load the remote repository index of powers - * - * @param object $path The repository path details - * - * @return void - * @since 3.2.0 - */ - private function remoteIndex(object &$path) - { - if (isset($path->index)) - { - return; - } - try { - $path->index = $this->contents->get($path->owner, $path->repo, 'joomla-powers.json', $path->branch); + $data = $this->contents->get($owner, $repo, $path, $branch); } catch (\Exception $e) { $this->app->enqueueMessage( - Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path->path, $e->getMessage()), + Text::sprintf('COM_COMPONENTBUILDER_PFILE_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path, $e->getMessage()), 'Error' ); - $path->index = null; + return null; } + + return $data; } } diff --git a/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/code.power b/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/code.power index 009ffc9..be21fe6 100644 --- a/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/code.power +++ b/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/code.power @@ -1,28 +1,63 @@ /** - * Get a local power + * Order of global search + * + * @var array + * @since 3.2.1 + **/ + protected array $order = ['remote']; + + /** + * Load the remote repository index of powers * * @param object $path The repository path details + * + * @return void + * @since 3.2.0 + */ + protected function remoteIndex(object &$path): void + { + if (isset($path->index)) + { + return; + } + + try + { + $path->index = $this->contents->get($path->owner, $path->repo, 'joomla-powers.json', $path->branch); + } + catch (\Exception $e) + { + $this->app->enqueueMessage( + Text::sprintf('

Super Power repository at %s/%s gave the following error!
%s

', $this->contents->api(), $path->path, $e->getMessage()), + 'Error' + ); + + $path->index = null; + } + } + + /** + * Search for a remote power + * * @param string $guid The global unique id of the power * * @return object|null * @since 3.2.0 */ - private function getLocal(object $path, string $guid): ?object + private function searchRemote(string $guid): ?object { - if (empty($path->local->{$guid}->settings)) + // we can only search if we have paths + if ($this->path && $this->paths) { - return null; - } - - // get the settings - if (($settings = FileHelper::getContent($path->full_path . '/' . $path->local->{$guid}->settings, null)) !== null && - JsonHelper::check($settings)) - { - $power = json_decode($settings); - - if (isset($power->guid)) + foreach ($this->paths as $path) { - return $power; + // get local index + $this->remoteIndex($path); + + if (!empty($path->index) && isset($path->index->{$guid})) + { + return $this->getRemote($path, $guid); + } } } @@ -49,6 +84,15 @@ if (($power = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->settings, $path->branch)) !== null && isset($power->guid)) { + // set the git details in params + $power->params = (object) [ + 'git' => [ + 'owner' => $path->owner, + 'repo' => $path->repo, + 'branch' => $path->branch + ] + ]; + return $power; } @@ -56,57 +100,31 @@ } /** - * Load the local repository index of powers + * Load the remote file * - * @param object $path The repository path details + * @param string $owner The repository owner + * @param string $repo The repository name + * @param string $path The repository path to file + * @param string|null $branch The repository branch name * - * @return void + * @return mixed * @since 3.2.0 */ - private function localIndex(object &$path) + private function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch) { - if (isset($path->local) || !isset($path->full_path)) - { - return; - } - - if (($content = FileHelper::getContent($path->full_path . '/joomla-powers.json', null)) !== null && - JsonHelper::check($content)) - { - $path->local = json_decode($content); - - return; - } - - $path->local = null; - } - - /** - * Load the remote repository index of powers - * - * @param object $path The repository path details - * - * @return void - * @since 3.2.0 - */ - private function remoteIndex(object &$path) - { - if (isset($path->index)) - { - return; - } - try { - $path->index = $this->contents->get($path->owner, $path->repo, 'joomla-powers.json', $path->branch); + $data = $this->contents->get($owner, $repo, $path, $branch); } catch (\Exception $e) { $this->app->enqueueMessage( - Text::sprintf('

Super Power repository at %s/%s gave the following error!
%s

', $this->contents->api(), $path->path, $e->getMessage()), + Text::sprintf('

File at %s/%s gave the following error!
%s

', $this->contents->api(), $path, $e->getMessage()), 'Error' ); - $path->index = null; + return null; } + + return $data; } \ No newline at end of file diff --git a/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/settings.json b/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/settings.json index 860a6b5..0571cda 100644 --- a/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/settings.json +++ b/src/355bf21a-f859-4528-9110-bcd2c6d05ea7/settings.json @@ -1,7 +1,7 @@ { - "add_head": "0", + "add_head": "1", "add_licensing_template": "2", - "extends": "6784dd52-0909-451a-a872-9a942a023c68", + "extends": "1401a167-0ce4-4f4a-afee-2d8b02ed339b", "guid": "355bf21a-f859-4528-9110-bcd2c6d05ea7", "implements": [ "c182506a-ab84-439c-b962-1e606b58d545" @@ -24,6 +24,6 @@ "namespace": "VDM\\Joomla\\Componentbuilder.JoomlaPower.Grep", "description": "Global Resource Empowerment Platform\r\n\r\n The Grep feature will try to find your joomla power in the repositories listed in the global\r\n Options of JCB in the super powers tab, and if it can't be found there will try the global core\r\n Super powers of JCB. All searches are performed according the the [algorithm:cascading]\r\n See documentation for more details: https:\/\/git.vdm.dev\/joomla\/super-powers\/wiki\r\n\r\n@since 3.2.1", "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/3ab0eba9-f37b-4b37-aec1-2e78067f2aff/code.php b/src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff/code.php index 223cf92..97b62ad 100644 --- a/src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff/code.php +++ b/src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff/code.php @@ -12,7 +12,7 @@ namespace VDM\Joomla\Componentbuilder\Power; -use VDM\Joomla\Componentbuilder\Interfaces\GrepInterface as Grep; +use VDM\Joomla\Interfaces\GrepInterface as Grep; use VDM\Joomla\Componentbuilder\Interfaces\Database\InsertInterface as Insert; use VDM\Joomla\Componentbuilder\Interfaces\Database\UpdateInterface as Update; use VDM\Joomla\Utilities\GuidHelper; diff --git a/src/6784dd52-0909-451a-a872-9a942a023c68/README.md b/src/6784dd52-0909-451a-a872-9a942a023c68/README.md index e28bfee..8ef01c0 100644 --- a/src/6784dd52-0909-451a-a872-9a942a023c68/README.md +++ b/src/6784dd52-0909-451a-a872-9a942a023c68/README.md @@ -6,56 +6,29 @@ ██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ ``` -# class Grep (Details) +# final class Grep (Details) > namespace: **VDM\Joomla\Componentbuilder\Power** +> extends: **ExtendingGrep** ```uml @startuml -class Grep #Gold { - + ?string $path - + ?array $paths - # Contents $contents - # CMSApplication $app - + __construct(string $path, array $paths, ...) - + getRemotePowersGuid() : ?array - + get(string $guid, array $order = ['local', 'remote']) : ?object +class Grep << (F,LightGreen) >> #RoyalBlue { + # remoteIndex(object $path) : void - searchLocal(string $guid) : ?object - searchRemote(string $guid) : ?object - getLocal(object $path, string $guid) : ?object - getRemote(object $path, string $guid) : ?object - - init() : void - - localIndex(object $path) : void - - remoteIndex(object $path) : void - loadRemoteFile(string $owner, string $repo, ...) : mixed - - getFunctionName(string $name) : ?string + - localIndex(object $path) : void } -note right of Grep::__construct - Constructor. +note right of Grep::remoteIndex + Load the remote repository index of powers since: 3.2.0 - - arguments: - string $path - array $paths - Contents $contents - ?CMSApplication $app = null + return: void end note -note left of Grep::getRemotePowersGuid - Get all remote powers GUID's - - since: 3.2.0 - return: ?array -end note - -note right of Grep::get - Get a power - - since: 3.2.0 - return: ?object -end note - -note left of Grep::searchLocal +note right of Grep::searchLocal Search for a local power since: 3.2.0 @@ -69,7 +42,7 @@ note right of Grep::searchRemote return: ?object end note -note left of Grep::getLocal +note right of Grep::getLocal Get a local power since: 3.2.0 @@ -83,27 +56,6 @@ note right of Grep::getRemote return: ?object end note -note left of Grep::init - Set path details - - since: 3.2.0 - return: void -end note - -note right of Grep::localIndex - Load the local repository index of powers - - since: 3.2.0 - return: void -end note - -note left of Grep::remoteIndex - Load the remote repository index of powers - - since: 3.2.0 - return: void -end note - note right of Grep::loadRemoteFile Load the remote file @@ -117,11 +69,11 @@ note right of Grep::loadRemoteFile ?string $branch end note -note left of Grep::getFunctionName - Get function name +note right of Grep::localIndex + Load the local repository index of powers since: 3.2.0 - return: ?string + return: void end note @enduml diff --git a/src/6784dd52-0909-451a-a872-9a942a023c68/code.php b/src/6784dd52-0909-451a-a872-9a942a023c68/code.php index 20e2e9d..936c5f8 100644 --- a/src/6784dd52-0909-451a-a872-9a942a023c68/code.php +++ b/src/6784dd52-0909-451a-a872-9a942a023c68/code.php @@ -12,14 +12,11 @@ namespace VDM\Joomla\Componentbuilder\Power; -use Joomla\CMS\Factory; -use Joomla\CMS\Filesystem\Folder; -use Joomla\CMS\Application\CMSApplication; use Joomla\CMS\Language\Text; -use VDM\Joomla\Gitea\Repository\Contents; use VDM\Joomla\Utilities\FileHelper; use VDM\Joomla\Utilities\JsonHelper; -use VDM\Joomla\Componentbuilder\Interfaces\GrepInterface; +use VDM\Joomla\Interfaces\GrepInterface; +use VDM\Joomla\Abstraction\Grep as ExtendingGrep; /** @@ -32,114 +29,36 @@ use VDM\Joomla\Componentbuilder\Interfaces\GrepInterface; * * @since 3.2.0 */ -class Grep implements GrepInterface +final class Grep extends ExtendingGrep implements GrepInterface { /** - * The local path + * Load the remote repository index of powers * - * @var string - * @since 3.2.0 - **/ - public ?string $path; - - /** - * All approved paths + * @param object $path The repository path details * - * @var array - * @since 3.2.0 - **/ - public ?array $paths; - - /** - * Gitea Repository Contents - * - * @var Contents - * @since 3.2.0 - **/ - protected Contents $contents; - - /** - * Joomla Application object - * - * @var CMSApplication - * @since 3.2.0 - **/ - protected CMSApplication $app; - - /** - * Constructor. - * - * @param string $path The local path - * @param array $paths The approved paths - * @param Contents $contents The Gitea Repository Contents object. - * @param CMSApplication|null $app The CMS Application object. - * - * @throws \Exception + * @return void * @since 3.2.0 */ - public function __construct(string $path, array $paths, Contents $contents, ?CMSApplication $app = null) + protected function remoteIndex(object &$path): void { - $this->path = $path; - $this->paths = $paths; - $this->contents = $contents; - $this->app = $app ?: Factory::getApplication(); - - $this->init(); - } - - /** - * Get all remote powers GUID's - * - * @return array|null - * @since 3.2.0 - */ - public function getRemotePowersGuid(): ?array - { - if (!is_array($this->paths) || $this->paths === []) + if (isset($path->index)) { - return null; + return; } - $powers = []; - foreach ($this->paths as $path) + try { - // Get local index - $this->remoteIndex($path); - - if (isset($path->index) && is_object($path->index)) - { - $powers = array_merge($powers, array_keys((array) $path->index)); - } + $path->index = $this->contents->get($path->owner, $path->repo, 'super-powers.json', $path->branch); } - - return empty($powers) ? null : array_unique($powers); - } - - /** - * Get a power - * - * @param string $guid The global unique id of the power - * @param array $order The search order - * - * @return object|null - * @since 3.2.0 - */ - public function get(string $guid, array $order = ['local', 'remote']): ?object - { - // we can only search if we have paths - if (is_array($this->paths) && $this->paths !== []) + catch (\Exception $e) { - foreach ($order as $target) - { - if (($function_name = $this->getFunctionName($target)) !== null && - ($power = $this->{$function_name}($guid)) !== null) - { - return $power; - } - } - } + $this->app->enqueueMessage( + Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path->path, $e->getMessage()), + 'Error' + ); - return null; + $path->index = null; + } } /** @@ -262,100 +181,6 @@ class Grep implements GrepInterface return null; } - /** - * Set path details - * - * @return void - * @since 3.2.0 - */ - private function init() - { - if (is_array($this->paths) && $this->paths !== []) - { - foreach ($this->paths as $n => &$path) - { - if (isset($path->owner) && strlen($path->owner) > 1 && - isset($path->repo) && strlen($path->repo) > 1) - { - // build the path - $path->path = trim($path->owner) . '/' . trim($path->repo); - - // update the branch - if ($path->branch === 'default' || empty($path->branch)) - { - $path->branch = null; - } - - // set local path - if ($this->path && Folder::exists($this->path . '/' . $path->path)) - { - $path->full_path = $this->path . '/' . $path->path; - } - } - else - { - unset($this->paths[$n]); - } - } - } - } - - /** - * Load the local repository index of powers - * - * @param object $path The repository path details - * - * @return void - * @since 3.2.0 - */ - private function localIndex(object &$path) - { - if (isset($path->local) || !isset($path->full_path)) - { - return; - } - - if (($content = FileHelper::getContent($path->full_path . '/super-powers.json', null)) !== null && - JsonHelper::check($content)) - { - $path->local = json_decode($content); - - return; - } - - $path->local = null; - } - - /** - * Load the remote repository index of powers - * - * @param object $path The repository path details - * - * @return void - * @since 3.2.0 - */ - private function remoteIndex(object &$path) - { - if (isset($path->index)) - { - return; - } - - try - { - $path->index = $this->contents->get($path->owner, $path->repo, 'super-powers.json', $path->branch); - } - catch (\Exception $e) - { - $this->app->enqueueMessage( - Text::sprintf('COM_COMPONENTBUILDER_PSUPER_POWERB_REPOSITORY_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path->path, $e->getMessage()), - 'Error' - ); - - $path->index = null; - } - } - /** * Load the remote file * @@ -387,18 +212,29 @@ class Grep implements GrepInterface } /** - * Get function name + * Load the local repository index of powers * - * @param string $name The targeted function name + * @param object $path The repository path details * - * @return string|null + * @return void * @since 3.2.0 */ - private function getFunctionName(string $name): ?string + private function localIndex(object &$path) { - $function_name = 'search' . ucfirst(strtolower($name)); + if (isset($path->local) || !isset($path->full_path)) + { + return; + } - return method_exists($this, $function_name) ? $function_name : null; + if (($content = FileHelper::getContent($path->full_path . '/super-powers.json', null)) !== null && + JsonHelper::check($content)) + { + $path->local = json_decode($content); + + return; + } + + $path->local = null; } } diff --git a/src/6784dd52-0909-451a-a872-9a942a023c68/code.power b/src/6784dd52-0909-451a-a872-9a942a023c68/code.power index 2feb4f0..6695d78 100644 --- a/src/6784dd52-0909-451a-a872-9a942a023c68/code.power +++ b/src/6784dd52-0909-451a-a872-9a942a023c68/code.power @@ -1,109 +1,31 @@ /** - * The local path + * Load the remote repository index of powers * - * @var string - * @since 3.2.0 - **/ - public ?string $path; - - /** - * All approved paths + * @param object $path The repository path details * - * @var array - * @since 3.2.0 - **/ - public ?array $paths; - - /** - * Gitea Repository Contents - * - * @var Contents - * @since 3.2.0 - **/ - protected Contents $contents; - - /** - * Joomla Application object - * - * @var CMSApplication - * @since 3.2.0 - **/ - protected CMSApplication $app; - - /** - * Constructor. - * - * @param string $path The local path - * @param array $paths The approved paths - * @param Contents $contents The Gitea Repository Contents object. - * @param CMSApplication|null $app The CMS Application object. - * - * @throws \Exception + * @return void * @since 3.2.0 */ - public function __construct(string $path, array $paths, Contents $contents, ?CMSApplication $app = null) + protected function remoteIndex(object &$path): void { - $this->path = $path; - $this->paths = $paths; - $this->contents = $contents; - $this->app = $app ?: Factory::getApplication(); - - $this->init(); - } - - /** - * Get all remote powers GUID's - * - * @return array|null - * @since 3.2.0 - */ - public function getRemotePowersGuid(): ?array - { - if (!is_array($this->paths) || $this->paths === []) + if (isset($path->index)) { - return null; + return; } - $powers = []; - foreach ($this->paths as $path) + try { - // Get local index - $this->remoteIndex($path); - - if (isset($path->index) && is_object($path->index)) - { - $powers = array_merge($powers, array_keys((array) $path->index)); - } + $path->index = $this->contents->get($path->owner, $path->repo, 'super-powers.json', $path->branch); } - - return empty($powers) ? null : array_unique($powers); - } - - /** - * Get a power - * - * @param string $guid The global unique id of the power - * @param array $order The search order - * - * @return object|null - * @since 3.2.0 - */ - public function get(string $guid, array $order = ['local', 'remote']): ?object - { - // we can only search if we have paths - if (is_array($this->paths) && $this->paths !== []) + catch (\Exception $e) { - foreach ($order as $target) - { - if (($function_name = $this->getFunctionName($target)) !== null && - ($power = $this->{$function_name}($guid)) !== null) - { - return $power; - } - } - } + $this->app->enqueueMessage( + Text::sprintf('

Super Power repository at %s/%s gave the following error!
%s

', $this->contents->api(), $path->path, $e->getMessage()), + 'Error' + ); - return null; + $path->index = null; + } } /** @@ -226,100 +148,6 @@ return null; } - /** - * Set path details - * - * @return void - * @since 3.2.0 - */ - private function init() - { - if (is_array($this->paths) && $this->paths !== []) - { - foreach ($this->paths as $n => &$path) - { - if (isset($path->owner) && strlen($path->owner) > 1 && - isset($path->repo) && strlen($path->repo) > 1) - { - // build the path - $path->path = trim($path->owner) . '/' . trim($path->repo); - - // update the branch - if ($path->branch === 'default' || empty($path->branch)) - { - $path->branch = null; - } - - // set local path - if ($this->path && Folder::exists($this->path . '/' . $path->path)) - { - $path->full_path = $this->path . '/' . $path->path; - } - } - else - { - unset($this->paths[$n]); - } - } - } - } - - /** - * Load the local repository index of powers - * - * @param object $path The repository path details - * - * @return void - * @since 3.2.0 - */ - private function localIndex(object &$path) - { - if (isset($path->local) || !isset($path->full_path)) - { - return; - } - - if (($content = FileHelper::getContent($path->full_path . '/super-powers.json', null)) !== null && - JsonHelper::check($content)) - { - $path->local = json_decode($content); - - return; - } - - $path->local = null; - } - - /** - * Load the remote repository index of powers - * - * @param object $path The repository path details - * - * @return void - * @since 3.2.0 - */ - private function remoteIndex(object &$path) - { - if (isset($path->index)) - { - return; - } - - try - { - $path->index = $this->contents->get($path->owner, $path->repo, 'super-powers.json', $path->branch); - } - catch (\Exception $e) - { - $this->app->enqueueMessage( - Text::sprintf('

Super Power repository at %s/%s gave the following error!
%s

', $this->contents->api(), $path->path, $e->getMessage()), - 'Error' - ); - - $path->index = null; - } - } - /** * Load the remote file * @@ -351,16 +179,27 @@ } /** - * Get function name + * Load the local repository index of powers * - * @param string $name The targeted function name + * @param object $path The repository path details * - * @return string|null + * @return void * @since 3.2.0 */ - private function getFunctionName(string $name): ?string + private function localIndex(object &$path) { - $function_name = 'search' . ucfirst(strtolower($name)); + if (isset($path->local) || !isset($path->full_path)) + { + return; + } - return method_exists($this, $function_name) ? $function_name : null; + if (($content = FileHelper::getContent($path->full_path . '/super-powers.json', null)) !== null && + JsonHelper::check($content)) + { + $path->local = json_decode($content); + + return; + } + + $path->local = null; } \ No newline at end of file diff --git a/src/6784dd52-0909-451a-a872-9a942a023c68/settings.json b/src/6784dd52-0909-451a-a872-9a942a023c68/settings.json index 019c0b4..3f59c97 100644 --- a/src/6784dd52-0909-451a-a872-9a942a023c68/settings.json +++ b/src/6784dd52-0909-451a-a872-9a942a023c68/settings.json @@ -1,7 +1,7 @@ { "add_head": "1", "add_licensing_template": "2", - "extends": "0", + "extends": "1401a167-0ce4-4f4a-afee-2d8b02ed339b", "guid": "6784dd52-0909-451a-a872-9a942a023c68", "implements": [ "c182506a-ab84-439c-b962-1e606b58d545" @@ -10,17 +10,13 @@ "name": "Grep", "power_version": "1.0.0", "system_name": "JCB.Power.Grep", - "type": "class", + "type": "final class", "use_selection": { "use_selection0": { - "use": "8d1baef6-fcad-49a9-848f-428009cdb989", - "as": "default" - }, - "use_selection1": { "use": "a223b31e-ea1d-4cdf-92ae-5f9becffaff0", "as": "default" }, - "use_selection2": { + "use_selection1": { "use": "4b225c51-d293-48e4-b3f6-5136cf5c3f18", "as": "default" } @@ -28,6 +24,6 @@ "namespace": "VDM\\Joomla\\Componentbuilder.Power.Grep", "description": "Global Resource Empowerment Platform\r\n\r\n The Grep feature will try to find your power in the repositories listed in the global\r\n Options of JCB in the super powers tab, and if it can't be found there will try the global core\r\n Super powers of JCB. All searches are performed according the the [algorithm:cascading]\r\n See documentation for more details: https:\/\/git.vdm.dev\/joomla\/super-powers\/wiki\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\\CMS\\Factory;\r\nuse Joomla\\CMS\\Filesystem\\Folder;\r\nuse Joomla\\CMS\\Application\\CMSApplication;\r\nuse Joomla\\CMS\\Language\\Text;", + "head": "use Joomla\\CMS\\Language\\Text;", "composer": "" } \ No newline at end of file diff --git a/super-powers.json b/super-powers.json index 1228b09..9189ac3 100644 --- a/super-powers.json +++ b/super-powers.json @@ -1662,7 +1662,7 @@ }, "6784dd52-0909-451a-a872-9a942a023c68": { "name": "Grep", - "type": "class", + "type": "final class", "namespace": "VDM\\Joomla\\Componentbuilder\\Power", "code": "src\/6784dd52-0909-451a-a872-9a942a023c68\/code.php", "power": "src\/6784dd52-0909-451a-a872-9a942a023c68\/code.power",