Skip to content

Commit

Permalink
Version 0.48
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Mar 26, 2021
2 parents 17ce710 + 2dbc906 commit 8c66932
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# (MODX)EvolutionCMS.libraries.ddTools changelog


## Version 0.48 (2021-03-25)
* \+ `\DDTools\Snippet`:
* \+ `$paramsTypes`: The new property. Overwrite in child classes if you want to convert some parameters types.
* \+ `prepareParams`: The parameter types will be converted respectively with `$this->paramsTypes`.


## Version 0.47 (2021-03-20)
* \+ `\DDTools\ObjectTools::convertType`:
* \+ Added [HJSON](https://hjson.github.io/) support (closes #7).
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG_ru.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# (MODX)EvolutionCMS.libraries.ddTools changelog


## Версия 0.48 (2021-03-25)
* \+ `\DDTools\Snippet`:
* \+ `$paramsTypes`: Новое свойство. Перекройте в дочерних классах если вы хотите сконвертировать типы параметров.
* \+ `prepareParams`: Типы параметров будут сконвертированы соответственно с `$this->paramsTypes`.


## Версия 0.47 (2021-03-20)
* \+ `\DDTools\ObjectTools::convertType`:
* \+ Добавлена поддержка [HJSON](https://hjson.github.io/) (closes #7).
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,26 @@ Abstract class for snippets.
* Desctription: Key is parameter name, value is value.
* Valid values: `mixed`

* `\DDTools\Snippet::$paramsTypes`
* Desctription: Overwrite in child classes if you want to convert some parameters types.
Parameters types will be converted respectively with this field in `\DDTools\Snippet::prepareParams`.
* Valid values: `arrayAssociative`
* Visibility: `protected`

* `\DDTools\Snippet::$paramsTypes[$paramName]`
* Desctription: The parameter type.
Values are case insensitive (the following names are equal: `'stringjsonauto'`, `'stringJsonAuto'`, `'STRINGJSONAUTO'`, etc).
* Valid values:
* `'integer'`
* `'boolean'`
* `'objectAuto'`
* `'objectStdClass'`
* `'objectArray'`
* `'stringJsonAuto'`
* `'stringJsonObject'`
* `'stringJsonArray'`
* Visibility: `protected`

* `\DDTools\Snippet::$renamedParamsCompliance`
* Desctription: Overwrite in child classes if you want to rename some parameters with backward compatibility (see `$params->compliance` of `\ddTools::verifyRenamedParams`).
* Valid values: `arrayAssociative`
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dd/evolutioncms-libraries-ddtools",
"type": "modxevo-library-ddtools",
"version": "0.47.0",
"version": "0.48.0",
"description": "A library with various tools facilitating your work.",
"keywords": [
"modx",
Expand Down
2 changes: 1 addition & 1 deletion modx.ddtools.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* EvolutionCMS.libraries.ddTools
* @version 0.47 (2021-03-20)
* @version 0.48 (2021-03-25)
*
* @see README.md
*
Expand Down
54 changes: 52 additions & 2 deletions src/Snippet/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ abstract class Snippet {
*/
$params = [],

/**
* @property $paramsTypes {arrayAssociative} — Overwrite in child classes if you want to convert some parameters types.
* @property $paramsTypes[$paramName] {'integer'|'boolean'|'objectAuto'|'objectStdClass'|'objectArray'|'stringJsonAuto'|'stringJsonObject'|'stringJsonArray'} — The parameter type.
*/
$paramsTypes = [],

/**
* @property $renamedParamsCompliance {arrayAssociative} — Overwrite in child classes if you want to rename some parameters with backward compatibility (see \ddTools::verifyRenamedParams).
*/
Expand Down Expand Up @@ -81,13 +87,15 @@ public function __construct($params = []){

/**
* prepareParams
* @version 1.0 (2021-03-10)
* @version 1.1 (2021-03-24)
*
* @param $params {stdClass|arrayAssociative|stringJsonObject|stringQueryFormatted}
*
* @return {void}
*/
protected function prepareParams($params = []){
$this->params = (object) $this->params;

$params = \DDTools\ObjectTools::convertType([
'object' => $params,
'type' => 'objectStdClass'
Expand All @@ -102,10 +110,52 @@ protected function prepareParams($params = []){
]);
}

if (!empty($this->paramsTypes)){
foreach (
$this->paramsTypes as
$paramName =>
$paramType
){
$paramType = strtolower($paramType);

if ($paramType == 'integer'){
$params->{$paramName} = intval($params->{$paramName});
}elseif ($paramType == 'boolean'){
$params->{$paramName} = boolval($params->{$paramName});
}else{
//Convert defaults
if (
\DDTools\ObjectTools::isPropExists([
'object' => $this->params,
'propName' => $paramName
])
){
$this->params->{$paramName} = \DDTools\ObjectTools::convertType([
'object' => $this->params->{$paramName},
'type' => $paramType
]);
}

//Convert given
if (
\DDTools\ObjectTools::isPropExists([
'object' => $params,
'propName' => $paramName
])
){
$params->{$paramName} = \DDTools\ObjectTools::convertType([
'object' => $params->{$paramName},
'type' => $paramType
]);
}
}
}
}

$this->params = \DDTools\ObjectTools::extend([
'objects' => [
//Defaults
(object) $this->params,
$this->params,
//Given parameters
$params
]
Expand Down

0 comments on commit 8c66932

Please sign in to comment.