Skip to content

Commit

Permalink
php 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Zauberfisch committed Aug 16, 2022
1 parent 023af6f commit de2899b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
],
"require": {
"php": "^7",
"php": "^7 || ^8",
"ext-json": "*",
"silverstripe/framework": "^4.5",
"silverstripe/vendor-plugin": "*"
Expand Down
58 changes: 29 additions & 29 deletions src/AbstractDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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?
Expand All @@ -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])) {
Expand All @@ -137,19 +137,19 @@ 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;
return $this;
}
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])) {
Expand All @@ -160,15 +160,15 @@ 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;
return $this;
}
throw new \Exception("Could not find field '$name'.");
}

/**
* @param array $data
* @return $this
Expand All @@ -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));
Expand All @@ -214,7 +214,7 @@ protected function i18nFields() {
}
return $fields;
}

public function fieldLabels() {
$cacheKey = get_class($this);
if (!isset(self::$_cache_field_labels[$cacheKey])) {
Expand All @@ -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) {
Expand All @@ -250,7 +250,7 @@ public function provideI18nEntities() {
}
return $entities;
}

public function __toString() {
return Serializer::serialize($this);
}
Expand Down Expand Up @@ -295,7 +295,7 @@ public function extendedCan($methodName, $member, $context = []) {
}
return null;
}

/**
* @param Member $member
* @return boolean
Expand All @@ -307,7 +307,7 @@ public function canView($member = null) {
}
return Permission::check('ADMIN', 'any', $member);
}

/**
* @param Member $member
* @return boolean
Expand All @@ -319,7 +319,7 @@ public function canEdit($member = null) {
}
return Permission::check('ADMIN', 'any', $member);
}

/**
* @param Member $member
* @return boolean
Expand All @@ -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);
Expand All @@ -346,15 +346,15 @@ 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);
$class = explode('\\', $phpClass);
$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();
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit de2899b

Please sign in to comment.