Adds getExtensionInstallClass and setInstallMethodScript to its own class. #950

This commit is contained in:
Llewellyn van der Merwe 2022-08-20 18:02:48 +02:00
parent 154cd5ae1e
commit a0fda76abd
Signed by: Llewellyn
GPG Key ID: A9201372263741E7
14 changed files with 516 additions and 244 deletions

View File

@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo
Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have! Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have!
You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.1.4) with **ALL** its features and **ALL** concepts totally open-source and free! You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.1.5) with **ALL** its features and **ALL** concepts totally open-source and free!
> Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45)
@ -140,14 +140,14 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 9th July, 2022 + *Last Build*: 20th August, 2022
+ *Version*: 3.1.4 + *Version*: 3.1.5
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **311349** + *Line count*: **311839**
+ *Field count*: **2002** + *Field count*: **2002**
+ *File count*: **2050** + *File count*: **2055**
+ *Folder count*: **349** + *Folder count*: **351**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com).
> Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)

View File

@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo
Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have! Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have!
You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.1.4) with **ALL** its features and **ALL** concepts totally open-source and free! You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.1.5) with **ALL** its features and **ALL** concepts totally open-source and free!
> Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45)
@ -140,14 +140,14 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 9th July, 2022 + *Last Build*: 20th August, 2022
+ *Version*: 3.1.4 + *Version*: 3.1.5
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **311349** + *Line count*: **311839**
+ *Field count*: **2002** + *Field count*: **2002**
+ *File count*: **2050** + *File count*: **2055**
+ *Folder count*: **349** + *Folder count*: **351**
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com).
> Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) > Developed by [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)

View File

