forked from joomla/super-powers
update 2024-05-25 20:54:21
This commit is contained in:
parent
1ca58eedb8
commit
e5b7d5ca87
@ -29,6 +29,7 @@ This repository contains an index (see below) of all the approved powers within
|
|||||||
- **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) | Super__ffbd4e1f_a342_4080_ab7d_1de3741bf319__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) | 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) | Super__e0f6ddbe_2a35_4537_942c_faff2ebd04f6__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) | 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) | Super__6cbef8f8_4813_48e3_b05a_65e1aea95171__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) | Super__6cbef8f8_4813_48e3_b05a_65e1aea95171__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) | 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) | Super__584747d1_3a86_453d_b7a3_a2219de8d777__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) | Super__584747d1_3a86_453d_b7a3_a2219de8d777__Power
|
||||||
- **abstract class Registry** | [Details](src/7e822c03-1b20-41d1-9427-f5b8d5836af7) | [Code](src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.php) | [Settings](src/7e822c03-1b20-41d1-9427-f5b8d5836af7/settings.json) | Super__7e822c03_1b20_41d1_9427_f5b8d5836af7__Power
|
- **abstract class Registry** | [Details](src/7e822c03-1b20-41d1-9427-f5b8d5836af7) | [Code](src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.php) | [Settings](src/7e822c03-1b20-41d1-9427-f5b8d5836af7/settings.json) | Super__7e822c03_1b20_41d1_9427_f5b8d5836af7__Power
|
||||||
- **abstract class Schema** | [Details](src/f3c04c28-bce4-422e-be93-7d163e4e342b) | [Code](src/f3c04c28-bce4-422e-be93-7d163e4e342b/code.php) | [Settings](src/f3c04c28-bce4-422e-be93-7d163e4e342b/settings.json) | Super__f3c04c28_bce4_422e_be93_7d163e4e342b__Power
|
- **abstract class Schema** | [Details](src/f3c04c28-bce4-422e-be93-7d163e4e342b) | [Code](src/f3c04c28-bce4-422e-be93-7d163e4e342b/code.php) | [Settings](src/f3c04c28-bce4-422e-be93-7d163e4e342b/settings.json) | Super__f3c04c28_bce4_422e_be93_7d163e4e342b__Power
|
||||||
@ -44,6 +45,7 @@ This repository contains an index (see below) of all the approved powers within
|
|||||||
|
|
||||||
- **interface Activeregistryinterface** | [Details](src/af0eedbe-603b-4671-8e5a-28165d88254b) | [Code](src/af0eedbe-603b-4671-8e5a-28165d88254b/code.php) | [Settings](src/af0eedbe-603b-4671-8e5a-28165d88254b/settings.json) | Super__af0eedbe_603b_4671_8e5a_28165d88254b__Power
|
- **interface Activeregistryinterface** | [Details](src/af0eedbe-603b-4671-8e5a-28165d88254b) | [Code](src/af0eedbe-603b-4671-8e5a-28165d88254b/code.php) | [Settings](src/af0eedbe-603b-4671-8e5a-28165d88254b/settings.json) | Super__af0eedbe_603b_4671_8e5a_28165d88254b__Power
|
||||||
- **interface FactoryInterface** | [Details](src/caf33c5d-858c-4f9a-894f-ab302ec5445a) | [Code](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.php) | [Settings](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/settings.json) | Super__caf33c5d_858c_4f9a_894f_ab302ec5445a__Power
|
- **interface FactoryInterface** | [Details](src/caf33c5d-858c-4f9a-894f-ab302ec5445a) | [Code](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.php) | [Settings](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/settings.json) | Super__caf33c5d_858c_4f9a_894f_ab302ec5445a__Power
|
||||||
|
- **interface GrepInterface** | [Details](src/c182506a-ab84-439c-b962-1e606b58d545) | [Code](src/c182506a-ab84-439c-b962-1e606b58d545/code.php) | [Settings](src/c182506a-ab84-439c-b962-1e606b58d545/settings.json) | Super__c182506a_ab84_439c_b962_1e606b58d545__Power
|
||||||
- **interface InsertInterface** | [Details](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48) | [Code](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php) | [Settings](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/settings.json) | Super__ad12ca1c_d3ce_4e7f_88c5_c6c92bdedc48__Power
|
- **interface InsertInterface** | [Details](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48) | [Code](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php) | [Settings](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/settings.json) | Super__ad12ca1c_d3ce_4e7f_88c5_c6c92bdedc48__Power
|
||||||
- **interface LoadInterface** | [Details](src/2ad31f74-f579-499d-b98b-c4f54fd615dd) | [Code](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.php) | [Settings](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/settings.json) | Super__2ad31f74_f579_499d_b98b_c4f54fd615dd__Power
|
- **interface LoadInterface** | [Details](src/2ad31f74-f579-499d-b98b-c4f54fd615dd) | [Code](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.php) | [Settings](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/settings.json) | Super__2ad31f74_f579_499d_b98b_c4f54fd615dd__Power
|
||||||
- **interface ModelInterface** | [Details](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff) | [Code](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.php) | [Settings](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/settings.json) | Super__8aef58c1_3f70_4bd4_b9e4_3f29fcd41cff__Power
|
- **interface ModelInterface** | [Details](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff) | [Code](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.php) | [Settings](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/settings.json) | Super__8aef58c1_3f70_4bd4_b9e4_3f29fcd41cff__Power
|
||||||
|
87
src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/README.md
Normal file
87
src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/README.md
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
```
|
||||||
|
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||||
|
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||||
|
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||||
|
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||||
|
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||||
|
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||||
|
```
|
||||||
|
# abstract class Grep (Details)
|
||||||
|
> namespace: **VDM\Joomla\Abstraction**
|
||||||
|
```uml
|
||||||
|
@startuml
|
||||||
|
abstract Grep #Orange {
|
||||||
|
+ ?string $path
|
||||||
|
+ ?array $paths
|
||||||
|
# array $order
|
||||||
|
# Contents $contents
|
||||||
|
# CMSApplication $app
|
||||||
|
+ __construct(string $path, array $paths, ...)
|
||||||
|
+ getRemotePowersGuid() : ?array
|
||||||
|
+ get(string $guid, ?array $order = null) : ?object
|
||||||
|
# {abstract} remoteIndex(object $path) : void
|
||||||
|
# getFunctionName(string $name) : ?string
|
||||||
|
- init() : void
|
||||||
|
}
|
||||||
|
|
||||||
|
note right of Grep::__construct
|
||||||
|
Constructor.
|
||||||
|
|
||||||
|
since: 3.2.0
|
||||||
|
|
||||||
|
arguments:
|
||||||
|
string $path
|
||||||
|
array $paths
|
||||||
|
Contents $contents
|
||||||
|
?CMSApplication $app = null
|
||||||
|
end note
|
||||||
|
|
||||||
|
note right 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 right of Grep::remoteIndex
|
||||||
|
Load the remote repository index of powers
|
||||||
|
|
||||||
|
since: 3.2.0
|
||||||
|
return: void
|
||||||
|
end note
|
||||||
|
|
||||||
|
note right of Grep::getFunctionName
|
||||||
|
Get function name
|
||||||
|
|
||||||
|
since: 3.2.0
|
||||||
|
return: ?string
|
||||||
|
end note
|
||||||
|
|
||||||
|
note right of Grep::init
|
||||||
|
Set path details
|
||||||
|
|
||||||
|
since: 3.2.0
|
||||||
|
return: void
|
||||||
|
end note
|
||||||
|
|
||||||
|
@enduml
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
```
|
||||||
|
██╗ ██████╗██████╗
|
||||||
|
██║██╔════╝██╔══██╗
|
||||||
|
██║██║ ██████╔╝
|
||||||
|
██ ██║██║ ██╔══██╗
|
||||||
|
╚█████╔╝╚██████╗██████╔╝
|
||||||
|
╚════╝ ╚═════╝╚═════╝
|
||||||
|
```
|
||||||
|
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||||
|
|
221
src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.php
Normal file
221
src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.php
Normal file
@ -0,0 +1,221 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package Joomla.Component.Builder
|
||||||
|
*
|
||||||
|
* @created 4th September, 2022
|
||||||
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||||
|
* @git Joomla Component Builder <https://git.vdm.dev/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\Abstraction;
|
||||||
|
|
||||||
|
|
||||||
|
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\Interfaces\GrepInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global Resource Empowerment Platform
|
||||||
|
*
|
||||||
|
* The Grep feature will try to find your power in the repositories listed in the global
|
||||||
|
* Options of JCB in the super powers tab, and if it can't be found there will try the global core
|
||||||
|
* Super powers of JCB. All searches are performed according the the [algorithm:cascading]
|
||||||
|
* See documentation for more details: https://git.vdm.dev/joomla/super-powers/wiki
|
||||||
|
*
|
||||||
|
* @since 3.2.1
|
||||||
|
*/
|
||||||
|
abstract class Grep implements GrepInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The local path
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 3.2.0
|
||||||
|
**/
|
||||||
|
public ?string $path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All approved paths
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 3.2.0
|
||||||
|
**/
|
||||||
|
public ?array $paths;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order of global search
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 3.2.1
|
||||||
|
**/
|
||||||
|
protected array $order = ['local', 'remote'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
public function __construct(string $path, array $paths, Contents $contents, ?CMSApplication $app = null)
|
||||||
|
{
|
||||||
|
$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 === [])
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$powers = [];
|
||||||
|
foreach ($this->paths as $path)
|
||||||
|
{
|
||||||
|
// Get remote index
|
||||||
|
$this->remoteIndex($path);
|
||||||
|
|
||||||
|
if (isset($path->index) && is_object($path->index))
|
||||||
|
{
|
||||||
|
$powers = array_merge($powers, array_keys((array) $path->index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return empty($powers) ? null : array_unique($powers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a power
|
||||||
|
*
|
||||||
|
* @param string $guid The global unique id of the power
|
||||||
|
* @param array|null $order The search order
|
||||||
|
*
|
||||||
|
* @return object|null
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
public function get(string $guid, ?array $order = null): ?object
|
||||||
|
{
|
||||||
|
if ($order === null)
|
||||||
|
{
|
||||||
|
$order = $this->order;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we can only search if we have paths
|
||||||
|
if (is_array($this->paths) && $this->paths !== [])
|
||||||
|
{
|
||||||
|
foreach ($order as $target)
|
||||||
|
{
|
||||||
|
if (($function_name = $this->getFunctionName($target)) !== null &&
|
||||||
|
($power = $this->{$function_name}($guid)) !== null)
|
||||||
|
{
|
||||||
|
return $power;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the remote repository index of powers
|
||||||
|
*
|
||||||
|
* @param object $path The repository path details
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
abstract protected function remoteIndex(object &$path): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get function name
|
||||||
|
*
|
||||||
|
* @param string $name The targeted function name
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
protected function getFunctionName(string $name): ?string
|
||||||
|
{
|
||||||
|
$function_name = 'search' . ucfirst(strtolower($name));
|
||||||
|
|
||||||
|
return method_exists($this, $function_name) ? $function_name : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set path details
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
private function init(): void
|
||||||
|
{
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
183
src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.power
Normal file
183
src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/code.power
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
/**
|
||||||
|
* The local path
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 3.2.0
|
||||||
|
**/
|
||||||
|
public ?string $path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All approved paths
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 3.2.0
|
||||||
|
**/
|
||||||
|
public ?array $paths;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order of global search
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 3.2.1
|
||||||
|
**/
|
||||||
|
protected array $order = ['local', 'remote'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
public function __construct(string $path, array $paths, Contents $contents, ?CMSApplication $app = null)
|
||||||
|
{
|
||||||
|
$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 === [])
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$powers = [];
|
||||||
|
foreach ($this->paths as $path)
|
||||||
|
{
|
||||||
|
// Get remote index
|
||||||
|
$this->remoteIndex($path);
|
||||||
|
|
||||||
|
if (isset($path->index) && is_object($path->index))
|
||||||
|
{
|
||||||
|
$powers = array_merge($powers, array_keys((array) $path->index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return empty($powers) ? null : array_unique($powers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a power
|
||||||
|
*
|
||||||
|
* @param string $guid The global unique id of the power
|
||||||
|
* @param array|null $order The search order
|
||||||
|
*
|
||||||
|
* @return object|null
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
public function get(string $guid, ?array $order = null): ?object
|
||||||
|
{
|
||||||
|
if ($order === null)
|
||||||
|
{
|
||||||
|
$order = $this->order;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we can only search if we have paths
|
||||||
|
if (is_array($this->paths) && $this->paths !== [])
|
||||||
|
{
|
||||||
|
foreach ($order as $target)
|
||||||
|
{
|
||||||
|
if (($function_name = $this->getFunctionName($target)) !== null &&
|
||||||
|
($power = $this->{$function_name}($guid)) !== null)
|
||||||
|
{
|
||||||
|
return $power;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the remote repository index of powers
|
||||||
|
*
|
||||||
|
* @param object $path The repository path details
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
abstract protected function remoteIndex(object &$path): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get function name
|
||||||
|
*
|
||||||
|
* @param string $name The targeted function name
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
protected function getFunctionName(string $name): ?string
|
||||||
|
{
|
||||||
|
$function_name = 'search' . ucfirst(strtolower($name));
|
||||||
|
|
||||||
|
return method_exists($this, $function_name) ? $function_name : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set path details
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
private function init(): void
|
||||||
|
{
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/settings.json
Normal file
33
src/1401a167-0ce4-4f4a-afee-2d8b02ed339b/settings.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"add_head": "1",
|
||||||
|
"add_licensing_template": "2",
|
||||||
|
"extends": "0",
|
||||||
|
"guid": "1401a167-0ce4-4f4a-afee-2d8b02ed339b",
|
||||||
|
"implements": [
|
||||||
|
"c182506a-ab84-439c-b962-1e606b58d545"
|
||||||
|
],
|
||||||
|
"load_selection": null,
|
||||||
|
"name": "Grep",
|
||||||
|
"power_version": "1.0.0",
|
||||||
|
"system_name": "VDM.Grep",
|
||||||
|
"type": "abstract 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": "4b225c51-d293-48e4-b3f6-5136cf5c3f18",
|
||||||
|
"as": "default"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"namespace": "[[[NamespacePrefix]]]\\Joomla\\Abstraction.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.1",
|
||||||
|
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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;",
|
||||||
|
"composer": ""
|
||||||
|
}
|
45
src/c182506a-ab84-439c-b962-1e606b58d545/README.md
Normal file
45
src/c182506a-ab84-439c-b962-1e606b58d545/README.md
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
```
|
||||||
|
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||||
|
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||||
|
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||||
|
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||||
|
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||||
|
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||||
|
```
|
||||||
|
# interface GrepInterface (Details)
|
||||||
|
> namespace: **VDM\Joomla\Interfaces**
|
||||||
|
```uml
|
||||||
|
@startuml
|
||||||
|
interface GrepInterface #Lavender {
|
||||||
|
+ getRemotePowersGuid() : ?array
|
||||||
|
+ get(string $guid, array $order = ['local', 'remote']) : ?object
|
||||||
|
}
|
||||||
|
|
||||||
|
note right of GrepInterface::getRemotePowersGuid
|
||||||
|
Get all remote powers GUID's
|
||||||
|
|
||||||
|
since: 3.2.0
|
||||||
|
return: ?array
|
||||||
|
end note
|
||||||
|
|
||||||
|
note right of GrepInterface::get
|
||||||
|
Get a power
|
||||||
|
|
||||||
|
since: 3.2.0
|
||||||
|
return: ?object
|
||||||
|
end note
|
||||||
|
|
||||||
|
@enduml
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
```
|
||||||
|
██╗ ██████╗██████╗
|
||||||
|
██║██╔════╝██╔══██╗
|
||||||
|
██║██║ ██████╔╝
|
||||||
|
██ ██║██║ ██╔══██╗
|
||||||
|
╚█████╔╝╚██████╗██████╔╝
|
||||||
|
╚════╝ ╚═════╝╚═════╝
|
||||||
|
```
|
||||||
|
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||||
|
|
41
src/c182506a-ab84-439c-b962-1e606b58d545/code.php
Normal file
41
src/c182506a-ab84-439c-b962-1e606b58d545/code.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package Joomla.Component.Builder
|
||||||
|
*
|
||||||
|
* @created 4th September, 2022
|
||||||
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||||
|
* @git Joomla Component Builder <https://git.vdm.dev/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\Interfaces;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global Resource Empowerment Platform
|
||||||
|
*
|
||||||
|
* @since 3.2.1
|
||||||
|
*/
|
||||||
|
interface GrepInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get all remote powers GUID's
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
public function getRemotePowersGuid(): ?array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
18
src/c182506a-ab84-439c-b962-1e606b58d545/code.power
Normal file
18
src/c182506a-ab84-439c-b962-1e606b58d545/code.power
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Get all remote powers GUID's
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
* @since 3.2.0
|
||||||
|
*/
|
||||||
|
public function getRemotePowersGuid(): ?array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
18
src/c182506a-ab84-439c-b962-1e606b58d545/settings.json
Normal file
18
src/c182506a-ab84-439c-b962-1e606b58d545/settings.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"add_head": "0",
|
||||||
|
"add_licensing_template": "2",
|
||||||
|
"extends": "0",
|
||||||
|
"guid": "c182506a-ab84-439c-b962-1e606b58d545",
|
||||||
|
"implements": null,
|
||||||
|
"load_selection": null,
|
||||||
|
"name": "GrepInterface",
|
||||||
|
"power_version": "1.0.0",
|
||||||
|
"system_name": "VDM.Interfaces.GrepInterface",
|
||||||
|
"type": "interface",
|
||||||
|
"use_selection": null,
|
||||||
|
"namespace": "[[[NamespacePrefix]]]\\Joomla\\Interfaces.GrepInterface",
|
||||||
|
"description": "Global Resource Empowerment Platform\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 <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/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": ""
|
||||||
|
}
|
@ -43,6 +43,17 @@
|
|||||||
"spk": "Super__1198aecf_84c6_45d2_aea8_d531aa4afdfa__Power",
|
"spk": "Super__1198aecf_84c6_45d2_aea8_d531aa4afdfa__Power",
|
||||||
"guid": "1198aecf-84c6-45d2-aea8-d531aa4afdfa"
|
"guid": "1198aecf-84c6-45d2-aea8-d531aa4afdfa"
|
||||||
},
|
},
|
||||||
|
"1401a167-0ce4-4f4a-afee-2d8b02ed339b": {
|
||||||
|
"name": "Grep",
|
||||||
|
"type": "abstract class",
|
||||||
|
"namespace": "VDM\\Joomla\\Abstraction",
|
||||||
|
"code": "src\/1401a167-0ce4-4f4a-afee-2d8b02ed339b\/code.php",
|
||||||
|
"power": "src\/1401a167-0ce4-4f4a-afee-2d8b02ed339b\/code.power",
|
||||||
|
"settings": "src\/1401a167-0ce4-4f4a-afee-2d8b02ed339b\/settings.json",
|
||||||
|
"path": "src\/1401a167-0ce4-4f4a-afee-2d8b02ed339b",
|
||||||
|
"spk": "Super__1401a167_0ce4_4f4a_afee_2d8b02ed339b__Power",
|
||||||
|
"guid": "1401a167-0ce4-4f4a-afee-2d8b02ed339b"
|
||||||
|
},
|
||||||
"152c8793-8b75-4715-996a-257b9f65451c": {
|
"152c8793-8b75-4715-996a-257b9f65451c": {
|
||||||
"name": "MathHelper",
|
"name": "MathHelper",
|
||||||
"type": "abstract class",
|
"type": "abstract class",
|
||||||
@ -428,6 +439,17 @@
|
|||||||
"spk": "Super__c09e8968_c767_4175_bb3d_8432f206a2c7__Power",
|
"spk": "Super__c09e8968_c767_4175_bb3d_8432f206a2c7__Power",
|
||||||
"guid": "c09e8968-c767-4175-bb3d-8432f206a2c7"
|
"guid": "c09e8968-c767-4175-bb3d-8432f206a2c7"
|
||||||
},
|
},
|
||||||
|
"c182506a-ab84-439c-b962-1e606b58d545": {
|
||||||
|
"name": "GrepInterface",
|
||||||
|
"type": "interface",
|
||||||
|
"namespace": "VDM\\Joomla\\Interfaces",
|
||||||
|
"code": "src\/c182506a-ab84-439c-b962-1e606b58d545\/code.php",
|
||||||
|
"power": "src\/c182506a-ab84-439c-b962-1e606b58d545\/code.power",
|
||||||
|
"settings": "src\/c182506a-ab84-439c-b962-1e606b58d545\/settings.json",
|
||||||
|
"path": "src\/c182506a-ab84-439c-b962-1e606b58d545",
|
||||||
|
"spk": "Super__c182506a_ab84_439c_b962_1e606b58d545__Power",
|
||||||
|
"guid": "c182506a-ab84-439c-b962-1e606b58d545"
|
||||||
|
},
|
||||||
"caf33c5d-858c-4f9a-894f-ab302ec5445a": {
|
"caf33c5d-858c-4f9a-894f-ab302ec5445a": {
|
||||||
"name": "FactoryInterface",
|
"name": "FactoryInterface",
|
||||||
"type": "interface",
|
"type": "interface",
|
||||||
|
Loading…
Reference in New Issue
Block a user