update 2023-04-30 01:34:12

This commit is contained in:
Robot 2023-04-30 01:34:15 +02:00
parent 7e95825bee
commit 677b8ace35
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
66 changed files with 4747 additions and 271 deletions

116
README.md
View File

@ -48,6 +48,8 @@ This repository contains an index (see below) of all the approved powers within
- **Namespace**: [VDM\Joomla\Componentbuilder\Power](#vdm-joomla-componentbuilder-power)
- **final class Grep** | [Details](src/6784dd52-0909-451a-a872-9a942a023c68) | [Code](src/6784dd52-0909-451a-a872-9a942a023c68/code.php) | [Settings](src/6784dd52-0909-451a-a872-9a942a023c68/settings.json) | [6784dd52-0909-451a-a872-9a942a023c68](src/6784dd52-0909-451a-a872-9a942a023c68)
- **final class Model** | [Details](src/7c1fb50f-8fb1-4627-8705-6fedf7182ca5) | [Code](src/7c1fb50f-8fb1-4627-8705-6fedf7182ca5/code.php) | [Settings](src/7c1fb50f-8fb1-4627-8705-6fedf7182ca5/settings.json) | [7c1fb50f-8fb1-4627-8705-6fedf7182ca5](src/7c1fb50f-8fb1-4627-8705-6fedf7182ca5)
- **final class Super** | [Details](src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff) | [Code](src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff/code.php) | [Settings](src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff/settings.json) | [3ab0eba9-f37b-4b37-aec1-2e78067f2aff](src/3ab0eba9-f37b-4b37-aec1-2e78067f2aff)
- **Namespace**: [VDM\Joomla\Componentbuilder\Utilities](#vdm-joomla-componentbuilder-utilities)
- **class Constantpaths** | [Details](src/e0c8c931-52a0-4171-9909-e8769505bb1f) | [Code](src/e0c8c931-52a0-4171-9909-e8769505bb1f/code.php) | [Settings](src/e0c8c931-52a0-4171-9909-e8769505bb1f/settings.json) | [e0c8c931-52a0-4171-9909-e8769505bb1f](src/e0c8c931-52a0-4171-9909-e8769505bb1f)
@ -163,6 +165,8 @@ This repository contains an index (see below) of all the approved powers within
- **class Reverse** | [Details](src/ca111518-e47c-4049-b1b2-cb010f23866f) | [Code](src/ca111518-e47c-4049-b1b2-cb010f23866f/code.php) | [Settings](src/ca111518-e47c-4049-b1b2-cb010f23866f/settings.json) | [ca111518-e47c-4049-b1b2-cb010f23866f](src/ca111518-e47c-4049-b1b2-cb010f23866f)
- **Namespace**: [VDM\Joomla\Componentbuilder\Compiler\Power](#vdm-joomla-componentbuilder-compiler-power)
- **final class Extractor** | [Details](src/eeb03266-22fd-45bb-953a-961bb6be3a54) | [Code](src/eeb03266-22fd-45bb-953a-961bb6be3a54/code.php) | [Settings](src/eeb03266-22fd-45bb-953a-961bb6be3a54/settings.json) | [eeb03266-22fd-45bb-953a-961bb6be3a54](src/eeb03266-22fd-45bb-953a-961bb6be3a54)
- **final class Injector** | [Details](src/763d137c-42bc-4282-98d8-cc5c0654985f) | [Code](src/763d137c-42bc-4282-98d8-cc5c0654985f/code.php) | [Settings](src/763d137c-42bc-4282-98d8-cc5c0654985f/settings.json) | [763d137c-42bc-4282-98d8-cc5c0654985f](src/763d137c-42bc-4282-98d8-cc5c0654985f)
- **final class Parser** | [Details](src/95d0e03f-24fd-4412-bc2e-f0899fcc3205) | [Code](src/95d0e03f-24fd-4412-bc2e-f0899fcc3205/code.php) | [Settings](src/95d0e03f-24fd-4412-bc2e-f0899fcc3205/settings.json) | [95d0e03f-24fd-4412-bc2e-f0899fcc3205](src/95d0e03f-24fd-4412-bc2e-f0899fcc3205)
- **class Autoloader** | [Details](src/6e64917c-d687-4ef3-a655-811319f5a81e) | [Code](src/6e64917c-d687-4ef3-a655-811319f5a81e/code.php) | [Settings](src/6e64917c-d687-4ef3-a655-811319f5a81e/settings.json) | [6e64917c-d687-4ef3-a655-811319f5a81e](src/6e64917c-d687-4ef3-a655-811319f5a81e)
- **class Infusion** | [Details](src/0419081e-4cb3-4c65-8c6a-ffe941fb0f1c) | [Code](src/0419081e-4cb3-4c65-8c6a-ffe941fb0f1c/code.php) | [Settings](src/0419081e-4cb3-4c65-8c6a-ffe941fb0f1c/settings.json) | [0419081e-4cb3-4c65-8c6a-ffe941fb0f1c](src/0419081e-4cb3-4c65-8c6a-ffe941fb0f1c)
@ -208,6 +212,10 @@ This repository contains an index (see below) of all the approved powers within
- **class Pathfix** | [Details](src/cdc9b06d-8333-4fa7-ab4d-b810dd90f95f) | [Code](src/cdc9b06d-8333-4fa7-ab4d-b810dd90f95f/code.php) | [Settings](src/cdc9b06d-8333-4fa7-ab4d-b810dd90f95f/settings.json) | [cdc9b06d-8333-4fa7-ab4d-b810dd90f95f](src/cdc9b06d-8333-4fa7-ab4d-b810dd90f95f)
- **class Paths** | [Details](src/6f20369a-8536-4870-a1a3-cda254c939c8) | [Code](src/6f20369a-8536-4870-a1a3-cda254c939c8/code.php) | [Settings](src/6f20369a-8536-4870-a1a3-cda254c939c8/settings.json) | [6f20369a-8536-4870-a1a3-cda254c939c8](src/6f20369a-8536-4870-a1a3-cda254c939c8)
- **class Structure** | [Details](src/1efdded5-d6c8-452c-8f37-0374483a7b3f) | [Code](src/1efdded5-d6c8-452c-8f37-0374483a7b3f/code.php) | [Settings](src/1efdded5-d6c8-452c-8f37-0374483a7b3f/settings.json) | [1efdded5-d6c8-452c-8f37-0374483a7b3f](src/1efdded5-d6c8-452c-8f37-0374483a7b3f)
- **Namespace**: [VDM\Joomla\Componentbuilder\Power\Database](#vdm-joomla-componentbuilder-power-database)
- **final class Insert** | [Details](src/380bb7a3-cdcc-4336-a699-5070cbf521a5) | [Code](src/380bb7a3-cdcc-4336-a699-5070cbf521a5/code.php) | [Settings](src/380bb7a3-cdcc-4336-a699-5070cbf521a5/settings.json) | [380bb7a3-cdcc-4336-a699-5070cbf521a5](src/380bb7a3-cdcc-4336-a699-5070cbf521a5)
- **final class Update** | [Details](src/e543c123-b1d9-4a0b-83b2-a9d371da5ff3) | [Code](src/e543c123-b1d9-4a0b-83b2-a9d371da5ff3/code.php) | [Settings](src/e543c123-b1d9-4a0b-83b2-a9d371da5ff3/settings.json) | [e543c123-b1d9-4a0b-83b2-a9d371da5ff3](src/e543c123-b1d9-4a0b-83b2-a9d371da5ff3)
- **Namespace**: [VDM\Joomla\Componentbuilder\Compiler\Builder\Update](#vdm-joomla-componentbuilder-compiler-builder-update)
- **class Mysql** | [Details](src/2b5c9989-1d4e-4f59-8b95-5cd2f72f82d9) | [Code](src/2b5c9989-1d4e-4f59-8b95-5cd2f72f82d9/code.php) | [Settings](src/2b5c9989-1d4e-4f59-8b95-5cd2f72f82d9/settings.json) | [2b5c9989-1d4e-4f59-8b95-5cd2f72f82d9](src/2b5c9989-1d4e-4f59-8b95-5cd2f72f82d9)
@ -346,6 +354,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler #Olive {
# Config $config
# Placeholder $placeholder
# Extractor $extractor
# Power $power
# External $external
# $db
+ __construct()
@ -412,10 +421,12 @@ namespace VDM\Joomla\Componentbuilder\Compiler #Olive {
+ array $superpowers
# string $fixUrl
# array $state
# array $retry
# Config $config
# Placeholder $placeholder
# Customcode $customcode
# Gui $gui
# Superpower $superpower
# \JDatabaseDriver $db
# CMSApplication $app
+ __construct()
@ -546,6 +557,25 @@ namespace VDM\Joomla\Componentbuilder\Power #Olive {
- localIndex() : void
- remoteIndex() : void
- loadRemoteFile() : mixed
- getFunctionName() : ?string
}
class Model << (F,LightGreen) >> #Green {
+ value() : mixed
# validateBefore() : bool
# validateAfter() : bool
# getTable() : string
}
class Super << (F,LightGreen) >> #Green {
# Grep $grep
# Insert $insert
# Update $update
+ __construct()
+ load() : bool
- insert() : bool
- update() : bool
- action() : string
}
}
@ -803,6 +833,8 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Customcode #LightGreen {
+ __construct()
+ set() : bool
+ get() : mixed
# initHub() : void
# setHub() : void
}
class External #Gold {
@ -848,6 +880,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Customcode #LightGreen {
class Gui #Gold {
# Config $config
# Reverse $reverse
# Parser $parser
# \JDatabaseDriver $db
# CMSApplication $app
+ __construct()
@ -1588,9 +1621,14 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Placeholder #LightGreen {
# Placeholder $placeholder
# Language $language
# Extractor $extractor
# Power $power
+ __construct()
+ engine() : string
# setReverse() : string
# reverseSuperPowers() : string
# getReversePower() : ?array
# reverseLanguage() : string
# reverseCustomCode() : string
}
}
@ -1606,10 +1644,46 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Placeholder #LightGreen {
namespace VDM\Joomla\Componentbuilder\Compiler\Power #LightGreen {
class Extractor << (F,LightGreen) >> #Green {
# array $powers
# \JDatabaseDriver $db
+ __construct()
+ get_() : ?array
+ get() : ?array
+ reverse() : ?array
+ search() : void
# load() : void
# map() : ?array
# filter() : ?array
# namespaces() : ?array
}
class Injector << (F,LightGreen) >> #Green {
# Power $power
# Extractor $extractor
# Parser $parser
# Placeholder $placeholder
# array $map
# array $useStatements
# array $traits
+ __construct()
+ power() : string
# update() : string
# inspect() : ?string
# getName() : ?string
# getUniqueName() : string
# removeLastSpace() : string
# addUseStatements() : string
# addLines() : string
# addLinesAfterDefinedLine() : string
}
class Parser << (F,LightGreen) >> #Green {
+ code() : array
+ getClassCode() : ?string
+ getClassLicense() : ?string
+ getUseStatements() : ?array
+ getTraits() : ?array
- properties() : ?array
- methods() : ?array
- extractDocBlock() : ?string
@ -1766,6 +1840,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service #LightGreen {
+ register() : void
+ getLoad() : Load
+ getInsert() : Insert
+ getUpdate() : Update
}
class Event #Gold {
@ -1885,6 +1960,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service #LightGreen {
class Power #Gold {
+ register() : void
+ getPowers() : Powers
+ getSuperpower() : Superpower
+ getGrep() : Grep
+ getAutoloader() : Autoloader
+ getInfusion() : Infusion
@ -1893,6 +1969,11 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service #LightGreen {
+ getPlantuml() : Plantuml
+ getRepoReadme() : RepoReadme
+ getReposReadme() : ReposReadme
+ getExtractor() : Extractor
+ getInjector() : Injector
+ getModel() : Model
+ getInsert() : Insert
+ getUpdate() : Update
}
class Templatelayout #Gold {
@ -2073,6 +2154,41 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Utilities #LightGreen {
}
@enduml
```
## VDM Joomla Componentbuilder Power Database
> namespace VDM\Joomla\Componentbuilder\Power\Database
```uml
@startuml
namespace VDM\Joomla\Componentbuilder\Power\Database #LightGreen {
class Insert << (F,LightGreen) >> #Green {
# Model $model
# Database $database
+ __construct()
+ value() : bool
+ row() : bool
+ rows() : bool
+ item() : bool
+ items() : bool
}
class Update << (F,LightGreen) >> #Green {
# Model $model
# Database $database
+ __construct()
+ value() : bool
+ row() : bool
+ rows() : bool
+ item() : bool
+ items() : bool
}
}
@enduml
```

View File

@ -124,7 +124,7 @@ class Readme
foreach ($powers as $guid => $power)
{
$power_object = $this->power->get($guid);
if (is_array($power_object->parsed_class_code))
if (isset($power_object->parsed_class_code) && is_array($power_object->parsed_class_code))
{
// add to the sort bucket
$classes[] = [
@ -232,7 +232,9 @@ class Readme
return [
'interface' => 1,
'abstract' => 2,
'abstract class' => 2,
'final' => 3,
'final class' => 3,
'class' => 4,
'trait' => 5
];

View File

@ -99,7 +99,7 @@
foreach ($powers as $guid => $power)
{
$power_object = $this->power->get($guid);
if (is_array($power_object->parsed_class_code))
if (isset($power_object->parsed_class_code) && is_array($power_object->parsed_class_code))
{
// add to the sort bucket
$classes[] = [
@ -207,7 +207,9 @@
return [
'interface' => 1,
'abstract' => 2,
'abstract class' => 2,
'final' => 3,
'final class' => 3,
'class' => 4,
'trait' => 5
];

View File

@ -13,6 +13,7 @@
class Gui #Gold {
# Config $config
# Reverse $reverse
# Parser $parser
# \JDatabaseDriver $db
# CMSApplication $app
+ __construct(?Config $config = null, ?Reverse $reverse = null, ...)
@ -29,6 +30,7 @@ note right of Gui::__construct
arguments:
?Config $config = null
?Reverse $reverse = null
?Parser $parser = null
?\JDatabaseDriver $db = null
?CMSApplication $app = null
end note

View File

@ -23,6 +23,7 @@ use VDM\Joomla\Utilities\String\FieldHelper;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder\Reverse;
use VDM\Joomla\Componentbuilder\Compiler\Power\Parser;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode\GuiInterface;
@ -49,6 +50,14 @@ class Gui implements GuiInterface
**/
protected Reverse $reverse;
/**
* Compiler Powers Parser
*
* @var Parser
* @since 3.2.0
**/
protected Parser $parser;
/**
* Database object to query local DB
*
@ -70,17 +79,19 @@ class Gui implements GuiInterface
*
* @param Config|null $config The compiler config object.
* @param Reverse|null $reverse The compiler placeholder reverse object.
* @param Parser|null $parser The powers parser object.
* @param \JDatabaseDriver|null $db The Database Driver object.
* @param CMSApplication|null $app The CMS Application object.
*
* @throws \Exception
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Reverse $reverse = null,
public function __construct(?Config $config = null, ?Reverse $reverse = null, ?Parser $parser = null,
?\JDatabaseDriver $db = null, ?CMSApplication $app = null)
{
$this->config = $config ?: Compiler::_('Config');
$this->reverse = $reverse ?: Compiler::_('Placeholder.Reverse');
$this->parser = $parser ?: Compiler::_('Power.Parser');
$this->db = $db ?: Factory::getDbo();
$this->app = $app ?: Factory::getApplication();
}
@ -181,15 +192,18 @@ class Gui implements GuiInterface
public function search(string &$file, array &$placeholders, string &$today, string &$target)
{
// get file content
$file_conent = FileHelper::getContent($file);
$file_content = FileHelper::getContent($file);
// get the USE statements (to reverse engineer super power keys)
$use_statements = $this->parser->getUseStatements($file_content);
$guiCode = [];
// we add a new search for the GUI CODE Blocks
$guiCode[] = GetHelper::allBetween(
$file_conent, '/***[JCB' . 'GUI<>', '/***[/JCBGUI' . '$$$$]***/'
$file_content, '/***[JCB' . 'GUI<>', '/***[/JCBGUI' . '$$$$]***/'
);
$guiCode[] = GetHelper::allBetween(
$file_conent, '<!--[JCB' . 'GUI<>', '<!--[/JCBGUI' . '$$$$]-->'
$file_content, '<!--[JCB' . 'GUI<>', '<!--[/JCBGUI' . '$$$$]-->'
);
if (($guiCode = ArrayHelper::merge($guiCode)) !== false
@ -214,7 +228,7 @@ class Gui implements GuiInterface
$table = StringHelper::safe($query[0]);
// reverse placeholder as much as we can
$code = $this->reverse->engine(
$code, $placeholders, $target, $id, $field, $table
$code, $placeholders, $target, $id, $field, $table, $use_statements
);
// update the GUI/Tables/Database
$object = new \stdClass();

View File

@ -14,6 +14,14 @@
**/
protected Reverse $reverse;
/**
* Compiler Powers Parser
*
* @var Parser
* @since 3.2.0
**/
protected Parser $parser;
/**
* Database object to query local DB
*
@ -35,17 +43,19 @@
*
* @param Config|null $config The compiler config object.
* @param Reverse|null $reverse The compiler placeholder reverse object.
* @param Parser|null $parser The powers parser object.
* @param \JDatabaseDriver|null $db The Database Driver object.
* @param CMSApplication|null $app The CMS Application object.
*
* @throws \Exception
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Reverse $reverse = null,
public function __construct(?Config $config = null, ?Reverse $reverse = null, ?Parser $parser = null,
?\JDatabaseDriver $db = null, ?CMSApplication $app = null)
{
$this->config = $config ?: Compiler::_('Config');
$this->reverse = $reverse ?: Compiler::_('Placeholder.Reverse');
$this->parser = $parser ?: Compiler::_('Power.Parser');
$this->db = $db ?: Factory::getDbo();
$this->app = $app ?: Factory::getApplication();
}
@ -146,15 +156,18 @@
public function search(string &$file, array &$placeholders, string &$today, string &$target)
{
// get file content
$file_conent = FileHelper::getContent($file);
$file_content = FileHelper::getContent($file);
// get the USE statements (to reverse engineer super power keys)
$use_statements = $this->parser->getUseStatements($file_content);
$guiCode = [];
// we add a new search for the GUI CODE Blocks
$guiCode[] = GetHelper::allBetween(
$file_conent, '/***[JCB' . 'GUI<>', '/***[/JCBGUI' . '$$$$]***/'
$file_content, '/***[JCB' . 'GUI<>', '/***[/JCBGUI' . '$$$$]***/'
);
$guiCode[] = GetHelper::allBetween(
$file_conent, '<!--[JCB' . 'GUI<>', '<!--[/JCBGUI' . '$$$$]-->'
$file_content, '<!--[JCB' . 'GUI<>', '<!--[/JCBGUI' . '$$$$]-->'
);
if (($guiCode = ArrayHelper::merge($guiCode)) !== false
@ -179,7 +192,7 @@
$table = StringHelper::safe($query[0]);
// reverse placeholder as much as we can
$code = $this->reverse->engine(
$code, $placeholders, $target, $id, $field, $table
$code, $placeholders, $target, $id, $field, $table, $use_statements
);
// update the GUI/Tables/Database
$object = new \stdClass();

View File

@ -43,6 +43,10 @@
"use_selection7": {
"use": "ca111518-e47c-4049-b1b2-cb010f23866f",
"as": "default"
},
"use_selection8": {
"use": "95d0e03f-24fd-4412-bc2e-f0899fcc3205",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Compiler.Customcode.Gui",

View File

@ -71,7 +71,8 @@ class Placeholder implements ServiceProviderInterface
$container->get('Config'),
$container->get('Placeholder'),
$container->get('Language'),
$container->get('Language.Extractor')
$container->get('Language.Extractor'),
$container->get('Power.Extractor')
);
}
}

View File

@ -44,6 +44,7 @@
$container->get('Config'),
$container->get('Placeholder'),
$container->get('Language'),
$container->get('Language.Extractor')
$container->get('Language.Extractor'),
$container->get('Power.Extractor')
);
}

View File

@ -18,6 +18,7 @@ class Customcode #Gold {
# Config $config
# Placeholder $placeholder
# Extractor $extractor
# Power $power
# External $external
# $db
+ __construct(?Config $config = null, ?Placeholder $placeholder = null, ...)
@ -38,6 +39,7 @@ note right of Customcode::__construct
?Config $config = null
?Placeholder $placeholder = null
?Extractor $extractor = null
?Power $power = null
?External $external = null
?\JDatabaseDriver $db = null
end note

View File

@ -20,6 +20,7 @@ use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
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\Customcode\External;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\CustomcodeInterface;
@ -102,6 +103,14 @@ class Customcode implements CustomcodeInterface
**/
protected Extractor $extractor;
/**
* Super Power Extractor
*
* @var Power
* @since 3.2.0
**/
protected Power $power;
/**
* Compiler Custom Code External
*
@ -124,17 +133,19 @@ class Customcode implements CustomcodeInterface
* @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 External|null $external The compiler external custom code 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.
*
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Placeholder $placeholder = null,
?Extractor $extractor = null, ?External $external = null, ?\JDatabaseDriver $db = null)
?Extractor $extractor = null, ?Power $power = null, ?External $external = null, ?\JDatabaseDriver $db = null)
{
$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->db = $db ?: Factory::getDbo();
}
@ -159,6 +170,9 @@ class Customcode implements CustomcodeInterface
$this->external->set($string, $debug), $debug
)
);
// extract any found super powers
$this->power->search($string);
}
// if debug
if ($debug)
@ -276,8 +290,7 @@ class Customcode implements CustomcodeInterface
if (strpos($array[1], ',') !== false)
{
// update the function values with the custom code key placeholders (this allow the use of [] + and , in the values)
$this->data[$id]['args'][$key]
= array_map(
$this->data[$id]['args'][$key] = array_map(
fn($_key) => $this->placeholder->update(
$_key,
$this->keys
@ -288,8 +301,7 @@ class Customcode implements CustomcodeInterface
$array[1]
))
{
$this->data[$id]['args'][$key]
= [];
$this->data[$id]['args'][$key] = [];
// update the function values with the custom code key placeholders (this allow the use of [] + and , in the values)
$this->data[$id]['args'][$key][]
= $this->placeholder->update(

View File

@ -68,6 +68,14 @@
**/
protected Extractor $extractor;
/**
* Super Power Extractor
*
* @var Power
* @since 3.2.0
**/
protected Power $power;
/**
* Compiler Custom Code External
*
@ -90,17 +98,19 @@
* @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 External|null $external The compiler external custom code 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.
*
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Placeholder $placeholder = null,
?Extractor $extractor = null, ?External $external = null, ?\JDatabaseDriver $db = null)
?Extractor $extractor = null, ?Power $power = null, ?External $external = null, ?\JDatabaseDriver $db = null)
{
$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->db = $db ?: Factory::getDbo();
}
@ -125,6 +135,9 @@
$this->external->set($string, $debug), $debug
)
);
// extract any found super powers
$this->power->search($string);
}
// if debug
if ($debug)
@ -242,8 +255,7 @@
if (strpos($array[1], ',') !== false)
{
// update the function values with the custom code key placeholders (this allow the use of [] + and , in the values)
$this->data[$id]['args'][$key]
= array_map(
$this->data[$id]['args'][$key] = array_map(
fn($_key) => $this->placeholder->update(
$_key,
$this->keys
@ -254,8 +266,7 @@
$array[1]
))
{
$this->data[$id]['args'][$key]
= [];
$this->data[$id]['args'][$key] = [];
// update the function values with the custom code key placeholders (this allow the use of [] + and , in the values)
$this->data[$id]['args'][$key][]
= $this->placeholder->update(

View File

@ -41,10 +41,14 @@
"as": "default"
},
"use_selection7": {
"use": "eeb03266-22fd-45bb-953a-961bb6be3a54",
"as": "Power"
},
"use_selection8": {
"use": "1cef0266-99e2-40d8-919f-c2ce32226b0a",
"as": "default"
},
"use_selection8": {
"use_selection9": {
"use": "500f3a7f-c16d-4dd4-81b2-2df6776b5388",
"as": "default"
}

View File

@ -0,0 +1,89 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Insert (Details)
> namespace: **VDM\Joomla\Componentbuilder\Power\Database**
```uml
@startuml
class Insert << (F,LightGreen) >> #Green {
# Model $model
# Database $database
+ __construct(Model $model, Database $database)
+ value(mixed $value, string $field, ...) : bool
+ row(array $item) : bool
+ rows(?array $items) : bool
+ item(object $item) : bool
+ items(?array $items) : bool
}
note right of Insert::__construct
Constructor
since: 3.2.0
end note
note right of Insert::value
Insert a value to a given table
Example: $this->value(Value, 'value_key', 'GUID');
since: 3.2.0
return: bool
arguments:
mixed $value
string $field
string $keyValue
string $key = 'guid'
end note
note right of Insert::row
Insert single row with multiple values to a given table
Example: $this->item(Array);
since: 3.2.0
return: bool
end note
note right of Insert::rows
Insert multiple rows to a given table
Example: $this->items(Array);
since: 3.2.0
return: bool
end note
note right of Insert::item
Insert single item with multiple values to a given table
Example: $this->item(Object);
since: 3.2.0
return: bool
end note
note right of Insert::items
Insert multiple items to a given table
Example: $this->items(Array);
since: 3.2.0
return: bool
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,160 @@
<?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\Power\Database;
use VDM\Joomla\Componentbuilder\Power\Model as Model;
use VDM\Joomla\Componentbuilder\Database\Insert as Database;
/**
* Power Database Insert
*
* @since 3.2.0
*/
final class Insert
{
/**
* Model
*
* @var Model
* @since 3.2.0
*/
protected Model $model;
/**
* Database
*
* @var Database
* @since 3.2.0
*/
protected Database $database;
/**
* Constructor
*
* @param Model $model The set model object.
* @param Database $database The insert database object.
*
* @since 3.2.0
*/
public function __construct(Model $model, Database $database)
{
$this->model = $model;
$this->database = $database;
}
/**
* Insert a value to a given table
* Example: $this->value(Value, 'value_key', 'GUID');
*
* @param mixed $value The field value
* @param string $field The field key
* @param string $keyValue The key value
* @param string $key The key name
*
* @return bool
* @since 3.2.0
*/
public function value($value, string $field, string $keyValue, string $key = 'guid'): bool
{
// build the array
$item = [];
$item[$key] = $keyValue;
$item[$field] = $value;
// Insert the column of this table
return $this->row($item);
}
/**
* Insert single row with multiple values to a given table
* Example: $this->item(Array);
*
* @param array $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function row(array $item): bool
{
// check if object could be modelled
if (($item = $this->model->row($item, 'power')) !== null)
{
// Insert the column of this table
return $this->database->row($item, 'power');
}
return false;
}
/**
* Insert multiple rows to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of arrays)
*
* @return bool
* @since 3.2.0
*/
public function rows(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->rows($items, 'power')) !== null)
{
// Insert the column of this table
return $this->database->rows($items, 'power');
}
return false;
}
/**
* Insert single item with multiple values to a given table
* Example: $this->item(Object);
*
* @param object $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function item(object $item): bool
{
// check if object could be modelled
if (($item = $this->model->item($item, 'power')) !== null)
{
// Insert the column of this table
return $this->database->item($item, 'power');
}
return false;
}
/**
* Insert multiple items to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of objects)
*
* @return bool
* @since 3.2.0
*/
public function items(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->items($items, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->items($items, 'power');
}
return false;
}
}

