Moved many field related get methods to its own classes
This commit is contained in:
parent
4a32d3d50e
commit
c5a85f167e
@ -498,6 +498,39 @@ class Config extends Registry implements \JsonSerializable, \ArrayAccess, \Itera
|
||||
// but this is a switch value and is changed many times
|
||||
return 'admin';
|
||||
}
|
||||
|
||||
/**
|
||||
* get basic encryption switch
|
||||
*
|
||||
* @return bool Switch to control the encryption
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getBasicencryption(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get medium encryption switch
|
||||
*
|
||||
* @return bool Switch to control the encryption
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getMediumencryption(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get whmcs encryption switch
|
||||
*
|
||||
* @return bool Switch to control the encryption
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getWhmcsencryption(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -94,14 +94,16 @@ abstract class Factory
|
||||
protected static function createContainer(): Container
|
||||
{
|
||||
$container = (new Container())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Config())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Compiler())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Event())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\History())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Language())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Placeholder())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Customcode())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Power())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Component())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Extension());
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Extension())
|
||||
->registerServiceProvider(new \VDM\Joomla\Componentbuilder\Compiler\Service\Field());
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
@ -0,0 +1,142 @@
|
||||
<?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\Compiler;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Data;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Name;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\TypeName;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\UniqueName;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Field
|
||||
{
|
||||
/**
|
||||
* Compiler Field Data
|
||||
*
|
||||
* @var Data
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Data $data;
|
||||
|
||||
/**
|
||||
* Compiler Field Name
|
||||
*
|
||||
* @var Name
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Name $name;
|
||||
|
||||
/**
|
||||
* Compiler Field Type Name
|
||||
*
|
||||
* @var TypeName
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected TypeName $typeName;
|
||||
|
||||
/**
|
||||
* Compiler Field Unique Name
|
||||
*
|
||||
* @var UniqueName
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected UniqueName $uniqueName;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Data|null $data The compiler field data object.
|
||||
* @param Name|null $name The compiler field name object.
|
||||
* @param TypeName|null $typeName The compiler field type name object.
|
||||
* @param UniqueName|null $uniqueName The compiler field unique name object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Data $data = null, ?Name $name = null, ?TypeName $typeName = null, ?UniqueName $uniqueName = null)
|
||||
{
|
||||
$this->data = $data ?: Compiler::_('Field.Data');
|
||||
$this->name = $name ?: Compiler::_('Field.Name');
|
||||
$this->typeName = $typeName ?: Compiler::_('Field.Type.Name');
|
||||
$this->uniqueName = $uniqueName ?: Compiler::_('Field.Unique.Name');
|
||||
}
|
||||
|
||||
/**
|
||||
* set Field details
|
||||
*
|
||||
* @param array $field The field array.
|
||||
* @param string|null $singleViewName The single view name.
|
||||
* @param string|null $listViewName The list view name.
|
||||
* @param string $amicably The peaceful resolve.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(array &$field, ?string $singleViewName = null, ?string $listViewName = null, string $amicably = '')
|
||||
{
|
||||
// set hash
|
||||
static $hash = 123467890;
|
||||
|
||||
// load hash if not found
|
||||
if (!isset($field['hash']))
|
||||
{
|
||||
$field['hash'] = \md5($field['field'] . $hash);
|
||||
// increment hash
|
||||
$hash++;
|
||||
}
|
||||
|
||||
// set the settings
|
||||
if (!isset($field['settings']))
|
||||
{
|
||||
$field['settings'] = $this->data->get(
|
||||
$field['field'], $singleViewName, $listViewName
|
||||
);
|
||||
}
|
||||
|
||||
// set real field name
|
||||
if (!isset($field['base_name']))
|
||||
{
|
||||
$field['base_name'] = $this->name->get($field);
|
||||
}
|
||||
|
||||
// set code name for field type
|
||||
if (!isset($field['type_name']))
|
||||
{
|
||||
$field['type_name'] = $this->typeName->get($field);
|
||||
}
|
||||
|
||||
// check if value is array
|
||||
if (isset($field['permission'])
|
||||
&& !ArrayHelper::check($field['permission'])
|
||||
&& is_numeric($field['permission']) && $field['permission'] > 0)
|
||||
{
|
||||
$field['permission'] = array($field['permission']);
|
||||
}
|
||||
|
||||
// set unique name keeper
|
||||
if ($listViewName)
|
||||
{
|
||||
$this->uniqueName->set(
|
||||
$field['base_name'], $listViewName . $amicably
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,232 @@
|
||||
<?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\Compiler\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Dispenser;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Customcode
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Customcode
|
||||
{
|
||||
/**
|
||||
* Tracking the update of fields per/view
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $views;
|
||||
|
||||
/**
|
||||
* Compiler Customcode Dispenser
|
||||
*
|
||||
* @var Dispenser
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Dispenser $dispenser;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Dispenser|null $dispenser The compiler customcode dispenser object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Dispenser $dispenser = null)
|
||||
{
|
||||
$this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update field customcode
|
||||
*
|
||||
* @param int $id The field id
|
||||
* @param object $field The field object
|
||||
* @param string|null $singleViewName The view edit or single name
|
||||
* @param string|null $listViewName The view list name
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function update(int $id, object &$field, $singleViewName = null, $listViewName = null)
|
||||
{
|
||||
// check if we should load scripts for single view
|
||||
if ($singleViewName && StringHelper::check($singleViewName)
|
||||
&& !isset($this->views[$singleViewName][$id]))
|
||||
{
|
||||
// add_javascript_view_footer
|
||||
if ($field->add_javascript_view_footer == 1
|
||||
&& StringHelper::check(
|
||||
$field->javascript_view_footer
|
||||
))
|
||||
{
|
||||
$convert__ = true;
|
||||
if (isset($field->javascript_view_footer_decoded)
|
||||
&& $field->javascript_view_footer_decoded)
|
||||
{
|
||||
$convert__ = false;
|
||||
}
|
||||
$this->dispenser->set(
|
||||
$field->javascript_view_footer,
|
||||
'view_footer',
|
||||
$singleViewName,
|
||||
null,
|
||||
array(
|
||||
'table' => 'field',
|
||||
'id' => (int) $id,
|
||||
'field' => 'javascript_view_footer',
|
||||
'type' => 'js',
|
||||
'prefix' => PHP_EOL),
|
||||
$convert__,
|
||||
$convert__,
|
||||
true
|
||||
);
|
||||
if (!isset($field->javascript_view_footer_decoded))
|
||||
{
|
||||
$field->javascript_view_footer_decoded
|
||||
= true;
|
||||
}
|
||||
|
||||
if (strpos($field->javascript_view_footer, "token") !== false
|
||||
|| strpos($field->javascript_view_footer, "task=ajax") !== false)
|
||||
{
|
||||
if (!isset($this->dispenser->hub['token']))
|
||||
{
|
||||
$this->dispenser->hub['token'] = [];
|
||||
}
|
||||
if (!isset($this->dispenser->hub['token'][$singleViewName])
|
||||
|| !$this->dispenser->hub['token'][$singleViewName])
|
||||
{
|
||||
$this->dispenser->hub['token'][$singleViewName]
|
||||
= true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add_css_view
|
||||
if ($field->add_css_view == 1)
|
||||
{
|
||||
$convert__ = true;
|
||||
if (isset($field->css_view_decoded)
|
||||
&& $field->css_view_decoded)
|
||||
{
|
||||
$convert__ = false;
|
||||
}
|
||||
$this->dispenser->set(
|
||||
$field->css_view,
|
||||
'css_view',
|
||||
$singleViewName,
|
||||
null,
|
||||
array('prefix' => PHP_EOL),
|
||||
$convert__,
|
||||
$convert__,
|
||||
true
|
||||
);
|
||||
if (!isset($field->css_view_decoded))
|
||||
{
|
||||
$field->css_view_decoded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// add this only once to single view.
|
||||
$this->views[$singleViewName][$id] = true;
|
||||
}
|
||||
|
||||
// check if we should load scripts for list views
|
||||
if ($listViewName && StringHelper::check($listViewName)
|
||||
&& !isset($this->views[$listViewName][$id]))
|
||||
{
|
||||
// add_javascript_views_footer
|
||||
if ($field->add_javascript_views_footer == 1
|
||||
&& StringHelper::check(
|
||||
$field->javascript_views_footer
|
||||
))
|
||||
{
|
||||
$convert__ = true;
|
||||
if (isset($field->javascript_views_footer_decoded)
|
||||
&& $field->javascript_views_footer_decoded)
|
||||
{
|
||||
$convert__ = false;
|
||||
}
|
||||
$this->dispenser->set(
|
||||
$field->javascript_views_footer,
|
||||
'views_footer',
|
||||
$singleViewName,
|
||||
null,
|
||||
array(
|
||||
'table' => 'field',
|
||||
'id' => (int) $id,
|
||||
'field' => 'javascript_views_footer',
|
||||
'type' => 'js',
|
||||
'prefix' => PHP_EOL),
|
||||
$convert__,
|
||||
$convert__,
|
||||
true
|
||||
);
|
||||
if (!isset($field->javascript_views_footer_decoded))
|
||||
{
|
||||
$field->javascript_views_footer_decoded = true;
|
||||
}
|
||||
if (strpos($field->javascript_views_footer, "token") !== false
|
||||
|| strpos($field->javascript_views_footer, "task=ajax") !== false)
|
||||
{
|
||||
if (!isset($this->dispenser->hub['token']))
|
||||
{
|
||||
$this->dispenser->hub['token'] = [];
|
||||
}
|
||||
if (!isset($this->dispenser->hub['token'][$listViewName])
|
||||
|| !$this->dispenser->hub['token'][$listViewName])
|
||||
{
|
||||
$this->dispenser->hub['token'][$listViewName]
|
||||
= true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add_css_views
|
||||
if ($field->add_css_views == 1)
|
||||
{
|
||||
$convert__ = true;
|
||||
if (isset($field->css_views_decoded)
|
||||
&& $field->css_views_decoded)
|
||||
{
|
||||
$convert__ = false;
|
||||
}
|
||||
$this->dispenser->set(
|
||||
$field->css_views,
|
||||
'css_views',
|
||||
$singleViewName,
|
||||
null,
|
||||
array('prefix' => PHP_EOL),
|
||||
$convert__,
|
||||
$convert__,
|
||||
true
|
||||
);
|
||||
if (!isset($field->css_views_decoded))
|
||||
{
|
||||
$field->css_views_decoded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// add this only once to list view.
|
||||
$this->views[$listViewName][$id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,329 @@
|
||||
<?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\Compiler\Field;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Customcode as FieldCustomcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Validation;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Data
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Data
|
||||
{
|
||||
/**
|
||||
* Compiler Fields
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $fields;
|
||||
|
||||
/**
|
||||
* Compiler Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Compiler Event
|
||||
*
|
||||
* @var EventInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected EventInterface $event;
|
||||
|
||||
/**
|
||||
* Compiler History
|
||||
*
|
||||
* @var HistoryInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected HistoryInterface $history;
|
||||
|
||||
/**
|
||||
* Compiler Placeholder
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* Compiler Customcode
|
||||
*
|
||||
* @var Customcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Customcode $customcode;
|
||||
|
||||
/**
|
||||
* Compiler Field Customcode
|
||||
*
|
||||
* @var FieldCustomcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected FieldCustomcode $fieldCustomcode;
|
||||
|
||||
/**
|
||||
* Compiler Field Validation
|
||||
*
|
||||
* @var Validation
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Validation $validation;
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @var \JDatabaseDriver
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected \JDatabaseDriver $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param EventInterface|null $event The compiler event api object.
|
||||
* @param HistoryInterface|null $history The compiler history object.
|
||||
* @param Placeholder|null $placeholder The compiler placeholder object.
|
||||
* @param Customcode|null $customcode The compiler customcode object.
|
||||
* @param FieldCustomcode|null $fieldCustomcode The field customcode object.
|
||||
* @param Validation|null $validation The field validation rule object.
|
||||
* @param \JDatabaseDriver|null $db The database object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?EventInterface $event = null, ?HistoryInterface $history = null,
|
||||
?Placeholder $placeholder = null, ?Customcode $customcode = null, ?FieldCustomcode $fieldCustomcode = null,
|
||||
?Validation $validation = null, ?\JDatabaseDriver $db = null)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->event = $event ?: Compiler::_('Event');
|
||||
$this->history = $history ?: Compiler::_('History');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->customcode = $customcode ?: Compiler::_('Customcode');
|
||||
$this->fieldCustomcode = $fieldCustomcode ?: Compiler::_('Field.Customcode');
|
||||
$this->validation = $validation ?: Compiler::_('Field.Validation');
|
||||
$this->db = $db ?: Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Field Data
|
||||
*
|
||||
* @param int $id The field ID
|
||||
* @param string|null $singleViewName The view edit or single name
|
||||
* @param string|null $listViewName The view list name
|
||||
*
|
||||
* @return object|null The field data
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(int $id, ?string $singleViewName = null, ?string $listViewName = null): ?object
|
||||
{
|
||||
if ($id > 0 && !isset($this->fields[$id]))
|
||||
{
|
||||
// Create a new query object.
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// Select all the values in the field
|
||||
$query->select('a.*');
|
||||
$query->select(
|
||||
$this->db->quoteName(
|
||||
array('c.name', 'c.properties'),
|
||||
array('type_name', 'properties')
|
||||
)
|
||||
);
|
||||
$query->from('#__componentbuilder_field AS a');
|
||||
$query->join(
|
||||
'LEFT',
|
||||
$this->db->quoteName('#__componentbuilder_fieldtype', 'c')
|
||||
. ' ON (' . $this->db->quoteName('a.fieldtype') . ' = '
|
||||
. $this->db->quoteName('c.id') . ')'
|
||||
);
|
||||
$query->where(
|
||||
$this->db->quoteName('a.id') . ' = ' . $this->db->quote($id)
|
||||
);
|
||||
|
||||
// TODO we need to update the event signatures
|
||||
$context = $this->config->component_context;
|
||||
|
||||
// Trigger Event: jcb_ce_onBeforeQueryFieldData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onBeforeQueryFieldData',
|
||||
array(&$context, &$id, &$query, &$this->db)
|
||||
);
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
|
||||
$field = $this->db->loadObject();
|
||||
|
||||
// Trigger Event: jcb_ce_onBeforeModelFieldData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onBeforeModelFieldData',
|
||||
array(&$context, &$field)
|
||||
);
|
||||
|
||||
// adding a fix for the changed name of type to fieldtype
|
||||
$field->type = $field->fieldtype;
|
||||
|
||||
// load the values form params
|
||||
$field->xml = $this->customcode->update(json_decode($field->xml));
|
||||
|
||||
// check if we have validate (validation rule and set it if found)
|
||||
$this->validation->set($id, $field->xml);
|
||||
|
||||
// load the type values form type params
|
||||
$field->properties = (isset($field->properties)
|
||||
&& JsonHelper::check($field->properties))
|
||||
? json_decode($field->properties, true) : null;
|
||||
if (ArrayHelper::check($field->properties))
|
||||
{
|
||||
$field->properties = array_values($field->properties);
|
||||
}
|
||||
|
||||
// check if we have WHMCS encryption
|
||||
if (4 == $field->store
|
||||
&& !$this->config->whmcs_encryption)
|
||||
{
|
||||
$this->config->whmcs_encryption = true;
|
||||
}
|
||||
// check if we have basic encryption
|
||||
elseif (3 == $field->store
|
||||
&& !$this->config->basic_encryption)
|
||||
{
|
||||
$this->config->basic_encryption = true;
|
||||
}
|
||||
// check if we have better encryption
|
||||
elseif (5 == $field->store
|
||||
&& $this->config->medium_encryption)
|
||||
{
|
||||
$this->config->medium_encryption = true;
|
||||
}
|
||||
// check if we have better encryption
|
||||
elseif (6 == $field->store
|
||||
&& StringHelper::check(
|
||||
$field->on_get_model_field
|
||||
)
|
||||
&& StringHelper::check(
|
||||
$field->on_save_model_field
|
||||
))
|
||||
{
|
||||
// add only if string lenght found
|
||||
if (StringHelper::check(
|
||||
$field->initiator_on_save_model
|
||||
))
|
||||
{
|
||||
$field->initiator_save_key = md5(
|
||||
$field->initiator_on_save_model
|
||||
);
|
||||
$field->initiator_save = explode(
|
||||
PHP_EOL, $this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$field->initiator_on_save_model
|
||||
)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
);
|
||||
}
|
||||
if (StringHelper::check(
|
||||
$field->initiator_on_save_model
|
||||
))
|
||||
{
|
||||
$field->initiator_get_key = md5(
|
||||
$field->initiator_on_get_model
|
||||
);
|
||||
$field->initiator_get = explode(
|
||||
PHP_EOL, $this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$field->initiator_on_get_model
|
||||
)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
);
|
||||
}
|
||||
// set the field modeling
|
||||
$field->model_field['save'] = explode(
|
||||
PHP_EOL, $this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
base64_decode($field->on_save_model_field)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
);
|
||||
$field->model_field['get'] = explode(
|
||||
PHP_EOL, $this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
base64_decode($field->on_get_model_field)
|
||||
), $this->placeholder->active
|
||||
)
|
||||
);
|
||||
// remove the original values
|
||||
unset(
|
||||
$field->on_save_model_field,
|
||||
$field->on_get_model_field,
|
||||
$field->initiator_on_save_model,
|
||||
$field->initiator_on_get_model
|
||||
);
|
||||
}
|
||||
|
||||
// get the last used version
|
||||
$field->history = $this->history->get('field', $id);
|
||||
|
||||
// Trigger Event: jcb_ce_onAfterModelFieldData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onAfterModelFieldData',
|
||||
array(&$context, &$field)
|
||||
);
|
||||
|
||||
$this->fields[$id] = $field;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($id > 0 && isset($this->fields[$id]))
|
||||
{
|
||||
// update the customcode of the field
|
||||
$this->fieldCustomcode->update($id, $this->fields[$id], $singleViewName, $listViewName);
|
||||
|
||||
// return the field
|
||||
return $this->fields[$id];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,102 @@
|
||||
<?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\Compiler\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Database Name
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class DatabaseName
|
||||
{
|
||||
/**
|
||||
* The compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Registry|null $config The compiler registry object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Registry $registry = null)
|
||||
{
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* get the field database name and AS prefix
|
||||
*
|
||||
* @param string $nameListCode The list view name
|
||||
* @param int $fieldId The field ID
|
||||
* @param string $targetArea The area being targeted
|
||||
*
|
||||
* @return string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $nameListCode, int $fieldId, string $targetArea = 'builder.list'): ?string
|
||||
{
|
||||
if (($fields = $this->registry->get("${targetArea}.${nameListCode}")) !== null)
|
||||
{
|
||||
if ($fieldId < 0)
|
||||
{
|
||||
switch ($fieldId)
|
||||
{
|
||||
case -1:
|
||||
return 'a.id';
|
||||
case -2:
|
||||
return 'a.ordering';
|
||||
case -3:
|
||||
return 'a.published';
|
||||
}
|
||||
}
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
if ($field['id'] == $fieldId)
|
||||
{
|
||||
// now check if this is a category
|
||||
if ($field['type'] === 'category')
|
||||
{
|
||||
return 'c.title';
|
||||
}
|
||||
// set the custom code
|
||||
elseif (ArrayHelper::check(
|
||||
$field['custom']
|
||||
))
|
||||
{
|
||||
return $field['custom']['db'] . "."
|
||||
. $field['custom']['text'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'a.' . $field['code'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,114 @@
|
||||
<?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\Compiler\Field\JoomlaThree;
|
||||
|
||||
|
||||
use Joomla\CMS\Filesystem\Folder;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreValidationInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Core Joomla Field Validation Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class CoreValidation implements CoreValidationInterface
|
||||
{
|
||||
/**
|
||||
* Local Core Joomla Rules
|
||||
*
|
||||
* @var array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected ?array $rules = null;
|
||||
|
||||
/**
|
||||
* Local Core Joomla Rules Path
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected string $path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// set the path to the form validation rules
|
||||
$this->path = JPATH_LIBRARIES . '/src/Form/Rule';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Array of Existing Validation Rule Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set rules lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array
|
||||
{
|
||||
if (!$this->rules)
|
||||
{
|
||||
// check if the path exist
|
||||
if (!Folder::exists($this->path))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// we must first store the current working directory
|
||||
$joomla = getcwd();
|
||||
|
||||
// go to that folder
|
||||
chdir($this->path);
|
||||
|
||||
// load all the files in this path
|
||||
$rules = Folder::files('.', '\.php', true, true);
|
||||
|
||||
// change back to Joomla working directory
|
||||
chdir($joomla);
|
||||
|
||||
// make sure we have an array
|
||||
if (!ArrayHelper::check($rules))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// remove the Rule.php from the name
|
||||
$this->rules = array_map( function ($name) {
|
||||
return str_replace(array('./','Rule.php'), '', $name);
|
||||
}, $rules);
|
||||
}
|
||||
|
||||
// return rules if found
|
||||
if (is_array($this->rules))
|
||||
{
|
||||
// check if the names should be all lowercase
|
||||
if ($lowercase)
|
||||
{
|
||||
return array_map( function($item) {
|
||||
return strtolower($item);
|
||||
}, $this->rules);
|
||||
}
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
// return empty array
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@ -0,0 +1,234 @@
|
||||
<?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\Compiler\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\String\TypeHelper;
|
||||
use VDM\Joomla\Utilities\String\FieldHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\UniqueName;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Name
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Name
|
||||
{
|
||||
/**
|
||||
* The compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Unique Field Names
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $unique;
|
||||
|
||||
/**
|
||||
* Compiler Placeholder
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* Compiler Field Unique Name
|
||||
*
|
||||
* @var UniqueName
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected UniqueName $uniqueName;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Placeholder|null $placeholder The compiler component placeholder object.
|
||||
* @param UniqueName|null $uniqueName The compiler field unique name object.
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Placeholder $placeholder = null, ?UniqueName $uniqueName = null, ?Registry $registry = null)
|
||||
{
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->uniqueName = $uniqueName ?: Compiler::_('Field.Unique.Name');
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the field's actual name
|
||||
*
|
||||
* @param array $field The field array
|
||||
* @param string|null $listViewName The list view name
|
||||
* @param string $amicably The peaceful resolve (for fields in subforms in same view :)
|
||||
*
|
||||
* @return string Success returns field name
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(array &$field, ?string $listViewName = null, string $amicably = ''): string
|
||||
{
|
||||
// return the unique name if already set
|
||||
if ($listViewName && StringHelper::check($listViewName)
|
||||
&& isset($field['hash'])
|
||||
&& isset(
|
||||
$this->unique[$listViewName . $amicably . $field['hash']]
|
||||
))
|
||||
{
|
||||
return $this->unique[$listViewName . $amicably . $field['hash']];
|
||||
}
|
||||
|
||||
// always make sure we have a field name and type
|
||||
if (!isset($field['settings']) || !isset($field['settings']->type_name)
|
||||
|| !isset($field['settings']->name))
|
||||
{
|
||||
return 'error';
|
||||
}
|
||||
|
||||
// set the type name
|
||||
$type_name = TypeHelper::safe(
|
||||
$field['settings']->type_name
|
||||
);
|
||||
|
||||
// set the name of the field
|
||||
$name = FieldHelper::safe($field['settings']->name);
|
||||
|
||||
// check that we have the properties
|
||||
if (ArrayHelper::check($field['settings']->properties))
|
||||
{
|
||||
foreach ($field['settings']->properties as $property)
|
||||
{
|
||||
if ($property['name'] === 'name')
|
||||
{
|
||||
// if category then name must be catid (only one per view)
|
||||
if ($type_name === 'category')
|
||||
{
|
||||
// quick check if this is a category linked to view page
|
||||
$requeSt_id = GetHelper::between(
|
||||
$field['settings']->xml, 'name="', '"'
|
||||
);
|
||||
if (strpos($requeSt_id, '_request_id') !== false
|
||||
|| strpos($requeSt_id, '_request_catid') !== false)
|
||||
{
|
||||
// keep it then, don't change
|
||||
$name = $this->placeholder->update(
|
||||
$requeSt_id, $this->placeholder->active
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = 'catid';
|
||||
}
|
||||
|
||||
// if list view name is set
|
||||
if (StringHelper::check($listViewName))
|
||||
{
|
||||
// check if we should use another Text Name as this views name
|
||||
$otherName = $this->placeholder->update(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'othername="', '"'
|
||||
), $this->placeholder->active
|
||||
);
|
||||
$otherViews = $this->placeholder->update(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'views="', '"'
|
||||
), $this->placeholder->active
|
||||
);
|
||||
$otherView = $this->placeholder->update(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'view="', '"'
|
||||
), $this->placeholder->active
|
||||
);
|
||||
// This is to link other view category
|
||||
if (StringHelper::check($otherName)
|
||||
&& StringHelper::check(
|
||||
$otherViews
|
||||
) && StringHelper::check(
|
||||
$otherView
|
||||
))
|
||||
{
|
||||
// set other category details
|
||||
$this->registry->set("category.other.name.${listViewName}", [
|
||||
'name' => FieldHelper::safe(
|
||||
$otherName
|
||||
),
|
||||
'views' => StringHelper::safe(
|
||||
$otherViews
|
||||
),
|
||||
'view' => StringHelper::safe(
|
||||
$otherView
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if tag is set then enable all tag options for this view (only one per view)
|
||||
elseif ($type_name === 'tag')
|
||||
{
|
||||
$name = 'tags';
|
||||
}
|
||||
// if the field is set as alias it must be called alias
|
||||
elseif (isset($field['alias']) && $field['alias'])
|
||||
{
|
||||
$name = 'alias';
|
||||
}
|
||||
else
|
||||
{
|
||||
// get value from xml
|
||||
$xml = FieldHelper::safe(
|
||||
$this->placeholder->update(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'name="', '"'
|
||||
), $this->placeholder->active
|
||||
)
|
||||
);
|
||||
// check if a value was found
|
||||
if (StringHelper::check($xml))
|
||||
{
|
||||
$name = $xml;
|
||||
}
|
||||
}
|
||||
// exit foreach loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return the value unique
|
||||
if (StringHelper::check($listViewName) && isset($field['hash']))
|
||||
{
|
||||
$this->unique[$listViewName . $amicably . $field['hash']]
|
||||
= $this->uniqueName->get($name, $listViewName . $amicably);
|
||||
|
||||
// now return the unique name
|
||||
return $this->unique[$listViewName . $amicably . $field['hash']];
|
||||
}
|
||||
|
||||
// fall back to global
|
||||
return $name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,127 @@
|
||||
<?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\Compiler\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Utilities\String\TypeHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Type Name
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class TypeName
|
||||
{
|
||||
/**
|
||||
* Get the field's actual type
|
||||
*
|
||||
* @param object $field The field object
|
||||
*
|
||||
* @return string Success returns field type
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(&$field)
|
||||
{
|
||||
// check if we have done this already
|
||||
if (isset($field['type_name']))
|
||||
{
|
||||
return $field['type_name'];
|
||||
}
|
||||
|
||||
// check that we have the properties
|
||||
if (isset($field['settings'])
|
||||
&& ObjectHelper::check(
|
||||
$field['settings']
|
||||
)
|
||||
&& isset($field['settings']->properties)
|
||||
&& ArrayHelper::check(
|
||||
$field['settings']->properties
|
||||
))
|
||||
{
|
||||
// search for own custom fields
|
||||
if (strpos($field['settings']->type_name, '@') !== false)
|
||||
{
|
||||
// set own custom field
|
||||
$field['settings']->own_custom = $field['settings']->type_name;
|
||||
$field['settings']->type_name = 'Custom';
|
||||
}
|
||||
|
||||
// set the type name
|
||||
$type_name = TypeHelper::safe(
|
||||
$field['settings']->type_name
|
||||
);
|
||||
|
||||
// if custom (we must use the xml value)
|
||||
if (strtolower($type_name) === 'custom'
|
||||
|| strtolower($type_name) === 'customuser')
|
||||
{
|
||||
$type = TypeHelper::safe(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'type="', '"'
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// loop over properties looking for the type value
|
||||
foreach ($field['settings']->properties as $property)
|
||||
{
|
||||
if ($property['name']
|
||||
=== 'type') // type field is never adjustable (unless custom)
|
||||
{
|
||||
// force the default value
|
||||
if (isset($property['example'])
|
||||
&& StringHelper::check(
|
||||
$property['example']
|
||||
))
|
||||
{
|
||||
$type = TypeHelper::safe(
|
||||
$property['example']
|
||||
);
|
||||
}
|
||||
// fall back on the xml settings (not ideal)
|
||||
else
|
||||
{
|
||||
$type = TypeHelper::safe(
|
||||
GetHelper::between(
|
||||
$field['settings']->xml, 'type="', '"'
|
||||
)
|
||||
);
|
||||
}
|
||||
// exit foreach loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// check if the value is set
|
||||
if (isset($type) && StringHelper::check($type))
|
||||
{
|
||||
return $type;
|
||||
}
|
||||
// fallback on type name set in name field (not ideal)
|
||||
else
|
||||
{
|
||||
return $type_name;
|
||||
}
|
||||
}
|
||||
|
||||
// fall back to text
|
||||
return 'text';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,112 @@
|
||||
<?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\Compiler\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\String\FieldHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Unique Name
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class UniqueName
|
||||
{
|
||||
/**
|
||||
* The compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Registry $registry = null)
|
||||
{
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* Count how many times the same field is used per view
|
||||
*
|
||||
* @param string $name The name of the field
|
||||
* @param string $view The name of the view
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(string $name, string $view)
|
||||
{
|
||||
if (($number = $this->registry->get("unique.names.${view}.counter.${name}")) === null)
|
||||
{
|
||||
$this->registry->set("unique.names.${view}.counter.${name}", 1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// count how many times the field is used
|
||||
$this->registry->set("unique.names.${view}.counter.${name}", ++$number);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Naming each field with an unique name
|
||||
*
|
||||
* @param string $name The name of the field
|
||||
* @param string $view The name of the view
|
||||
*
|
||||
* @return string the name
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $name, string $view): string
|
||||
{
|
||||
// only increment if the field name is used multiple times
|
||||
if ($this->registry->get("unique.names.${view}.counter.${name}") > 1)
|
||||
{
|
||||
$counter = 1;
|
||||
// set the unique name
|
||||
$unique_name = FieldHelper::safe(
|
||||
$name . '_' . $counter
|
||||
);
|
||||
|
||||
while ($this->registry->get("unique.names.${view}.names.${unique_name}") !== null)
|
||||
{
|
||||
// increment the number
|
||||
$counter++;
|
||||
// try again
|
||||
$unique_name = FieldHelper::safe(
|
||||
$name . '_' . $counter
|
||||
);
|
||||
}
|
||||
|
||||
// set the new name number
|
||||
$this->registry->set("unique.names.${view}.names.${unique_name}", $counter);
|
||||
|
||||
// return the unique name
|
||||
return $unique_name;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,168 @@
|
||||
<?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\Compiler\Field;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreValidationInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field Validation Rules
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Validation
|
||||
{
|
||||
/**
|
||||
* Compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Compiler Gui
|
||||
*
|
||||
* @var Gui
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Gui $gui;
|
||||
|
||||
/**
|
||||
* Compiler Placeholder
|
||||
*
|
||||
* @var Placeholder
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Placeholder $placeholder;
|
||||
|
||||
/**
|
||||
* Compiler Customcode
|
||||
*
|
||||
* @var Customcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Customcode $customcode;
|
||||
|
||||
/**
|
||||
* Compiler Field Core Validation
|
||||
*
|
||||
* @var CoreValidationInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected CoreValidationInterface $validation;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
* @param Gui|null $gui The compiler customcode gui object.
|
||||
* @param Placeholder|null $placeholder The compiler placeholder object.
|
||||
* @param Customcode|null $customcode The compiler customcode object.
|
||||
* @param CoreValidationInterface|null $validation The core validation rule object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Registry $registry = null, ?Gui $gui = null, ?Placeholder $placeholder = null,
|
||||
?Customcode $customcode = null, ?CoreValidationInterface $validation = null)
|
||||
{
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
$this->gui = $gui ?: Compiler::_('Customcode.Gui');
|
||||
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
|
||||
$this->customcode = $customcode ?: Compiler::_('Customcode');
|
||||
$this->validation = $validation ?: Compiler::_('Field.Core.Validation');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the validation rule
|
||||
*
|
||||
* @param int $id The field id
|
||||
* @param string $field The field string
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(int $id, string $field)
|
||||
{
|
||||
// check if we have validate (validation rule set)
|
||||
$validation_rule = GetHelper::between(
|
||||
$field, 'validate="', '"'
|
||||
);
|
||||
|
||||
if (StringHelper::check($validation_rule))
|
||||
{
|
||||
// make sure it is lowercase
|
||||
$validation_rule = StringHelper::safe(
|
||||
$validation_rule
|
||||
);
|
||||
|
||||
// link this field to this validation (don't move this down)
|
||||
$this->registry->set("validation.linked.${id}", $validation_rule);
|
||||
|
||||
// make sure it is not already set
|
||||
if ($this->registry->get("validation.rules.${validation_rule}") === null)
|
||||
{
|
||||
// get joomla core validation names and make sure this rule is not a core validation rule
|
||||
if (!in_array($validation_rule, (array) $this->validation->get(true)))
|
||||
{
|
||||
// get the class methods for this rule if it exists
|
||||
if (($php_code = GetHelper::var(
|
||||
'validation_rule', $validation_rule, 'name', 'php'
|
||||
)) !== false)
|
||||
{
|
||||
// open and set the validation rule
|
||||
$this->registry->set("validation.rules.${validation_rule}",
|
||||
$this->gui->set(
|
||||
$this->placeholder->update(
|
||||
$this->customcode->update(
|
||||
base64_decode(
|
||||
$php_code
|
||||
)
|
||||
), $this->placeholder->active
|
||||
),
|
||||
array(
|
||||
'table' => 'validation_rule',
|
||||
'field' => 'php',
|
||||
'id' => GetHelper::var(
|
||||
'validation_rule',
|
||||
$validation_rule, 'name', 'id'
|
||||
),
|
||||
'type' => 'php'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO set the notice that this validation rule is custom and was not found
|
||||
$this->registry->remove("validation.linked.${id}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove link (we only want custom validations linked)
|
||||
$this->registry->remove("validation.linked.${id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@ -13,7 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Component;
|
||||
|
||||
|
||||
/**
|
||||
* Component Placeholder Interface
|
||||
* Component Placeholder Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface PlaceholderInterface
|
||||
{
|
||||
|
@ -13,7 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode;
|
||||
|
||||
|
||||
/**
|
||||
* Customcode Dispenser Interface
|
||||
* Customcode Dispenser Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface DispenserInterface
|
||||
{
|
||||
|
@ -13,7 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode;
|
||||
|
||||
|
||||
/**
|
||||
* Customcode External Interface
|
||||
* Customcode External Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface ExternalInterface
|
||||
{
|
||||
|
@ -13,7 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode;
|
||||
|
||||
|
||||
/**
|
||||
* Customcode Extractor Interface
|
||||
* Customcode Extractor Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface ExtractorInterface
|
||||
{
|
||||
|
@ -13,7 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode;
|
||||
|
||||
|
||||
/**
|
||||
* Customcode Gui Interface
|
||||
* Customcode Gui Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface GuiInterface
|
||||
{
|
||||
|
@ -13,7 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode;
|
||||
|
||||
|
||||
/**
|
||||
* Customcode LockBase Interface
|
||||
* Customcode LockBase Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface LockBaseInterface
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ interface EventInterface
|
||||
* Trigger an event
|
||||
*
|
||||
* @param string $event The event to trigger
|
||||
* @param mix $data The values to pass to the event/plugin
|
||||
* @param mixed $data The values to pass to the event/plugin
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
|
@ -13,7 +13,9 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Extension;
|
||||
|
||||
|
||||
/**
|
||||
* The properties an extension should have to be passed to the InstallScript class
|
||||
* The properties an extension should have to be passed to the InstallScript class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface InstallInterface
|
||||
{
|
||||
|
@ -0,0 +1,32 @@
|
||||
<?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\Compiler\Interfaces\Field;
|
||||
|
||||
|
||||
/**
|
||||
* Field Joomla Core Validation Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface CoreValidationInterface
|
||||
{
|
||||
/**
|
||||
* Get the Array of Existing Validation Rule Names
|
||||
*
|
||||
* @param bool $lowercase Switch to set rules lowercase
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(bool $lowercase = false): array;
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
@ -0,0 +1,34 @@
|
||||
<?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\Compiler\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler History Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface HistoryInterface
|
||||
{
|
||||
/**
|
||||
* Get Item History object
|
||||
*
|
||||
* @param string $type The type of item
|
||||
* @param int $id The item ID
|
||||
*
|
||||
* @return ?object The history item object
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $type, int $id): ?object;
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace VDM\Joomla\Componentbuilder\Compiler\JoomlaThree;
|
||||
|
||||
|
||||
use Joomla\Registry\Registry;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface;
|
||||
|
||||
@ -64,12 +65,13 @@ class Event implements EventInterface
|
||||
* Trigger and event
|
||||
*
|
||||
* @param string $event The event to trigger
|
||||
* @param mix $data The values to pass to the event/plugin
|
||||
* @param mixed $data The values to pass to the event/plugin
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function trigger($event, $data)
|
||||
public function trigger(string $event, $data)
|
||||
{
|
||||
// only execute if plugins were loaded (active)
|
||||
if ($this->activePlugins)
|
||||
|
@ -0,0 +1,232 @@
|
||||
<?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\Compiler\JoomlaThree;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler History
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class History implements HistoryInterface
|
||||
{
|
||||
/**
|
||||
* History Item Object
|
||||
*
|
||||
* @var object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?object $tmp;
|
||||
|
||||
/**
|
||||
* Compiler Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @var \JDatabaseDriver
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected \JDatabaseDriver $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param \JDatabaseDriver|null $db The Database Driver object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?\JDatabaseDriver $db = null)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->db = $db ?: Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Item History object
|
||||
*
|
||||
* @param string $type The type of item
|
||||
* @param int $id The item ID
|
||||
*
|
||||
* @return ?object The history
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $type, int $id): ?object
|
||||
{
|
||||
// quick class object to store old history object
|
||||
$this->tmp = null;
|
||||
// Create a new query object.
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
$query->select('h.*');
|
||||
$query->from('#__ucm_history AS h');
|
||||
$query->where(
|
||||
$this->db->quoteName('h.ucm_item_id') . ' = ' . (int) $id
|
||||
);
|
||||
// Join over the content type for the type id
|
||||
$query->join(
|
||||
'LEFT', '#__content_types AS ct ON ct.type_id = h.ucm_type_id'
|
||||
);
|
||||
$query->where(
|
||||
'ct.type_alias = ' . $this->db->quote(
|
||||
'com_componentbuilder.' . $type
|
||||
)
|
||||
);
|
||||
$query->order('h.save_date DESC');
|
||||
$this->db->setQuery($query, 0, 1);
|
||||
$this->db->execute();
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
// new version of this item found
|
||||
// so we need to mark it as the last compiled version
|
||||
$newActive = $this->db->loadObject();
|
||||
// set the new version watch
|
||||
$this->set($newActive, 1);
|
||||
}
|
||||
// Get last compiled verion
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
$query->select('h.*');
|
||||
$query->from('#__ucm_history AS h');
|
||||
$query->where(
|
||||
$this->db->quoteName('h.ucm_item_id') . ' = ' . (int) $id
|
||||
);
|
||||
$query->where('h.keep_forever = 1');
|
||||
$query->where('h.version_note LIKE ' . $this->db->quote('%component%'));
|
||||
// make sure it does not return the active version
|
||||
if (isset($newActive) && isset($newActive->version_id))
|
||||
{
|
||||
$query->where('h.version_id != ' . (int) $newActive->version_id);
|
||||
}
|
||||
// Join over the content type for the type id
|
||||
$query->join(
|
||||
'LEFT', '#__content_types AS ct ON ct.type_id = h.ucm_type_id'
|
||||
);
|
||||
$query->where(
|
||||
'ct.type_alias = ' . $this->db->quote(
|
||||
'com_componentbuilder.' . $type
|
||||
)
|
||||
);
|
||||
$query->order('h.save_date DESC');
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
// the old active version was found
|
||||
// so we may need to do an SQL update
|
||||
// and unmark the old compiled version
|
||||
$oldActives = $this->db->loadObjectList();
|
||||
foreach ($oldActives as $oldActive)
|
||||
{
|
||||
// remove old version watch
|
||||
$this->set($oldActive, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// return the last used history record or null.
|
||||
return $this->tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Item History Watch
|
||||
*
|
||||
* @param Object $object The history object
|
||||
* @param int $action The action to take
|
||||
* 0 = remove watch
|
||||
* 1 = add watch
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function set(object $object, int $action): bool
|
||||
{
|
||||
// check the note
|
||||
if (JsonHelper::check($object->version_note))
|
||||
{
|
||||
$version_note = json_decode($object->version_note, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$version_note = array('component' => array());
|
||||
}
|
||||
// set watch
|
||||
switch ($action)
|
||||
{
|
||||
case 0:
|
||||
// remove watch
|
||||
if (isset($version_note['component'])
|
||||
&& ($key = array_search(
|
||||
$this->config->component_id, $version_note['component']
|
||||
)) !== false)
|
||||
{
|
||||
// last version that was used to build/compile
|
||||
$this->tmp = json_decode($object->version_data);
|
||||
// remove it from this component
|
||||
unset($version_note['component'][$key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// since it was not found, no need to update anything
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
// add watch
|
||||
if (!in_array($this->config->component_id, $version_note['component']))
|
||||
{
|
||||
$version_note['component'][] = $this->config->component_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
// since it is there already, no need to update anything
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// check if we need to still keep this locked
|
||||
if (isset($version_note['component'])
|
||||
&& ArrayHelper::check($version_note['component']))
|
||||
{
|
||||
// insure component ids are only added once per item
|
||||
$version_note['component'] = array_unique(
|
||||
$version_note['component']
|
||||
);
|
||||
// we may change this, little risky (but since JCB does not have history notes it should be okay for now)
|
||||
$object->version_note = json_encode($version_note);
|
||||
$object->keep_forever = '1';
|
||||
}
|
||||
else
|
||||
{
|
||||
$object->version_note = '';
|
||||
$object->keep_forever = '0';
|
||||
}
|
||||
|
||||
// run the update
|
||||
return $this->db->updateObject('#__ucm_history', $object, 'version_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class Placeholder implements PlaceholderInterface
|
||||
// make sure the placeholders is an array
|
||||
if (!ArrayHelper::check($placeholder))
|
||||
{
|
||||
// This is an error, (TODO) actualy we need to add a kind of log here to know that this happened
|
||||
// This is an error, TODO actually we need to add a kind of log here to know that this happened
|
||||
return $data;
|
||||
}
|
||||
// continue with the work of replacement
|
||||
@ -189,9 +189,6 @@ class Placeholder implements PlaceholderInterface
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case 3:
|
||||
return [ 'start' => "", 'end' => ""];
|
||||
break;
|
||||
case 11:
|
||||
//***[REPLACED$$$$]***//**1**/
|
||||
if ($this->config->get('add_placeholders', false) === true)
|
||||
|
@ -0,0 +1,48 @@
|
||||
<?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\Compiler;
|
||||
|
||||
|
||||
use Joomla\Registry\Registry as JoomlaRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Registry
|
||||
*
|
||||
* So we have full control over this class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Registry extends JoomlaRegistry implements \JsonSerializable, \ArrayAccess, \IteratorAggregate, \Countable
|
||||
{
|
||||
/**
|
||||
* Method to iterate over any part of the registry
|
||||
*
|
||||
* @param string $path Registry path (e.g. joomla.content.showauthor)
|
||||
*
|
||||
* @return \ArrayIterator This object represented as an ArrayIterator.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function _($path)
|
||||
{
|
||||
$data = $this->extract($path);
|
||||
|
||||
if ($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $data->getIterator();
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,16 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service;
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config as CompilerConfig;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Config Service Provider
|
||||
* Compiler Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Config implements ServiceProviderInterface
|
||||
class Compiler implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
@ -34,8 +35,11 @@ class Config implements ServiceProviderInterface
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(CompilerConfig::class, 'Config')
|
||||
$container->alias(Config::class, 'Config')
|
||||
->share('Config', [$this, 'getConfig'], true);
|
||||
|
||||
$container->alias(Registry::class, 'Registry')
|
||||
->share('Registry', [$this, 'getRegistry'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,12 +47,26 @@ class Config implements ServiceProviderInterface
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return CompilerConfig
|
||||
* @return Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getConfig(Container $container): CompilerConfig
|
||||
public function getConfig(Container $container): Config
|
||||
{
|
||||
return new CompilerConfig();
|
||||
}
|
||||
return new Config();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Registry
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getRegistry(Container $container): Registry
|
||||
{
|
||||
return new Registry();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\CMS\Version;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\JoomlaThree\Event as J3Event;
|
||||
|
||||
@ -25,6 +26,14 @@ use VDM\Joomla\Componentbuilder\Compiler\JoomlaThree\Event as J3Event;
|
||||
*/
|
||||
class Event implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Current Joomla Version We are IN
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected $currentVersion;
|
||||
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
@ -37,6 +46,27 @@ class Event implements ServiceProviderInterface
|
||||
{
|
||||
$container->alias(J3Event::class, 'J3.Event')
|
||||
->share('J3.Event', [$this, 'getJ3Event'], true);
|
||||
|
||||
$container->alias(EventInterface::class, 'Event')
|
||||
->share('Event', [$this, 'getEvent'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Event
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return EventInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getEvent(Container $container): EventInterface
|
||||
{
|
||||
if (empty($this->currentVersion))
|
||||
{
|
||||
$this->currentVersion = Version::MAJOR_VERSION;
|
||||
}
|
||||
|
||||
return $container->get('J' . $this->currentVersion . '.Event');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,12 +74,13 @@ class Event implements ServiceProviderInterface
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return EventInterface
|
||||
* @return J3Event
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getJ3Event(Container $container): EventInterface
|
||||
public function getJ3Event(Container $container): J3Event
|
||||
{
|
||||
return new J3Event();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,14 @@ use VDM\Joomla\Componentbuilder\Compiler\Extension\JoomlaThree\InstallScript as
|
||||
*/
|
||||
class Extension implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Current Joomla Version Being Build
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected $targetVersion;
|
||||
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
@ -35,6 +43,9 @@ class Extension implements ServiceProviderInterface
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(GetScriptInterface::class, 'Extension.InstallScript')
|
||||
->share('Extension.InstallScript', [$this, 'getExtensionInstallScript'], true);
|
||||
|
||||
$container->alias(J3InstallScript::class, 'J3.Extension.InstallScript')
|
||||
->share('J3.Extension.InstallScript', [$this, 'getJ3ExtensionInstallScript'], true);
|
||||
}
|
||||
@ -44,12 +55,31 @@ class Extension implements ServiceProviderInterface
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return J3InstallScript
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getJ3ExtensionInstallScript(Container $container): J3InstallScript
|
||||
{
|
||||
return new J3InstallScript();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Joomla Extension Install Script
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return GetScriptInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getJ3ExtensionInstallScript(Container $container): GetScriptInterface
|
||||
public function getExtensionInstallScript(Container $container): GetScriptInterface
|
||||
{
|
||||
return new J3InstallScript();
|
||||
}
|
||||
if (empty($this->targetVersion))
|
||||
{
|
||||
$this->targetVersion = $container->get('Config')->joomla_version;
|
||||
}
|
||||
|
||||
return $container->get('J' . $this->targetVersion . '.Extension.InstallScript');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,250 @@
|
||||
<?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\Compiler\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field as CompilerField;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Data;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Name;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\TypeName;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\UniqueName;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Validation;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\DatabaseName;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Field\JoomlaThree\CoreValidation as J3CoreValidation;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Field\CoreValidationInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Compiler Field
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Field implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Current Joomla Version Being Build
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected $targetVersion;
|
||||
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(CompilerField::class, 'Field')
|
||||
->share('Field', [$this, 'getField'], true);
|
||||
|
||||
$container->alias(Data::class, 'Field.Data')
|
||||
->share('Field.Data', [$this, 'getData'], true);
|
||||
|
||||
$container->alias(Validation::class, 'Field.Validation')
|
||||
->share('Field.Validation', [$this, 'getValidation'], true);
|
||||
|
||||
$container->alias(J3CoreValidation::class, 'J3.Field.Core.Validation')
|
||||
->share('J3.Field.Core.Validation', [$this, 'getJ3CoreValidation'], true);
|
||||
|
||||
$container->alias(CoreValidationInterface::class, 'Field.Core.Validation')
|
||||
->share('Field.Core.Validation', [$this, 'getCoreValidation'], true);
|
||||
|
||||
$container->alias(Customcode::class, 'Field.Customcode')
|
||||
->share('Field.Customcode', [$this, 'getCustomcode'], true);
|
||||
|
||||
$container->alias(Name::class, 'Field.Name')
|
||||
->share('Field.Name', [$this, 'getFieldName'], true);
|
||||
|
||||
$container->alias(TypeName::class, 'Field.Type.Name')
|
||||
->share('Field.Type.Name', [$this, 'getFieldTypeName'], true);
|
||||
|
||||
$container->alias(UniqueName::class, 'Field.Unique.Name')
|
||||
->share('Field.Unique.Name', [$this, 'getFieldUniqueName'], true);
|
||||
|
||||
$container->alias(DatabaseName::class, 'Field.Database.Name')
|
||||
->share('Field.Database.Name', [$this, 'getFieldDatabaseName'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return CompilerField
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getField(Container $container): CompilerField
|
||||
{
|
||||
return new CompilerField(
|
||||
$container->get('Field.Data'),
|
||||
$container->get('Field.Name'),
|
||||
$container->get('Field.Type.Name'),
|
||||
$container->get('Field.Unique.Name')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field Data
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Data
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getData(Container $container): Data
|
||||
{
|
||||
return new Data(
|
||||
$container->get('Config'),
|
||||
$container->get('Event'),
|
||||
$container->get('History'),
|
||||
$container->get('Placeholder'),
|
||||
$container->get('Customcode'),
|
||||
$container->get('Field.Customcode'),
|
||||
$container->get('Field.Validation')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field Validation
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Validation
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getValidation(Container $container): Validation
|
||||
{
|
||||
return new Validation(
|
||||
$container->get('Registry'),
|
||||
$container->get('Customcode.Gui'),
|
||||
$container->get('Placeholder'),
|
||||
$container->get('Customcode'),
|
||||
$container->get('Field.Core.Validation')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field Joomla 3 Validation
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return J3CoreValidation
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getJ3CoreValidation(Container $container): J3CoreValidation
|
||||
{
|
||||
return new J3CoreValidation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field Core Validation
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return CoreValidationInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getCoreValidation(Container $container): CoreValidationInterface
|
||||
{
|
||||
if (empty($this->targetVersion))
|
||||
{
|
||||
$this->targetVersion = $container->get('Config')->joomla_version;
|
||||
}
|
||||
|
||||
return $container->get('J' . $this->targetVersion . '.Field.Core.Validation');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field Customcode
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Customcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getCustomcode(Container $container): Customcode
|
||||
{
|
||||
return new Customcode(
|
||||
$container->get('Customcode.Dispenser')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field Name
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Name
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getFieldName(Container $container): Name
|
||||
{
|
||||
return new Name(
|
||||
$container->get('Placeholder'),
|
||||
$container->get('Field.Unique.Name'),
|
||||
$container->get('Registry')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field Type Name
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return TypeName
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getFieldTypeName(Container $container): TypeName
|
||||
{
|
||||
return new TypeName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field Unique Name
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return UniqueName
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getFieldUniqueName(Container $container): UniqueName
|
||||
{
|
||||
return new UniqueName(
|
||||
$container->get('Registry')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Compiler Field Database Name
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return DatabaseName
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getFieldDatabaseName(Container $container): DatabaseName
|
||||
{
|
||||
return new DatabaseName(
|
||||
$container->get('Registry')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
<?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\Compiler\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\CMS\Version;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\JoomlaThree\History as J3History;
|
||||
|
||||
|
||||
/**
|
||||
* History Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class History implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Current Joomla Version We are IN
|
||||
*
|
||||
* @var int
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected $currentVersion;
|
||||
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->alias(J3History::class, 'J3.History')
|
||||
->share('J3.History', [$this, 'getJ3History'], true);
|
||||
|
||||
$container->alias(HistoryInterface::class, 'History')
|
||||
->share('History', [$this, 'getHistory'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the History
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return HistoryInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getHistory(Container $container): HistoryInterface
|
||||
{
|
||||
if (empty($this->currentVersion))
|
||||
{
|
||||
$this->currentVersion = Version::MAJOR_VERSION;
|
||||
}
|
||||
|
||||
return $container->get('J' . $this->currentVersion . '.History');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Joomla 3 History
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return J3History
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getJ3History(Container $container): J3History
|
||||
{
|
||||
return new J3History(
|
||||
$container->get('Config')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ abstract class Indent
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function _(int $nr): string
|
||||
public static function _(int $nr): string
|
||||
{
|
||||
// check if we already have the string
|
||||
if (!isset(self::$bucket[$nr]))
|
||||
|
Loading…
Reference in New Issue
Block a user