Release of v5.0.1-alpha3

Add in JCB gitea push feature to help maintain JCB core features. Add extending options to interfaces.
This commit is contained in:
2024-06-05 17:08:34 +02:00
parent aba1267f8e
commit 0c9a098335
40 changed files with 1642 additions and 672 deletions

View File

@ -12,7 +12,7 @@
namespace VDM\Joomla\Gitea\Utilities;
use Joomla\Http\Response as JoomlaResponse;
use Joomla\CMS\Http\Response as JoomlaResponse;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\StringHelper;

View File

@ -12,7 +12,7 @@
namespace VDM\Joomla\Openai\Utilities;
use Joomla\Http\Response as JoomlaResponse;
use Joomla\CMS\Http\Response as JoomlaResponse;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\StringHelper;

View File

@ -0,0 +1,218 @@
<?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 VDM\Joomla\Gitea\Repository\Contents;
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 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.
*
* @throws \Exception
* @since 3.2.0
*/
public function __construct(Contents $contents, array $paths, ?string $path = null, ?CMSApplication $app = null)
{
$this->paths = $paths;
$this->contents = $contents;
$this->path = $path;
$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
*/
protected 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]);
}
}
}
}
}

View File

@ -12,7 +12,6 @@
namespace VDM\Joomla\Abstraction;
use VDM\Joomla\Interfaces\Activeregistryinterface;
use VDM\Joomla\Interfaces\Registryinterface;
use VDM\Joomla\Abstraction\ActiveRegistry;
@ -24,7 +23,7 @@ use VDM\Joomla\Abstraction\ActiveRegistry;
*
* @since 3.2.0
*/
abstract class Registry extends ActiveRegistry implements Activeregistryinterface, Registryinterface
abstract class Registry extends ActiveRegistry implements Registryinterface
{
/**
* Path separator

View File

@ -57,6 +57,17 @@ class Config extends BaseConfig
$this->config = $config ?: JoomlaFactory::getConfig();
}
/**
* get Gitea Username
*
* @return string the access token
* @since 3.2.0
*/
protected function getGiteausername(): ?string
{
return $this->custom_gitea_username ?? $this->params->get('gitea_username');
}
/**
* get Gitea Access Token
*
@ -95,6 +106,22 @@ class Config extends BaseConfig
return null;
}
/**
* get Custom Gitea Username
*
* @return string the custom access token
* @since 3.2.0
*/
protected function getCustomgiteausername(): ?string
{
if ($this->add_custom_gitea_url == 2)
{
return $this->params->get('custom_gitea_username');
}
return null;
}
/**
* get Custom Gitea Access Token
*
@ -148,6 +175,12 @@ class Config extends BaseConfig
$paths = $this->params->get('super_powers_core_repos');
}
// get the users own power repo (can overwrite all)
if (!empty($this->gitea_username))
{
$repos[$this->gitea_username . '.super-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'super-powers', 'branch' => 'master'];
}
if (!empty($paths) && is_array($paths))
{
foreach ($paths as $path)
@ -845,6 +878,11 @@ class Config extends BaseConfig
{
// some defaults repos we need by JCB
$repos = [];
// get the users own power repo (can overwrite all)
if (!empty($this->gitea_username))
{
$repos[$this->gitea_username . '.joomla-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'joomla-powers', 'branch' => 'master'];
}
$repos[$this->joomla_powers_core_organisation . '.joomla-powers'] = (object) ['owner' => $this->joomla_powers_core_organisation, 'repo' => 'joomla-powers', 'branch' => 'master'];
return $repos;
@ -866,15 +904,12 @@ class Config extends BaseConfig
/**
* Get joomla power approved paths
*
* @return array The paths to the repositories on Gitea
* @return array The approved paths to the repositories on Gitea
* @since 3.2.0
*/
protected function getApprovedjoomlapaths(): array
{
// some defaults repos we need by JCB
$approved = $this->joomla_powers_init_repos;
return array_values($approved);
return array_values($this->joomla_powers_init_repos);
}
/**

View File

@ -244,7 +244,7 @@ class Data
);
// Make sure the icon is only an icon path
if (strpos($item->icon, '#') !== false)
if (isset($item->icon) && strpos($item->icon, '#') !== false)
{
$item->icon = strstr($item->icon, '#', true);
}

View File

@ -207,96 +207,192 @@ final class JoomlaPower implements PowerInterface
}
/**
* Set a power
* Set a Joomla power
*
* @param string $guid The global unique id of the power
* @param string $guid The global unique id of the power
*
* @return bool true on successful setting of a power
* @return bool true on successful setting of a power
* @since 3.2.1
*/
private function set(string $guid): bool
{
// check if we have been here before
// Check if power is already set
if ($this->isPowerSet($guid))
{
return $this->state[$guid];
}
elseif ($this->isGuidValid($guid))
// Validate GUID
if (!$this->isGuidValid($guid))
{
// get the power data
$this->active[$guid] = $this->getPowerData($guid);
$this->state[$guid] = false;
return false;
}
if (is_object($this->active[$guid]))
// Get the power data
$this->active[$guid] = $this->getPowerData($guid);
// Validate power data object
if ($this->active[$guid] === null)
{
return $this->handlePowerNotFound($guid);
}
// Prevent recursive loading of the same power
$this->state[$guid] = true;
// Convert settings to array if valid JSON
$settings = $this->convertSettingsToArray(
$this->active[$guid]->settings
);
// Set the target version if settings array is valid
if (!$this->setTargetVersion($guid, $settings))
{
return false;
}
// Set class name and namespace
$this->setClassAndNamespace($guid);
return true;
}
/**
* Convert settings JSON string to array
*
* @param string $settingsJson
*
* @return array|null
* @since 3.2.2
*/
private function convertSettingsToArray(string $settingsJson): ?array
{
if (JsonHelper::check($settingsJson))
{
return json_decode($settingsJson, true);
}
return null;
}
/**
* Set the target version based on Joomla version and settings
*
* @param string $guid
* @param array|null $settings
*
* @return bool
* @since 3.2.2
*/
private function setTargetVersion(string $guid, ?array $settings): bool
{
$joomla_version = $this->config->joomla_version;
if (!$joomla_version || !ArrayHelper::check($settings))
{
return false;
}
$joomla_version_target = null;
$target_found = false;
foreach ($settings as $namespace)
{
// Set default values for all versions
if ($namespace['joomla_version'] == 0)
{
// make sure that in recursion we
// don't try to load this power again
// since during the load of a power we also load
// all powers linked to it
$this->state[$guid] = true;
$this->setNamespaceAndType($guid, $namespace);
$target_found = true;
}
// convert settings to an array
if (JsonHelper::check($this->active[$guid]->settings))
{
$this->active[$guid]->settings = $settings
= json_decode($this->active[$guid]->settings, true);
}
// set a target version
$joomla_version = $this->config->joomla_version;
if ($joomla_version && ArrayHelper::check($settings))
{
foreach ($settings as $namespace)
{
if ($joomla_version == $namespace['joomla_version'] ||
$namespace['joomla_version'] == 0)
{
$this->active[$guid]->namespace = $namespace['namespace'];
$this->active[$guid]->type = $namespace['type'] ?? 'class';
break;
}
}
$this->active[$guid]->class_name =
$this->extractLastNameFromNamespace($this->active[$guid]->namespace);
$this->active[$guid]->_namespace =
$this->removeLastNameFromNamespace($this->active[$guid]->namespace);
// set the approved super power values
$this->setSuperPowers($guid);
return true;
}
// Check for direct target version
if ($joomla_version == $namespace['joomla_version'])
{
$joomla_version_target = $namespace;
break;
}
}
// we failed to get the power,
// so we raise an error message
// only if guid is valid
if ($this->isGuidValid($guid))
if ($joomla_version_target)
{
// now we search for it via the super power paths
if (empty($this->retry[$guid]) && $this->superpower->load($guid, ['remote', 'local']))
{
// we found it and it was loaded into the database
unset($this->state[$guid]);
unset($this->active[$guid]);
// we make sure that this retry only happen once! (just in-case...)
$this->retry[$guid] = true;
// so we try to load it again
return $this->set($guid);
}
$this->setNamespaceAndType($guid, $joomla_version_target);
$target_found = true;
}
if (!$target_found)
{
$this->app->enqueueMessage(
Text::sprintf('COM_COMPONENTBUILDER_PJOOMLA_POWER_BGUIDSB_NOT_FOUNDP', $guid),
Text::sprintf('COM_COMPONENTBUILDER_PJOOMLA_POWER_BGUIDSB_WAS_FOUND_BUT_MISSING_A_NAMESPACE_VALUE_FOR_JOOMLA_SP', $guid, $joomla_version),
'Error'
);
$this->state[$guid] = false;
return false;
}
// let's not try again
return true;
}
/**
* Set namespace and type for the active power
*
* @param string $guid
* @param array $namespace
*
* @since 3.2.2
*/
private function setNamespaceAndType(string $guid, array $namespace): void
{
$this->active[$guid]->namespace = $namespace['namespace'];
$this->active[$guid]->type = $namespace['type'] ?? 'class';
}
/**
* Set class name and namespace for the active power
*
* @param string $guid
*
* @since 3.2.2
*/
private function setClassAndNamespace(string $guid): void
{
$this->active[$guid]->class_name = $this->extractLastNameFromNamespace(
$this->active[$guid]->namespace
);
$this->active[$guid]->_namespace = $this->removeLastNameFromNamespace(
$this->active[$guid]->namespace
);
}
/**
* Handle power not found scenario
*
* @param string $guid
*
* @return bool
* @since 3.2.2
*/
private function handlePowerNotFound(string $guid): bool
{
if (empty($this->retry[$guid]) && $this->superpower->load($guid, ['remote', 'local']))
{
// Retry loading the power
unset($this->state[$guid]);
unset($this->active[$guid]);
$this->retry[$guid] = true;
return $this->set($guid);
}
$this->app->enqueueMessage(
Text::sprintf('COM_COMPONENTBUILDER_PJOOMLA_POWER_BGUIDSB_NOT_FOUNDP', $guid),
'Error'
);
$this->state[$guid] = false;
return false;

View File

@ -756,7 +756,7 @@ class Power implements PowerInterface
}
/**
* Set Extend Class
* Set Extend
*
* @param string $guid The global unique id of the power
* @param array $use The use array
@ -767,9 +767,29 @@ class Power implements PowerInterface
*/
private function setExtend(string $guid, array &$use, array &$as)
{
// does this extend something
$this->active[$guid]->extends_name = null;
// build the interface extends details
if ($this->active[$guid]->type === 'interface')
{
$this->setExtendInterface($guid, $use, $as);
}
else
{
$this->setExtendClass($guid, $use, $as);
}
}
/**
* Set Extend Class
*
* @param string $guid The global unique id of the power
* @param array $use The use array
* @param array $as The use as array
*
* @return void
* @since 3.2.0
*/
private function setExtendClass(string $guid, array &$use, array &$as)
{
// we first check for custom extending options
if ($this->active[$guid]->extends == -1
&& StringHelper::check($this->active[$guid]->extends_custom))
@ -803,6 +823,89 @@ class Power implements PowerInterface
}
}
}
// reset it not found
else
{
$this->active[$guid]->extends = '';
$this->active[$guid]->extends_custom = '';
}
// always rest these for normal classes
$this->active[$guid]->extendsinterfaces = null;
$this->active[$guid]->extendsinterfaces_custom = '';
}
/**
* Set Extend Interface
*
* @param string $guid The global unique id of the power
* @param array $use The use array
* @param array $as The use as array
*
* @return void
* @since 3.2.2
*/
private function setExtendInterface(string $guid, array &$use, array &$as)
{
// does this extends interfaces
$this->active[$guid]->extendsinterfaces = (isset($this->active[$guid]->extendsinterfaces)
&& JsonHelper::check(
$this->active[$guid]->extendsinterfaces
)) ? json_decode((string)$this->active[$guid]->extendsinterfaces, true) : null;
if (ArrayHelper::check($this->active[$guid]->extendsinterfaces))
{
$bucket = [];
foreach ($this->active[$guid]->extendsinterfaces as $extend)
{
// we first check for custom extending options
if ($extend == -1
&& isset($this->active[$guid]->extendsinterfaces_custom)
&& StringHelper::check($this->active[$guid]->extendsinterfaces_custom))
{
// reserve extends custom for the linker
$this->active[$guid]->unchanged_extendsinterfaces_custom = $this->active[$guid]->extendsinterfaces_custom;
$bucket[] = $this->placeholder->update_(
$this->customcode->update($this->active[$guid]->extendsinterfaces_custom)
);
// just add once
unset($this->active[$guid]->extendsinterfaces_custom);
}
// does this extend existing
elseif (GuidHelper::valid($extend))
{
// check if it was set
if ($this->set($extend))
{
$extends_name = $this->get($extend, 1)->class_name;
// add to use
$use[] = $extend;
// add padding if the two names are the same
if ($extends_name === $this->active[$guid]->class_name)
{
$extends_name = $as[$extend]
= 'Extending' . $extends_name;
}
// get the name
$bucket[] = $extends_name;
}
}
}
if ($bucket !== [])
{
$this->active[$guid]->extends_name = implode(', ', $bucket);
}
}
else
{
$this->active[$guid]->extendsinterfaces = null;
$this->active[$guid]->extendsinterfaces_custom = '';
}
// always rest these for interfaces
$this->active[$guid]->extends = '';
$this->active[$guid]->extends_custom = '';
}
/**

View File

@ -115,6 +115,8 @@ class Infusion
'unchanged_description' => 'description',
'extends' => 'extends',
'unchanged_extends_custom' => 'extends_custom',
'extendsinterfaces' => 'extendsinterfaces',
'unchanged_extendsinterfaces_custom' => 'extendsinterfaces_custom',
'guid' => 'guid',
'unchanged_head' => 'head',
'use_selection' => 'use_selection',

View File

@ -113,9 +113,8 @@ class JoomlaPower implements ServiceProviderInterface
public function getGrep(Container $container): Grep
{
return new Grep(
$container->get('Config')->local_joomla_powers_repository_path,
$container->get('Config')->approved_joomla_paths,
$container->get('Gitea.Repository.Contents')
$container->get('Gitea.Repository.Contents'),
$container->get('Config')->approved_joomla_paths
);
}

View File

@ -140,9 +140,9 @@ class Power implements ServiceProviderInterface
public function getGrep(Container $container): Grep
{
return new Grep(
$container->get('Config')->local_powers_repository_path,
$container->get('Gitea.Repository.Contents'),
$container->get('Config')->approved_paths,
$container->get('Gitea.Repository.Contents')
$container->get('Config')->local_powers_repository_path
);
}

View File

@ -57,6 +57,17 @@ class Config extends BaseConfig
$this->config = $config ?: JoomlaFactory::getConfig();
}
/**
* get Gitea Username
*
* @return string the access token
* @since 3.2.0
*/
protected function getGiteausername(): ?string
{
return $this->custom_gitea_username ?? $this->params->get('gitea_username');
}
/**
* get Gitea Access Token
*
@ -95,6 +106,22 @@ class Config extends BaseConfig
return null;
}
/**
* get Custom Gitea Username
*
* @return string the custom access token
* @since 3.2.0
*/
protected function getCustomgiteausername(): ?string
{
if ($this->add_custom_gitea_url == 2)
{
return $this->params->get('custom_gitea_username');
}
return null;
}
/**
* get Custom Gitea Access Token
*
@ -135,48 +162,40 @@ class Config extends BaseConfig
{
// some defaults repos we need by JCB
$repos = [];
// get the users own power repo (can overwrite all)
if (!empty($this->gitea_username))
{
$repos[$this->gitea_username . '.joomla-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'joomla-powers', 'branch' => 'master'];
}
$repos[$this->joomla_powers_core_organisation . '.joomla-powers'] = (object) ['owner' => $this->joomla_powers_core_organisation, 'repo' => 'joomla-powers', 'branch' => 'master'];
return $repos;
}
/**
* get temporary path
* Get Joomla power push repo
*
* @return string The temporary path
* @since 3.2.0
* @return object|null The push repository on Gitea
* @since 3.2.1
*/
protected function getTmppath(): string
protected function getJoomlapowerspushrepo(): ?object
{
// get the temporary path
return $this->config->get('tmp_path');
}
/**
* Get local joomla super powers repository path
*
* @return string The path to the local repository
* @since 3.2.0
*/
protected function getLocaljoomlapowersrepositorypath(): string
{
$default = $this->tmp_path . '/joomla_powers';
return $this->params->get('local_joomla_powers_repository_path', $default);
// some defaults repos we need by JCB
if (!empty($this->gitea_username))
{
return (object) ['owner' => $this->gitea_username, 'repo' => 'joomla-powers', 'branch' => 'master'];
}
}
/**
* Get joomla power approved paths
*
* @return array The paths to the repositories on Gitea
* @return array The approved paths to the repositories on Gitea
* @since 3.2.0
*/
protected function getApprovedjoomlapaths(): array
{
// some defaults repos we need by JCB
$approved = $this->joomla_powers_init_repos;
return array_values($approved);
return array_values($this->joomla_powers_init_repos);
}
}

