Release of v5.1.1-alpha5

Refactor initialization flow to accommodate future scalability and integration with all designated areas. Refactor the Creator Builders class. Refactor the FieldString and FieldXML classes.
This commit is contained in:
2025-05-13 13:39:32 +00:00
parent 0b7e68d14e
commit 3b502eb09b
336 changed files with 22863 additions and 20677 deletions

View File

@@ -0,0 +1,147 @@
<?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\Componentbuilder\Snippet;
use Joomla\Registry\Registry as JoomlaRegistry;
use Joomla\CMS\Factory as JoomlaFactory;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Utilities\RepoHelper;
use VDM\Joomla\Componentbuilder\Abstraction\ComponentConfig;
/**
* Compiler Configurations
*
* All these functions are accessed via the direct name without the get:
* example: $this->component_code_name calls: $this->getComponentcodename()
*
* All values once called are cached, yet can be updated directly:
* example: $this->component_code_name = 'new_code_name'; // be warned!
*
* @since 5.1.1
*/
class Config extends ComponentConfig
{
/**
* The Global Joomla Configuration
*
* @var JoomlaRegistry
* @since 5.1.1
*/
protected JoomlaRegistry $config;
/**
* Constructor
*
* @param Input|null $input Input
* @param Registry|null $params The component parameters
* @param Registry|null $config The Joomla configuration
*
* @throws \Exception
* @since 5.1.1
*/
public function __construct(?Input $input = null, ?JoomlaRegistry $params = null, ?JoomlaRegistry $config = null)
{
parent::__construct($input, $params);
$this->config = $config ?: JoomlaFactory::getConfig();
}
/**
* get Gitea Username
*
* @return string the access token
* @since 5.1.1
*/
protected function getGiteausername(): ?string
{
return $this->params->get('gitea_username');
}
/**
* get Gitea Access Token
*
* @return string the access token
* @since 5.1.1
*/
protected function getGiteatoken(): ?string
{
return $this->params->get('gitea_token');
}
/**
* Get snippet core organisation
*
* @return string The snippet core organisation
* @since 5.1.1
*/
protected function getSnippetcoreorganisation(): string
{
// the VDM default organisation is [joomla]
$organisation = 'joomla';
return $this->params->get('snippet_core_organisation', $organisation);
}
/**
* Get Snippet init repos
*
* @return array The init repositories on Gitea
* @since 5.1.1
*/
protected function getSnippetinitrepos(): array
{
// 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 . '.snippet'] = (object) ['organisation' => $this->gitea_username, 'repository' => 'snippet', 'read_branch' => 'master'];
}
$repos[$this->snippet_core_organisation . '.snippet'] = (object) ['organisation' => $this->snippet_core_organisation, 'repository' => 'snippet', 'read_branch' => 'master'];
return $repos;
}
/**
* Get joomla snippet approved paths
*
* @return array The approved paths to the repositories on Gitea
* @since 5.1.1
*/
protected function getApprovedjoomlapaths(): array
{
// some defaults repos we need by JCB
$approved = $this->snippet_init_repos;
$paths = RepoHelper::get(5); // Snippet = 5
if ($paths !== null)
{
foreach ($paths as $path)
{
$owner = $path->organisation ?? null;
$repo = $path->repository ?? null;
if ($owner !== null && $repo !== null)
{
// we make sure to get only the objects
$approved = ["{$owner}.{$repo}" => $path] + $approved;
}
}
}
return array_values($approved);
}
}

View File