View File

@ -0,0 +1,132 @@
/**
* Model
*
* @var Model
* @since 3.2.0
*/
protected Model $model;
/**
* Database
*
* @var Database
* @since 3.2.0
*/
protected Database $database;
/**
* Constructor
*
* @param Model $model The set model object.
* @param Database $database The insert database object.
*
* @since 3.2.0
*/
public function __construct(Model $model, Database $database)
{
$this->model = $model;
$this->database = $database;
}
/**
* Insert a value to a given table
* Example: $this->value(Value, 'value_key', 'GUID');
*
* @param mixed $value The field value
* @param string $field The field key
* @param string $keyValue The key value
* @param string $key The key name
*
* @return bool
* @since 3.2.0
*/
public function value($value, string $field, string $keyValue, string $key = 'guid'): bool
{
// build the array
$item = [];
$item[$key] = $keyValue;
$item[$field] = $value;
// Insert the column of this table
return $this->row($item);
}
/**
* Insert single row with multiple values to a given table
* Example: $this->item(Array);
*
* @param array $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function row(array $item): bool
{
// check if object could be modelled
if (($item = $this->model->row($item, 'power')) !== null)
{
// Insert the column of this table
return $this->database->row($item, 'power');
}
return false;
}
/**
* Insert multiple rows to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of arrays)
*
* @return bool
* @since 3.2.0
*/
public function rows(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->rows($items, 'power')) !== null)
{
// Insert the column of this table
return $this->database->rows($items, 'power');
}
return false;
}
/**
* Insert single item with multiple values to a given table
* Example: $this->item(Object);
*
* @param object $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function item(object $item): bool
{
// check if object could be modelled
if (($item = $this->model->item($item, 'power')) !== null)
{
// Insert the column of this table
return $this->database->item($item, 'power');
}
return false;
}
/**
* Insert multiple items to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of objects)
*
* @return bool
* @since 3.2.0
*/
public function items(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->items($items, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->items($items, 'power');
}
return false;
}

View File

@ -0,0 +1,27 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "380bb7a3-cdcc-4336-a699-5070cbf521a5",
"implements": null,
"load_selection": null,
"name": "Insert",
"power_version": "1.0.0",
"system_name": "JCB.Power.Database.Insert",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "7c1fb50f-8fb1-4627-8705-6fedf7182ca5",
"as": "Model"
},
"use_selection1": {
"use": "524eb8f6-38d4-47dc-92ad-98b94e099ac0",
"as": "Database"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Power.Database.Insert",
"description": "Power Database Insert\r\n\r\n@since 3.2.0",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,81 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Super (Details)
> namespace: **VDM\Joomla\Componentbuilder\Power**
```uml
@startuml
class Super << (F,LightGreen) >> #Green {
# Grep $grep
# Insert $insert
# Update $update
+ __construct(Grep $grep, Insert $insert, ...)
+ load(string $guid, array $order = ['remote', 'local'], ...) : bool
- insert(object $power) : bool
- update(object $power) : bool
- action(string $guid) : string
}
note right of Super::__construct
Constructor.
since: 3.2.0
arguments:
Grep $grep
Insert $insert
Update $update
end note
note right of Super::load
Load a superpower
since: 3.2.0
return: bool
arguments:
string $guid
array $order = ['remote', 'local']
?string $action = null
end note
note right of Super::insert
Insert a superpower
since: 3.2.0
return: bool
end note
note right of Super::update
Update a superpower
since: 3.2.0
return: bool
end note
note right of Super::action
Get loading action
since: 3.2.0
return: string
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,133 @@
<?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\Power;
use VDM\Joomla\Componentbuilder\Power\Database\Insert;
use VDM\Joomla\Componentbuilder\Power\Database\Update;
use VDM\Joomla\Componentbuilder\Power\Grep;
use VDM\Joomla\Utilities\GuidHelper;
/**
* Superpower of JCB
*
* @since 3.2.0
*/
final class Super
{
/**
* The Power Search Tool
*
* @var Grep
* @since 3.2.0
**/
protected Grep $grep;
/**
* Insert Data Class
*
* @var Insert
* @since 3.2.0
**/
protected Insert $insert;
/**
* Update Data Class
*
* @var Update
* @since 3.2.0
**/
protected Update $update;
/**
* Constructor.
*
* @param Grep $grep The Power Grep object.
* @param Insert $insert The Power Database Insert object.
* @param Update $update The Power Database Update object.
*
* @since 3.2.0
*/
public function __construct(Grep $grep, Insert $insert, Update $update)
{
$this->grep = $grep;
$this->insert = $insert;
$this->update = $update;
}
/**
* Load a superpower
*
* @param string $guid The global unique id of the power
* @param array $order The search order
* @param string|null $action The action to load power
*
* @return bool
* @since 3.2.0
*/
public function load(string $guid, array $order = ['remote', 'local'], ?string $action = null): bool
{
if (($power = $this->grep->get($guid, $order)) !== null &&
($action !== null || ($action = $this->action($power->guid)) !== null))
{
return method_exists($this, $action) ? $this->{$action}($power) : false;
}
return false;
}
/**
* Insert a superpower
*
* @param object $power The power
*
* @return bool
* @since 3.2.0
*/
private function insert(object $power): bool
{
return $this->insert->item($power);
}
/**
* Update a superpower
*
* @param object $power The power
*
* @return bool
* @since 3.2.0
*/
private function update(object $power): bool
{
return $this->update->item($power);
}
/**
* Get loading action
*
* @param string $guid The global unique id of the power
*
* @return string
* @since 3.2.0
*/
private function action(string $guid): string
{
if (($id = GuidHelper::item($guid, 'power')) !== null && $id > 0)
{
return 'update';
}
return 'insert';
}
}

View File

@ -0,0 +1,104 @@
/**
* The Power Search Tool
*
* @var Grep
* @since 3.2.0
**/
protected Grep $grep;
/**
* Insert Data Class
*
* @var Insert
* @since 3.2.0
**/
protected Insert $insert;
/**
* Update Data Class
*
* @var Update
* @since 3.2.0
**/
protected Update $update;
/**
* Constructor.
*
* @param Grep $grep The Power Grep object.
* @param Insert $insert The Power Database Insert object.
* @param Update $update The Power Database Update object.
*
* @since 3.2.0
*/
public function __construct(Grep $grep, Insert $insert, Update $update)
{
$this->grep = $grep;
$this->insert = $insert;
$this->update = $update;
}
/**
* Load a superpower
*
* @param string $guid The global unique id of the power
* @param array $order The search order
* @param string|null $action The action to load power
*
* @return bool
* @since 3.2.0
*/
public function load(string $guid, array $order = ['remote', 'local'], ?string $action = null): bool
{
if (($power = $this->grep->get($guid, $order)) !== null &&
($action !== null || ($action = $this->action($power->guid)) !== null))
{
return method_exists($this, $action) ? $this->{$action}($power) : false;
}
return false;
}
/**
* Insert a superpower
*
* @param object $power The power
*
* @return bool
* @since 3.2.0
*/
private function insert(object $power): bool
{
return $this->insert->item($power);
}
/**
* Update a superpower
*
* @param object $power The power
*
* @return bool
* @since 3.2.0
*/
private function update(object $power): bool
{
return $this->update->item($power);
}
/**
* Get loading action
*
* @param string $guid The global unique id of the power
*
* @return string
* @since 3.2.0
*/
private function action(string $guid): string
{
if (($id = GuidHelper::item($guid, 'power')) !== null && $id > 0)
{
return 'update';
}
return 'insert';
}

View File

@ -0,0 +1,35 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "3ab0eba9-f37b-4b37-aec1-2e78067f2aff",
"implements": null,
"load_selection": null,
"name": "Super",
"power_version": "1.0.0",
"system_name": "JCB.Power.Super",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "380bb7a3-cdcc-4336-a699-5070cbf521a5",
"as": "default"
},
"use_selection1": {
"use": "e543c123-b1d9-4a0b-83b2-a9d371da5ff3",
"as": "default"
},
"use_selection2": {
"use": "6784dd52-0909-451a-a872-9a942a023c68",
"as": "default"
},
"use_selection3": {
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Power.Super",
"description": "Superpower of JCB\r\n\r\n@since 3.2.0",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "",
"composer": ""
}

View File

@ -14,6 +14,7 @@ class Database #Gold {
+ register(Container $container) : void
+ getLoad(Container $container) : Load
+ getInsert(Container $container) : Insert
+ getUpdate(Container $container) : Update
}
note right of Database::register
@ -36,6 +37,13 @@ note right of Database::getInsert
since: 3.2.0
return: Insert
end note
note right of Database::getUpdate
Get the Core Update Database
since: 3.2.0
return: Update
end note
@enduml
```

View File

@ -16,6 +16,7 @@ use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Database\Load;
use VDM\Joomla\Componentbuilder\Database\Insert;
use VDM\Joomla\Componentbuilder\Database\Update;
/**
@ -40,6 +41,9 @@ class Database implements ServiceProviderInterface
$container->alias(Insert::class, 'Insert')
->share('Insert', [$this, 'getInsert'], true);
$container->alias(Update::class, 'Update')
->share('Update', [$this, 'getUpdate'], true);
}
/**
@ -67,6 +71,18 @@ class Database implements ServiceProviderInterface
{
return new Insert();
}
/**
* Get the Core Update Database
*
* @param Container $container The DI container.
*
* @return Update
* @since 3.2.0
*/
public function getUpdate(Container $container): Update
{
return new Update();
}
}

