Fixed changelog direction so newest changes is listed at top of the file. Finished the init function of super powers. Adds rest function inside super power. Adds super powers to all templates. Updates many helper class methods to now use the utility classes. Adds the method to the component entry file (as-well). Moved most methods from the compiler fields class to powers. #955 Refactored many new builder classes from the registry class. Converted the Content class to two builder classes. Adds option to add additional templates to a module. Resolves #1002 by adding STRING instead of WORD. Ported the FOF encryption class into Powers. https://git.vdm.dev/joomla/fof Changed all CSS and JS to use instead of in compiler code. Adds option to turn jQuery off if UIKIT 3 is added. Adds option to auto write injection boilerplate code in Powers area. Adds option to auto write service provider boilerplate code in the Powers area. Improved the method and all banner locations to fetch from https://git.vdm.dev/joomla/jcb-external/ instead. Major stability improvements all over the new powers complier classes. New [base Registry class](https://git.vdm.dev/joomla/super-powers/src/branch/master/src/7e822c03-1b20-41d1-9427-f5b8d5836af7) has been created specially for JCB. Remember to update all plug-ins with this version update (use the package).
This commit is contained in:
182
libraries/jcb_powers/VDM.Joomla/src/Abstraction/Registry.php
Normal file
182
libraries/jcb_powers/VDM.Joomla/src/Abstraction/Registry.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?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\Abstraction;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\Activeregistryinterface;
|
||||
use VDM\Joomla\Interfaces\Registryinterface;
|
||||
use VDM\Joomla\Abstraction\ActiveRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* VDM Basic Registry.
|
||||
*
|
||||
* Don't use this beyond 10 dimensional depth for best performance.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Registry extends ActiveRegistry implements Activeregistryinterface, Registryinterface
|
||||
{
|
||||
/**
|
||||
* Path separator
|
||||
*
|
||||
* @var string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?string $separator = '.';
|
||||
|
||||
/**
|
||||
* Sets a value into the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(string $path, $value): void
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to set any value.");
|
||||
}
|
||||
|
||||
$this->setActive($value, ...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content into the registry. If a key exists,
|
||||
* it either appends or concatenates based on $asArray switch.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
* @param bool $asArray Determines if the new value should be treated as an array. Default is false.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function add(string $path, $value, bool $asArray = false): void
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to add any value.");
|
||||
}
|
||||
|
||||
$this->addActive($value, $asArray, ...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $default Optional default value, returned if the internal doesn't exist.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return mixed The value or sub-array from the storage. Null if the location doesn't exist.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $path, $default = null)
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to get any value.");
|
||||
}
|
||||
|
||||
return $this->getActive($default, ...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function remove(string $path): void
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to remove any value.");
|
||||
}
|
||||
|
||||
$this->removeActive(...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the existence of a particular location in the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return bool True if the location exists, false otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function exists(string $path): bool
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to check if any value exist.");
|
||||
}
|
||||
|
||||
return $this->existsActive(...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a separator value
|
||||
*
|
||||
* @param string|null $value The value to set.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function setSeparator(?string $value): void
|
||||
{
|
||||
$this->separator = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get that the active keys from a path
|
||||
*
|
||||
* @param string $path The path to determine the location registry.
|
||||
*
|
||||
* @return array|null The valid array of keys
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getActiveKeys(string $path): ?array
|
||||
{
|
||||
// empty path no allowed
|
||||
if ($path === '')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Flatten the path
|
||||
if ($this->separator === null || $this->separator === '')
|
||||
{
|
||||
return [$path];
|
||||
}
|
||||
|
||||
$keys = array_values(array_filter(explode($this->separator, $path), 'strlen'));
|
||||
|
||||
if (empty($keys))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user