@ -29271,227 +29271,6 @@ function vdm_dkim() {
); );
} }
public function getExtensionInstallClass(&$extension)
{
// yes we are adding it
$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 . '{';
// set constructor
if (isset($extension->add_php_script_construct)
&& $extension->add_php_script_construct == 1
&& StringHelper::check(
$extension->php_script_construct
))
{
$script .= $this->setInstallMethodScript(
'construct', $extension->php_script_construct
);
}
// add PHP in extension install
$addScriptMethods = array('php_preflight', 'php_postflight',
'php_method');
$addScriptTypes = array('install', 'update', 'uninstall',
'discover_install');
// set some buckets for sorting
$function_install = array();
$function_update = array();
$function_uninstall = array();
$has_php_preflight = false;
$function_php_preflight = array('install' => array(),
'uninstall' => array(),
'discover_install' => array(),
'update' => array());
$has_php_postflight = false;
$function_php_postflight = array('install' => array(),
'uninstall' => array(),
'discover_install' => array(),
'update' => array());
// the function sorter
foreach ($addScriptMethods as $scriptMethod)
{
foreach ($addScriptTypes as $scriptType)
{
if (isset(
$extension->{'add_' . $scriptMethod . '_' . $scriptType}
)
&& $extension->{'add_' . $scriptMethod . '_' . $scriptType}
== 1
&& StringHelper::check(
$extension->{$scriptMethod . '_' . $scriptType}
))
{
// add to the main methods
if ('php_method' === $scriptMethod)
{
${'function_' . $scriptType}[]
= $extension->{$scriptMethod . '_' . $scriptType};
}
else
{
${'function_' . $scriptMethod}[$scriptType][]
= $extension->{$scriptMethod
. '_' . $scriptType};
${'has_' . $scriptMethod} = true;
}
}
}
}
// now add the install script.
if (ArrayHelper::check($function_install))
{
$script .= $this->setInstallMethodScript(
'install', $function_install
);
}
// now add the update script.
if (ArrayHelper::check($function_update))
{
$script .= $this->setInstallMethodScript(
'update', $function_update
);
}
// now add the uninstall script.
if (ArrayHelper::check($function_uninstall))
{
$script .= $this->setInstallMethodScript(
'uninstall', $function_uninstall
);
}
// now add the preflight script.
if ($has_php_preflight)
{
$script .= $this->setInstallMethodScript(
'preflight', $function_php_preflight
);
}
// now add the postflight script.
if ($has_php_postflight)
{
$script .= $this->setInstallMethodScript(
'postflight', $function_php_postflight
);
}
$script .= PHP_EOL . '}' . PHP_EOL;
return $script;
}
protected function setInstallMethodScript($function_name, &$scripts)
{
$script = '';
// build function
switch ($function_name)
{
case 'install':
case 'update':
case 'uninstall':
// the main function types
$script = PHP_EOL . PHP_EOL . $this->_t(1) . '/**';
$script .= PHP_EOL . $this->_t(1) . ' * Called on '
. $function_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 '
. $function_name . '($adapter)';
$script .= PHP_EOL . $this->_t(1) . '{';
$script .= PHP_EOL . implode(PHP_EOL . PHP_EOL, $scripts);
// return true
if ('uninstall' !== $function_name)
{
$script .= PHP_EOL . $this->_t(2) . 'return true;';
}
break;
case 'preflight':
case 'postflight':
// 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 '
. $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' === $function_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 ($scripts 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;';
break;
case 'construct':
// 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 . $scripts;
break;
default:
// oops error
return '';
}
// close the function
$script .= PHP_EOL . $this->_t(1) . '}';
return $script;
}
/** /**
* check if a translation should be added * check if a translation should be added
* *

View File

@ -19,6 +19,7 @@ use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\ArrayHelper; use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\ObjectHelper; use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\FileHelper; use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Componentbuilder\Extension\InstallScript;
/** /**
* Infusion class * Infusion class
@ -2393,7 +2394,7 @@ class Infusion extends Interpretation
// INSTALLCLASS // INSTALLCLASS
$this->fileContentDynamic[$module->key][$this->hhh $this->fileContentDynamic[$module->key][$this->hhh
. 'INSTALLCLASS' . $this->hhh] . 'INSTALLCLASS' . $this->hhh]
= $this->getExtensionInstallClass($module); = (new InstallScript($module))->get();
} }
// FIELDSET // FIELDSET
if (isset($module->form_files) if (isset($module->form_files)
@ -2455,7 +2456,7 @@ class Infusion extends Interpretation
// INSTALLCLASS // INSTALLCLASS
$this->fileContentDynamic[$plugin->key][$this->hhh $this->fileContentDynamic[$plugin->key][$this->hhh
. 'INSTALLCLASS' . $this->hhh] . 'INSTALLCLASS' . $this->hhh]
= $this->getExtensionInstallClass($plugin); = (new InstallScript($plugin))->get();
} }
// FIELDSET // FIELDSET
if (isset($plugin->form_files) if (isset($plugin->form_files)

View File

@ -392,7 +392,7 @@ class ComponentbuilderModelAjax extends ListModel
else else
{ {
// download link of the latest version // download link of the latest version
$download = "https://git.vdm.dev/api/v1/repos/joomla/Component-Builder/archive/" . $tags[0]->name . ".zip?access_token=" . $token; $download = "https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/" . $tags[0]->name . ".zip?access_token=" . $token;
return ['notice' => '<small><span style="color:red;"><span class="icon-warning-circle"></span>' . JText::_('COM_COMPONENTBUILDER_OUT_OF_DATE') . '!</span> <a style="color:green;" href="' . return ['notice' => '<small><span style="color:red;"><span class="icon-warning-circle"></span>' . JText::_('COM_COMPONENTBUILDER_OUT_OF_DATE') . '!</span> <a style="color:green;" href="' .
$download . '" title="' . JText::_('COM_COMPONENTBUILDER_YOU_CAN_DIRECTLY_DOWNLOAD_THE_LATEST_UPDATE_OR_USE_THE_JOOMLA_UPDATE_AREA') . '">' . JText::_('COM_COMPONENTBUILDER_DOWNLOAD_UPDATE') . '!</a></small>']; $download . '" title="' . JText::_('COM_COMPONENTBUILDER_YOU_CAN_DIRECTLY_DOWNLOAD_THE_LATEST_UPDATE_OR_USE_THE_JOOMLA_UPDATE_AREA') . '">' . JText::_('COM_COMPONENTBUILDER_DOWNLOAD_UPDATE') . '!</a></small>'];

File diff suppressed because one or more lines are too long

View File

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="4" method="upgrade"> <extension type="component" version="4" method="upgrade">
<name>COM_COMPONENTBUILDER</name> <name>COM_COMPONENTBUILDER</name>
<creationDate>9th July, 2022</creationDate> <creationDate>20th August, 2022</creationDate>
<author>Llewellyn van der Merwe</author> <author>Llewellyn van der Merwe</author>
<authorEmail>joomla@vdm.io</authorEmail> <authorEmail>joomla@vdm.io</authorEmail>
<authorUrl>https://dev.vdm.io</authorUrl> <authorUrl>https://dev.vdm.io</authorUrl>
<copyright>Copyright (C) 2015 Vast Development Method. All rights reserved.</copyright> <copyright>Copyright (C) 2015 Vast Development Method. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license> <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>3.1.4</version> <version>3.1.5</version>
<description><![CDATA[ <description><![CDATA[
<h1>Component Builder (v.3.1.4)</h1> <h1>Component Builder (v.3.1.5)</h1>
<div style="clear: both;"></div> <div style="clear: both;"></div>
<p>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. <p>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.

View File

@ -1079,10 +1079,10 @@
<element>pkg_component_builder</element> <element>pkg_component_builder</element>
<type>package</type> <type>package</type>
<client>site</client> <client>site</client>
<version>3.1.4</version> <version>3.1.5</version>
<infourl title="Component Builder!">https://dev.vdm.io</infourl> <infourl title="Component Builder!">https://dev.vdm.io</infourl>
<downloads> <downloads>
<downloadurl type="full" format="zip">https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v3.1.4.zip</downloadurl> <downloadurl type="full" format="zip">https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v3.1.5.zip</downloadurl>
</downloads> </downloads>
<tags> <tags>
<tag>stable</tag> <tag>stable</tag>

View File

@ -0,0 +1,388 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @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\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;
}
}

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1,40 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @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;
/**
* 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 '';
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @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;
/**
* 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];
}
}

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -9422,7 +9422,7 @@ class com_componentbuilderInstallerScript
echo '<a target="_blank" href="https://dev.vdm.io" title="Component Builder"> echo '<a target="_blank" href="https://dev.vdm.io" title="Component Builder">
<img src="components/com_componentbuilder/assets/images/vdm-component.jpg"/> <img src="components/com_componentbuilder/assets/images/vdm-component.jpg"/>
</a> </a>
<h3>Upgrade to Version 3.1.4 Was Successful! Let us know if anything is not working as expected.</h3>'; <h3>Upgrade to Version 3.1.5 Was Successful! Let us know if anything is not working as expected.</h3>';
// Set db if not set already. // Set db if not set already.
if (!isset($db)) if (!isset($db))