@@ -0,0 +1,66 @@
<?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\Componentbuilder\Snippet;
use Joomla\DI\Container;
use VDM\Joomla\Componentbuilder\Snippet\Service\Snippet as Power;
use VDM\Joomla\Service\Database;
use VDM\Joomla\Service\Model;
use VDM\Joomla\Service\Data;
use VDM\Joomla\Componentbuilder\Service\Gitea;
use VDM\Joomla\Componentbuilder\Power\Service\Gitea as GiteaPower;
use VDM\Joomla\Gitea\Service\Utilities as GiteaUtilities;
use VDM\Joomla\Componentbuilder\Service\Api;
use VDM\Joomla\Componentbuilder\Service\Network;
use VDM\Joomla\Componentbuilder\Service\Utilities;
use VDM\Joomla\Interfaces\FactoryInterface;
use VDM\Joomla\Abstraction\Factory as ExtendingFactory;
/**
* Snippet Power Factory
*
* @since 5.1.1
*/
abstract class Factory extends ExtendingFactory implements FactoryInterface
{
/**
* Package Container
*
* @var Container|null
* @since 5.1.1
**/
protected static ?Container $container = null;
/**
* Create a container object
*
* @return Container
* @since 5.1.1
*/
protected static function createContainer(): Container
{
return (new Container())
->registerServiceProvider(new Power())
->registerServiceProvider(new Database())
->registerServiceProvider(new Model())
->registerServiceProvider(new Data())
->registerServiceProvider(new Gitea())
->registerServiceProvider(new GiteaPower())
->registerServiceProvider(new GiteaUtilities())
->registerServiceProvider(new Api())
->registerServiceProvider(new Network())
->registerServiceProvider(new Utilities());
}
}

View File

@@ -0,0 +1,165 @@
<?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\Componentbuilder\Snippet;
use Joomla\CMS\Language\Text;
use VDM\Joomla\Interfaces\GrepInterface;
use VDM\Joomla\Abstraction\Grep as ExtendingGrep;
/**
* Global Resource Empowerment Platform
*
* The Grep feature will try to find your power in the repositories
* linked to this [area], and if it can't be found there will try the global core
* Super Powers of JCB. All searches are performed according the [algorithm:cascading]
* See documentation for more details: https://git.vdm.dev/joomla/super-powers/wiki
*
* @since 5.1.1
*/
final class Grep extends ExtendingGrep implements GrepInterface
{
/**
* The Grep target [network]
*
* @var string
* @since 5.1.1
**/
protected ?string $target = 'snippet';
/**
* Order of global search
*
* @var array
* @since 5.1.1
**/
protected array $order = ['remote'];
/**
* Search for a remote item
*
* @param string $guid The global unique id of the item
*
* @return object|null
* @since 5.1.1
*/
protected function searchRemote(string $guid): ?object
{
// check if it exists remotely
if (($path = $this->existsRemotely($guid)) !== null)
{
return $this->getRemote($path, $guid);
}
return null;
}
/**
* Get a remote joomla power
*
* @param object $path The repository path details
* @param string $guid The global unique id of the power
*
* @return object|null
* @since 5.1.1
*/
protected function getRemote(object $path, string $guid): ?object
{
$power = null;
if (empty($path->index->{$guid}->path))
{
return $power;
}
// get the branch name
$branch = $this->getBranchName($path);
// get the guid_field key
$guid_field = $this->getGuidField();
// get the settings path
$settings_path = $this->getSettingsPath();
// load the base and token if set
$this->loadApi($this->contents, $path->base ?? null, $path->token ?? null);
// get the settings
if (($power = $this->loadRemoteFile($path->organisation, $path->repository, $path->index->{$guid}->path . '/' . $settings_path, $branch)) !== null &&
isset($power->{$guid_field}))
{
// set the git details in params
$path_guid = $path->guid ?? null;
if ($path_guid !== null)
{
// get the Settings meta
if (($meta = $this->contents->metadata($path->organisation, $path->repository, $path->index->{$guid}->path . '/' . $settings_path, $branch)) !== null &&
isset($meta->sha))
{
if (isset($power->params) && is_object($power->params) &&
isset($power->params->source) && is_array($power->params->source))
{
$power->params->source[$path_guid . '-settings'] = $meta->sha;
}
else
{
$power->params = (object) [
'source' => [$path_guid . '-settings' => $meta->sha]
];
}
}
// get the README meta
if (($meta = $this->contents->metadata($path->organisation, $path->repository, $path->index->{$guid}->path . '/README.md', $branch)) !== null &&
isset($meta->sha))
{
if (isset($power->params) && is_object($power->params) &&
isset($power->params->source) && is_array($power->params->source))
{
$power->params->source[$path_guid . '-readme'] = $meta->sha;
}
else
{
$power->params = (object) [
'source' => [$path_guid . '-readme' => $meta->sha]
];
}
}
}
}
// reset back to the global base and token
$this->contents->reset_();
return $power;
}
/**
* Set repository messages and errors based on given conditions.
*
* @param string $message The message to set (if error)
* @param string $path Path value
* @param string $repository Repository name
* @param string $organisation Organisation name
* @param string|null $base Base URL
*
* @return void
* @since 5.1.1
*/
protected function setRemoteIndexMessage(string $message, string $path, string $repository, string $organisation, ?string $base): void
{
$this->app->enqueueMessage(
Text::sprintf('COM_COMPONENTBUILDER_PSNIPPETB_REPOSITORY_AT_BSSB_GAVE_THE_FOLLOWING_ERRORBR_SP', $this->contents->api(), $path, $message),
'Error'
);
}
}

