diff --git a/CHANGELOG.md b/CHANGELOG.md index 74d0686..6fbfdf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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): diff --git a/CHANGELOG_ru.md b/CHANGELOG_ru.md index 5488a54..8075c70 100644 --- a/CHANGELOG_ru.md +++ b/CHANGELOG_ru.md @@ -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): diff --git a/README.md b/README.md index 1776a9d..59e9a25 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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` diff --git a/composer.json b/composer.json index abda380..621e173 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/modx.ddtools.class.php b/modx.ddtools.class.php index 6580be9..e148f24 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -1,7 +1,7 @@ [], + '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 .