View File

@ -13,6 +13,9 @@
$container->alias(Insert::class, 'Insert')
->share('Insert', [$this, 'getInsert'], true);
$container->alias(Update::class, 'Update')
->share('Update', [$this, 'getUpdate'], true);
}
/**
@ -40,3 +43,16 @@
{
return new Insert();
}
/**
* Get the Core Update Database
*
* @param Container $container The DI container.
*
* @return Update
* @since 3.2.0
*/
public function getUpdate(Container $container): Update
{
return new Update();
}

View File

@ -19,6 +19,10 @@
"use_selection1": {
"use": "524eb8f6-38d4-47dc-92ad-98b94e099ac0",
"as": "default"
},
"use_selection2": {
"use": "cce56585-58b0-4f72-a92c-e2635ea52d83",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Compiler.Service.Database",

View File

@ -16,7 +16,7 @@ class Grep << (F,LightGreen) >> #Green {
# Contents $contents
# CMSApplication $app
+ __construct(string $path, array $paths, ...)
+ get(string $guid, array $order = ['Local', 'Remote']) : ?object
+ get(string $guid, array $order = ['local', 'remote']) : ?object
- searchLocal(string $guid) : ?object
- searchRemote(string $guid) : ?object
- getLocal(object $path, string $guid) : ?object
@ -25,6 +25,7 @@ class Grep << (F,LightGreen) >> #Green {
- localIndex(object $path) : void
- remoteIndex(object $path) : void
- loadRemoteFile(string $owner, string $repo, ...) : mixed
- getFunctionName(string $name) : ?string
}
note right of Grep::__construct
@ -107,6 +108,13 @@ note left of Grep::loadRemoteFile
string $path
?string $branch
end note
note right of Grep::getFunctionName
Get function name
since: 3.2.0
return: ?string
end note
@enduml
```

View File

@ -22,11 +22,12 @@ use VDM\Joomla\Utilities\JsonHelper;
/**
* Power Grep
* 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
* 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.0
*/
@ -35,7 +36,7 @@ final class Grep
/**
* The local path
*
* @var array
* @var string
* @since 3.2.0
**/
public string $path;
@ -67,10 +68,10 @@ final class Grep
/**
* Constructor.
*
* @param string $path The the local path
* @param array $paths The the approved paths
* @param Contents $contents The Gitea Repository Contents object.
* @param CMSApplication|null $app The CMS Application object.
* @param string $path The local path
* @param array $paths The approved paths
* @param Contents $contents The Gitea Repository Contents object.
* @param CMSApplication|null $app The CMS Application object.
*
* @throws \Exception
* @since 3.2.0
@ -88,20 +89,21 @@ final class Grep
/**
* Get a power
*
* @param string $guid The global unique id of the power
* @param array $order The search order
* @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, $order = ['Local', 'Remote']): ?object
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 !== [])
{
foreach ($order as $target)
{
if (($power = $this->{'search' . $target}($guid)) !== null)
if (($function_name = $this->getFunctionName($target)) !== null &&
($power = $this->{$function_name}($guid)) !== null)
{
return $power;
}
@ -367,6 +369,20 @@ final class Grep
return $data;
}
/**
* Get function name
*
* @param string $name The targeted function name
*
* @return string|null
* @since 3.2.0
*/
private function getFunctionName(string $name): ?string
{
$function_name = 'search' . ucfirst(strtolower($name));
return method_exists($this, $function_name) ? $function_name : null;
}
}

View File

@ -1,7 +1,7 @@
/**
* The local path
*
* @var array
* @var string
* @since 3.2.0
**/
public string $path;
@ -33,10 +33,10 @@
/**
* Constructor.
*
* @param string $path The the local path
* @param array $paths The the approved paths
* @param Contents $contents The Gitea Repository Contents object.
* @param CMSApplication|null $app The CMS Application object.
* @param string $path The local path
* @param array $paths The approved paths
* @param Contents $contents The Gitea Repository Contents object.
* @param CMSApplication|null $app The CMS Application object.
*
* @throws \Exception
* @since 3.2.0
@ -54,20 +54,21 @@
/**
* Get a power
*
* @param string $guid The global unique id of the power
* @param array $order The search order
* @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, $order = ['Local', 'Remote']): ?object
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 !== [])
{
foreach ($order as $target)
{
if (($power = $this->{'search' . $target}($guid)) !== null)
if (($function_name = $this->getFunctionName($target)) !== null &&
($power = $this->{$function_name}($guid)) !== null)
{
return $power;
}
@ -333,3 +334,18 @@
return $data;
}
/**
* Get function name
*
* @param string $name The targeted function name
*
* @return string|null
* @since 3.2.0
*/
private function getFunctionName(string $name): ?string
{
$function_name = 'search' . ucfirst(strtolower($name));
return method_exists($this, $function_name) ? $function_name : null;
}

View File

@ -24,7 +24,7 @@
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Power.Grep",
"description": "Power Grep\r\n The Grep feature will try to find your power in the repositories listed in the global\r\n Options of JCB in the super powers tab, and if it can't be found there will try the global core\r\n Super powers of JCB. All searches are performed according the the [algorithm:cascading]\r\n See documentation for more details: https:\/\/git.vdm.dev\/joomla\/super-powers\/wiki\r\n\r\n@since 3.2.0",
"description": "Global Resource Empowerment Platform\r\n\r\n The Grep feature will try to find your power in the repositories listed in the global\r\n Options of JCB in the super powers tab, and if it can't be found there will try the global core\r\n Super powers of JCB. All searches are performed according the the [algorithm:cascading]\r\n See documentation for more details: https:\/\/git.vdm.dev\/joomla\/super-powers\/wiki\r\n\r\n@since 3.2.0",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "use Joomla\\CMS\\Factory;\r\nuse Joomla\\CMS\\Filesystem\\Folder;\r\nuse Joomla\\CMS\\Application\\CMSApplication;\r\nuse Joomla\\CMS\\Language\\Text;",
"composer": ""

View File

@ -0,0 +1,131 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Injector (Details)
> namespace: **VDM\Joomla\Componentbuilder\Compiler\Power**
```uml
@startuml
class Injector << (F,LightGreen) >> #Green {
# Power $power
# Extractor $extractor
# Parser $parser
# Placeholder $placeholder
# array $map
# array $useStatements
# array $traits
+ __construct(?Power $power = null, ?Extractor $extractor = null, ...)
+ power(string $code) : string
# update(array $guids, string $code) : string
# inspect(object $power, ?array $useStatements, ...) : ?string
# getName(string $useStatement) : ?string
# getUniqueName(string $name, string $namespace, ...) : string
# removeLastSpace(string $namespace) : string
# addUseStatements(string $code, ?array $useStatements) : string
# addLines(string $code, string $lines) : string
# addLinesAfterDefinedLine(string $code, string $lines) : string
}
note right of Injector::__construct
Constructor.
since: 3.2.0
arguments:
?Power $power = null
?Extractor $extractor = null
?Parser $parser = null
?Placeholder $placeholder = null
end note
note left of Injector::power
Inject the powers found in the code
since: 3.2.0
return: string
end note
note right of Injector::update
Update the code
since: 3.2.0
return: string
end note
note left of Injector::inspect
inspect the super power
since: 3.2.0
return: ?string
arguments:
object $power
?array $useStatements
?array $traits
end note
note right of Injector::getName
Extracts the class name from a use statement.
since: 3.2.0
return: ?string
end note
note left of Injector::getUniqueName
Removes the last space from the namespace.
since: 3.2.0
return: string
arguments:
string $name
string $namespace
array $useOther
end note
note right of Injector::removeLastSpace
Removes the last space from the namespace.
since: 3.2.0
return: string
end note
note left of Injector::addUseStatements
Insert a line before the class declaration in the given class code.
since: 3.2.0
return: string
end note
note right of Injector::addLines
Insert a line before the class declaration in the given class code.
since: 3.2.0
return: string
end note
note left of Injector::addLinesAfterDefinedLine
Inserts a new line after the defined('_JEXEC') line.
since: 3.2.0
return: string
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,481 @@
<?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\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\Power\Parser;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
/**
* Compiler Power Injector
* @since 3.2.0
*/
final class Injector
{
/**
* Power Objects
*
* @var Power
* @since 3.2.0
**/
protected Power $power;
/**
* Compiler Powers Extractor
*
* @var Extractor
* @since 3.2.0
**/
protected Extractor $extractor;
/**
* Compiler Powers Parser
*
* @var Parser
* @since 3.2.0
**/
protected Parser $parser;
/**
* Compiler Placeholder
*
* @var Placeholder
* @since 3.2.0
*/
protected Placeholder $placeholder;
/**
* Super Power Update Map
*
* @var array
* @since 3.2.0
*/
protected array $map = [];
/**
* Insert Use Statements
*
* @var array
* @since 3.2.0
*/
protected array $useStatements = [];
/**
* Insert Trait Statements
*
* @var array
* @since 3.2.0
*/
protected array $traits = [];
/**
* Constructor.
*
* @param Power|null $power The power object.
* @param Extractor|null $extractor The powers extractor object.
* @param Parser|null $parser The powers parser object.
* @param Placeholder|null $placeholder The compiler placeholder object.
*
* @since 3.2.0
*/
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');
}
/**
* 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
{
if (($guids = $this->extractor->get($code)) !== null)
{
return $this->update($guids, $code);
}
return $code;
}
/**
* Update the code
*
* @param array $guids The Power guids found
* @param string $code The class code
*
* @return string The updated code
* @since 3.2.0
*/
protected function update(array $guids, string $code): string
{
$use_statements = $this->parser->getUseStatements($code);
$traits = $this->parser->getTraits(
$this->parser->getClassCode($code) ?? ''
);
// reset with each file
$this->map = [];
$this->useStatements = [];
$this->traits = [];
foreach ($guids as $key => $guid)
{
if (($power = $this->power->get($guid)) !== null)
{
if (($name = $this->inspect($power, $use_statements, $traits)) !== null)
{
$this->map[$key] = $name;
}
}
}
// update
if ($this->map !== [])
{
if ($this->useStatements !== [])
{
$code = $this->addUseStatements($code, $use_statements);
}
return $this->placeholder->update($code, $this->map);
}
return $code;
}
/**
* inspect the super power
*
* @param object|null $power The power object.
* @param array|null $useStatements The code use statments
* @param array|null $traits The code traits use statments
*
* @return string|null The class name (or as name)
* @since 3.2.0
*/
protected function inspect(object $power, ?array $useStatements, ?array $traits): ?string
{
if (isset($power->type) && in_array($power->type, ['class', 'abstract class', 'final class', 'trait']))
{
$statement = 'use ' . $power->_namespace . '\\' . $power->class_name;
// other class names
$use_other = [];
$trait_other = [];
// some tracker globals
$has_use_statement = false; // add if not found
$has_trait_statement = !('trait' === $power->type); // don't add if not trait
$name = null;
$trait_name = null;
// check if the name space is loaded
if ($useStatements !== null)
{
foreach ($useStatements as $use_statement)
{
if ($use_statement === $statement . ';' || strpos($use_statement, $statement . ' as ') !== false)
{
$name = $this->getName($use_statement);
$has_use_statement = true;
}
else
{
$tmp = $this->getName($use_statement);
if ($power->class_name === $tmp)
{
$use_other[$tmp] = $tmp;
}
}
}
}
// check if the trait is loaded
if (!$has_trait_statement && $traits !== null)
{
$trait_statement = $name ?? $power->class_name;
foreach ($traits as $trait)
{
if ($trait === $trait_statement)
{
$trait_name = $trait;
$has_trait_statement = true;
}
}
}
// build the name
$name = $trait_name ?? $name ?? $power->class_name;
// if we have a trait we may need to add use and trait
if ('trait' === $power->type)
{
if (!$has_trait_statement)
{
$this->traits[$name] = 'use ' . $name . ';';
}
}
// check if we need to update the name
if ($use_other !== [])
{
// set search namespace
$namespace = ($name !== $power->class_name) ? $power->_namespace . '\\' . $power->class_name : $power->_namespace;
// get the unique name
$name = $this->getUniqueName($name, $namespace, $use_other);
}
if (!$has_use_statement)
{
// if the name is not the same as class name
if ($name !== $power->class_name)
{
$statement .= ' as ' . $name . ';';
}
else
{
$statement .= ';';
}
$this->useStatements[$name] = $statement;
}
return $name;
}
return null;
}
/**
* Extracts the class name from a use statement.
*
* @param string $useStatement The use statement from which to extract the class name
*
* @return string|null The class name or null if not found
* @since 3.2.0
*/
protected function getName(string $useStatement): ?string
{
// If the input doesn't start with 'use ', assume it's a class name without a use statement
if (strpos($useStatement, 'use ') !== 0)
{
$parts = explode('\\', $useStatement);
$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;
}
$pattern = '/use\s+([\w\\\\]+)(?:\s+as\s+)?([\w]+)?;/';
if (preg_match($pattern, $useStatement, $matches))
{
// If there's an alias, return it
if (!empty($matches[2]))
{
return $matches[2];
}
// If there's no alias, extract the class name from the namespace
$parts = explode('\\', $matches[1]);
return end($parts);
}
return null;
}
/**
* Removes the last space from the namespace.
*
* @param string $name The current name
* @param string $namespace The namespace
* @param array $useOther The other use names
*
* @return string The namespace shortened
* @since 3.2.0
*/
protected function getUniqueName(string $name, string $namespace, array $useOther): string
{
// if the name is already used
while (isset($useOther[$name]))
{
if (($tmp = $this->getName($namespace)) !== null)
{
$name = ucfirst($tmp) . $name;
$namespace = $this->removeLastSpace($namespace);
}
}
return $name;
}
/**
* Removes the last space from the namespace.
*
* @param string $namespace The namespace
*
* @return string The namespace shortened
* @since 3.2.0
*/
protected function removeLastSpace(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);
}
/**
* Insert a line before the class declaration in the given class code.
*
* @param string $code The class code
* @param array|null $useStatements The existing use statements
*
* @return string The modified file content
* @since 3.2.0
*/
protected function addUseStatements(string $code, ?array $useStatements): string
{
if ($useStatements !== null)
{
// we add the use statements using existing use statements
$key = end($useStatements);
array_unshift($this->useStatements, $key);
return $this->placeholder->update($code, [$key => implode(PHP_EOL, array_values($this->useStatements))]);
}
return $this->addLines($code, implode(PHP_EOL, array_values($this->useStatements)));
}
/**
* Insert a line before the class declaration in the given class code.
*
* @param string $code The class code
* @param string $lines The new lines to insert
*
* @return string The modified file content
* @since 3.2.0
*/
protected function addLines(string $code, string $lines): string
{
// Pattern to match class, final class, abstract class, interface, and trait
$pattern = '/(?:class|final class|abstract class|interface|trait)\s+[a-zA-Z0-9_]+\s*(?:extends\s+[a-zA-Z0-9_]+\s*)?(?:implements\s+[a-zA-Z0-9_]+(?:\s*,\s*[a-zA-Z0-9_]+)*)?\s*\{/s';
// Find the position of the class declaration
preg_match($pattern, $code, $matches, PREG_OFFSET_CAPTURE);
$class_declaration_pos = $matches[0][1] ?? null;
if (null !== $class_declaration_pos)
{
// Find the position of the last newline character before the class declaration
$last_newline_pos = strrpos($code, PHP_EOL, -(strlen($code) - $class_declaration_pos));
// Find the position of the comment block right before the class declaration
$comment_pattern = '/\s*\*\/\s*$/m';
$insert_pos = null;
if (preg_match($comment_pattern, $code, $comment_matches, PREG_OFFSET_CAPTURE, 0, $last_newline_pos))
{
$insert_pos = (int) $comment_matches[0][1] + strlen($comment_matches[0][0]);
}
else
{
// Find the last empty line before the class declaration
$empty_line_pattern = '/(^|\r\n|\r|\n)[\s]*($|\r\n|\r|\n)/';
if (preg_match($empty_line_pattern, $code, $empty_line_matches, PREG_OFFSET_CAPTURE, 0, $last_newline_pos))
{
$insert_pos = (int) $empty_line_matches[0][1] + strlen($empty_line_matches[0][0]);
}
}
// Insert the new line at the found position
if (null !== $insert_pos)
{
return substr_replace($code, $lines . PHP_EOL, $insert_pos, 0);
}
}
// last try targeting the defined line
return $this->addLinesAfterDefinedLine($code, $lines);
}
/**
* Inserts a new line after the defined('_JEXEC') line.
*
* @param string $code The class code
* @param string $lines The new lines to insert
*
* @return string The modified file content
* @since 3.2.0
*/
protected function addLinesAfterDefinedLine(string $code, string $lines): string
{
// Patterns to match the defined('_JEXEC') and defined('JPATH_BASE') lines
$patterns = [
"/defined\('_JEXEC'\)(.*?)\s*;/",
"/defined\('JPATH_BASE'\)(.*?)\s*;/",
];
$insert_pos = null;
// Iterate through the patterns and try to find a match
foreach ($patterns as $pattern)
{
preg_match($pattern, $code, $matches, PREG_OFFSET_CAPTURE);
$defined_line_pos = $matches[0][1] ?? null;
if ($defined_line_pos !== null)
{
// Find the position of the newline character after the defined() line
$next_lines_pos = strpos($code, PHP_EOL, (int) $defined_line_pos + strlen($matches[0][0]));
// Insert the new line at the found position
if ($next_lines_pos !== false)
{
$insert_pos = $next_lines_pos;
break;
}
}
}
// Insert the new line at the found position
if ($insert_pos !== null)
{
$code = substr_replace($code, PHP_EOL . $lines, $insert_pos, 0);
}
return $code;
}
}

View File

@ -0,0 +1,452 @@
/**
* Power Objects
*
* @var Power
* @since 3.2.0
**/
protected Power $power;
/**
* Compiler Powers Extractor
*
* @var Extractor
* @since 3.2.0
**/
protected Extractor $extractor;
/**
* Compiler Powers Parser
*
* @var Parser
* @since 3.2.0
**/
protected Parser $parser;
/**
* Compiler Placeholder
*
* @var Placeholder
* @since 3.2.0
*/
protected Placeholder $placeholder;
/**
* Super Power Update Map
*
* @var array
* @since 3.2.0
*/
protected array $map = [];
/**
* Insert Use Statements
*
* @var array
* @since 3.2.0
*/
protected array $useStatements = [];
/**
* Insert Trait Statements
*
* @var array
* @since 3.2.0
*/
protected array $traits = [];
/**
* Constructor.
*
* @param Power|null $power The power object.
* @param Extractor|null $extractor The powers extractor object.
* @param Parser|null $parser The powers parser object.
* @param Placeholder|null $placeholder The compiler placeholder object.
*
* @since 3.2.0
*/
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');
}
/**
* 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
{
if (($guids = $this->extractor->get($code)) !== null)
{
return $this->update($guids, $code);
}
return $code;
}
/**
* Update the code
*
* @param array $guids The Power guids found
* @param string $code The class code
*
* @return string The updated code
* @since 3.2.0
*/
protected function update(array $guids, string $code): string
{
$use_statements = $this->parser->getUseStatements($code);
$traits = $this->parser->getTraits(
$this->parser->getClassCode($code) ?? ''
);
// reset with each file
$this->map = [];
$this->useStatements = [];
$this->traits = [];
foreach ($guids as $key => $guid)
{
if (($power = $this->power->get($guid)) !== null)
{
if (($name = $this->inspect($power, $use_statements, $traits)) !== null)
{
$this->map[$key] = $name;
}
}
}
// update
if ($this->map !== [])
{
if ($this->useStatements !== [])
{
$code = $this->addUseStatements($code, $use_statements);
}
return $this->placeholder->update($code, $this->map);
}
return $code;
}
/**
* inspect the super power
*
* @param object|null $power The power object.
* @param array|null $useStatements The code use statments
* @param array|null $traits The code traits use statments
*
* @return string|null The class name (or as name)
* @since 3.2.0
*/
protected function inspect(object $power, ?array $useStatements, ?array $traits): ?string
{
if (isset($power->type) && in_array($power->type, ['class', 'abstract class', 'final class', 'trait']))
{
$statement = 'use ' . $power->_namespace . '\\' . $power->class_name;
// other class names
$use_other = [];
$trait_other = [];
// some tracker globals
$has_use_statement = false; // add if not found
$has_trait_statement = !('trait' === $power->type); // don't add if not trait
$name = null;
$trait_name = null;
// check if the name space is loaded
if ($useStatements !== null)
{
foreach ($useStatements as $use_statement)
{
if ($use_statement === $statement . ';' || strpos($use_statement, $statement . ' as ') !== false)
{
$name = $this->getName($use_statement);
$has_use_statement = true;
}
else
{
$tmp = $this->getName($use_statement);
if ($power->class_name === $tmp)
{
$use_other[$tmp] = $tmp;
}
}
}
}
// check if the trait is loaded
if (!$has_trait_statement && $traits !== null)
{
$trait_statement = $name ?? $power->class_name;
foreach ($traits as $trait)
{
if ($trait === $trait_statement)
{
$trait_name = $trait;
$has_trait_statement = true;
}
}
}
// build the name
$name = $trait_name ?? $name ?? $power->class_name;
// if we have a trait we may need to add use and trait
if ('trait' === $power->type)
{
if (!$has_trait_statement)
{
$this->traits[$name] = 'use ' . $name . ';';
}
}
// check if we need to update the name
if ($use_other !== [])
{
// set search namespace
$namespace = ($name !== $power->class_name) ? $power->_namespace . '\\' . $power->class_name : $power->_namespace;
// get the unique name
$name = $this->getUniqueName($name, $namespace, $use_other);
}
if (!$has_use_statement)
{
// if the name is not the same as class name
if ($name !== $power->class_name)
{
$statement .= ' as ' . $name . ';';
}
else
{
$statement .= ';';
}
$this->useStatements[$name] = $statement;
}
return $name;
}
return null;
}
/**
* Extracts the class name from a use statement.
*
* @param string $useStatement The use statement from which to extract the class name
*
* @return string|null The class name or null if not found
* @since 3.2.0
*/
protected function getName(string $useStatement): ?string
{
// If the input doesn't start with 'use ', assume it's a class name without a use statement
if (strpos($useStatement, 'use ') !== 0)
{
$parts = explode('\\', $useStatement);
$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;
}
$pattern = '/use\s+([\w\\\\]+)(?:\s+as\s+)?([\w]+)?;/';
if (preg_match($pattern, $useStatement, $matches))
{
// If there's an alias, return it
if (!empty($matches[2]))
{
return $matches[2];
}
// If there's no alias, extract the class name from the namespace
$parts = explode('\\', $matches[1]);
return end($parts);
}
return null;
}
/**
* Removes the last space from the namespace.
*
* @param string $name The current name
* @param string $namespace The namespace
* @param array $useOther The other use names
*
* @return string The namespace shortened
* @since 3.2.0
*/
protected function getUniqueName(string $name, string $namespace, array $useOther): string
{
// if the name is already used
while (isset($useOther[$name]))
{
if (($tmp = $this->getName($namespace)) !== null)
{
$name = ucfirst($tmp) . $name;
$namespace = $this->removeLastSpace($namespace);
}
}
return $name;
}
/**
* Removes the last space from the namespace.
*
* @param string $namespace The namespace
*
* @return string The namespace shortened
* @since 3.2.0
*/
protected function removeLastSpace(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);
}
/**
* Insert a line before the class declaration in the given class code.
*
* @param string $code The class code
* @param array|null $useStatements The existing use statements
*
* @return string The modified file content
* @since 3.2.0
*/
protected function addUseStatements(string $code, ?array $useStatements): string
{
if ($useStatements !== null)
{
// we add the use statements using existing use statements
$key = end($useStatements);
array_unshift($this->useStatements, $key);
return $this->placeholder->update($code, [$key => implode(PHP_EOL, array_values($this->useStatements))]);
}
return $this->addLines($code, implode(PHP_EOL, array_values($this->useStatements)));
}
/**
* Insert a line before the class declaration in the given class code.
*
* @param string $code The class code
* @param string $lines The new lines to insert
*
* @return string The modified file content
* @since 3.2.0
*/
protected function addLines(string $code, string $lines): string
{
// Pattern to match class, final class, abstract class, interface, and trait
$pattern = '/(?:class|final class|abstract class|interface|trait)\s+[a-zA-Z0-9_]+\s*(?:extends\s+[a-zA-Z0-9_]+\s*)?(?:implements\s+[a-zA-Z0-9_]+(?:\s*,\s*[a-zA-Z0-9_]+)*)?\s*\{/s';
// Find the position of the class declaration
preg_match($pattern, $code, $matches, PREG_OFFSET_CAPTURE);
$class_declaration_pos = $matches[0][1] ?? null;
if (null !== $class_declaration_pos)
{
// Find the position of the last newline character before the class declaration
$last_newline_pos = strrpos($code, PHP_EOL, -(strlen($code) - $class_declaration_pos));
// Find the position of the comment block right before the class declaration
$comment_pattern = '/\s*\*\/\s*$/m';
$insert_pos = null;
if (preg_match($comment_pattern, $code, $comment_matches, PREG_OFFSET_CAPTURE, 0, $last_newline_pos))
{
$insert_pos = (int) $comment_matches[0][1] + strlen($comment_matches[0][0]);
}
else
{
// Find the last empty line before the class declaration
$empty_line_pattern = '/(^|\r\n|\r|\n)[\s]*($|\r\n|\r|\n)/';
if (preg_match($empty_line_pattern, $code, $empty_line_matches, PREG_OFFSET_CAPTURE, 0, $last_newline_pos))
{
$insert_pos = (int) $empty_line_matches[0][1] + strlen($empty_line_matches[0][0]);
}
}
// Insert the new line at the found position
if (null !== $insert_pos)
{
return substr_replace($code, $lines . PHP_EOL, $insert_pos, 0);
}
}
// last try targeting the defined line
return $this->addLinesAfterDefinedLine($code, $lines);
}
/**
* Inserts a new line after the defined('_JEXEC') line.
*
* @param string $code The class code
* @param string $lines The new lines to insert
*
* @return string The modified file content
* @since 3.2.0
*/
protected function addLinesAfterDefinedLine(string $code, string $lines): string
{
// Patterns to match the defined('_JEXEC') and defined('JPATH_BASE') lines
$patterns = [
"/defined\('_JEXEC'\)(.*?)\s*;/",
"/defined\('JPATH_BASE'\)(.*?)\s*;/",
];
$insert_pos = null;
// Iterate through the patterns and try to find a match
foreach ($patterns as $pattern)
{
preg_match($pattern, $code, $matches, PREG_OFFSET_CAPTURE);
$defined_line_pos = $matches[0][1] ?? null;
if ($defined_line_pos !== null)
{
// Find the position of the newline character after the defined() line
$next_lines_pos = strpos($code, PHP_EOL, (int) $defined_line_pos + strlen($matches[0][0]));
// Insert the new line at the found position
if ($next_lines_pos !== false)
{
$insert_pos = $next_lines_pos;
break;
}
}
}
// Insert the new line at the found position
if ($insert_pos !== null)
{
$code = substr_replace($code, PHP_EOL . $lines, $insert_pos, 0);
}
return $code;
}

View File

