forked from joomla/Component-Builder
Update master #1
@ -140,13 +140,13 @@ 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*: 11th December, 2022
|
||||
+ *Last Build*: 18th December, 2022
|
||||
+ *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*: **337314**
|
||||
+ *Line count*: **337557**
|
||||
+ *Field count*: **2009**
|
||||
+ *File count*: **2206**
|
||||
+ *File count*: **2207**
|
||||
+ *Folder count*: **388**
|
||||
|
||||
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
|
||||
|
@ -140,13 +140,13 @@ 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*: 11th December, 2022
|
||||
+ *Last Build*: 18th December, 2022
|
||||
+ *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*: **337314**
|
||||
+ *Line count*: **337557**
|
||||
+ *Field count*: **2009**
|
||||
+ *File count*: **2206**
|
||||
+ *File count*: **2207**
|
||||
+ *Folder count*: **388**
|
||||
|
||||
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
|
||||
|
@ -1802,37 +1802,10 @@ class Infusion extends Interpretation
|
||||
{
|
||||
CFactory::_('Content')->set('README', $this->componentData->readme);
|
||||
}
|
||||
// remove all the power placeholders
|
||||
CFactory::_('Content')->set('ADMIN_POWER_HELPER', '');
|
||||
CFactory::_('Content')->set('SITE_POWER_HELPER', '');
|
||||
CFactory::_('Content')->set('CUSTOM_POWER_AUTOLOADER', '');
|
||||
|
||||
// infuse powers data if set
|
||||
if (ArrayHelper::check(CFactory::_('Power')->active))
|
||||
{
|
||||
// start the autoloader
|
||||
$autoloader = array();
|
||||
foreach (CFactory::_('Power')->active as $power)
|
||||
{
|
||||
if (ObjectHelper::check($power))
|
||||
{
|
||||
// Trigger Event: jcb_ce_onBeforeInfusePowerData
|
||||
CFactory::_('Event')->trigger(
|
||||
'jcb_ce_onBeforeInfusePowerData',
|
||||
array(&$this->componentContext, &$power, &$this)
|
||||
);
|
||||
// POWERCODE
|
||||
CFactory::_('Content')->set_($power->key, 'POWERCODE', $this->getPowerCode($power));
|
||||
// Trigger Event: jcb_ce_onAfterInfusePowerData
|
||||
CFactory::_('Event')->trigger(
|
||||
'jcb_ce_onAfterInfusePowerData',
|
||||
array(&$this->componentContext, &$power, &$this)
|
||||
);
|
||||
}
|
||||
}
|
||||
// now set the power autoloader
|
||||
CFactory::_('Power.Autoloader')->set((!CFactory::_('Config')->remove_site_folder || !CFactory::_('Config')->remove_site_edit_folder));
|
||||
}
|
||||
// Infuse POWERS
|
||||
CFactory::_('Power.Infusion')->set();
|
||||
|
||||
// tweak system to set stuff to the module domain
|
||||
$_backup_target = CFactory::_('Config')->build_target;
|
||||
$_backup_lang = CFactory::_('Config')->lang_target;
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension type="component" version="4" method="upgrade">
|
||||
<name>COM_COMPONENTBUILDER</name>
|
||||
<creationDate>11th December, 2022</creationDate>
|
||||
<creationDate>18th December, 2022</creationDate>
|
||||
<author>Llewellyn van der Merwe</author>
|
||||
<authorEmail>joomla@vdm.io</authorEmail>
|
||||
<authorUrl>https://dev.vdm.io</authorUrl>
|
||||
|
@ -84,12 +84,15 @@ class Autoloader
|
||||
if (($size = ArrayHelper::check($this->power->namespace)) > 0)
|
||||
{
|
||||
// set if we should load the autoloader on the site area
|
||||
$loadSite = true;
|
||||
$loadSite = (!$this->config->remove_site_folder || !$this->config->remove_site_edit_folder);
|
||||
|
||||
// check if we are using a plugin
|
||||
$use_plugin = $this->content->exist('PLUGIN_POWER_AUTOLOADER');
|
||||
|
||||
// build the methods
|
||||
$autoloadNotSiteMethod = array();
|
||||
$autoloadMethod = array();
|
||||
|
||||
// add only if we are not using a plugin
|
||||
$tab_space = 2;
|
||||
if (!$use_plugin)
|
||||
@ -107,6 +110,7 @@ class Autoloader
|
||||
$autoloadNotSiteMethod[] = Indent::_(3) . 'return;';
|
||||
$autoloadNotSiteMethod[] = Indent::_(2) . '}' . PHP_EOL;
|
||||
}
|
||||
|
||||
// we start building the spl_autoload_register function call
|
||||
$autoloadMethod[] = Indent::_($tab_space) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' register this component namespace';
|
||||
@ -114,6 +118,7 @@ class Autoloader
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '//'
|
||||
. Line::_(__Line__, __Class__) . ' project-specific base directories and namespace prefix';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '$search = array(';
|
||||
|
||||
// ==== IMPORTANT NOTICE =====
|
||||
// make sure the name space values are sorted from the longest string to the shortest
|
||||
// so that the search do not mistakenly match a shorter namespace before a longer one
|
||||
@ -125,9 +130,11 @@ class Autoloader
|
||||
// ^^^^^^^^^^^^^^^^^^^^^
|
||||
// NameSpace\SubName\SubSubName\ClassName
|
||||
// ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
uksort($this->power->namespace, function ($a, $b) {
|
||||
return strlen($b) - strlen($a);
|
||||
});
|
||||
|
||||
// counter to manage the comma in the actual array
|
||||
$counter = 1;
|
||||
foreach ($this->power->namespace as $base_dir => $prefix)
|
||||
@ -188,8 +195,10 @@ class Autoloader
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(2) . 'require $file;';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . Indent::_(1) . '}';
|
||||
$autoloadMethod[] = Indent::_($tab_space) . '});';
|
||||
|
||||
// create the method string
|
||||
$autoloader = implode(PHP_EOL, $autoloadNotSiteMethod) . implode(PHP_EOL, $autoloadMethod);
|
||||
|
||||
// check if we are using a plugin
|
||||
if ($use_plugin)
|
||||
{
|
||||
@ -205,6 +214,7 @@ class Autoloader
|
||||
$this->content->add('SITE_POWER_HELPER', $autoloader);
|
||||
}
|
||||
}
|
||||
|
||||
// to add to custom files
|
||||
$this->content->add('CUSTOM_POWER_AUTOLOADER', PHP_EOL . implode(PHP_EOL, $autoloadMethod));
|
||||
}
|
||||
|
@ -0,0 +1,207 @@
|
||||
<?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\Compiler\Power;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Content;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Autoloader;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Power Infusion
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Infusion
|
||||
{
|
||||
/**
|
||||
* Compiler Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Power Objects
|
||||
*
|
||||
* @var Power
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Power $power;
|
||||
|
||||
/**
|
||||
* Compiler Content
|
||||
*
|
||||
* @var Content
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Content $content;
|
||||
|
||||
/**
|
||||
* Compiler Powers Autoloader
|
||||
*
|
||||
* @var Autoloader
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Autoloader $autoloader;
|
||||
|
||||
/**
|
||||
* Compiler Placeholder
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* Compiler Event
|
||||
*
|
||||
* @var Event
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Event $event;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config|null $config The Config object.
|
||||
* @param Power|null $power The power object.
|
||||
* @param Content|null $content The compiler content object.
|
||||
* @param Autoloader|null $autoloader The powers autoloader object.
|
||||
* @param Placeholder|null $placeholder The placeholder object.
|
||||
* @param Event|null $event The events object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Power $power = null, ?Content $content = null,
|
||||
?Autoloader $autoloader = null, ?Placeholder $placeholder = null, ?Event $event = null)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->power = $power ?: Compiler::_('Power');
|
||||
$this->content = $content ?: Compiler::_('Content');
|
||||
$this->autoloader = $autoloader ?: Compiler::_('Power.Autoloader');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->event = $event ?: Compiler::_('Event');
|
||||
}
|
||||
|
||||
/**
|
||||
* Infuse the powers data with the content
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set()
|
||||
{
|
||||
// infuse powers data if set
|
||||
if (ArrayHelper::check($this->power->active))
|
||||
{
|
||||
// TODO we need to update the event signatures
|
||||
$context = $this->config->component_context;
|
||||
|
||||
foreach ($this->power->active as $power)
|
||||
{
|
||||
if (ObjectHelper::check($power))
|
||||
{
|
||||
// Trigger Event: jcb_ce_onBeforeInfusePowerData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onBeforeInfusePowerData',
|
||||
array(&$context, &$power)
|
||||
);
|
||||
|
||||
// POWERCODE
|
||||
$this->content->set_($power->key, 'POWERCODE', $this->get($power));
|
||||
|
||||
// Trigger Event: jcb_ce_onAfterInfusePowerData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onAfterInfusePowerData',
|
||||
array(&$context, &$power)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// now set the power autoloader
|
||||
$this->autoloader->set();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Power code
|
||||
*
|
||||
* @param object $power A power object.
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function get(object &$power): string
|
||||
{
|
||||
$code = [];
|
||||
|
||||
// set the name space
|
||||
$code[] = 'namespace ' . $power->_namespace . ';' . PHP_EOL;
|
||||
|
||||
// check if we have header data
|
||||
if (StringHelper::check($power->head))
|
||||
{
|
||||
$code[] = PHP_EOL . $power->head;
|
||||
}
|
||||
|
||||
// add description if set
|
||||
if (StringHelper::check($power->description))
|
||||
{
|
||||
// check if this is escaped
|
||||
if (strpos($power->description, '/*') === false)
|
||||
{
|
||||
// make this description escaped
|
||||
$power->description = '/**' . PHP_EOL . ' * ' . implode(PHP_EOL . ' * ', explode(PHP_EOL, $power->description)) . PHP_EOL . ' */';
|
||||
}
|
||||
$code[] = PHP_EOL . $power->description;
|
||||
}
|
||||
|
||||
// build power declaration
|
||||
$declaration = $power->type . ' ' . $power->class_name;
|
||||
|
||||
// check if we have extends
|
||||
if (StringHelper::check($power->extends_name))
|
||||
{
|
||||
$declaration .= ' extends ' . $power->extends_name;
|
||||
}
|
||||
|
||||
// check if we have implements
|
||||
if (ArrayHelper::check($power->implement_names))
|
||||
{
|
||||
$declaration .= ' implements ' . implode(', ', $power->implement_names);
|
||||
}
|
||||
|
||||
$code[] = $declaration;
|
||||
$code[] = '{';
|
||||
|
||||
// add the main code if set
|
||||
if (StringHelper::check($power->main_class_code))
|
||||
{
|
||||
$code[] = $power->main_class_code;
|
||||
}
|
||||
|
||||
$code[] = '}' . PHP_EOL . PHP_EOL;
|
||||
|
||||
return $this->placeholder->update(implode(PHP_EOL, $code), $this->content->active);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power as Powers;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Infusion;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Power\Autoloader;
|
||||
|
||||
|
||||
@ -40,6 +41,9 @@ class Power implements ServiceProviderInterface
|
||||
|
||||
$container->alias(Autoloader::class, 'Power.Autoloader')
|
||||
->share('Power.Autoloader', [$this, 'getAutoloader'], true);
|
||||
|
||||
$container->alias(Infusion::class, 'Power.Infusion')
|
||||
->share('Power.Infusion', [$this, 'getInfusion'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,5 +81,25 @@ class Power implements ServiceProviderInterface
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Power Infusion
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Infusion
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInfusion(Container $container): Infusion
|
||||
{
|
||||
return new Infusion(
|
||||
$container->get('Config'),
|
||||
$container->get('Power'),
|
||||
$container->get('Content'),
|
||||
$container->get('Power.Autoloader'),
|
||||
$container->get('Placeholder'),
|
||||
$container->get('Event')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user