View File

@ -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,87 +32,12 @@ use VDM\Joomla\Componentbuilder\Power\Grep as ExtendingGrep;
final class Grep extends ExtendingGrep implements GrepInterface
{
/**
* Get a local power
* Order of global search
*
* @param object $path The repository path details
* @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
{
if (empty($path->local->{$guid}->settings))
{
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))
{
return $power;
}
}
return null;
}
/**
* Get a remote power
*
* @param object $path The repository path details
* @param string $guid The global unique id of the power
*
* @return object|null
* @since 3.2.0
*/
private function getRemote(object $path, string $guid): ?object
{
if (empty($path->index->{$guid}->settings))
{
return null;
}
// get the settings
if (($power = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->settings, $path->branch)) !== null &&
isset($power->guid))
{
return $power;
}
return null;
}
/**
* 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 . '/joomla-powers.json', null)) !== null &&
JsonHelper::check($content))
{
$path->local = json_decode($content);
return;
}
$path->local = null;
}
* @var array
* @since 3.2.1
**/
protected array $order = ['remote'];
/**
* Load the remote repository index of powers
@ -121,7 +47,7 @@ final class Grep extends ExtendingGrep implements GrepInterface
* @return void
* @since 3.2.0
*/
private function remoteIndex(object &$path)
protected function remoteIndex(object &$path): void
{
if (isset($path->index))
{
@ -141,6 +67,99 @@ final class Grep extends ExtendingGrep implements GrepInterface
$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
*/
protected function searchRemote(string $guid): ?object
{
// we can only search if we have paths
if ($this->path && $this->paths)
{
foreach ($this->paths as $path)
{
// get local index
$this->remoteIndex($path);
if (!empty($path->index) && isset($path->index->{$guid}))
{
return $this->getRemote($path, $guid);
}
}
}
return null;
}
/**
* Get a remote power
*
* @param object $path The repository path details
* @param string $guid The global unique id of the power
*
* @return object|null
* @since 3.2.0
*/
protected function getRemote(object $path, string $guid): ?object
{
if (empty($path->index->{$guid}->settings))
{
return null;
}
// get the settings
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;
}
return null;
}
/**
* Load the remote file
*
* @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 mixed
* @since 3.2.0
*/
protected function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch)
{
try
{
$data = $this->contents->get($owner, $repo, $path, $branch);
}
catch (\Exception $e)
{
$this->app->enqueueMessage(
Text::sprintf('COM_COMPONENTBUILDER_PFILE_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path, $e->getMessage()),
'Error'
);
return null;
}
return $data;
}
}