View File

@@ -0,0 +1,72 @@
<?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\Componentbuilder\Snippet\Readme;
use VDM\Joomla\Interfaces\Readme\ItemInterface;
/**
* Compiler Snippet Item Readme
*
* @since 5.1.1
*/
final class Item implements ItemInterface
{
/**
* Get an item readme
*
* @param object $item An item details.
*
* @return string
* @since 3.2.2
*/
public function get(object $item): string
{
// build readme
$readme = ["```
███████╗███╗ ██╗██╗██████╗ ██████╗ ███████╗████████╗
██╔════╝████╗ ██║██║██╔══██╗██╔══██╗██╔════╝╚══██╔══╝
███████╗██╔██╗ ██║██║██████╔╝██████╔╝█████╗ ██║
╚════██║██║╚██╗██║██║██╔═══╝ ██╔═══╝ ██╔══╝ ██║
███████║██║ ╚████║██║██║ ██║ ███████╗ ██║
╚══════╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚══════╝ ╚═╝
```"];
// system name
$readme[] = "# " . $item->name;
if (!empty($item->heading))
{
$readme[] = "\n### " . $item->heading;
}
if (!empty($item->description))
{
$readme[] = "\n" . $item->description;
}
$readme[] = "\nThis repository contains a snippet purpose-built for seamless integration with Joomla Component Builder (JCB). Each snippet is carefully crafted to work across site views, custom admin views, templates, and layouts—empowering developers to streamline development, promote code reuse, and maintain consistency throughout their components. The reset function allows you to easily update individual snippets to the latest versions from the core repository. For more tailored solutions, you can fork the repository to maintain and distribute your own customized snippet set. This flexible approach embraces JCBs open-source model, giving you the freedom to adapt while staying connected to a robust, community-driven ecosystem.";
// yes you can remove this, but why?
$readme[] = "\n---\n```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```\n> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)\n\n";
return implode("\n", $readme);
}
}

View File

@@ -0,0 +1,225 @@
<?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\Componentbuilder\Snippet\Readme;
use VDM\Joomla\Interfaces\Readme\MainInterface;
/**
* Snippet Main Readme
*
* @since 5.1.1
*/
final class Main implements MainInterface
{
/**
* Get Main Readme
*
* @param array $items All items of this repository.
*
* @return string
* @since 3.2.0
*/
public function get(array $items): string
{
// build readme
$readme = ["```
███████╗███╗ ██╗██╗██████╗ ██████╗ ███████╗████████╗███████╗
██╔════╝████╗ ██║██║██╔══██╗██╔══██╗██╔════╝╚══██╔══╝██╔════╝
███████╗██╔██╗ ██║██║██████╔╝██████╔╝█████╗ ██║ ███████╗
╚════██║██║╚██╗██║██║██╔═══╝ ██╔═══╝ ██╔══╝ ██║ ╚════██║
███████║██║ ╚████║██║██║ ██║ ███████╗ ██║ ███████║
╚══════╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚══════╝ ╚═╝ ╚══════╝
```"];
// default description of super powers
$readme[] = "\n### What is JCB Snippets?\n
\nJCB snippets provide a powerful way to define and reuse small blocks of code throughout your JCB-generated components. This repository serves as a central system for maintaining, updating, and distributing these snippets within the Joomla Component Builder (JCB) ecosystem.\n
\nWhen you need to update any snippet in JCB, simply select the desired snippet and click the **“reset”** button. This will automatically sync the selected snippet with the latest version hosted in our core repository, ensuring you benefit from the most up-to-date improvements and fixes.\n
\nIf you prefer to tailor snippets to your specific development style or component structure, you can fork this repository and point your JCB instance to your own fork. This allows you to independently maintain and update your custom snippet collection, offering the flexibility to build components your way—while still leveraging the foundation provided by the community.\n
\nWe believe this approach empowers you to extend and customize JCB to meet your exact needs, embodying the open-source principles of freedom, adaptability, and shared progress.\n";
// get the readme body
$readme[] = $this->readmeBuilder($items);
// yes you can remove this, but why?
$readme[] = "\n---\n```
██╗ ██████╗ ██████╗ ███╗ ███╗██╗ █████╗
██║██╔═══██╗██╔═══██╗████╗ ████║██║ ██╔══██╗
██║██║ ██║██║ ██║██╔████╔██║██║ ███████║
██ ██║██║ ██║██║ ██║██║╚██╔╝██║██║ ██╔══██║
╚█████╔╝╚██████╔╝╚██████╔╝██║ ╚═╝ ██║███████╗██║ ██║
╚════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗ ███╗ ██╗███████╗███╗ ██╗████████╗
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔═══██╗████╗ ██║██╔════╝████╗ ██║╚══██╔══╝
██║ ██║ ██║██╔████╔██║██████╔╝██║ ██║██╔██╗ ██║█████╗ ██╔██╗ ██║ ██║
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██║╚██╗██║██╔══╝ ██║╚██╗██║ ██║
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚██████╔╝██║ ╚████║███████╗██║ ╚████║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═══╝ ╚═╝
██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗
██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗
██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝
██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗
██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝
```\n> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)\n\n";
return implode("\n", $readme);
}
/**
* The readme builder
*
* @param array $classes The powers.
*
* @return string
* @since 3.2.0
*/
private function readmeBuilder(array &$items): string
{
$classes = [];
foreach ($items as $guid => $power)
{
// add to the sort bucket
$classes[] = [
'name' => $power['name'],
'link' => $this->indexLinkPower($power)
];
}
return $this->readmeModel($classes);
}
/**
* Sort and model the readme classes
*
* @param array $classes The powers.
*
* @return string
* @since 3.2.0
*/
private function readmeModel(array &$classes): string
{
$this->sortClasses($classes);
return $this->generateIndex($classes);
}
/**
* Generate the index string for classes
*
* @param array $classes The sorted classes
*
* @return string The index string
*/
private function generateIndex(array &$classes): string
{
$result = "# Index of Snippets\n";
foreach ($classes as $class)
{
// Add the class details
$result .= "\n - " . $class['link'];
}
return $result;
}
/**
* Sort the flattened array using a single sorting function
*
* @param array $classes The classes to sort
*
* @since 3.2.0
*/
private function sortClasses(array &$classes): void
{
usort($classes, function ($a, $b) {
return $this->compareName($a, $b);
});
}
/**
* Compare the name of two classes
*
* @param array $a First class
* @param array $b Second class
*
* @return int Comparison result
* @since 3.2.0
*/
private function compareName(array $a, array $b): int
{
return strcmp($a['name'], $b['name']);
}
/**
* Build the Link to the power in this repository
*
* @param array $power The power details.
*
* @return string
* @since 3.2.0
*/
private function indexLinkPower(array &$power): string
{
$name = $power['name'] ?? 'error';
return '**' . $name . "** | "
. $this->linkPowerRepo($power) . ' | '
. $this->linkPowerSettings($power) . ' | '
. $this->linkPowerDesc($power);
}
/**
* Build the Link to the power in this repository
*
* @param array $power The power details.
*
* @return string
* @since 3.2.0
*/
private function linkPowerRepo(array &$power): string
{
$path = $power['path'] ?? 'error';
return '[Details](' . $path . ')';
}
/**
* Build the Link to the power settings in this repository
*
* @param array $power The power details.
*
* @return string
* @since 3.2.0
*/
private function linkPowerSettings(array &$power): string
{
$settings = $power['settings'] ?? 'error';
return '[Settings](' . $settings . ')';
}
/**
* Get the short description
*
* @param array $power The power details.
*
* @return string
* @since 3.2.0
*/
private function linkPowerDesc(array &$power): string
{
$jpk = $power['desc'] ?? '';
return $jpk;
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -0,0 +1,153 @@
<?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\Componentbuilder\Snippet\Remote;
use VDM\Joomla\Interfaces\Remote\ConfigInterface;
use VDM\Joomla\Abstraction\Remote\Config as ExtendingConfig;
/**
* Base Configure values for the remote classes
*
* @since 5.2.1
*/
final class Config extends ExtendingConfig implements ConfigInterface
{
/**
* Table Name
*
* @var string
* @since 5.2.1
*/
protected string $table = 'snippet';
/**
* Area Name
*
* @var string|null
* @since 5.2.1
*/
protected ?string $area = 'Snippet';
/**
* Prefix Key
*
* @var string
* @since 5.2.1
*/
protected string $prefix_key = '';
/**
* Suffix Key
*
* @var string
* @since 5.2.1
*/
protected string $suffix_key = '';
/**
* The main readme file path
*
* @var string
* @since 5.2.1
*/
// [DEFAULT] protected string $main_readme_path = 'README.md';
/**
* The index file path (index of all items)
*
* @var string
* @since 3.2.2
*/
// [DEFAULT] protected string $index_path = 'index.json';
/**
* The item (files) source path
*
* @var string
* @since 5.2.1
*/
// [DEFAULT] protected string $src_path = 'src';
/**
* The item settings file path
*
* @var string
* @since 3.2.2
*/
// [DEFAULT] protected string $settings_path = 'item.json';
/**
* The item guid=unique field
*
* @var string
* @since 5.2.1
*/
// [DEFAULT] protected string $guid_field = 'guid';
/**
* The item map
*
* @var array
* @since 5.0.3
protected array $map = [];
[DEFAULT] */
/**
* The index map
* must always have: [name,path,guid]
* you can add more
*
* @var array
* @since 5.0.3
*/
protected array $index_map = [
'name' => 'index_map_IndexName',
'description' => 'index_map_ShortDescription',
'path' => 'index_map_IndexPath',
'guid' => 'index_map_IndexGUID'
];
/**
* The index header
* mapping the index map to a table
* must always have: [name,path,guid,local]
* with [name] always first
* with [path,guid,local] always last
* you can add more in between
*
* @var array
* @since 5.2.1
*/
protected array $index_header = [
'name',
'description',
'path',
'guid',
'local'
];
/**
* Core Placeholders
*
* @var array
* @since 5.0.3
protected array $placeholders = [
'[['.'[NamespacePrefix]]]' => 'VDM',
'[['.'[ComponentNamespace]]]' => 'Componentbuilder',
'[['.'[Component]]]' => 'Componentbuilder',
'[['.'[component]]]' => 'componentbuilder'
];
[DEFAULT] */
}

View File

@@ -0,0 +1,158 @@
<?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\Componentbuilder\Snippet\Remote;
use Joomla\CMS\Language\Text;
use VDM\Joomla\Interfaces\Remote\SetInterface;
use VDM\Joomla\Abstraction\Remote\Set as ExtendingSet;
/**
* Set Snippet based on global unique ids to remote repository
*
* @since 5.1.1
*/
final class Set extends ExtendingSet implements SetInterface
{
/**
* update an existing item (if changed)
*
* @param object $item
* @param object $existing
* @param object $repo
*
* @return bool
* @since 5.0.3
*/
protected function updateItem(object $item, object $existing, object $repo): bool
{
$sha = $existing->params->source[$repo->guid . '-settings'] ?? null;
$existing = $this->mapItem($existing);
$area = $this->getArea();
$item_name = $this->index_map_IndexName($item);
$repo_name = $this->getRepoName($repo);
if ($sha === null || $this->areObjectsEqual($item, $existing))
{
$this->messages->add('warning', Text::sprintf('COM_COMPONENTBUILDER_S_ITEM_S_DETAILS_IN_REPOS_DID_NOT_CHANGE_SO_NO_UPDATE_WAS_MADE', $area, $item_name, $repo_name));
return false;
}
$result = $this->git->update(
$repo->organisation, // The owner name.
$repo->repository, // The repository name.
$this->index_map_IndexSettingsPath($item), // The file path.
json_encode($item, JSON_PRETTY_PRINT), // The file content.
'Update ' . $item->name, // The commit message.
$sha, // The blob SHA of the old file.
$repo->write_branch // The branch name.
);
$success = is_object($result);
if (!$success)
{
$this->messages->add('warning', Text::sprintf('COM_COMPONENTBUILDER_S_ITEM_S_DETAILS_IN_REPOS_FAILED_TO_UPDATE', $area, $item_name, $repo_name));
}
return $success;
}
/**
* create a new item
*
* @param object $item
* @param object $repo
*
* @return void
* @since 5.0.3
*/
protected function createItem(object $item, object $repo): void
{
$result = $this->git->create(
$repo->organisation, // The owner name.
$repo->repository, // The repository name.
$this->index_map_IndexSettingsPath($item), // The file path.
json_encode($item, JSON_PRETTY_PRINT), // The file content.
'Create ' . $item->name, // The commit message.
$repo->write_branch // The branch name.
);
return is_object($result);
}
/**
* update an existing item readme
*
* @param object $item
* @param object $existing
* @param object $repo
*
* @return void
* @since 5.0.3
*/
protected function updateItemReadme(object $item, object $existing, object $repo): void
{
// make sure there was a change
$sha = $existing->params->source[$repo->guid . '-readme'] ?? null;
if ($sha === null)
{
return;
}
$this->git->update(
$repo->organisation, // The owner name.
$repo->repository, // The repository name.
$this->index_map_IndexPath($item) . '/README.md', // The file path.
$this->itemReadme->get($item), // The file content.
'Update ' . $item->name . ' readme file', // The commit message.
$sha, // The blob SHA of the old file.
$repo->write_branch // The branch name.
);
}
/**
* create a new item readme
*
* @param object $item
* @param object $repo
*
* @return void
* @since 5.0.3
*/
protected function createItemReadme(object $item, object $repo): void
{
$this->git->create(
$repo->organisation, // The owner name.
$repo->repository, // The repository name.
$this->index_map_IndexPath($item) . '/README.md', // The file path.
$this->itemReadme->get($item), // The file content.
'Create ' . $item->name . ' readme file', // The commit message.
$repo->write_branch // The branch name.
);
}
/**
* Get the item name for the index values
*
* @param object $item
*
* @return string|null
* @since 5.0.3
*/
protected function index_map_IndexName(object $item): ?string
{
return $item->name ?? null;
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -0,0 +1,231 @@
<?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\Componentbuilder\Snippet\Service;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Snippet\Config;
use VDM\Joomla\Componentbuilder\Power\Table;
use VDM\Joomla\Componentbuilder\Package\MessageBus;
use VDM\Joomla\Componentbuilder\Snippet\Grep;
use VDM\Joomla\Componentbuilder\Snippet\Remote\Config as RemoteConfig;
use VDM\Joomla\Componentbuilder\Package\Dependency\Resolver;
use VDM\Joomla\Componentbuilder\Power\Remote\Get;
use VDM\Joomla\Componentbuilder\Snippet\Remote\Set;
use VDM\Joomla\Componentbuilder\Snippet\Readme\Item as ItemReadme;
use VDM\Joomla\Componentbuilder\Snippet\Readme\Main as MainReadme;
/**
* Snippet Service Provider
*
* @since 5.2.1
*/
class Snippet implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
* @since 5.2.1
*/
public function register(Container $container)
{
$container->alias(Config::class, 'Config')
->share('Config', [$this, 'getConfig'], true);
$container->alias(Table::class, 'Power.Table')->alias('Table', 'Power.Table')
->share('Power.Table', [$this, 'getPowerTable'], true);
$container->alias(MessageBus::class, 'Power.Message')
->share('Power.Message', [$this, 'getMessageBus'], true);
$container->alias(Grep::class, 'Snippet.Grep')
->share('Snippet.Grep', [$this, 'getGrep'], true);
$container->alias(RemoteConfig::class, 'Snippet.Remote.Config')
->share('Snippet.Remote.Config', [$this, 'getRemoteConfig'], true);
$container->alias(Resolver::class, 'Snippet.Resolver')
->share('Snippet.Resolver', [$this, 'getResolver'], true);
$container->alias(Get::class, 'Snippet.Remote.Get')
->share('Snippet.Remote.Get', [$this, 'getRemoteGet'], true);
$container->alias(Set::class, 'Snippet.Remote.Set')
->share('Snippet.Remote.Set', [$this, 'getRemoteSet'], true);
$container->alias(ItemReadme::class, 'Snippet.Readme.Item')
->share('Snippet.Readme.Item', [$this, 'getItemReadme'], true);
$container->alias(MainReadme::class, 'Snippet.Readme.Main')
->share('Snippet.Readme.Main', [$this, 'getMainReadme'], true);
}
/**
* Get The Config Class.
*
* @param Container $container The DI container.
*
* @return Config
* @since 5.2.1
*/
public function getConfig(Container $container): Config
{
return new Config();
}
/**
* Get The Power Table Class.
*
* @param Container $container The DI container.
*
* @return Table
* @since 5.2.1
*/
public function getPowerTable(Container $container): Table
{
return new Table();
}
/**
* Get The Message Bus Class.
*
* @param Container $container The DI container.
*
* @return MessageBus
* @since 5.2.1
*/
public function getMessageBus(Container $container): MessageBus
{
return new MessageBus();
}
/**
* Get The Grep Class.
*
* @param Container $container The DI container.
*
* @return Grep
* @since 5.2.1
*/
public function getGrep(Container $container): Grep
{
return new Grep(
$container->get('Snippet.Remote.Config'),
$container->get('Gitea.Repository.Contents'),
$container->get('Network.Resolve'),
$container->get('Config')->approved_joomla_paths
);
}
/**
* Get The Remote Configure Class.
*
* @param Container $container The DI container.
*
* @return RemoteConfig
* @since 5.2.1
*/
public function getRemoteConfig(Container $container): RemoteConfig
{
return new RemoteConfig(
$container->get('Power.Table')
);
}
/**
* Get The Resolver Class.
*
* @param Container $container The DI container.
*
* @return Resolver
* @since 5.2.1
*/
public function getResolver(Container $container): Resolver
{
return new Resolver(
$container->get('Snippet.Remote.Config'),
$container->get('Power.Tracker'),
$container->get('Power.Table')
);
}
/**
* Get The Remote Get Class.
*
* @param Container $container The DI container.
*
* @return Get
* @since 5.2.1
*/
public function getRemoteGet(Container $container): Get
{
return new Get(
$container->get('Snippet.Remote.Config'),
$container->get('Snippet.Grep'),
$container->get('Data.Item')
);
}
/**
* Get The Remote Set Class.
*
* @param Container $container The DI container.
*
* @return Set
* @since 5.2.1
*/
public function getRemoteSet(Container $container): Set
{
return new Set(
$container->get('Snippet.Remote.Config'),
$container->get('Snippet.Grep'),
$container->get('Data.Items'),
$container->get('Snippet.Readme.Item'),
$container->get('Snippet.Readme.Main'),
$container->get('Gitea.Repository.Contents'),
$container->get('Power.Message'),
$container->get('Config')->approved_joomla_paths
);
}
/**
* Get The Item Class.
*
* @param Container $container The DI container.
*
* @return ItemReadme
* @since 5.2.1
*/
public function getItemReadme(Container $container): ItemReadme
{
return new ItemReadme();
}
/**
* Get The Main Class.
*
* @param Container $container The DI container.
*
* @return MainReadme
* @since 5.2.1
*/
public function getMainReadme(Container $container): MainReadme
{
return new MainReadme();
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>