From de2899bbe1ebe8f916d364ec5365fc30cccb1091 Mon Sep 17 00:00:00 2001 From: Zauberfisch Date: Tue, 16 Aug 2022 10:26:26 +0200 Subject: [PATCH] php 8 --- composer.json | 2 +- src/AbstractDataObject.php | 58 +++++++++++++++++++------------------- src/AbstractList.php | 2 +- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index 9afc8f9..0d013a8 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ } ], "require": { - "php": "^7", + "php": "^7 || ^8", "ext-json": "*", "silverstripe/framework": "^4.5", "silverstripe/vendor-plugin": "*" diff --git a/src/AbstractDataObject.php b/src/AbstractDataObject.php index 96757b6..919b6a4 100644 --- a/src/AbstractDataObject.php +++ b/src/AbstractDataObject.php @@ -26,27 +26,27 @@ abstract class AbstractDataObject extends ViewableData implements JsonSerializab private static $lists = []; protected $fieldsData = []; protected $listsData = []; - + use JsonSerializer { jsonSerialize as jsonSerializeTrait; } - - public function jsonSerialize() { + + public function jsonSerialize(): array { return array_merge([ 'fieldsData' => $this->fieldsData, 'listsData' => $this->listsData, ], $this->jsonSerializeTrait()); } - + public function jsonDeserialize(array $data = null) { $this->fieldsData = isset($data['fieldsData']) ? $data['fieldsData'] : []; $this->listsData = isset($data['listsData']) ? $data['listsData'] : []; } - + public function __construct() { parent::__construct(); } - + ///** // * @deprecated 4.0 Support for php serialisation will be removed in Version 4.0 // * @return string @@ -81,11 +81,11 @@ public function __construct() { // } // } //} - + public function __get($fieldName) { return $this->getField($fieldName); } - + public function __set($fieldName, $value) { return $this->setField($fieldName, $value); } @@ -102,7 +102,7 @@ public function __set($fieldName, $value) { // // } // return parent::__call($method, $arguments); // } - + public function defineMethods() { parent::defineMethods(); // TODO how to handle method name collisions? @@ -123,11 +123,11 @@ public function defineMethods() { }); } } - + public function hasField($name) { return in_array($name, static::config()->fields); } - + public function getField($name) { if ($this->hasField($name)) { if (isset($this->fieldsData[$name])) { @@ -137,7 +137,7 @@ public function getField($name) { } throw new \Exception("Could not find field '$name'."); } - + public function setField($name, $value) { if ($this->hasField($name)) { $this->fieldsData[$name] = $value; @@ -145,11 +145,11 @@ public function setField($name, $value) { } throw new \Exception("Could not find field '$name'."); } - + public function hasList($name) { return in_array($name, static::config()->lists); } - + public function getList($name) { if ($this->hasList($name)) { if (!isset($this->listsData[$name])) { @@ -160,7 +160,7 @@ public function getList($name) { } throw new \Exception("Could not find field '$name'."); } - + public function setList($name, AbstractList $value) { if ($this->hasList($name)) { $this->listsData[$name] = $value; @@ -168,7 +168,7 @@ public function setList($name, AbstractList $value) { } throw new \Exception("Could not find field '$name'."); } - + /** * @param array $data * @return $this @@ -189,9 +189,9 @@ public function update($data) { } return $this; } - + private static $_cache_field_labels = []; - + protected function i18nFields() { $fields = []; $ancestry = array_reverse(ClassInfo::ancestry($this)); @@ -214,7 +214,7 @@ protected function i18nFields() { } return $fields; } - + public function fieldLabels() { $cacheKey = get_class($this); if (!isset(self::$_cache_field_labels[$cacheKey])) { @@ -233,12 +233,12 @@ public function fieldLabels() { } return self::$_cache_field_labels[$cacheKey]; } - + public function fieldLabel($name) { $labels = $this->fieldLabels(); return (isset($labels[$name])) ? $labels[$name] : FormField::name_to_label($name); } - + public function provideI18nEntities() { $entities = []; foreach ($this->i18nFields() as $className => $types) { @@ -250,7 +250,7 @@ public function provideI18nEntities() { } return $entities; } - + public function __toString() { return Serializer::serialize($this); } @@ -295,7 +295,7 @@ public function extendedCan($methodName, $member, $context = []) { } return null; } - + /** * @param Member $member * @return boolean @@ -307,7 +307,7 @@ public function canView($member = null) { } return Permission::check('ADMIN', 'any', $member); } - + /** * @param Member $member * @return boolean @@ -319,7 +319,7 @@ public function canEdit($member = null) { } return Permission::check('ADMIN', 'any', $member); } - + /** * @param Member $member * @return boolean @@ -331,13 +331,13 @@ public function canDelete($member = null) { } return Permission::check('ADMIN', 'any', $member); } - + /** - * @todo Should canCreate be a static method? * @param Member $member * @param array $context Additional context-specific data which might * affect whether (or where) this object could be created. * @return boolean + * @todo Should canCreate be a static method? */ public function canCreate($member = null, $context = []) { $extended = $this->extendedCan(__FUNCTION__, $member, $context); @@ -346,7 +346,7 @@ public function canCreate($member = null, $context = []) { } return Permission::check('ADMIN', 'any', $member); } - + public function i18n_singular_name() { // TODO fix class name $phpClass = get_class($this); @@ -354,7 +354,7 @@ public function i18n_singular_name() { $class = $class[count($class) - 1]; return _t("{$phpClass}.SINGULARNAME", FormField::name_to_label($class)); } - + public function i18n_plural_name() { $phpClass = get_class($this); $name = $this->i18n_singular_name(); diff --git a/src/AbstractList.php b/src/AbstractList.php index ae2723d..23c19ec 100644 --- a/src/AbstractList.php +++ b/src/AbstractList.php @@ -17,7 +17,7 @@ abstract class AbstractList extends \SilverStripe\ORM\ArrayList implements JsonS jsonSerialize as jsonSerializeTrait; } - public function jsonSerialize() { + public function jsonSerialize(): array { return array_merge([ 'items' => $this->serializeItems(), ], $this->jsonSerializeTrait());