diff options
author | Thomas Lange <code@nerdmind.de> | 2017-05-30 21:03:03 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2017-05-30 21:03:03 +0200 |
commit | fd6af01e313f441189c4cd69668766d2ded7ced3 (patch) | |
tree | 0a0ae7cb2dd19c2a52b0799c37bb53b0e5e9e892 /core/namespace | |
parent | 1f1de386b09e48a02fccd62aa82ff319533969cc (diff) | |
download | blog-2.2.tar.gz blog-2.2.tar.xz blog-2.2.zip |
Several changes have been made in this commit, which together with the previous commits result in version 2.2 [changed template parameters]:v2.2
+ Implemented [core]: A new method called "getAll" has been added to the "Attribute" class which now returns all attributes as key->value array. The first parameter can be an array with attribute names which shall be excluded from returning.
+ Optimization [core]: The function "generateItemData" has been renamed to "generateItemTemplateData" and has been restructured to use the new implemented method "getAll" from the "Attribute" class.
+ Optimization [core]: The function "generateNaviTemplate" has been added and the functions "generatePageNaviTemplate", "generatePostNaviTemplate" and "generateUserNaviTemplate" have been restructured to make use of the new "generateNaviTemplate" function to reduce duplicate code.
+ Optimization [core]: Several files within the admin directory has been optimized to use the new "getAll" method of the "Attribute" class.
+ Optimization [core]: Several code optimizations have been made to the "HTTP" class.
+ Optimization [admin template]: All occurences of $PAGE['ID'], $POST['ID'] and $USER['ID'] have been replaced with $PAGE['ATTR']['ID'], $POST['ATTR']['ID'] and $USER['ATTR']['ID'] to make it more consistent. You now have to use ['ATTR']['ID'] instead of ['ID'] in your templates to get the ID of an item!
Template upgrade to version 2.2 (only for customized templates):
SEARCH: ['ID']
REPLACE: ['ATTR']['ID']
Diffstat (limited to 'core/namespace')
-rw-r--r-- | core/namespace/Attribute.php | 11 | ||||
-rw-r--r-- | core/namespace/HTTP.php | 67 |
2 files changed, 36 insertions, 42 deletions
diff --git a/core/namespace/Attribute.php b/core/namespace/Attribute.php index 69998e0..32cfa0a 100644 --- a/core/namespace/Attribute.php +++ b/core/namespace/Attribute.php @@ -16,6 +16,17 @@ abstract class Attribute implements AttributeInterface { } #=============================================================================== + # Get all attributes + #=============================================================================== + public function getAll($exclude = []): array { + $attributes = get_object_vars($this); + + return array_filter($attributes, function($attribute) use($exclude) { + return !in_array($attribute, $exclude); + }, ARRAY_FILTER_USE_KEY); + } + + #=============================================================================== # Get array with not FALSE attributes #=============================================================================== protected function getFilteredAttributes(): array { diff --git a/core/namespace/HTTP.php b/core/namespace/HTTP.php index bc2e062..d14b69b 100644 --- a/core/namespace/HTTP.php +++ b/core/namespace/HTTP.php @@ -81,23 +81,22 @@ class HTTP { self::$POST = $POST; self::$FILE = $FILE; - $removeArrays AND self::removeArrays(); + if($removeArrays) { + self::$GET = self::removeArrayValues(self::$GET); + self::$POST = self::removeArrayValues(self::$POST); + } self::$GET = ($trimValues === TRUE ? self::trim(self::$GET) : self::$GET ); self::$POST = ($trimValues === TRUE ? self::trim(self::$POST) : self::$POST); } #=============================================================================== - # Remove all arrays from $_GET and $_POST + # Remove all array values inside an array #=============================================================================== - private static function removeArrays() { - foreach(['GET', 'POST'] as $HTTP) { - foreach(self::$$HTTP as $name => $value) { - if(is_array(self::$$HTTP[$name])) { - unset(self::$$HTTP[$name]); - } - } - } + private static function removeArrayValues(array $array) { + return array_filter($array, function($value) { + return !is_array($value); + }); } #=============================================================================== @@ -114,7 +113,7 @@ class HTTP { #=============================================================================== # Checks if all elements of $arguments are set as key of $data #=============================================================================== - private static function issetData($data, $arguments) { + private static function issetData($data, $arguments): bool { foreach($arguments as $key) { if(is_array($key)) { if(!isset($data[key($key)]) OR $data[key($key)] !== $key[key($key)]) { @@ -131,61 +130,45 @@ class HTTP { } #=============================================================================== - # Return null or the value (if set) from one of the three requests attributes - #=============================================================================== - public static function returnKey($data, array $paths) { - $current = &$data; - - foreach($paths as $path) { - if(!isset($current[$path])) { - return NULL; - } - $current = &$current[$path]; - } - - return $current; - } - - #=============================================================================== # Return GET value #=============================================================================== - public static function GET() { - return self::returnKey(self::$GET, func_get_args()); + public static function GET($parameter) { + return self::$GET[$parameter] ?? NULL; } #=============================================================================== # Return POST value #=============================================================================== - public static function POST() { - return self::returnKey(self::$POST, func_get_args()); + public static function POST($parameter) { + return self::$POST[$parameter] ?? NULL; } #=============================================================================== # Return FILE value #=============================================================================== - public static function FILE() { - return self::returnKey(self::$FILE, func_get_args()); + public static function FILE($parameter) { + return self::$FILE[$parameter] ?? NULL; } #=============================================================================== - # Checks if all elements of func_get_args() are set key of self::$POST + # Checks if all elements of $parameters are set as key in self::$GET #=============================================================================== - public static function issetPOST() { - return self::issetData(self::$POST, func_get_args()); + public static function issetGET(... $parameters): bool { + return self::issetData(self::$GET, $parameters); } #=============================================================================== - # Checks if all elements of func_get_args() are set key of self::$GET + # Checks if all elements of $parameters are set as key in self::$POST #=============================================================================== - public static function issetGET() { - return self::issetData(self::$GET, func_get_args()); + public static function issetPOST(... $parameters): bool { + return self::issetData(self::$POST, $parameters); } #=============================================================================== - # Checks if all elements of func_get_args() are set key of self::$FILE + # Checks if all elements of $parameters are set as key in self::$FILE #=============================================================================== - public static function issetFILE() { - return self::issetData(self::$FILE, func_get_args()); + public static function issetFILE(... $parameters): bool { + return self::issetData(self::$FILE, $parameters); } #=============================================================================== |