update 2024-03-26 19:05:48
This commit is contained in:
parent
08ee03a01a
commit
0010165da8
116
README.md
116
README.md
|
@ -1 +1,115 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
███████╗██╗ ██╗██████╗ ███████╗██████╗
|
||||
██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗
|
||||
███████╗██║ ██║██████╔╝█████╗ ██████╔╝
|
||||
╚════██║██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗
|
||||
███████║╚██████╔╝██║ ███████╗██║ ██║
|
||||
╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗ ███████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗██╔════╝
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝███████╗
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗╚════██║
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║███████║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚══════╝
|
||||
```
|
||||
|
||||
### What is JCB Super Powers?
|
||||
The Joomla Component Builder (JCB) Super Power features are designed to enhance JCB's functionality and streamline the development process. These Super Powers enable developers to efficiently manage and share their custom powers across multiple JCB instances through repositories hosted on [https://git.vdm.dev/[username]/[repository-name]](https://git.vdm.dev). JCB Super Powers are managed using a combination of layers, events, tasks, methods, switches, and algorithms, which work together to provide powerful customization and extensibility options. More details on JCB Super Powers can be found in the [Super Powers Documentation](https://git.vdm.dev/joomla/super-powers/wiki).
|
||||
|
||||
In summary, JCB Super Powers offer a flexible and efficient way to manage and share functionalities between JCB instances. By utilizing a sophisticated system of layers, events, tasks, methods, switches, and algorithms, developers can seamlessly integrate JCB core powers and their custom powers. For more information on how to work with JCB Super Powers, refer to the [Super Powers User Guide](https://git.vdm.dev/joomla/super-powers/wiki).
|
||||
|
||||
### What can I find here?
|
||||
This repository contains an index (see below) of all the approved powers within the JCB GUI. During the compilation of a component, these powers are automatically added to the repository, ensuring a well-organized and accessible collection of functionalities.
|
||||
|
||||
# Index of powers
|
||||
|
||||
- **Namespace**: [VDM\Joomla\Abstraction](#vdm-joomla-abstraction)
|
||||
|
||||
- **abstract class ActiveRegistry** | [Details](src/43134867-5cb8-4280-9be8-309fd2fd135f) | [Code](src/43134867-5cb8-4280-9be8-309fd2fd135f/code.php) | [Settings](src/43134867-5cb8-4280-9be8-309fd2fd135f/settings.json) | Super__43134867_5cb8_4280_9be8_309fd2fd135f__Power
|
||||
- **abstract class BaseConfig** | [Details](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319) | [Code](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/code.php) | [Settings](src/ffbd4e1f-a342-4080-ab7d-1de3741bf319/settings.json) | Super__ffbd4e1f_a342_4080_ab7d_1de3741bf319__Power
|
||||
- **abstract class BaseTable** | [Details](src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6) | [Code](src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/code.php) | [Settings](src/e0f6ddbe-2a35-4537-942c-faff2ebd04f6/settings.json) | Super__e0f6ddbe_2a35_4537_942c_faff2ebd04f6__Power
|
||||
- **abstract class Database** | [Details](src/6cbef8f8-4813-48e3-b05a-65e1aea95171) | [Code](src/6cbef8f8-4813-48e3-b05a-65e1aea95171/code.php) | [Settings](src/6cbef8f8-4813-48e3-b05a-65e1aea95171/settings.json) | Super__6cbef8f8_4813_48e3_b05a_65e1aea95171__Power
|
||||
- **abstract class Model** | [Details](src/584747d1-3a86-453d-b7a3-a2219de8d777) | [Code](src/584747d1-3a86-453d-b7a3-a2219de8d777/code.php) | [Settings](src/584747d1-3a86-453d-b7a3-a2219de8d777/settings.json) | Super__584747d1_3a86_453d_b7a3_a2219de8d777__Power
|
||||
- **abstract class Registry** | [Details](src/7e822c03-1b20-41d1-9427-f5b8d5836af7) | [Code](src/7e822c03-1b20-41d1-9427-f5b8d5836af7/code.php) | [Settings](src/7e822c03-1b20-41d1-9427-f5b8d5836af7/settings.json) | Super__7e822c03_1b20_41d1_9427_f5b8d5836af7__Power
|
||||
- **Namespace**: [VDM\Joomla\Componentbuilder](#vdm-joomla-componentbuilder)
|
||||
|
||||
- **class Table** | [Details](src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8) | [Code](src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/code.php) | [Settings](src/bfd1d6d5-56c1-4fe9-9fee-1c5910e1f5d8/settings.json) | Super__bfd1d6d5_56c1_4fe9_9fee_1c5910e1f5d8__Power
|
||||
- **Namespace**: [VDM\Joomla\Database](#vdm-joomla-database)
|
||||
|
||||
- **final class Insert** | [Details](src/524eb8f6-38d4-47dc-92ad-98b94e099ac0) | [Code](src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/code.php) | [Settings](src/524eb8f6-38d4-47dc-92ad-98b94e099ac0/settings.json) | Super__524eb8f6_38d4_47dc_92ad_98b94e099ac0__Power
|
||||
- **final class Load** | [Details](src/06f8eada-d59b-441c-b287-0aea1793da5a) | [Code](src/06f8eada-d59b-441c-b287-0aea1793da5a/code.php) | [Settings](src/06f8eada-d59b-441c-b287-0aea1793da5a/settings.json) | Super__06f8eada_d59b_441c_b287_0aea1793da5a__Power
|
||||
- **final class Update** | [Details](src/cce56585-58b0-4f72-a92c-e2635ea52d83) | [Code](src/cce56585-58b0-4f72-a92c-e2635ea52d83/code.php) | [Settings](src/cce56585-58b0-4f72-a92c-e2635ea52d83/settings.json) | Super__cce56585_58b0_4f72_a92c_e2635ea52d83__Power
|
||||
- **Namespace**: [VDM\Joomla\Interfaces](#vdm-joomla-interfaces)
|
||||
|
||||
- **interface Activeregistryinterface** | [Details](src/af0eedbe-603b-4671-8e5a-28165d88254b) | [Code](src/af0eedbe-603b-4671-8e5a-28165d88254b/code.php) | [Settings](src/af0eedbe-603b-4671-8e5a-28165d88254b/settings.json) | Super__af0eedbe_603b_4671_8e5a_28165d88254b__Power
|
||||
- **interface FactoryInterface** | [Details](src/caf33c5d-858c-4f9a-894f-ab302ec5445a) | [Code](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/code.php) | [Settings](src/caf33c5d-858c-4f9a-894f-ab302ec5445a/settings.json) | Super__caf33c5d_858c_4f9a_894f_ab302ec5445a__Power
|
||||
- **interface InsertInterface** | [Details](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48) | [Code](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/code.php) | [Settings](src/ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48/settings.json) | Super__ad12ca1c_d3ce_4e7f_88c5_c6c92bdedc48__Power
|
||||
- **interface LoadInterface** | [Details](src/2ad31f74-f579-499d-b98b-c4f54fd615dd) | [Code](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/code.php) | [Settings](src/2ad31f74-f579-499d-b98b-c4f54fd615dd/settings.json) | Super__2ad31f74_f579_499d_b98b_c4f54fd615dd__Power
|
||||
- **interface ModelInterface** | [Details](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff) | [Code](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/code.php) | [Settings](src/8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff/settings.json) | Super__8aef58c1_3f70_4bd4_b9e4_3f29fcd41cff__Power
|
||||
- **interface Registryinterface** | [Details](src/64e291c2-11f1-423d-a44d-837cc12cc017) | [Code](src/64e291c2-11f1-423d-a44d-837cc12cc017/code.php) | [Settings](src/64e291c2-11f1-423d-a44d-837cc12cc017/settings.json) | Super__64e291c2_11f1_423d_a44d_837cc12cc017__Power
|
||||
- **interface Tableinterface** | [Details](src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf) | [Code](src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf/code.php) | [Settings](src/2da6d6c4-eb29-4d69-8bc2-36d96e916adf/settings.json) | Super__2da6d6c4_eb29_4d69_8bc2_36d96e916adf__Power
|
||||
- **interface UpdateInterface** | [Details](src/7179fde6-1e51-4b51-8545-7ca18f74a0f4) | [Code](src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/code.php) | [Settings](src/7179fde6-1e51-4b51-8545-7ca18f74a0f4/settings.json) | Super__7179fde6_1e51_4b51_8545_7ca18f74a0f4__Power
|
||||
- **Namespace**: [VDM\Joomla\Utilities](#vdm-joomla-utilities)
|
||||
|
||||
- **abstract class ArrayHelper** | [Details](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a) | [Code](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/code.php) | [Settings](src/0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a/settings.json) | Super__0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a__Power
|
||||
- **abstract class Base64Helper** | [Details](src/64a6ff6c-069c-4a11-a76b-db5e36c27690) | [Code](src/64a6ff6c-069c-4a11-a76b-db5e36c27690/code.php) | [Settings](src/64a6ff6c-069c-4a11-a76b-db5e36c27690/settings.json) | Super__64a6ff6c_069c_4a11_a76b_db5e36c27690__Power
|
||||
- **abstract class FileHelper** | [Details](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0) | [Code](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/code.php) | [Settings](src/a223b31e-ea1d-4cdf-92ae-5f9becffaff0/settings.json) | Super__a223b31e_ea1d_4cdf_92ae_5f9becffaff0__Power
|
||||
- **abstract class FormHelper** | [Details](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa) | [Code](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/code.php) | [Settings](src/1198aecf-84c6-45d2-aea8-d531aa4afdfa/settings.json) | Super__1198aecf_84c6_45d2_aea8_d531aa4afdfa__Power
|
||||
- **abstract class GetHelper** | [Details](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc) | [Code](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/code.php) | [Settings](src/db87c339-5bb6-4291-a7ef-2c48ea1b06bc/settings.json) | Super__db87c339_5bb6_4291_a7ef_2c48ea1b06bc__Power
|
||||
- **abstract class GuidHelper** | [Details](src/9c513baf-b279-43fd-ae29-a585c8cbc4f0) | [Code](src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/code.php) | [Settings](src/9c513baf-b279-43fd-ae29-a585c8cbc4f0/settings.json) | Super__9c513baf_b279_43fd_ae29_a585c8cbc4f0__Power
|
||||
- **abstract class JsonHelper** | [Details](src/4b225c51-d293-48e4-b3f6-5136cf5c3f18) | [Code](src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/code.php) | [Settings](src/4b225c51-d293-48e4-b3f6-5136cf5c3f18/settings.json) | Super__4b225c51_d293_48e4_b3f6_5136cf5c3f18__Power
|
||||
- **abstract class MathHelper** | [Details](src/152c8793-8b75-4715-996a-257b9f65451c) | [Code](src/152c8793-8b75-4715-996a-257b9f65451c/code.php) | [Settings](src/152c8793-8b75-4715-996a-257b9f65451c/settings.json) | Super__152c8793_8b75_4715_996a_257b9f65451c__Power
|
||||
- **abstract class ObjectHelper** | [Details](src/91004529-94a9-4590-b842-e7c6b624ecf5) | [Code](src/91004529-94a9-4590-b842-e7c6b624ecf5/code.php) | [Settings](src/91004529-94a9-4590-b842-e7c6b624ecf5/settings.json) | Super__91004529_94a9_4590_b842_e7c6b624ecf5__Power
|
||||
- **abstract class StringHelper** | [Details](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef) | [Code](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/code.php) | [Settings](src/1f28cb53-60d9-4db1-b517-3c7dc6b429ef/settings.json) | Super__1f28cb53_60d9_4db1_b517_3c7dc6b429ef__Power
|
||||
- **Namespace**: [VDM\Joomla\Componentbuilder\Abstraction](#vdm-joomla-componentbuilder-abstraction)
|
||||
|
||||
- **abstract class BaseRegistry** | [Details](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c) | [Code](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/code.php) | [Settings](src/b84e947d-2a13-44f7-ac0f-3902ae55ae0c/settings.json) | Super__b84e947d_2a13_44f7_ac0f_3902ae55ae0c__Power
|
||||
- **Namespace**: [VDM\Joomla\Componentbuilder\Service](#vdm-joomla-componentbuilder-service)
|
||||
|
||||
- **class Database** | [Details](src/4815e1c7-a433-443d-a112-d1e03d7df84b) | [Code](src/4815e1c7-a433-443d-a112-d1e03d7df84b/code.php) | [Settings](src/4815e1c7-a433-443d-a112-d1e03d7df84b/settings.json) | Super__4815e1c7_a433_443d_a112_d1e03d7df84b__Power
|
||||
- **Namespace**: [VDM\Joomla\Componentbuilder\Utilities](#vdm-joomla-componentbuilder-utilities)
|
||||
|
||||
- **abstract class FilterHelper** | [Details](src/cddcac51-9a46-47c4-ba59-105c70453bd6) | [Code](src/cddcac51-9a46-47c4-ba59-105c70453bd6/code.php) | [Settings](src/cddcac51-9a46-47c4-ba59-105c70453bd6/settings.json) | Super__cddcac51_9a46_47c4_ba59_105c70453bd6__Power
|
||||
- **Namespace**: [VDM\Joomla\Utilities\Component](#vdm-joomla-utilities-component)
|
||||
|
||||
- **abstract class Helper** | [Details](src/640b5352-fb09-425f-a26e-cd44eda03f15) | [Code](src/640b5352-fb09-425f-a26e-cd44eda03f15/code.php) | [Settings](src/640b5352-fb09-425f-a26e-cd44eda03f15/settings.json) | Super__640b5352_fb09_425f_a26e_cd44eda03f15__Power
|
||||
- **Namespace**: [VDM\Joomla\Utilities\String](#vdm-joomla-utilities-string)
|
||||
|
||||
- **abstract class ClassfunctionHelper** | [Details](src/30c5b4c2-f75f-4d15-869a-f8bfedd87358) | [Code](src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/code.php) | [Settings](src/30c5b4c2-f75f-4d15-869a-f8bfedd87358/settings.json) | Super__30c5b4c2_f75f_4d15_869a_f8bfedd87358__Power
|
||||
- **abstract class FieldHelper** | [Details](src/9ef0eb24-aae4-4f5a-99af-d724db44808f) | [Code](src/9ef0eb24-aae4-4f5a-99af-d724db44808f/code.php) | [Settings](src/9ef0eb24-aae4-4f5a-99af-d724db44808f/settings.json) | Super__9ef0eb24_aae4_4f5a_99af_d724db44808f__Power
|
||||
- **abstract class NamespaceHelper** | [Details](src/ce8cf834-6bac-44fb-941c-861f7e046cc0) | [Code](src/ce8cf834-6bac-44fb-941c-861f7e046cc0/code.php) | [Settings](src/ce8cf834-6bac-44fb-941c-861f7e046cc0/settings.json) | Super__ce8cf834_6bac_44fb_941c_861f7e046cc0__Power
|
||||
- **abstract class PluginHelper** | [Details](src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6) | [Code](src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/code.php) | [Settings](src/3cf76fbf-fd95-4a33-878e-7aff6d36b7f6/settings.json) | Super__3cf76fbf_fd95_4a33_878e_7aff6d36b7f6__Power
|
||||
- **abstract class TypeHelper** | [Details](src/a8935cbe-7701-40dc-bfd5-675f2d600954) | [Code](src/a8935cbe-7701-40dc-bfd5-675f2d600954/code.php) | [Settings](src/a8935cbe-7701-40dc-bfd5-675f2d600954/settings.json) | Super__a8935cbe_7701_40dc_bfd5_675f2d600954__Power
|
||||
- **Namespace**: [VDM\Joomla\Abstraction\Registry\Traits](#vdm-joomla-abstraction-registry-traits)
|
||||
|
||||
- **trait Count** | [Details](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8) | [Code](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.php) | [Settings](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/settings.json) | Super__11572d9b_e3d5_4b29_904c_9618d8f2bfd8__Power
|
||||
- **trait GetString** | [Details](src/59b1a2ea-d77e-4040-ac8c-e65cd8743e9b) | [Code](src/59b1a2ea-d77e-4040-ac8c-e65cd8743e9b/code.php) | [Settings](src/59b1a2ea-d77e-4040-ac8c-e65cd8743e9b/settings.json) | Super__59b1a2ea_d77e_4040_ac8c_e65cd8743e9b__Power
|
||||
- **trait InArray** | [Details](src/215b35ac-1b26-4838-bbcf-d1fdbbd9353f) | [Code](src/215b35ac-1b26-4838-bbcf-d1fdbbd9353f/code.php) | [Settings](src/215b35ac-1b26-4838-bbcf-d1fdbbd9353f/settings.json) | Super__215b35ac_1b26_4838_bbcf_d1fdbbd9353f__Power
|
||||
- **trait IsArray** | [Details](src/c09e8968-c767-4175-bb3d-8432f206a2c7) | [Code](src/c09e8968-c767-4175-bb3d-8432f206a2c7/code.php) | [Settings](src/c09e8968-c767-4175-bb3d-8432f206a2c7/settings.json) | Super__c09e8968_c767_4175_bb3d_8432f206a2c7__Power
|
||||
- **trait IsString** | [Details](src/ff7d0111-8f79-42aa-ac14-b53ba2c49369) | [Code](src/ff7d0111-8f79-42aa-ac14-b53ba2c49369/code.php) | [Settings](src/ff7d0111-8f79-42aa-ac14-b53ba2c49369/settings.json) | Super__ff7d0111_8f79_42aa_ac14_b53ba2c49369__Power
|
||||
- **trait ToString** | [Details](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e) | [Code](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.php) | [Settings](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/settings.json) | Super__7d494d91_ab60_43cd_aecf_d50e07f7f30e__Power
|
||||
- **trait VarExport** | [Details](src/52a1d14f-304a-431c-8fa4-411179942db5) | [Code](src/52a1d14f-304a-431c-8fa4-411179942db5/code.php) | [Settings](src/52a1d14f-304a-431c-8fa4-411179942db5/settings.json) | Super__52a1d14f_304a_431c_8fa4_411179942db5__Power
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗ ██████╗ ███╗ ███╗██╗ █████╗
|
||||
██║██╔═══██╗██╔═══██╗████╗ ████║██║ ██╔══██╗
|
||||
██║██║ ██║██║ ██║██╔████╔██║██║ ███████║
|
||||
██ ██║██║ ██║██║ ██║██║╚██╔╝██║██║ ██╔══██║
|
||||
╚█████╔╝╚██████╔╝╚██████╔╝██║ ╚═╝ ██║███████╗██║ ██║
|
||||
╚════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
|
||||
██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗ ███╗ ██╗███████╗███╗ ██╗████████╗
|
||||
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔═══██╗████╗ ██║██╔════╝████╗ ██║╚══██╔══╝
|
||||
██║ ██║ ██║██╔████╔██║██████╔╝██║ ██║██╔██╗ ██║█████╗ ██╔██╗ ██║ ██║
|
||||
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██║╚██╗██║██╔══╝ ██║╚██╗██║ ██║
|
||||
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚██████╔╝██║ ╚████║███████╗██║ ╚████║ ██║
|
||||
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═══╝ ╚═╝
|
||||
██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗
|
||||
██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝
|
||||
██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗
|
||||
██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║
|
||||
╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -1 +1,167 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# final class Load (Details)
|
||||
> namespace: **VDM\Joomla\Database**
|
||||
> extends: **Database**
|
||||
```uml
|
||||
@startuml
|
||||
class Load << (F,LightGreen) >> #RoyalBlue {
|
||||
+ rows(array $select, array $tables, ...) : ?array
|
||||
+ items(array $select, array $tables, ...) : ?array
|
||||
+ row(array $select, array $tables, ...) : ?array
|
||||
+ item(array $select, array $tables, ...) : ?object
|
||||
+ max(string $field, array $tables, ...) : ?int
|
||||
+ count(array $tables, array $filter) : ?int
|
||||
+ value(array $select, array $tables, ...) : mixed
|
||||
# many(array $select, array $tables, ...) : bool
|
||||
# one(array $select, array $tables, ...) : bool
|
||||
# query(array $select, array $tables, ...) : ?object
|
||||
}
|
||||
|
||||
note right of Load::rows
|
||||
Load data rows as an array of associated arrays
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
?int $limit = null
|
||||
end note
|
||||
|
||||
note left of Load::items
|
||||
Load data rows as an array of objects
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
?int $limit = null
|
||||
end note
|
||||
|
||||
note right of Load::row
|
||||
Load data row as an associated array
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
end note
|
||||
|
||||
note left of Load::item
|
||||
Load data row as an object
|
||||
|
||||
since: 3.2.0
|
||||
return: ?object
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
end note
|
||||
|
||||
note right of Load::max
|
||||
Get the max value based on a filtered result from a given table
|
||||
|
||||
since: 3.2.0
|
||||
return: ?int
|
||||
|
||||
arguments:
|
||||
string $field
|
||||
array $tables
|
||||
array $filter
|
||||
end note
|
||||
|
||||
note left of Load::count
|
||||
Count the number of items based on filter result from a given table
|
||||
|
||||
since: 3.2.0
|
||||
return: ?int
|
||||
end note
|
||||
|
||||
note right of Load::value
|
||||
Load one value from a row
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
end note
|
||||
|
||||
note left of Load::many
|
||||
Load many
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
?int $limit = null
|
||||
end note
|
||||
|
||||
note right of Load::one
|
||||
Load one
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
end note
|
||||
|
||||
note left of Load::query
|
||||
Get the query object
|
||||
|
||||
since: 3.2.0
|
||||
return: ?object
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
?int $limit = null
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,461 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Database;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Interfaces\LoadInterface;
|
||||
use VDM\Joomla\Abstraction\Database;
|
||||
|
||||
|
||||
/**
|
||||
* Database Load
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Load extends Database implements LoadInterface
|
||||
{
|
||||
/**
|
||||
* Load data rows as an array of associated arrays
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array
|
||||
{
|
||||
// set key if found
|
||||
$key = '';
|
||||
if (isset($select['key']))
|
||||
{
|
||||
if (is_string($select['key']))
|
||||
{
|
||||
$key = $select['key'];
|
||||
}
|
||||
unset($select['key']);
|
||||
}
|
||||
|
||||
// check if we can get many rows
|
||||
if ($this->many($select, $tables, $where, $order, $limit))
|
||||
{
|
||||
// return associated arrays from the table records
|
||||
return $this->db->loadAssocList($key);
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data rows as an array of objects
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array
|
||||
{
|
||||
// set key if found
|
||||
$key = '';
|
||||
if (isset($select['key']))
|
||||
{
|
||||
if (is_string($select['key']))
|
||||
{
|
||||
$key = $select['key'];
|
||||
}
|
||||
unset($select['key']);
|
||||
}
|
||||
|
||||
// check if we can get many rows
|
||||
if ($this->many($select, $tables, $where, $order, $limit))
|
||||
{
|
||||
// return associated arrays from the table records
|
||||
return $this->db->loadObjectList($key);
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data row as an associated array
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $select, array $tables, ?array $where = null, ?array $order = null): ?array
|
||||
{
|
||||
// check if we can get one row
|
||||
if ($this->one($select, $tables, $where, $order))
|
||||
{
|
||||
return $this->db->loadAssoc();
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data row as an object
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object
|
||||
{
|
||||
// check if we can get one row
|
||||
if ($this->one($select, $tables, $where, $order))
|
||||
{
|
||||
return $this->db->loadObject();
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the max value based on a filtered result from a given table
|
||||
*
|
||||
* @param string $field The field key
|
||||
* @param string $tables The tables
|
||||
* @param array $filter The filter keys
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function max($field, array $tables, array $filter): ?int
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query(["all" => "MAX(`$field`)"], $tables, $filter);
|
||||
|
||||
// Load the max number
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return (int) $this->db->loadResult();
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of items based on filter result from a given table
|
||||
*
|
||||
* @param string $tables The table
|
||||
* @param array $filter The filter keys
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function count(array $tables, array $filter): ?int
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query(["all" => 'COUNT(*)'], $tables, $filter);
|
||||
|
||||
// Load the max number
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return (int) $this->db->loadResult();
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load one value from a row
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function value(array $select, array $tables, ?array $where = null, ?array $order = null)
|
||||
{
|
||||
// check if we can get one value
|
||||
if ($this->one($select, $tables, $where, $order))
|
||||
{
|
||||
return $this->db->loadResult();
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load many
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function many(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): bool
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query($select, $tables, $where, $order, $limit);
|
||||
|
||||
// Load the items
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load one
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function one(array $select, array $tables, ?array $where = null, ?array $order = null): bool
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query($select, $tables, $where, $order);
|
||||
|
||||
// Load the item
|
||||
$this->db->setQuery($query, 0, 1);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query object
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return object|null The query object (DatabaseQuery)
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function query(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?object
|
||||
{
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// check if we have an all selection set
|
||||
if (isset($select['all']))
|
||||
{
|
||||
// all selection example array: ['all' => ['a.*', 'b.*']]
|
||||
if (ArrayHelper::check($select['all']))
|
||||
{
|
||||
foreach ($select['all'] as $select_all)
|
||||
{
|
||||
// set target selection
|
||||
$query->select(
|
||||
$select_all
|
||||
);
|
||||
}
|
||||
}
|
||||
// all selection example string: ['all' =>'a.*']
|
||||
elseif (is_string($select['all']))
|
||||
{
|
||||
// set target selection
|
||||
$query->select(
|
||||
$select['all']
|
||||
);
|
||||
}
|
||||
unset($select['all']);
|
||||
}
|
||||
|
||||
// load the table where join
|
||||
if (ArrayHelper::check($select))
|
||||
{
|
||||
// set target selection
|
||||
$query->select(
|
||||
$this->db->quoteName(
|
||||
array_keys($select),
|
||||
array_values($select)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// set main table
|
||||
$query->from($this->db->quoteName($this->getTable($tables['a']), 'a'));
|
||||
|
||||
// remove main table
|
||||
unset($tables['a']);
|
||||
|
||||
// load the table where join
|
||||
if (ArrayHelper::check($tables))
|
||||
{
|
||||
foreach ($tables as $as => $table)
|
||||
{
|
||||
$query->join(
|
||||
'LEFT', $this->db->quoteName(
|
||||
$this->getTable($table['name']), $as
|
||||
) . ' ON (' . $this->db->quoteName($table['join_on'])
|
||||
. ' = ' . $this->db->quoteName($table['as_on']) . ')'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// load the table where getters
|
||||
if (ArrayHelper::check($where))
|
||||
{
|
||||
foreach ($where as $key => $value)
|
||||
{
|
||||
if (ArrayHelper::check($value))
|
||||
{
|
||||
if (isset($value['value']) && isset($value['operator']))
|
||||
{
|
||||
// check if value needs to be quoted
|
||||
$quote = $value['quote'] ?? true;
|
||||
if (!$quote)
|
||||
{
|
||||
if (ArrayHelper::check($value['value']))
|
||||
{
|
||||
// add the where by array
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' (' .
|
||||
implode(',', $value['value'])
|
||||
. ')'
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the where
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' ' . $value['value']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ArrayHelper::check($value['value']))
|
||||
{
|
||||
// add the where by array
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' (' .
|
||||
implode(',',
|
||||
array_map(
|
||||
fn($val) => $this->quote($val),
|
||||
$value['value']
|
||||
)
|
||||
)
|
||||
. ')'
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the where
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' ' . $this->quote($value['value']));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we should through an exception
|
||||
// for security we just return nothing for now
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the where
|
||||
$query->where($this->db->quoteName($key) .
|
||||
' = ' . $this->quote($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load the row ordering
|
||||
if (ArrayHelper::check($order))
|
||||
{
|
||||
foreach ($order as $key => $direction)
|
||||
{
|
||||
// add the ordering
|
||||
$query->order($this->db->quoteName($key) .
|
||||
' ' . $direction);
|
||||
}
|
||||
}
|
||||
|
||||
// only return a limited number
|
||||
if (is_numeric($limit))
|
||||
{
|
||||
$query->setLimit($limit);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,440 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Load data rows as an array of associated arrays
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array
|
||||
{
|
||||
// set key if found
|
||||
$key = '';
|
||||
if (isset($select['key']))
|
||||
{
|
||||
if (is_string($select['key']))
|
||||
{
|
||||
$key = $select['key'];
|
||||
}
|
||||
unset($select['key']);
|
||||
}
|
||||
|
||||
// check if we can get many rows
|
||||
if ($this->many($select, $tables, $where, $order, $limit))
|
||||
{
|
||||
// return associated arrays from the table records
|
||||
return $this->db->loadAssocList($key);
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data rows as an array of objects
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array
|
||||
{
|
||||
// set key if found
|
||||
$key = '';
|
||||
if (isset($select['key']))
|
||||
{
|
||||
if (is_string($select['key']))
|
||||
{
|
||||
$key = $select['key'];
|
||||
}
|
||||
unset($select['key']);
|
||||
}
|
||||
|
||||
// check if we can get many rows
|
||||
if ($this->many($select, $tables, $where, $order, $limit))
|
||||
{
|
||||
// return associated arrays from the table records
|
||||
return $this->db->loadObjectList($key);
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data row as an associated array
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $select, array $tables, ?array $where = null, ?array $order = null): ?array
|
||||
{
|
||||
// check if we can get one row
|
||||
if ($this->one($select, $tables, $where, $order))
|
||||
{
|
||||
return $this->db->loadAssoc();
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data row as an object
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object
|
||||
{
|
||||
// check if we can get one row
|
||||
if ($this->one($select, $tables, $where, $order))
|
||||
{
|
||||
return $this->db->loadObject();
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the max value based on a filtered result from a given table
|
||||
*
|
||||
* @param string $field The field key
|
||||
* @param string $tables The tables
|
||||
* @param array $filter The filter keys
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function max($field, array $tables, array $filter): ?int
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query(["all" => "MAX(`$field`)"], $tables, $filter);
|
||||
|
||||
// Load the max number
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return (int) $this->db->loadResult();
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of items based on filter result from a given table
|
||||
*
|
||||
* @param string $tables The table
|
||||
* @param array $filter The filter keys
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function count(array $tables, array $filter): ?int
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query(["all" => 'COUNT(*)'], $tables, $filter);
|
||||
|
||||
// Load the max number
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return (int) $this->db->loadResult();
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load one value from a row
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function value(array $select, array $tables, ?array $where = null, ?array $order = null)
|
||||
{
|
||||
// check if we can get one value
|
||||
if ($this->one($select, $tables, $where, $order))
|
||||
{
|
||||
return $this->db->loadResult();
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load many
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function many(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): bool
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query($select, $tables, $where, $order, $limit);
|
||||
|
||||
// Load the items
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load one
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function one(array $select, array $tables, ?array $where = null, ?array $order = null): bool
|
||||
{
|
||||
// only do check if we have the table set
|
||||
if (isset($tables['a']))
|
||||
{
|
||||
// get the query
|
||||
$query = $this->query($select, $tables, $where, $order);
|
||||
|
||||
// Load the item
|
||||
$this->db->setQuery($query, 0, 1);
|
||||
$this->db->execute();
|
||||
|
||||
// check if we have values
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// data does not exist
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query object
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return object|null The query object (DatabaseQuery)
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function query(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?object
|
||||
{
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// check if we have an all selection set
|
||||
if (isset($select['all']))
|
||||
{
|
||||
// all selection example array: ['all' => ['a.*', 'b.*']]
|
||||
if (ArrayHelper::check($select['all']))
|
||||
{
|
||||
foreach ($select['all'] as $select_all)
|
||||
{
|
||||
// set target selection
|
||||
$query->select(
|
||||
$select_all
|
||||
);
|
||||
}
|
||||
}
|
||||
// all selection example string: ['all' =>'a.*']
|
||||
elseif (is_string($select['all']))
|
||||
{
|
||||
// set target selection
|
||||
$query->select(
|
||||
$select['all']
|
||||
);
|
||||
}
|
||||
unset($select['all']);
|
||||
}
|
||||
|
||||
// load the table where join
|
||||
if (ArrayHelper::check($select))
|
||||
{
|
||||
// set target selection
|
||||
$query->select(
|
||||
$this->db->quoteName(
|
||||
array_keys($select),
|
||||
array_values($select)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// set main table
|
||||
$query->from($this->db->quoteName($this->getTable($tables['a']), 'a'));
|
||||
|
||||
// remove main table
|
||||
unset($tables['a']);
|
||||
|
||||
// load the table where join
|
||||
if (ArrayHelper::check($tables))
|
||||
{
|
||||
foreach ($tables as $as => $table)
|
||||
{
|
||||
$query->join(
|
||||
'LEFT', $this->db->quoteName(
|
||||
$this->getTable($table['name']), $as
|
||||
) . ' ON (' . $this->db->quoteName($table['join_on'])
|
||||
. ' = ' . $this->db->quoteName($table['as_on']) . ')'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// load the table where getters
|
||||
if (ArrayHelper::check($where))
|
||||
{
|
||||
foreach ($where as $key => $value)
|
||||
{
|
||||
if (ArrayHelper::check($value))
|
||||
{
|
||||
if (isset($value['value']) && isset($value['operator']))
|
||||
{
|
||||
// check if value needs to be quoted
|
||||
$quote = $value['quote'] ?? true;
|
||||
if (!$quote)
|
||||
{
|
||||
if (ArrayHelper::check($value['value']))
|
||||
{
|
||||
// add the where by array
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' (' .
|
||||
implode(',', $value['value'])
|
||||
. ')'
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the where
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' ' . $value['value']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ArrayHelper::check($value['value']))
|
||||
{
|
||||
// add the where by array
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' (' .
|
||||
implode(',',
|
||||
array_map(
|
||||
fn($val) => $this->quote($val),
|
||||
$value['value']
|
||||
)
|
||||
)
|
||||
. ')'
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the where
|
||||
$query->where($this->db->quoteName($key) . ' ' .
|
||||
$value['operator'] . ' ' . $this->quote($value['value']));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we should through an exception
|
||||
// for security we just return nothing for now
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// add the where
|
||||
$query->where($this->db->quoteName($key) .
|
||||
' = ' . $this->quote($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// load the row ordering
|
||||
if (ArrayHelper::check($order))
|
||||
{
|
||||
foreach ($order as $key => $direction)
|
||||
{
|
||||
// add the ordering
|
||||
$query->order($this->db->quoteName($key) .
|
||||
' ' . $direction);
|
||||
}
|
||||
}
|
||||
|
||||
// only return a limited number
|
||||
if (is_numeric($limit))
|
||||
{
|
||||
$query->setLimit($limit);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
|
|
@ -1 +1,25 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "6cbef8f8-4813-48e3-b05a-65e1aea95171",
|
||||
"guid": "06f8eada-d59b-441c-b287-0aea1793da5a",
|
||||
"implements": [
|
||||
"2ad31f74-f579-499d-b98b-c4f54fd615dd"
|
||||
],
|
||||
"load_selection": null,
|
||||
"name": "Load",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Database.Load",
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Database.Load",
|
||||
"description": "Database Load\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,52 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class ArrayHelper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities**
|
||||
```uml
|
||||
@startuml
|
||||
abstract ArrayHelper #Orange {
|
||||
+ {static} check($array, $removeEmptyString = false)
|
||||
+ {static} merge($arrays) : ?array
|
||||
+ {static} intersect($a_array, $b_array) : bool
|
||||
}
|
||||
|
||||
note right of ArrayHelper::check
|
||||
Check if have an array with a length
|
||||
|
||||
since: 3.2.0
|
||||
end note
|
||||
|
||||
note right of ArrayHelper::merge
|
||||
Merge an array of array's
|
||||
|
||||
since: 3.0.9
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
note right of ArrayHelper::intersect
|
||||
Check if arrays intersect
|
||||
|
||||
since: 3.1.1
|
||||
return: bool
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,99 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* Some array tricks helper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class ArrayHelper
|
||||
{
|
||||
/**
|
||||
* Check if have an array with a length
|
||||
*
|
||||
* @input array The array to check
|
||||
*
|
||||
* @returns int|false number of items in array on success
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function check($array, $removeEmptyString = false)
|
||||
{
|
||||
if (is_array($array) && ($nr = count((array) $array)) > 0)
|
||||
{
|
||||
// also make sure the empty strings are removed
|
||||
if ($removeEmptyString)
|
||||
{
|
||||
$array = array_filter($array);
|
||||
|
||||
if ($array === [])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($array);
|
||||
}
|
||||
|
||||
return $nr;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge an array of array's
|
||||
*
|
||||
* @input array The arrays you would like to merge
|
||||
*
|
||||
* @returns array|null merged array on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function merge($arrays): ?array
|
||||
{
|
||||
if(self::check($arrays))
|
||||
{
|
||||
$merged = [];
|
||||
foreach ($arrays as $array)
|
||||
{
|
||||
if (self::check($array))
|
||||
{
|
||||
$merged = array_merge($merged, $array);
|
||||
}
|
||||
}
|
||||
return $merged;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if arrays intersect
|
||||
*
|
||||
* @input array The first array
|
||||
* @input array The second array
|
||||
*
|
||||
* @returns bool true if intersect else false
|
||||
*
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public static function intersect($a_array, $b_array): bool
|
||||
{
|
||||
// flip the second array
|
||||
$b_array = array_flip($b_array);
|
||||
|
||||
// loop the first array
|
||||
foreach ($a_array as $v)
|
||||
{
|
||||
if (isset($b_array[$v]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,83 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Check if have an array with a length
|
||||
*
|
||||
* @input array The array to check
|
||||
*
|
||||
* @returns int|false number of items in array on success
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function check($array, $removeEmptyString = false)
|
||||
{
|
||||
if (is_array($array) && ($nr = count((array) $array)) > 0)
|
||||
{
|
||||
// also make sure the empty strings are removed
|
||||
if ($removeEmptyString)
|
||||
{
|
||||
$array = array_filter($array);
|
||||
|
||||
if ($array === [])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return count($array);
|
||||
}
|
||||
|
||||
return $nr;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge an array of array's
|
||||
*
|
||||
* @input array The arrays you would like to merge
|
||||
*
|
||||
* @returns array|null merged array on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function merge($arrays): ?array
|
||||
{
|
||||
if(self::check($arrays))
|
||||
{
|
||||
$merged = [];
|
||||
foreach ($arrays as $array)
|
||||
{
|
||||
if (self::check($array))
|
||||
{
|
||||
$merged = array_merge($merged, $array);
|
||||
}
|
||||
}
|
||||
return $merged;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if arrays intersect
|
||||
*
|
||||
* @input array The first array
|
||||
* @input array The second array
|
||||
*
|
||||
* @returns bool true if intersect else false
|
||||
*
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public static function intersect($a_array, $b_array): bool
|
||||
{
|
||||
// flip the second array
|
||||
$b_array = array_flip($b_array);
|
||||
|
||||
// loop the first array
|
||||
foreach ($a_array as $v)
|
||||
{
|
||||
if (isset($b_array[$v]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "ArrayHelper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Utilities Array Helper",
|
||||
"type": "abstract class",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Utilities.ArrayHelper",
|
||||
"description": "Some array tricks helper\r\n\r\n@since 3.0.9",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,37 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# trait Count (Details)
|
||||
> namespace: **VDM\Joomla\Abstraction\Registry\Traits**
|
||||
```uml
|
||||
@startuml
|
||||
class Count << (T,Orange) >> #Turquoise {
|
||||
+ count(string $path) : int
|
||||
}
|
||||
|
||||
note right of Count::count
|
||||
Retrieves number of values (or sub-array) from the storage using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: int
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,43 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Abstraction\Registry\Traits;
|
||||
|
||||
|
||||
/**
|
||||
* Count Values
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
trait Count
|
||||
{
|
||||
/**
|
||||
* Retrieves number of values (or sub-array) from the storage using multiple keys.
|
||||
*
|
||||
* @param string $path Storage path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return int The number of values
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function count(string $path): int
|
||||
{
|
||||
if (($values = $this->get($path)) === null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is_array($values))
|
||||
{
|
||||
return count($values);
|
||||
}
|
||||
|
||||
if (is_object($values))
|
||||
{
|
||||
return count((array) $values);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,28 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Retrieves number of values (or sub-array) from the storage using multiple keys.
|
||||
*
|
||||
* @param string $path Storage path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return int The number of values
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function count(string $path): int
|
||||
{
|
||||
if (($values = $this->get($path)) === null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (is_array($values))
|
||||
{
|
||||
return count($values);
|
||||
}
|
||||
|
||||
if (is_object($values))
|
||||
{
|
||||
return count((array) $values);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "11572d9b-e3d5-4b29-904c-9618d8f2bfd8",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Count",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Abstraction.Registry.Traits.Count",
|
||||
"type": "trait",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Abstraction.Registry.Traits.Count",
|
||||
"description": "Count Values\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,84 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class FormHelper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities**
|
||||
```uml
|
||||
@startuml
|
||||
abstract FormHelper #Orange {
|
||||
+ {static} xml(array $attributes, ?array $options = null) : ?\SimpleXMLElement
|
||||
+ {static} append(\SimpleXMLElement $xml, mixed $node) : void
|
||||
+ {static} comment(\SimpleXMLElement $xml, string $comment) : void
|
||||
+ {static} attributes(\SimpleXMLElement $xml, array $attributes = []) : void
|
||||
+ {static} options(\SimpleXMLElement $xml, array $options = []) : void
|
||||
+ {static} field(array $attributes, string $default = '', ...) : ?FormField
|
||||
}
|
||||
|
||||
note right of FormHelper::xml
|
||||
get the field xml
|
||||
|
||||
since: 3.2.0
|
||||
return: ?\SimpleXMLElement
|
||||
end note
|
||||
|
||||
note right of FormHelper::append
|
||||
xmlAppend
|
||||
or a stdClass object containing a comment attribute to be injected
|
||||
before the XML node and a fieldXML attribute containing a SimpleXMLElement
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of FormHelper::comment
|
||||
xmlComment
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of FormHelper::attributes
|
||||
xmlAddAttributes
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of FormHelper::options
|
||||
xmlAddOptions
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of FormHelper::field
|
||||
get the field object
|
||||
|
||||
since: 3.2.0
|
||||
return: ?FormField
|
||||
|
||||
arguments:
|
||||
array $attributes
|
||||
string $default = ''
|
||||
?array $options = null
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,179 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Form\FormHelper as JoomlaFormHelper;
|
||||
use Joomla\CMS\Form\FormField;
|
||||
|
||||
|
||||
/**
|
||||
* Form Helper
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class FormHelper
|
||||
{
|
||||
/**
|
||||
* get the field xml
|
||||
*
|
||||
* @param array $attributes The array of attributes
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return \SimpleXMLElement|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function xml(array $attributes, ?array $options = null): ?\SimpleXMLElement
|
||||
{
|
||||
// make sure we have attributes and a type value
|
||||
if (ArrayHelper::check($attributes))
|
||||
{
|
||||
// start field xml
|
||||
$XML = new \SimpleXMLElement('<field/>');
|
||||
|
||||
// load the attributes
|
||||
self::attributes($XML, $attributes);
|
||||
|
||||
// check if we have options
|
||||
if (ArrayHelper::check($options))
|
||||
{
|
||||
// load the options
|
||||
self::options($XML, $options);
|
||||
}
|
||||
|
||||
// return the field xml
|
||||
return $XML;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAppend
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param mixed $node A SimpleXMLElement node to append to the XML element reference,
|
||||
* or a stdClass object containing a comment attribute to be injected
|
||||
* before the XML node and a fieldXML attribute containing a SimpleXMLElement
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function append(\SimpleXMLElement &$xml, $node)
|
||||
{
|
||||
if (!$node)
|
||||
{
|
||||
// element was not returned
|
||||
return;
|
||||
}
|
||||
|
||||
if ($node instanceof \stdClass)
|
||||
{
|
||||
if (property_exists($node, 'comment'))
|
||||
{
|
||||
self::comment($xml, $node->comment);
|
||||
}
|
||||
if (property_exists($node, 'fieldXML'))
|
||||
{
|
||||
self::append($xml, $node->fieldXML);
|
||||
}
|
||||
}
|
||||
elseif ($node instanceof \SimpleXMLElement)
|
||||
{
|
||||
$domXML = \dom_import_simplexml($xml);
|
||||
$domNode = \dom_import_simplexml($node);
|
||||
$domXML->appendChild($domXML->ownerDocument->importNode($domNode, true));
|
||||
$xml = \simplexml_import_dom($domXML);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlComment
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param string $comment The comment to inject
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function comment(\SimpleXMLElement &$xml, string $comment)
|
||||
{
|
||||
$domXML = \dom_import_simplexml($xml);
|
||||
$domComment = new \DOMComment($comment);
|
||||
$nodeTarget = $domXML->ownerDocument->importNode($domComment, true);
|
||||
$domXML->appendChild($nodeTarget);
|
||||
$xml = \simplexml_import_dom($domXML);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAddAttributes
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param array $attributes The attributes to apply to the XML element
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function attributes(\SimpleXMLElement &$xml, array $attributes = [])
|
||||
{
|
||||
foreach ($attributes as $key => $value)
|
||||
{
|
||||
$xml->addAttribute($key, $value ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAddOptions
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function options(\SimpleXMLElement &$xml, array $options = [])
|
||||
{
|
||||
foreach ($options as $key => $value)
|
||||
{
|
||||
$addOption = $xml->addChild('option');
|
||||
$addOption->addAttribute('value', $key ?? '');
|
||||
$addOption[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the field object
|
||||
*
|
||||
* @param array $attributes The array of attributes
|
||||
* @param string $default The default of the field
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return FormField|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function field(array $attributes, string $default = '', ?array $options = null): ?FormField
|
||||
{
|
||||
// make sure we have attributes and a type value
|
||||
if (ArrayHelper::check($attributes) && isset($attributes['type']))
|
||||
{
|
||||
// get field type
|
||||
if (($field = JoomlaFormHelper::loadFieldType($attributes['type'], true)) === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// get field xml
|
||||
$XML = self::xml($attributes, $options);
|
||||
|
||||
// setup the field
|
||||
$field->setup($XML, $default);
|
||||
|
||||
// return the field object
|
||||
return $field;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,160 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* get the field xml
|
||||
*
|
||||
* @param array $attributes The array of attributes
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return \SimpleXMLElement|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function xml(array $attributes, ?array $options = null): ?\SimpleXMLElement
|
||||
{
|
||||
// make sure we have attributes and a type value
|
||||
if (ArrayHelper::check($attributes))
|
||||
{
|
||||
// start field xml
|
||||
$XML = new \SimpleXMLElement('<field/>');
|
||||
|
||||
// load the attributes
|
||||
self::attributes($XML, $attributes);
|
||||
|
||||
// check if we have options
|
||||
if (ArrayHelper::check($options))
|
||||
{
|
||||
// load the options
|
||||
self::options($XML, $options);
|
||||
}
|
||||
|
||||
// return the field xml
|
||||
return $XML;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAppend
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param mixed $node A SimpleXMLElement node to append to the XML element reference,
|
||||
* or a stdClass object containing a comment attribute to be injected
|
||||
* before the XML node and a fieldXML attribute containing a SimpleXMLElement
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function append(\SimpleXMLElement &$xml, $node)
|
||||
{
|
||||
if (!$node)
|
||||
{
|
||||
// element was not returned
|
||||
return;
|
||||
}
|
||||
|
||||
if ($node instanceof \stdClass)
|
||||
{
|
||||
if (property_exists($node, 'comment'))
|
||||
{
|
||||
self::comment($xml, $node->comment);
|
||||
}
|
||||
if (property_exists($node, 'fieldXML'))
|
||||
{
|
||||
self::append($xml, $node->fieldXML);
|
||||
}
|
||||
}
|
||||
elseif ($node instanceof \SimpleXMLElement)
|
||||
{
|
||||
$domXML = \dom_import_simplexml($xml);
|
||||
$domNode = \dom_import_simplexml($node);
|
||||
$domXML->appendChild($domXML->ownerDocument->importNode($domNode, true));
|
||||
$xml = \simplexml_import_dom($domXML);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlComment
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param string $comment The comment to inject
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function comment(\SimpleXMLElement &$xml, string $comment)
|
||||
{
|
||||
$domXML = \dom_import_simplexml($xml);
|
||||
$domComment = new \DOMComment($comment);
|
||||
$nodeTarget = $domXML->ownerDocument->importNode($domComment, true);
|
||||
$domXML->appendChild($nodeTarget);
|
||||
$xml = \simplexml_import_dom($domXML);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAddAttributes
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param array $attributes The attributes to apply to the XML element
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function attributes(\SimpleXMLElement &$xml, array $attributes = [])
|
||||
{
|
||||
foreach ($attributes as $key => $value)
|
||||
{
|
||||
$xml->addAttribute($key, $value ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlAddOptions
|
||||
*
|
||||
* @param \SimpleXMLElement $xml The XML element reference in which to inject a comment
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function options(\SimpleXMLElement &$xml, array $options = [])
|
||||
{
|
||||
foreach ($options as $key => $value)
|
||||
{
|
||||
$addOption = $xml->addChild('option');
|
||||
$addOption->addAttribute('value', $key ?? '');
|
||||
$addOption[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the field object
|
||||
*
|
||||
* @param array $attributes The array of attributes
|
||||
* @param string $default The default of the field
|
||||
* @param array $options The options to apply to the XML element
|
||||
*
|
||||
* @return FormField|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function field(array $attributes, string $default = '', ?array $options = null): ?FormField
|
||||
{
|
||||
// make sure we have attributes and a type value
|
||||
if (ArrayHelper::check($attributes) && isset($attributes['type']))
|
||||
{
|
||||
// get field type
|
||||
if (($field = JoomlaFormHelper::loadFieldType($attributes['type'], true)) === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// get field xml
|
||||
$XML = self::xml($attributes, $options);
|
||||
|
||||
// setup the field
|
||||
$field->setup($XML, $default);
|
||||
|
||||
// return the field object
|
||||
return $field;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
|
@ -1 +1,22 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "1198aecf-84c6-45d2-aea8-d531aa4afdfa",
|
||||
"implements": null,
|
||||
"load_selection": {
|
||||
"load_selection0": {
|
||||
"load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a"
|
||||
}
|
||||
},
|
||||
"name": "FormHelper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Utilities FormHelper",
|
||||
"type": "abstract class",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Utilities.FormHelper",
|
||||
"description": "Form Helper\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Form\\FormHelper as JoomlaFormHelper;\r\nuse Joomla\\CMS\\Form\\FormField;",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,51 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class MathHelper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities**
|
||||
```uml
|
||||
@startuml
|
||||
abstract MathHelper #Orange {
|
||||
+ {static} bc(string $type, int $val1, ...) : string|int|null|bool
|
||||
+ {static} sum(array $array, int $scale = 4) : float
|
||||
}
|
||||
|
||||
note right of MathHelper::bc
|
||||
bc math wrapper (very basic not for accounting)
|
||||
|
||||
since: 3.0.9
|
||||
return: string|int|null|bool
|
||||
|
||||
arguments:
|
||||
string $type
|
||||
int $val1
|
||||
int $val2
|
||||
int $scale
|
||||
end note
|
||||
|
||||
note right of MathHelper::sum
|
||||
Basic sum of an array with more precision
|
||||
|
||||
since: 3.0.9
|
||||
return: float
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,94 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* Basic Math Helper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class MathHelper
|
||||
{
|
||||
/**
|
||||
* bc math wrapper (very basic not for accounting)
|
||||
*
|
||||
* @param string $type The type bc math
|
||||
* @param int $val1 The first value
|
||||
* @param int $val2 The second value
|
||||
* @param int $scale The scale value
|
||||
*
|
||||
* @return string|int|null|bool
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function bc($type, $val1, $val2, $scale = 0)
|
||||
{
|
||||
// Validate input
|
||||
if (!is_numeric($val1) || !is_numeric($val2))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Build function name
|
||||
$function = 'bc' . $type;
|
||||
|
||||
// Use the bcmath function if available
|
||||
if (is_callable($function))
|
||||
{
|
||||
return $function($val1, $val2, $scale);
|
||||
}
|
||||
|
||||
// if function does not exist we use +-*/ operators (fallback - not ideal)
|
||||
switch ($type)
|
||||
{
|
||||
case 'mul':
|
||||
return (string) round($val1 * $val2, $scale);
|
||||
case 'div':
|
||||
if ($val2 == 0) return null; // Avoid division by zero
|
||||
return (string) round($val1 / $val2, $scale);
|
||||
case 'add':
|
||||
return (string) round($val1 + $val2, $scale);
|
||||
case 'sub':
|
||||
return (string) round($val1 - $val2, $scale);
|
||||
case 'pow':
|
||||
return (string) round(pow($val1, $val2), $scale);
|
||||
case 'comp':
|
||||
$diff = round($val1 - $val2, $scale);
|
||||
return ($diff > 0) ? 1 : (($diff < 0) ? -1 : 0);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic sum of an array with more precision
|
||||
*
|
||||
* @param array $array The values to sum
|
||||
* @param int $scale The scale value
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function sum($array, $scale = 4)
|
||||
{
|
||||
// use the bcadd function if available
|
||||
if (function_exists('bcadd'))
|
||||
{
|
||||
// set the start value
|
||||
$value = 0.0;
|
||||
// loop the values and run bcadd
|
||||
foreach($array as $val)
|
||||
{
|
||||
$value = bcadd($value, (string) $val, $scale);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
// fall back on array sum
|
||||
return array_sum($array);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,78 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* bc math wrapper (very basic not for accounting)
|
||||
*
|
||||
* @param string $type The type bc math
|
||||
* @param int $val1 The first value
|
||||
* @param int $val2 The second value
|
||||
* @param int $scale The scale value
|
||||
*
|
||||
* @return string|int|null|bool
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function bc($type, $val1, $val2, $scale = 0)
|
||||
{
|
||||
// Validate input
|
||||
if (!is_numeric($val1) || !is_numeric($val2))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Build function name
|
||||
$function = 'bc' . $type;
|
||||
|
||||
// Use the bcmath function if available
|
||||
if (is_callable($function))
|
||||
{
|
||||
return $function($val1, $val2, $scale);
|
||||
}
|
||||
|
||||
// if function does not exist we use +-*/ operators (fallback - not ideal)
|
||||
switch ($type)
|
||||
{
|
||||
case 'mul':
|
||||
return (string) round($val1 * $val2, $scale);
|
||||
case 'div':
|
||||
if ($val2 == 0) return null; // Avoid division by zero
|
||||
return (string) round($val1 / $val2, $scale);
|
||||
case 'add':
|
||||
return (string) round($val1 + $val2, $scale);
|
||||
case 'sub':
|
||||
return (string) round($val1 - $val2, $scale);
|
||||
case 'pow':
|
||||
return (string) round(pow($val1, $val2), $scale);
|
||||
case 'comp':
|
||||
$diff = round($val1 - $val2, $scale);
|
||||
return ($diff > 0) ? 1 : (($diff < 0) ? -1 : 0);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic sum of an array with more precision
|
||||
*
|
||||
* @param array $array The values to sum
|
||||
* @param int $scale The scale value
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function sum($array, $scale = 4)
|
||||
{
|
||||
// use the bcadd function if available
|
||||
if (function_exists('bcadd'))
|
||||
{
|
||||
// set the start value
|
||||
$value = 0.0;
|
||||
// loop the values and run bcadd
|
||||
foreach($array as $val)
|
||||
{
|
||||
$value = bcadd($value, (string) $val, $scale);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
// fall back on array sum
|
||||
return array_sum($array);
|
||||
}
|
||||
|
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "152c8793-8b75-4715-996a-257b9f65451c",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "MathHelper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Utilities Math Helper",
|
||||
"type": "abstract class",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Utilities.MathHelper",
|
||||
"description": "Basic Math Helper\r\n\r\n@since 3.0.9",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,108 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class StringHelper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities**
|
||||
```uml
|
||||
@startuml
|
||||
abstract StringHelper #Orange {
|
||||
+ static $langTag
|
||||
+ {static} check($string) : bool
|
||||
+ {static} shorten($string, $length = 40, ...)
|
||||
+ {static} safe($string, $type = 'L', ...)
|
||||
+ {static} transliterate($string)
|
||||
+ {static} html($var, $charset = 'UTF-8', ...)
|
||||
+ {static} numbers($string)
|
||||
+ {static} number($x)
|
||||
+ {static} random(int $size) : string
|
||||
}
|
||||
|
||||
note right of StringHelper::check
|
||||
Check if we have a string with a length
|
||||
|
||||
since: 3.0.9
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note left of StringHelper::shorten
|
||||
Shorten a string
|
||||
|
||||
since: 3.2.0
|
||||
|
||||
arguments:
|
||||
$string
|
||||
$length = 40
|
||||
$addTip = true
|
||||
end note
|
||||
|
||||
note right of StringHelper::safe
|
||||
Making strings safe (various ways)
|
||||
|
||||
since: 3.0.9
|
||||
|
||||
arguments:
|
||||
$string
|
||||
$type = 'L'
|
||||
$spacer = '_'
|
||||
$replaceNumbers = true
|
||||
$keepOnlyCharacters = true
|
||||
end note
|
||||
|
||||
note left of StringHelper::transliterate
|
||||
Convert none English strings to code usable string
|
||||
|
||||
since: 3.0.9
|
||||
end note
|
||||
|
||||
note right of StringHelper::html
|
||||
make sure a string is HTML save
|
||||
|
||||
since: 3.0.9
|
||||
|
||||
arguments:
|
||||
$var
|
||||
$charset = 'UTF-8'
|
||||
$shorten = false
|
||||
$length = 40
|
||||
$addTip = true
|
||||
end note
|
||||
|
||||
note left of StringHelper::numbers
|
||||
Convert all int in a string to an English word string
|
||||
|
||||
since: 3.0.9
|
||||
end note
|
||||
|
||||
note right of StringHelper::number
|
||||
Convert an integer into an English word string
|
||||
Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
|
||||
|
||||
since: 3.0.9
|
||||
end note
|
||||
|
||||
note left of StringHelper::random
|
||||
Random Key
|
||||
|
||||
since: 3.0.9
|
||||
return: string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,408 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use Joomla\CMS\Filter\InputFilter;
|
||||
use Joomla\CMS\Language\Language;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Some string tricks
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class StringHelper
|
||||
{
|
||||
/**
|
||||
* The Main Active Language
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static $langTag;
|
||||
|
||||
/**
|
||||
* Check if we have a string with a length
|
||||
*
|
||||
* @input string $string The string to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function check($string): bool
|
||||
{
|
||||
return is_string($string) && strlen($string) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten a string
|
||||
*
|
||||
* @input string The sting that you would like to shorten
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function shorten($string, $length = 40, $addTip = true)
|
||||
{
|
||||
if (self::check($string))
|
||||
{
|
||||
$initial = strlen((string) $string);
|
||||
$words = preg_split('/([\s\n\r]+)/', (string) $string, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$words_count = count((array)$words);
|
||||
|
||||
$word_length = 0;
|
||||
$last_word = 0;
|
||||
for (; $last_word < $words_count; ++$last_word)
|
||||
{
|
||||
$word_length += strlen($words[$last_word]);
|
||||
if ($word_length > $length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$newString = implode(array_slice($words, 0, $last_word));
|
||||
$final = strlen($newString);
|
||||
if ($initial !== $final && $addTip)
|
||||
{
|
||||
$title = self::shorten($string, 400 , false);
|
||||
return '<span class="hasTip" title="' . $title . '" style="cursor:help">' . trim($newString) . '...</span>';
|
||||
}
|
||||
elseif ($initial !== $final && !$addTip)
|
||||
{
|
||||
return trim($newString) . '...';
|
||||
}
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Making strings safe (various ways)
|
||||
*
|
||||
* @input string The you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true)
|
||||
{
|
||||
if ($replaceNumbers === true)
|
||||
{
|
||||
// remove all numbers and replace with English text version (works well only up to millions)
|
||||
$string = self::numbers($string);
|
||||
}
|
||||
// 0nly continue if we have a string
|
||||
if (self::check($string))
|
||||
{
|
||||
// create file name without the extension that is safe
|
||||
if ($type === 'filename')
|
||||
{
|
||||
// make sure VDM is not in the string
|
||||
$string = str_replace('VDM', 'vDm', (string) $string);
|
||||
// Remove anything which isn't a word, whitespace, number
|
||||
// or any of the following caracters -_()
|
||||
// If you don't need to handle multi-byte characters
|
||||
// you can use preg_replace rather than mb_ereg_replace
|
||||
// Thanks @Łukasz Rysiak!
|
||||
// $string = mb_ereg_replace("([^\w\s\d\-_\(\)])", '', $string);
|
||||
$string = preg_replace("([^\w\s\d\-_\(\)])", '', $string);
|
||||
|
||||
// http://stackoverflow.com/a/2021729/1429677
|
||||
return preg_replace('/\s+/', ' ', (string) $string);
|
||||
}
|
||||
// remove all other characters
|
||||
$string = trim((string) $string);
|
||||
$string = preg_replace('/'.$spacer.'+/', ' ', $string);
|
||||
$string = preg_replace('/\s+/', ' ', $string);
|
||||
// Transliterate string
|
||||
$string = self::transliterate($string);
|
||||
// remove all and keep only characters
|
||||
if ($keepOnlyCharacters)
|
||||
{
|
||||
$string = preg_replace("/[^A-Za-z ]/", '', (string) $string);
|
||||
}
|
||||
// keep both numbers and characters
|
||||
else
|
||||
{
|
||||
$string = preg_replace("/[^A-Za-z0-9 ]/", '', (string) $string);
|
||||
}
|
||||
// select final adaptations
|
||||
if ($type === 'L' || $type === 'strtolower')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', (string) $spacer, (string) $string);
|
||||
// default is to return lower
|
||||
return strtolower($string);
|
||||
}
|
||||
elseif ($type === 'W')
|
||||
{
|
||||
// return a string with all first letter of each word uppercase(no underscore)
|
||||
return ucwords(strtolower($string));
|
||||
}
|
||||
elseif ($type === 'w' || $type === 'word')
|
||||
{
|
||||
// return a string with all lowercase(no underscore)
|
||||
return strtolower($string);
|
||||
}
|
||||
elseif ($type === 'Ww' || $type === 'Word')
|
||||
{
|
||||
// return a string with first letter of the first word uppercase and all the rest lowercase(no underscore)
|
||||
return ucfirst(strtolower($string));
|
||||
}
|
||||
elseif ($type === 'WW' || $type === 'WORD')
|
||||
{
|
||||
// return a string with all the uppercase(no underscore)
|
||||
return strtoupper($string);
|
||||
}
|
||||
elseif ($type === 'U' || $type === 'strtoupper')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
// return all upper
|
||||
return strtoupper($string);
|
||||
}
|
||||
elseif ($type === 'F' || $type === 'ucfirst')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
// return with first character to upper
|
||||
return ucfirst(strtolower($string));
|
||||
}
|
||||
elseif ($type === 'cA' || $type === 'cAmel' || $type === 'camelcase')
|
||||
{
|
||||
// convert all words to first letter uppercase
|
||||
$string = ucwords(strtolower($string));
|
||||
// remove white space
|
||||
$string = preg_replace('/\s+/', '', $string);
|
||||
// now return first letter lowercase
|
||||
return lcfirst($string);
|
||||
}
|
||||
// return string
|
||||
return $string;
|
||||
}
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert none English strings to code usable string
|
||||
*
|
||||
* @input an string
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function transliterate($string)
|
||||
{
|
||||
// set tag only once
|
||||
if (!self::check(self::$langTag))
|
||||
{
|
||||
// get global value
|
||||
self::$langTag = Helper::getParams()->get('language', 'en-GB');
|
||||
}
|
||||
|
||||
// Transliterate on the language requested
|
||||
$lang = Language::getInstance(self::$langTag);
|
||||
|
||||
return $lang->transliterate($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* make sure a string is HTML save
|
||||
*
|
||||
* @input an html string
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function html($var, $charset = 'UTF-8', $shorten = false, $length = 40, $addTip = true)
|
||||
{
|
||||
if (self::check($var))
|
||||
{
|
||||
$filter = new InputFilter();
|
||||
$string = $filter->clean(
|
||||
html_entity_decode(
|
||||
htmlentities(
|
||||
(string) $var,
|
||||
ENT_COMPAT,
|
||||
$charset
|
||||
)
|
||||
),
|
||||
'HTML'
|
||||
);
|
||||
if ($shorten)
|
||||
{
|
||||
return self::shorten($string, $length, $addTip);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all int in a string to an English word string
|
||||
*
|
||||
* @input an string with numbers
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function numbers($string)
|
||||
{
|
||||
// set numbers array
|
||||
$numbers = [];
|
||||
$search_replace= [];
|
||||
|
||||
// first get all numbers
|
||||
preg_match_all('!\d+!', (string) $string, $numbers);
|
||||
|
||||
// check if we have any numbers
|
||||
if (isset($numbers[0]) && ArrayHelper::check($numbers[0]))
|
||||
{
|
||||
foreach ($numbers[0] as $number)
|
||||
{
|
||||
$search_replace[$number] = self::number((int)$number);
|
||||
}
|
||||
|
||||
// now replace numbers in string
|
||||
$string = str_replace(array_keys($search_replace), array_values($search_replace), (string) $string);
|
||||
|
||||
// check if we missed any, strange if we did.
|
||||
return self::numbers($string);
|
||||
}
|
||||
|
||||
// return the string with no numbers remaining.
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an integer into an English word string
|
||||
* Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
|
||||
*
|
||||
* @input an int
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function number($x)
|
||||
{
|
||||
$nwords = array( "zero", "one", "two", "three", "four", "five", "six", "seven",
|
||||
"eight", "nine", "ten", "eleven", "twelve", "thirteen",
|
||||
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
|
||||
"nineteen", "twenty", 30 => "thirty", 40 => "forty",
|
||||
50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty",
|
||||
90 => "ninety" );
|
||||
|
||||
if(!is_numeric($x))
|
||||
{
|
||||
$w = $x;
|
||||
}
|
||||
elseif(fmod($x, 1) != 0)
|
||||
{
|
||||
$w = $x;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($x < 0)
|
||||
{
|
||||
$w = 'minus ';
|
||||
$x = -$x;
|
||||
}
|
||||
else
|
||||
{
|
||||
$w = '';
|
||||
// ... now $x is a non-negative integer.
|
||||
}
|
||||
|
||||
if($x < 21) // 0 to 20
|
||||
{
|
||||
$w .= $nwords[$x];
|
||||
}
|
||||
elseif($x < 100) // 21 to 99
|
||||
{
|
||||
$w .= $nwords[10 * floor($x/10)];
|
||||
$r = fmod($x, 10);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' ' . $nwords[$r];
|
||||
}
|
||||
}
|
||||
elseif($x < 1000) // 100 to 999
|
||||
{
|
||||
$w .= $nwords[floor($x/100)] .' hundred';
|
||||
$r = fmod($x, 100);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' and '. self::number($r);
|
||||
}
|
||||
}
|
||||
elseif($x < 1000000) // 1000 to 999999
|
||||
{
|
||||
$w .= self::number(floor($x/1000)) .' thousand';
|
||||
$r = fmod($x, 1000);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' ';
|
||||
if($r < 100)
|
||||
{
|
||||
$w .= 'and ';
|
||||
}
|
||||
$w .= self::number($r);
|
||||
}
|
||||
}
|
||||
else // millions
|
||||
{
|
||||
$w .= self::number(floor($x/1000000)) .' million';
|
||||
$r = fmod($x, 1000000);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' ';
|
||||
if($r < 100)
|
||||
{
|
||||
$w .= 'and ';
|
||||
}
|
||||
$w .= self::number($r);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Random Key
|
||||
*
|
||||
* @input int $size The size of the random string
|
||||
*
|
||||
* @returns a string
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function random(int $size): string
|
||||
{
|
||||
$bag = "abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ";
|
||||
$key = [];
|
||||
$bagsize = strlen($bag) - 1;
|
||||
|
||||
for ($i = 0; $i < $size; $i++)
|
||||
{
|
||||
$get = rand(0, $bagsize);
|
||||
$key[] = $bag[$get];
|
||||
}
|
||||
|
||||
return implode($key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,387 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* The Main Active Language
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static $langTag;
|
||||
|
||||
/**
|
||||
* Check if we have a string with a length
|
||||
*
|
||||
* @input string $string The string to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function check($string): bool
|
||||
{
|
||||
return is_string($string) && strlen($string) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten a string
|
||||
*
|
||||
* @input string The sting that you would like to shorten
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function shorten($string, $length = 40, $addTip = true)
|
||||
{
|
||||
if (self::check($string))
|
||||
{
|
||||
$initial = strlen((string) $string);
|
||||
$words = preg_split('/([\s\n\r]+)/', (string) $string, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$words_count = count((array)$words);
|
||||
|
||||
$word_length = 0;
|
||||
$last_word = 0;
|
||||
for (; $last_word < $words_count; ++$last_word)
|
||||
{
|
||||
$word_length += strlen($words[$last_word]);
|
||||
if ($word_length > $length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$newString = implode(array_slice($words, 0, $last_word));
|
||||
$final = strlen($newString);
|
||||
if ($initial !== $final && $addTip)
|
||||
{
|
||||
$title = self::shorten($string, 400 , false);
|
||||
return '<span class="hasTip" title="' . $title . '" style="cursor:help">' . trim($newString) . '...</span>';
|
||||
}
|
||||
elseif ($initial !== $final && !$addTip)
|
||||
{
|
||||
return trim($newString) . '...';
|
||||
}
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Making strings safe (various ways)
|
||||
*
|
||||
* @input string The you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true)
|
||||
{
|
||||
if ($replaceNumbers === true)
|
||||
{
|
||||
// remove all numbers and replace with English text version (works well only up to millions)
|
||||
$string = self::numbers($string);
|
||||
}
|
||||
// 0nly continue if we have a string
|
||||
if (self::check($string))
|
||||
{
|
||||
// create file name without the extension that is safe
|
||||
if ($type === 'filename')
|
||||
{
|
||||
// make sure VDM is not in the string
|
||||
$string = str_replace('VDM', 'vDm', (string) $string);
|
||||
// Remove anything which isn't a word, whitespace, number
|
||||
// or any of the following caracters -_()
|
||||
// If you don't need to handle multi-byte characters
|
||||
// you can use preg_replace rather than mb_ereg_replace
|
||||
// Thanks @Łukasz Rysiak!
|
||||
// $string = mb_ereg_replace("([^\w\s\d\-_\(\)])", '', $string);
|
||||
$string = preg_replace("([^\w\s\d\-_\(\)])", '', $string);
|
||||
|
||||
// http://stackoverflow.com/a/2021729/1429677
|
||||
return preg_replace('/\s+/', ' ', (string) $string);
|
||||
}
|
||||
// remove all other characters
|
||||
$string = trim((string) $string);
|
||||
$string = preg_replace('/'.$spacer.'+/', ' ', $string);
|
||||
$string = preg_replace('/\s+/', ' ', $string);
|
||||
// Transliterate string
|
||||
$string = self::transliterate($string);
|
||||
// remove all and keep only characters
|
||||
if ($keepOnlyCharacters)
|
||||
{
|
||||
$string = preg_replace("/[^A-Za-z ]/", '', (string) $string);
|
||||
}
|
||||
// keep both numbers and characters
|
||||
else
|
||||
{
|
||||
$string = preg_replace("/[^A-Za-z0-9 ]/", '', (string) $string);
|
||||
}
|
||||
// select final adaptations
|
||||
if ($type === 'L' || $type === 'strtolower')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', (string) $spacer, (string) $string);
|
||||
// default is to return lower
|
||||
return strtolower($string);
|
||||
}
|
||||
elseif ($type === 'W')
|
||||
{
|
||||
// return a string with all first letter of each word uppercase(no underscore)
|
||||
return ucwords(strtolower($string));
|
||||
}
|
||||
elseif ($type === 'w' || $type === 'word')
|
||||
{
|
||||
// return a string with all lowercase(no underscore)
|
||||
return strtolower($string);
|
||||
}
|
||||
elseif ($type === 'Ww' || $type === 'Word')
|
||||
{
|
||||
// return a string with first letter of the first word uppercase and all the rest lowercase(no underscore)
|
||||
return ucfirst(strtolower($string));
|
||||
}
|
||||
elseif ($type === 'WW' || $type === 'WORD')
|
||||
{
|
||||
// return a string with all the uppercase(no underscore)
|
||||
return strtoupper($string);
|
||||
}
|
||||
elseif ($type === 'U' || $type === 'strtoupper')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
// return all upper
|
||||
return strtoupper($string);
|
||||
}
|
||||
elseif ($type === 'F' || $type === 'ucfirst')
|
||||
{
|
||||
// replace white space with underscore
|
||||
$string = preg_replace('/\s+/', (string) $spacer, $string);
|
||||
// return with first character to upper
|
||||
return ucfirst(strtolower($string));
|
||||
}
|
||||
elseif ($type === 'cA' || $type === 'cAmel' || $type === 'camelcase')
|
||||
{
|
||||
// convert all words to first letter uppercase
|
||||
$string = ucwords(strtolower($string));
|
||||
// remove white space
|
||||
$string = preg_replace('/\s+/', '', $string);
|
||||
// now return first letter lowercase
|
||||
return lcfirst($string);
|
||||
}
|
||||
// return string
|
||||
return $string;
|
||||
}
|
||||
// not a string
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert none English strings to code usable string
|
||||
*
|
||||
* @input an string
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function transliterate($string)
|
||||
{
|
||||
// set tag only once
|
||||
if (!self::check(self::$langTag))
|
||||
{
|
||||
// get global value
|
||||
self::$langTag = Helper::getParams()->get('language', 'en-GB');
|
||||
}
|
||||
|
||||
// Transliterate on the language requested
|
||||
$lang = Language::getInstance(self::$langTag);
|
||||
|
||||
return $lang->transliterate($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* make sure a string is HTML save
|
||||
*
|
||||
* @input an html string
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function html($var, $charset = 'UTF-8', $shorten = false, $length = 40, $addTip = true)
|
||||
{
|
||||
if (self::check($var))
|
||||
{
|
||||
$filter = new InputFilter();
|
||||
$string = $filter->clean(
|
||||
html_entity_decode(
|
||||
htmlentities(
|
||||
(string) $var,
|
||||
ENT_COMPAT,
|
||||
$charset
|
||||
)
|
||||
),
|
||||
'HTML'
|
||||
);
|
||||
if ($shorten)
|
||||
{
|
||||
return self::shorten($string, $length, $addTip);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all int in a string to an English word string
|
||||
*
|
||||
* @input an string with numbers
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function numbers($string)
|
||||
{
|
||||
// set numbers array
|
||||
$numbers = [];
|
||||
$search_replace= [];
|
||||
|
||||
// first get all numbers
|
||||
preg_match_all('!\d+!', (string) $string, $numbers);
|
||||
|
||||
// check if we have any numbers
|
||||
if (isset($numbers[0]) && ArrayHelper::check($numbers[0]))
|
||||
{
|
||||
foreach ($numbers[0] as $number)
|
||||
{
|
||||
$search_replace[$number] = self::number((int)$number);
|
||||
}
|
||||
|
||||
// now replace numbers in string
|
||||
$string = str_replace(array_keys($search_replace), array_values($search_replace), (string) $string);
|
||||
|
||||
// check if we missed any, strange if we did.
|
||||
return self::numbers($string);
|
||||
}
|
||||
|
||||
// return the string with no numbers remaining.
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an integer into an English word string
|
||||
* Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
|
||||
*
|
||||
* @input an int
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function number($x)
|
||||
{
|
||||
$nwords = array( "zero", "one", "two", "three", "four", "five", "six", "seven",
|
||||
"eight", "nine", "ten", "eleven", "twelve", "thirteen",
|
||||
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
|
||||
"nineteen", "twenty", 30 => "thirty", 40 => "forty",
|
||||
50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty",
|
||||
90 => "ninety" );
|
||||
|
||||
if(!is_numeric($x))
|
||||
{
|
||||
$w = $x;
|
||||
}
|
||||
elseif(fmod($x, 1) != 0)
|
||||
{
|
||||
$w = $x;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($x < 0)
|
||||
{
|
||||
$w = 'minus ';
|
||||
$x = -$x;
|
||||
}
|
||||
else
|
||||
{
|
||||
$w = '';
|
||||
// ... now $x is a non-negative integer.
|
||||
}
|
||||
|
||||
if($x < 21) // 0 to 20
|
||||
{
|
||||
$w .= $nwords[$x];
|
||||
}
|
||||
elseif($x < 100) // 21 to 99
|
||||
{
|
||||
$w .= $nwords[10 * floor($x/10)];
|
||||
$r = fmod($x, 10);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' ' . $nwords[$r];
|
||||
}
|
||||
}
|
||||
elseif($x < 1000) // 100 to 999
|
||||
{
|
||||
$w .= $nwords[floor($x/100)] .' hundred';
|
||||
$r = fmod($x, 100);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' and '. self::number($r);
|
||||
}
|
||||
}
|
||||
elseif($x < 1000000) // 1000 to 999999
|
||||
{
|
||||
$w .= self::number(floor($x/1000)) .' thousand';
|
||||
$r = fmod($x, 1000);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' ';
|
||||
if($r < 100)
|
||||
{
|
||||
$w .= 'and ';
|
||||
}
|
||||
$w .= self::number($r);
|
||||
}
|
||||
}
|
||||
else // millions
|
||||
{
|
||||
$w .= self::number(floor($x/1000000)) .' million';
|
||||
$r = fmod($x, 1000000);
|
||||
if($r > 0)
|
||||
{
|
||||
$w .= ' ';
|
||||
if($r < 100)
|
||||
{
|
||||
$w .= 'and ';
|
||||
}
|
||||
$w .= self::number($r);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Random Key
|
||||
*
|
||||
* @input int $size The size of the random string
|
||||
*
|
||||
* @returns a string
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function random(int $size): string
|
||||
{
|
||||
$bag = "abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ";
|
||||
$key = [];
|
||||
$bagsize = strlen($bag) - 1;
|
||||
|
||||
for ($i = 0; $i < $size; $i++)
|
||||
{
|
||||
$get = rand(0, $bagsize);
|
||||
$key[] = $bag[$get];
|
||||
}
|
||||
|
||||
return implode($key);
|
||||
}
|
||||
|
|
|
@ -1 +1,27 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef",
|
||||
"implements": null,
|
||||
"load_selection": {
|
||||
"load_selection0": {
|
||||
"load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a"
|
||||
}
|
||||
},
|
||||
"name": "StringHelper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Utilities String Helper",
|
||||
"type": "abstract class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "640b5352-fb09-425f-a26e-cd44eda03f15",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Utilities.StringHelper",
|
||||
"description": "Some string tricks\r\n\r\n@since 3.0.9",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Filter\\InputFilter;\r\nuse Joomla\\CMS\\Language\\Language;",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,37 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# trait InArray (Details)
|
||||
> namespace: **VDM\Joomla\Abstraction\Registry\Traits**
|
||||
```uml
|
||||
@startuml
|
||||
class InArray << (T,Orange) >> #Turquoise {
|
||||
+ inArray(mixed $value, ?string $path = null) : bool
|
||||
}
|
||||
|
||||
note right of InArray::inArray
|
||||
Check if a value is found in an array
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,42 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Abstraction\Registry\Traits;
|
||||
|
||||
|
||||
/**
|
||||
* Check if a value is in an array
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
trait InArray
|
||||
{
|
||||
/**
|
||||
* Check if a value is found in an array
|
||||
*
|
||||
* @param mixed $value The value to check for
|
||||
* @param string|null $path Registry path (e.g. joomla.content.showauthor)
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function inArray($value, ?string $path = null): bool
|
||||
{
|
||||
// Check base array if no path is given
|
||||
if (empty($path))
|
||||
{
|
||||
return in_array($value, $this->active);
|
||||
}
|
||||
|
||||
// get the value
|
||||
if (($node = $this->get($path)) !== null
|
||||
&& is_array($node)
|
||||
&& in_array($value, $node))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,27 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Check if a value is found in an array
|
||||
*
|
||||
* @param mixed $value The value to check for
|
||||
* @param string|null $path Registry path (e.g. joomla.content.showauthor)
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function inArray($value, ?string $path = null): bool
|
||||
{
|
||||
// Check base array if no path is given
|
||||
if (empty($path))
|
||||
{
|
||||
return in_array($value, $this->active);
|
||||
}
|
||||
|
||||
// get the value
|
||||
if (($node = $this->get($path)) !== null
|
||||
&& is_array($node)
|
||||
&& in_array($value, $node))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "215b35ac-1b26-4838-bbcf-d1fdbbd9353f",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "InArray",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Abstraction.Registry.Traits.InArray",
|
||||
"type": "trait",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Abstraction.Registry.Traits.InArray",
|
||||
"description": "Check if a value is in an array\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,122 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# interface LoadInterface (Details)
|
||||
> namespace: **VDM\Joomla\Interfaces**
|
||||
```uml
|
||||
@startuml
|
||||
interface LoadInterface #Lavender {
|
||||
+ rows(array $select, array $tables, ...) : ?array
|
||||
+ items(array $select, array $tables, ...) : ?array
|
||||
+ row(array $select, array $tables, ...) : ?array
|
||||
+ item(array $select, array $tables, ...) : ?object
|
||||
+ max(string $field, array $tables, ...) : ?int
|
||||
+ count(array $tables, array $filter) : ?int
|
||||
+ value(array $select, array $tables, ...) : mixed
|
||||
}
|
||||
|
||||
note right of LoadInterface::rows
|
||||
Load data rows as an array of associated arrays
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
?int $limit = null
|
||||
end note
|
||||
|
||||
note right of LoadInterface::items
|
||||
Load data rows as an array of objects
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
?int $limit = null
|
||||
end note
|
||||
|
||||
note right of LoadInterface::row
|
||||
Load data row as an associated array
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
end note
|
||||
|
||||
note right of LoadInterface::item
|
||||
Load data row as an object
|
||||
|
||||
since: 3.2.0
|
||||
return: ?object
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
end note
|
||||
|
||||
note right of LoadInterface::max
|
||||
Get the max value based on a filtered result from a given table
|
||||
|
||||
since: 3.2.0
|
||||
return: ?int
|
||||
|
||||
arguments:
|
||||
string $field
|
||||
array $tables
|
||||
array $filter
|
||||
end note
|
||||
|
||||
note right of LoadInterface::count
|
||||
Count the number of items based on filter result from a given table
|
||||
|
||||
since: 3.2.0
|
||||
return: ?int
|
||||
end note
|
||||
|
||||
note right of LoadInterface::value
|
||||
Load one value from a row
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
|
||||
arguments:
|
||||
array $select
|
||||
array $tables
|
||||
?array $where = null
|
||||
?array $order = null
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,106 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Database Load Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface LoadInterface
|
||||
{
|
||||
/**
|
||||
* Load data rows as an array of associated arrays
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array;
|
||||
|
||||
/**
|
||||
* Load data rows as an array of objects
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array;
|
||||
|
||||
/**
|
||||
* Load data row as an associated array
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $select, array $tables, ?array $where = null, ?array $order = null): ?array;
|
||||
|
||||
/**
|
||||
* Load data row as an object
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object;
|
||||
|
||||
/**
|
||||
* Get the max value based on a filtered result from a given table
|
||||
*
|
||||
* @param string $field The field key
|
||||
* @param string $tables The table
|
||||
* @param array $filter The filter keys
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function max($field, array $tables, array $filter): ?int;
|
||||
|
||||
/**
|
||||
* Count the number of items based on filter result from a given table
|
||||
*
|
||||
* @param string $tables The table
|
||||
* @param array $filter The filter keys
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function count(array $tables, array $filter): ?int;
|
||||
|
||||
/**
|
||||
* Load one value from a row
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function value(array $select, array $tables, ?array $where = null, ?array $order = null);
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,91 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Load data rows as an array of associated arrays
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array;
|
||||
|
||||
/**
|
||||
* Load data rows as an array of objects
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
* @param int|null $limit Limit the number of values returned
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $select, array $tables, ?array $where = null,
|
||||
?array $order = null, ?int $limit = null): ?array;
|
||||
|
||||
/**
|
||||
* Load data row as an associated array
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $select, array $tables, ?array $where = null, ?array $order = null): ?array;
|
||||
|
||||
/**
|
||||
* Load data row as an object
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(array $select, array $tables, ?array $where = null, ?array $order = null): ?object;
|
||||
|
||||
/**
|
||||
* Get the max value based on a filtered result from a given table
|
||||
*
|
||||
* @param string $field The field key
|
||||
* @param string $tables The table
|
||||
* @param array $filter The filter keys
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function max($field, array $tables, array $filter): ?int;
|
||||
|
||||
/**
|
||||
* Count the number of items based on filter result from a given table
|
||||
*
|
||||
* @param string $tables The table
|
||||
* @param array $filter The filter keys
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function count(array $tables, array $filter): ?int;
|
||||
|
||||
/**
|
||||
* Load one value from a row
|
||||
*
|
||||
* @param array $select Array of selection keys
|
||||
* @param array $tables Array of tables to search
|
||||
* @param array|null $where Array of where key=>value match exist
|
||||
* @param array|null $order Array of how to order the data
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function value(array $select, array $tables, ?array $where = null, ?array $order = null);
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "2ad31f74-f579-499d-b98b-c4f54fd615dd",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "LoadInterface",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Interfaces.LoadInterface",
|
||||
"type": "interface",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Interfaces.LoadInterface",
|
||||
"description": "Database Load Interface\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,89 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# interface Tableinterface (Details)
|
||||
> namespace: **VDM\Joomla\Interfaces**
|
||||
```uml
|
||||
@startuml
|
||||
interface Tableinterface #Lavender {
|
||||
+ get(string $table, ?string $field = null, ...) : mixed
|
||||
+ title(string $table) : ?array
|
||||
+ titleName(string $table) : string
|
||||
+ tables() : array
|
||||
+ exist(string $table, ?string $field = null) : bool
|
||||
+ fields(string $table, bool $default = false) : ?array
|
||||
}
|
||||
|
||||
note right of Tableinterface::get
|
||||
Get any value from a item/field/column of an area/view/table
|
||||
Example: $this->get('table_name', 'field_name', 'value_key');
|
||||
Get an item/field/column of an area/view/table
|
||||
Example: $this->get('table_name', 'field_name');
|
||||
Get all items/fields/columns of an area/view/table
|
||||
Example: $this->get('table_name');
|
||||
Get all areas/views/tables with all their item/field/column details
|
||||
Example: $this->get('All');
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
|
||||
arguments:
|
||||
string $table
|
||||
?string $field = null
|
||||
?string $key = null
|
||||
end note
|
||||
|
||||
note right of Tableinterface::title
|
||||
Get title field from an area/view/table
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
note right of Tableinterface::titleName
|
||||
Get title field name
|
||||
|
||||
since: 3.2.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of Tableinterface::tables
|
||||
Get all tables
|
||||
|
||||
since: 3.2.0
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of Tableinterface::exist
|
||||
Check if a table (and field) exist
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of Tableinterface::fields
|
||||
Get all fields of an area/view/table
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,81 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* The VDM Core Table Interface
|
||||
*/
|
||||
interface Tableinterface
|
||||
{
|
||||
/**
|
||||
* Get any value from a item/field/column of an area/view/table
|
||||
* Example: $this->get('table_name', 'field_name', 'value_key');
|
||||
* Get an item/field/column of an area/view/table
|
||||
* Example: $this->get('table_name', 'field_name');
|
||||
* Get all items/fields/columns of an area/view/table
|
||||
* Example: $this->get('table_name');
|
||||
* Get all areas/views/tables with all their item/field/column details
|
||||
* Example: $this->get('All');
|
||||
*
|
||||
* @param string $table The table
|
||||
* @param string|null $field The field
|
||||
* @param string|null $key The value key
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $table, ?string $field = null, ?string $key = null);
|
||||
|
||||
/**
|
||||
* Get title field from an area/view/table
|
||||
*
|
||||
* @param string $table The area
|
||||
*
|
||||
* @return ?array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function title(string $table): ?array;
|
||||
|
||||
/**
|
||||
* Get title field name
|
||||
*
|
||||
* @param string $table The area
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function titleName(string $table): string;
|
||||
|
||||
/**
|
||||
* Get all tables
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function tables(): array;
|
||||
|
||||
/**
|
||||
* Check if a table (and field) exist
|
||||
*
|
||||
* @param string $table The area
|
||||
* @param string|null $field The area
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function exist(string $table, ?string $field = null): bool;
|
||||
|
||||
/**
|
||||
* Get all fields of an area/view/table
|
||||
*
|
||||
* @param string $table The area
|
||||
* @param bool $default Add the default fields
|
||||
*
|
||||
* @return array|null On success an array of fields
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function fields(string $table, bool $default = false): ?array;
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,68 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Get any value from a item/field/column of an area/view/table
|
||||
* Example: $this->get('table_name', 'field_name', 'value_key');
|
||||
* Get an item/field/column of an area/view/table
|
||||
* Example: $this->get('table_name', 'field_name');
|
||||
* Get all items/fields/columns of an area/view/table
|
||||
* Example: $this->get('table_name');
|
||||
* Get all areas/views/tables with all their item/field/column details
|
||||
* Example: $this->get('All');
|
||||
*
|
||||
* @param string $table The table
|
||||
* @param string|null $field The field
|
||||
* @param string|null $key The value key
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $table, ?string $field = null, ?string $key = null);
|
||||
|
||||
/**
|
||||
* Get title field from an area/view/table
|
||||
*
|
||||
* @param string $table The area
|
||||
*
|
||||
* @return ?array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function title(string $table): ?array;
|
||||
|
||||
/**
|
||||
* Get title field name
|
||||
*
|
||||
* @param string $table The area
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function titleName(string $table): string;
|
||||
|
||||
/**
|
||||
* Get all tables
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function tables(): array;
|
||||
|
||||
/**
|
||||
* Check if a table (and field) exist
|
||||
*
|
||||
* @param string $table The area
|
||||
* @param string|null $field The area
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function exist(string $table, ?string $field = null): bool;
|
||||
|
||||
/**
|
||||
* Get all fields of an area/view/table
|
||||
*
|
||||
* @param string $table The area
|
||||
* @param bool $default Add the default fields
|
||||
*
|
||||
* @return array|null On success an array of fields
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function fields(string $table, bool $default = false): ?array;
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "2da6d6c4-eb29-4d69-8bc2-36d96e916adf",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Tableinterface",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Interfaces.Tableinterface",
|
||||
"type": "interface",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Interfaces.Tableinterface",
|
||||
"description": "The VDM Core Table Interface",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,37 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class ClassfunctionHelper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities\String**
|
||||
```uml
|
||||
@startuml
|
||||
abstract ClassfunctionHelper #Orange {
|
||||
+ {static} safe($name) : string
|
||||
}
|
||||
|
||||
note right of ClassfunctionHelper::safe
|
||||
Making class or function name safe
|
||||
|
||||
since: 3.0.9
|
||||
return: string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,39 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a class and function
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class ClassfunctionHelper
|
||||
{
|
||||
/**
|
||||
* Making class or function name safe
|
||||
*
|
||||
* @input string The name you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe($name): string
|
||||
{
|
||||
// remove numbers if the first character is a number
|
||||
if (is_numeric(substr((string) $name, 0, 1)))
|
||||
{
|
||||
$name = StringHelper::numbers($name);
|
||||
}
|
||||
|
||||
// remove all spaces and strange characters
|
||||
return trim(preg_replace("/[^A-Za-z0-9_-]/", '', (string) $name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,20 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Making class or function name safe
|
||||
*
|
||||
* @input string The name you would like to make safe
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safe($name): string
|
||||
{
|
||||
// remove numbers if the first character is a number
|
||||
if (is_numeric(substr((string) $name, 0, 1)))
|
||||
{
|
||||
$name = StringHelper::numbers($name);
|
||||
}
|
||||
|
||||
// remove all spaces and strange characters
|
||||
return trim(preg_replace("/[^A-Za-z0-9_-]/", '', (string) $name));
|
||||
}
|
||||
|
|
|
@ -1 +1,23 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "30c5b4c2-f75f-4d15-869a-f8bfedd87358",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "ClassfunctionHelper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "String Classfunction Helper",
|
||||
"type": "abstract class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Utilities.String.ClassfunctionHelper",
|
||||
"description": "Control the naming of a class and function\r\n\r\n@since 3.0.9",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,61 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class PluginHelper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities\String**
|
||||
```uml
|
||||
@startuml
|
||||
abstract PluginHelper #Orange {
|
||||
+ {static} safeFolderName(string $codeName, string $group) : string
|
||||
+ {static} safeClassName(string $codeName, string $group) : string
|
||||
+ {static} safeInstallClassName(string $codeName, string $group) : string
|
||||
+ {static} safeLangPrefix(string $codeName, string $group) : string
|
||||
}
|
||||
|
||||
note right of PluginHelper::safeFolderName
|
||||
Making plugin folder name safe
|
||||
|
||||
since: 3.0.9
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of PluginHelper::safeClassName
|
||||
Making plugin class name safe
|
||||
|
||||
since: 3.0.9
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of PluginHelper::safeInstallClassName
|
||||
Making plugin install class name safe
|
||||
|
||||
since: 3.0.9
|
||||
return: string
|
||||
end note
|
||||
|
||||
note right of PluginHelper::safeLangPrefix
|
||||
Making language prefix safe
|
||||
|
||||
since: 3.0.9
|
||||
return: string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,107 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Utilities\String;
|
||||
|
||||
|
||||
/**
|
||||
* Control the naming of a plugin
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class PluginHelper
|
||||
{
|
||||
/**
|
||||
* Making plugin folder name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeFolderName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'plg_' . strtolower($group) . '_' . strtolower(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making plugin class name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeClassName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'Plg' . ucfirst($group) . ucfirst(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making plugin install class name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeInstallClassName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'plg' . ucfirst($group) . ucfirst(
|
||||
$codeName
|
||||
) . 'InstallerScript';
|
||||
}
|
||||
|
||||
/**
|
||||
* Making language prefix safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeLangPrefix(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'PLG_' . strtoupper($group) . '_' . strtoupper(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,91 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Making plugin folder name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeFolderName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'plg_' . strtolower($group) . '_' . strtolower(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making plugin class name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeClassName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'Plg' . ucfirst($group) . ucfirst(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Making plugin install class name safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeInstallClassName(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'plg' . ucfirst($group) . ucfirst(
|
||||
$codeName
|
||||
) . 'InstallerScript';
|
||||
}
|
||||
|
||||
/**
|
||||
* Making language prefix safe
|
||||
*
|
||||
* @input string $codeName The name
|
||||
* @input string $group The group name
|
||||
*
|
||||
* @returns string on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function safeLangPrefix(string $codeName, string $group): string
|
||||
{
|
||||
// editors-xtd group plugins must have a class with plgButton<PluginName> structure
|
||||
if ($group === 'editors-xtd')
|
||||
{
|
||||
$group = 'Button';
|
||||
}
|
||||
|
||||
return 'PLG_' . strtoupper($group) . '_' . strtoupper(
|
||||
$codeName
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "3cf76fbf-fd95-4a33-878e-7aff6d36b7f6",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "PluginHelper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "String Plugin Helper",
|
||||
"type": "abstract class",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Utilities.String.PluginHelper",
|
||||
"description": "Control the naming of a plugin\r\n\r\n@since 3.0.9",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,103 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class ActiveRegistry (Details)
|
||||
> namespace: **VDM\Joomla\Abstraction**
|
||||
```uml
|
||||
@startuml
|
||||
abstract ActiveRegistry #Orange {
|
||||
# array $active
|
||||
# bool $addAsArray
|
||||
+ isActive() : bool
|
||||
+ allActive() : array
|
||||
+ setActive(mixed $value, $keys) : void
|
||||
+ addActive(mixed $value, ?bool $asArray, ...) : void
|
||||
+ getActive(mixed $default, $keys) : mixed
|
||||
+ removeActive($keys) : void
|
||||
+ existsActive($keys) : bool
|
||||
# validActiveKeys(array $keys) : bool
|
||||
}
|
||||
|
||||
note right of ActiveRegistry::isActive
|
||||
Check if the registry has any content.
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note left of ActiveRegistry::allActive
|
||||
Get all value from the active registry.
|
||||
|
||||
since: 3.2.0
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of ActiveRegistry::setActive
|
||||
Sets a value into the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note left of ActiveRegistry::addActive
|
||||
Adds content into the registry. If a key exists,
|
||||
it either appends or concatenates based on the value's type.
|
||||
Default is $addAsArray = false (if null) in base class.
|
||||
Override in child class allowed set class property $addAsArray = true.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
|
||||
arguments:
|
||||
mixed $value
|
||||
?bool $asArray
|
||||
$keys
|
||||
end note
|
||||
|
||||
note right of ActiveRegistry::getActive
|
||||
Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
end note
|
||||
|
||||
note left of ActiveRegistry::removeActive
|
||||
Removes a value (or sub-array) from the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of ActiveRegistry::existsActive
|
||||
Checks the existence of a particular location in the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note left of ActiveRegistry::validActiveKeys
|
||||
Checks that the keys are valid
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,280 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Abstraction;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\Activeregistryinterface;
|
||||
|
||||
|
||||
/**
|
||||
* Active Storage Registry.
|
||||
*
|
||||
* Don't use this beyond 10 dimensional depth for best performance.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class ActiveRegistry implements Activeregistryinterface
|
||||
{
|
||||
/**
|
||||
* The registry array.
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $active = [];
|
||||
|
||||
/**
|
||||
* Base switch to add values as string or array
|
||||
*
|
||||
* @var boolean
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected bool $addAsArray = false;
|
||||
|
||||
/**
|
||||
* Check if the registry has any content.
|
||||
*
|
||||
* @return bool Returns true if the active array is not empty, false otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
return !empty($this->active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all value from the active registry.
|
||||
*
|
||||
* @return array The values or empty array.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function allActive(): array
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value into the registry using multiple keys.
|
||||
*
|
||||
* @param mixed $value The value to set.
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function setActive($value, string ...$keys): void
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to set any value.");
|
||||
}
|
||||
|
||||
$array = &$this->active;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
if (!is_array($array))
|
||||
{
|
||||
$path = '[' . implode('][', $keys) . ']';
|
||||
throw new \InvalidArgumentException("Attempted to use key '{$key}' on a non-array value: {$array}. Path: {$path} Value: {$value}");
|
||||
}
|
||||
|
||||
$array[$key] = [];
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
|
||||
$array = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content into the registry. If a key exists,
|
||||
* it either appends or concatenates based on the value's type.
|
||||
*
|
||||
* @param mixed $value The value to set.
|
||||
* @param bool|null $asArray Determines if the new value should be treated as an array.
|
||||
* Default is $addAsArray = false (if null) in base class.
|
||||
* Override in child class allowed set class property $addAsArray = true.
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function addActive($value, ?bool $asArray, string ...$keys): void
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to add any value.");
|
||||
}
|
||||
|
||||
// null fallback to class value
|
||||
if ($asArray === null)
|
||||
{
|
||||
$asArray = $this->addAsArray;
|
||||
}
|
||||
|
||||
$array = &$this->active;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
if (!is_array($array))
|
||||
{
|
||||
$path = '[' . implode('][', $keys) . ']';
|
||||
throw new \InvalidArgumentException("Attempted to use key '{$key}' on a non-array value: {$array}. Path: {$path} Value: {$value}");
|
||||
}
|
||||
|
||||
$array[$key] = [];
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
|
||||
// add string
|
||||
if (!$asArray && $array === [])
|
||||
{
|
||||
$array = '';
|
||||
}
|
||||
|
||||
// Handle the adding logic at the tip of the array
|
||||
if (is_array($array) || $asArray)
|
||||
{
|
||||
if (!is_array($array))
|
||||
{
|
||||
// Convert to array if it's not already an array
|
||||
$array = [$array];
|
||||
}
|
||||
$array[] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_string($value) || is_numeric($value))
|
||||
{
|
||||
$array .= (string) $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$array = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param mixed $default The default value if not set.
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return mixed The value or sub-array from the storage. Null if the location doesn't exist.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getActive($default, string ...$keys)
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to get any value.");
|
||||
}
|
||||
|
||||
$array = $this->active;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
$array = $array[$key];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function removeActive(string ...$keys): void
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to remove any value.");
|
||||
}
|
||||
|
||||
$array = &$this->active;
|
||||
$lastKey = array_pop($keys);
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
return; // Exit early if the key doesn't exist
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
|
||||
unset($array[$lastKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the existence of a particular location in the registry using multiple keys.
|
||||
*
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return bool True if the location exists, false otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function existsActive(string ...$keys): bool
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to check if any value exist.");
|
||||
}
|
||||
|
||||
$array = $this->active;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$array = $array[$key];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the keys are valid
|
||||
*
|
||||
* @param array $keys The keys to determine the location.
|
||||
*
|
||||
* @return bool False if any of the keys are not a number or string.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function validActiveKeys(array $keys): bool
|
||||
{
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if ($key === '' || (!is_string($key) && !is_numeric($key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,260 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* The registry array.
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected array $active = [];
|
||||
|
||||
/**
|
||||
* Base switch to add values as string or array
|
||||
*
|
||||
* @var boolean
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected bool $addAsArray = false;
|
||||
|
||||
/**
|
||||
* Check if the registry has any content.
|
||||
*
|
||||
* @return bool Returns true if the active array is not empty, false otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function isActive(): bool
|
||||
{
|
||||
return !empty($this->active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all value from the active registry.
|
||||
*
|
||||
* @return array The values or empty array.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function allActive(): array
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value into the registry using multiple keys.
|
||||
*
|
||||
* @param mixed $value The value to set.
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function setActive($value, string ...$keys): void
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to set any value.");
|
||||
}
|
||||
|
||||
$array = &$this->active;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
if (!is_array($array))
|
||||
{
|
||||
$path = '[' . implode('][', $keys) . ']';
|
||||
throw new \InvalidArgumentException("Attempted to use key '{$key}' on a non-array value: {$array}. Path: {$path} Value: {$value}");
|
||||
}
|
||||
|
||||
$array[$key] = [];
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
|
||||
$array = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content into the registry. If a key exists,
|
||||
* it either appends or concatenates based on the value's type.
|
||||
*
|
||||
* @param mixed $value The value to set.
|
||||
* @param bool|null $asArray Determines if the new value should be treated as an array.
|
||||
* Default is $addAsArray = false (if null) in base class.
|
||||
* Override in child class allowed set class property $addAsArray = true.
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function addActive($value, ?bool $asArray, string ...$keys): void
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to add any value.");
|
||||
}
|
||||
|
||||
// null fallback to class value
|
||||
if ($asArray === null)
|
||||
{
|
||||
$asArray = $this->addAsArray;
|
||||
}
|
||||
|
||||
$array = &$this->active;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
if (!is_array($array))
|
||||
{
|
||||
$path = '[' . implode('][', $keys) . ']';
|
||||
throw new \InvalidArgumentException("Attempted to use key '{$key}' on a non-array value: {$array}. Path: {$path} Value: {$value}");
|
||||
}
|
||||
|
||||
$array[$key] = [];
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
|
||||
// add string
|
||||
if (!$asArray && $array === [])
|
||||
{
|
||||
$array = '';
|
||||
}
|
||||
|
||||
// Handle the adding logic at the tip of the array
|
||||
if (is_array($array) || $asArray)
|
||||
{
|
||||
if (!is_array($array))
|
||||
{
|
||||
// Convert to array if it's not already an array
|
||||
$array = [$array];
|
||||
}
|
||||
$array[] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_string($value) || is_numeric($value))
|
||||
{
|
||||
$array .= (string) $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$array = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param mixed $default The default value if not set.
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return mixed The value or sub-array from the storage. Null if the location doesn't exist.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getActive($default, string ...$keys)
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to get any value.");
|
||||
}
|
||||
|
||||
$array = $this->active;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
$array = $array[$key];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function removeActive(string ...$keys): void
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to remove any value.");
|
||||
}
|
||||
|
||||
$array = &$this->active;
|
||||
$lastKey = array_pop($keys);
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
return; // Exit early if the key doesn't exist
|
||||
}
|
||||
$array = &$array[$key];
|
||||
}
|
||||
|
||||
unset($array[$lastKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the existence of a particular location in the registry using multiple keys.
|
||||
*
|
||||
* @param string ...$keys The keys to determine the location.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the keys are not a number or string.
|
||||
* @return bool True if the location exists, false otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function existsActive(string ...$keys): bool
|
||||
{
|
||||
if (!$this->validActiveKeys($keys))
|
||||
{
|
||||
throw new \InvalidArgumentException("Keys must only be strings or numbers to check if any value exist.");
|
||||
}
|
||||
|
||||
$array = $this->active;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (!isset($array[$key]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$array = $array[$key];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the keys are valid
|
||||
*
|
||||
* @param array $keys The keys to determine the location.
|
||||
*
|
||||
* @return bool False if any of the keys are not a number or string.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function validActiveKeys(array $keys): bool
|
||||
{
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if ($key === '' || (!is_string($key) && !is_numeric($key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1 +1,20 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "43134867-5cb8-4280-9be8-309fd2fd135f",
|
||||
"implements": [
|
||||
"af0eedbe-603b-4671-8e5a-28165d88254b"
|
||||
],
|
||||
"load_selection": null,
|
||||
"name": "ActiveRegistry",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Abstraction.ActiveRegistry",
|
||||
"type": "abstract class",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Abstraction.ActiveRegistry",
|
||||
"description": "Active Storage Registry.\r\n\r\nDon't use this beyond 10 dimensional depth for best performance.\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,61 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# class Database (Details)
|
||||
> namespace: **VDM\Joomla\Componentbuilder\Service**
|
||||
```uml
|
||||
@startuml
|
||||
class Database #Gold {
|
||||
+ register(Container $container) : void
|
||||
+ getLoad(Container $container) : Load
|
||||
+ getInsert(Container $container) : Insert
|
||||
+ getUpdate(Container $container) : Update
|
||||
}
|
||||
|
||||
note right of Database::register
|
||||
Registers the service provider with a DI container.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of Database::getLoad
|
||||
Get the Core Load Database
|
||||
|
||||
since: 3.2.0
|
||||
return: Load
|
||||
end note
|
||||
|
||||
note right of Database::getInsert
|
||||
Get the Core Insert Database
|
||||
|
||||
since: 3.2.0
|
||||
return: Insert
|
||||
end note
|
||||
|
||||
note right of Database::getUpdate
|
||||
Get the Core Update Database
|
||||
|
||||
since: 3.2.0
|
||||
return: Update
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,80 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Componentbuilder\Service;
|
||||
|
||||
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use VDM\Joomla\Database\Load;
|
||||
use VDM\Joomla\Database\Insert;
|
||||
use VDM\Joomla\Database\Update;
|
||||
|
||||
|
||||
/**
|
||||
* Database Service Provider
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Database implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* 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(Load::class, 'Load')
|
||||
->share('Load', [$this, 'getLoad'], true);
|
||||
|
||||
$container->alias(Insert::class, 'Insert')
|
||||
->share('Insert', [$this, 'getInsert'], true);
|
||||
|
||||
$container->alias(Update::class, 'Update')
|
||||
->share('Update', [$this, 'getUpdate'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Load Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getLoad(Container $container): Load
|
||||
{
|
||||
return new Load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Update Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Update
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpdate(Container $container): Update
|
||||
{
|
||||
return new Update();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,58 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* 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(Load::class, 'Load')
|
||||
->share('Load', [$this, 'getLoad'], true);
|
||||
|
||||
$container->alias(Insert::class, 'Insert')
|
||||
->share('Insert', [$this, 'getInsert'], true);
|
||||
|
||||
$container->alias(Update::class, 'Update')
|
||||
->share('Update', [$this, 'getUpdate'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Load Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Load
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getLoad(Container $container): Load
|
||||
{
|
||||
return new Load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Insert Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Insert
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getInsert(Container $container): Insert
|
||||
{
|
||||
return new Insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Core Update Database
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return Update
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getUpdate(Container $container): Update
|
||||
{
|
||||
return new Update();
|
||||
}
|
|
@ -1 +1,34 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "4815e1c7-a433-443d-a112-d1e03d7df84b",
|
||||
"implements": [
|
||||
"-1"
|
||||
],
|
||||
"load_selection": null,
|
||||
"name": "Database",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "JCB.Service.Database",
|
||||
"type": "class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "06f8eada-d59b-441c-b287-0aea1793da5a",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "524eb8f6-38d4-47dc-92ad-98b94e099ac0",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "cce56585-58b0-4f72-a92c-e2635ea52d83",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Componentbuilder.Service.Database",
|
||||
"description": "Database Service Provider\r\n\r\n@since 3.2.0",
|
||||
"implements_custom": "ServiceProviderInterface",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\DI\\Container;\r\nuse Joomla\\DI\\ServiceProviderInterface;",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,51 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class JsonHelper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities**
|
||||
```uml
|
||||
@startuml
|
||||
abstract JsonHelper #Orange {
|
||||
+ {static} check($string) : bool
|
||||
+ {static} string($value, $separator = ", ...)
|
||||
}
|
||||
|
||||
note right of JsonHelper::check
|
||||
Check if you have a json string
|
||||
|
||||
since: 3.0.9
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of JsonHelper::string
|
||||
Convert a json object to a string
|
||||
|
||||
since: 3.0.9
|
||||
|
||||
arguments:
|
||||
$value
|
||||
$separator = "
|
||||
$table = null
|
||||
$id = 'id'
|
||||
$name = 'name'
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,93 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
/**
|
||||
* The json checker
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
abstract class JsonHelper
|
||||
{
|
||||
/**
|
||||
* Check if you have a json string
|
||||
*
|
||||
* @input string $string The json string to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function check($string): bool
|
||||
{
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
json_decode((string) $string);
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a json object to a string
|
||||
*
|
||||
* @input string $value The json string to convert
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function string($value, $separator = ", ", $table = null, $id = 'id', $name = 'name')
|
||||
{
|
||||
// do some table foot work
|
||||
$external = false;
|
||||
if (is_string($table) && strpos((string) $table, '#__') !== false)
|
||||
{
|
||||
$external = true;
|
||||
$table = str_replace('#__', '', (string) $table);
|
||||
}
|
||||
|
||||
// check if string is JSON
|
||||
$result = json_decode((string) $value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE)
|
||||
{
|
||||
// is JSON
|
||||
if (ArrayHelper::check($result))
|
||||
{
|
||||
if (StringHelper::check($table))
|
||||
{
|
||||
$names = [];
|
||||
foreach ($result as $val)
|
||||
{
|
||||
if ($external)
|
||||
{
|
||||
if ($_name = GetHelper::var(null, $val, $id, $name, '=', $table))
|
||||
{
|
||||
$names[] = $_name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($_name = GetHelper::var($table, $val, $id, $name))
|
||||
{
|
||||
$names[] = $_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ArrayHelper::check($names))
|
||||
{
|
||||
return (string) implode($separator, $names);
|
||||
}
|
||||
}
|
||||
return (string) implode($separator, $result);
|
||||
}
|
||||
return (string) json_decode((string) $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,77 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Check if you have a json string
|
||||
*
|
||||
* @input string $string The json string to check
|
||||
*
|
||||
* @returns bool true on success
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function check($string): bool
|
||||
{
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
json_decode((string) $string);
|
||||
return (json_last_error() === JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a json object to a string
|
||||
*
|
||||
* @input string $value The json string to convert
|
||||
*
|
||||
* @returns a string
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function string($value, $separator = ", ", $table = null, $id = 'id', $name = 'name')
|
||||
{
|
||||
// do some table foot work
|
||||
$external = false;
|
||||
if (is_string($table) && strpos((string) $table, '#__') !== false)
|
||||
{
|
||||
$external = true;
|
||||
$table = str_replace('#__', '', (string) $table);
|
||||
}
|
||||
|
||||
// check if string is JSON
|
||||
$result = json_decode((string) $value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE)
|
||||
{
|
||||
// is JSON
|
||||
if (ArrayHelper::check($result))
|
||||
{
|
||||
if (StringHelper::check($table))
|
||||
{
|
||||
$names = [];
|
||||
foreach ($result as $val)
|
||||
{
|
||||
if ($external)
|
||||
{
|
||||
if ($_name = GetHelper::var(null, $val, $id, $name, '=', $table))
|
||||
{
|
||||
$names[] = $_name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($_name = GetHelper::var($table, $val, $id, $name))
|
||||
{
|
||||
$names[] = $_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ArrayHelper::check($names))
|
||||
{
|
||||
return (string) implode($separator, $names);
|
||||
}
|
||||
}
|
||||
return (string) implode($separator, $result);
|
||||
}
|
||||
return (string) json_decode((string) $value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
|
|
@ -1 +1,28 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "4b225c51-d293-48e4-b3f6-5136cf5c3f18",
|
||||
"implements": null,
|
||||
"load_selection": {
|
||||
"load_selection0": {
|
||||
"load": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef"
|
||||
},
|
||||
"load_selection1": {
|
||||
"load": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a"
|
||||
},
|
||||
"load_selection2": {
|
||||
"load": "db87c339-5bb6-4291-a7ef-2c48ea1b06bc"
|
||||
}
|
||||
},
|
||||
"name": "JsonHelper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Utilities Json Helper",
|
||||
"type": "abstract class",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Utilities.JsonHelper",
|
||||
"description": "The json checker\r\n\r\n@since 3.0.9",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,111 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# final class Insert (Details)
|
||||
> namespace: **VDM\Joomla\Database**
|
||||
> extends: **Database**
|
||||
```uml
|
||||
@startuml
|
||||
class Insert << (F,LightGreen) >> #RoyalBlue {
|
||||
# bool $defaults
|
||||
+ defaults(bool $trigger = true) : void
|
||||
+ rows(array $data, string $table, ...) : bool
|
||||
+ items(array $data, string $table, ...) : bool
|
||||
+ row(array $data, string $table) : bool
|
||||
+ item(object $data, string $table) : bool
|
||||
# getArrayColumns(array $data) : array
|
||||
# getObjectsColumns(array $data) : array
|
||||
# insert(array $data, string $table, ...) : bool
|
||||
}
|
||||
|
||||
note right of Insert::defaults
|
||||
Switch to prevent/allow defaults from being added.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note left of Insert::rows
|
||||
Insert rows to the database (with remapping and filtering columns option)
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
array $data
|
||||
string $table
|
||||
array $columns = []
|
||||
end note
|
||||
|
||||
note right of Insert::items
|
||||
Insert items to the database (with remapping and filtering columns option)
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
array $data
|
||||
string $table
|
||||
array $columns = []
|
||||
end note
|
||||
|
||||
note left of Insert::row
|
||||
Insert row to the database
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of Insert::item
|
||||
Insert item to the database
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note left of Insert::getArrayColumns
|
||||
Get columns from data array
|
||||
|
||||
since: 3.2.0
|
||||
return: array
|
||||
end note
|
||||
|
||||
note right of Insert::getObjectsColumns
|
||||
Get columns from data objects
|
||||
|
||||
since: 3.2.0
|
||||
return: array
|
||||
end note
|
||||
|
||||
note left of Insert::insert
|
||||
Insert data into the database
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
array $data
|
||||
string $table
|
||||
array $columns
|
||||
bool $isArray
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,282 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Database;
|
||||
|
||||
|
||||
use Joomla\CMS\Date\Date;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Interfaces\InsertInterface;
|
||||
use VDM\Joomla\Abstraction\Database;
|
||||
|
||||
|
||||
/**
|
||||
* Database Insert Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
final class Insert extends Database implements InsertInterface
|
||||
{
|
||||
/**
|
||||
* Switch to set the defaults
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.2.0
|
||||
**/
|
||||
protected bool $defaults = true;
|
||||
|
||||
/**
|
||||
* Switch to prevent/allow defaults from being added.
|
||||
*
|
||||
* @param bool $trigger toggle the defaults
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function defaults(bool $trigger = true)
|
||||
{
|
||||
$this->defaults = $trigger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert rows to the database (with remapping and filtering columns option)
|
||||
*
|
||||
* @param array $data Dataset to store in database [array of arrays (key => value)]
|
||||
* @param string $table The table where the data is being added
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $data, string $table, array $columns = []): bool
|
||||
{
|
||||
if (!ArrayHelper::check($data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($columns === [])
|
||||
{
|
||||
$columns = $this->getArrayColumns($data);
|
||||
}
|
||||
|
||||
return ($columns === []) ? false : $this->insert($data, $table, $columns, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert items to the database (with remapping and filtering columns option)
|
||||
*
|
||||
* @param array $data Data to store in database (array of objects)
|
||||
* @param string $table The table where the data is being added
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $data, string $table, array $columns = []): bool
|
||||
{
|
||||
if (!ArrayHelper::check($data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($columns === [])
|
||||
{
|
||||
$columns = $this->getObjectsColumns($data);
|
||||
}
|
||||
|
||||
return ($columns === []) ? false : $this->insert($data, $table, $columns, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert row to the database
|
||||
*
|
||||
* @param array $data Dataset to store in database (key => value)
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $data, string $table): bool
|
||||
{
|
||||
return $this->rows([$data], $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert item to the database
|
||||
*
|
||||
* @param object $data Dataset to store in database (key => value)
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(object $data, string $table): bool
|
||||
{
|
||||
return $this->items([$data], $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get columns from data array
|
||||
*
|
||||
* @param array $data Data array
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getArrayColumns(array &$data): array
|
||||
{
|
||||
$row = array_values($data)[0];
|
||||
|
||||
if (!ArrayHelper::check($row))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$columns = array_keys($row);
|
||||
|
||||
return array_combine($columns, $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get columns from data objects
|
||||
*
|
||||
* @param array $data Data objects
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getObjectsColumns(array &$data): array
|
||||
{
|
||||
$row = array_values($data)[0];
|
||||
|
||||
if (!is_object($row))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$columns = get_object_vars($row);
|
||||
|
||||
return array_combine(array_keys($columns), array_keys($columns));
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert data into the database
|
||||
*
|
||||
* @param array $data Data to store in database
|
||||
* @param string $table The table where the data is being added
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
* @param bool $isArray Whether the data is an array of arrays or an array of objects
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function insert(array &$data, string $table, array $columns, bool $isArray): bool
|
||||
{
|
||||
// set joomla default columns
|
||||
$add_created = false;
|
||||
$add_version = false;
|
||||
$add_published = false;
|
||||
|
||||
// check if we should load the defaults
|
||||
if ($this->defaults)
|
||||
{
|
||||
// get the date
|
||||
$date = (new Date())->toSql();
|
||||
|
||||
if (!isset($columns['created']))
|
||||
{
|
||||
$columns['created'] = ' (o_O) ';
|
||||
$add_created = true;
|
||||
}
|
||||
|
||||
if (!isset($columns['version']))
|
||||
{
|
||||
$columns['version'] = ' (o_O) ';
|
||||
$add_version = true;
|
||||
}
|
||||
|
||||
if (!isset($columns['published']))
|
||||
{
|
||||
$columns['published'] = ' (o_O) ';
|
||||
$add_published = true;
|
||||
}
|
||||
// the (o_O) prevents an empty value from being loaded
|
||||
}
|
||||
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// set the query targets
|
||||
$query->insert($this->db->quoteName($this->getTable($table)))->columns($this->db->quoteName(array_keys($columns)));
|
||||
|
||||
// limiting factor on the amount of rows to insert before we reset the query
|
||||
$limit = 300;
|
||||
|
||||
// set the insert values
|
||||
foreach ($data as $nr => $value)
|
||||
{
|
||||
// check the limit
|
||||
if ($limit <= 1)
|
||||
{
|
||||
// execute and reset the query
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// reset limit
|
||||
$limit = 300;
|
||||
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// set the query targets
|
||||
$query->insert($this->db->quoteName($this->getTable($table)))->columns($this->db->quoteName(array_keys($columns)));
|
||||
}
|
||||
|
||||
$row = [];
|
||||
foreach ($columns as $column => $key)
|
||||
{
|
||||
if (' (o_O) ' !== $key)
|
||||
{
|
||||
$row[] = ($isArray && isset($value[$key])) ? $this->quote($value[$key])
|
||||
: ((!$isArray && isset($value->{$key})) ? $this->quote($value->{$key}) : '');
|
||||
}
|
||||
}
|
||||
|
||||
// set joomla default columns
|
||||
if ($add_created)
|
||||
{
|
||||
$row[] = $this->db->quote($date);
|
||||
}
|
||||
|
||||
if ($add_version)
|
||||
{
|
||||
$row[] = 1;
|
||||
}
|
||||
|
||||
if ($add_published)
|
||||
{
|
||||
$row[] = 1;
|
||||
}
|
||||
|
||||
// add to query
|
||||
$query->values(implode(',', $row));
|
||||
|
||||
// decrement the limiter
|
||||
$limit--;
|
||||
|
||||
// clear the data from memory
|
||||
unset($data[$nr]);
|
||||
}
|
||||
|
||||
// execute the final query
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// always reset the default switch
|
||||
$this->defaults();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,261 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Switch to set the defaults
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.2.0
|
||||
**/
|
||||
protected bool $defaults = true;
|
||||
|
||||
/**
|
||||
* Switch to prevent/allow defaults from being added.
|
||||
*
|
||||
* @param bool $trigger toggle the defaults
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function defaults(bool $trigger = true)
|
||||
{
|
||||
$this->defaults = $trigger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert rows to the database (with remapping and filtering columns option)
|
||||
*
|
||||
* @param array $data Dataset to store in database [array of arrays (key => value)]
|
||||
* @param string $table The table where the data is being added
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $data, string $table, array $columns = []): bool
|
||||
{
|
||||
if (!ArrayHelper::check($data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($columns === [])
|
||||
{
|
||||
$columns = $this->getArrayColumns($data);
|
||||
}
|
||||
|
||||
return ($columns === []) ? false : $this->insert($data, $table, $columns, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert items to the database (with remapping and filtering columns option)
|
||||
*
|
||||
* @param array $data Data to store in database (array of objects)
|
||||
* @param string $table The table where the data is being added
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $data, string $table, array $columns = []): bool
|
||||
{
|
||||
if (!ArrayHelper::check($data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($columns === [])
|
||||
{
|
||||
$columns = $this->getObjectsColumns($data);
|
||||
}
|
||||
|
||||
return ($columns === []) ? false : $this->insert($data, $table, $columns, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert row to the database
|
||||
*
|
||||
* @param array $data Dataset to store in database (key => value)
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $data, string $table): bool
|
||||
{
|
||||
return $this->rows([$data], $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert item to the database
|
||||
*
|
||||
* @param object $data Dataset to store in database (key => value)
|
||||
* @param string $table The table where the data is being added
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(object $data, string $table): bool
|
||||
{
|
||||
return $this->items([$data], $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get columns from data array
|
||||
*
|
||||
* @param array $data Data array
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getArrayColumns(array &$data): array
|
||||
{
|
||||
$row = array_values($data)[0];
|
||||
|
||||
if (!ArrayHelper::check($row))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$columns = array_keys($row);
|
||||
|
||||
return array_combine($columns, $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get columns from data objects
|
||||
*
|
||||
* @param array $data Data objects
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getObjectsColumns(array &$data): array
|
||||
{
|
||||
$row = array_values($data)[0];
|
||||
|
||||
if (!is_object($row))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$columns = get_object_vars($row);
|
||||
|
||||
return array_combine(array_keys($columns), array_keys($columns));
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert data into the database
|
||||
*
|
||||
* @param array $data Data to store in database
|
||||
* @param string $table The table where the data is being added
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
* @param bool $isArray Whether the data is an array of arrays or an array of objects
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function insert(array &$data, string $table, array $columns, bool $isArray): bool
|
||||
{
|
||||
// set joomla default columns
|
||||
$add_created = false;
|
||||
$add_version = false;
|
||||
$add_published = false;
|
||||
|
||||
// check if we should load the defaults
|
||||
if ($this->defaults)
|
||||
{
|
||||
// get the date
|
||||
$date = (new Date())->toSql();
|
||||
|
||||
if (!isset($columns['created']))
|
||||
{
|
||||
$columns['created'] = ' (o_O) ';
|
||||
$add_created = true;
|
||||
}
|
||||
|
||||
if (!isset($columns['version']))
|
||||
{
|
||||
$columns['version'] = ' (o_O) ';
|
||||
$add_version = true;
|
||||
}
|
||||
|
||||
if (!isset($columns['published']))
|
||||
{
|
||||
$columns['published'] = ' (o_O) ';
|
||||
$add_published = true;
|
||||
}
|
||||
// the (o_O) prevents an empty value from being loaded
|
||||
}
|
||||
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// set the query targets
|
||||
$query->insert($this->db->quoteName($this->getTable($table)))->columns($this->db->quoteName(array_keys($columns)));
|
||||
|
||||
// limiting factor on the amount of rows to insert before we reset the query
|
||||
$limit = 300;
|
||||
|
||||
// set the insert values
|
||||
foreach ($data as $nr => $value)
|
||||
{
|
||||
// check the limit
|
||||
if ($limit <= 1)
|
||||
{
|
||||
// execute and reset the query
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// reset limit
|
||||
$limit = 300;
|
||||
|
||||
// get a query object
|
||||
$query = $this->db->getQuery(true);
|
||||
|
||||
// set the query targets
|
||||
$query->insert($this->db->quoteName($this->getTable($table)))->columns($this->db->quoteName(array_keys($columns)));
|
||||
}
|
||||
|
||||
$row = [];
|
||||
foreach ($columns as $column => $key)
|
||||
{
|
||||
if (' (o_O) ' !== $key)
|
||||
{
|
||||
$row[] = ($isArray && isset($value[$key])) ? $this->quote($value[$key])
|
||||
: ((!$isArray && isset($value->{$key})) ? $this->quote($value->{$key}) : '');
|
||||
}
|
||||
}
|
||||
|
||||
// set joomla default columns
|
||||
if ($add_created)
|
||||
{
|
||||
$row[] = $this->db->quote($date);
|
||||
}
|
||||
|
||||
if ($add_version)
|
||||
{
|
||||
$row[] = 1;
|
||||
}
|
||||
|
||||
if ($add_published)
|
||||
{
|
||||
$row[] = 1;
|
||||
}
|
||||
|
||||
// add to query
|
||||
$query->values(implode(',', $row));
|
||||
|
||||
// decrement the limiter
|
||||
$limit--;
|
||||
|
||||
// clear the data from memory
|
||||
unset($data[$nr]);
|
||||
}
|
||||
|
||||
// execute the final query
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
// always reset the default switch
|
||||
$this->defaults();
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1 +1,25 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "6cbef8f8-4813-48e3-b05a-65e1aea95171",
|
||||
"guid": "524eb8f6-38d4-47dc-92ad-98b94e099ac0",
|
||||
"implements": [
|
||||
"ad12ca1c-d3ce-4e7f-88c5-c6c92bdedc48"
|
||||
],
|
||||
"load_selection": null,
|
||||
"name": "Insert",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Database.Insert",
|
||||
"type": "final class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Database.Insert",
|
||||
"description": "Database Insert Class\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Date\\Date;",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,46 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# trait VarExport (Details)
|
||||
> namespace: **VDM\Joomla\Abstraction\Registry\Traits**
|
||||
```uml
|
||||
@startuml
|
||||
class VarExport << (T,Orange) >> #Turquoise {
|
||||
# int $indent
|
||||
+ varExport(?string $path = null, int $indentation = 2) : ?string
|
||||
# convertIndent(array $matches) : string
|
||||
}
|
||||
|
||||
note right of VarExport::varExport
|
||||
Method to export a set of values to a PHP array
|
||||
|
||||
since: 3.4.0
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note right of VarExport::convertIndent
|
||||
Method to convert found of grouped spaces to system indentation
|
||||
|
||||
since: 3.4.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,97 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Abstraction\Registry\Traits;
|
||||
|
||||
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
|
||||
|
||||
|
||||
/**
|
||||
* Var Export Values
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
trait VarExport
|
||||
{
|
||||
/**
|
||||
* Default indentation value
|
||||
*
|
||||
* @var int
|
||||
* @since 3.4.0
|
||||
*/
|
||||
protected int $indent = 2;
|
||||
|
||||
/**
|
||||
* Method to export a set of values to a PHP array
|
||||
*
|
||||
* @param string|null $path Registry path (e.g. joomla.content.showauthor)
|
||||
* @param int $indentation The default indentation
|
||||
*
|
||||
* @return ?string The var set being exported as a PHP array
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function varExport(?string $path = null, int $indentation = 2): ?string
|
||||
{
|
||||
// Load the data array
|
||||
if ($path === null && $this->isActive())
|
||||
{
|
||||
$data = $this->allActive();
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $this->get($path);
|
||||
}
|
||||
|
||||
// check if we have data
|
||||
if ($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// set the default indentation value
|
||||
$this->indent = $indentation;
|
||||
|
||||
// convert to string
|
||||
$data = var_export($data, true);
|
||||
|
||||
// replace all space with system indentation
|
||||
$data = preg_replace_callback("/^(\s{2})(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(.*)/m", [$this, 'convertIndent'], $data);
|
||||
|
||||
// convert all array to []
|
||||
$array = preg_split("/\r\n|\n|\r/", $data);
|
||||
$array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ']$1', ' => ['], $array);
|
||||
$data = implode(PHP_EOL, array_filter(["["] + $array));
|
||||
|
||||
// add needed indentation to the last ]
|
||||
$data = preg_replace("/^(\])/m", Indent::_($indentation) . '$1', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to convert found of grouped spaces to system indentation
|
||||
*
|
||||
* @param array $matches The regex array of matching values
|
||||
*
|
||||
* @return string The resulting string.
|
||||
* @since 3.4.0
|
||||
*/
|
||||
protected function convertIndent(array $matches): string
|
||||
{
|
||||
// set number to indent by default
|
||||
$indent = Indent::_($this->indent);
|
||||
|
||||
// update each found space (group) with one indentation
|
||||
foreach (range(1, 11) as $space)
|
||||
{
|
||||
if (strlen((string) $matches[$space]) > 0)
|
||||
{
|
||||
$indent .= Indent::_(1);
|
||||
}
|
||||
}
|
||||
|
||||
return $indent . $matches[12];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,79 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Default indentation value
|
||||
*
|
||||
* @var int
|
||||
* @since 3.4.0
|
||||
*/
|
||||
protected int $indent = 2;
|
||||
|
||||
/**
|
||||
* Method to export a set of values to a PHP array
|
||||
*
|
||||
* @param string|null $path Registry path (e.g. joomla.content.showauthor)
|
||||
* @param int $indentation The default indentation
|
||||
*
|
||||
* @return ?string The var set being exported as a PHP array
|
||||
* @since 3.4.0
|
||||
*/
|
||||
public function varExport(?string $path = null, int $indentation = 2): ?string
|
||||
{
|
||||
// Load the data array
|
||||
if ($path === null && $this->isActive())
|
||||
{
|
||||
$data = $this->allActive();
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $this->get($path);
|
||||
}
|
||||
|
||||
// check if we have data
|
||||
if ($data === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// set the default indentation value
|
||||
$this->indent = $indentation;
|
||||
|
||||
// convert to string
|
||||
$data = var_export($data, true);
|
||||
|
||||
// replace all space with system indentation
|
||||
$data = preg_replace_callback("/^(\s{2})(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(\s{2})?(.*)/m", [$this, 'convertIndent'], $data);
|
||||
|
||||
// convert all array to []
|
||||
$array = preg_split("/\r\n|\n|\r/", $data);
|
||||
$array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ']$1', ' => ['], $array);
|
||||
$data = implode(PHP_EOL, array_filter(["["] + $array));
|
||||
|
||||
// add needed indentation to the last ]
|
||||
$data = preg_replace("/^(\])/m", Indent::_($indentation) . '$1', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to convert found of grouped spaces to system indentation
|
||||
*
|
||||
* @param array $matches The regex array of matching values
|
||||
*
|
||||
* @return string The resulting string.
|
||||
* @since 3.4.0
|
||||
*/
|
||||
protected function convertIndent(array $matches): string
|
||||
{
|
||||
// set number to indent by default
|
||||
$indent = Indent::_($this->indent);
|
||||
|
||||
// update each found space (group) with one indentation
|
||||
foreach (range(1, 11) as $space)
|
||||
{
|
||||
if (strlen((string) $matches[$space]) > 0)
|
||||
{
|
||||
$indent .= Indent::_(1);
|
||||
}
|
||||
}
|
||||
|
||||
return $indent . $matches[12];
|
||||
}
|
|
@ -1 +1,23 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "52a1d14f-304a-431c-8fa4-411179942db5",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "VarExport",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Abstraction.Registry.Traits.VarExport",
|
||||
"type": "trait",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "a68c010b-e92e-47d5-8a44-d23cfddeb6c6",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Abstraction.Registry.Traits.VarExport",
|
||||
"description": "Var Export Values\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,139 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class Model (Details)
|
||||
> namespace: **VDM\Joomla\Abstraction**
|
||||
```uml
|
||||
@startuml
|
||||
abstract Model #Orange {
|
||||
# array $last
|
||||
# Table $table
|
||||
+ __construct(Table $table)
|
||||
+ {abstract} value(mixed $value, string $field, ...) : mixed
|
||||
+ item(?object $item, ?string $table = null) : ?object
|
||||
+ items(?array $items = null, ?string $table = null) : ?array
|
||||
+ row(?array $item, ?string $table = null) : ?array
|
||||
+ rows(?array $items = null, ?string $table = null) : ?array
|
||||
+ last(?string $table = null) : ?int
|
||||
# getTableFields(string $table, bool $default = false) : ?array
|
||||
# {abstract} validateBefore(mixed $value, ?string $field = null, ...) : bool
|
||||
# {abstract} validateAfter(mixed $value, ?string $field = null, ...) : bool
|
||||
# {abstract} getTable() : string
|
||||
}
|
||||
|
||||
note right of Model::__construct
|
||||
Constructor
|
||||
|
||||
since: 3.2.0
|
||||
end note
|
||||
|
||||
note left of Model::value
|
||||
Model the value
|
||||
Example: $this->value(value, 'value_key', 'table_name');
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
|
||||
arguments:
|
||||
mixed $value
|
||||
string $field
|
||||
?string $table = null
|
||||
end note
|
||||
|
||||
note right of Model::item
|
||||
Model the values of an item
|
||||
Example: $this->item(Object, 'table_name');
|
||||
|
||||
since: 3.2.0
|
||||
return: ?object
|
||||
end note
|
||||
|
||||
note left of Model::items
|
||||
Model the values of multiple items
|
||||
Example: $this->items(Array, 'table_name');
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
note right of Model::row
|
||||
Model the values of an row
|
||||
Example: $this->item(Array, 'table_name');
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
note left of Model::rows
|
||||
Model the values of multiple rows
|
||||
Example: $this->items(Array, 'table_name');
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
note right of Model::last
|
||||
Get last modeled ID
|
||||
Example: $this->last('table_name');
|
||||
|
||||
since: 3.2.0
|
||||
return: ?int
|
||||
end note
|
||||
|
||||
note left of Model::getTableFields
|
||||
Get the current active table's fields (including defaults)
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
note right of Model::validateBefore
|
||||
Validate before the value is modelled (basic, override in child class)
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
mixed $value
|
||||
?string $field = null
|
||||
?string $table = null
|
||||
end note
|
||||
|
||||
note left of Model::validateAfter
|
||||
Validate after the value is modelled (basic, override in child class)
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
mixed $value
|
||||
?string $field = null
|
||||
?string $table = null
|
||||
end note
|
||||
|
||||
note right of Model::getTable
|
||||
Get the current active table
|
||||
|
||||
since: 3.2.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,350 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Abstraction;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Interfaces\Tableinterface as Table;
|
||||
|
||||
|
||||
/**
|
||||
* Base Model
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Model
|
||||
{
|
||||
/**
|
||||
* Last ID
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $last;
|
||||
|
||||
/**
|
||||
* Search Table
|
||||
*
|
||||
* @var Table
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Table $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Table $table The search table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Table $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'value_key', 'table_name');
|
||||
*
|
||||
* @param mixed $value The value to model
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract public function value($value, string $field, ?string $table = null);
|
||||
|
||||
/**
|
||||
* Model the values of an item
|
||||
* Example: $this->item(Object, 'table_name');
|
||||
*
|
||||
* @param object|null $item The item object
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(?object $item, ?string $table = null): ?object
|
||||
{
|
||||
// we must have an object
|
||||
if (empty($item))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
if (($fields = $this->getTableFields($table, true)) !== null)
|
||||
{
|
||||
// field counter
|
||||
$field_number = 0;
|
||||
|
||||
// check if this is a valid table
|
||||
$item_bucket = new \stdClass();
|
||||
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
// model a value if it exists
|
||||
if(isset($item->{$field}))
|
||||
{
|
||||
if (!$this->validateBefore($item->{$field}, $field, $table))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$item->{$field} = $this->value($item->{$field}, $field, $table);
|
||||
|
||||
if (!$this->validateAfter($item->{$field}, $field, $table))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$item_bucket->{$field} = $item->{$field};
|
||||
|
||||
$field_number++;
|
||||
}
|
||||
}
|
||||
|
||||
// all items must have more than one field or its empty (1 = key)
|
||||
if ($field_number > 1)
|
||||
{
|
||||
return $item_bucket;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the values of multiple items
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $items The array of item objects
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null): ?array
|
||||
{
|
||||
// check if this is a valid table
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
foreach ($items as $id => &$item)
|
||||
{
|
||||
// model the item
|
||||
if (($item = $this->item($item, $table)) !== null)
|
||||
{
|
||||
// add the last ID
|
||||
$this->last[$table] = $item->id ?? $this->last[$table] ?? null;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($items[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the values of an row
|
||||
* Example: $this->item(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $item The item array
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function row(?array $item, ?string $table = null): ?array
|
||||
{
|
||||
// we must have an array
|
||||
if (empty($item))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
if (($fields = $this->getTableFields($table, true)) !== null)
|
||||
{
|
||||
// field counter
|
||||
$field_number = 0;
|
||||
|
||||
// check if this is a valid table
|
||||
$item_bucket = [];
|
||||
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
// model a value if it exists
|
||||
if(isset($item[$field]))
|
||||
{
|
||||
if (!$this->validateBefore($item[$field], $field, $table))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$item[$field] = $this->value($item[$field], $field, $table);
|
||||
|
||||
if (!$this->validateAfter($item[$field], $field, $table))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$item_bucket[$field] = $item[$field];
|
||||
|
||||
$field_number++;
|
||||
}
|
||||
}
|
||||
|
||||
// all items must have more than one field or its empty (1 = id or guid)
|
||||
if ($field_number > 1)
|
||||
{
|
||||
return $item_bucket;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the values of multiple rows
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $items The array of item array
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function rows(?array $items = null, ?string $table = null): ?array
|
||||
{
|
||||
// check if this is a valid table
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
foreach ($items as $id => &$item)
|
||||
{
|
||||
// model the item
|
||||
if (($item = $this->row($item, $table)) !== null)
|
||||
{
|
||||
// add the last ID
|
||||
$this->last[$table] = $item['id'] ?? $this->last[$table] ?? null;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($items[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last modeled ID
|
||||
* Example: $this->last('table_name');
|
||||
*
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function last(?string $table = null): ?int
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ($table && isset($this->last[$table]))
|
||||
{
|
||||
return $this->last[$table];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table's fields (including defaults)
|
||||
*
|
||||
* @param string $table The area
|
||||
* @param bool $default Add the default fields
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTableFields(string $table, bool $default = false): ?array
|
||||
{
|
||||
return $this->table->fields($table, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate before the value is modelled (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool;
|
||||
|
||||
/**
|
||||
* Validate after the value is modelled (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool;
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function getTable(): string;
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,330 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Last ID
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $last;
|
||||
|
||||
/**
|
||||
* Search Table
|
||||
*
|
||||
* @var Table
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Table $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Table $table The search table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Table $table)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the value
|
||||
* Example: $this->value(value, 'value_key', 'table_name');
|
||||
*
|
||||
* @param mixed $value The value to model
|
||||
* @param string $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract public function value($value, string $field, ?string $table = null);
|
||||
|
||||
/**
|
||||
* Model the values of an item
|
||||
* Example: $this->item(Object, 'table_name');
|
||||
*
|
||||
* @param object|null $item The item object
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return object|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function item(?object $item, ?string $table = null): ?object
|
||||
{
|
||||
// we must have an object
|
||||
if (empty($item))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
if (($fields = $this->getTableFields($table, true)) !== null)
|
||||
{
|
||||
// field counter
|
||||
$field_number = 0;
|
||||
|
||||
// check if this is a valid table
|
||||
$item_bucket = new \stdClass();
|
||||
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
// model a value if it exists
|
||||
if(isset($item->{$field}))
|
||||
{
|
||||
if (!$this->validateBefore($item->{$field}, $field, $table))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$item->{$field} = $this->value($item->{$field}, $field, $table);
|
||||
|
||||
if (!$this->validateAfter($item->{$field}, $field, $table))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$item_bucket->{$field} = $item->{$field};
|
||||
|
||||
$field_number++;
|
||||
}
|
||||
}
|
||||
|
||||
// all items must have more than one field or its empty (1 = key)
|
||||
if ($field_number > 1)
|
||||
{
|
||||
return $item_bucket;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the values of multiple items
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $items The array of item objects
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function items(?array $items = null, ?string $table = null): ?array
|
||||
{
|
||||
// check if this is a valid table
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
foreach ($items as $id => &$item)
|
||||
{
|
||||
// model the item
|
||||
if (($item = $this->item($item, $table)) !== null)
|
||||
{
|
||||
// add the last ID
|
||||
$this->last[$table] = $item->id ?? $this->last[$table] ?? null;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($items[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the values of an row
|
||||
* Example: $this->item(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $item The item array
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function row(?array $item, ?string $table = null): ?array
|
||||
{
|
||||
// we must have an array
|
||||
if (empty($item))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
if (($fields = $this->getTableFields($table, true)) !== null)
|
||||
{
|
||||
// field counter
|
||||
$field_number = 0;
|
||||
|
||||
// check if this is a valid table
|
||||
$item_bucket = [];
|
||||
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
// model a value if it exists
|
||||
if(isset($item[$field]))
|
||||
{
|
||||
if (!$this->validateBefore($item[$field], $field, $table))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$item[$field] = $this->value($item[$field], $field, $table);
|
||||
|
||||
if (!$this->validateAfter($item[$field], $field, $table))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$item_bucket[$field] = $item[$field];
|
||||
|
||||
$field_number++;
|
||||
}
|
||||
}
|
||||
|
||||
// all items must have more than one field or its empty (1 = id or guid)
|
||||
if ($field_number > 1)
|
||||
{
|
||||
return $item_bucket;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Model the values of multiple rows
|
||||
* Example: $this->items(Array, 'table_name');
|
||||
*
|
||||
* @param array|null $items The array of item array
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function rows(?array $items = null, ?string $table = null): ?array
|
||||
{
|
||||
// check if this is a valid table
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
foreach ($items as $id => &$item)
|
||||
{
|
||||
// model the item
|
||||
if (($item = $this->row($item, $table)) !== null)
|
||||
{
|
||||
// add the last ID
|
||||
$this->last[$table] = $item['id'] ?? $this->last[$table] ?? null;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($items[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($items))
|
||||
{
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last modeled ID
|
||||
* Example: $this->last('table_name');
|
||||
*
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return int|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function last(?string $table = null): ?int
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
// check if this is a valid table
|
||||
if ($table && isset($this->last[$table]))
|
||||
{
|
||||
return $this->last[$table];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active table's fields (including defaults)
|
||||
*
|
||||
* @param string $table The area
|
||||
* @param bool $default Add the default fields
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getTableFields(string $table, bool $default = false): ?array
|
||||
{
|
||||
return $this->table->fields($table, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate before the value is modelled (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool;
|
||||
|
||||
/**
|
||||
* Validate after the value is modelled (basic, override in child class)
|
||||
*
|
||||
* @param mixed $value The field value
|
||||
* @param string|null $field The field key
|
||||
* @param string|null $table The table
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool;
|
||||
|
||||
/**
|
||||
* Get the current active table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract protected function getTable(): string;
|
|
@ -1 +1,31 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "584747d1-3a86-453d-b7a3-a2219de8d777",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Model",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Abstraction.Model",
|
||||
"type": "abstract class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection1": {
|
||||
"use": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
|
||||
"as": "default"
|
||||
},
|
||||
"use_selection2": {
|
||||
"use": "2da6d6c4-eb29-4d69-8bc2-36d96e916adf",
|
||||
"as": "Table"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Abstraction.Model",
|
||||
"description": "Base Model\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,37 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# trait GetString (Details)
|
||||
> namespace: **VDM\Joomla\Abstraction\Registry\Traits**
|
||||
```uml
|
||||
@startuml
|
||||
class GetString << (T,Orange) >> #Turquoise {
|
||||
+ getString(string $path, ?string $default = null) : ?string
|
||||
}
|
||||
|
||||
note right of GetString::getString
|
||||
Get a registry path if the return value is a string
|
||||
|
||||
since: 3.2.0
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,42 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Abstraction\Registry\Traits;
|
||||
|
||||
|
||||
/**
|
||||
* Get String Values
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
trait GetString
|
||||
{
|
||||
/**
|
||||
* Get a registry path if the return value is a string
|
||||
*
|
||||
* @param string $path Registry path (e.g. joomla.content.showauthor)
|
||||
* @param string|null $default A default value
|
||||
*
|
||||
* @return string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getString(string $path, ?string $default = null): ?string
|
||||
{
|
||||
// Return default value if path is empty
|
||||
if (empty($path))
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
|
||||
// get the value
|
||||
if (($node = $this->get($path)) !== null
|
||||
&& is_string($node)
|
||||
&& strlen((string) $node) > 0)
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,27 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Get a registry path if the return value is a string
|
||||
*
|
||||
* @param string $path Registry path (e.g. joomla.content.showauthor)
|
||||
* @param string|null $default A default value
|
||||
*
|
||||
* @return string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getString(string $path, ?string $default = null): ?string
|
||||
{
|
||||
// Return default value if path is empty
|
||||
if (empty($path))
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
|
||||
// get the value
|
||||
if (($node = $this->get($path)) !== null
|
||||
&& is_string($node)
|
||||
&& strlen((string) $node) > 0)
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "59b1a2ea-d77e-4040-ac8c-e65cd8743e9b",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "GetString",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Abstraction.Registry.Traits.GetString",
|
||||
"type": "trait",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Abstraction.Registry.Traits.GetString",
|
||||
"description": "Get String Values\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,106 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class Helper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities\Component**
|
||||
```uml
|
||||
@startuml
|
||||
abstract Helper #Orange {
|
||||
+ {static} getParams(?string $option = null) : Registry
|
||||
+ {static} setOption(?string $option) : void
|
||||
+ {static} getOption(?string $default = 'empty') : ?string
|
||||
+ {static} getCode(?string $option = null, ?string $default = null) : ?string
|
||||
+ {static} get(?string $option = null, ?string $default = null) : ?string
|
||||
+ {static} getNamespace(?string $option = null) : ?string
|
||||
+ {static} getManifest(?string $option = null) : ?object
|
||||
+ {static} methodExists(string $method, ?string $option = null) : bool
|
||||
+ {static} _(string $method, array $arguments = [], ...) : mixed
|
||||
}
|
||||
|
||||
note right of Helper::getParams
|
||||
Gets the parameter object for the component
|
||||
|
||||
since: 3.0.11
|
||||
return: Registry
|
||||
end note
|
||||
|
||||
note left of Helper::setOption
|
||||
Set the component option
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of Helper::getOption
|
||||
Get the component option
|
||||
|
||||
since: 3.0.11
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note left of Helper::getCode
|
||||
Gets the component code name
|
||||
|
||||
since: 3.0.11
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note right of Helper::get
|
||||
Gets the component abstract helper class
|
||||
|
||||
since: 3.0.11
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note left of Helper::getNamespace
|
||||
Gets the component namespace if set
|
||||
|
||||
since: 3.0.11
|
||||
return: ?string
|
||||
end note
|
||||
|
||||
note right of Helper::getManifest
|
||||
Gets the component abstract helper class
|
||||
|
||||
since: 3.0.11
|
||||
return: ?object
|
||||
end note
|
||||
|
||||
note left of Helper::methodExists
|
||||
Check if the helper class of this component has a method
|
||||
|
||||
since: 3.0.11
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of Helper::_
|
||||
Check if the helper class of this component has a method, and call it with the arguments
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
|
||||
arguments:
|
||||
string $method
|
||||
array $arguments = []
|
||||
?string $option = null
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,288 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Utilities\Component;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\Input\Input;
|
||||
use Joomla\Registry\Registry;
|
||||
use VDM\Joomla\Utilities\String\NamespaceHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Some component helper
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
abstract class Helper
|
||||
{
|
||||
/**
|
||||
* The current option
|
||||
*
|
||||
* @var string|null
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static ?string $option = null;
|
||||
|
||||
/**
|
||||
* The component manifest list cache
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static array $manifest = [];
|
||||
|
||||
/**
|
||||
* The component params list cache
|
||||
*
|
||||
* @var Registry[]
|
||||
* @since 3.0.11
|
||||
*/
|
||||
protected static array $params = [];
|
||||
|
||||
/**
|
||||
* Gets the parameter object for the component
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
*
|
||||
* @return Registry A Registry object.
|
||||
* @see Registry
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getParams(?string $option = null): Registry
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
{
|
||||
$option = self::getOption();
|
||||
}
|
||||
|
||||
// get global value
|
||||
if (!isset(self::$params[$option]) || !self::$params[$option] instanceof Registry)
|
||||
{
|
||||
self::$params[$option] = ComponentHelper::getParams($option);
|
||||
}
|
||||
|
||||
return self::$params[$option];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the component option
|
||||
*
|
||||
* @param string|null $option The option
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function setOption(?string $option): void
|
||||
{
|
||||
self::$option = $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component option
|
||||
*
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component option
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getOption(?string $default = 'empty'): ?string
|
||||
{
|
||||
if (empty(self::$option))
|
||||
{
|
||||
// get the option from the url input
|
||||
self::$option = (new Input)->getString('option', null);
|
||||
}
|
||||
|
||||
if (empty(self::$option))
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
// Check if the getInput method exists in the application object
|
||||
if (method_exists($app, 'getInput'))
|
||||
{
|
||||
// get the option from the application
|
||||
self::$option = $app->getInput()->getCmd('option', $default);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the default value if getInput method does not exist
|
||||
self::$option = $default;
|
||||
}
|
||||
}
|
||||
|
||||
return self::$option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component code name
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component code name
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getCode(?string $option = null, ?string $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
{
|
||||
$option = self::getOption();
|
||||
}
|
||||
// option with com_
|
||||
if (is_string($option) && strpos($option, 'com_') === 0)
|
||||
{
|
||||
return strtolower(trim(substr($option, 4)));
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component abstract helper class
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component helper name
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function get(?string $option = null, ?string $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
// and get the code name from it
|
||||
if (($code_name = self::getCode($option, null)) !== null)
|
||||
{
|
||||
// we build the helper class name
|
||||
$helper_name = '\\' . \ucfirst($code_name) . 'Helper';
|
||||
|
||||
// check if class exist
|
||||
if (class_exists($helper_name))
|
||||
{
|
||||
return $helper_name;
|
||||
}
|
||||
|
||||
// try loading namespace
|
||||
if (($namespace = self::getNamespace($option)) !== null)
|
||||
{
|
||||
$name = \ucfirst($code_name) . 'Helper';
|
||||
$namespace_helper = '\\' . $namespace . '\Administrator\Helper\\' . NamespaceHelper::safeSegment($name); // TODO target site or admin locations not just admin...
|
||||
if (class_exists($namespace_helper))
|
||||
{
|
||||
return $namespace_helper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component namespace if set
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component namespace
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getNamespace(?string $option = null): ?string
|
||||
{
|
||||
$manifest = self::getManifest($option);
|
||||
|
||||
return $manifest->namespace ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component abstract helper class
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return object|null A component helper name
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getManifest(?string $option = null): ?object
|
||||
{
|
||||
if ($option === null
|
||||
&& ($option = self::getOption($option)) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// get global manifest_cache values
|
||||
if (!isset(self::$manifest[$option]))
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select($db->quoteName('manifest_cache'))
|
||||
->from($db->quoteName('#__extensions'))
|
||||
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
|
||||
->where($db->quoteName('element') . ' LIKE ' . $db->quote($option));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$manifest = $db->loadResult();
|
||||
self::$manifest[$option] = json_decode($manifest);
|
||||
} catch (\Exception $e) {
|
||||
// Handle the database error appropriately.
|
||||
self::$manifest[$option] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return self::$manifest[$option];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the helper class of this component has a method
|
||||
*
|
||||
* @param string $method The method name to search for
|
||||
* @param string|null $option The option for the component.
|
||||
*
|
||||
* @return bool true if method exist
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function methodExists(string $method, ?string $option = null): bool
|
||||
{
|
||||
// get the helper class
|
||||
return ($helper = self::get($option, null)) !== null &&
|
||||
method_exists($helper, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the helper class of this component has a method, and call it with the arguments
|
||||
*
|
||||
* @param string $method The method name to search for
|
||||
* @param array $arguments The arguments for function.
|
||||
* @param string|null $option The option for the component.
|
||||
*
|
||||
* @return mixed return whatever the method returns or null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function _(string $method, array $arguments = [], ?string $option = null)
|
||||
{
|
||||
// get the helper class
|
||||
if (($helper = self::get($option, null)) !== null &&
|
||||
method_exists($helper, $method))
|
||||
{
|
||||
// we know this is not ideal...
|
||||
// so we need to move these
|
||||
// functions to their own classes
|
||||
return call_user_func_array([$helper, $method], $arguments);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,265 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* The current option
|
||||
*
|
||||
* @var string|null
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static ?string $option = null;
|
||||
|
||||
/**
|
||||
* The component manifest list cache
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static array $manifest = [];
|
||||
|
||||
/**
|
||||
* The component params list cache
|
||||
*
|
||||
* @var Registry[]
|
||||
* @since 3.0.11
|
||||
*/
|
||||
protected static array $params = [];
|
||||
|
||||
/**
|
||||
* Gets the parameter object for the component
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
*
|
||||
* @return Registry A Registry object.
|
||||
* @see Registry
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getParams(?string $option = null): Registry
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
{
|
||||
$option = self::getOption();
|
||||
}
|
||||
|
||||
// get global value
|
||||
if (!isset(self::$params[$option]) || !self::$params[$option] instanceof Registry)
|
||||
{
|
||||
self::$params[$option] = ComponentHelper::getParams($option);
|
||||
}
|
||||
|
||||
return self::$params[$option];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the component option
|
||||
*
|
||||
* @param string|null $option The option
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function setOption(?string $option): void
|
||||
{
|
||||
self::$option = $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the component option
|
||||
*
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component option
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getOption(?string $default = 'empty'): ?string
|
||||
{
|
||||
if (empty(self::$option))
|
||||
{
|
||||
// get the option from the url input
|
||||
self::$option = (new Input)->getString('option', null);
|
||||
}
|
||||
|
||||
if (empty(self::$option))
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
// Check if the getInput method exists in the application object
|
||||
if (method_exists($app, 'getInput'))
|
||||
{
|
||||
// get the option from the application
|
||||
self::$option = $app->getInput()->getCmd('option', $default);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the default value if getInput method does not exist
|
||||
self::$option = $default;
|
||||
}
|
||||
}
|
||||
|
||||
return self::$option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component code name
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component code name
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getCode(?string $option = null, ?string $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
if (empty($option))
|
||||
{
|
||||
$option = self::getOption();
|
||||
}
|
||||
// option with com_
|
||||
if (is_string($option) && strpos($option, 'com_') === 0)
|
||||
{
|
||||
return strtolower(trim(substr($option, 4)));
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component abstract helper class
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component helper name
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function get(?string $option = null, ?string $default = null): ?string
|
||||
{
|
||||
// check that we have an option
|
||||
// and get the code name from it
|
||||
if (($code_name = self::getCode($option, null)) !== null)
|
||||
{
|
||||
// we build the helper class name
|
||||
$helper_name = '\\' . \ucfirst($code_name) . 'Helper';
|
||||
|
||||
// check if class exist
|
||||
if (class_exists($helper_name))
|
||||
{
|
||||
return $helper_name;
|
||||
}
|
||||
|
||||
// try loading namespace
|
||||
if (($namespace = self::getNamespace($option)) !== null)
|
||||
{
|
||||
$name = \ucfirst($code_name) . 'Helper';
|
||||
$namespace_helper = '\\' . $namespace . '\Administrator\Helper\\' . NamespaceHelper::safeSegment($name); // TODO target site or admin locations not just admin...
|
||||
if (class_exists($namespace_helper))
|
||||
{
|
||||
return $namespace_helper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component namespace if set
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return string|null A component namespace
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getNamespace(?string $option = null): ?string
|
||||
{
|
||||
$manifest = self::getManifest($option);
|
||||
|
||||
return $manifest->namespace ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the component abstract helper class
|
||||
*
|
||||
* @param string|null $option The option for the component.
|
||||
* @param string|null $default The default return value if none is found
|
||||
*
|
||||
* @return object|null A component helper name
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function getManifest(?string $option = null): ?object
|
||||
{
|
||||
if ($option === null
|
||||
&& ($option = self::getOption($option)) === null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// get global manifest_cache values
|
||||
if (!isset(self::$manifest[$option]))
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select($db->quoteName('manifest_cache'))
|
||||
->from($db->quoteName('#__extensions'))
|
||||
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
|
||||
->where($db->quoteName('element') . ' LIKE ' . $db->quote($option));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$manifest = $db->loadResult();
|
||||
self::$manifest[$option] = json_decode($manifest);
|
||||
} catch (\Exception $e) {
|
||||
// Handle the database error appropriately.
|
||||
self::$manifest[$option] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return self::$manifest[$option];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the helper class of this component has a method
|
||||
*
|
||||
* @param string $method The method name to search for
|
||||
* @param string|null $option The option for the component.
|
||||
*
|
||||
* @return bool true if method exist
|
||||
*
|
||||
* @since 3.0.11
|
||||
*/
|
||||
public static function methodExists(string $method, ?string $option = null): bool
|
||||
{
|
||||
// get the helper class
|
||||
return ($helper = self::get($option, null)) !== null &&
|
||||
method_exists($helper, $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the helper class of this component has a method, and call it with the arguments
|
||||
*
|
||||
* @param string $method The method name to search for
|
||||
* @param array $arguments The arguments for function.
|
||||
* @param string|null $option The option for the component.
|
||||
*
|
||||
* @return mixed return whatever the method returns or null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function _(string $method, array $arguments = [], ?string $option = null)
|
||||
{
|
||||
// get the helper class
|
||||
if (($helper = self::get($option, null)) !== null &&
|
||||
method_exists($helper, $method))
|
||||
{
|
||||
// we know this is not ideal...
|
||||
// so we need to move these
|
||||
// functions to their own classes
|
||||
return call_user_func_array([$helper, $method], $arguments);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1 +1,23 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "640b5352-fb09-425f-a26e-cd44eda03f15",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Helper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Utilities Component Helper",
|
||||
"type": "abstract class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "ce8cf834-6bac-44fb-941c-861f7e046cc0",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Utilities.Component.Helper",
|
||||
"description": "Some component helper\r\n\r\n@since 3.0.11",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 3rd September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Factory;\r\nuse Joomla\\CMS\\Component\\ComponentHelper;\r\nuse Joomla\\Input\\Input;\r\nuse Joomla\\Registry\\Registry;",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,42 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class Base64Helper (Details)
|
||||
> namespace: **VDM\Joomla\Utilities**
|
||||
```uml
|
||||
@startuml
|
||||
abstract Base64Helper #Orange {
|
||||
+ {static} open(?string $data, ?string $key = '__.o0=base64=Oo.__', ...) : ?string
|
||||
}
|
||||
|
||||
note right of Base64Helper::open
|
||||
open base64 string if stored as base64 (in JCB)
|
||||
|
||||
since: 3.2.0
|
||||
return: ?string
|
||||
|
||||
arguments:
|
||||
?string $data
|
||||
?string $key = '__.o0=base64=Oo.__'
|
||||
?string $default = 'string'
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,57 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Utilities;
|
||||
|
||||
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* The Base64 Helper
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Base64Helper
|
||||
{
|
||||
/**
|
||||
* open base64 string if stored as base64 (in JCB)
|
||||
*
|
||||
* @param string|null $data The base64 string
|
||||
* @param string|null $key We store the string with that suffix :)
|
||||
* @param string|null $default The default switch
|
||||
*
|
||||
* @return string|null The opened string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function open(?string $data, ?string $key = '__.o0=base64=Oo.__', ?string $default = 'string'): ?string
|
||||
{
|
||||
// check that we have a string
|
||||
if (StringHelper::check($data))
|
||||
{
|
||||
// check if we have a key
|
||||
if (StringHelper::check($key))
|
||||
{
|
||||
if (strpos($data, $key) !== false)
|
||||
{
|
||||
return base64_decode(str_replace($key, '', $data));
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to this, not perfect method
|
||||
if (base64_encode(base64_decode($data, true)) === $data)
|
||||
{
|
||||
return base64_decode($data);
|
||||
}
|
||||
}
|
||||
|
||||
// check if we should just return the string
|
||||
if ('string' === $default)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,39 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* open base64 string if stored as base64 (in JCB)
|
||||
*
|
||||
* @param string|null $data The base64 string
|
||||
* @param string|null $key We store the string with that suffix :)
|
||||
* @param string|null $default The default switch
|
||||
*
|
||||
* @return string|null The opened string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public static function open(?string $data, ?string $key = '__.o0=base64=Oo.__', ?string $default = 'string'): ?string
|
||||
{
|
||||
// check that we have a string
|
||||
if (StringHelper::check($data))
|
||||
{
|
||||
// check if we have a key
|
||||
if (StringHelper::check($key))
|
||||
{
|
||||
if (strpos($data, $key) !== false)
|
||||
{
|
||||
return base64_decode(str_replace($key, '', $data));
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to this, not perfect method
|
||||
if (base64_encode(base64_decode($data, true)) === $data)
|
||||
{
|
||||
return base64_decode($data);
|
||||
}
|
||||
}
|
||||
|
||||
// check if we should just return the string
|
||||
if ('string' === $default)
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
|
@ -1 +1,23 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "64a6ff6c-069c-4a11-a76b-db5e36c27690",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Base64Helper",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "Utilities Base64 Helper",
|
||||
"type": "abstract class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Utilities.Base64Helper",
|
||||
"description": "The Base64 Helper\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,85 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# interface Registryinterface (Details)
|
||||
> namespace: **VDM\Joomla\Interfaces**
|
||||
```uml
|
||||
@startuml
|
||||
interface Registryinterface #Lavender {
|
||||
+ set(string $path, mixed $value) : void
|
||||
+ add(string $path, mixed $value, ...) : void
|
||||
+ get(string $path, mixed $default = null) : mixed
|
||||
+ remove(string $path) : void
|
||||
+ exists(string $path) : bool
|
||||
+ setSeparator(?string $value) : void
|
||||
}
|
||||
|
||||
note right of Registryinterface::set
|
||||
Sets a value into the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of Registryinterface::add
|
||||
Adds content into the registry. If a key exists,
|
||||
it either appends or concatenates based on $asArray switch.
|
||||
Default is $addAsArray = false (if null) in base class.
|
||||
Override in child class allowed set class property $addAsArray = true.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
|
||||
arguments:
|
||||
string $path
|
||||
mixed $value
|
||||
?bool $asArray = null
|
||||
end note
|
||||
|
||||
note right of Registryinterface::get
|
||||
Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
end note
|
||||
|
||||
note right of Registryinterface::remove
|
||||
Removes a value (or sub-array) from the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of Registryinterface::exists
|
||||
Checks the existence of a particular location in the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of Registryinterface::setSeparator
|
||||
Sets a separator value
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,86 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* The Registry Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface Registryinterface
|
||||
{
|
||||
/**
|
||||
* Sets a value into the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(string $path, $value): void;
|
||||
|
||||
/**
|
||||
* Adds content into the registry. If a key exists,
|
||||
* it either appends or concatenates based on $asArray switch.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
* @param bool|null $asArray Determines if the new value should be treated as an array.
|
||||
* Default is $addAsArray = false (if null) in base class.
|
||||
* Override in child class allowed set class property $addAsArray = true.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function add(string $path, $value, ?bool $asArray = null): void;
|
||||
|
||||
/**
|
||||
* Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $default Optional default value, returned if the internal doesn't exist.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return mixed The value or sub-array from the storage. Null if the location doesn't exist.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $path, $default = null);
|
||||
|
||||
/**
|
||||
* Removes a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function remove(string $path): void;
|
||||
|
||||
/**
|
||||
* Checks the existence of a particular location in the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return bool True if the location exists, false otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function exists(string $path): bool;
|
||||
|
||||
/**
|
||||
* Sets a separator value
|
||||
*
|
||||
* @param string|null $value The value to set.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function setSeparator(?string $value): void;
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,71 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Sets a value into the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(string $path, $value): void;
|
||||
|
||||
/**
|
||||
* Adds content into the registry. If a key exists,
|
||||
* it either appends or concatenates based on $asArray switch.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
* @param bool|null $asArray Determines if the new value should be treated as an array.
|
||||
* Default is $addAsArray = false (if null) in base class.
|
||||
* Override in child class allowed set class property $addAsArray = true.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function add(string $path, $value, ?bool $asArray = null): void;
|
||||
|
||||
/**
|
||||
* Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $default Optional default value, returned if the internal doesn't exist.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return mixed The value or sub-array from the storage. Null if the location doesn't exist.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $path, $default = null);
|
||||
|
||||
/**
|
||||
* Removes a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function remove(string $path): void;
|
||||
|
||||
/**
|
||||
* Checks the existence of a particular location in the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return bool True if the location exists, false otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function exists(string $path): bool;
|
||||
|
||||
/**
|
||||
* Sets a separator value
|
||||
*
|
||||
* @param string|null $value The value to set.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function setSeparator(?string $value): void;
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "64e291c2-11f1-423d-a44d-837cc12cc017",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Registryinterface",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Interfaces.Registryinterface",
|
||||
"type": "interface",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Interfaces.Registryinterface",
|
||||
"description": "The Registry Interface\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,55 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class Database (Details)
|
||||
> namespace: **VDM\Joomla\Abstraction**
|
||||
```uml
|
||||
@startuml
|
||||
abstract Database #Orange {
|
||||
# $db
|
||||
# string $table
|
||||
+ __construct()
|
||||
# quote(mixed $value) : mixed
|
||||
# getTable(string $table) : string
|
||||
}
|
||||
|
||||
note right of Database::__construct
|
||||
Constructor
|
||||
|
||||
since: 3.2.0
|
||||
end note
|
||||
|
||||
note right of Database::quote
|
||||
Set a value based on data type
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
end note
|
||||
|
||||
note right of Database::getTable
|
||||
Set a table name, adding the
|
||||
core component as needed
|
||||
|
||||
since: 3.2.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,107 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Abstraction;
|
||||
|
||||
|
||||
use Joomla\CMS\Factory as JoomlaFactory;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
|
||||
|
||||
/**
|
||||
* Database
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Database
|
||||
{
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Core Component Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = JoomlaFactory::getDbo();
|
||||
|
||||
// set the component table
|
||||
$this->table = '#__' . Helper::getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value based on data type
|
||||
*
|
||||
* @param mixed $value The value to set
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function quote($value)
|
||||
{
|
||||
if ($value === null) // hmm the null does pose an issue (will keep an eye on this)
|
||||
{
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
if (is_numeric($value))
|
||||
{
|
||||
if (filter_var($value, FILTER_VALIDATE_INT))
|
||||
{
|
||||
return (int) $value;
|
||||
}
|
||||
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
|
||||
{
|
||||
return (float) $value;
|
||||
}
|
||||
}
|
||||
elseif (is_bool($value)) // not sure if this will work well (but its correct)
|
||||
{
|
||||
return $value ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
// For date and datetime values
|
||||
if ($value instanceof \DateTime)
|
||||
{
|
||||
return $this->db->quote($value->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
// For other data types, just escape it
|
||||
return $this->db->quote($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a table name, adding the
|
||||
* core component as needed
|
||||
*
|
||||
* @param string $table The table string
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getTable(string $table): string
|
||||
{
|
||||
if (strpos($table, '#__') === false)
|
||||
{
|
||||
return $this->table . '_' . $table;
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,88 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Core Component Table Name
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->db = JoomlaFactory::getDbo();
|
||||
|
||||
// set the component table
|
||||
$this->table = '#__' . Helper::getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value based on data type
|
||||
*
|
||||
* @param mixed $value The value to set
|
||||
*
|
||||
* @return mixed
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function quote($value)
|
||||
{
|
||||
if ($value === null) // hmm the null does pose an issue (will keep an eye on this)
|
||||
{
|
||||
return 'NULL';
|
||||
}
|
||||
|
||||
if (is_numeric($value))
|
||||
{
|
||||
if (filter_var($value, FILTER_VALIDATE_INT))
|
||||
{
|
||||
return (int) $value;
|
||||
}
|
||||
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
|
||||
{
|
||||
return (float) $value;
|
||||
}
|
||||
}
|
||||
elseif (is_bool($value)) // not sure if this will work well (but its correct)
|
||||
{
|
||||
return $value ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
// For date and datetime values
|
||||
if ($value instanceof \DateTime)
|
||||
{
|
||||
return $this->db->quote($value->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
// For other data types, just escape it
|
||||
return $this->db->quote($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a table name, adding the
|
||||
* core component as needed
|
||||
*
|
||||
* @param string $table The table string
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected function getTable(string $table): string
|
||||
{
|
||||
if (strpos($table, '#__') === false)
|
||||
{
|
||||
return $this->table . '_' . $table;
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
|
@ -1 +1,23 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "1",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "6cbef8f8-4813-48e3-b05a-65e1aea95171",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "Database",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Abstraction.Database",
|
||||
"type": "abstract class",
|
||||
"use_selection": {
|
||||
"use_selection0": {
|
||||
"use": "640b5352-fb09-425f-a26e-cd44eda03f15",
|
||||
"as": "default"
|
||||
}
|
||||
},
|
||||
"namespace": "VDM\\Joomla\\Abstraction.Database",
|
||||
"description": "Database\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "use Joomla\\CMS\\Factory as JoomlaFactory;",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,83 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# interface UpdateInterface (Details)
|
||||
> namespace: **VDM\Joomla\Interfaces**
|
||||
```uml
|
||||
@startuml
|
||||
interface UpdateInterface #Lavender {
|
||||
+ rows(array $data, string $key, ...) : bool
|
||||
+ items(array $data, string $key, ...) : bool
|
||||
+ row(array $data, string $key, ...) : bool
|
||||
+ item(object $data, string $key, ...) : bool
|
||||
}
|
||||
|
||||
note right of UpdateInterface::rows
|
||||
Update rows in the database (with remapping and filtering columns option)
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
array $data
|
||||
string $key
|
||||
string $table
|
||||
array $columns = []
|
||||
end note
|
||||
|
||||
note right of UpdateInterface::items
|
||||
Update items in the database (with remapping and filtering columns option)
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
array $data
|
||||
string $key
|
||||
string $table
|
||||
array $columns = []
|
||||
end note
|
||||
|
||||
note right of UpdateInterface::row
|
||||
Update row in the database
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
array $data
|
||||
string $key
|
||||
string $table
|
||||
end note
|
||||
|
||||
note right of UpdateInterface::item
|
||||
Update item in the database
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
|
||||
arguments:
|
||||
object $data
|
||||
string $key
|
||||
string $table
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,64 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Interfaces;
|
||||
|
||||
|
||||
/**
|
||||
* Database Update Interface
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
interface UpdateInterface
|
||||
{
|
||||
/**
|
||||
* Update rows in the database (with remapping and filtering columns option)
|
||||
*
|
||||
* @param array $data Dataset to update in database [array of arrays (key => value)]
|
||||
* @param string $key Dataset key column to use in updating the values in the Database
|
||||
* @param string $table The table where the data is being updated
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $data, string $key, string $table, array $columns = []): bool;
|
||||
|
||||
/**
|
||||
* Update items in the database (with remapping and filtering columns option)
|
||||
*
|
||||
* @param array $data Data to updated in database (array of objects)
|
||||
* @param string $key Dataset key column to use in updating the values in the Database
|
||||
* @param string $table The table where the data is being update
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $data, string $key, string $table, array $columns = []): bool;
|
||||
|
||||
/**
|
||||
* Update row in the database
|
||||
*
|
||||
* @param array $data Dataset to update in database (key => value)
|
||||
* @param string $key Dataset key column to use in updating the values in the Database
|
||||
* @param string $table The table where the data is being updated
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $data, string $key, string $table): bool;
|
||||
|
||||
/**
|
||||
* Update item in the database
|
||||
*
|
||||
* @param object $data Dataset to update in database (key => value)
|
||||
* @param string $key Dataset key column to use in updating the values in the Database
|
||||
* @param string $table The table where the data is being updated
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(object $data, string $key, string $table): bool;
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,49 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Update rows in the database (with remapping and filtering columns option)
|
||||
*
|
||||
* @param array $data Dataset to update in database [array of arrays (key => value)]
|
||||
* @param string $key Dataset key column to use in updating the values in the Database
|
||||
* @param string $table The table where the data is being updated
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function rows(array $data, string $key, string $table, array $columns = []): bool;
|
||||
|
||||
/**
|
||||
* Update items in the database (with remapping and filtering columns option)
|
||||
*
|
||||
* @param array $data Data to updated in database (array of objects)
|
||||
* @param string $key Dataset key column to use in updating the values in the Database
|
||||
* @param string $table The table where the data is being update
|
||||
* @param array $columns Data columns for remapping and filtering
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function items(array $data, string $key, string $table, array $columns = []): bool;
|
||||
|
||||
/**
|
||||
* Update row in the database
|
||||
*
|
||||
* @param array $data Dataset to update in database (key => value)
|
||||
* @param string $key Dataset key column to use in updating the values in the Database
|
||||
* @param string $table The table where the data is being updated
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function row(array $data, string $key, string $table): bool;
|
||||
|
||||
/**
|
||||
* Update item in the database
|
||||
*
|
||||
* @param object $data Dataset to update in database (key => value)
|
||||
* @param string $key Dataset key column to use in updating the values in the Database
|
||||
* @param string $table The table where the data is being updated
|
||||
*
|
||||
* @return bool
|
||||
* @since 3.2.0
|
||||
**/
|
||||
public function item(object $data, string $key, string $table): bool;
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "7179fde6-1e51-4b51-8545-7ca18f74a0f4",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "UpdateInterface",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Interfaces.UpdateInterface",
|
||||
"type": "interface",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Interfaces.UpdateInterface",
|
||||
"description": "Database Update Interface\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,37 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# trait ToString (Details)
|
||||
> namespace: **VDM\Joomla\Abstraction\Registry\Traits**
|
||||
```uml
|
||||
@startuml
|
||||
class ToString << (T,Orange) >> #Turquoise {
|
||||
+ toString(string $path, string $separator = '') : string
|
||||
}
|
||||
|
||||
note right of ToString::toString
|
||||
Convert an array of values to a string (or return string)
|
||||
|
||||
since: 3.2.0
|
||||
return: string
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,47 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Abstraction\Registry\Traits;
|
||||
|
||||
|
||||
/**
|
||||
* To String Values
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
trait ToString
|
||||
{
|
||||
/**
|
||||
* Convert an array of values to a string (or return string)
|
||||
*
|
||||
* @param string $path Registry path (e.g. joomla.content.showauthor)
|
||||
* @param string $seperator Return string separator
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function toString(string $path, string $separator = ''): string
|
||||
{
|
||||
// Return default value if path is empty
|
||||
if (empty($path))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// get the value
|
||||
if (($node = $this->get($path)) !== null)
|
||||
{
|
||||
if (is_array($node) && $node !== [])
|
||||
{
|
||||
return implode($separator, $node);
|
||||
}
|
||||
elseif (is_string($node) && strlen((string) $node) > 0)
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,32 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Convert an array of values to a string (or return string)
|
||||
*
|
||||
* @param string $path Registry path (e.g. joomla.content.showauthor)
|
||||
* @param string $seperator Return string separator
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function toString(string $path, string $separator = ''): string
|
||||
{
|
||||
// Return default value if path is empty
|
||||
if (empty($path))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// get the value
|
||||
if (($node = $this->get($path)) !== null)
|
||||
{
|
||||
if (is_array($node) && $node !== [])
|
||||
{
|
||||
return implode($separator, $node);
|
||||
}
|
||||
elseif (is_string($node) && strlen((string) $node) > 0)
|
||||
{
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
|
@ -1 +1,18 @@
|
|||
###POWERLINKER###
|
||||
{
|
||||
"add_head": "0",
|
||||
"add_licensing_template": "2",
|
||||
"extends": "0",
|
||||
"guid": "7d494d91-ab60-43cd-aecf-d50e07f7f30e",
|
||||
"implements": null,
|
||||
"load_selection": null,
|
||||
"name": "ToString",
|
||||
"power_version": "1.0.0",
|
||||
"system_name": "VDM.Abstraction.Registry.Traits.ToString",
|
||||
"type": "trait",
|
||||
"use_selection": null,
|
||||
"namespace": "VDM\\Joomla\\Abstraction.Registry.Traits.ToString",
|
||||
"description": "To String Values\r\n\r\n@since 3.2.0",
|
||||
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
|
||||
"head": "",
|
||||
"composer": ""
|
||||
}
|
|
@ -1 +1,95 @@
|
|||
###POWERREADME###
|
||||
```
|
||||
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
|
||||
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
|
||||
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
|
||||
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
|
||||
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
|
||||
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
|
||||
```
|
||||
# abstract class Registry (Details)
|
||||
> namespace: **VDM\Joomla\Abstraction**
|
||||
> extends: **ActiveRegistry**
|
||||
```uml
|
||||
@startuml
|
||||
abstract Registry #Orange {
|
||||
# ?string $separator
|
||||
+ set(string $path, mixed $value) : void
|
||||
+ add(string $path, mixed $value, ...) : void
|
||||
+ get(string $path, mixed $default = null) : mixed
|
||||
+ remove(string $path) : void
|
||||
+ exists(string $path) : bool
|
||||
+ setSeparator(?string $value) : void
|
||||
# getActiveKeys(string $path) : ?array
|
||||
}
|
||||
|
||||
note right of Registry::set
|
||||
Sets a value into the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of Registry::add
|
||||
Adds content into the registry. If a key exists,
|
||||
it either appends or concatenates based on $asArray switch.
|
||||
Default is $addAsArray = false (if null) in base class.
|
||||
Override in child class allowed set class property $addAsArray = true.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
|
||||
arguments:
|
||||
string $path
|
||||
mixed $value
|
||||
?bool $asArray = null
|
||||
end note
|
||||
|
||||
note right of Registry::get
|
||||
Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: mixed
|
||||
end note
|
||||
|
||||
note right of Registry::remove
|
||||
Removes a value (or sub-array) from the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of Registry::exists
|
||||
Checks the existence of a particular location in the registry using multiple keys.
|
||||
|
||||
since: 3.2.0
|
||||
return: bool
|
||||
end note
|
||||
|
||||
note right of Registry::setSeparator
|
||||
Sets a separator value
|
||||
|
||||
since: 3.2.0
|
||||
return: void
|
||||
end note
|
||||
|
||||
note right of Registry::getActiveKeys
|
||||
Get that the active keys from a path
|
||||
|
||||
since: 3.2.0
|
||||
return: ?array
|
||||
end note
|
||||
|
||||
@enduml
|
||||
```
|
||||
|
||||
---
|
||||
```
|
||||
██╗ ██████╗██████╗
|
||||
██║██╔════╝██╔══██╗
|
||||
██║██║ ██████╔╝
|
||||
██ ██║██║ ██╔══██╗
|
||||
╚█████╔╝╚██████╗██████╔╝
|
||||
╚════╝ ╚═════╝╚═════╝
|
||||
```
|
||||
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)
|
||||
|
||||
|
|
|
@ -9,4 +9,176 @@
|
|||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
###POWERCODE###
|
||||
namespace VDM\Joomla\Abstraction;
|
||||
|
||||
|
||||
use VDM\Joomla\Interfaces\Activeregistryinterface;
|
||||
use VDM\Joomla\Interfaces\Registryinterface;
|
||||
use VDM\Joomla\Abstraction\ActiveRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* VDM Basic Registry.
|
||||
*
|
||||
* Don't use this beyond 10 dimensional depth for best performance.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
abstract class Registry extends ActiveRegistry implements Activeregistryinterface, Registryinterface
|
||||
{
|
||||
/**
|
||||
* Path separator
|
||||
*
|
||||
* @var string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?string $separator = '.';
|
||||
|
||||
/**
|
||||
* Sets a value into the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(string $path, $value): void
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to set any value.");
|
||||
}
|
||||
|
||||
$this->setActive($value, ...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content into the registry. If a key exists,
|
||||
* it either appends or concatenates based on $asArray switch.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
* @param bool|null $asArray Determines if the new value should be treated as an array.
|
||||
* Default is $addAsArray = false (if null) in base class.
|
||||
* Override in child class allowed set class property $addAsArray = true.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function add(string $path, $value, ?bool $asArray = null): void
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to add any value.");
|
||||
}
|
||||
|
||||
$this->addActive($value, $asArray, ...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $default Optional default value, returned if the internal doesn't exist.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return mixed The value or sub-array from the storage. Null if the location doesn't exist.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $path, $default = null)
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to get any value.");
|
||||
}
|
||||
|
||||
return $this->getActive($default, ...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function remove(string $path): void
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to remove any value.");
|
||||
}
|
||||
|
||||
$this->removeActive(...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the existence of a particular location in the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return bool True if the location exists, false otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function exists(string $path): bool
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to check if any value exist.");
|
||||
}
|
||||
|
||||
return $this->existsActive(...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a separator value
|
||||
*
|
||||
* @param string|null $value The value to set.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function setSeparator(?string $value): void
|
||||
{
|
||||
$this->separator = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get that the active keys from a path
|
||||
*
|
||||
* @param string $path The path to determine the location registry.
|
||||
*
|
||||
* @return array|null The valid array of keys
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getActiveKeys(string $path): ?array
|
||||
{
|
||||
// empty path no allowed
|
||||
if ($path === '')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Flatten the path
|
||||
if ($this->separator === null || $this->separator === '')
|
||||
{
|
||||
return [$path];
|
||||
}
|
||||
|
||||
$keys = array_values(array_filter(explode($this->separator, $path), 'strlen'));
|
||||
|
||||
if (empty($keys))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,154 @@
|
|||
###CODEPOWER###
|
||||
/**
|
||||
* Path separator
|
||||
*
|
||||
* @var string|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected ?string $separator = '.';
|
||||
|
||||
/**
|
||||
* Sets a value into the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set(string $path, $value): void
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to set any value.");
|
||||
}
|
||||
|
||||
$this->setActive($value, ...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds content into the registry. If a key exists,
|
||||
* it either appends or concatenates based on $asArray switch.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $value Value of entry
|
||||
* @param bool|null $asArray Determines if the new value should be treated as an array.
|
||||
* Default is $addAsArray = false (if null) in base class.
|
||||
* Override in child class allowed set class property $addAsArray = true.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function add(string $path, $value, ?bool $asArray = null): void
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to add any value.");
|
||||
}
|
||||
|
||||
$this->addActive($value, $asArray, ...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
* @param mixed $default Optional default value, returned if the internal doesn't exist.
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return mixed The value or sub-array from the storage. Null if the location doesn't exist.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $path, $default = null)
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to get any value.");
|
||||
}
|
||||
|
||||
return $this->getActive($default, ...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a value (or sub-array) from the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function remove(string $path): void
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to remove any value.");
|
||||
}
|
||||
|
||||
$this->removeActive(...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the existence of a particular location in the registry using multiple keys.
|
||||
*
|
||||
* @param string $path Registry path (e.g. vdm.content.builder)
|
||||
*
|
||||
* @throws \InvalidArgumentException If any of the path values are not a number or string.
|
||||
* @return bool True if the location exists, false otherwise.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function exists(string $path): bool
|
||||
{
|
||||
if (($keys = $this->getActiveKeys($path)) === null)
|
||||
{
|
||||
throw new \InvalidArgumentException("Path must only be strings or numbers to check if any value exist.");
|
||||
}
|
||||
|
||||
return $this->existsActive(...$keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a separator value
|
||||
*
|
||||
* @param string|null $value The value to set.
|
||||
*
|
||||
* @return void
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function setSeparator(?string $value): void
|
||||
{
|
||||
$this->separator = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get that the active keys from a path
|
||||
*
|
||||
* @param string $path The path to determine the location registry.
|
||||
*
|
||||
* @return array|null The valid array of keys
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getActiveKeys(string $path): ?array
|
||||
{
|
||||
// empty path no allowed
|
||||
if ($path === '')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Flatten the path
|
||||
if ($this->separator === null || $this->separator === '')
|
||||
{
|
||||
return [$path];
|
||||
}
|
||||
|
||||
$keys = array_values(array_filter(explode($this->separator, $path), 'strlen'));
|
||||
|
||||
if (empty($keys))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue