From 42310f5d44e33558ed04dbc47cfb8456e3a32a9d Mon Sep 17 00:00:00 2001 From: aB0t Date: Mon, 29 Apr 2024 11:28:11 +0200 Subject: [PATCH] update 2024-04-29 11:28:11 --- .../README.md | 19 ++++-- .../code.php | 60 +++++++++++++++++-- .../code.power | 59 ++++++++++++++++-- .../settings.json | 4 ++ .../code.php | 3 +- .../code.power | 3 +- .../code.php | 1 + .../settings.json | 7 ++- 8 files changed, 136 insertions(+), 20 deletions(-) diff --git a/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/README.md b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/README.md index dd14dcb..2478920 100644 --- a/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/README.md +++ b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/README.md @@ -12,22 +12,24 @@ @startuml class FileInjector << (F,LightGreen) >> #RoyalBlue { # Power $power - + __construct(Power $power) + # JoomlaPower $joomla + + __construct(Power $power, JoomlaPower $joomla) + add(string $file, string $data, ...) : void - openFileWithLock(string $file) : resource - processFile(resource $actual_file, resource $temp_file, ...) : void - truncateIfNeeded(resource $actual_file, string $data, ...) : void - copyRemainingData(resource $actual_file, resource $temp_file, ...) : void - injectSuperPowers(resource $actual_file) : void + - injectJoomlaPowers(resource $actual_file) : void } note right of FileInjector::__construct Constructor. - since: 3.2.0 + since: 3.2.1 end note -note right of FileInjector::add +note left of FileInjector::add Inserts or replaces data in a file at a specific position. since: 3.2.0 @@ -47,7 +49,7 @@ note right of FileInjector::openFileWithLock return: resource end note -note right of FileInjector::processFile +note left of FileInjector::processFile Processes the file for data insertion and copying the remaining data. since: 3.2.0 @@ -73,7 +75,7 @@ note right of FileInjector::truncateIfNeeded int $position end note -note right of FileInjector::copyRemainingData +note left of FileInjector::copyRemainingData Copies the remaining data from the temporary stream to the actual file. since: 3.2.0 @@ -92,6 +94,13 @@ note right of FileInjector::injectSuperPowers since: 3.2.0 return: void end note + +note left of FileInjector::injectJoomlaPowers + Injects Joomla powers into the file content, if found, and updates the file. + + since: 3.2.1 + return: void +end note @enduml ``` diff --git a/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.php b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.php index 47c9af0..eaf28e2 100644 --- a/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.php +++ b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.php @@ -13,6 +13,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Utilities; use VDM\Joomla\Componentbuilder\Compiler\Power\Injector as Power; +use VDM\Joomla\Componentbuilder\Compiler\JoomlaPower\Injector as JoomlaPower; use VDM\Joomla\Utilities\MathHelper; @@ -33,23 +34,41 @@ final class FileInjector protected Power $power; /** - * The pattern to get the powers + * The Joomla Injector Class. + * + * @var JoomlaPower + * @since 3.2.1 + */ + protected JoomlaPower $joomla; + + /** + * The power pattern to get the powers * * @var string * @since 3.2.0 **/ - protected string $pattern = '/Super_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/'; + protected string $powerPattern = '/Super_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/'; + + /** + * The Joomla power pattern to get the powers + * + * @var string + * @since 3.2.1 + **/ + protected string $joomlaPattern = '/Joomla_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/'; /** * Constructor. * - * @param Power $power The Injector Class. + * @param Power $power The Injector Class. + * @param JoomlaPower $joomla The Joomla Injector Class. * - * @since 3.2.0 + * @since 3.2.1 */ - public function __construct(Power $power) + public function __construct(Power $power, JoomlaPower $joomla) { $this->power = $power; + $this->joomla = $joomla; } /** @@ -72,7 +91,9 @@ final class FileInjector throw new \InvalidArgumentException('Position cannot be negative.'); } - $found_super_powers = preg_match($this->pattern, $data); + $found_joomla_powers = preg_match($this->joomlaPattern, $data); + $found_super_powers = preg_match($this->powerPattern, $data); + $actual_file = $this->openFileWithLock($file); try @@ -85,6 +106,11 @@ final class FileInjector $this->processFile($actual_file, $temp_file, $data, $position, $replace); + if ($found_joomla_powers) + { + $this->injectJoomlaPowers($actual_file); + } + if ($found_super_powers) { $this->injectSuperPowers($actual_file); @@ -207,6 +233,28 @@ final class FileInjector ftruncate($actual_file, 0); rewind($actual_file); + fwrite($actual_file, $power_data); + } + + /** + * Injects Joomla powers into the file content, if found, and updates the file. + * + * @param resource $actual_file The file handle of the actual file. + * + * @return void + * @since 3.2.1 + */ + private function injectJoomlaPowers($actual_file): void + { + rewind($actual_file); + + $power_data = $this->joomla->power( + stream_get_contents($actual_file) + ); + + ftruncate($actual_file, 0); + rewind($actual_file); + fwrite($actual_file, $power_data); } } diff --git a/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.power b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.power index 851a68a..b23c285 100644 --- a/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.power +++ b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/code.power @@ -7,23 +7,41 @@ protected Power $power; /** - * The pattern to get the powers + * The Joomla Injector Class. + * + * @var JoomlaPower + * @since 3.2.1 + */ + protected JoomlaPower $joomla; + + /** + * The power pattern to get the powers * * @var string * @since 3.2.0 **/ - protected string $pattern = '/Super_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/'; + protected string $powerPattern = '/Super_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/'; + + /** + * The Joomla power pattern to get the powers + * + * @var string + * @since 3.2.1 + **/ + protected string $joomlaPattern = '/Joomla_'.'_'.'_[a-zA-Z0-9_]+_'.'_'.'_Power/'; /** * Constructor. * - * @param Power $power The Injector Class. + * @param Power $power The Injector Class. + * @param JoomlaPower $joomla The Joomla Injector Class. * - * @since 3.2.0 + * @since 3.2.1 */ - public function __construct(Power $power) + public function __construct(Power $power, JoomlaPower $joomla) { $this->power = $power; + $this->joomla = $joomla; } /** @@ -46,7 +64,9 @@ throw new \InvalidArgumentException('Position cannot be negative.'); } - $found_super_powers = preg_match($this->pattern, $data); + $found_joomla_powers = preg_match($this->joomlaPattern, $data); + $found_super_powers = preg_match($this->powerPattern, $data); + $actual_file = $this->openFileWithLock($file); try @@ -59,6 +79,11 @@ $this->processFile($actual_file, $temp_file, $data, $position, $replace); + if ($found_joomla_powers) + { + $this->injectJoomlaPowers($actual_file); + } + if ($found_super_powers) { $this->injectSuperPowers($actual_file); @@ -181,5 +206,27 @@ ftruncate($actual_file, 0); rewind($actual_file); + fwrite($actual_file, $power_data); + } + + /** + * Injects Joomla powers into the file content, if found, and updates the file. + * + * @param resource $actual_file The file handle of the actual file. + * + * @return void + * @since 3.2.1 + */ + private function injectJoomlaPowers($actual_file): void + { + rewind($actual_file); + + $power_data = $this->joomla->power( + stream_get_contents($actual_file) + ); + + ftruncate($actual_file, 0); + rewind($actual_file); + fwrite($actual_file, $power_data); } \ No newline at end of file diff --git a/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/settings.json b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/settings.json index 755b25e..d28fe13 100644 --- a/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/settings.json +++ b/src/23f2ca33-440a-4941-8e9a-4bc67522c0cb/settings.json @@ -15,6 +15,10 @@ "as": "Power" }, "use_selection1": { + "use": "a6052fe9-0d2b-4b36-b3e7-03b47c483542", + "as": "JoomlaPower" + }, + "use_selection2": { "use": "152c8793-8b75-4715-996a-257b9f65451c", "as": "default" } diff --git a/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.php b/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.php index 2f4b56a..bf14861 100644 --- a/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.php +++ b/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.php @@ -121,7 +121,8 @@ class Utilities implements ServiceProviderInterface public function getFileInjector(Container $container): FileInjector { return new FileInjector( - $container->get('Power.Injector') + $container->get('Power.Injector'), + $container->get('Joomla.Power.Injector') ); } diff --git a/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.power b/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.power index 3e6c1c9..3ec4950 100644 --- a/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.power +++ b/src/516f93b8-5fff-41c6-aeaf-2d93180a12cc/code.power @@ -84,7 +84,8 @@ public function getFileInjector(Container $container): FileInjector { return new FileInjector( - $container->get('Power.Injector') + $container->get('Power.Injector'), + $container->get('Joomla.Power.Injector') ); } diff --git a/src/82505f3f-297f-4d75-a581-929ab3e93689/code.php b/src/82505f3f-297f-4d75-a581-929ab3e93689/code.php index 043954d..71835a2 100644 --- a/src/82505f3f-297f-4d75-a581-929ab3e93689/code.php +++ b/src/82505f3f-297f-4d75-a581-929ab3e93689/code.php @@ -12,6 +12,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\JoomlaPower; +use VDM\Joomla\Utilities\JsonHelper; use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Power\ExtractorInterface; use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor as ExtendingExtractor; diff --git a/src/82505f3f-297f-4d75-a581-929ab3e93689/settings.json b/src/82505f3f-297f-4d75-a581-929ab3e93689/settings.json index 1f139de..ab56251 100644 --- a/src/82505f3f-297f-4d75-a581-929ab3e93689/settings.json +++ b/src/82505f3f-297f-4d75-a581-929ab3e93689/settings.json @@ -11,7 +11,12 @@ "power_version": "1.0.0", "system_name": "JCB.Compiler.JoomlaPower.Extractor", "type": "final class", - "use_selection": null, + "use_selection": { + "use_selection0": { + "use": "4b225c51-d293-48e4-b3f6-5136cf5c3f18", + "as": "default" + } + }, "namespace": "VDM\\Joomla\\Componentbuilder.Compiler.JoomlaPower.Extractor", "description": "Compiler Joomla Power Extractor\r\n@since 3.2.1", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git 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",