Adds phpseclib version 3.

This commit is contained in:
Llewellyn van der Merwe 2022-12-29 08:12:03 +02:00
parent d28e4c74af
commit e614f2ec23
Signed by: Llewellyn
GPG Key ID: A9201372263741E7
412 changed files with 66550 additions and 477 deletions

View File

@ -140,14 +140,14 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015
+ *Last Build*: 18th December, 2022
+ *Last Build*: 29th December, 2023
+ *Version*: 3.1.13
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **337557**
+ *Line count*: **341727**
+ *Field count*: **2009**
+ *File count*: **2207**
+ *Folder count*: **388**
+ *File count*: **2222**
+ *Folder count*: **391**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
> Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)

View File

@ -140,14 +140,14 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015
+ *Last Build*: 18th December, 2022
+ *Last Build*: 29th December, 2023
+ *Version*: 3.1.13
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **337557**
+ *Line count*: **341727**
+ *Field count*: **2009**
+ *File count*: **2207**
+ *Folder count*: **388**
+ *File count*: **2222**
+ *Folder count*: **391**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
> Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)

View File

@ -5294,13 +5294,14 @@ class Fields extends Structure
}
$this->setLayoutBuilder($nameSingleCode, $tabName, $name, $field);
// only load fields we want to search
if ($dbSwitch && ComponentbuilderHelper::fieldCheck($typeName, 'search'))
// load all fields that are in the database
if ($dbSwitch)
{
// load a search array of view, field, and [encryption, type, tab]
CFactory::_('Registry')->set('all_search_fields.' . $nameSingleCode . '.' . $name,
// load array of view, field, and [encryption, type, tab]
CFactory::_('Registry')->set('all_component_fields.' . $nameSingleCode . '.' . $name,
[
'name' => $name,
'label' => $langLabel,
'type' => $typeName,
'title' => (isset($this->titleBuilder[$nameSingleCode]) && $name === $this->titleBuilder[$nameSingleCode]) ? true : false,
'list' => $nameListCode,

View File

@ -24403,7 +24403,7 @@ class Interpretation extends Fields
CFactory::_('Language')->set(
CFactory::_('Config')->lang_target, $lang . '_GLOBAL_DESC', "The Global Parameters"
);
// add auto checin if required
// add auto checkin if required
if ($this->addCheckin)
{
$this->configFieldSets[] = Indent::_(2) . "<field";

View File

@ -1037,7 +1037,7 @@ class Infusion extends Interpretation
}
// all fields stored in database
CFactory::_('Content')->set('ARRAY_ALL_SEARCH_FIELDS', CFactory::_('Registry')->varExport('all_search_fields', 1));
CFactory::_('Content')->set('ALL_COMPONENT_FIELDS', CFactory::_('Registry')->varExport('all_component_fields', 1));
// setup the layouts
$this->setCustomViewLayouts();

View File

@ -12,13 +12,20 @@
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// add the autoloader for the composer classes
$composer_autoloader = JPATH_LIBRARIES . '/phpseclib3/vendor/autoload.php';
if (file_exists($composer_autoloader))
{
require_once $composer_autoloader;
}
// register this component namespace
spl_autoload_register(function ($class) {
// project-specific base directories and namespace prefix
$search = array(
$search = [
'libraries/jcb_powers/VDM.Joomla' => 'VDM\\Joomla',
'libraries/jcb_powers/VDM.Gitea' => 'VDM\\Gitea'
);
];
// Start the search and load if found
$found = false;
$found_base_dir = "";
@ -40,7 +47,7 @@ spl_autoload_register(function ($class) {
// check if we found a match
if (!$found)
{
// no, move to the next registered autoloader
// not found so move to the next registered autoloader
return;
}
// get the relative class name
@ -3799,7 +3806,7 @@ abstract class ComponentbuilderHelper
// make sure we have the composer classes loaded
self::composerAutoload('phpseclib');
// build class name
$CLASS = '\phpseclib3\Crypt\\' . $type;
$CLASS = '\phpseclib\Crypt\\' . $type;
// make sure we have the phpseclib classes
if (!class_exists($CLASS))
{
@ -3958,7 +3965,7 @@ abstract class ComponentbuilderHelper
// make sure we have the composer classes loaded
self::composerAutoload('phpseclib');
// make sure we have the phpseclib classes
if (!class_exists('\phpseclib3\Net\SFTP'))
if (!class_exists('\phpseclib\Net\SFTP'))
{
// class not in place so send out error
JFactory::getApplication()->enqueueMessage(JText::_('COM_COMPONENTBUILDER_THE_BPHPSECLIBNETSFTPB_LIBRARYCLASS_IS_NOT_AVAILABLE_THIS_LIBRARYCLASS_SHOULD_HAVE_BEEN_ADDED_TO_YOUR_BLIBRARIESVDM_IOVENDORB_FOLDER_PLEASE_CONTACT_YOUR_SYSTEM_ADMINISTRATOR_FOR_MORE_INFO'), 'Error');
@ -3967,7 +3974,7 @@ abstract class ComponentbuilderHelper
// insure the port is set
$server->port = (isset($server->port) && is_numeric($server->port) && $server->port > 0) ? (int) $server->port : 22;
// open the connection
self::$sftp[$server->cache] = new phpseclib3\Net\SFTP($server->host, $server->port);
self::$sftp[$server->cache] = new phpseclib\Net\SFTP($server->host, $server->port);
// heads-up on protocol
self::$sftp[$server->cache]->jcb_protocol = 2; // SFTP <-- if called not knowing what type of protocol is being used
// now login based on authentication type

View File

@ -175,7 +175,7 @@ class ComponentbuilderModelAjax extends ListModel
// we first use the new encryption
// load phpseclib <https://phpseclib.com/docs/symmetric>
$opened = false;
if(ComponentbuilderHelper::crypt('AES', 'CBC') instanceof \phpseclib3\Crypt\Rijndael)
if(ComponentbuilderHelper::crypt('AES', 'CBC') instanceof \phpseclib\Crypt\Rijndael)
{
// load the system password
ComponentbuilderHelper::crypt('AES', 'CBC')->setPassword($password, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt');

View File

@ -1096,7 +1096,7 @@ class ComponentbuilderModelImport_joomla_components extends BaseDatabaseModel
// check if we should use the phpseclib decryption
$phpseclip = (isset($this->packageInfo['phpseclib']) && $this->packageInfo['phpseclib']) ? true : $force;
// load phpseclib <https://phpseclib.com/docs/symmetric>
if($phpseclip && ComponentbuilderHelper::crypt('AES', 'CBC') instanceof \phpseclib3\Crypt\Rijndael)
if($phpseclip && ComponentbuilderHelper::crypt('AES', 'CBC') instanceof \phpseclib\Crypt\Rijndael)
{
// load the system password
ComponentbuilderHelper::crypt('AES', 'CBC')->setPassword($password, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt');

View File

@ -1260,7 +1260,7 @@ class ComponentbuilderModelJoomla_components extends ListModel
// $locker = new FOFEncryptAes($this->key, 128);
// $data = $locker->encryptString($data);
// load phpseclib <https://phpseclib.com/docs/symmetric>
if(ComponentbuilderHelper::crypt('AES', 'CBC') instanceof \phpseclib3\Crypt\Rijndael)
if(ComponentbuilderHelper::crypt('AES', 'CBC') instanceof \phpseclib\Crypt\Rijndael)
{
// set the password
ComponentbuilderHelper::crypt('AES', 'CBC')->setPassword($this->key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt');
@ -1314,7 +1314,7 @@ class ComponentbuilderModelJoomla_components extends ListModel
return false;
}
// set info data
if(ComponentbuilderHelper::crypt('AES', 'CBC') instanceof \phpseclib3\Crypt\Rijndael)
if(ComponentbuilderHelper::crypt('AES', 'CBC') instanceof \phpseclib\Crypt\Rijndael)
{
// set system password
$db = 'COM_COMPONENTBUILDER_SZDEQZDMVSMHBTRWFIFTYTSQFLVVXJTMTHREEJTWOIXM';

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="4" method="upgrade">
<name>COM_COMPONENTBUILDER</name>
<creationDate>18th December, 2022</creationDate>
<creationDate>29th December, 2023</creationDate>
<author>Llewellyn van der Merwe</author>
<authorEmail>joomla@vdm.io</authorEmail>
<authorUrl>https://dev.vdm.io</authorUrl>

View File

@ -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'];
}
}

View File

@ -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;
}
}

View File

@ -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(

View File

@ -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

View File

@ -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',

View File

@ -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();

View File

@ -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);
}
/**

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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());
}
}

View File

@ -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
*

View File

@ -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;
}
}

View File

@ -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)
{

View File

@ -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;
}
}

View File

@ -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
*/