@ -0,0 +1,39 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "763d137c-42bc-4282-98d8-cc5c0654985f",
"implements": null,
"load_selection": null,
"name": "Injector",
"power_version": "1.0.0",
"system_name": "JCB.Compiler.Power.Injector",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "d910d8b8-4c23-4f3e-8cda-438f2d2bd7ac",
"as": "Compiler"
},
"use_selection1": {
"use": "b836c1b1-b6b1-44f7-b8a2-9a763a4185b1",
"as": "default"
},
"use_selection2": {
"use": "eeb03266-22fd-45bb-953a-961bb6be3a54",
"as": "default"
},
"use_selection3": {
"use": "95d0e03f-24fd-4412-bc2e-f0899fcc3205",
"as": "default"
},
"use_selection4": {
"use": "06453ada-e370-49f0-b262-e3f5a8ed0c2c",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Compiler.Power.Injector",
"description": "Compiler Power Injector\r\n@since 3.2.0",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,77 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Model (Details)
> namespace: **VDM\Joomla\Componentbuilder\Power**
```uml
@startuml
class Model << (F,LightGreen) >> #Green {
+ value(mixed $value, string $field, ...) : mixed
# validateBefore(mixed $value, ?string $field = null, ...) : bool
# validateAfter(mixed $value, ?string $field = null, ...) : bool
# getTable() : string
}
note right of Model::value
Model the value
Example: $this->value(value, 'field_key', 'table_name');
since: 3.2.0
return: mixed
arguments:
mixed $value
string $field
?string $table = null
end note
note right of Model::validateBefore
Validate before the value is modelled
since: 3.2.0
return: bool
arguments:
mixed $value
?string $field = null
?string $table = null
end note
note right of Model::validateAfter
Validate after the value is modelled
since: 3.2.0
return: bool
arguments:
mixed $value
?string $field = null
?string $table = null
end note
note right of Model::getTable
Get the current active table
since: 3.2.0
return: string
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,119 @@
<?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\Power;
use VDM\Joomla\Componentbuilder\Abstraction\Model as AbstractionModel;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Interfaces\ModelInterface;
/**
* Power Model
*
* @since 3.2.0
*/
final class Model extends AbstractionModel implements ModelInterface
{
/**
* Model the value
* Example: $this->value(value, 'field_key', 'table_name');
*
* @param mixed $value The value to model
* @param string $field The field key
* @param string|null $table The table
*
* @return mixed
* @since 3.2.0
*/
public function value($value, string $field, ?string $table = null)
{
// set the table name
if (empty($table))
{
$table = $this->getTable();
}
// check if this is a valid table
if (($store = $this->table->get($table, $field, 'store')) !== null)
{
// open the value based on the store method
switch($store)
{
case 'base64':
$value = base64_encode((string) $value);
break;
case 'json':
$value = json_encode($value, JSON_FORCE_OBJECT);
break;
}
}
return $value;
}
/**
* Validate before the value is modelled
*
* @param mixed $value The field value
* @param string|null $field The field key
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool
{
// check values
if (StringHelper::check($value) || ArrayHelper::check($value, true) || is_numeric($value))
{
return true;
}
// remove empty values
return false;
}
/**
* Validate after the value is modelled
*
* @param mixed $value The field value
* @param string|null $field The field key
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool
{
// only strings or numbers allowed
if (StringHelper::check($value) || is_numeric($value))
{
return true;
}
// remove empty values
return false;
}
/**
* Get the current active table
*
* @return string
* @since 3.2.0
*/
protected function getTable(): string
{
return 'power';
}
}

View File

@ -0,0 +1,89 @@
/**
* Model the value
* Example: $this->value(value, 'field_key', 'table_name');
*
* @param mixed $value The value to model
* @param string $field The field key
* @param string|null $table The table
*
* @return mixed
* @since 3.2.0
*/
public function value($value, string $field, ?string $table = null)
{
// set the table name
if (empty($table))
{
$table = $this->getTable();
}
// check if this is a valid table
if (($store = $this->table->get($table, $field, 'store')) !== null)
{
// open the value based on the store method
switch($store)
{
case 'base64':
$value = base64_encode((string) $value);
break;
case 'json':
$value = json_encode($value, JSON_FORCE_OBJECT);
break;
}
}
return $value;
}
/**
* Validate before the value is modelled
*
* @param mixed $value The field value
* @param string|null $field The field key
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool
{
// check values
if (StringHelper::check($value) || ArrayHelper::check($value, true) || is_numeric($value))
{
return true;
}
// remove empty values
return false;
}
/**
* Validate after the value is modelled
*
* @param mixed $value The field value
* @param string|null $field The field key
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool
{
// only strings or numbers allowed
if (StringHelper::check($value) || is_numeric($value))
{
return true;
}
// remove empty values
return false;
}
/**
* Get the current active table
*
* @return string
* @since 3.2.0
*/
protected function getTable(): string
{
return 'power';
}

View File

@ -0,0 +1,34 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "-1",
"guid": "7c1fb50f-8fb1-4627-8705-6fedf7182ca5",
"implements": [
"8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff"
],
"load_selection": null,
"name": "Model",
"power_version": "1.0.0",
"system_name": "JCB.Power.Model",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "584747d1-3a86-453d-b7a3-a2219de8d777",
"as": "AbstractionModel"
},
"use_selection1": {
"use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef",
"as": "default"
},
"use_selection2": {
"use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Power.Model",
"description": "Power Model\r\n\r\n@since 3.2.0",
"extends_custom": "AbstractionModel",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "",
"composer": ""
}

View File

@ -14,6 +14,8 @@ class Parser << (F,LightGreen) >> #Green {
+ code(string $code) : array
+ getClassCode(string $code) : ?string
+ getClassLicense(string $code) : ?string
+ getUseStatements(string $code) : ?array
+ getTraits(string $code) : ?array
- properties(string $code) : ?array
- methods(string $code) : ?array
- extractDocBlock(string $code, string $declaration) : ?string
@ -49,6 +51,20 @@ note right of Parser::getClassLicense
return: ?string
end note
note left of Parser::getUseStatements
Extracts the first consecutive `use` statements from the given PHP class.
since: 3.2.0
return: ?array
end note
note right of Parser::getTraits
Extracts trait use statements from the given code.
since: 3.2.0
return: ?array
end note
note left of Parser::properties
Extracts properties declarations and other details from the given code.

View File

@ -117,6 +117,86 @@ final class Parser
return null;
}
/**
* Extracts the first consecutive `use` statements from the given PHP class.
*
* @param string $code The PHP class as a string
*
* @return array|null An array of consecutive `use` statements
* @since 3.2.0
*/
public function getUseStatements(string $code): ?array
{
// Match class, final class, abstract class, interface, and trait
$pattern = '/(?:class|final class|abstract class|interface|trait)\s+[a-zA-Z0-9_]+\s*(?:extends\s+[a-zA-Z0-9_]+\s*)?(?:implements\s+[a-zA-Z0-9_]+(?:\s*,\s*[a-zA-Z0-9_]+)*)?\s*\{/s';
// Split the input code based on the class declaration pattern
$parts = preg_split($pattern, $code, 2, PREG_SPLIT_DELIM_CAPTURE);
$header = $parts[0] ?? '';
$use_statements = [];
$found_first_use = false;
if ($header !== '')
{
$lines = explode(PHP_EOL, $header);
foreach ($lines as $line)
{
if (strpos($line, 'use ') === 0)
{
$use_statements[] = trim($line);
$found_first_use = true;
}
elseif ($found_first_use && trim($line) === '')
{
break;
}
}
}
return $found_first_use ? $use_statements : null;
}
/**
* Extracts trait use statements from the given code.
*
* @param string $code The code containing class traits
*
* @return array|null An array of trait names
* @since 3.2.0
*/
public function getTraits(string $code): ?array
{
// regex to target trait use statements
$traitPattern = '/^\s*use\s+[\p{L}0-9\\\\_]+(?:\s*,\s*[\p{L}0-9\\\\_]+)*\s*;/mu';
preg_match_all($traitPattern, $code, $matches, PREG_SET_ORDER);
if ($matches != [])
{
$traitNames = [];
foreach ($matches as $n => $match)
{
$declaration = $match[0] ?? null;
if ($declaration !== null)
{
$names = preg_replace('/\s*use\s+/', '', $declaration);
$names = preg_replace('/\s*;/', '', $names);
$names = preg_split('/\s*,\s*/', $names);
$traitNames = array_merge($traitNames, $names);
}
}
return $traitNames;
}
return null;
}
/**
* Extracts properties declarations and other details from the given code.
*

View File

@ -94,6 +94,86 @@
return null;
}
/**
* Extracts the first consecutive `use` statements from the given PHP class.
*
* @param string $code The PHP class as a string
*
* @return array|null An array of consecutive `use` statements
* @since 3.2.0
*/
public function getUseStatements(string $code): ?array
{
// Match class, final class, abstract class, interface, and trait
$pattern = '/(?:class|final class|abstract class|interface|trait)\s+[a-zA-Z0-9_]+\s*(?:extends\s+[a-zA-Z0-9_]+\s*)?(?:implements\s+[a-zA-Z0-9_]+(?:\s*,\s*[a-zA-Z0-9_]+)*)?\s*\{/s';
// Split the input code based on the class declaration pattern
$parts = preg_split($pattern, $code, 2, PREG_SPLIT_DELIM_CAPTURE);
$header = $parts[0] ?? '';
$use_statements = [];
$found_first_use = false;
if ($header !== '')
{
$lines = explode(PHP_EOL, $header);
foreach ($lines as $line)
{
if (strpos($line, 'use ') === 0)
{
$use_statements[] = trim($line);
$found_first_use = true;
}
elseif ($found_first_use && trim($line) === '')
{
break;
}
}
}
return $found_first_use ? $use_statements : null;
}
/**
* Extracts trait use statements from the given code.
*
* @param string $code The code containing class traits
*
* @return array|null An array of trait names
* @since 3.2.0
*/
public function getTraits(string $code): ?array
{
// regex to target trait use statements
$traitPattern = '/^\s*use\s+[\p{L}0-9\\\\_]+(?:\s*,\s*[\p{L}0-9\\\\_]+)*\s*;/mu';
preg_match_all($traitPattern, $code, $matches, PREG_SET_ORDER);
if ($matches != [])
{
$traitNames = [];
foreach ($matches as $n => $match)
{
$declaration = $match[0] ?? null;
if ($declaration !== null)
{
$names = preg_replace('/\s*use\s+/', '', $declaration);
$names = preg_replace('/\s*;/', '', $names);
$names = preg_split('/\s*,\s*/', $names);
$traitNames = array_merge($traitNames, $names);
}
}
return $traitNames;
}
return null;
}
/**
* Extracts properties declarations and other details from the given code.
*

View File

@ -81,6 +81,7 @@ class Customcode implements ServiceProviderInterface
$container->get('Config'),
$container->get('Placeholder'),
$container->get('Language.Extractor'),
$container->get('Power.Extractor'),
$container->get('Customcode.External')
);
}

View File

@ -47,6 +47,7 @@
$container->get('Config'),
$container->get('Placeholder'),
$container->get('Language.Extractor'),
$container->get('Power.Extractor'),
$container->get('Customcode.External')
);
}

View File

@ -17,10 +17,12 @@ class Power #Gold {
+ array $superpowers
# string $fixUrl
# array $state
# array $retry
# Config $config
# Placeholder $placeholder
# Customcode $customcode
# Gui $gui
# Superpower $superpower
# \JDatabaseDriver $db
# CMSApplication $app
+ __construct(?Config $config = null, ?Placeholder $placeholder = null, ...)
@ -56,6 +58,7 @@ note right of Power::__construct
?Placeholder $placeholder = null
?Customcode $customcode = null
?Gui $gui = null
?Superpower $superpower = null
?\JDatabaseDriver $db = null
?CMSApplication $app = null
end note

View File

@ -26,6 +26,7 @@ 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\Power\Super as Superpower;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\PowerInterface;
@ -84,6 +85,14 @@ class Power implements PowerInterface
**/
protected array $state = [];
/**
* The state of retry to loaded powers
*
* @var array
* @since 3.2.0
**/
protected array $retry = [];
/**
* Compiler Config
*
@ -116,6 +125,14 @@ class Power implements PowerInterface
**/
protected Gui $gui;
/**
* The JCB Superpower class
*
* @var Superpower
* @since 3.2.0
**/
protected Superpower $superpower;
/**
* Database object to query local DB
*
@ -139,6 +156,7 @@ class Power implements PowerInterface
* @param Placeholder|null $placeholder The compiler placeholder object.
* @param Customcode|null $customcode The compiler customcode object.
* @param Gui|null $gui The compiler customcode gui object.
* @param Superpower|null $superpower The JCB superpower object.
* @param \JDatabaseDriver|null $db The Database Driver object.
* @param CMSApplication|null $app The CMS Application object.
*
@ -146,13 +164,14 @@ class Power implements PowerInterface
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Placeholder $placeholder = null,
?Customcode $customcode = null, ?Gui $gui = null,
?Customcode $customcode = null, ?Gui $gui = null, ?Superpower $superpower = null,
?\JDatabaseDriver $db = null, ?CMSApplication $app = null)
{
$this->config = $config ?: Compiler::_('Config');
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
$this->customcode = $customcode ?: Compiler::_('Customcode');
$this->gui = $gui ?: Compiler::_('Customcode.Gui');
$this->superpower = $superpower ?: Compiler::_('Superpower');
$this->db = $db ?: Factory::getDbo();
$this->app = $app ?: Factory::getApplication();
}
@ -325,6 +344,20 @@ class Power implements PowerInterface
// 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_PPOWER_BGUIDSB_NOT_FOUNDP', $guid),
'Error'
@ -1020,7 +1053,6 @@ class Power implements PowerInterface
$this->active[$guid]->super_power_paths = null;
$this->active[$guid]->approved_paths = null;
$this->active[$guid]->approved = null;
}
}
}

View File

@ -46,6 +46,14 @@
**/
protected array $state = [];
/**
* The state of retry to loaded powers
*
* @var array
* @since 3.2.0
**/
protected array $retry = [];
/**
* Compiler Config
*
@ -78,6 +86,14 @@
**/
protected Gui $gui;
/**
* The JCB Superpower class
*
* @var Superpower
* @since 3.2.0
**/
protected Superpower $superpower;
/**
* Database object to query local DB
*
@ -101,6 +117,7 @@
* @param Placeholder|null $placeholder The compiler placeholder object.
* @param Customcode|null $customcode The compiler customcode object.
* @param Gui|null $gui The compiler customcode gui object.
* @param Superpower|null $superpower The JCB superpower object.
* @param \JDatabaseDriver|null $db The Database Driver object.
* @param CMSApplication|null $app The CMS Application object.
*
@ -108,13 +125,14 @@
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Placeholder $placeholder = null,
?Customcode $customcode = null, ?Gui $gui = null,
?Customcode $customcode = null, ?Gui $gui = null, ?Superpower $superpower = null,
?\JDatabaseDriver $db = null, ?CMSApplication $app = null)
{
$this->config = $config ?: Compiler::_('Config');
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
$this->customcode = $customcode ?: Compiler::_('Customcode');
$this->gui = $gui ?: Compiler::_('Customcode.Gui');
$this->superpower = $superpower ?: Compiler::_('Superpower');
$this->db = $db ?: Factory::getDbo();
$this->app = $app ?: Factory::getApplication();
}
@ -287,6 +305,20 @@
// 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('<p>Power <b>guid:%s</b> not found!</p>', $guid),
'Error'
@ -982,4 +1014,4 @@
$this->active[$guid]->super_power_paths = null;
$this->active[$guid]->approved_paths = null;
$this->active[$guid]->approved = null;
}
}

View File

@ -55,6 +55,10 @@
"use_selection10": {
"use": "1bd48df2-4f7e-4581-9fe9-4b54e59105e3",
"as": "default"
},
"use_selection11": {
"use": "3ab0eba9-f37b-4b37-aec1-2e78067f2aff",
"as": "Superpower"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Compiler.Power",

View File

@ -15,9 +15,14 @@ class Reverse #Gold {
# Placeholder $placeholder
# Language $language
# Extractor $extractor
# Power $power
+ __construct(?Config $config = null, ?Placeholder $placeholder = null, ...)
+ engine(string $string, array $placeholders, ...) : string
# setReverse(string $updateString, string $string, ...) : string
# reverseSuperPowers(string $updateString, string $string, ...) : string
# getReversePower(array $powers, array $useStatements) : ?array
# reverseLanguage(string $updateString, string $string, ...) : string
# reverseCustomCode(string $updateString, string $string) : string
}
note right of Reverse::__construct
@ -30,6 +35,7 @@ note right of Reverse::__construct
?Placeholder $placeholder = null
?Language $language = null
?Extractor $extractor = null
?Power $power = null
end note
note right of Reverse::engine
@ -45,9 +51,42 @@ note right of Reverse::engine
?int $id = null
string $field = 'code'
string $table = 'custom_code'
?array $useStatements = null
end note
note right of Reverse::setReverse
Reverse engineer the dynamic language, and super powers
since: 3.2.0
return: string
arguments:
string $updateString
string $string
string $target
?array $useStatements
end note
note right of Reverse::reverseSuperPowers
Set the super powers keys for the reveres process
since: 3.2.0
return: string
arguments:
string $updateString
string $string
?array $useStatements
end note
note right of Reverse::getReversePower
Set the super powers keys for the reveres process
since: 3.2.0
return: ?array
end note
note right of Reverse::reverseLanguage
Set the language strings for the reveres process
since: 3.2.0
@ -58,6 +97,13 @@ note right of Reverse::setReverse
string $string
string $target
end note
note right of Reverse::reverseCustomCode
Set the custom code placeholder for the reveres process
since: 3.2.0
return: string
end note
@enduml
```

View File

@ -20,6 +20,7 @@ use VDM\Joomla\Componentbuilder\Compiler\Config;
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;
/**
@ -61,41 +62,54 @@ class Reverse
**/
protected Extractor $extractor;
/**
* Super Power Extractor
*
* @var Power
* @since 3.2.0
**/
protected Power $power;
/**
* 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 Extract|null $extractor The compiler language extractor object.
* @param Extractor|null $extractor The compiler language extractor object.
* @param Power|null $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)
?Language $language = null, ?Extractor $extractor = null,
?Power $power = null)
{
$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');
}
/**
* Reverse Engineer the dynamic placeholders (TODO hmmmm this is not ideal)
*
* @param string $string The string to revers
* @param array $placeholders The values to search for
* @param string $target The target path type
* @param int|null $id The custom code id
* @param string $field The field name
* @param string $table The table name
* @param string $string The string to reverse
* @param array $placeholders The values to search for
* @param string $target The target path type
* @param int|null $id The custom code id
* @param string $field The field name
* @param string $table The table name
* @param array|null $useStatements The file use statements (needed for super powers)
*
* @return string
* @since 3.2.0
*/
public function engine(string $string, array &$placeholders,
string $target, ?int $id = null, string $field = 'code', string $table = 'custom_code'): string
string $target, ?int $id = null, string $field = 'code',
string $table = 'custom_code', ?array $useStatements = null): string
{
// get local code if set
if ($id > 0 && $code = base64_decode(
@ -103,13 +117,112 @@ class Reverse
))
{
$string = $this->setReverse(
$string, $code, $target
$string, $code, $target, $useStatements
);
}
return $this->placeholder->update($string, $placeholders, 2);
}
/**
* Reverse engineer the dynamic language, and super powers
*
* @param string $updateString The string to update
* @param string $string The string to use language update
* @param string $target The target path type
* @param array|null $useStatements The file use statements (needed for super powers)
*
* @return string
* @since 3.2.0
*/
protected function setReverse(string $updateString, string $string,
string $target, ?array $useStatements): string
{
// we have to reverse engineer to super powers
$updateString = $this->reverseSuperPowers($updateString, $string, $useStatements);
// reverse engineer the language strings
$updateString = $this->reverseLanguage($updateString, $string, $target);
// reverse engineer the custom code (if possible)
// $updateString = $this->reverseCustomCode($updateString, $string); // TODO - we would like to also reverse basic customcode
return $updateString;
}
/**
* Set the super 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 reverseSuperPowers(string $updateString, string $string,
?array $useStatements): string
{
// 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)
{
return $this->placeholder->update($updateString, $reverse);
}
return $updateString;
}
/**
* Set the super powers keys for the reveres process
*
* @param array $powers The powers found in the database text
* @param array $useStatements The file use statements
*
* @return array|null
* @since 3.2.0
*/
protected function getReversePower(array $powers, array $useStatements): ?array
{
$matching_statements = [];
foreach ($useStatements as $use_statement)
{
$namespace = substr($use_statement, 4, -1); // remove 'use ' and ';'
$class_name = '';
// Check for 'as' alias
if (strpos($namespace, ' as ') !== false)
{
list($namespace, $class_name) = explode(' as ', $namespace);
}
// If there is no 'as' alias, get the class name from the last '\'
if (empty($class_name))
{
$last_slash = strrpos($namespace, '\\');
if ($last_slash !== false)
{
$class_name = substr($namespace, $last_slash + 1);
}
}
// Check if the namespace is in the powers array
if (in_array($namespace, $powers))
{
$guid = array_search($namespace, $powers);
$matching_statements[$class_name] =
'Super_'.'_'.'_' . str_replace('-', '_', $guid) . '_'.'_'.'_Power';
}
}
if ($matching_statements !== [])
{
return $matching_statements;
}
return null;
}
/**
* Set the language strings for the reveres process
*
@ -120,7 +233,7 @@ class Reverse
* @return string
* @since 3.2.0
*/
protected function setReverse(string $updateString, string $string, string $target): string
protected function reverseLanguage(string $updateString, string $string, string $target): string
{
// get targets to search for
$lang_string_targets = array_filter(
@ -184,7 +297,7 @@ class Reverse
$string, $lang_string_target . "'", "'"
);
$lang_check[] = GetHelper::allBetween(
$string, $lang_string_target . "'", "'"
$string, $lang_string_target . '"', '"'
);
}
// merge arrays
@ -232,6 +345,56 @@ class Reverse
return $updateString;
}
/**
* Set the custom code placeholder for the reveres process
*
* @param string $updateString The string to update
* @param string $string The string to use for super power update
*
* @return string
* @since 3.2.0
*/
protected function reverseCustomCode(string $updateString, string $string): string
{
// check if content has custom code place holder
if (strpos($string, '[CUSTO' . 'MCODE=') !== false)
{
$found = GetHelper::allBetween(
$string, '[CUSTO' . 'MCODE=', ']'
);
$bucket = [];
if (ArrayHelper::check($found))
{
foreach ($found as $key)
{
// we only update those without args
if (is_numeric($key) && $get_func_name = GetHelper::var(
'custom_code', $key, 'id', 'function_name'
))
{
$bucket[$get_func_name] = (int) $key;
}
elseif (StringHelper::check($key)
&& strpos((string) $key, '+') === false)
{
$get_func_name = trim((string) $key);
if (isset($bucket[$get_func_name]) || !$found_local = GetHelper::var(
'custom_code', $get_func_name, 'function_name',
'id'
))
{
continue;
}
$bucket[$get_func_name] = (int) $found_local;
}
}
// TODO - we need to now get the customcode
// search and replace the customcode with the placeholder
}
}
return $updateString;
}
}

