Adds the initial classes needed for the new search feature. Adds the empty view for the search feature. #952

This commit is contained in:
2022-09-14 17:40:02 +02:00
parent 1dddba0fc8
commit d757e14fac
57 changed files with 6293 additions and 177 deletions

View File

@@ -71,11 +71,11 @@ class Placeholder implements PlaceholderInterface
/**
* get all System Placeholders
*
* @return array The global placeholders
* @return array The global placeholders
*
* @since 3.2.0
*/
public function get()
public function get(): array
{
// set only once
if (is_array($this->placeholders))

View File

@@ -12,13 +12,9 @@
namespace VDM\Joomla\Componentbuilder\Compiler;
use Joomla\Registry\Registry;
use Joomla\CMS\Factory;
use Joomla\Input\Input;
use VDM\Joomla\Utilities\Component\Helper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\String\ClassfunctionHelper;
use VDM\Joomla\Componentbuilder\BaseConfig;
/**
@@ -26,119 +22,8 @@ use VDM\Joomla\Utilities\String\ClassfunctionHelper;
*
* @since 3.2.0
*/
class Config extends Registry implements \JsonSerializable, \ArrayAccess, \IteratorAggregate, \Countable
class Config extends BaseConfig
{
/**
* Hold a JInput object for easier access to the input variables.
*
* @var Input
* @since 3.2.0
*/
protected $input;
/**
* The Params
*
* @var Registry
* @since 3.2.0
*/
protected Registry $params;
/**
* Constructor
*
* @param Input|null $input Input
* @param Registry|null $params The component parameters
*
* @throws \Exception
* @since 3.2.0
*/
public function __construct(?Input $input = null, ?Registry $params = null)
{
$this->input = $input ?: Factory::getApplication()->input;
$this->params = $params ?: Helper::getParams('com_componentbuilder');
// use underscore as the separator
$this->separator = '_';
// Instantiate the internal data object.
$this->data = new \stdClass();
}
/**
* setting any config value
*
* @param String $key The value's key/path name
* @param mixed $value Optional default value, returned if the internal value is null.
*
* @since 3.2.0
*/
public function __set($key, $value)
{
$this->set($key, $value);
}
/**
* getting any valid value
*
* @param String $key The value's key/path name
*
* @since 3.2.0
* @throws \InvalidArgumentException If $key is not a valid function name.
*/
public function __get($key)
{
// function name with no underscores
$method = 'get' . ucfirst(ClassfunctionHelper::safe(str_replace('_', '', $key)));
if (($value = $this->get($key, '__N0T_S3T_')) !== '__N0T_S3T_')
{
return $value;
}
elseif (method_exists($this, $method))
{
$value = $this->{$method}();
$this->set($key, $value);
return $value;
}
throw new \InvalidArgumentException(sprintf('Argument %s could not be found as function [%s], or path.', $key, $method));
}
/**
* Get a registry value.
*
* @param string $path Registry path (e.g. joomla.content.showauthor)
* @param mixed $default Optional default value, returned if the internal value is null.
*
* @return mixed Value of entry or null
*
* @since 3.2.0
*/
public function get($path, $default = null)
{
// function name with no underscores
$method = 'get' . ucfirst(ClassfunctionHelper::safe(str_replace('_', '', $path)));
// check if it has been set
if (($value = parent::get($path, '__N0T_S3T_Y3T_')) !== '__N0T_S3T_Y3T_')
{
return $value;
}
elseif (method_exists($this, $method))
{
$value = $this->{$method}();
$this->set($path, $value);
return $value;
}
return $default;
}
/**
* get posted component id
*

View File

@@ -26,6 +26,6 @@ interface PlaceholderInterface
*
* @since 3.2.0
*/
public function get();
public function get(): array;
}

View File

@@ -13,6 +13,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler;
use Joomla\Registry\Registry as JoomlaRegistry;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
/**
@@ -24,6 +25,14 @@ use Joomla\Registry\Registry as JoomlaRegistry;
*/
class Registry extends JoomlaRegistry implements \JsonSerializable, \ArrayAccess, \IteratorAggregate, \Countable
{
/**
* Default indentation value
*
* @var int
* @since 1.0
*/
protected $indent = 2;
/**
* Method to iterate over any part of the registry
*
@@ -43,6 +52,73 @@ class Registry extends JoomlaRegistry implements \JsonSerializable, \ArrayAccess
}
return $data->getIterator();
}
}
/**
* Method to export a set of values to a PHP array
*
* @param string $path Registry path (e.g. joomla.content.showauthor)
* @param int $default The default indentation
*
* @return ?string The var set being exported as a PHP array
*
* @since 3.4.0
*/
public function varExport(string $path, int $default = 2): ?string
{
// check if we have data
if (($data = $this->extract($path)) !== null)
{
// set the default indentation value
$this->indent = $default;
// convert to array
$data = $data->toArray();
// convert to string
$data = var_export($data, true);
// replace all space with system indentation
$data = preg_replace_callback("/^(\s{2})(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(.*)/m", [$this, 'convertIndent'], $data);
// convert all array to []
$array = preg_split("/\r\n|\n|\r/", $data);
$array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ']$1', ' => ['], $array);
$data = join(PHP_EOL, array_filter(["["] + $array));
// add needed indentation to the last ]
$data = preg_replace("/^(\])/m", Indent::_($default) . '$1', $data);
return $data;
}
return null;
}
/**
* Method to convert found of grouped spaces to system indentation
*
* @param array $matches The regex array of matching values
*
* @return string The resulting string.
*
* @since 3.4.0
*/
protected function convertIndent(array $matches): string
{
// set number to indent by default
$indent = Indent::_($this->indent);
// update each found space (group) with one indentation
foreach (range(1, 11) as $space)
{
if (strlen($matches[$space]) > 0)
{
$indent .= Indent::_(1);
}
}
return $indent . $matches[12];
}
}

View File

@@ -44,9 +44,9 @@ abstract class Path
{
foreach ($targets as $target)
{
if (isset($values[$target]) && strpos($values[$target], '\\') !== false)
if (isset($values[$target]))
{
$values[$target] = str_replace('\\', '/', $values[$target]);
self::fix($values[$target], $targets);
}
}
}