update 2024-04-29 11:28:11
This commit is contained in:
parent
37ad7da5ad
commit
42310f5d44
@ -12,22 +12,24 @@
|
|||||||
@startuml
|
@startuml
|
||||||
class FileInjector << (F,LightGreen) >> #RoyalBlue {
|
class FileInjector << (F,LightGreen) >> #RoyalBlue {
|
||||||
# Power $power
|
# Power $power
|
||||||
+ __construct(Power $power)
|
# JoomlaPower $joomla
|
||||||
|
+ __construct(Power $power, JoomlaPower $joomla)
|
||||||
+ add(string $file, string $data, ...) : void
|
+ add(string $file, string $data, ...) : void
|
||||||
- openFileWithLock(string $file) : resource
|
- openFileWithLock(string $file) : resource
|
||||||
- processFile(resource $actual_file, resource $temp_file, ...) : void
|
- processFile(resource $actual_file, resource $temp_file, ...) : void
|
||||||
- truncateIfNeeded(resource $actual_file, string $data, ...) : void
|
- truncateIfNeeded(resource $actual_file, string $data, ...) : void
|
||||||
- copyRemainingData(resource $actual_file, resource $temp_file, ...) : void
|
- copyRemainingData(resource $actual_file, resource $temp_file, ...) : void
|
||||||
- injectSuperPowers(resource $actual_file) : void
|
- injectSuperPowers(resource $actual_file) : void
|
||||||
|
- injectJoomlaPowers(resource $actual_file) : void
|
||||||
}
|
}
|
||||||
|
|
||||||
note right of FileInjector::__construct
|
note right of FileInjector::__construct
|
||||||
Constructor.
|
Constructor.
|
||||||
|
|
||||||
since: 3.2.0
|
since: 3.2.1
|
||||||
end note
|
end note
|
||||||
|
|
||||||
note right of FileInjector::add
|
note left of FileInjector::add
|
||||||
Inserts or replaces data in a file at a specific position.
|
Inserts or replaces data in a file at a specific position.
|
||||||
|
|
||||||
since: 3.2.0
|
since: 3.2.0
|
||||||
@ -47,7 +49,7 @@ note right of FileInjector::openFileWithLock
|
|||||||
return: resource
|
return: resource
|
||||||
end note
|
end note
|
||||||
|
|
||||||
note right of FileInjector::processFile
|
note left of FileInjector::processFile
|
||||||
Processes the file for data insertion and copying the remaining data.
|
Processes the file for data insertion and copying the remaining data.
|
||||||
|
|
||||||
since: 3.2.0
|
since: 3.2.0
|
||||||
@ -73,7 +75,7 @@ note right of FileInjector::truncateIfNeeded
|
|||||||
int $position
|
int $position
|
||||||
end note
|
end note
|
||||||
|
|
||||||
note right of FileInjector::copyRemainingData
|
note left of FileInjector::copyRemainingData
|
||||||
Copies the remaining data from the temporary stream to the actual file.
|
Copies the remaining data from the temporary stream to the actual file.
|
||||||
|
|
||||||
since: 3.2.0
|
since: 3.2.0
|
||||||
@ -92,6 +94,13 @@ note right of FileInjector::injectSuperPowers
|
|||||||
since: 3.2.0
|
since: 3.2.0
|
||||||
return: void
|
return: void
|
||||||
end note
|
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
|
@enduml
|
||||||
```
|
```
|
||||||
|
@ -13,6 +13,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Utilities;
|
|||||||
|
|
||||||
|
|
||||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Injector as Power;
|
use VDM\Joomla\Componentbuilder\Compiler\Power\Injector as Power;
|
||||||
|
use VDM\Joomla\Componentbuilder\Compiler\JoomlaPower\Injector as JoomlaPower;
|
||||||
use VDM\Joomla\Utilities\MathHelper;
|
use VDM\Joomla\Utilities\MathHelper;
|
||||||
|
|
||||||
|
|
||||||
@ -33,23 +34,41 @@ final class FileInjector
|
|||||||
protected Power $power;
|
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
|
* @var string
|
||||||
* @since 3.2.0
|
* @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.
|
* 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->power = $power;
|
||||||
|
$this->joomla = $joomla;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +91,9 @@ final class FileInjector
|
|||||||
throw new \InvalidArgumentException('Position cannot be negative.');
|
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);
|
$actual_file = $this->openFileWithLock($file);
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -85,6 +106,11 @@ final class FileInjector
|
|||||||
|
|
||||||
$this->processFile($actual_file, $temp_file, $data, $position, $replace);
|
$this->processFile($actual_file, $temp_file, $data, $position, $replace);
|
||||||
|
|
||||||
|
if ($found_joomla_powers)
|
||||||
|
{
|
||||||
|
$this->injectJoomlaPowers($actual_file);
|
||||||
|
}
|
||||||
|
|
||||||
if ($found_super_powers)
|
if ($found_super_powers)
|
||||||
{
|
{
|
||||||
$this->injectSuperPowers($actual_file);
|
$this->injectSuperPowers($actual_file);
|
||||||
@ -207,6 +233,28 @@ final class FileInjector
|
|||||||
ftruncate($actual_file, 0);
|
ftruncate($actual_file, 0);
|
||||||
rewind($actual_file);
|
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);
|
fwrite($actual_file, $power_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,23 +7,41 @@
|
|||||||
protected Power $power;
|
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
|
* @var string
|
||||||
* @since 3.2.0
|
* @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.
|
* 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->power = $power;
|
||||||
|
$this->joomla = $joomla;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,7 +64,9 @@
|
|||||||
throw new \InvalidArgumentException('Position cannot be negative.');
|
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);
|
$actual_file = $this->openFileWithLock($file);
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -59,6 +79,11 @@
|
|||||||
|
|
||||||
$this->processFile($actual_file, $temp_file, $data, $position, $replace);
|
$this->processFile($actual_file, $temp_file, $data, $position, $replace);
|
||||||
|
|
||||||
|
if ($found_joomla_powers)
|
||||||
|
{
|
||||||
|
$this->injectJoomlaPowers($actual_file);
|
||||||
|
}
|
||||||
|
|
||||||
if ($found_super_powers)
|
if ($found_super_powers)
|
||||||
{
|
{
|
||||||
$this->injectSuperPowers($actual_file);
|
$this->injectSuperPowers($actual_file);
|
||||||
@ -181,5 +206,27 @@
|
|||||||
ftruncate($actual_file, 0);
|
ftruncate($actual_file, 0);
|
||||||
rewind($actual_file);
|
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);
|
fwrite($actual_file, $power_data);
|
||||||
}
|
}
|
@ -15,6 +15,10 @@
|
|||||||
"as": "Power"
|
"as": "Power"
|
||||||
},
|
},
|
||||||
"use_selection1": {
|
"use_selection1": {
|
||||||
|
"use": "a6052fe9-0d2b-4b36-b3e7-03b47c483542",
|
||||||
|
"as": "JoomlaPower"
|
||||||
|
},
|
||||||
|
"use_selection2": {
|
||||||
"use": "152c8793-8b75-4715-996a-257b9f65451c",
|
"use": "152c8793-8b75-4715-996a-257b9f65451c",
|
||||||
"as": "default"
|
"as": "default"
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,8 @@ class Utilities implements ServiceProviderInterface
|
|||||||
public function getFileInjector(Container $container): FileInjector
|
public function getFileInjector(Container $container): FileInjector
|
||||||
{
|
{
|
||||||
return new FileInjector(
|
return new FileInjector(
|
||||||
$container->get('Power.Injector')
|
$container->get('Power.Injector'),
|
||||||
|
$container->get('Joomla.Power.Injector')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,8 @@
|
|||||||
public function getFileInjector(Container $container): FileInjector
|
public function getFileInjector(Container $container): FileInjector
|
||||||
{
|
{
|
||||||
return new FileInjector(
|
return new FileInjector(
|
||||||
$container->get('Power.Injector')
|
$container->get('Power.Injector'),
|
||||||
|
$container->get('Joomla.Power.Injector')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace VDM\Joomla\Componentbuilder\Compiler\JoomlaPower;
|
namespace VDM\Joomla\Componentbuilder\Compiler\JoomlaPower;
|
||||||
|
|
||||||
|
|
||||||
|
use VDM\Joomla\Utilities\JsonHelper;
|
||||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Power\ExtractorInterface;
|
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Power\ExtractorInterface;
|
||||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor as ExtendingExtractor;
|
use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor as ExtendingExtractor;
|
||||||
|
|
||||||
|
@ -11,7 +11,12 @@
|
|||||||
"power_version": "1.0.0",
|
"power_version": "1.0.0",
|
||||||
"system_name": "JCB.Compiler.JoomlaPower.Extractor",
|
"system_name": "JCB.Compiler.JoomlaPower.Extractor",
|
||||||
"type": "final class",
|
"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",
|
"namespace": "VDM\\Joomla\\Componentbuilder.Compiler.JoomlaPower.Extractor",
|
||||||
"description": "Compiler Joomla Power Extractor\r\n@since 3.2.1",
|
"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 <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",
|
"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",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user