Skip to content

Commit

Permalink
Version 0.58
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Mar 21, 2023
2 parents 7e27f98 + 9b5b102 commit 6f76311
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# (MODX)EvolutionCMS.libraries.ddTools changelog


## Version 0.58 (2023-03-21)
* \+ `\DDTools\Base\AncestorTrait::createChildInstance` → Parameters → `$params->parentDir`: Is no longer required and by default is equal to dirname of a class that uses this trait.


## Version 0.57 (2023-03-09)
* \+ `\DDTools\ObjectTools::getPropValue` → Parameters → `$params->propName`: The method can now get the value of an object property or an array element in any nesting level. Just use `'.'` to get nested properties.
Several examples (see full examples in README):
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG_ru.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# (MODX)EvolutionCMS.libraries.ddTools changelog


## Версия 0.58 (2023-03-21)
* \+ `\DDTools\Base\AncestorTrait::createChildInstance` → Параметры → `$params->parentDir`: Больше не обязателен и по умолчанию равен папке класса, использующего этот трейт.


## Версия 0.57 (2023-03-09)
* \+ `\DDTools\ObjectTools::getPropValue` → Параметры → `$params->propName`: Теперь метод умеет получать значение свойства объекта или элемента массива на любом уровне вложенности. Просто используйте `'.'` в параметре для получения свойств вложенных элементов.
Несколько примеров (см. полные примеры в README):
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -918,11 +918,6 @@ You can see an example of how it works in the [(MODX)EvolutionCMS.snippets.ddGet
* `arrayAssociative`
* **Required**

* `$params->parentDir`
* Desctription: Directory of the parent file (e. g. `__DIR__`).
* Valid values: `string`
* **Required**

* `$params->name`
* Desctription: Class name.
* Valid values: `string`
Expand All @@ -935,6 +930,11 @@ You can see an example of how it works in the [(MODX)EvolutionCMS.snippets.ddGet
* `arrayAssociative`
* Default value: `[]`

* `$params->parentDir`
* Desctription: Directory of the parent file (e. g. `__DIR__`).
* Valid values: `string`
* Default value: — (dirname of a class that uses this trait)

* `$params->capitalizeName`
* Desctription: Need to capitalize child name?
* Valid values: `boolean`
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.57.0",
"version": "0.58.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.57 (2023-03-09)
* @version 0.58 (2023-03-21)
*
* @see README.md
*
Expand Down
29 changes: 18 additions & 11 deletions src/Base/AncestorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
trait AncestorTrait {
/**
* createChildInstance
* @version 1.1.1 (2019-08-22)
* @version 1.2 (2023-03-21)
*
* @see README.md
*
Expand All @@ -15,36 +15,43 @@ public static final function createChildInstance($params){
$params = (object) array_merge(
[
'params' => [],
'parentDir' => null,
'capitalizeName' => true
],
(array) $params
);

$thisClassName = get_called_class();
//Capitalize child name if needed
if ($params->capitalizeName){
$params->name = ucfirst(strtolower($params->name));
}

$thisClassNameFull = get_called_class();

if (empty($params->parentDir)){
$objectClassReflector = new \ReflectionClass($thisClassNameFull);

$params->parentDir = dirname($objectClassReflector->getFileName());
}

$thisNameSpace = substr(
$thisClassName,
$thisClassNameFull,
0,
strrpos(
$thisClassName,
$thisClassNameFull,
'\\'
)
);

//Current classname without namespace
$thisClassName = substr(
$thisClassName,
$thisClassNameFull,
strrpos(
$thisClassName,
$thisClassNameFull,
'\\'
) + 1
);

//Capitalize child name if needed
if ($params->capitalizeName){
$params->name = ucfirst(strtolower($params->name));
}

$filePath =
$params->parentDir .
DIRECTORY_SEPARATOR .
Expand Down

0 comments on commit 6f76311

Please sign in to comment.