From 39140b6a5565f8953f33ae329e95c3e319fc32f9 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Sat, 17 Aug 2019 17:34:58 +0300 Subject: [PATCH 1/4] * Attention! Backward compatibility with 0.25 is broken. - \DDTools\ObjectTools. + \DDTools\BaseClass. --- require.php | 2 +- src/BaseClass/BaseClass.php | 96 ++++++++++++++++++++++++++ src/ObjectTools/ObjectTools.php | 116 -------------------------------- 3 files changed, 97 insertions(+), 117 deletions(-) create mode 100644 src/BaseClass/BaseClass.php delete mode 100644 src/ObjectTools/ObjectTools.php diff --git a/require.php b/require.php index a4085c4..a04d358 100644 --- a/require.php +++ b/require.php @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/src/BaseClass/BaseClass.php b/src/BaseClass/BaseClass.php new file mode 100644 index 0000000..a0de70b --- /dev/null +++ b/src/BaseClass/BaseClass.php @@ -0,0 +1,96 @@ + + $propValue + ){ + if (property_exists( + $this, + $propName + )){ + $this->{$propName} = $propValue; + } + } + } + + /** + * createChildInstance + * @version 1.1 (2019-08-16) + * + * @throws \Exception + * + * @param $params {array_associative|stdClass} — The object of params. @required + * @param $params->parentDir {string} — Directory of the parent file (e. g. __DIR__). @required + * @param $params->name {string} — Class name. @required + * @param $params->params {array_associative|stdClass} — Params to be passed to object constructor. Default: []. + * @param $params->capitalizeName {boolean} — Need to capitalize child name? Default: true. + * + * @return {object} + */ + public static final function createChildInstance($params){ + //Defaults + $params = (object) array_merge( + [ + 'params' => [], + 'capitalizeChildName' => true + ], + (array) $params + ); + + //Current classname without namespace + $thisClassName = substr( + __CLASS__, + strrpos( + __CLASS__, + '\\' + ) + 1 + ); + + //Capitalize child name if needed + if ($params->capitalizeName){ + $params->name = ucfirst(strtolower($params->name)); + } + + $filePath = + $params->name . + DIRECTORY_SEPARATOR . + $thisClassName . + '.php' + ; + + if(is_file($params->parentDir . DIRECTORY_SEPARATOR . $filePath)){ + require_once($filePath); + + $objectClass = + __NAMESPACE__ . + '\\' . + $params->name . + '\\' . + $thisClassName + ; + + return new $objectClass($params->params); + }else{ + throw new \Exception( + $thisClassName . ' “' . $params->name . '” not found.', + 500 + ); + } + } +} \ No newline at end of file diff --git a/src/ObjectTools/ObjectTools.php b/src/ObjectTools/ObjectTools.php deleted file mode 100644 index cc52569..0000000 --- a/src/ObjectTools/ObjectTools.php +++ /dev/null @@ -1,116 +0,0 @@ -object {object} — The object. @required - * @param $params->props {array_associative|stdClass} — The object properties. @required - * - * @return {void} - */ - public static function setExistingProps($params){ - $params = (object) $params; - - $params->props = (object) $params->props; - - foreach ( - $params->props as - $paramName => - $paramValue - ){ - if (property_exists( - $params->object, - $paramName - )){ - $params->object->{$paramName} = $paramValue; - } - } - } - - /** - * createChildInstance - * @version 1.0.1 (2019-06-23) - * - * @desc Creates an instance of the needed child class (e. g. \ddSendFeedback\Sender\Telegram\Sender). - * - * @param $params {array_associative|stdClass} — The object of params. @required - * @param $params->parentDir {string} — Directory of the parent file (e. g. __DIR__). @required - * @param $params->parentFullClassName {string} — Parent class name including namespace (e. g. __CLASS__). @required - * @param $params->childName {string} — Child name. @required - * @param $params->childParams {array_associative|stdClass} — Params to be passed to object constructor. Default: []. - * @param $params->capitalizeChildName {boolean} — Need to capitalize child name? Default: false. - * - * @throws \Exception - * - * @return {object} - */ - public static function createChildInstance($params){ - //Defaults - $params = (object) array_merge( - [ - 'childParams' => [], - 'capitalizeChildName' => false - ], - (array) $params - ); - - //Delimiter between parent class name and namespace - $parentNamespaceDelimiter = strrpos( - $params->parentFullClassName, - '\\' - ); - //Parent classname without namespace - $parentClassName = substr( - $params->parentFullClassName, - $parentNamespaceDelimiter + 1 - ); - //Parent namespace - $parentNamespace = substr( - $params->parentFullClassName, - 0, - $parentNamespaceDelimiter - ); - - //Capitalize child name if needed - if ($params->capitalizeChildName){ - $params->childName = ucfirst(strtolower($params->childName)); - } - - $childFullPath = - $params->parentDir . - DIRECTORY_SEPARATOR . - $params->childName . - DIRECTORY_SEPARATOR . - $parentClassName . '.php' - ; - - //If child exist - if(is_file($childFullPath)){ - //Iclude child - require_once($childFullPath); - - $childClass = - $parentNamespace . - '\\' . - $params->childName . - '\\' . - $parentClassName - ; - - return new $childClass($params->childParams); - }else{ - throw new \Exception( - $parentClassName . ' “' . $params->childName . '” not found.', - 500 - ); - } - } -} \ No newline at end of file From 4ec4bb15b9643bf36261fecbd12033d6d579fadd Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Wed, 21 Aug 2019 10:32:12 +0300 Subject: [PATCH 2/4] + \DDTools\BaseClass::setExistingProps: Can set private properties too. --- src/BaseClass/BaseClass.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/BaseClass/BaseClass.php b/src/BaseClass/BaseClass.php index a0de70b..463d1f0 100644 --- a/src/BaseClass/BaseClass.php +++ b/src/BaseClass/BaseClass.php @@ -4,7 +4,7 @@ class BaseClass { /** * setExistingProps - * @version 1.1 (2019-08-16) + * @version 1.2 (2019-08-21) * * @desc Sets existing object properties. * @@ -24,7 +24,19 @@ public function setExistingProps($props){ $this, $propName )){ - $this->{$propName} = $propValue; + $setProp = function( + $propName, + $propValue + ){ + $this->{$propName} = $propValue; + }; + + //Access to private properties too + $setProp->call( + $this, + $propName, + $propValue + ); } } } From 968a20aabecf3ba91e4422e91a8107ce6a5e7ab4 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Thu, 22 Aug 2019 13:12:21 +0300 Subject: [PATCH 3/4] * \DDTools\BaseClass::createChildInstance: Fixed some bugs. --- src/BaseClass/BaseClass.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/BaseClass/BaseClass.php b/src/BaseClass/BaseClass.php index 463d1f0..1abef8c 100644 --- a/src/BaseClass/BaseClass.php +++ b/src/BaseClass/BaseClass.php @@ -43,7 +43,7 @@ public function setExistingProps($props){ /** * createChildInstance - * @version 1.1 (2019-08-16) + * @version 1.1.1 (2019-08-22) * * @throws \Exception * @@ -60,16 +60,27 @@ public static final function createChildInstance($params){ $params = (object) array_merge( [ 'params' => [], - 'capitalizeChildName' => true + 'capitalizeName' => true ], (array) $params ); + $thisClassName = get_called_class(); + + $thisNameSpace = substr( + $thisClassName, + 0, + strrpos( + $thisClassName, + '\\' + ) + ); + //Current classname without namespace $thisClassName = substr( - __CLASS__, + $thisClassName, strrpos( - __CLASS__, + $thisClassName, '\\' ) + 1 ); @@ -80,17 +91,20 @@ public static final function createChildInstance($params){ } $filePath = + $params->parentDir . + DIRECTORY_SEPARATOR . $params->name . DIRECTORY_SEPARATOR . $thisClassName . '.php' ; - if(is_file($params->parentDir . DIRECTORY_SEPARATOR . $filePath)){ + if(is_file($filePath)){ require_once($filePath); $objectClass = - __NAMESPACE__ . + '\\' . + $thisNameSpace . '\\' . $params->name . '\\' . From 74e45332d14d37f40b82086253123f55976c66b7 Mon Sep 17 00:00:00 2001 From: Ilyas Ronef Date: Mon, 9 Sep 2019 11:01:06 +0300 Subject: [PATCH 4/4] Prerelease --- README.md | 7 +++++++ composer.json | 2 +- modx.ddtools.class.php | 8 +++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e6eb605..e201072 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ # (MODX)EvolutionCMS.libraries.ddTools A library with various tools facilitating your work. + + +## # Requires +* PHP >= 5.4 +* [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.0.10 +* [PHP.libraries.phpThumb](http://phpthumb.sourceforge.net) 1.7.13-201406261000 (included) + ___ Visit the following [link](http://code.divandesign.biz/modx/ddtools) to read the documentation, instructions & changelog. \ No newline at end of file diff --git a/composer.json b/composer.json index 87c1462..d1f8f7e 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "dd/modxevo-library-ddtools", "type": "modxevo-library-ddtools", - "version": "0.25.0", + "version": "0.26.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 a1d824b..1dc2bc9 100644 --- a/modx.ddtools.class.php +++ b/modx.ddtools.class.php @@ -1,13 +1,11 @@ = 5.4. - * @uses (MODX)EvolutionCMS >= 1.0.10 {@link https://github.com/evolution-cms/evolution }. - * @uses phpThumb lib 1.7.13-201406261000 (included) {@link http://phpthumb.sourceforge.net }. + * @see README.md * - * @link http://code.divandesign.biz/modx/ddtools/0.24.1 + * @link http://code.divandesign.biz/modx/ddtools * * @copyright 2012–2019 DivanDesign {@link http://www.DivanDesign.biz } */