Component Builder (v.3.1.4)
+ Component Builder (v.3.1.5)
The Component Builder for [Joomla](https://extensions.joomla.org/extension/component-builder/) is highly advanced tool that is truly able to build extremely complex components in a fraction of the time.
diff --git a/componentbuilder_update_server.xml b/componentbuilder_update_server.xml
index 2cd47afe7..afff5d7f6 100644
--- a/componentbuilder_update_server.xml
+++ b/componentbuilder_update_server.xml
@@ -1079,10 +1079,10 @@
pkg_component_builder
package
site
- 3.1.4
+ 3.1.5
https://dev.vdm.io
- https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v3.1.4.zip
+ https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v3.1.5.zip
stable
diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Extension/InstallScript.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Extension/InstallScript.php
new file mode 100644
index 000000000..0c72523fd
--- /dev/null
+++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Extension/InstallScript.php
@@ -0,0 +1,388 @@
+
+ * @git 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\Extension;
+
+
+use VDM\Joomla\Utilities\ArrayHelper;
+use VDM\Joomla\Utilities\StringHelper;
+use VDM\Joomla\Componentbuilder\Line;
+use VDM\Joomla\Componentbuilder\Tab;
+
+
+/**
+ * Loading the Extension Installation Script Class
+ *
+ * @since 3.1.5
+ */
+class InstallScript
+{
+ /**
+ * The Line numbering Methods
+ *
+ * @since 3.1.5
+ */
+ use Line;
+
+ /**
+ * The Tab Adding Method
+ *
+ * @since 3.1.5
+ */
+ use Tab;
+
+ /**
+ * The extension
+ *
+ * @var object
+ * @since 3.1.5
+ */
+ protected object $extension;
+
+ /**
+ * The methods
+ *
+ * @var array
+ * @since 3.1.5
+ */
+ protected array $methods = ['php_script', 'php_preflight', 'php_postflight', 'php_method'];
+
+ /**
+ * The types
+ *
+ * @var array
+ * @since 3.1.5
+ */
+ protected array $types = ['construct', 'install', 'update', 'uninstall', 'discover_install'];
+
+ /**
+ * The construct bucket
+ *
+ * @var array
+ * @since 3.1.5
+ */
+ protected array $construct = [];
+
+ /**
+ * The install bucket
+ *
+ * @var array
+ * @since 3.1.5
+ */
+ protected array $install = [];
+
+ /**
+ * The update bucket
+ *
+ * @var array
+ * @since 3.1.5
+ */
+ protected array $update = [];
+
+ /**
+ * The uninstall bucket
+ *
+ * @var array
+ * @since 3.1.5
+ */
+ protected array $uninstall = [];
+
+ /**
+ * The preflight switch
+ *
+ * @var bool
+ * @since 3.1.5
+ */
+ protected bool $preflightActive = false;
+
+ /**
+ * The preflight bucket
+ *
+ * @var array
+ * @since 3.1.5
+ */
+ protected array $preflightBucket = ['install' => [], 'uninstall' => [], 'discover_install' => [], 'update' => []];
+
+ /**
+ * The postflight switch
+ *
+ * @var bool
+ * @since 3.1.5
+ */
+ protected bool $postflightActive = false;
+
+ /**
+ * The postflight bucket
+ *
+ * @var array
+ * @since 3.1.5
+ */
+ protected array $postflightBucket = ['install' => [], 'uninstall' => [], 'discover_install' => [], 'update' => []];
+
+ /**
+ * Constructor
+ * @since 3.1.5
+ */
+ public function __construct(object $extension)
+ {
+ // loop over methods and types
+ foreach ($this->methods as $method)
+ {
+ foreach ($this->types as $type)
+ {
+ if (isset($extension->{'add_' . $method . '_' . $type})
+ && $extension->{'add_' . $method . '_' . $type} == 1
+ && StringHelper::check(
+ $extension->{$method . '_' . $type}
+ ))
+ {
+ // add to the main methods
+ if ('php_method' === $method || 'php_script' === $method)
+ {
+ $this->{$type}[] = $extension->{$method . '_' . $type};
+ }
+ else
+ {
+ // get the flight key
+ $flight = str_replace('php_', '', $method);
+ // load the script to our bucket
+ $this->{$flight . 'Bucket'}[$type][] = $extension->{$method . '_' . $type};
+ // show that the method is active
+ $this->{$flight . 'Active'} = true;
+ }
+ }
+ }
+ }
+
+ $this->extension = $extension;
+ }
+
+ /**
+ * get install script
+ *
+ * @return string
+ * @since 3.1.5
+ */
+ public function get(): string
+ {
+ // return the class
+ return $this->build();
+ }
+
+ /**
+ * build the install class
+ *
+ * @return string
+ * @since 3.1.5
+ */
+ protected function build(): string
+ {
+ // start build
+ $script = $this->head();
+
+ // load constructor if set
+ $script .= $this->construct();
+
+ // load install method if set
+ $script .= $this->main('install');
+
+ // load update method if set
+ $script .= $this->main('update');
+
+ // load uninstall method if set
+ $script .= $this->main('uninstall');
+
+ // load preflight method if set
+ $script .= $this->flight('preflight');
+
+ // load postflight method if set
+ $script .= $this->flight('postflight');
+
+ // close the class
+ $script .= PHP_EOL . '}' . PHP_EOL;
+
+ return $script;
+ }
+
+ /**
+ * get install script head
+ *
+ * @return string
+ * @since 3.1.5
+ */
+ protected function head(): string
+ {
+ // get the extension
+ $extension = $this->extension;
+ // start build
+ $script = PHP_EOL . '/**';
+ $script .= PHP_EOL . ' * ' . $extension->official_name
+ . ' script file.';
+ $script .= PHP_EOL . ' *';
+ $script .= PHP_EOL . ' * @package ' . $extension->class_name;
+ $script .= PHP_EOL . ' */';
+ $script .= PHP_EOL . 'class ' . $extension->installer_class_name;
+ $script .= PHP_EOL . '{';
+
+ return $script;
+ }
+
+ /**
+ * get constructor
+ *
+ * @return string
+ * @since 3.1.5
+ */
+ protected function construct(): string
+ {
+ // return empty string if not set
+ if (!ArrayHelper::check($this->construct))
+ {
+ return '';
+ }
+
+ // the __construct script
+ $script = PHP_EOL . PHP_EOL . $this->_t(1) . '/**';
+ $script .= PHP_EOL . $this->_t(1) . ' * Constructor';
+ $script .= PHP_EOL . $this->_t(1) . ' *';
+ $script .= PHP_EOL . $this->_t(1)
+ . ' * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script';
+ $script .= PHP_EOL . $this->_t(1) . ' */';
+ $script .= PHP_EOL . $this->_t(1)
+ . 'public function __construct($adapter)';
+ $script .= PHP_EOL . $this->_t(1) . '{';
+ $script .= PHP_EOL . implode(PHP_EOL . PHP_EOL, $this->construct);
+ // close the function
+ $script .= PHP_EOL . $this->_t(1) . '}';
+
+ return $script;
+ }
+
+ /**
+ * build main methods
+ *
+ * @param string $name the method being called
+ *
+ * @return string
+ * @since 3.1.5
+ */
+ protected function main(string $name): string
+ {
+ // return empty string if not set
+ if (!ArrayHelper::check($this->{$name}))
+ {
+ return '';
+ }
+ // load the install method
+ $script = PHP_EOL . PHP_EOL . $this->_t(1) . '/**';
+ $script .= PHP_EOL . $this->_t(1) . " * Called on $name";
+ $script .= PHP_EOL . $this->_t(1) . ' *';
+ $script .= PHP_EOL . $this->_t(1)
+ . ' * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script';
+ $script .= PHP_EOL . $this->_t(1) . ' *';
+ $script .= PHP_EOL . $this->_t(1)
+ . ' * @return boolean True on success';
+ $script .= PHP_EOL . $this->_t(1) . ' */';
+ $script .= PHP_EOL . $this->_t(1) . 'public function '
+ . $name . '($adapter)';
+ $script .= PHP_EOL . $this->_t(1) . '{';
+ $script .= PHP_EOL . implode(PHP_EOL . PHP_EOL, $this->{$name});
+ // return true
+ if ('uninstall' !== $name)
+ {
+ $script .= PHP_EOL . $this->_t(2) . 'return true;';
+ }
+ // close the function
+ $script .= PHP_EOL . $this->_t(1) . '}';
+
+ return $script;
+ }
+
+ /**
+ * build flight methods
+ *
+ * @param string $name the method being called
+ *
+ * @return string
+ * @since 3.1.5
+ */
+ protected function flight(string $name): string
+ {
+ // return empty string if not set
+ if (empty($this->{$name . 'Active'}))
+ {
+ return '';
+ }
+
+ // the pre/post function types
+ $script = PHP_EOL . PHP_EOL . $this->_t(1) . '/**';
+ $script .= PHP_EOL . $this->_t(1)
+ . ' * Called before any type of action';
+ $script .= PHP_EOL . $this->_t(1) . ' *';
+ $script .= PHP_EOL . $this->_t(1)
+ . ' * @param string $route Which action is happening (install|uninstall|discover_install|update)';
+ $script .= PHP_EOL . $this->_t(1)
+ . ' * @param Joomla\CMS\Installer\InstallerAdapter $adapter The object responsible for running this script';
+ $script .= PHP_EOL . $this->_t(1) . ' *';
+ $script .= PHP_EOL . $this->_t(1)
+ . ' * @return boolean True on success';
+ $script .= PHP_EOL . $this->_t(1) . ' */';
+ $script .= PHP_EOL . $this->_t(1) . 'public function '
+ . $name . '($route, $adapter)';
+ $script .= PHP_EOL . $this->_t(1) . '{';
+ $script .= PHP_EOL . $this->_t(2) . '//' . $this->setLine(
+ __LINE__
+ ) . ' get application';
+ $script .= PHP_EOL . $this->_t(2)
+ . '$app = JFactory::getApplication();' . PHP_EOL;
+
+ // add the default version check (TODO) must make this dynamic
+ if ('preflight' === $name)
+ {
+ $script .= PHP_EOL . $this->_t(2) . '//' . $this->setLine(
+ __LINE__
+ ) . ' the default for both install and update';
+ $script .= PHP_EOL . $this->_t(2)
+ . '$jversion = new JVersion();';
+ $script .= PHP_EOL . $this->_t(2)
+ . "if (!\$jversion->isCompatible('3.8.0'))";
+ $script .= PHP_EOL . $this->_t(2) . '{';
+ $script .= PHP_EOL . $this->_t(3)
+ . "\$app->enqueueMessage('Please upgrade to at least Joomla! 3.8.0 before continuing!', 'error');";
+ $script .= PHP_EOL . $this->_t(3) . 'return false;';
+ $script .= PHP_EOL . $this->_t(2) . '}' . PHP_EOL;
+ }
+
+ // now add the scripts
+ foreach ($this->{$name . 'Bucket'} as $route => $_script)
+ {
+ if (ArrayHelper::check($_script))
+ {
+ // set the if and script
+ $script .= PHP_EOL . $this->_t(2) . "if ('" . $route
+ . "' === \$route)";
+ $script .= PHP_EOL . $this->_t(2) . '{';
+ $script .= PHP_EOL . implode(
+ PHP_EOL . PHP_EOL, $_script
+ );
+ $script .= PHP_EOL . $this->_t(2) . '}' . PHP_EOL;
+ }
+ }
+
+ // return true
+ $script .= PHP_EOL . $this->_t(2) . 'return true;';
+ // close the function
+ $script .= PHP_EOL . $this->_t(1) . '}';
+
+ return $script;
+ }
+}
+
diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Extension/index.html b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Extension/index.html
new file mode 100644
index 000000000..fa6d84e80
--- /dev/null
+++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Extension/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Line.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Line.php
new file mode 100644
index 000000000..97b53b5e7
--- /dev/null
+++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Line.php
@@ -0,0 +1,40 @@
+
+ * @git 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;
+
+
+/**
+ * Add line comment
+ *
+ * @since 3.1.5
+ */
+trait Line
+{
+ /**
+ * Set the line number in comments
+ *
+ * @param int $nr The line number
+ *
+ * @return string
+ * @since 3.1.5
+ */
+ private function setLine(int $nr): string
+ {
+ if ($this->debug)
+ {
+ return ' [' . get_called_class() . ' ' . $nr . ']';
+ }
+
+ return '';
+ }
+}
+
diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Tab.php b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Tab.php
new file mode 100644
index 000000000..070435503
--- /dev/null
+++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Tab.php
@@ -0,0 +1,58 @@
+
+ * @git 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;
+
+
+/**
+ * Adds Tabs
+ *
+ * @since 3.1.5
+ */
+trait Tab
+{
+ /**
+ * Tab/spacer bucket (to speed-up the build)
+ *
+ * @var array
+ * @since 3.1.5
+ */
+ protected $tabSpacerBucket = array();
+
+ /**
+ * Set tab/spacer
+ *
+ * @var string
+ * @since 3.1.5
+ */
+ protected $tabSpacer = "\t";
+
+ /**
+ * Set the tab/space
+ *
+ * @param int $nr The number of tag/space
+ *
+ * @return string
+ * @since 3.1.5
+ */
+ public function _t(int $nr) : string
+ {
+ // check if we already have the string
+ if (!isset($this->tabSpacerBucket[$nr]))
+ {
+ // get the string
+ $this->tabSpacerBucket[$nr] = str_repeat($this->tabSpacer, (int) $nr);
+ }
+ // return stored string
+ return $this->tabSpacerBucket[$nr];
+ }
+}
+
diff --git a/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/index.html b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/index.html
new file mode 100644
index 000000000..fa6d84e80
--- /dev/null
+++ b/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/index.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/script.php b/script.php
index 26557c517..a6b8b4cb2 100644
--- a/script.php
+++ b/script.php
@@ -9422,7 +9422,7 @@ class com_componentbuilderInstallerScript
echo '
- Upgrade to Version 3.1.4 Was Successful! Let us know if anything is not working as expected.
';
+ Upgrade to Version 3.1.5 Was Successful! Let us know if anything is not working as expected.
';
// Set db if not set already.
if (!isset($db))