View File

@ -30,41 +30,54 @@
**/
protected Extractor $extractor;
/**
* Super Power Extractor
*
* @var Power
* @since 3.2.0
**/
protected Power $power;
/**
* 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 Extract|null $extractor The compiler language extractor object.
* @param Extractor|null $extractor The compiler language extractor object.
* @param Power|null $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)
?Language $language = null, ?Extractor $extractor = null,
?Power $power = null)
{
$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');
}
/**
* Reverse Engineer the dynamic placeholders (TODO hmmmm this is not ideal)
*
* @param string $string The string to revers
* @param array $placeholders The values to search for
* @param string $target The target path type
* @param int|null $id The custom code id
* @param string $field The field name
* @param string $table The table name
* @param string $string The string to reverse
* @param array $placeholders The values to search for
* @param string $target The target path type
* @param int|null $id The custom code id
* @param string $field The field name
* @param string $table The table name
* @param array|null $useStatements The file use statements (needed for super powers)
*
* @return string
* @since 3.2.0
*/
public function engine(string $string, array &$placeholders,
string $target, ?int $id = null, string $field = 'code', string $table = 'custom_code'): string
string $target, ?int $id = null, string $field = 'code',
string $table = 'custom_code', ?array $useStatements = null): string
{
// get local code if set
if ($id > 0 && $code = base64_decode(
@ -72,13 +85,112 @@
))
{
$string = $this->setReverse(
$string, $code, $target
$string, $code, $target, $useStatements
);
}
return $this->placeholder->update($string, $placeholders, 2);
}
/**
* Reverse engineer the dynamic language, and super powers
*
* @param string $updateString The string to update
* @param string $string The string to use language update
* @param string $target The target path type
* @param array|null $useStatements The file use statements (needed for super powers)
*
* @return string
* @since 3.2.0
*/
protected function setReverse(string $updateString, string $string,
string $target, ?array $useStatements): string
{
// we have to reverse engineer to super powers
$updateString = $this->reverseSuperPowers($updateString, $string, $useStatements);
// reverse engineer the language strings
$updateString = $this->reverseLanguage($updateString, $string, $target);
// reverse engineer the custom code (if possible)
// $updateString = $this->reverseCustomCode($updateString, $string); // TODO - we would like to also reverse basic customcode
return $updateString;
}
/**
* Set the super 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 reverseSuperPowers(string $updateString, string $string,
?array $useStatements): string
{
// 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)
{
return $this->placeholder->update($updateString, $reverse);
}
return $updateString;
}
/**
* Set the super powers keys for the reveres process
*
* @param array $powers The powers found in the database text
* @param array $useStatements The file use statements
*
* @return array|null
* @since 3.2.0
*/
protected function getReversePower(array $powers, array $useStatements): ?array
{
$matching_statements = [];
foreach ($useStatements as $use_statement)
{
$namespace = substr($use_statement, 4, -1); // remove 'use ' and ';'
$class_name = '';
// Check for 'as' alias
if (strpos($namespace, ' as ') !== false)
{
list($namespace, $class_name) = explode(' as ', $namespace);
}
// If there is no 'as' alias, get the class name from the last '\'
if (empty($class_name))
{
$last_slash = strrpos($namespace, '\\');
if ($last_slash !== false)
{
$class_name = substr($namespace, $last_slash + 1);
}
}
// Check if the namespace is in the powers array
if (in_array($namespace, $powers))
{
$guid = array_search($namespace, $powers);
$matching_statements[$class_name] =
'Super_'.'_'.'_' . str_replace('-', '_', $guid) . '_'.'_'.'_Power';
}
}
if ($matching_statements !== [])
{
return $matching_statements;
}
return null;
}
/**
* Set the language strings for the reveres process
*
@ -89,7 +201,7 @@
* @return string
* @since 3.2.0
*/
protected function setReverse(string $updateString, string $string, string $target): string
protected function reverseLanguage(string $updateString, string $string, string $target): string
{
// get targets to search for
$lang_string_targets = array_filter(
@ -153,7 +265,7 @@
$string, $lang_string_target . "'", "'"
);
$lang_check[] = GetHelper::allBetween(
$string, $lang_string_target . "'", "'"
$string, $lang_string_target . '"', '"'
);
}
// merge arrays
@ -201,3 +313,54 @@
return $updateString;
}
/**
* Set the custom code placeholder for the reveres process
*
* @param string $updateString The string to update
* @param string $string The string to use for super power update
*
* @return string
* @since 3.2.0
*/
protected function reverseCustomCode(string $updateString, string $string): string
{
// check if content has custom code place holder
if (strpos($string, '[CUSTO' . 'MCODE=') !== false)
{
$found = GetHelper::allBetween(
$string, '[CUSTO' . 'MCODE=', ']'
);
$bucket = [];
if (ArrayHelper::check($found))
{
foreach ($found as $key)
{
// we only update those without args
if (is_numeric($key) && $get_func_name = GetHelper::var(
'custom_code', $key, 'id', 'function_name'
))
{
$bucket[$get_func_name] = (int) $key;
}
elseif (StringHelper::check($key)
&& strpos((string) $key, '+') === false)
{
$get_func_name = trim((string) $key);
if (isset($bucket[$get_func_name]) || !$found_local = GetHelper::var(
'custom_code', $get_func_name, 'function_name',
'id'
))
{
continue;
}
$bucket[$get_func_name] = (int) $found_local;
}
}
// TODO - we need to now get the customcode
// search and replace the customcode with the placeholder
}
}
return $updateString;
}

View File

@ -41,6 +41,10 @@
"use_selection7": {
"use": "d33b9278-c409-4aec-a047-b72f56712391",
"as": "default"
},
"use_selection8": {
"use": "eeb03266-22fd-45bb-953a-961bb6be3a54",
"as": "Power"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Compiler.Placeholder.Reverse",

View File

@ -13,6 +13,7 @@
class Power #Gold {
+ register(Container $container) : void
+ getPowers(Container $container) : Powers
+ getSuperpower(Container $container) : Superpower
+ getGrep(Container $container) : Grep
+ getAutoloader(Container $container) : Autoloader
+ getInfusion(Container $container) : Infusion
@ -21,6 +22,11 @@ class Power #Gold {
+ getPlantuml(Container $container) : Plantuml
+ getRepoReadme(Container $container) : RepoReadme
+ getReposReadme(Container $container) : ReposReadme
+ getExtractor(Container $container) : Extractor
+ getInjector(Container $container) : Injector
+ getModel(Container $container) : Model
+ getInsert(Container $container) : Insert
+ getUpdate(Container $container) : Update
}
note right of Power::register
@ -37,61 +43,103 @@ note left of Power::getPowers
return: Powers
end note
note right of Power::getGrep
note right of Power::getSuperpower
Get the Superpower
since: 3.2.0
return: Superpower
end note
note left of Power::getGrep
Get the Grep
since: 3.2.0
return: Grep
end note
note left of Power::getAutoloader
note right of Power::getAutoloader
Get the Compiler Autoloader
since: 3.2.0
return: Autoloader
end note
note right of Power::getInfusion
note left of Power::getInfusion
Get the Compiler Power Infusion
since: 3.2.0
return: Infusion
end note
note left of Power::getStructure
note right of Power::getStructure
Get the Compiler Power Structure Builder
since: 3.2.0
return: Structure
end note
note right of Power::getParser
note left of Power::getParser
Get the Compiler Power Parser
since: 3.2.0
return: Parser
end note
note left of Power::getPlantuml
note right of Power::getPlantuml
Get the Compiler Power Plantuml Builder
since: 3.2.0
return: Plantuml
end note
note right of Power::getRepoReadme
note left of Power::getRepoReadme
Get the Compiler Power Repo Readme Builder
since: 3.2.0
return: RepoReadme
end note
note left of Power::getReposReadme
note right of Power::getReposReadme
Get the Compiler Power Repos Readme Builder
since: 3.2.0
return: ReposReadme
end note
note left of Power::getExtractor
Get the Compiler Power Extractor
since: 3.2.0
return: Extractor
end note
note right of Power::getInjector
Get the Compiler Power Injector
since: 3.2.0
return: Injector
end note
note left of Power::getModel
Get the Power Model
since: 3.2.0
return: Model
end note
note right of Power::getInsert
Get the Power Insert
since: 3.2.0
return: Insert
end note
note left of Power::getUpdate
Get the Power Update
since: 3.2.0
return: Update
end note
@enduml
```

View File

@ -16,6 +16,7 @@ use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Compiler\Power as Powers;
use VDM\Joomla\Componentbuilder\Power\Grep;
use VDM\Joomla\Componentbuilder\Power\Super as Superpower;
use VDM\Joomla\Componentbuilder\Compiler\Power\Infusion;
use VDM\Joomla\Componentbuilder\Compiler\Power\Autoloader;
use VDM\Joomla\Componentbuilder\Compiler\Power\Structure;
@ -23,6 +24,11 @@ use VDM\Joomla\Componentbuilder\Compiler\Power\Parser;
use VDM\Joomla\Componentbuilder\Compiler\Power\Plantuml;
use VDM\Joomla\Componentbuilder\Compiler\Power\Repo\Readme as RepoReadme;
use VDM\Joomla\Componentbuilder\Compiler\Power\Repos\Readme as ReposReadme;
use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor;
use VDM\Joomla\Componentbuilder\Compiler\Power\Injector;
use VDM\Joomla\Componentbuilder\Power\Model;
use VDM\Joomla\Componentbuilder\Power\Database\Insert;
use VDM\Joomla\Componentbuilder\Power\Database\Update;
/**
@ -45,8 +51,11 @@ class Power implements ServiceProviderInterface
$container->alias(Powers::class, 'Power')
->share('Power', [$this, 'getPowers'], true);
$container->alias(Superpower::class, 'Superpower')
->share('Superpower', [$this, 'getSuperpower'], true);
$container->alias(Grep::class, 'Power.Grep')
->share('Grep', [$this, 'getGrep'], true);
->share('Power.Grep', [$this, 'getGrep'], true);
$container->alias(Autoloader::class, 'Power.Autoloader')
->share('Power.Autoloader', [$this, 'getAutoloader'], true);
@ -68,6 +77,21 @@ class Power implements ServiceProviderInterface
$container->alias(ReposReadme::class, 'Power.Repos.Readme')
->share('Power.Repos.Readme', [$this, 'getReposReadme'], true);
$container->alias(Extractor::class, 'Power.Extractor')
->share('Power.Extractor', [$this, 'getExtractor'], true);
$container->alias(Injector::class, 'Power.Injector')
->share('Power.Injector', [$this, 'getInjector'], true);
$container->alias(Model::class, 'Power.Model')
->share('Power.Model', [$this, 'getModel'], true);
$container->alias(Insert::class, 'Power.Insert')
->share('Power.Insert', [$this, 'getInsert'], true);
$container->alias(Update::class, 'Power.Update')
->share('Power.Update', [$this, 'getUpdate'], true);
}
/**
@ -88,6 +112,23 @@ class Power implements ServiceProviderInterface
);
}
/**
* 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('Power.Grep'),
$container->get('Power.Insert'),
$container->get('Power.Update')
);
}
/**
* Get the Grep
*
@ -98,7 +139,11 @@ class Power implements ServiceProviderInterface
*/
public function getGrep(Container $container): Grep
{
return new Grep();
return new Grep(
$container->get('Config')->local_powers_repository_path,
$container->get('Config')->approved_paths,
$container->get('Gitea.Repository.Contents')
);
}
/**
@ -221,6 +266,83 @@ class Power implements ServiceProviderInterface
$container->get('Power.Plantuml')
);
}
/**
* 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();
}
/**
* 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('Power'),
$container->get('Power.Extractor'),
$container->get('Power.Parser'),
$container->get('Placeholder')
);
}
/**
* Get the Power Model
*
* @param Container $container The DI container.
*
* @return Model
* @since 3.2.0
*/
public function getModel(Container $container): Model
{
return new Model(
$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('Power.Model'),
$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('Power.Model'),
$container->get('Update')
);
}
}

View File

@ -11,8 +11,11 @@
$container->alias(Powers::class, 'Power')
->share('Power', [$this, 'getPowers'], true);
$container->alias(Superpower::class, 'Superpower')
->share('Superpower', [$this, 'getSuperpower'], true);
$container->alias(Grep::class, 'Power.Grep')
->share('Grep', [$this, 'getGrep'], true);
->share('Power.Grep', [$this, 'getGrep'], true);
$container->alias(Autoloader::class, 'Power.Autoloader')
->share('Power.Autoloader', [$this, 'getAutoloader'], true);
@ -34,6 +37,21 @@
$container->alias(ReposReadme::class, 'Power.Repos.Readme')
->share('Power.Repos.Readme', [$this, 'getReposReadme'], true);
$container->alias(Extractor::class, 'Power.Extractor')
->share('Power.Extractor', [$this, 'getExtractor'], true);
$container->alias(Injector::class, 'Power.Injector')
->share('Power.Injector', [$this, 'getInjector'], true);
$container->alias(Model::class, 'Power.Model')
->share('Power.Model', [$this, 'getModel'], true);
$container->alias(Insert::class, 'Power.Insert')
->share('Power.Insert', [$this, 'getInsert'], true);
$container->alias(Update::class, 'Power.Update')
->share('Power.Update', [$this, 'getUpdate'], true);
}
/**
@ -54,6 +72,23 @@
);
}
/**
* 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('Power.Grep'),
$container->get('Power.Insert'),
$container->get('Power.Update')
);
}
/**
* Get the Grep
*
@ -64,7 +99,11 @@
*/
public function getGrep(Container $container): Grep
{
return new Grep();
return new Grep(
$container->get('Config')->local_powers_repository_path,
$container->get('Config')->approved_paths,
$container->get('Gitea.Repository.Contents')
);
}
/**
@ -187,3 +226,81 @@
$container->get('Power.Plantuml')
);
}
/**
* 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();
}
/**
* 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('Power'),
$container->get('Power.Extractor'),
$container->get('Power.Parser'),
$container->get('Placeholder')
);
}
/**
* Get the Power Model
*
* @param Container $container The DI container.
*
* @return Model
* @since 3.2.0
*/
public function getModel(Container $container): Model
{
return new Model(
$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('Power.Model'),
$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('Power.Model'),
$container->get('Update')
);
}

View File

@ -16,37 +16,61 @@
"use": "b836c1b1-b6b1-44f7-b8a2-9a763a4185b1",
"as": "Powers"
},
"use_selection8": {
"use_selection1": {
"use": "6784dd52-0909-451a-a872-9a942a023c68",
"as": "default"
},
"use_selection1": {
"use_selection2": {
"use": "3ab0eba9-f37b-4b37-aec1-2e78067f2aff",
"as": "Superpower"
},
"use_selection3": {
"use": "0419081e-4cb3-4c65-8c6a-ffe941fb0f1c",
"as": "default"
},
"use_selection2": {
"use_selection4": {
"use": "6e64917c-d687-4ef3-a655-811319f5a81e",
"as": "default"
},
"use_selection3": {
"use_selection5": {
"use": "324566de-0f7d-4b6e-9caf-8424d55013ae",
"as": "default"
},
"use_selection4": {
"use_selection6": {
"use": "95d0e03f-24fd-4412-bc2e-f0899fcc3205",
"as": "default"
},
"use_selection5": {
"use_selection7": {
"use": "ff5e9e63-86d0-4691-ab59-d4b9d9154096",
"as": "default"
},
"use_selection6": {
"use_selection8": {
"use": "efb1d0f8-2d14-4d2c-8b5f-4fcdd9df45a5",
"as": "RepoReadme"
},
"use_selection7": {
"use_selection9": {
"use": "0d08c583-04d5-454e-b756-48ca05e1651a",
"as": "ReposReadme"
},
"use_selection10": {
"use": "eeb03266-22fd-45bb-953a-961bb6be3a54",
"as": "default"
},
"use_selection11": {
"use": "763d137c-42bc-4282-98d8-cc5c0654985f",
"as": "default"
},
"use_selection12": {
"use": "7c1fb50f-8fb1-4627-8705-6fedf7182ca5",
"as": "default"
},
"use_selection13": {
"use": "380bb7a3-cdcc-4336-a699-5070cbf521a5",
"as": "default"
},
"use_selection14": {
"use": "e543c123-b1d9-4a0b-83b2-a9d371da5ff3",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Compiler.Service.Power",

View File

@ -0,0 +1,89 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Update (Details)
> namespace: **VDM\Joomla\Componentbuilder\Power\Database**
```uml
@startuml
class Update << (F,LightGreen) >> #Green {
# Model $model
# Database $database
+ __construct(Model $model, Database $database)
+ value(mixed $value, string $field, ...) : bool
+ row(array $item) : bool
+ rows(?array $items) : bool
+ item(object $item) : bool
+ items(?array $items) : bool
}
note right of Update::__construct
Constructor
since: 3.2.0
end note
note right of Update::value
Update a value to a given table
Example: $this->value(Value, 'value_key', 'GUID');
since: 3.2.0
return: bool
arguments:
mixed $value
string $field
string $keyValue
string $key = 'guid'
end note
note right of Update::row
Update single row with multiple values to a given table
Example: $this->item(Array);
since: 3.2.0
return: bool
end note
note right of Update::rows
Update multiple rows to a given table
Example: $this->items(Array);
since: 3.2.0
return: bool
end note
note right of Update::item
Update single item with multiple values to a given table
Example: $this->item(Object);
since: 3.2.0
return: bool
end note
note right of Update::items
Update multiple items to a given table
Example: $this->items(Array);
since: 3.2.0
return: bool
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,160 @@
<?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\Power\Database;
use VDM\Joomla\Componentbuilder\Power\Model as Model;
use VDM\Joomla\Componentbuilder\Database\Update as Database;
/**
* Power Database Update
*
* @since 3.2.0
*/
final class Update
{
/**
* Model
*
* @var Model
* @since 3.2.0
*/
protected Model $model;
/**
* Database
*
* @var Database
* @since 3.2.0
*/
protected Database $database;
/**
* Constructor
*
* @param Model $model The set model object.
* @param Database $database The update database object.
*
* @since 3.2.0
*/
public function __construct(Model $model, Database $database)
{
$this->model = $model;
$this->database = $database;
}
/**
* Update a value to a given table
* Example: $this->value(Value, 'value_key', 'GUID');
*
* @param mixed $value The field value
* @param string $field The field key
* @param string $keyValue The key value
* @param string $key The key name
*
* @return bool
* @since 3.2.0
*/
public function value($value, string $field, string $keyValue, string $key = 'guid'): bool
{
// build the array
$item = [];
$item[$key] = $keyValue;
$item[$field] = $value;
// Update the column of this table using guid as the primary key.
return $this->row($item);
}
/**
* Update single row with multiple values to a given table
* Example: $this->item(Array);
*
* @param array $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function row(array $item): bool
{
// check if object could be modelled
if (($item = $this->model->row($item, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->row($item, 'guid', 'power');
}
return false;
}
/**
* Update multiple rows to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of arrays)
*
* @return bool
* @since 3.2.0
*/
public function rows(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->rows($items, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->rows($items, 'guid', 'power');
}
return false;
}
/**
* Update single item with multiple values to a given table
* Example: $this->item(Object);
*
* @param object $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function item(object $item): bool
{
// check if object could be modelled
if (($item = $this->model->item($item, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->item($item, 'guid', 'power');
}
return false;
}
/**
* Update multiple items to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of objects)
*
* @return bool
* @since 3.2.0
*/
public function items(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->items($items, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->items($items, 'guid', 'power');
}
return false;
}
}

