Adds phpseclib version 3.
This commit is contained in:
@@ -564,8 +564,8 @@ class Customcode implements CustomcodeInterface
|
||||
var_dump($this->placeholder->active);
|
||||
}
|
||||
$code['[CUSTOM' . 'CODE=' . $key . ']'] = $placeholder['start']
|
||||
. PHP_EOL . $this->placeholder->update(
|
||||
$item['code'], $this->placeholder->active
|
||||
. PHP_EOL . $this->placeholder->update_(
|
||||
$item['code']
|
||||
) . $placeholder['end'];
|
||||
}
|
||||
// always clear the args
|
||||
@@ -596,8 +596,8 @@ class Customcode implements CustomcodeInterface
|
||||
);
|
||||
$code['[CUSTOM' . 'CODE=' . $keyPlaceholder . ']']
|
||||
= $placeholder['start'] . PHP_EOL
|
||||
. $this->placeholder->update(
|
||||
$item['code'], $this->placeholder->active
|
||||
. $this->placeholder->update_(
|
||||
$item['code']
|
||||
) . $placeholder['end'];
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,10 @@ namespace VDM\Joomla\Componentbuilder\Compiler;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use VDM\Joomla\Componentbuilder\Service\Crypt;
|
||||
use VDM\Joomla\Componentbuilder\Service\Server;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Database;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Model;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\Event;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Service\History;
|
||||
@@ -104,7 +108,11 @@ abstract class Factory implements FactoryInterface
|
||||
*/
|
||||
protected static function createContainer(): Container
|
||||
{
|
||||
$container = (new Container())
|
||||
return (new Container())
|
||||
->registerServiceProvider(new Crypt())
|
||||
->registerServiceProvider(new Server())
|
||||
->registerServiceProvider(new Database())
|
||||
->registerServiceProvider(new Model())
|
||||
->registerServiceProvider(new Compiler())
|
||||
->registerServiceProvider(new Event())
|
||||
->registerServiceProvider(new History())
|
||||
@@ -115,8 +123,6 @@ abstract class Factory implements FactoryInterface
|
||||
->registerServiceProvider(new Component())
|
||||
->registerServiceProvider(new Extension())
|
||||
->registerServiceProvider(new Field());
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -246,13 +246,13 @@ class Data
|
||||
$field->initiator_on_save_model
|
||||
);
|
||||
$field->initiator_save = explode(
|
||||
PHP_EOL, $this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$field->initiator_on_save_model
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$field->initiator_on_save_model
|
||||
)
|
||||
)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (StringHelper::check(
|
||||
@@ -263,29 +263,29 @@ class Data
|
||||
$field->initiator_on_get_model
|
||||
);
|
||||
$field->initiator_get = explode(
|
||||
PHP_EOL, $this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$field->initiator_on_get_model
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$field->initiator_on_get_model
|
||||
)
|
||||
)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
// set the field modelling
|
||||
$field->model_field['save'] = explode(
|
||||
PHP_EOL, $this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
base64_decode($field->on_save_model_field)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode($field->on_save_model_field)
|
||||
)
|
||||
)
|
||||
);
|
||||
$field->model_field['get'] = explode(
|
||||
PHP_EOL, $this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
base64_decode($field->on_get_model_field)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
PHP_EOL, $this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode($field->on_get_model_field)
|
||||
)
|
||||
)
|
||||
);
|
||||
// remove the original values
|
||||
unset(
|
||||
|
@@ -133,8 +133,8 @@ class Name
|
||||
|| strpos($requeSt_id, '_request_catid') !== false)
|
||||
{
|
||||
// keep it then, don't change
|
||||
$name = $this->placeholder->update(
|
||||
$requeSt_id, $this->placeholder->active
|
||||
$name = $this->placeholder->update_(
|
||||
$requeSt_id
|
||||
);
|
||||
}
|
||||
else
|
||||
@@ -146,20 +146,20 @@ class Name
|
||||
if (StringHelper::check($listViewName))
|
||||
{
|
||||
// check if we should use another Text Name as this views name
|
||||
$otherName = $this->placeholder->update(
|
||||
$otherName = $this->placeholder->update_(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'othername="', '"'
|
||||
), $this->placeholder->active
|
||||
)
|
||||
);
|
||||
$otherViews = $this->placeholder->update(
|
||||
$otherViews = $this->placeholder->update_(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'views="', '"'
|
||||
), $this->placeholder->active
|
||||
)
|
||||
);
|
||||
$otherView = $this->placeholder->update(
|
||||
$otherView = $this->placeholder->update_(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'view="', '"'
|
||||
), $this->placeholder->active
|
||||
)
|
||||
);
|
||||
// This is to link other view category
|
||||
if (StringHelper::check($otherName)
|
||||
@@ -198,10 +198,10 @@ class Name
|
||||
{
|
||||
// get value from xml
|
||||
$xml = FieldHelper::safe(
|
||||
$this->placeholder->update(
|
||||
$this->placeholder->update_(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'name="', '"'
|
||||
), $this->placeholder->active
|
||||
)
|
||||
)
|
||||
);
|
||||
// check if a value was found
|
||||
|
@@ -130,12 +130,12 @@ class Validation
|
||||
// open and set the validation rule
|
||||
$this->registry->set("validation.rules.${validation_rule}",
|
||||
$this->gui->set(
|
||||
$this->placeholder->update(
|
||||
$this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$php_code
|
||||
)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
),
|
||||
array(
|
||||
'table' => 'validation_rule',
|
||||
|
@@ -117,7 +117,7 @@ class Extractor
|
||||
if (ArrayHelper::check($lang_string_targets))
|
||||
{
|
||||
// insure string is not broken
|
||||
$content = $this->placeholder->update($content, $this->placeholder->active);
|
||||
$content = $this->placeholder->update_($content);
|
||||
// reset some buckets
|
||||
$lang_holders = array();
|
||||
$lang_check = array();
|
||||
|
@@ -242,9 +242,8 @@ class Power implements PowerInterface
|
||||
$this->active[$guid]->key = $this->active[$guid]->id . '_' . $this->active[$guid]->target_type;
|
||||
|
||||
// now set the name
|
||||
$this->active[$guid]->name = $this->placeholder->update(
|
||||
$this->customcode->update($this->active[$guid]->name),
|
||||
$this->placeholder->active
|
||||
$this->active[$guid]->name = $this->placeholder->update_(
|
||||
$this->customcode->update($this->active[$guid]->name)
|
||||
);
|
||||
|
||||
// now set the code_name and class name
|
||||
@@ -295,12 +294,12 @@ class Power implements PowerInterface
|
||||
$guiMapper['field'] = 'licensing_template';
|
||||
// base64 Decode code
|
||||
$this->active[$guid]->licensing_template = $this->gui->set(
|
||||
$this->placeholder->update(
|
||||
$this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$this->active[$guid]->licensing_template
|
||||
)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
),
|
||||
$guiMapper
|
||||
);
|
||||
@@ -319,12 +318,12 @@ class Power implements PowerInterface
|
||||
|
||||
// base64 Decode code
|
||||
$this->active[$guid]->head = $this->gui->set(
|
||||
$this->placeholder->update(
|
||||
$this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$this->active[$guid]->head
|
||||
)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
),
|
||||
$guiMapper
|
||||
) . PHP_EOL;
|
||||
@@ -338,9 +337,8 @@ class Power implements PowerInterface
|
||||
$this->setComposer($guid);
|
||||
|
||||
// now set the description
|
||||
$this->active[$guid]->description = (StringHelper::check($this->active[$guid]->description)) ? $this->placeholder->update(
|
||||
$this->active[$guid]->description = (StringHelper::check($this->active[$guid]->description)) ? $this->placeholder->update_(
|
||||
$this->customcode->update($this->active[$guid]->description),
|
||||
$this->placeholder->active
|
||||
) : '';
|
||||
|
||||
// add the main code if set
|
||||
@@ -350,12 +348,12 @@ class Power implements PowerInterface
|
||||
$guiMapper['field'] = 'main_class_code';
|
||||
// base64 Decode code
|
||||
$this->active[$guid]->main_class_code = $this->gui->set(
|
||||
$this->placeholder->update(
|
||||
$this->placeholder->update_(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$this->active[$guid]->main_class_code
|
||||
)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
),
|
||||
$guiMapper
|
||||
);
|
||||
@@ -399,8 +397,8 @@ class Power implements PowerInterface
|
||||
protected function setNamespace(string $guid)
|
||||
{
|
||||
// set namespace
|
||||
$this->active[$guid]->namespace = $this->placeholder->update(
|
||||
$this->active[$guid]->namespace, $this->placeholder->active
|
||||
$this->active[$guid]->namespace = $this->placeholder->update_(
|
||||
$this->active[$guid]->namespace
|
||||
);
|
||||
|
||||
// validate namespace
|
||||
@@ -614,8 +612,23 @@ class Power implements PowerInterface
|
||||
if (isset($_namespace['use']) && StringHelper::check($_namespace['use']) &&
|
||||
strpos($_namespace['use'], '\\') !== false)
|
||||
{
|
||||
// trim possible use or ; added to the namespace
|
||||
$namespace = $this->getCleanNamespace($_namespace['use']);
|
||||
// add the namespace to this access point
|
||||
$as = 'default';
|
||||
if (strpos($_namespace['use'], ' as ') !== false)
|
||||
{
|
||||
$namespace_as = explode(' as ', $_namespace['use']);
|
||||
// make sure the AS value is set
|
||||
if (count($namespace_as) == 2)
|
||||
{
|
||||
$as = trim(trim($namespace_as[1], ';'));
|
||||
}
|
||||
$namespace = $this->getCleanNamespace($namespace_as[0], false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// trim possible use or ; added to the namespace
|
||||
$namespace = $this->getCleanNamespace($_namespace['use'], false);
|
||||
}
|
||||
|
||||
// check if still valid
|
||||
if (!StringHelper::check($namespace))
|
||||
@@ -624,13 +637,7 @@ class Power implements PowerInterface
|
||||
}
|
||||
|
||||
// add to the header of the class
|
||||
$this->addToHeader($guid, $this->getUseNamespace($namespace));
|
||||
|
||||
// add the namespace to this access point
|
||||
if (strpos($namespace, ' as ') !== false)
|
||||
{
|
||||
$namespace = $this->getCleanNamespace(explode(' as ', $namespace)[0]);
|
||||
}
|
||||
$this->addToHeader($guid, $this->getUseNamespace($namespace, $as));
|
||||
|
||||
// add composer namespaces for autoloader
|
||||
$this->composer[$namespace] = $composer['access_point'];
|
||||
@@ -669,9 +676,8 @@ class Power implements PowerInterface
|
||||
if ($implement == -1
|
||||
&& StringHelper::check($this->active[$guid]->implements_custom))
|
||||
{
|
||||
$this->active[$guid]->implement_names[] = $this->placeholder->update(
|
||||
$this->customcode->update($this->active[$guid]->implements_custom),
|
||||
$this->placeholder->active
|
||||
$this->active[$guid]->implement_names[] = $this->placeholder->update_(
|
||||
$this->customcode->update($this->active[$guid]->implements_custom)
|
||||
);
|
||||
// just add this once
|
||||
unset($this->active[$guid]->implements_custom);
|
||||
@@ -710,9 +716,8 @@ class Power implements PowerInterface
|
||||
if ($this->active[$guid]->extends == -1
|
||||
&& StringHelper::check($this->active[$guid]->extends_custom))
|
||||
{
|
||||
$this->active[$guid]->extends_name = $this->placeholder->update(
|
||||
$this->customcode->update($this->active[$guid]->extends_custom),
|
||||
$this->placeholder->active
|
||||
$this->active[$guid]->extends_name = $this->placeholder->update_(
|
||||
$this->customcode->update($this->active[$guid]->extends_custom)
|
||||
);
|
||||
// just add once
|
||||
unset($this->active[$guid]->extends_custom);
|
||||
@@ -771,15 +776,16 @@ class Power implements PowerInterface
|
||||
/**
|
||||
* Get Clean Namespace without use or ; as part of the name space
|
||||
*
|
||||
* @param string $namespace The actual name space
|
||||
* @param string $namespace The actual name space
|
||||
* @input bool $removeNumbers The switch to remove numers
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getCleanNamespace(string $namespace): string
|
||||
protected function getCleanNamespace(string $namespace, bool $removeNumbers = true): string
|
||||
{
|
||||
// trim possible (use) or (;) or (starting or ending \) added to the namespace
|
||||
return NamespaceHelper::safe(str_replace(['use ', ';'], '', $namespace));
|
||||
return NamespaceHelper::safe(str_replace(['use ', ';'], '', $namespace), $removeNumbers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -90,34 +90,34 @@ class Autoloader
|
||||
$use_plugin = $this->content->exist('PLUGIN_POWER_AUTOLOADER');
|
||||
|
||||
// build the methods
|
||||
$autoloadNotSiteMethod = array();
|
||||
$autoloadMethod = array();
|
||||
$autoload_not_site_method = [];
|
||||
$autoload_method = [];
|
||||
|
||||
// add only if we are not using a plugin
|
||||
$tab_space = 2;
|
||||
if (!$use_plugin)
|
||||
{
|
||||
$autoloadNotSiteMethod[] = PHP_EOL . PHP_EOL;
|
||||
$autoload_not_site_method[] = PHP_EOL . PHP_EOL;
|
||||
$tab_space = 0;
|
||||
}
|
||||
elseif (!$loadSite)
|
||||
{
|
||||
// we add code to prevent this plugin from triggering on the site area
|
||||
$autoloadNotSiteMethod[] = PHP_EOL . Indent::_(2) . '//'
|
||||
$autoload_not_site_method[] = PHP_EOL . Indent::_(2) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' do not run the autoloader in the site area';
|
||||
$autoloadNotSiteMethod[] = Indent::_(2) . 'if ($this->app->isClient(\'site\'))';
|
||||
$autoloadNotSiteMethod[] = Indent::_(2) . '{';
|
||||
$autoloadNotSiteMethod[] = Indent::_(3) . 'return;';
|
||||
$autoloadNotSiteMethod[] = Indent::_(2) . '}' . PHP_EOL;
|
||||
$autoload_not_site_method[] = Indent::_(2) . 'if ($this->app->isClient(\'site\'))';
|
||||
$autoload_not_site_method[] = Indent::_(2) . '{';
|
||||
$autoload_not_site_method[] = Indent::_(3) . 'return;';
|
||||
$autoload_not_site_method[] = Indent::_(2) . '}' . PHP_EOL;
|
||||
}
|
||||
|
||||
// we start building the spl_autoload_register function call
|
||||
$autoloadMethod[] = Indent::_($tab_space) . '//'
|
||||
$autoload_method[] = Indent::_($tab_space) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' register this component namespace';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . 'spl_autoload_register(function ($class) {';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
$autoload_method[] = Indent::_($tab_space) . 'spl_autoload_register(function ($class) {';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' project-specific base directories and namespace prefix';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$search = array(';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '$search = [';
|
||||
|
||||
// ==== IMPORTANT NOTICE =====
|
||||
// make sure the name space values are sorted from the longest string to the shortest
|
||||
@@ -142,62 +142,73 @@ class Autoloader
|
||||
// don't add the ending comma on last value
|
||||
if ($size == $counter)
|
||||
{
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . "'" . $this->config->get('jcb_powers_path', 'libraries/jcb_powers') . "/$base_dir' => '" . implode('\\\\', $prefix) . "'";
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . "'" . $this->config->get('jcb_powers_path', 'libraries/jcb_powers') . "/$base_dir' => '" . implode('\\\\', $prefix) . "'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . "'" . $this->config->get('jcb_powers_path', 'libraries/jcb_powers') . "/$base_dir' => '" . implode('\\\\', $prefix) . "',";
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . "'" . $this->config->get('jcb_powers_path', 'libraries/jcb_powers') . "/$base_dir' => '" . implode('\\\\', $prefix) . "',";
|
||||
}
|
||||
$counter++;
|
||||
}
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . ');';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '// Start the search and load if found';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$found = false;';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$found_base_dir = "";';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$found_len = 0;';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . 'foreach ($search as $base_dir => $prefix)';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '{';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '//'
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '];';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '// Start the search and load if found';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '$found = false;';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '$found_base_dir = "";';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '$found_len = 0;';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . 'foreach ($search as $base_dir => $prefix)';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '{';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' does the class use the namespace prefix?';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '$len = strlen($prefix);';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . 'if (strncmp($prefix, $class, $len) === 0)';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '{';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '//'
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . '$len = strlen($prefix);';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . 'if (strncmp($prefix, $class, $len) === 0)';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . '{';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(3) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' we have a match so load the values';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '$found = true;';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '$found_base_dir = $base_dir;';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '$found_len = $len;';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . '//'
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(3) . '$found = true;';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(3) . '$found_base_dir = $base_dir;';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(3) . '$found_len = $len;';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(3) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' done here';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(3) . 'break;';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '}';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '}';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(3) . 'break;';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . '}';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '}';
|
||||
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' check if we found a match';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . 'if (!$found)';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '{';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' no, move to the next registered autoloader';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . 'return;';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '}';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . 'if (!$found)';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '{';
|
||||
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' not found so move to the next registered autoloader';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . 'return;';
|
||||
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '}';
|
||||
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' get the relative class name';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$relative_class = substr($class, $found_len);';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '$relative_class = substr($class, $found_len);';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' replace the namespace prefix with the base directory, replace namespace';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '// separators with directory separators in the relative class name, append';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '// with .php';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . "\$file = JPATH_ROOT . '/' . \$found_base_dir . '/src' . str_replace('\\\\', '/', \$relative_class) . '.php';";
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '// separators with directory separators in the relative class name, append';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '// with .php';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . "\$file = JPATH_ROOT . '/' . \$found_base_dir . '/src' . str_replace('\\\\', '/', \$relative_class) . '.php';";
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' if the file exists, require it';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . 'if (file_exists($file))';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '{';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . 'require $file;';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '}';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . '});';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . 'if (file_exists($file))';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '{';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(2) . 'require $file;';
|
||||
$autoload_method[] = Indent::_($tab_space) . Indent::_(1) . '}';
|
||||
$autoload_method[] = Indent::_($tab_space) . '});';
|
||||
|
||||
// add the composer stuff here
|
||||
$autoload_composer = '';
|
||||
if (ArrayHelper::check($this->power->composer))
|
||||
{
|
||||
$autoload_composer = $this->getComposer($tab_space);
|
||||
}
|
||||
|
||||
// create the method string
|
||||
$autoloader = implode(PHP_EOL, $autoloadNotSiteMethod) . implode(PHP_EOL, $autoloadMethod);
|
||||
$autoloader = $autoload_composer . implode(PHP_EOL, $autoload_not_site_method) . implode(PHP_EOL, $autoload_method);
|
||||
|
||||
// check if we are using a plugin
|
||||
if ($use_plugin)
|
||||
@@ -216,9 +227,53 @@ class Autoloader
|
||||
}
|
||||
|
||||
// to add to custom files
|
||||
$this->content->add('CUSTOM_POWER_AUTOLOADER', PHP_EOL . implode(PHP_EOL, $autoloadMethod));
|
||||
$this->content->add('CUSTOM_POWER_AUTOLOADER', PHP_EOL . implode(PHP_EOL, $autoload_method));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the composer autoloader routine
|
||||
*
|
||||
* @param string $tabSpace The dynamic tab spacer
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getComposer(string $tabSpace): string
|
||||
{
|
||||
// load the composer routine
|
||||
$composer_routine = [];
|
||||
|
||||
// counter to manage the comma in the actual array
|
||||
$add_once = [];
|
||||
foreach ($this->power->composer as $access_point)
|
||||
{
|
||||
// don't add the ending comma on last value
|
||||
if (empty($add_once[$access_point]))
|
||||
{
|
||||
$composer_routine[] = Indent::_($tabSpace) . "\$composer_autoloader = JPATH_LIBRARIES . '/$access_point';";
|
||||
$composer_routine[] = Indent::_($tabSpace) . 'if (file_exists($composer_autoloader))';
|
||||
$composer_routine[] = Indent::_($tabSpace) . "{";
|
||||
$composer_routine[] = Indent::_($tabSpace) . Indent::_(1) . 'require_once $composer_autoloader;';
|
||||
$composer_routine[] = Indent::_($tabSpace) . "}";
|
||||
|
||||
$add_once[$access_point] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($add_once) == 1)
|
||||
{
|
||||
array_unshift($composer_routine, PHP_EOL . PHP_EOL . Indent::_($tabSpace) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' add the autoloader for the composer classes');
|
||||
}
|
||||
else
|
||||
{
|
||||
array_unshift($composer_routine, PHP_EOL . PHP_EOL . Indent::_($tabSpace) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' add the autoloaders for the composer classes');
|
||||
}
|
||||
|
||||
return implode(PHP_EOL, $composer_routine);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -78,12 +78,13 @@ interface Tableinterface
|
||||
/**
|
||||
* Get all fields of an area/view/table
|
||||
*
|
||||
* @param string|null $table The area
|
||||
* @param string $table The area
|
||||
* @param bool $default Add the default fields
|
||||
*
|
||||
* @return ?array
|
||||
* @return array|null On success an array of fields
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function fields(string $table): ?array;
|
||||
public function fields(string $table, bool $default = false): ?array;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@ namespace VDM\Joomla\Componentbuilder\Package;
|
||||
use Joomla\DI\Container;
|
||||
use VDM\Joomla\Componentbuilder\Service\Crypt;
|
||||
use VDM\Joomla\Componentbuilder\Package\Service\Database;
|
||||
use VDM\Joomla\Componentbuilder\Service\Server;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\FactoryInterface;
|
||||
|
||||
|
||||
@@ -70,11 +71,10 @@ abstract class Factory implements FactoryInterface
|
||||
*/
|
||||
protected static function createContainer(): Container
|
||||
{
|
||||
$container = (new Container())
|
||||
return (new Container())
|
||||
->registerServiceProvider(new Database())
|
||||
->registerServiceProvider(new Crypt());
|
||||
|
||||
return $container;
|
||||
->registerServiceProvider(new Crypt())
|
||||
->registerServiceProvider(new Server());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -14,10 +14,10 @@ namespace VDM\Joomla\Componentbuilder\Package\Service;
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Package\Database\Load as LoadDatabase;
|
||||
use VDM\Joomla\Componentbuilder\Database\Load;
|
||||
use VDM\Joomla\Componentbuilder\Package\Database\Insert as InsertDatabase;
|
||||
use VDM\Joomla\Componentbuilder\Database\Insert;
|
||||
use VDM\Joomla\Componentbuilder\Package\Database\Load as LoadDatabase;
|
||||
use VDM\Joomla\Componentbuilder\Package\Database\Insert as InsertDatabase;
|
||||
|
||||
|
||||
/**
|
||||
@@ -40,12 +40,12 @@ class Database implements ServiceProviderInterface
|
||||
$container->alias(Load::class, 'Load')
|
||||
->share('Load', [$this, 'getLoad'], true);
|
||||
|
||||
$container->alias(LoadDatabase::class, 'Load.Database')
|
||||
->share('Load.Database', [$this, 'getDatabaseLoad'], true);
|
||||
|
||||
$container->alias(Insert::class, 'Insert')
|
||||
->share('Insert', [$this, 'getInsert'], true);
|
||||
|
||||
$container->alias(LoadDatabase::class, 'Load.Database')
|
||||
->share('Load.Database', [$this, 'getDatabaseLoad'], true);
|
||||
|
||||
$container->alias(InsertDatabase::class, 'Insert.Database')
|
||||
->share('Insert.Database', [$this, 'getDatabaseInsert'], true);
|
||||
}
|
||||
@@ -63,6 +63,19 @@ class Database implements ServiceProviderInterface
|
||||
return new Load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Load Database
|
||||
*
|
||||
@@ -79,19 +92,6 @@ class Database implements ServiceProviderInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Insert Database
|
||||
*
|
||||
|
@@ -1,191 +0,0 @@
|
||||
<?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\Search\Abstraction;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
|
||||
|
||||
/**
|
||||
* Search Model
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Model
|
||||
{
|
||||
/**
|
||||
* Last ID
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $last;
|
||||
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Search Table
|
||||
*
|
||||
* @var Table
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Table $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Table|null $table The search table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Table $table = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->table = $table ?: Factory::_('Table');
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the values of an item
|
||||
* Example: $this->item('table_name', Object);
|
||||
*
|
||||
* @param object $item The item object
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?string $table = null): ?object
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// field counter
|
||||
$field_number = 0;
|
||||
|
||||
// check if this is a valid table
|
||||
if (($fields = $this->table->fields($table)) !== null)
|
||||
{
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
// model a value if it exists
|
||||
if(isset($item->{$field}))
|
||||
{
|
||||
$item->{$field} = $this->value($item->{$field}, $field, $table);
|
||||
|
||||
// remove empty values
|
||||
if (!StringHelper::check($item->{$field}) && !ArrayHelper::check($item->{$field}, true))
|
||||
{
|
||||
unset($item->{$field});
|
||||
}
|
||||
else
|
||||
{
|
||||
$field_number++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// all items must have more than one field or its empty (1 = id)
|
||||
if ($field_number > 1)
|
||||
{
|
||||
return $item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the values of multiple items
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $items The array of item objects
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null): ?array
|
||||
{
|
||||
// check if this is a valid table
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
foreach ($items as $id => &$item)
|
||||
{
|
||||
// model the item
|
||||
if (($item = $this->item($item, $table)) !== null)
|
||||
{
|
||||
// add the last ID
|
||||
$this->last[$table] = $item->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($items[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last modeled ID
|
||||
* Example: $this->last('table_name');
|
||||
*
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function last(?string $table = null): ?int
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ($table && isset($this->last[$table]))
|
||||
{
|
||||
return $this->last[$table];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -141,7 +141,7 @@ class Load implements LoadInterface
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ($id > 0 && ($fields = $this->getFields($table)) !== null &&
|
||||
if ($id > 0 && ($fields = $this->setDatabaseFields($table)) !== null &&
|
||||
($item = $this->load->item(
|
||||
$fields, // select
|
||||
['a' => $table], // tables
|
||||
@@ -174,7 +174,7 @@ class Load implements LoadInterface
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ( ($fields = $this->getFields($table)) !== null)
|
||||
if ( ($fields = $this->setDatabaseFields($table)) !== null)
|
||||
{
|
||||
// add a key to the selection return set
|
||||
$fields['key'] = 'id';
|
||||
@@ -273,11 +273,13 @@ class Load implements LoadInterface
|
||||
* Get Fields ready to use in database call
|
||||
*
|
||||
* @param string $table The table which fields we want to get
|
||||
* @param string $key The table key to which the fields belong
|
||||
* @param bool $addId The switch to add ID
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getFields(string $table, string $key = 'a', bool $addId = true): ?array
|
||||
protected function setDatabaseFields(string $table, string $key = 'a', bool $addId = true): ?array
|
||||
{
|
||||
if (($fields = $this->table->fields($table)) !== null)
|
||||
{
|
||||
|
@@ -72,13 +72,11 @@ abstract class Factory implements FactoryInterface
|
||||
*/
|
||||
protected static function createContainer(): Container
|
||||
{
|
||||
$container = (new Container())
|
||||
return (new Container())
|
||||
->registerServiceProvider(new Search())
|
||||
->registerServiceProvider(new Model())
|
||||
->registerServiceProvider(new Database())
|
||||
->registerServiceProvider(new Agent());
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,71 +0,0 @@
|
||||
<?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\Search\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Search Model Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface ModelInterface
|
||||
{
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'value_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);
|
||||
|
||||
/**
|
||||
* Model the values of an item
|
||||
* Example: $this->item(Object, 'table_name');
|
||||
*
|
||||
* @param object $item The item object
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(object $item, ?string $table = null): ?object;
|
||||
|
||||
/**
|
||||
* Model the values of multiple items
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $items The array of item objects
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null): ?array;
|
||||
|
||||
/**
|
||||
* Get last modeled ID
|
||||
* Example: $this->last('table_name');
|
||||
*
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function last(?string $table = null): ?int;
|
||||
|
||||
}
|
||||
|
@@ -12,8 +12,11 @@
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Model;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Abstraction\Model;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Componentbuilder\Abstraction\Model;
|
||||
|
||||
|
||||
/**
|
||||
@@ -23,6 +26,29 @@ use VDM\Joomla\Componentbuilder\Search\Abstraction\Model;
|
||||
*/
|
||||
class Insert extends Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Table|null $table The search table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Table $table = null)
|
||||
{
|
||||
parent::__construct($table ?? Factory::_('Table'));
|
||||
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'field_key', 'table_name');
|
||||
@@ -39,7 +65,7 @@ class Insert extends Model implements ModelInterface
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
@@ -49,15 +75,27 @@ class Insert extends Model implements ModelInterface
|
||||
switch($store)
|
||||
{
|
||||
case 'base64':
|
||||
$value = \base64_encode($value);
|
||||
$value = base64_encode($value);
|
||||
break;
|
||||
case 'json':
|
||||
$value = \json_encode($value, JSON_FORCE_OBJECT);
|
||||
$value = json_encode($value, JSON_FORCE_OBJECT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return $this->config->table_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -12,10 +12,13 @@
|
||||
namespace VDM\Joomla\Componentbuilder\Search\Model;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Table;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Search\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Componentbuilder\Search\Abstraction\Model;
|
||||
use VDM\Joomla\Componentbuilder\Interfaces\ModelInterface;
|
||||
use VDM\Joomla\Componentbuilder\Abstraction\Model;
|
||||
|
||||
|
||||
/**
|
||||
@@ -25,6 +28,29 @@ use VDM\Joomla\Componentbuilder\Search\Abstraction\Model;
|
||||
*/
|
||||
class Load extends Model implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* Search Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Table|null $table The search table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Table $table = null)
|
||||
{
|
||||
parent::__construct($table ?? Factory::_('Table'));
|
||||
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'value_key', 'table_name');
|
||||
@@ -41,7 +67,7 @@ class Load extends Model implements ModelInterface
|
||||
// load the table
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
@@ -51,19 +77,30 @@ class Load extends Model implements ModelInterface
|
||||
switch($store)
|
||||
{
|
||||
case 'base64':
|
||||
$value = \base64_decode($value);
|
||||
$value = base64_decode($value);
|
||||
break;
|
||||
case 'json':
|
||||
// check if there is a json string
|
||||
if (JsonHelper::check($value))
|
||||
{
|
||||
$value = \json_decode($value, true);
|
||||
$value = json_decode($value, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTable(): string
|
||||
{
|
||||
return $this->config->table_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -14,9 +14,12 @@ namespace VDM\Joomla\Componentbuilder\Service;
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use phpseclibthree\Crypt\AES;
|
||||
use phpseclibthree\Crypt\Rijndael;
|
||||
use phpseclibthree\Crypt\DES;
|
||||
use phpseclib3\Crypt\AES;
|
||||
use phpseclib3\Crypt\Rijndael;
|
||||
use phpseclib3\Crypt\DES;
|
||||
use VDM\Joomla\Componentbuilder\Crypt as Crypto;
|
||||
use VDM\Joomla\Componentbuilder\Crypt\KeyLoader;
|
||||
use VDM\Joomla\Componentbuilder\Crypt\Random;
|
||||
|
||||
|
||||
/**
|
||||
@@ -36,8 +39,18 @@ class Crypt implements ServiceProviderInterface
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(Crypto::class, 'Crypt')
|
||||
->share('Crypt', [$this, 'getCrypt'], true);
|
||||
|
||||
$container->alias(Random::class, 'Crypt.Random')
|
||||
->share('Crypt.Random', [$this, 'getRandom'], true);
|
||||
|
||||
$container->alias(KeyLoader::class, 'Crypt.Key')
|
||||
->share('Crypt.Key', [$this, 'getKeyLoader'], true);
|
||||
|
||||
$container->alias(AES::class, 'Crypt.AES')
|
||||
->share('Crypt.AES', [$this, 'getAesCBC'], true)
|
||||
->share('Crypt.AES.CBC', [$this, 'getAesCBC'], true)
|
||||
->share('Crypt.AES.CTR', [$this, 'getAesCTR'], true)
|
||||
->share('Crypt.AES.ECB', [$this, 'getAesECB'], true)
|
||||
->share('Crypt.AES.CBC3', [$this, 'getAesCBC3'], true)
|
||||
@@ -48,6 +61,7 @@ class Crypt implements ServiceProviderInterface
|
||||
|
||||
$container->alias(Rijndael::class, 'Crypt.Rijndael')
|
||||
->share('Crypt.Rijndael', [$this, 'getRijndaelCBC'], true)
|
||||
->share('Crypt.Rijndael.CBC', [$this, 'getRijndaelCBC'], true)
|
||||
->share('Crypt.Rijndael.CTR', [$this, 'getRijndaelCTR'], true)
|
||||
->share('Crypt.Rijndael.ECB', [$this, 'getRijndaelECB'], true)
|
||||
->share('Crypt.Rijndael.CBC3', [$this, 'getRijndaelCBC3'], true)
|
||||
@@ -58,6 +72,7 @@ class Crypt implements ServiceProviderInterface
|
||||
|
||||
$container->alias(DES::class, 'Crypt.DES')
|
||||
->share('Crypt.DES', [$this, 'getDesCBC'], true)
|
||||
->share('Crypt.DES.CBC', [$this, 'getDesCBC'], true)
|
||||
->share('Crypt.DES.CTR', [$this, 'getDesCTR'], true)
|
||||
->share('Crypt.DES.ECB', [$this, 'getDesECB'], true)
|
||||
->share('Crypt.DES.CBC3', [$this, 'getDesCBC3'], true)
|
||||
@@ -68,6 +83,45 @@ class Crypt implements ServiceProviderInterface
|
||||
->share('Crypt.DES.STREAM', [$this, 'getDesSTREAM'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Crypto class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Crypto
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getCrypt(Container $container): Crypto
|
||||
{
|
||||
return new Crypto();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Random class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Random
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getRandom(Container $container): Random
|
||||
{
|
||||
return new Random();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the KeyLoader class
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return KeyLoader
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getKeyLoader(Container $container): KeyLoader
|
||||
{
|
||||
return new KeyLoader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the AES Cyper with CBC mode
|
||||
*
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -25,32 +25,44 @@ abstract class NamespaceHelper
|
||||
/**
|
||||
* Making namespace safe
|
||||
*
|
||||
* @input string The you would like to make safe
|
||||
* @input string $string The you would like to make safe
|
||||
* @input bool $removeNumbers The switch to remove numbers
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe($string)
|
||||
public static function safe(string $string, bool $removeNumbers = true)
|
||||
{
|
||||
// 0nly continue if we have a string
|
||||
// 0nly continue if we have a string with length
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
// make sure it has not numbers
|
||||
$string = StringHelper::numbers($string);
|
||||
if ($removeNumbers)
|
||||
{
|
||||
$string = StringHelper::numbers($string);
|
||||
}
|
||||
|
||||
// Transliterate string TODO: look again as this make it lowercase
|
||||
// Transliterate string TODO: look again as this makes it lowercase
|
||||
// $string = StringHelper::transliterate($string);
|
||||
|
||||
// first remove all [\] backslashes
|
||||
$string = str_replace('\\', '1', $string);
|
||||
$string = str_replace('\\', '+', $string);
|
||||
|
||||
// remove all and keep only characters and [\] backslashes inside of the string
|
||||
$string = trim( preg_replace("/[^A-Za-z1]/", '', $string), '1');
|
||||
if ($removeNumbers)
|
||||
{
|
||||
$string = trim( preg_replace("/[^A-Za-z\+]/", '', $string), '+');
|
||||
}
|
||||
else
|
||||
{
|
||||
$string = trim( preg_replace("/[^A-Za-z0-9\+]/", '', $string), '+');
|
||||
}
|
||||
|
||||
// place the [\] backslashes back
|
||||
return trim( preg_replace("/1+/", '\\', $string));
|
||||
return trim( preg_replace("/\++/", '\\', $string));
|
||||
}
|
||||
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
Reference in New Issue
Block a user