Release of v5.0.0-beta3
Add Joomla powers for namespace dynamic management.
This commit is contained in:
@@ -800,6 +800,62 @@ class Config extends BaseConfig
|
||||
return array_values($approved);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get super power core organisation
|
||||
*
|
||||
* @return string The super power core organisation
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getJoomlapowerscoreorganisation(): string
|
||||
{
|
||||
// the VDM default organisation is [joomla]
|
||||
$organisation = 'joomla';
|
||||
|
||||
return $this->params->get('joomla_powers_core_organisation', $organisation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Joomla power init repos
|
||||
*
|
||||
* @return array The init repositories on Gitea
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getJoomlapowersinitrepos(): array
|
||||
{
|
||||
// some defaults repos we need by JCB
|
||||
$repos = [];
|
||||
$repos[$this->joomla_powers_core_organisation . '.joomla-powers'] = (object) ['owner' => $this->joomla_powers_core_organisation, 'repo' => 'joomla-powers', 'branch' => 'master'];
|
||||
|
||||
return $repos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get joomla power approved paths
|
||||
*
|
||||
* @return array The 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* get bom path
|
||||
*
|
||||
|
@@ -18,6 +18,7 @@ use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Language\Extractor;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor as Power;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\JoomlaPower\Extractor as JoomlaPower;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode\External;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
@@ -111,6 +112,14 @@ class Customcode implements CustomcodeInterface
|
||||
**/
|
||||
protected Power $power;
|
||||
|
||||
/**
|
||||
* Joomla Power Extractor
|
||||
*
|
||||
* @var Power
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected JoomlaPower $joomla;
|
||||
|
||||
/**
|
||||
* Compiler Custom Code External
|
||||
*
|
||||
@@ -129,23 +138,25 @@ class Customcode implements CustomcodeInterface
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param Placeholder|null $placeholder The compiler placeholder object.
|
||||
* @param Extractor|null $extractor The compiler language extractor object.
|
||||
* @param Power|null $power The compiler power extractor object.
|
||||
* @param External|null $external The compiler external custom code object.
|
||||
* @param \JDatabaseDriver $db The Database Driver object.
|
||||
* @param Config $config The compiler config object.
|
||||
* @param Placeholder $placeholder The compiler placeholder object.
|
||||
* @param Extractor $extractor The compiler language extractor object.
|
||||
* @param Power $power The compiler power extractor object.
|
||||
* @param JoomlaPower $joomla The compiler joomla power extractor object.
|
||||
* @param External $external The compiler external custom code object.
|
||||
* @param \JDatabaseDriver $db The Database Driver object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Placeholder $placeholder = null,
|
||||
?Extractor $extractor = null, ?Power $power = null, ?External $external = null)
|
||||
public function __construct(Config $config, Placeholder $placeholder,
|
||||
Extractor $extractor, Power $power, JoomlaPower $joomla, External $external)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->extractor = $extractor ?: Compiler::_('Language.Extractor');
|
||||
$this->power = $power ?: Compiler::_('Power.Extractor');
|
||||
$this->external = $external ?: Compiler::_('Customcode.External');
|
||||
$this->config = $config;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->extractor = $extractor;
|
||||
$this->power = $power;
|
||||
$this->joomla = $joomla;
|
||||
$this->external = $external;
|
||||
$this->db = Factory::getDbo();
|
||||
}
|
||||
|
||||
@@ -170,8 +181,9 @@ class Customcode implements CustomcodeInterface
|
||||
)
|
||||
);
|
||||
|
||||
// extract any found super powers
|
||||
// extract any found powers
|
||||
$this->power->search($string);
|
||||
$this->joomla->search($string);
|
||||
}
|
||||
// if debug
|
||||
if ($debug)
|
||||
|
@@ -25,6 +25,7 @@ use VDM\Joomla\Componentbuilder\Compiler\Service\Language;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Power;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\JoomlaPower;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Component;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Adminview;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Library;
|
||||
@@ -157,6 +158,7 @@ abstract class Factory implements FactoryInterface
|
||||
->registerServiceProvider(new Placeholder())
|
||||
->registerServiceProvider(new Customcode())
|
||||
->registerServiceProvider(new Power())
|
||||
->registerServiceProvider(new JoomlaPower())
|
||||
->registerServiceProvider(new Component())
|
||||
->registerServiceProvider(new Adminview())
|
||||
->registerServiceProvider(new Library())
|
||||
|
@@ -405,7 +405,7 @@ class Compiler extends Infusion
|
||||
{
|
||||
CFactory::_('Power')->load($super_powers);
|
||||
}
|
||||
// set the autoloader for Powers
|
||||
// set the autoloader for Powers (second time)
|
||||
CFactory::_('Power.Autoloader')->set();
|
||||
// get the bom file
|
||||
$bom = FileHelper::getContent(CFactory::_('Config')->bom_path);
|
||||
@@ -739,7 +739,11 @@ class Compiler extends Infusion
|
||||
);
|
||||
|
||||
// inject any super powers found
|
||||
$answer = CFactory::_('Power.Injector')->power($answer);
|
||||
$answer = CFactory::_('Joomla.Power.Injector')->power(
|
||||
CFactory::_('Power.Injector')->power(
|
||||
$answer
|
||||
)
|
||||
);
|
||||
|
||||
// add answer back to file
|
||||
CFactory::_('Utilities.File')->write($path, $answer);
|
||||
|
@@ -2144,6 +2144,9 @@ class Infusion extends Interpretation
|
||||
);
|
||||
}
|
||||
|
||||
// set the autoloader for Powers (first time)
|
||||
CFactory::_('Power.Autoloader')->set();
|
||||
|
||||
// tweak system to set stuff to the module domain
|
||||
$_backup_target = CFactory::_('Config')->build_target;
|
||||
$_backup_lang = CFactory::_('Config')->lang_target;
|
||||
|
@@ -0,0 +1,61 @@
|
||||
<?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\Compiler\Interfaces\Power;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Power Extractor
|
||||
* @since 3.2.1
|
||||
*/
|
||||
interface ExtractorInterface
|
||||
{
|
||||
/**
|
||||
* Get Super Powers from the code string
|
||||
*
|
||||
* @param string $code The code
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get_(): ?array;
|
||||
|
||||
/**
|
||||
* Get Super Powers from the code string
|
||||
*
|
||||
* @param string $code The code
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $code): ?array;
|
||||
|
||||
/**
|
||||
* Get Super Powers from the code string
|
||||
*
|
||||
* @param string $code The code
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function reverse(string $code): ?array;
|
||||
|
||||
/**
|
||||
* Get Super Powers from the code string and load it
|
||||
*
|
||||
* @param string $code The code
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function search(string $code): void;
|
||||
}
|
||||
|
@@ -0,0 +1,31 @@
|
||||
<?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\Compiler\Interfaces\Power;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Power Injector
|
||||
* @since 3.2.1
|
||||
*/
|
||||
interface InjectorInterface
|
||||
{
|
||||
/**
|
||||
* Inject the powers found in the code
|
||||
*
|
||||
* @param string $code The class code
|
||||
*
|
||||
* @return string The updated code
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function power(string $code): string;
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -0,0 +1,446 @@
|
||||
<?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\Compiler;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
use VDM\Joomla\Utilities\String\NamespaceHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Super as SuperPower;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\PowerInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Joomla Power
|
||||
*
|
||||
* @since 3.2.1
|
||||
*/
|
||||
final class JoomlaPower implements PowerInterface
|
||||
{
|
||||
/**
|
||||
* All loaded powers
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.1
|
||||
**/
|
||||
public array $active = [];
|
||||
|
||||
/**
|
||||
* All power namespaces
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.1
|
||||
**/
|
||||
public array $namespace = [];
|
||||
|
||||
/**
|
||||
* All super powers of this build
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.1
|
||||
**/
|
||||
public array $superpowers = [];
|
||||
|
||||
/**
|
||||
* Old super powers found in the local repos
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.1
|
||||
**/
|
||||
public array $old_superpowers = [];
|
||||
|
||||
/**
|
||||
* The url to the power, if there is an error.
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected string $fixUrl;
|
||||
|
||||
/**
|
||||
* The state of all loaded powers
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected array $state = [];
|
||||
|
||||
/**
|
||||
* The state of retry to loaded powers
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected array $retry = [];
|
||||
|
||||
/**
|
||||
* Compiler Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Compiler Placeholder
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* Compiler Customcode
|
||||
*
|
||||
* @var Customcode
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected Customcode $customcode;
|
||||
|
||||
/**
|
||||
* Compiler Customcode in Gui
|
||||
*
|
||||
* @var Gui
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected Gui $gui;
|
||||
|
||||
/**
|
||||
* The JCB Superpower class
|
||||
*
|
||||
* @var Superpower
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected Superpower $superpower;
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config $config The compiler config object.
|
||||
* @param Placeholder $placeholder The compiler placeholder object.
|
||||
* @param Customcode $customcode The compiler customcode object.
|
||||
* @param Gui $gui The compiler customcode gui object.
|
||||
* @param Superpower $superpower The JCB superpower object.
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.1
|
||||
*/
|
||||
public function __construct(Config $config, Placeholder $placeholder,
|
||||
Customcode $customcode, Gui $gui, Superpower $superpower)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->customcode = $customcode;
|
||||
$this->gui = $gui;
|
||||
$this->superpower = $superpower;
|
||||
$this->db = Factory::getDbo();
|
||||
$this->app = Factory::getApplication();
|
||||
}
|
||||
|
||||
/**
|
||||
* load all the powers linked to this component
|
||||
*
|
||||
* @param array $guids The global unique ids of the linked powers
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.1
|
||||
*/
|
||||
public function load(array $guids)
|
||||
{
|
||||
if (ArrayHelper::check($guids))
|
||||
{
|
||||
foreach ($guids as $guid => $build)
|
||||
{
|
||||
$this->get($guid, $build);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a power
|
||||
*
|
||||
* @param string $guid The global unique id of the power
|
||||
* @param int $build Force build switch (to override global switch)
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.1
|
||||
*/
|
||||
public function get(string $guid, int $build = 0): ?object
|
||||
{
|
||||
if (($this->config->get('add_power', true) || $build == 1) && $this->set($guid))
|
||||
{
|
||||
return $this->active[$guid];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a power
|
||||
*
|
||||
* @param string $guid The global unique id of the 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
|
||||
if ($this->isPowerSet($guid))
|
||||
{
|
||||
return $this->state[$guid];
|
||||
}
|
||||
elseif ($this->isGuidValid($guid))
|
||||
{
|
||||
// get the power data
|
||||
$this->active[$guid] = $this->getPowerData($guid);
|
||||
|
||||
if (is_object($this->active[$guid]))
|
||||
{
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// we failed to get the power,
|
||||
// so we raise an error message
|
||||
// only if guid is valid
|
||||
if ($this->isGuidValid($guid))
|
||||
{
|
||||
// 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->app->enqueueMessage(
|
||||
Text::sprintf('COM_COMPONENTBUILDER_PJOOMLA_POWER_BGUIDSB_NOT_FOUNDP', $guid),
|
||||
'Error'
|
||||
);
|
||||
}
|
||||
|
||||
// let's not try again
|
||||
$this->state[$guid] = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the last part of a namespace string, which is typically the class name.
|
||||
*
|
||||
* @param string $namespace The namespace string to extract from.
|
||||
*
|
||||
* @return string|null The extracted class name.
|
||||
* @since 3.2.1
|
||||
*/
|
||||
private function extractLastNameFromNamespace(string $namespace): ?string
|
||||
{
|
||||
$parts = explode('\\', $namespace);
|
||||
$result = end($parts);
|
||||
|
||||
// Remove '\\' from the beginning and end of the resulting string
|
||||
$result = trim($result, '\\');
|
||||
|
||||
// If the resulting string is empty, return null
|
||||
return empty($result) ? null : $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the last name from the namespace.
|
||||
*
|
||||
* @param string $namespace The namespace
|
||||
*
|
||||
* @return string The namespace shortened
|
||||
* @since 3.2.1
|
||||
*/
|
||||
private function removeLastNameFromNamespace(string $namespace): string
|
||||
{
|
||||
// Remove '\\' from the beginning and end of the resulting string
|
||||
$namespace = trim($namespace, '\\');
|
||||
|
||||
$parts = explode('\\', $namespace);
|
||||
|
||||
// Remove the last part (the class name)
|
||||
array_pop($parts);
|
||||
|
||||
// Reassemble the namespace without the class name
|
||||
return implode('\\', $parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the power is already set
|
||||
*
|
||||
* @param string $guid The global unique id of the power
|
||||
*
|
||||
* @return bool true if the power is already set
|
||||
* @since 3.2.1
|
||||
*/
|
||||
private function isPowerSet(string $guid): bool
|
||||
{
|
||||
return isset($this->state[$guid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the GUID
|
||||
*
|
||||
* @param string $guid The global unique id of the power
|
||||
*
|
||||
* @return bool true if the GUID is valid
|
||||
* @since 3.2.1
|
||||
*/
|
||||
private function isGuidValid(string $guid): bool
|
||||
{
|
||||
return GuidHelper::valid($guid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the power data from the database
|
||||
*
|
||||
* @param string $guid The global unique id of the power
|
||||
*
|
||||
* @return object|null The power data
|
||||
* @since 3.2.1
|
||||
*/
|
||||
private function getPowerData(string $guid): ?object
|
||||
{
|
||||
$query = $this->db->getQuery(true);
|
||||
$query->select('a.*');
|
||||
$query->from('#__componentbuilder_joomla_power AS a');
|
||||
$query->where($this->db->quoteName('a.guid') . ' = ' . $this->db->quote($guid));
|
||||
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return $this->db->loadObject();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Clean Namespace without use or ; as part of the name space
|
||||
*
|
||||
* @param string $namespace The actual name space
|
||||
* @param bool $removeNumbers The switch to remove numbers
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
private function getCleanNamespace(string $namespace): string
|
||||
{
|
||||
// trim possible (use) or (;) or (starting or ending \) added to the namespace
|
||||
return NamespaceHelper::safe(str_replace(['use ', ';'], '', $namespace));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get [use Namespace\Class;]
|
||||
*
|
||||
* @param string $namespace The actual name space
|
||||
* @param string $as The use as name (default is none)
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.1
|
||||
*/
|
||||
private function getUseNamespace(string $namespace, string $as = 'default'): string
|
||||
{
|
||||
// check if it has an AS option
|
||||
if ($as !== 'default')
|
||||
{
|
||||
return 'use ' . $namespace . ' as ' . $as . ';';
|
||||
}
|
||||
return 'use ' . $namespace . ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the super powers of this power
|
||||
*
|
||||
* @param string $guid The global unique id of the power
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.1
|
||||
*/
|
||||
private function setSuperPowers(string $guid): void
|
||||
{
|
||||
// soon
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,118 @@
|
||||
<?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\Compiler\JoomlaPower;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Power\ExtractorInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor as ExtendingExtractor;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Joomla Power Extractor
|
||||
* @since 3.2.1
|
||||
*/
|
||||
final class Extractor extends ExtendingExtractor implements ExtractorInterface
|
||||
{
|
||||
/**
|
||||
* The pattern to get the powers
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected string $pattern = '/Joomla_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/';
|
||||
|
||||
/**
|
||||
* The pattern to get the Front
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected string $_pattern = 'Joomla';
|
||||
|
||||
/**
|
||||
* The pattern to get the Back
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected string $pattern_ = 'Power';
|
||||
|
||||
/**
|
||||
* The Table
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected string $table = 'joomla_power';
|
||||
|
||||
/**
|
||||
* Current Joomla Version Being Build
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected $targetVersion;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $targetVersion The targeted Joomla version.
|
||||
*
|
||||
* @since 3.2.1
|
||||
*/
|
||||
public function __construct(int $targetVersion)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->targetVersion = $targetVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the complete namespace strings of the guids passed as an array.
|
||||
*
|
||||
* @param array $guids The guids to filter the results
|
||||
*
|
||||
* @return array|null The result namespaces with their guids
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function namespaces(array $guids): ?array
|
||||
{
|
||||
$query = $this->db->getQuery(true);
|
||||
$query->select($this->db->quoteName(['settings', 'guid']))
|
||||
->from($this->db->quoteName('#__componentbuilder_' . $this->table))
|
||||
->where($this->db->quoteName('guid') . ' IN (' . implode(',', array_map([$this->db, 'quote'], $guids)) . ')');
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
$namespaces = [];
|
||||
$items = $this->db->loadAssocList();
|
||||
foreach ($items as $item)
|
||||
{
|
||||
if (JsonHelper::check($item->settings))
|
||||
{
|
||||
$item->settings = json_decode($item->settings, true);
|
||||
echo '<pre>'; var_dump($item->settings, 'Joomla Version: ' . $this->targetVersion); exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($namespaces !== [])
|
||||
{
|
||||
return $namespaces;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,91 @@
|
||||
<?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\Compiler\JoomlaPower;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Power\InjectorInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Injector as ExtendingInjector;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Joomla Power Injector
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Injector extends ExtendingInjector implements InjectorInterface
|
||||
{
|
||||
/**
|
||||
* Builds the namespace statement from the power object's namespace and class name.
|
||||
*
|
||||
* @param object $power The power object.
|
||||
*
|
||||
* @return string The constructed use statement.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function buildNamespaceStatment(object $power): string
|
||||
{
|
||||
return $power->_namespace . '\\' . $power->class_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the name for the use statement is unique, avoiding conflicts with other classes.
|
||||
*
|
||||
* @param string $name The current name
|
||||
* @param object $power The power object containing type, namespace, and class name.
|
||||
*
|
||||
* @return string The unique name
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getUniqueName(string $name, object $power): string
|
||||
{
|
||||
// set search namespace
|
||||
$namespace = ($name !== $power->class_name) ? $this->buildNamespaceStatment($power) : $power->_namespace;
|
||||
|
||||
// check if we need to update the name
|
||||
if (isset($this->other[$name]))
|
||||
{
|
||||
// if the name is already used
|
||||
while (isset($this->other[$name]))
|
||||
{
|
||||
if (($tmp = $this->extractClassNameOrAlias($namespace)) !== null)
|
||||
{
|
||||
$name = ucfirst($tmp) . $name;
|
||||
$namespace = $this->removeLastNameFromNamespace($namespace);
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = 'Unique' . $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// also loop new found use statements
|
||||
if (isset($this->useStatements[$name]))
|
||||
{
|
||||
// if the name is already used
|
||||
while (isset($this->useStatements[$name]))
|
||||
{
|
||||
if (($tmp = $this->extractClassNameOrAlias($namespace)) !== null)
|
||||
{
|
||||
$name = ucfirst($tmp) . $name;
|
||||
$namespace = $this->removeLastNameFromNamespace($namespace);
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = 'Unique' . $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@@ -174,16 +174,18 @@ class Router
|
||||
|
||||
// We can only work with ID if the [main get] is a [getItem] dynamicGet for this site view.
|
||||
$key = ($view['settings']->main_get->gettype == 1) ? 'id' : null;
|
||||
$view_selected = $selection['view'] ?? null;
|
||||
$name_selected = $selection['name'] ?? null;
|
||||
|
||||
// Construct the enriched view object.
|
||||
return (object) [
|
||||
'view' => $view['settings']->code,
|
||||
'View' => $view['settings']->Code,
|
||||
'stable' => ($selection['view'] === $view['settings']->code), // sanity check
|
||||
'target_view' => $selection['view'],
|
||||
'table' => $selection['table'],
|
||||
'table_name' => $selection['name'],
|
||||
'alias' => $this->getSiteViewAliasKey($selection['name'] ?? null, $adminViews),
|
||||
'stable' => ($view_selected === $view['settings']->code), // sanity check
|
||||
'target_view' => $view_selected,
|
||||
'table' => $selection['table'] ?? null,
|
||||
'table_name' => $name_selected,
|
||||
'alias' => $this->getSiteViewAliasKey($name_selected, $adminViews),
|
||||
'key' => $key,
|
||||
'form' => false
|
||||
];
|
||||
|
@@ -21,6 +21,7 @@ use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Language;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Language\Extractor;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor as Power;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\JoomlaPower\Extractor as JoomlaPower;
|
||||
|
||||
|
||||
/**
|
||||
@@ -70,27 +71,36 @@ class Reverse
|
||||
**/
|
||||
protected Power $power;
|
||||
|
||||
/**
|
||||
* Joomla Power Extractor
|
||||
*
|
||||
* @var Power
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected JoomlaPower $joomla;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param Placeholder|null $placeholder The compiler placeholder object.
|
||||
* @param Language|null $language The compiler language object.
|
||||
* @param Extractor|null $extractor The compiler language extractor object.
|
||||
* @param Power|null $power The compiler power extractor object.
|
||||
* @param Config $config The compiler config object.
|
||||
* @param Placeholder $placeholder The compiler placeholder object.
|
||||
* @param Language $language The compiler language object.
|
||||
* @param Extractor $extractor The compiler language extractor object.
|
||||
* @param Power $power The compiler power extractor object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(
|
||||
?Config $config = null, ?Placeholder $placeholder = null,
|
||||
?Language $language = null, ?Extractor $extractor = null,
|
||||
?Power $power = null)
|
||||
Config $config, Placeholder $placeholder,
|
||||
Language $language, Extractor $extractor,
|
||||
Power $power, JoomlaPower $joomla)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->language = $language ?: Compiler::_('Language');
|
||||
$this->extractor = $extractor ?: Compiler::_('Language.Extractor');
|
||||
$this->power = $power ?: Compiler::_('Power.Extractor');
|
||||
$this->config = $config;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->language = $language;
|
||||
$this->extractor = $extractor;
|
||||
$this->power = $power;
|
||||
$this->joomla = $joomla;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,8 +148,9 @@ class Reverse
|
||||
protected function setReverse(string $updateString, string $string,
|
||||
string $target, ?array $useStatements): string
|
||||
{
|
||||
// we have to reverse engineer to super powers
|
||||
// we have to reverse engineer of powers
|
||||
$updateString = $this->reverseSuperPowers($updateString, $string, $useStatements);
|
||||
$updateString = $this->reverseJoomlaPowers($updateString, $string, $useStatements);
|
||||
|
||||
// reverse engineer the language strings
|
||||
$updateString = $this->reverseLanguage($updateString, $string, $target);
|
||||
@@ -165,7 +176,30 @@ class Reverse
|
||||
{
|
||||
// only if we have use statements can we reverse engineer this
|
||||
if ($useStatements !== null && ($powers = $this->power->reverse($string)) !== null &&
|
||||
($reverse = $this->getReversePower($powers, $useStatements)) !== null)
|
||||
($reverse = $this->getReversePower($powers, $useStatements, 'Super')) !== null)
|
||||
{
|
||||
return $this->placeholder->update($updateString, $reverse);
|
||||
}
|
||||
|
||||
return $updateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the joomla powers keys for the reveres process
|
||||
*
|
||||
* @param string $updateString The string to update
|
||||
* @param string $string The string to use for super power update
|
||||
* @param array|null $useStatements The file use statements (needed for super powers)
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function reverseJoomlaPowers(string $updateString, string $string,
|
||||
?array $useStatements): string
|
||||
{
|
||||
// only if we have use statements can we reverse engineer this
|
||||
if ($useStatements !== null && ($powers = $this->joomla->reverse($string)) !== null &&
|
||||
($reverse = $this->getReversePower($powers, $useStatements, 'Joomla')) !== null)
|
||||
{
|
||||
return $this->placeholder->update($updateString, $reverse);
|
||||
}
|
||||
@@ -178,11 +212,12 @@ class Reverse
|
||||
*
|
||||
* @param array $powers The powers found in the database text
|
||||
* @param array $useStatements The file use statements
|
||||
* @param string $target The power target type
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getReversePower(array $powers, array $useStatements): ?array
|
||||
protected function getReversePower(array $powers, array $useStatements, string $target): ?array
|
||||
{
|
||||
$matching_statements = [];
|
||||
foreach ($useStatements as $use_statement)
|
||||
@@ -211,7 +246,7 @@ class Reverse
|
||||
{
|
||||
$guid = array_search($namespace, $powers);
|
||||
$matching_statements[$class_name] =
|
||||
'Super_'.'_'.'_' . str_replace('-', '_', $guid) . '_'.'_'.'_Power';
|
||||
$target . '_'.'_'.'_' . str_replace('-', '_', $guid) . '_'.'_'.'_Power';
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -303,7 +303,7 @@ class Power implements PowerInterface
|
||||
$this->setImplements($guid, $use);
|
||||
|
||||
// set extend class
|
||||
$this->setExtend($guid, $use);
|
||||
$this->setExtend($guid, $use, $as);
|
||||
|
||||
// set GUI mapper
|
||||
$guiMapper = [
|
||||
@@ -760,11 +760,12 @@ class Power implements PowerInterface
|
||||
*
|
||||
* @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 setExtend(string $guid, array &$use)
|
||||
private function setExtend(string $guid, array &$use, array &$as)
|
||||
{
|
||||
// does this extend something
|
||||
$this->active[$guid]->extends_name = null;
|
||||
@@ -793,6 +794,13 @@ class Power implements PowerInterface
|
||||
$this->active[$guid]->extends_name = $this->get($this->active[$guid]->extends, 1)->class_name;
|
||||
// add to use
|
||||
$use[] = $this->active[$guid]->extends;
|
||||
|
||||
// add padding if the two names are the same
|
||||
if ($this->active[$guid]->extends_name === $this->active[$guid]->class_name)
|
||||
{
|
||||
$this->active[$guid]->extends_name = $as[$this->active[$guid]->extends]
|
||||
= 'Extending' . $this->active[$guid]->class_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,13 +14,14 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Power;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Power\ExtractorInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Power Extractor
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Extractor
|
||||
class Extractor implements ExtractorInterface
|
||||
{
|
||||
/**
|
||||
* The pattern to get the powers
|
||||
@@ -30,6 +31,30 @@ final class Extractor
|
||||
**/
|
||||
protected string $pattern = '/Super_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/';
|
||||
|
||||
/**
|
||||
* The pattern to get the Front
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected string $_pattern = 'Super';
|
||||
|
||||
/**
|
||||
* The pattern to get the Back
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected string $pattern_ = 'Power';
|
||||
|
||||
/**
|
||||
* The Table
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.1
|
||||
**/
|
||||
protected string $table = 'power';
|
||||
|
||||
/**
|
||||
* Powers GUID's
|
||||
*
|
||||
@@ -122,7 +147,7 @@ final class Extractor
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function search(string $code)
|
||||
public function search(string $code): void
|
||||
{
|
||||
$matches = [];
|
||||
preg_match_all($this->pattern, $code, $matches);
|
||||
@@ -147,7 +172,7 @@ final class Extractor
|
||||
{
|
||||
foreach ($found as $super_power)
|
||||
{
|
||||
$guid = str_replace(['Super_'.'_'.'_', '_'.'_'.'_Power'], '', $super_power);
|
||||
$guid = str_replace([], '', $super_power);
|
||||
$guid = str_replace('_', '-', $guid);
|
||||
|
||||
if (GuidHelper::valid($guid))
|
||||
@@ -171,7 +196,7 @@ final class Extractor
|
||||
|
||||
foreach ($found as $super_power)
|
||||
{
|
||||
$guid = str_replace(['Super_'.'_'.'_', '_'.'_'.'_Power'], '', $super_power);
|
||||
$guid = str_replace([$this->_pattern . '___', '___' . $this->pattern_], '', $super_power);
|
||||
$guid = str_replace('_', '-', $guid);
|
||||
|
||||
if (GuidHelper::valid($guid))
|
||||
@@ -197,7 +222,7 @@ final class Extractor
|
||||
|
||||
foreach ($found as $super_power)
|
||||
{
|
||||
$guid = str_replace(['Super_'.'_'.'_', '_'.'_'.'_Power'], '', $super_power);
|
||||
$guid = str_replace([$this->_pattern . '___', '___' . $this->pattern_], '', $super_power);
|
||||
$guid = str_replace('_', '-', $guid);
|
||||
|
||||
if (GuidHelper::valid($guid))
|
||||
@@ -226,7 +251,7 @@ final class Extractor
|
||||
. ', ".", "\\\") AS full_namespace, '
|
||||
. $this->db->quoteName('guid')
|
||||
)
|
||||
->from($this->db->quoteName('#__componentbuilder_power'))
|
||||
->from($this->db->quoteName('#__componentbuilder_' . $this->table))
|
||||
->where($this->db->quoteName('guid') . ' IN (' . implode(',', array_map([$this->db, 'quote'], $guids)) . ')');
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
@@ -12,18 +12,18 @@
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\Power;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\PowerInterface as Power;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Power\ExtractorInterface as Extractor;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Parser;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Power\InjectorInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Power Injector
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Injector
|
||||
class Injector implements InjectorInterface
|
||||
{
|
||||
/**
|
||||
* Power Objects
|
||||
@@ -107,13 +107,13 @@ final class Injector
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Power $power = null, ?Extractor $extractor = null,
|
||||
?Parser $parser = null, ?Placeholder $placeholder = null)
|
||||
public function __construct(Power $power = null, Extractor $extractor = null,
|
||||
Parser $parser = null, Placeholder $placeholder = null)
|
||||
{
|
||||
$this->power = $power ?: Compiler::_('Power');
|
||||
$this->extractor = $extractor ?: Compiler::_('Power.Extractor');
|
||||
$this->parser = $parser ?: Compiler::_('Power.Parser');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->power = $power;
|
||||
$this->extractor = $extractor;
|
||||
$this->parser = $parser;
|
||||
$this->placeholder = $placeholder;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -82,6 +82,7 @@ class Customcode implements ServiceProviderInterface
|
||||
$container->get('Placeholder'),
|
||||
$container->get('Language.Extractor'),
|
||||
$container->get('Power.Extractor'),
|
||||
$container->get('Joomla.Power.Extractor'),
|
||||
$container->get('Customcode.External')
|
||||
);
|
||||
}
|
||||
|
@@ -0,0 +1,202 @@
|
||||
<?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\Compiler\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\JoomlaPower as Powers;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Grep;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Super as Superpower;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\JoomlaPower\Extractor;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\JoomlaPower\Injector;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Model\Upsert;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Database\Insert;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Database\Update;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Joomla Power Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class JoomlaPower implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Powers::class, 'Joomla.Power')
|
||||
->share('Joomla.Power', [$this, 'getPowers'], true);
|
||||
|
||||
$container->alias(Superpower::class, 'Joomlapower')
|
||||
->share('Joomlapower', [$this, 'getSuperpower'], true);
|
||||
|
||||
$container->alias(Grep::class, 'Joomla.Power.Grep')
|
||||
->share('Joomla.Power.Grep', [$this, 'getGrep'], true);
|
||||
|
||||
$container->alias(Extractor::class, 'Joomla.Power.Extractor')
|
||||
->share('Joomla.Power.Extractor', [$this, 'getExtractor'], true);
|
||||
|
||||
$container->alias(Injector::class, 'Joomla.Power.Injector')
|
||||
->share('Joomla.Power.Injector', [$this, 'getInjector'], true);
|
||||
|
||||
$container->alias(Upsert::class, 'Joomla.Power.Model.Upsert')
|
||||
->share('Joomla.Power.Model.Upsert', [$this, 'getModelUpsert'], true);
|
||||
|
||||
$container->alias(Insert::class, 'Joomla.Power.Insert')
|
||||
->share('Joomla.Power.Insert', [$this, 'getInsert'], true);
|
||||
|
||||
$container->alias(Update::class, 'Joomla.Power.Update')
|
||||
->share('Joomla.Power.Update', [$this, 'getUpdate'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Powers
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Powers
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getPowers(Container $container): Powers
|
||||
{
|
||||
return new Powers(
|
||||
$container->get('Config'),
|
||||
$container->get('Placeholder'),
|
||||
$container->get('Customcode'),
|
||||
$container->get('Customcode.Gui'),
|
||||
$container->get('Joomlapower')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Superpower
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Superpower
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getSuperpower(Container $container): Superpower
|
||||
{
|
||||
return new Superpower(
|
||||
$container->get('Joomla.Power.Grep'),
|
||||
$container->get('Joomla.Power.Insert'),
|
||||
$container->get('Joomla.Power.Update')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Grep
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Grep
|
||||
* @since 3.2.0
|
||||
*/
|
||||
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')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Extractor
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Extractor
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getExtractor(Container $container): Extractor
|
||||
{
|
||||
return new Extractor(
|
||||
$container->get('Config')->joomla_version
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Injector
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Injector
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInjector(Container $container): Injector
|
||||
{
|
||||
return new Injector(
|
||||
$container->get('Joomla.Power'),
|
||||
$container->get('Joomla.Power.Extractor'),
|
||||
$container->get('Power.Parser'),
|
||||
$container->get('Placeholder')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Model Upsert
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Upsert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getModelUpsert(Container $container): Upsert
|
||||
{
|
||||
return new Upsert(
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Insert
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert(
|
||||
$container->get('Joomla.Power.Model.Upsert'),
|
||||
$container->get('Insert')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power Update
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Update
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpdate(Container $container): Update
|
||||
{
|
||||
return new Update(
|
||||
$container->get('Joomla.Power.Model.Upsert'),
|
||||
$container->get('Update')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -62,7 +62,7 @@ class Placeholder implements ServiceProviderInterface
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Worker
|
||||
* @return Reverse
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getPlaceholderReverse(Container $container): Reverse
|
||||
@@ -72,7 +72,8 @@ class Placeholder implements ServiceProviderInterface
|
||||
$container->get('Placeholder'),
|
||||
$container->get('Language'),
|
||||
$container->get('Language.Extractor'),
|
||||
$container->get('Power.Extractor')
|
||||
$container->get('Power.Extractor'),
|
||||
$container->get('Joomla.Power.Extractor')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user