View File

@ -0,0 +1,132 @@
/**
* Model
*
* @var Model
* @since 3.2.0
*/
protected Model $model;
/**
* Database
*
* @var Database
* @since 3.2.0
*/
protected Database $database;
/**
* Constructor
*
* @param Model $model The set model object.
* @param Database $database The update database object.
*
* @since 3.2.0
*/
public function __construct(Model $model, Database $database)
{
$this->model = $model;
$this->database = $database;
}
/**
* Update a value to a given table
* Example: $this->value(Value, 'value_key', 'GUID');
*
* @param mixed $value The field value
* @param string $field The field key
* @param string $keyValue The key value
* @param string $key The key name
*
* @return bool
* @since 3.2.0
*/
public function value($value, string $field, string $keyValue, string $key = 'guid'): bool
{
// build the array
$item = [];
$item[$key] = $keyValue;
$item[$field] = $value;
// Update the column of this table using guid as the primary key.
return $this->row($item);
}
/**
* Update single row with multiple values to a given table
* Example: $this->item(Array);
*
* @param array $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function row(array $item): bool
{
// check if object could be modelled
if (($item = $this->model->row($item, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->row($item, 'guid', 'power');
}
return false;
}
/**
* Update multiple rows to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of arrays)
*
* @return bool
* @since 3.2.0
*/
public function rows(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->rows($items, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->rows($items, 'guid', 'power');
}
return false;
}
/**
* Update single item with multiple values to a given table
* Example: $this->item(Object);
*
* @param object $item The item to save
*
* @return bool
* @since 3.2.0
*/
public function item(object $item): bool
{
// check if object could be modelled
if (($item = $this->model->item($item, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->item($item, 'guid', 'power');
}
return false;
}
/**
* Update multiple items to a given table
* Example: $this->items(Array);
*
* @param array|null $items The items updated in database (array of objects)
*
* @return bool
* @since 3.2.0
*/
public function items(?array $items): bool
{
// check if object could be modelled
if (($items = $this->model->items($items, 'power')) !== null)
{
// Update the column of this table using guid as the primary key.
return $this->database->items($items, 'guid', 'power');
}
return false;
}

View File

@ -0,0 +1,27 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "e543c123-b1d9-4a0b-83b2-a9d371da5ff3",
"implements": null,
"load_selection": null,
"name": "Update",
"power_version": "1.0.0",
"system_name": "JCB.Power.Database.Update",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "7c1fb50f-8fb1-4627-8705-6fedf7182ca5",
"as": "Model"
},
"use_selection1": {
"use": "cce56585-58b0-4f72-a92c-e2635ea52d83",
"as": "Database"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Power.Database.Update",
"description": "Power Database Update\r\n\r\n@since 3.2.0",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,102 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Extractor (Details)
> namespace: **VDM\Joomla\Componentbuilder\Compiler\Power**
```uml
@startuml
class Extractor << (F,LightGreen) >> #Green {
# array $powers
# \JDatabaseDriver $db
+ __construct(?\JDatabaseDriver $db = null)
+ get_() : ?array
+ get(string $code) : ?array
+ reverse(string $code) : ?array
+ search(string $code) : void
# load(array $found) : void
# map(array $found) : ?array
# filter(array $found) : ?array
# namespaces(array $guids) : ?array
}
note right of Extractor::__construct
Constructor
since: 3.2.0
end note
note left of Extractor::get_
Get Super Powers from the code string
since: 3.2.0
return: ?array
end note
note right of Extractor::get
Get Super Powers from the code string
since: 3.2.0
return: ?array
end note
note left of Extractor::reverse
Get Super Powers from the code string
since: 3.2.0
return: ?array
end note
note right of Extractor::search
Get Super Powers from the code string and load it
since: 3.2.0
return: void
end note
note left of Extractor::load
Load the Super Powers found
since: 3.2.0
return: void
end note
note right of Extractor::map
Map the Super Powers to GUIDs
since: 3.2.0
return: ?array
end note
note left of Extractor::filter
Filter the Super Powers to GUIDs
since: 3.2.0
return: ?array
end note
note right of Extractor::namespaces
Get the complete namespace strings of the guids passed as an array.
since: 3.2.0
return: ?array
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,244 @@
<?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\Power;
use Joomla\CMS\Factory;
use VDM\Joomla\Utilities\GuidHelper;
/**
* Compiler Power Extractor
* @since 3.2.0
*/
final class Extractor
{
/**
* The pattern to get the powers
*
* @var string
* @since 3.2.0
**/
protected string $pattern = '/Super_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/';
/**
* Powers GUID's
*
* @var array
* @since 3.2.0
**/
protected array $powers = [];
/**
* Database object to query local DB
*
* @var \JDatabaseDriver
* @since 3.2.0
**/
protected \JDatabaseDriver $db;
/**
* Constructor
*
* @param \JDatabaseDriver|null $db The database object.
* @since 3.2.0
*/
public function __construct(?\JDatabaseDriver $db = null)
{
$this->db = $db ?: Factory::getDbo();
}
/**
* Get Super Powers from the code string
*
* @param string $code The code
*
* @return array|null
* @since 3.2.0
*/
public function get_(): ?array
{
return $this->powers !== [] ? $this->powers : null;
}
/**
* 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
{
$matches = [];
preg_match_all($this->pattern, $code, $matches);
$found = $matches[0];
if (!empty($found))
{
return $this->map($found);
}
return null;
}
/**
* 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
{
$matches = [];
preg_match_all($this->pattern, $code, $matches);
$found = $matches[0];
if (!empty($found) && ($guids = $this->filter($found)) !== null)
{
return $this->namespaces($guids);
}
return null;
}
/**
* 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)
{
$matches = [];
preg_match_all($this->pattern, $code, $matches);
$found = $matches[0];
if (!empty($found))
{
$this->load($found);
}
}
/**
* Load the Super Powers found
*
* @param array $found The found Super Powers
*
* @return void
* @since 3.2.0
*/
protected function load(array $found)
{
foreach ($found as $super_power)
{
$guid = str_replace(['Super_'.'_'.'_', '_'.'_'.'_Power'], '', $super_power);
$guid = str_replace('_', '-', $guid);
if (GuidHelper::valid($guid))
{
$this->powers[$guid] = 1; // 1 force the power to be added
}
}
}
/**
* Map the Super Powers to GUIDs
*
* @param array $found The found Super Powers
*
* @return array
* @since 3.2.0
*/
protected function map(array $found): ?array
{
$guids = [];
foreach ($found as $super_power)
{
$guid = str_replace(['Super_'.'_'.'_', '_'.'_'.'_Power'], '', $super_power);
$guid = str_replace('_', '-', $guid);
if (GuidHelper::valid($guid))
{
$guids[$super_power] = $guid;
}
}
return $guids !== [] ? $guids : null;
}
/**
* Filter the Super Powers to GUIDs
*
* @param array $found The found Super Powers
*
* @return array
* @since 3.2.0
*/
protected function filter(array $found): ?array
{
$guids = [];
foreach ($found as $super_power)
{
$guid = str_replace(['Super_'.'_'.'_', '_'.'_'.'_Power'], '', $super_power);
$guid = str_replace('_', '-', $guid);
if (GuidHelper::valid($guid))
{
$guids[$guid] = $guid;
}
}
return $guids !== [] ? array_values($guids) : null;
}
/**
* 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(
'DISTINCT REPLACE('
. $this->db->quoteName('namespace')
. ', ".", "\\\") AS full_namespace, '
. $this->db->quoteName('guid')
)
->from($this->db->quoteName('#__componentbuilder_power'))
->where($this->db->quoteName('guid') . ' IN (' . implode(',', array_map([$this->db, 'quote'], $guids)) . ')');
$this->db->setQuery($query);
$this->db->execute();
if ($this->db->getNumRows())
{
return $this->db->loadAssocList('guid', 'full_namespace');
}
return null;
}
}

View File

@ -0,0 +1,218 @@
/**
* The pattern to get the powers
*
* @var string
* @since 3.2.0
**/
protected string $pattern = '/Super_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/';
/**
* Powers GUID's
*
* @var array
* @since 3.2.0
**/
protected array $powers = [];
/**
* Database object to query local DB
*
* @var \JDatabaseDriver
* @since 3.2.0
**/
protected \JDatabaseDriver $db;
/**
* Constructor
*
* @param \JDatabaseDriver|null $db The database object.
* @since 3.2.0
*/
public function __construct(?\JDatabaseDriver $db = null)
{
$this->db = $db ?: Factory::getDbo();
}
/**
* Get Super Powers from the code string
*
* @param string $code The code
*
* @return array|null
* @since 3.2.0
*/
public function get_(): ?array
{
return $this->powers !== [] ? $this->powers : null;
}
/**
* 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
{
$matches = [];
preg_match_all($this->pattern, $code, $matches);
$found = $matches[0];
if (!empty($found))
{
return $this->map($found);
}
return null;
}
/**
* 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
{
$matches = [];
preg_match_all($this->pattern, $code, $matches);
$found = $matches[0];
if (!empty($found) && ($guids = $this->filter($found)) !== null)
{
return $this->namespaces($guids);
}
return null;
}
/**
* 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)
{
$matches = [];
preg_match_all($this->pattern, $code, $matches);
$found = $matches[0];
if (!empty($found))
{
$this->load($found);
}
}
/**
* Load the Super Powers found
*
* @param array $found The found Super Powers
*
* @return void
* @since 3.2.0
*/
protected function load(array $found)
{
foreach ($found as $super_power)
{
$guid = str_replace(['Super_'.'_'.'_', '_'.'_'.'_Power'], '', $super_power);
$guid = str_replace('_', '-', $guid);
if (GuidHelper::valid($guid))
{
$this->powers[$guid] = 1; // 1 force the power to be added
}
}
}
/**
* Map the Super Powers to GUIDs
*
* @param array $found The found Super Powers
*
* @return array
* @since 3.2.0
*/
protected function map(array $found): ?array
{
$guids = [];
foreach ($found as $super_power)
{
$guid = str_replace(['Super_'.'_'.'_', '_'.'_'.'_Power'], '', $super_power);
$guid = str_replace('_', '-', $guid);
if (GuidHelper::valid($guid))
{
$guids[$super_power] = $guid;
}
}
return $guids !== [] ? $guids : null;
}
/**
* Filter the Super Powers to GUIDs
*
* @param array $found The found Super Powers
*
* @return array
* @since 3.2.0
*/
protected function filter(array $found): ?array
{
$guids = [];
foreach ($found as $super_power)
{
$guid = str_replace(['Super_'.'_'.'_', '_'.'_'.'_Power'], '', $super_power);
$guid = str_replace('_', '-', $guid);
if (GuidHelper::valid($guid))
{
$guids[$guid] = $guid;
}
}
return $guids !== [] ? array_values($guids) : null;
}
/**
* 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(
'DISTINCT REPLACE('
. $this->db->quoteName('namespace')
. ', ".", "\\\") AS full_namespace, '
. $this->db->quoteName('guid')
)
->from($this->db->quoteName('#__componentbuilder_power'))
->where($this->db->quoteName('guid') . ' IN (' . implode(',', array_map([$this->db, 'quote'], $guids)) . ')');
$this->db->setQuery($query);
$this->db->execute();
if ($this->db->getNumRows())
{
return $this->db->loadAssocList('guid', 'full_namespace');
}
return null;
}

View File

@ -0,0 +1,23 @@
{
"add_head": "1",
"add_licensing_template": "2",
"extends": "0",
"guid": "eeb03266-22fd-45bb-953a-961bb6be3a54",
"implements": null,
"load_selection": null,
"name": "Extractor",
"power_version": "1.0.0",
"system_name": "JCB.Compiler.Power.Extractor",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Compiler.Power.Extractor",
"description": "Compiler Power Extractor\r\n@since 3.2.0",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "use Joomla\\CMS\\Factory;",
"composer": ""
}

View File

@ -20,6 +20,8 @@ class Dispenser #Gold {
+ __construct(?Placeholder $placeholder = null, ?Customcode $customcode = null, ...)
+ set(string $script, string $first, ...) : bool
+ get(string $first, string $second, ...) : mixed
# initHub(string $first, ?string $second = null, ...) : void
# setHub(string $script, string $first, ...) : void
}
note right of Dispenser::__construct
@ -70,6 +72,35 @@ note right of Dispenser::get
mixed|null $default = null
string $suffix = ''
end note
note right of Dispenser::initHub
Make sure the hub arrays are all set
default: false
since: 3.2.0
return: void
arguments:
string $first
?string $second = null
?string $third = null
bool $add = false
end note
note right of Dispenser::setHub
Set a script in the hub
default: false
since: 3.2.0
return: void
arguments:
string $script
string $first
?string $second = null
?string $third = null
bool $add = false
end note
@enduml
```

View File

@ -124,39 +124,10 @@ class Dispenser implements DispenserInterface
{
return false;
}
// this needs refactoring (TODO)
if (!isset($this->hub[$first])
|| ($second
&& !isset($this->hub[$first][$second])))
{
// check if the script first key is set
if ($second && !isset($this->hub[$first]))
{
$this->hub[$first] = [];
}
elseif ($add && !$second
&& !isset($this->hub[$first]))
{
$this->hub[$first] = '';
}
// check if the script second key is set
if ($second && $third
&& !isset($this->hub[$first][$second]))
{
$this->hub[$first][$second] = [];
}
elseif ($add && $second && !$third
&& !isset($this->hub[$first][$second]))
{
$this->hub[$first][$second] = '';
}
// check if the script third key is set
if ($add && $second && $third
&& !isset($this->hub[$first][$second][$third]))
{
$this->hub[$first][$second][$third] = '';
}
}
// init all needed arrays
$this->initHub($first, $second, $third, $add);
// prep the script string
if ($base64 && $dynamic)
{
@ -166,7 +137,7 @@ class Dispenser implements DispenserInterface
{
$script = base64_decode($script);
}
elseif ($dynamic) // this does not happen (just incase)
elseif ($dynamic) // this does not happen (just in-case)
{
$script = $this->customcode->update($script);
}
@ -178,49 +149,15 @@ class Dispenser implements DispenserInterface
{
$script = $this->gui->set($script, $config);
}
// add Dynamic HASHING option of a file/string
$script = $this->hash->set($script);
// add base64 locking option of a string
$script = $this->base64->set($script);
// load the script
if ($first && $second && $third)
{
// now act on loading option
if ($add)
{
$this->hub[$first][$second][$third]
.= $script;
}
else
{
$this->hub[$first][$second][$third]
= $script;
}
}
elseif ($first && $second)
{
// now act on loading option
if ($add)
{
$this->hub[$first][$second] .= $script;
}
else
{
$this->hub[$first][$second] = $script;
}
}
else
{
// now act on loading option
if ($add)
{
$this->hub[$first] .= $script;
}
else
{
$this->hub[$first] = $script;
}
}
$this->setHub($script, $first, $second, $third, $add);
return true;
}
@ -240,7 +177,6 @@ class Dispenser implements DispenserInterface
* @param string $suffix The suffix to add after the script if found
*
* @return mixed The string/script if found or the default value if not found
*
* @since 3.2.0
*/
public function get(string $first, string $second, string $prefix = '', ?string $note = null,
@ -279,6 +215,71 @@ class Dispenser implements DispenserInterface
return $script;
}
/**
* Make sure the hub arrays are all set
*
* @param string $first The first key
* @param string|null $second The second key (if not set we use only first key)
* @param string|null $third The third key (if not set we use only first and second key)
* @param bool $add The switch to add to exiting instead of replace
* default: false
*
* @return void
* @since 3.2.0
*/
protected function initHub(string $first, ?string $second = null, ?string $third = null, bool $add = false)
{
if (!isset($this->hub[$first]))
{
$this->hub[$first] = ($second !== null || $add) ? ($second !== null ? [] : '') : [];
}
if ($second !== null && !isset($this->hub[$first][$second]))
{
$this->hub[$first][$second] = ($third !== null || $add) ? ($third !== null ? [] : '') : [];
}
if ($third !== null && !isset($this->hub[$first][$second][$third]))
{
$this->hub[$first][$second][$third] = $add ? '' : [];
}
}
/**
* Set a script in the hub
*
* @param string $script The script
* @param string $first The first key
* @param string|null $second The second key (if not set we use only first key)
* @param string|null $third The third key (if not set we use only first and second key)
* @param bool $add The switch to add to exiting instead of replace
* default: false
*
* @return void
* @since 3.2.0
*/
protected function setHub(string $script, string $first, ?string $second = null, ?string $third = null, bool $add = false)
{
// Load the script
if ($second !== null)
{
if ($third !== null)
{
$this->hub[$first][$second][$third] =
$add ? $this->hub[$first][$second][$third] . $script : $script;
}
else
{
$this->hub[$first][$second] =
$add ? $this->hub[$first][$second] . $script : $script;
}
}
else
{
$this->hub[$first] =
$add ? $this->hub[$first] . $script : $script;
}
}
}

View File

@ -93,39 +93,10 @@
{
return false;
}
// this needs refactoring (TODO)
if (!isset($this->hub[$first])
|| ($second
&& !isset($this->hub[$first][$second])))
{
// check if the script first key is set
if ($second && !isset($this->hub[$first]))
{
$this->hub[$first] = [];
}
elseif ($add && !$second
&& !isset($this->hub[$first]))
{
$this->hub[$first] = '';
}
// check if the script second key is set
if ($second && $third
&& !isset($this->hub[$first][$second]))
{
$this->hub[$first][$second] = [];
}
elseif ($add && $second && !$third
&& !isset($this->hub[$first][$second]))
{
$this->hub[$first][$second] = '';
}
// check if the script third key is set
if ($add && $second && $third
&& !isset($this->hub[$first][$second][$third]))
{
$this->hub[$first][$second][$third] = '';
}
}
// init all needed arrays
$this->initHub($first, $second, $third, $add);
// prep the script string
if ($base64 && $dynamic)
{
@ -135,7 +106,7 @@
{
$script = base64_decode($script);
}
elseif ($dynamic) // this does not happen (just incase)
elseif ($dynamic) // this does not happen (just in-case)
{
$script = $this->customcode->update($script);
}
@ -147,49 +118,15 @@
{
$script = $this->gui->set($script, $config);
}
// add Dynamic HASHING option of a file/string
$script = $this->hash->set($script);
// add base64 locking option of a string
$script = $this->base64->set($script);
// load the script
if ($first && $second && $third)
{
// now act on loading option
if ($add)
{
$this->hub[$first][$second][$third]
.= $script;
}
else
{
$this->hub[$first][$second][$third]
= $script;
}
}
elseif ($first && $second)
{
// now act on loading option
if ($add)
{
$this->hub[$first][$second] .= $script;
}
else
{
$this->hub[$first][$second] = $script;
}
}
else
{
// now act on loading option
if ($add)
{
$this->hub[$first] .= $script;
}
else
{
$this->hub[$first] = $script;
}
}
$this->setHub($script, $first, $second, $third, $add);
return true;
}
@ -209,7 +146,6 @@
* @param string $suffix The suffix to add after the script if found
*
* @return mixed The string/script if found or the default value if not found
*
* @since 3.2.0
*/
public function get(string $first, string $second, string $prefix = '', ?string $note = null,
@ -248,3 +184,69 @@
return $script;
}
/**
* Make sure the hub arrays are all set
*
* @param string $first The first key
* @param string|null $second The second key (if not set we use only first key)
* @param string|null $third The third key (if not set we use only first and second key)
* @param bool $add The switch to add to exiting instead of replace
* default: false
*
* @return void
* @since 3.2.0
*/
protected function initHub(string $first, ?string $second = null, ?string $third = null, bool $add = false)
{
if (!isset($this->hub[$first]))
{
$this->hub[$first] = ($second !== null || $add) ? ($second !== null ? [] : '') : [];
}
if ($second !== null && !isset($this->hub[$first][$second]))
{
$this->hub[$first][$second] = ($third !== null || $add) ? ($third !== null ? [] : '') : [];
}
if ($third !== null && !isset($this->hub[$first][$second][$third]))
{
$this->hub[$first][$second][$third] = $add ? '' : [];
}
}
/**
* Set a script in the hub
*
* @param string $script The script
* @param string $first The first key
* @param string|null $second The second key (if not set we use only first key)
* @param string|null $third The third key (if not set we use only first and second key)
* @param bool $add The switch to add to exiting instead of replace
* default: false
*
* @return void
* @since 3.2.0
*/
protected function setHub(string $script, string $first, ?string $second = null, ?string $third = null, bool $add = false)
{
// Load the script
if ($second !== null)
{
if ($third !== null)
{
$this->hub[$first][$second][$third] =
$add ? $this->hub[$first][$second][$third] . $script : $script;
}
else
{
$this->hub[$first][$second] =
$add ? $this->hub[$first][$second] . $script : $script;
}
}
else
{
$this->hub[$first] =
$add ? $this->hub[$first] . $script : $script;
}
}

View File

@ -139,6 +139,16 @@
"path": "src\/d33b9278-c409-4aec-a047-b72f56712391",
"guid": "d33b9278-c409-4aec-a047-b72f56712391"
},
"eeb03266-22fd-45bb-953a-961bb6be3a54": {
"name": "Extractor",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Compiler\\Power",
"code": "src\/eeb03266-22fd-45bb-953a-961bb6be3a54\/code.php",
"power": "src\/eeb03266-22fd-45bb-953a-961bb6be3a54\/code.power",
"settings": "src\/eeb03266-22fd-45bb-953a-961bb6be3a54\/settings.json",
"path": "src\/eeb03266-22fd-45bb-953a-961bb6be3a54",
"guid": "eeb03266-22fd-45bb-953a-961bb6be3a54"
},
"1fcb13a2-f3f0-4fa8-b8c6-ff9dc546777a": {
"name": "ExternalInterface",
"type": "interface",
@ -189,6 +199,16 @@
"path": "src\/ca111518-e47c-4049-b1b2-cb010f23866f",
"guid": "ca111518-e47c-4049-b1b2-cb010f23866f"
},
"95d0e03f-24fd-4412-bc2e-f0899fcc3205": {
"name": "Parser",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Compiler\\Power",
"code": "src\/95d0e03f-24fd-4412-bc2e-f0899fcc3205\/code.php",
"power": "src\/95d0e03f-24fd-4412-bc2e-f0899fcc3205\/code.power",
"settings": "src\/95d0e03f-24fd-4412-bc2e-f0899fcc3205\/settings.json",
"path": "src\/95d0e03f-24fd-4412-bc2e-f0899fcc3205",
"guid": "95d0e03f-24fd-4412-bc2e-f0899fcc3205"
},
"1bd48df2-4f7e-4581-9fe9-4b54e59105e3": {
"name": "Gui",
"type": "class",
@ -1059,15 +1079,35 @@
"path": "src\/1133c2d7-ba7e-4c95-8cde-01f084d04682",
"guid": "1133c2d7-ba7e-4c95-8cde-01f084d04682"
},
"b836c1b1-b6b1-44f7-b8a2-9a763a4185b1": {
"name": "Power",
"type": "class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Compiler",
"code": "src\/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1\/code.php",
"power": "src\/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1\/code.power",
"settings": "src\/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1\/settings.json",
"path": "src\/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1",
"guid": "b836c1b1-b6b1-44f7-b8a2-9a763a4185b1"
"7c1fb50f-8fb1-4627-8705-6fedf7182ca5": {
"name": "Model",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Power",
"code": "src\/7c1fb50f-8fb1-4627-8705-6fedf7182ca5\/code.php",
"power": "src\/7c1fb50f-8fb1-4627-8705-6fedf7182ca5\/code.power",
"settings": "src\/7c1fb50f-8fb1-4627-8705-6fedf7182ca5\/settings.json",
"path": "src\/7c1fb50f-8fb1-4627-8705-6fedf7182ca5",
"guid": "7c1fb50f-8fb1-4627-8705-6fedf7182ca5"
},
"380bb7a3-cdcc-4336-a699-5070cbf521a5": {
"name": "Insert",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Power\\Database",
"code": "src\/380bb7a3-cdcc-4336-a699-5070cbf521a5\/code.php",
"power": "src\/380bb7a3-cdcc-4336-a699-5070cbf521a5\/code.power",
"settings": "src\/380bb7a3-cdcc-4336-a699-5070cbf521a5\/settings.json",
"path": "src\/380bb7a3-cdcc-4336-a699-5070cbf521a5",
"guid": "380bb7a3-cdcc-4336-a699-5070cbf521a5"
},
"e543c123-b1d9-4a0b-83b2-a9d371da5ff3": {
"name": "Update",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Power\\Database",
"code": "src\/e543c123-b1d9-4a0b-83b2-a9d371da5ff3\/code.php",
"power": "src\/e543c123-b1d9-4a0b-83b2-a9d371da5ff3\/code.power",
"settings": "src\/e543c123-b1d9-4a0b-83b2-a9d371da5ff3\/settings.json",
"path": "src\/e543c123-b1d9-4a0b-83b2-a9d371da5ff3",
"guid": "e543c123-b1d9-4a0b-83b2-a9d371da5ff3"
},
"6784dd52-0909-451a-a872-9a942a023c68": {
"name": "Grep",
@ -1079,6 +1119,26 @@
"path": "src\/6784dd52-0909-451a-a872-9a942a023c68",
"guid": "6784dd52-0909-451a-a872-9a942a023c68"
},
"3ab0eba9-f37b-4b37-aec1-2e78067f2aff": {
"name": "Super",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Power",
"code": "src\/3ab0eba9-f37b-4b37-aec1-2e78067f2aff\/code.php",
"power": "src\/3ab0eba9-f37b-4b37-aec1-2e78067f2aff\/code.power",
"settings": "src\/3ab0eba9-f37b-4b37-aec1-2e78067f2aff\/settings.json",
"path": "src\/3ab0eba9-f37b-4b37-aec1-2e78067f2aff",
"guid": "3ab0eba9-f37b-4b37-aec1-2e78067f2aff"
},
"b836c1b1-b6b1-44f7-b8a2-9a763a4185b1": {
"name": "Power",
"type": "class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Compiler",
"code": "src\/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1\/code.php",
"power": "src\/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1\/code.power",
"settings": "src\/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1\/settings.json",
"path": "src\/b836c1b1-b6b1-44f7-b8a2-9a763a4185b1",
"guid": "b836c1b1-b6b1-44f7-b8a2-9a763a4185b1"
},
"4e6ff11d-bebf-42f5-8fd7-b2f882857222": {
"name": "Line",
"type": "abstract class",
@ -1099,16 +1159,6 @@
"path": "src\/6e64917c-d687-4ef3-a655-811319f5a81e",
"guid": "6e64917c-d687-4ef3-a655-811319f5a81e"
},
"95d0e03f-24fd-4412-bc2e-f0899fcc3205": {
"name": "Parser",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Compiler\\Power",
"code": "src\/95d0e03f-24fd-4412-bc2e-f0899fcc3205\/code.php",
"power": "src\/95d0e03f-24fd-4412-bc2e-f0899fcc3205\/code.power",
"settings": "src\/95d0e03f-24fd-4412-bc2e-f0899fcc3205\/settings.json",
"path": "src\/95d0e03f-24fd-4412-bc2e-f0899fcc3205",
"guid": "95d0e03f-24fd-4412-bc2e-f0899fcc3205"
},
"ff5e9e63-86d0-4691-ab59-d4b9d9154096": {
"name": "Plantuml",
"type": "class",
@ -1229,6 +1279,16 @@
"path": "src\/324566de-0f7d-4b6e-9caf-8424d55013ae",
"guid": "324566de-0f7d-4b6e-9caf-8424d55013ae"
},
"763d137c-42bc-4282-98d8-cc5c0654985f": {
"name": "Injector",
"type": "final class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Compiler\\Power",
"code": "src\/763d137c-42bc-4282-98d8-cc5c0654985f\/code.php",
"power": "src\/763d137c-42bc-4282-98d8-cc5c0654985f\/code.power",
"settings": "src\/763d137c-42bc-4282-98d8-cc5c0654985f\/settings.json",
"path": "src\/763d137c-42bc-4282-98d8-cc5c0654985f",
"guid": "763d137c-42bc-4282-98d8-cc5c0654985f"
},
"de01527a-6586-46ea-92e7-11ea3de1cedb": {
"name": "Power",
"type": "class",