Skip to content

Commit

Permalink
Version 0.26
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronef committed Sep 9, 2019
2 parents 63a37d3 + 74e4533 commit ac39253
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 123 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 3 additions & 5 deletions modx.ddtools.class.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php
/**
* EvolutionCMS.libraries.ddTools
* @version 0.25 (2019-06-27)
* @version 0.26 (2019-09-09)
*
* @uses PHP >= 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 }
*/
Expand Down
2 changes: 1 addition & 1 deletion require.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require_once('src/ObjectTools/ObjectTools.php');
require_once('src/BaseClass/BaseClass.php');
require_once('src/FilesTools/FilesTools.php');
require_once('src/Response.php');
?>
122 changes: 122 additions & 0 deletions src/BaseClass/BaseClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php
namespace DDTools;

class BaseClass {
/**
* setExistingProps
* @version 1.2 (2019-08-21)
*
* @desc Sets existing object properties.
*
* @param $params {array_associative|stdClass} — The object properties. @required
*
* @return {void}
*/
public function setExistingProps($props){
$props = (object) $props;

foreach (
$props as
$propName =>
$propValue
){
if (property_exists(
$this,
$propName
)){
$setProp = function(
$propName,
$propValue
){
$this->{$propName} = $propValue;
};

//Access to private properties too
$setProp->call(
$this,
$propName,
$propValue
);
}
}
}

/**
* createChildInstance
* @version 1.1.1 (2019-08-22)
*
* @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' => [],
'capitalizeName' => true
],
(array) $params
);

$thisClassName = get_called_class();

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

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

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

$filePath =
$params->parentDir .
DIRECTORY_SEPARATOR .
$params->name .
DIRECTORY_SEPARATOR .
$thisClassName .
'.php'
;

if(is_file($filePath)){
require_once($filePath);

$objectClass =
'\\' .
$thisNameSpace .
'\\' .
$params->name .
'\\' .
$thisClassName
;

return new $objectClass($params->params);
}else{
throw new \Exception(
$thisClassName . '' . $params->name . '” not found.',
500
);
}
}
}
116 changes: 0 additions & 116 deletions src/ObjectTools/ObjectTools.php

This file was deleted.

0 comments on commit ac39253

Please sign in to comment.