Release of v3.2.5-beta1
Add first classes for the new import engine.
This commit is contained in:
parent
a745bb39cd
commit
00e846f41c
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,9 +1,6 @@
|
|||||||
# v3.2.5-alpha3
|
# v3.2.5-beta1
|
||||||
|
|
||||||
- Fix Save failed issue in dynamicGet. #1148
|
- Add first classes for the new import engine.
|
||||||
- Move all [TEXT, EDITOR, TEXTAREA] fields from [NOT NULL] to [NULL]
|
|
||||||
- Add the DateHelper class and improve the date methods.
|
|
||||||
- Add simple SessionHelper class.
|
|
||||||
|
|
||||||
# v3.2.5-alpha
|
# v3.2.5-alpha
|
||||||
|
|
||||||
@ -14,6 +11,10 @@
|
|||||||
- Move the setDocument and _prepareDocument above the display in the site view and custom admin view.
|
- Move the setDocument and _prepareDocument above the display in the site view and custom admin view.
|
||||||
- Update the trashhelper layout to work in Joomla 5.
|
- Update the trashhelper layout to work in Joomla 5.
|
||||||
- Add AllowDynamicProperties (Joomla 4+5) to view class to allow Custom Dynamic Get methods to work without issues.
|
- Add AllowDynamicProperties (Joomla 4+5) to view class to allow Custom Dynamic Get methods to work without issues.
|
||||||
|
- Fix Save failed issue in dynamicGet. #1148
|
||||||
|
- Move all [TEXT, EDITOR, TEXTAREA] fields from [NOT NULL] to [NULL]
|
||||||
|
- Add the DateHelper class and improve the date methods.
|
||||||
|
- Add simple SessionHelper class.
|
||||||
|
|
||||||
# v3.2.4
|
# v3.2.4
|
||||||
|
|
||||||
|
10
README.md
10
README.md
@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo
|
|||||||
|
|
||||||
Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have!
|
Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have!
|
||||||
|
|
||||||
You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.2.5-alpha3) with **ALL** its features and **ALL** concepts totally open-source and free!
|
You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.2.5-beta1) with **ALL** its features and **ALL** concepts totally open-source and free!
|
||||||
|
|
||||||
> Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45)
|
> Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45)
|
||||||
|
|
||||||
@ -144,13 +144,13 @@ TODO
|
|||||||
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
|
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
|
||||||
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||||
+ *First Build*: 30th April, 2015
|
+ *First Build*: 30th April, 2015
|
||||||
+ *Last Build*: 13th October, 2024
|
+ *Last Build*: 7th November, 2024
|
||||||
+ *Version*: 3.2.5-alpha3
|
+ *Version*: 3.2.5-beta1
|
||||||
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
|
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||||
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
|
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
+ *Line count*: **859606**
|
+ *Line count*: **864927**
|
||||||
+ *Field count*: **2098**
|
+ *Field count*: **2098**
|
||||||
+ *File count*: **5826**
|
+ *File count*: **5860**
|
||||||
+ *Folder count*: **505**
|
+ *Folder count*: **505**
|
||||||
|
|
||||||
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
|
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
|
||||||
|
@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo
|
|||||||
|
|
||||||
Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have!
|
Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have!
|
||||||
|
|
||||||
You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.2.5-alpha3) with **ALL** its features and **ALL** concepts totally open-source and free!
|
You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (3.2.5-beta1) with **ALL** its features and **ALL** concepts totally open-source and free!
|
||||||
|
|
||||||
> Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45)
|
> Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45)
|
||||||
|
|
||||||
@ -144,13 +144,13 @@ TODO
|
|||||||
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
|
+ *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io)
|
||||||
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
+ *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||||
+ *First Build*: 30th April, 2015
|
+ *First Build*: 30th April, 2015
|
||||||
+ *Last Build*: 13th October, 2024
|
+ *Last Build*: 7th November, 2024
|
||||||
+ *Version*: 3.2.5-alpha3
|
+ *Version*: 3.2.5-beta1
|
||||||
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
|
+ *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved.
|
||||||
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
|
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
+ *Line count*: **859606**
|
+ *Line count*: **864927**
|
||||||
+ *Field count*: **2098**
|
+ *Field count*: **2098**
|
||||||
+ *File count*: **5826**
|
+ *File count*: **5860**
|
||||||
+ *Folder count*: **505**
|
+ *Folder count*: **505**
|
||||||
|
|
||||||
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
|
> This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com).
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<extension type="component" version="3.10" method="upgrade">
|
<extension type="component" version="3.10" method="upgrade">
|
||||||
<name>COM_COMPONENTBUILDER</name>
|
<name>COM_COMPONENTBUILDER</name>
|
||||||
<creationDate>13th October, 2024</creationDate>
|
<creationDate>7th November, 2024</creationDate>
|
||||||
<author>Llewellyn van der Merwe</author>
|
<author>Llewellyn van der Merwe</author>
|
||||||
<authorEmail>joomla@vdm.io</authorEmail>
|
<authorEmail>joomla@vdm.io</authorEmail>
|
||||||
<authorUrl>https://dev.vdm.io</authorUrl>
|
<authorUrl>https://dev.vdm.io</authorUrl>
|
||||||
<copyright>Copyright (C) 2015 Vast Development Method. All rights reserved.</copyright>
|
<copyright>Copyright (C) 2015 Vast Development Method. All rights reserved.</copyright>
|
||||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||||
<version>3.2.5-alpha3</version>
|
<version>3.2.5-beta1</version>
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
<h1>Component Builder (v.3.2.5-alpha3)</h1>
|
<h1>Component Builder (v.3.2.5-beta1)</h1>
|
||||||
<div style="clear: both;"></div>
|
<div style="clear: both;"></div>
|
||||||
<p>The Component Builder for [Joomla](https://extensions.joomla.org/extension/component-builder/) is highly advanced tool that is truly able to build extremely complex components in a fraction of the time.
|
<p>The Component Builder for [Joomla](https://extensions.joomla.org/extension/component-builder/) is highly advanced tool that is truly able to build extremely complex components in a fraction of the time.
|
||||||
|
|
||||||
|
@ -220,13 +220,13 @@
|
|||||||
<element>pkg_component_builder</element>
|
<element>pkg_component_builder</element>
|
||||||
<type>package</type>
|
<type>package</type>
|
||||||
<client>site</client>
|
<client>site</client>
|
||||||
<version>3.2.5-alpha3</version>
|
<version>3.2.5-beta1</version>
|
||||||
<infourl title="Component Builder!">https://dev.vdm.io</infourl>
|
<infourl title="Component Builder!">https://dev.vdm.io</infourl>
|
||||||
<downloads>
|
<downloads>
|
||||||
<downloadurl type="full" format="zip">https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v3.2.5-alpha3.zip</downloadurl>
|
<downloadurl type="full" format="zip">https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v3.2.5-beta1.zip</downloadurl>
|
||||||
</downloads>
|
</downloads>
|
||||||
<tags>
|
<tags>
|
||||||
<tag>alpha</tag>
|
<tag>beta</tag>
|
||||||
</tags>
|
</tags>
|
||||||
<maintainer>Llewellyn van der Merwe</maintainer>
|
<maintainer>Llewellyn van der Merwe</maintainer>
|
||||||
<maintainerurl>https://dev.vdm.io</maintainerurl>
|
<maintainerurl>https://dev.vdm.io</maintainerurl>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace VDM\Joomla\Abstraction;
|
namespace VDM\Joomla\Abstraction;
|
||||||
|
|
||||||
|
|
||||||
use VDM\Joomla\Interfaces\Tableinterface;
|
use VDM\Joomla\Interfaces\TableInterface;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,7 +20,7 @@ use VDM\Joomla\Interfaces\Tableinterface;
|
|||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
*/
|
*/
|
||||||
abstract class BaseTable implements Tableinterface
|
abstract class BaseTable implements TableInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* All areas/views/tables with their field details
|
* All areas/views/tables with their field details
|
||||||
|
@ -38,6 +38,14 @@ abstract class Database
|
|||||||
*/
|
*/
|
||||||
protected string $table;
|
protected string $table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date format to return
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 5.0.2
|
||||||
|
*/
|
||||||
|
protected string $dateFormat = 'Y-m-d H:i:s';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -62,23 +70,32 @@ abstract class Database
|
|||||||
**/
|
**/
|
||||||
protected function quote($value)
|
protected function quote($value)
|
||||||
{
|
{
|
||||||
if ($value === null) // hmm the null does pose an issue (will keep an eye on this)
|
if ($value === null)
|
||||||
{
|
{
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_numeric($value))
|
if (is_numeric($value))
|
||||||
{
|
{
|
||||||
|
// If the value is a numeric string (e.g., "0123"), treat it as a string to preserve the format
|
||||||
|
if (is_string($value) && ltrim($value, '0') !== $value)
|
||||||
|
{
|
||||||
|
return $this->db->quote($value);
|
||||||
|
}
|
||||||
|
|
||||||
if (filter_var($value, FILTER_VALIDATE_INT))
|
if (filter_var($value, FILTER_VALIDATE_INT))
|
||||||
{
|
{
|
||||||
return (int) $value;
|
return (int) $value;
|
||||||
}
|
}
|
||||||
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
|
|
||||||
|
if (filter_var($value, FILTER_VALIDATE_FLOAT))
|
||||||
{
|
{
|
||||||
return (float) $value;
|
return (float) $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif (is_bool($value)) // not sure if this will work well (but its correct)
|
|
||||||
|
// Handle boolean values
|
||||||
|
if (is_bool($value))
|
||||||
{
|
{
|
||||||
return $value ? 'TRUE' : 'FALSE';
|
return $value ? 'TRUE' : 'FALSE';
|
||||||
}
|
}
|
||||||
@ -86,10 +103,10 @@ abstract class Database
|
|||||||
// For date and datetime values
|
// For date and datetime values
|
||||||
if ($value instanceof \DateTime)
|
if ($value instanceof \DateTime)
|
||||||
{
|
{
|
||||||
return $this->db->quote($value->format('Y-m-d H:i:s'));
|
return $this->db->quote($value->format($this->getDateFormat()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// For other data types, just escape it
|
// For other types of values, quote as string
|
||||||
return $this->db->quote($value);
|
return $this->db->quote($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,5 +128,16 @@ abstract class Database
|
|||||||
|
|
||||||
return $table;
|
return $table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the date format to return in the quote
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @since 5.0.2
|
||||||
|
**/
|
||||||
|
protected function getDateFormat(): string
|
||||||
|
{
|
||||||
|
return $this->dateFormat;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ namespace VDM\Joomla\Abstraction;
|
|||||||
|
|
||||||
use VDM\Joomla\Utilities\StringHelper;
|
use VDM\Joomla\Utilities\StringHelper;
|
||||||
use VDM\Joomla\Utilities\ArrayHelper;
|
use VDM\Joomla\Utilities\ArrayHelper;
|
||||||
use VDM\Joomla\Interfaces\Tableinterface as Table;
|
use VDM\Joomla\Interfaces\TableInterface as Table;
|
||||||
use VDM\Joomla\Interfaces\ModelInterface;
|
use VDM\Joomla\Interfaces\ModelInterface;
|
||||||
|
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ abstract class Model implements ModelInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Model a value of multiple items
|
* Model a value of multiple items
|
||||||
* Example: $this->items(Array, 'value_key', 'table_name');
|
* Example: $this->values(Array, 'value_key', 'table_name');
|
||||||
*
|
*
|
||||||
* @param array|null $items The array of values
|
* @param array|null $items The array of values
|
||||||
* @param string $field The field key
|
* @param string $field The field key
|
||||||
|
@ -14,7 +14,7 @@ namespace VDM\Joomla\Abstraction;
|
|||||||
|
|
||||||
use Joomla\CMS\Factory;
|
use Joomla\CMS\Factory;
|
||||||
use Joomla\CMS\Version;
|
use Joomla\CMS\Version;
|
||||||
use VDM\Joomla\Interfaces\Tableinterface as Table;
|
use VDM\Joomla\Interfaces\TableInterface as Table;
|
||||||
use VDM\Joomla\Interfaces\SchemaInterface;
|
use VDM\Joomla\Interfaces\SchemaInterface;
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ namespace VDM\Joomla\Abstraction;
|
|||||||
|
|
||||||
use Joomla\CMS\Factory;
|
use Joomla\CMS\Factory;
|
||||||
use VDM\Joomla\Interfaces\SchemaInterface as Schema;
|
use VDM\Joomla\Interfaces\SchemaInterface as Schema;
|
||||||
use VDM\Joomla\Interfaces\Tableinterface as Table;
|
use VDM\Joomla\Interfaces\TableInterface as Table;
|
||||||
use VDM\Joomla\Utilities\ClassHelper;
|
use VDM\Joomla\Utilities\ClassHelper;
|
||||||
use VDM\Joomla\Interfaces\SchemaCheckerInterface;
|
use VDM\Joomla\Interfaces\SchemaCheckerInterface;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace VDM\Joomla\Componentbuilder;
|
namespace VDM\Joomla\Componentbuilder;
|
||||||
|
|
||||||
|
|
||||||
use VDM\Joomla\Interfaces\Tableinterface;
|
use VDM\Joomla\Interfaces\TableInterface;
|
||||||
use VDM\Joomla\Abstraction\BaseTable;
|
use VDM\Joomla\Abstraction\BaseTable;
|
||||||
|
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ use VDM\Joomla\Abstraction\BaseTable;
|
|||||||
*
|
*
|
||||||
* @since 3.2.0
|
* @since 3.2.0
|
||||||
*/
|
*/
|
||||||
final class Table extends BaseTable implements Tableinterface
|
final class Table extends BaseTable implements TableInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* All areas/views/tables with their field details
|
* All areas/views/tables with their field details
|
||||||
|
@ -0,0 +1,426 @@
|
|||||||
|
<?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\Table;
|
||||||
|
|
||||||
|
|
||||||
|
use VDM\Joomla\Componentbuilder\Table;
|
||||||
|
use VDM\Joomla\Interfaces\TableValidatorInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table Value Validator
|
||||||
|
*
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
final class Validator implements TableValidatorInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The Table Class.
|
||||||
|
*
|
||||||
|
* @var Table
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
protected Table $table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A map of MySQL base types to their respective validation methods.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
protected array $validators = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A map of defaults for the respective datatypes.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
protected array $defaults = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache of the parsed datatype details
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
protected array $datatypes = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param Table $table The Table Class.
|
||||||
|
*
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
public function __construct(Table $table)
|
||||||
|
{
|
||||||
|
$this->table = $table;
|
||||||
|
|
||||||
|
// Register datatype validators (mapping MySQL types to handlers)
|
||||||
|
$this->registerValidators();
|
||||||
|
|
||||||
|
// Register datatype defaults
|
||||||
|
$this->registerDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the valid value based on datatype definition.
|
||||||
|
* If the value is valid, return it. If not, return the default value,
|
||||||
|
* NULL (if allowed), or an empty string if 'EMPTY' is set.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param string $field The field name.
|
||||||
|
* @param string $table The table name.
|
||||||
|
*
|
||||||
|
* @return mixed Returns the valid value, or the default, NULL, or empty string based on validation.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
public function getValid($value, string $field, string $table)
|
||||||
|
{
|
||||||
|
// Get the database field definition
|
||||||
|
if (($dbField = $this->getDatabaseField($field, $table)) === null)
|
||||||
|
{
|
||||||
|
return null; // not legal field or table
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the value is valid for the field
|
||||||
|
if ($this->validate($value, $dbField))
|
||||||
|
{
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If invalid, return default, NULL (if allowed), or empty string
|
||||||
|
return $this->getDefault($dbField, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate if the given value is valid for the provided database field.
|
||||||
|
* This is a private method as `getValid()` will handle the actual logic.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param array $dbField The database field details (type, default, null_switch, etc.).
|
||||||
|
*
|
||||||
|
* @return bool Returns true if the value is valid, false otherwise.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function validate($value, array $dbField): bool
|
||||||
|
{
|
||||||
|
// Extract datatype and handle the validation
|
||||||
|
$typeInfo = $this->parseDataType($dbField['type']);
|
||||||
|
$baseType = $typeInfo['type'];
|
||||||
|
|
||||||
|
// Use the appropriate validator if it exists
|
||||||
|
if (isset($this->validators[$baseType]))
|
||||||
|
{
|
||||||
|
return call_user_func($this->validators[$baseType], $value, $typeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no validator exists, assume invalid
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle returning the default value, null, or empty string if validation fails.
|
||||||
|
*
|
||||||
|
* @param array $dbField The database field details.
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
*
|
||||||
|
* @return mixed The default value, null, or empty string based on field settings.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function getDefault(array $dbField, $value)
|
||||||
|
{
|
||||||
|
// get default value from field db
|
||||||
|
$db_default = isset($dbField['default']) ? $dbField['default'] : null;
|
||||||
|
|
||||||
|
// If a default value is provided, return it
|
||||||
|
if ($db_default !== null)
|
||||||
|
{
|
||||||
|
return strtoupper($db_default) === 'EMPTY' ? '' : $db_default;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if NULL is allowed
|
||||||
|
if (isset($dbField['null_switch']) && strtoupper($dbField['null_switch']) === 'NULL')
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to datatype default
|
||||||
|
$typeInfo = $this->parseDataType($dbField['type']);
|
||||||
|
return $this->defaults[$typeInfo['type']] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the data type from the database field and extract details like type, size, and precision.
|
||||||
|
*
|
||||||
|
* @param string $datatype The full MySQL datatype (e.g., VARCHAR(255)).
|
||||||
|
*
|
||||||
|
* @return array An array containing 'type', 'size', and other relevant info.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function parseDataType(string $datatype): array
|
||||||
|
{
|
||||||
|
if (isset($this->datatypes[$datatype]))
|
||||||
|
{
|
||||||
|
return $this->datatypes[$datatype];
|
||||||
|
}
|
||||||
|
|
||||||
|
$pattern = '/(?<type>\w+)(\((?<size>\d+)(,\s*(?<precision>\d+))?\))?/i';
|
||||||
|
preg_match($pattern, $datatype, $matches);
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'type' => isset($matches['type']) ? strtolower($matches['type']) : strtolower($datatype),
|
||||||
|
'size' => $matches['size'] ?? null,
|
||||||
|
'precision' => $matches['precision'] ?? null,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->datatypes[$datatype] = $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the database field structure for the specified field and table.
|
||||||
|
* In your case, you use `$db = $this->table->get($table, $field, 'db')`.
|
||||||
|
*
|
||||||
|
* @param string $field The field name.
|
||||||
|
* @param string $table The table name.
|
||||||
|
*
|
||||||
|
* @return array The database field details, including type, default, null_switch, etc.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function getDatabaseField(string $field, string $table): array
|
||||||
|
{
|
||||||
|
// Simulated retrieval of field details. Replace with actual logic.
|
||||||
|
return $this->table->get($table, $field, 'db');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register validators for MySQL data types.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function registerValidators(): void
|
||||||
|
{
|
||||||
|
$this->validators = [
|
||||||
|
'int' => [$this, 'validateInteger'],
|
||||||
|
'tinyint' => [$this, 'validateInteger'],
|
||||||
|
'smallint' => [$this, 'validateInteger'],
|
||||||
|
'mediumint' => [$this, 'validateInteger'],
|
||||||
|
'bigint' => [$this, 'validateInteger'],
|
||||||
|
'varchar' => [$this, 'validateString'],
|
||||||
|
'char' => [$this, 'validateString'],
|
||||||
|
'text' => [$this, 'validateText'],
|
||||||
|
'tinytext' => [$this, 'validateText'],
|
||||||
|
'mediumtext' => [$this, 'validateText'],
|
||||||
|
'longtext' => [$this, 'validateText'],
|
||||||
|
'decimal' => [$this, 'validateDecimal'],
|
||||||
|
'float' => [$this, 'validateFloat'],
|
||||||
|
'double' => [$this, 'validateFloat'],
|
||||||
|
'date' => [$this, 'validateDate'],
|
||||||
|
'datetime' => [$this, 'validateDate'],
|
||||||
|
'timestamp' => [$this, 'validateDate'],
|
||||||
|
'time' => [$this, 'validateDate'],
|
||||||
|
'json' => [$this, 'validateJson'],
|
||||||
|
'blob' => [$this, 'validateBlob'],
|
||||||
|
'tinyblob' => [$this, 'validateBlob'],
|
||||||
|
'mediumblob' => [$this, 'validateBlob'],
|
||||||
|
'longblob' => [$this, 'validateBlob'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register default values for MySQL data types.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function registerDefaults(): void
|
||||||
|
{
|
||||||
|
$this->defaults = [
|
||||||
|
'int' => 0,
|
||||||
|
'tinyint' => 0,
|
||||||
|
'smallint' => 0,
|
||||||
|
'mediumint' => 0,
|
||||||
|
'bigint' => 0,
|
||||||
|
'varchar' => '',
|
||||||
|
'char' => '',
|
||||||
|
'text' => '',
|
||||||
|
'tinytext' => '',
|
||||||
|
'mediumtext' => '',
|
||||||
|
'longtext' => '',
|
||||||
|
'decimal' => 0.0,
|
||||||
|
'float' => 0.0,
|
||||||
|
'double' => 0.0,
|
||||||
|
'date' => '0000-00-00',
|
||||||
|
'datetime' => '0000-00-00 00:00:00',
|
||||||
|
'timestamp' => '0000-00-00 00:00:00',
|
||||||
|
'time' => '00:00:00',
|
||||||
|
'json' => '{}',
|
||||||
|
'blob' => '',
|
||||||
|
'tinyblob' => '',
|
||||||
|
'mediumblob' => '',
|
||||||
|
'longblob' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------- Validation Methods -----------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate integer types (including tinyint, smallint, mediumint, etc.).
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param array $typeInfo The parsed data type information.
|
||||||
|
*
|
||||||
|
* @return bool True if valid, false otherwise.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function validateInteger($value, array $typeInfo): bool
|
||||||
|
{
|
||||||
|
if (!is_numeric($value))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = (int)$value;
|
||||||
|
if (isset($typeInfo['unsigned']) && $typeInfo['unsigned'] && $value < 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate string types like VARCHAR and CHAR.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param array $typeInfo The parsed data type information.
|
||||||
|
*
|
||||||
|
* @return bool True if valid, false otherwise.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function validateString($value, array $typeInfo): bool
|
||||||
|
{
|
||||||
|
if (!is_string($value))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the length exceeds the allowed size
|
||||||
|
if ($typeInfo['size'] !== null && strlen($value) > (int)$typeInfo['size'])
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate text types like TEXT, TINYTEXT, MEDIUMTEXT, LONGTEXT.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param array $typeInfo The parsed data type information.
|
||||||
|
*
|
||||||
|
* @return bool True if valid, false otherwise.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function validateText($value, array $typeInfo): bool
|
||||||
|
{
|
||||||
|
return is_string($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate float, double, and decimal types.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param array $typeInfo The parsed data type information.
|
||||||
|
*
|
||||||
|
* @return bool True if valid, false otherwise.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function validateFloat($value, array $typeInfo): bool
|
||||||
|
{
|
||||||
|
return is_numeric($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate decimal types (numeric precision and scale).
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param array $typeInfo The parsed data type information.
|
||||||
|
*
|
||||||
|
* @return bool True if valid, false otherwise.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function validateDecimal($value, array $typeInfo): bool
|
||||||
|
{
|
||||||
|
return is_numeric($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate date, datetime, timestamp, and time types.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param array $typeInfo The parsed data type information.
|
||||||
|
*
|
||||||
|
* @return bool True if valid, false otherwise.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function validateDate($value, array $typeInfo): bool
|
||||||
|
{
|
||||||
|
$formats = [
|
||||||
|
'date' => 'Y-m-d',
|
||||||
|
'datetime' => 'Y-m-d H:i:s',
|
||||||
|
'timestamp' => 'Y-m-d H:i:s',
|
||||||
|
'time' => 'H:i:s',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!isset($formats[$typeInfo['type']]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dateTime = \DateTime::createFromFormat($formats[$typeInfo['type']], $value);
|
||||||
|
return $dateTime && $dateTime->format($formats[$typeInfo['type']]) === $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate JSON types.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param array $typeInfo The parsed data type information.
|
||||||
|
*
|
||||||
|
* @return bool True if valid, false otherwise.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function validateJson($value, array $typeInfo): bool
|
||||||
|
{
|
||||||
|
json_decode($value);
|
||||||
|
return json_last_error() === JSON_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate BLOB types (including TINYBLOB, MEDIUMBLOB, LONGBLOB).
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param array $typeInfo The parsed data type information.
|
||||||
|
*
|
||||||
|
* @return bool True if valid, false otherwise.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
private function validateBlob($value, array $typeInfo): bool
|
||||||
|
{
|
||||||
|
return is_string($value) || is_resource($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,7 @@ namespace VDM\Joomla\Interfaces;
|
|||||||
/**
|
/**
|
||||||
* The VDM Core Table Interface
|
* The VDM Core Table Interface
|
||||||
*/
|
*/
|
||||||
interface Tableinterface
|
interface TableInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get any value from a item/field/column of an area/view/table
|
* Get any value from a item/field/column of an area/view/table
|
@ -0,0 +1,34 @@
|
|||||||
|
<?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\Interfaces;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The VDM Core Table Validator Interface
|
||||||
|
*/
|
||||||
|
interface TableValidatorInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the valid value based on datatype definition.
|
||||||
|
* If the value is valid, return it. If not, return the default value,
|
||||||
|
* NULL (if allowed), or an empty string if 'EMPTY' is set.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to validate.
|
||||||
|
* @param string $field The field name.
|
||||||
|
* @param string $table The table name.
|
||||||
|
*
|
||||||
|
* @return mixed Returns the valid value, or the default, NULL, or empty string based on validation.
|
||||||
|
* @since 5.3.0
|
||||||
|
*/
|
||||||
|
public function getValid($value, string $field, string $table);
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,7 @@ use Joomla\DI\Container;
|
|||||||
use Joomla\DI\ServiceProviderInterface;
|
use Joomla\DI\ServiceProviderInterface;
|
||||||
use VDM\Joomla\Componentbuilder\Table as DataTable;
|
use VDM\Joomla\Componentbuilder\Table as DataTable;
|
||||||
use VDM\Joomla\Componentbuilder\Table\Schema;
|
use VDM\Joomla\Componentbuilder\Table\Schema;
|
||||||
|
use VDM\Joomla\Componentbuilder\Table\Validator;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,6 +41,9 @@ class Table implements ServiceProviderInterface
|
|||||||
|
|
||||||
$container->alias(Schema::class, 'Table.Schema')
|
$container->alias(Schema::class, 'Table.Schema')
|
||||||
->share('Table.Schema', [$this, 'getSchema'], true);
|
->share('Table.Schema', [$this, 'getSchema'], true);
|
||||||
|
|
||||||
|
$container->alias(Validator::class, 'Table.Validator')
|
||||||
|
->share('Table.Validator', [$this, 'getValidator'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,5 +73,20 @@ class Table implements ServiceProviderInterface
|
|||||||
$container->get('Table')
|
$container->get('Table')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get The Validator Class.
|
||||||
|
*
|
||||||
|
* @param Container $container The DI container.
|
||||||
|
*
|
||||||
|
* @return Validator
|
||||||
|
* @since 3.2.2
|
||||||
|
*/
|
||||||
|
public function getValidator(Container $container): Validator
|
||||||
|
{
|
||||||
|
return new Validator(
|
||||||
|
$container->get('Table')
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10001,7 +10001,7 @@ class Com_ComponentbuilderInstallerScript
|
|||||||
echo '<div style="background-color: #fff;" class="alert alert-info"><a target="_blank" href="https://dev.vdm.io" title="Component Builder">
|
echo '<div style="background-color: #fff;" class="alert alert-info"><a target="_blank" href="https://dev.vdm.io" title="Component Builder">
|
||||||
<img src="components/com_componentbuilder/assets/images/vdm-component.jpg"/>
|
<img src="components/com_componentbuilder/assets/images/vdm-component.jpg"/>
|
||||||
</a>
|
</a>
|
||||||
<h3>Upgrade to Version 3.2.5-alpha3 Was Successful! Let us know if anything is not working as expected.</h3></div>';
|
<h3>Upgrade to Version 3.2.5-beta1 Was Successful! Let us know if anything is not working as expected.</h3></div>';
|
||||||
|
|
||||||
// Set db if not set already.
|
// Set db if not set already.
|
||||||
if (!isset($db))
|
if (!isset($db))
|
||||||
|
Loading…
Reference in New Issue
Block a user