Skip to content

Commit

Permalink
Version 0.47
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Mar 20, 2021
2 parents 2937e71 + e4e2e31 commit 17ce710
Show file tree
Hide file tree
Showing 9 changed files with 731 additions and 12 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.47 (2021-03-20)
* \+ `\DDTools\ObjectTools::convertType`:
* \+ Added [HJSON](https://hjson.github.io/) support (closes #7).
* \+ Improved detection of failed `json_decode` attempt.


## Version 0.46 (2021-03-15)
* \+ `\ddTools::updateDocument`: Added default values for the following parameters:
* \+ `$docData->editedon`: If it isn't set, it will be equal to current date-time (`time()`).
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.47 (2021-03-20)
* \+ `\DDTools\ObjectTools::convertType`:
* \+ Добавлена поддержка [HJSON](https://hjson.github.io/) (closes #7).
* \+ Улучшено обнаружение неудачной попытки `json_decode`.


## Версия 0.46 (2021-03-15)
* \+ `\ddTools::updateDocument`: Добавлены значения по умолчанию для следующих параметров:
* \+ `$docData->editedon`: Если не задан — будет равен текущей дате-времени (`time()`).
Expand Down
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A library with various tools facilitating your work.
* PHP >= 5.6
* [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1
* [PHP.libraries.phpThumb](http://phpthumb.sourceforge.net) 1.7.15-202004301145 (included)
* [PHP.libraries.hjson](https://github.com/hjson/hjson-php) 2.1 (included)


## Documentation
Expand Down Expand Up @@ -258,8 +259,10 @@ Arrays, [JSON](https://en.wikipedia.org/wiki/JSON) and [Query string](https://en
* Valid values:
* `stdClass`
* `array`
* `stringJsonObject`
* `stringJsonArray`
* `stringJsonObject` — [JSON](https://en.wikipedia.org/wiki/JSON) object
* `stringJsonArray` — [JSON](https://en.wikipedia.org/wiki/JSON) array
* `stringHjsonObject` — [HJSON](https://hjson.github.io/) object
* `stringHjsonArray` — [HJSON](https://hjson.github.io/) array
* `stringQueryFormated`
* **Required**

Expand Down Expand Up @@ -677,6 +680,36 @@ Returns:
```


##### Convert a HJSON encoded string to an object

```php
\DDTools\ObjectTools::convertType([
'object' => "{
//This is HJSON, not JSON, so we can use comments insides
keys: and values can be specified without quotes,
multilineValues:
'''
Write multiline strings with proper whitespace handling.
Starts and ends with triple quotes.
A simple syntax and easy to read.
'''
}",
'type' => 'objectStdClass'
]);
```

Returns:

```php
stdClass::__set_state(array(
'keys' => 'and values can be specified without quotes,',
'multilineValues' => 'Write multiline strings with proper whitespace handling.
Starts and ends with triple quotes.
A simple syntax and easy to read.',
))
```


#### `\DDTools\ObjectTools::extend($params)`


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.46.0",
"version": "0.47.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.46 (2021-03-15)
* @version 0.47 (2021-03-20)
*
* @see README.md
*
Expand Down
44 changes: 36 additions & 8 deletions src/ObjectTools/ObjectTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function getPropValue($params){

/**
* convertType
* @version 1.0.2 (2021-03-09)
* @version 1.1 (2021-03-20)
*
* @see README.md
*/
Expand Down Expand Up @@ -110,14 +110,42 @@ public static function convertType($params){
;

if ($isObjectJson){
try {
$result = json_decode(
$params->object,
$params->type == 'objectarray'
$result = json_decode(
$params->object,
$params->type == 'objectarray'
);

if (is_null($result)){
//Include PHP.libraries.hjson
require_once(
'hjson' .
DIRECTORY_SEPARATOR .
'HJSONException.php'
);
require_once(
'hjson' .
DIRECTORY_SEPARATOR .
'HJSONUtils.php'
);
}catch (\Exception $e){
//Flag
$isObjectJson = false;
require_once(
'hjson' .
DIRECTORY_SEPARATOR .
'HJSONParser.php'
);

try {
$hjsonParser = new \HJSON\HJSONParser();

$result = $hjsonParser->parse(
$params->object,
[
'assoc' => $params->type == 'objectarray'
]
);
}catch (\Exception $e){
//Flag
$isObjectJson = false;
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/ObjectTools/hjson/HJSONException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace HJSON;

class HJSONException extends \Exception
{
}
Loading

0 comments on commit 17ce710

Please sign in to comment.