View File

@ -91,9 +91,8 @@ class JoomlaPower implements ServiceProviderInterface
public function getGrep(Container $container): Grep
{
return new Grep(
$container->get('Config')->local_joomla_powers_repository_path,
$container->get('Config')->approved_joomla_paths,
$container->get('Gitea.Repository.Contents')
$container->get('Gitea.Repository.Contents'),
$container->get('Config')->approved_joomla_paths
);
}

View File

@ -57,6 +57,17 @@ class Config extends BaseConfig
$this->config = $config ?: JoomlaFactory::getConfig();
}
/**
* get Gitea Username
*
* @return string the access token
* @since 3.2.0
*/
protected function getGiteausername(): ?string
{
return $this->custom_gitea_username ?? $this->params->get('gitea_username');
}
/**
* get Gitea Access Token
*
@ -95,6 +106,22 @@ class Config extends BaseConfig
return null;
}
/**
* get Custom Gitea Username
*
* @return string the custom access token
* @since 3.2.0
*/
protected function getCustomgiteausername(): ?string
{
if ($this->add_custom_gitea_url == 2)
{
return $this->params->get('custom_gitea_username');
}
return null;
}
/**
* get Custom Gitea Access Token
*
@ -148,6 +175,12 @@ class Config extends BaseConfig
$paths = $this->params->get('super_powers_init_repos');
}
// get the users own power repo (can overwrite all)
if (!empty($this->gitea_username))
{
$repos[$this->gitea_username . '.super-powers'] = (object) ['owner' => $this->gitea_username, 'repo' => 'super-powers', 'branch' => 'master'];
}
if (!empty($paths) && is_array($paths))
{
foreach ($paths as $path)
@ -171,6 +204,22 @@ class Config extends BaseConfig
return $repos;
}
/**
* Get super power push repo
*
* @return object|null The push repository on Gitea
* @since 3.2.1
*/
protected function getSuperpowerspushrepo(): ?object
{
if (!empty($this->gitea_username))
{
return (object) ['owner' => $this->gitea_username, 'repo' => 'super-powers', 'branch' => 'master'];
}
return null;
}
/**
* get temporary path
*

View File

@ -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;
}
}
/**
@ -150,7 +69,7 @@ class Grep implements GrepInterface
* @return object|null
* @since 3.2.0
*/
private function searchLocal(string $guid): ?object
protected function searchLocal(string $guid): ?object
{
// we can only search if we have paths
if ($this->path && $this->paths)
@ -178,7 +97,7 @@ class Grep implements GrepInterface
* @return object|null
* @since 3.2.0
*/
private function searchRemote(string $guid): ?object
protected function searchRemote(string $guid): ?object
{
// we can only search if we have paths
if ($this->path && $this->paths)
@ -207,7 +126,7 @@ class Grep implements GrepInterface
* @return object|null
* @since 3.2.0
*/
private function getLocal(object $path, string $guid): ?object
protected function getLocal(object $path, string $guid): ?object
{
if (empty($path->local->{$guid}->settings) || empty($path->local->{$guid}->code))
{
@ -240,7 +159,7 @@ class Grep implements GrepInterface
* @return object|null
* @since 3.2.0
*/
private function getRemote(object $path, string $guid): ?object
protected function getRemote(object $path, string $guid): ?object
{
if (empty($path->index->{$guid}->settings) || empty($path->index->{$guid}->code))
{
@ -254,6 +173,14 @@ class Grep implements GrepInterface
// get the code
if (($code = $this->loadRemoteFile($path->owner, $path->repo, $path->index->{$guid}->power, $path->branch)) !== null)
{
// set the git details in params
$power->params = (object) [
'git' => [
'owner' => $path->owner,
'repo' => $path->repo,
'branch' => $path->branch
]
];
$power->main_class_code = $code;
return $power;
}
@ -262,100 +189,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
*
@ -367,7 +200,7 @@ class Grep implements GrepInterface
* @return mixed
* @since 3.2.0
*/
private function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch)
protected function loadRemoteFile(string $owner, string $repo, string $path, ?string $branch)
{
try
{
@ -387,18 +220,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
protected 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;
}
}

View File

@ -91,9 +91,9 @@ class Power implements ServiceProviderInterface
public function getGrep(Container $container): Grep
{
return new Grep(
$container->get('Config')->local_powers_repository_path,
$container->get('Gitea.Repository.Contents'),
$container->get('Config')->approved_paths,
$container->get('Gitea.Repository.Contents')
$container->get('Config')->local_powers_repository_path
);
}

View File

@ -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;

View File

@ -3139,22 +3139,6 @@ class Table extends BaseTable implements Tableinterface
'key' => false,
],
],
'method_selection' => [
'name' => 'method_selection',
'label' => 'COM_COMPONENTBUILDER_POWER_METHOD_SELECTION_LABEL',
'type' => 'subform',
'title' => false,
'list' => 'powers',
'store' => 'json',
'tab_name' => 'Code',
'db' => [
'type' => 'TEXT',
'default' => 'EMPTY',
'null_switch' => 'NULL',
'unique_key' => false,
'key' => false,
],
],
'load_selection' => [
'name' => 'load_selection',
'label' => 'COM_COMPONENTBUILDER_POWER_LOAD_SELECTION_LABEL',
@ -3171,22 +3155,6 @@ class Table extends BaseTable implements Tableinterface
'key' => false,
],
],
'licensing_template' => [
'name' => 'licensing_template',
'label' => 'COM_COMPONENTBUILDER_POWER_LICENSING_TEMPLATE_LABEL',
'type' => 'textarea',
'title' => false,
'list' => 'powers',
'store' => 'base64',
'tab_name' => 'Licensing',
'db' => [
'type' => 'TEXT',
'default' => 'EMPTY',
'null_switch' => 'NULL',
'unique_key' => false,
'key' => false,
],
],
'description' => [
'name' => 'description',
'label' => 'COM_COMPONENTBUILDER_POWER_DESCRIPTION_LABEL',
@ -3219,18 +3187,18 @@ class Table extends BaseTable implements Tableinterface
'key' => false,
],
],
'extends' => [
'name' => 'extends',
'label' => 'COM_COMPONENTBUILDER_POWER_EXTENDS_LABEL',
'type' => 'classpowers',
'licensing_template' => [
'name' => 'licensing_template',
'label' => 'COM_COMPONENTBUILDER_POWER_LICENSING_TEMPLATE_LABEL',
'type' => 'textarea',
'title' => false,
'list' => 'powers',
'store' => NULL,
'tab_name' => 'Code',
'store' => 'base64',
'tab_name' => 'Licensing',
'db' => [
'type' => 'VARCHAR(36)',
'default' => '',
'null_switch' => 'NOT NULL',
'type' => 'TEXT',
'default' => 'EMPTY',
'null_switch' => 'NULL',
'unique_key' => false,
'key' => false,
],
@ -3251,13 +3219,13 @@ class Table extends BaseTable implements Tableinterface
'key' => false,
],
],
'property_selection' => [
'name' => 'property_selection',
'label' => 'COM_COMPONENTBUILDER_POWER_PROPERTY_SELECTION_LABEL',
'type' => 'subform',
'extendsinterfaces_custom' => [
'name' => 'extendsinterfaces_custom',
'label' => 'COM_COMPONENTBUILDER_POWER_EXTENDSINTERFACES_CUSTOM_LABEL',
'type' => 'text',
'title' => false,
'list' => 'powers',
'store' => 'json',
'store' => NULL,
'tab_name' => 'Code',
'db' => [
'type' => 'TEXT',
@ -3283,6 +3251,22 @@ class Table extends BaseTable implements Tableinterface
'key' => false,
],
],
'extends' => [
'name' => 'extends',
'label' => 'COM_COMPONENTBUILDER_POWER_EXTENDS_LABEL',
'type' => 'classpowers',
'title' => false,
'list' => 'powers',
'store' => NULL,
'tab_name' => 'Code',
'db' => [
'type' => 'VARCHAR(36)',
'default' => '',
'null_switch' => 'NOT NULL',
'unique_key' => false,
'key' => false,
],
],
'extends_custom' => [
'name' => 'extends_custom',
'label' => 'COM_COMPONENTBUILDER_POWER_EXTENDS_CUSTOM_LABEL',
@ -3331,13 +3315,45 @@ class Table extends BaseTable implements Tableinterface
'key' => false,
],
],
'head' => [
'name' => 'head',
'label' => 'COM_COMPONENTBUILDER_POWER_HEAD_LABEL',
'type' => 'editor',
'property_selection' => [
'name' => 'property_selection',
'label' => 'COM_COMPONENTBUILDER_POWER_PROPERTY_SELECTION_LABEL',
'type' => 'subform',
'title' => false,
'list' => 'powers',
'store' => 'base64',
'store' => 'json',
'tab_name' => 'Code',
'db' => [
'type' => 'TEXT',
'default' => 'EMPTY',
'null_switch' => 'NULL',
'unique_key' => false,
'key' => false,
],
],
'extendsinterfaces' => [
'name' => 'extendsinterfaces',
'label' => 'COM_COMPONENTBUILDER_POWER_EXTENDSINTERFACES_LABEL',
'type' => 'interfacepowers',
'title' => false,
'list' => 'powers',
'store' => 'json',
'tab_name' => 'Code',
'db' => [
'type' => 'TEXT',
'default' => 'EMPTY',
'null_switch' => 'NOT NULL',
'unique_key' => false,
'key' => false,
],
],
'method_selection' => [
'name' => 'method_selection',
'label' => 'COM_COMPONENTBUILDER_POWER_METHOD_SELECTION_LABEL',
'type' => 'subform',
'title' => false,
'list' => 'powers',
'store' => 'json',
'tab_name' => 'Code',
'db' => [
'type' => 'TEXT',
@ -3363,6 +3379,22 @@ class Table extends BaseTable implements Tableinterface
'key' => false,
],
],
'head' => [
'name' => 'head',
'label' => 'COM_COMPONENTBUILDER_POWER_HEAD_LABEL',
'type' => 'editor',
'title' => false,
'list' => 'powers',
'store' => 'base64',
'tab_name' => 'Code',
'db' => [
'type' => 'TEXT',
'default' => 'EMPTY',
'null_switch' => 'NULL',
'unique_key' => false,
'key' => false,
],
],
'use_selection' => [
'name' => 'use_selection',
'label' => 'COM_COMPONENTBUILDER_POWER_USE_SELECTION_LABEL',
@ -3379,22 +3411,6 @@ class Table extends BaseTable implements Tableinterface
'key' => false,
],
],
'main_class_code' => [
'name' => 'main_class_code',
'label' => 'COM_COMPONENTBUILDER_POWER_MAIN_CLASS_CODE_LABEL',
'type' => 'editor',
'title' => false,
'list' => 'powers',
'store' => 'base64',
'tab_name' => 'Code',
'db' => [
'type' => 'MEDIUMTEXT',
'default' => 'EMPTY',
'null_switch' => 'NOT NULL',
'unique_key' => false,
'key' => false,
],
],
'add_licensing_template' => [
'name' => 'add_licensing_template',
'label' => 'COM_COMPONENTBUILDER_POWER_ADD_LICENSING_TEMPLATE_LABEL',
@ -3411,6 +3427,22 @@ class Table extends BaseTable implements Tableinterface
'key' => true,
],
],
'main_class_code' => [
'name' => 'main_class_code',
'label' => 'COM_COMPONENTBUILDER_POWER_MAIN_CLASS_CODE_LABEL',
'type' => 'editor',
'title' => false,
'list' => 'powers',
'store' => 'base64',
'tab_name' => 'Code',
'db' => [
'type' => 'MEDIUMTEXT',
'default' => 'EMPTY',
'null_switch' => 'NOT NULL',
'unique_key' => false,
'key' => false,
],
],
'guid' => [
'name' => 'guid',
'label' => 'COM_COMPONENTBUILDER_POWER_GUID_LABEL',

View File

@ -9,7 +9,7 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Interfaces;
namespace VDM\Joomla\Interfaces;
/**

View File

@ -12,12 +12,15 @@
namespace VDM\Joomla\Interfaces;
use VDM\Joomla\Interfaces\Activeregistryinterface;
/**
* The Registry Interface
*
* @since 3.2.0
*/
interface Registryinterface
interface Registryinterface extends Activeregistryinterface
{
/**
* Sets a value into the registry using multiple keys.

View File

@ -12,7 +12,7 @@
namespace VDM\Joomla\Utilities;
use Joomla\CMS\Filter\InputFilter;
use Joomla\Filter\InputFilter;
use Joomla\CMS\Language\Language;
use VDM\Joomla\Utilities\Component\Helper;