ENH Use class name instead of self

This commit is contained in:
Steve Boyd 2024-06-14 21:46:22 +12:00
parent dec88ce497
commit d395845eb1
4 changed files with 11 additions and 11 deletions

View File

@ -136,7 +136,7 @@ abstract class DataFormatter
public static function for_extensions($extensions) public static function for_extensions($extensions)
{ {
foreach ($extensions as $extension) { foreach ($extensions as $extension) {
if ($formatter = self::for_extension($extension)) { if ($formatter = DataFormatter::for_extension($extension)) {
return $formatter; return $formatter;
} }
} }
@ -178,7 +178,7 @@ abstract class DataFormatter
public static function for_mimetypes($mimetypes) public static function for_mimetypes($mimetypes)
{ {
foreach ($mimetypes as $mimetype) { foreach ($mimetypes as $mimetype) {
if ($formatter = self::for_mimetype($mimetype)) { if ($formatter = DataFormatter::for_mimetype($mimetype)) {
return $formatter; return $formatter;
} }
} }
@ -286,7 +286,7 @@ abstract class DataFormatter
/** /**
* Returns all fields on the object which should be shown * Returns all fields on the object which should be shown
* in the output. Can be customised through {@link self::setCustomFields()}. * in the output. Can be customised through {@link DataFormatter::setCustomFields()}.
* *
* @param DataObject $obj * @param DataObject $obj
* @return array * @return array

View File

@ -89,7 +89,7 @@ class JSONDataFormatter extends DataFormatter
continue; continue;
} }
$fieldValue = self::cast($obj->obj($fieldName)); $fieldValue = JSONDataFormatter::cast($obj->obj($fieldName));
$mappedFieldName = $this->getFieldAlias($className, $fieldName); $mappedFieldName = $this->getFieldAlias($className, $fieldName);
$serobj->$mappedFieldName = $fieldValue; $serobj->$mappedFieldName = $fieldValue;
} }
@ -120,7 +120,7 @@ class JSONDataFormatter extends DataFormatter
$serobj->$relName = ArrayData::array_to_object(array( $serobj->$relName = ArrayData::array_to_object(array(
"className" => $relClass, "className" => $relClass,
"href" => "$href.json", "href" => "$href.json",
"id" => self::cast($obj->obj($fieldName)) "id" => JSONDataFormatter::cast($obj->obj($fieldName))
)); ));
} }

View File

@ -262,7 +262,7 @@ class XMLDataFormatter extends DataFormatter
*/ */
public function convertStringToArray($strData) public function convertStringToArray($strData)
{ {
return self::xml2array($strData); return XMLDataFormatter::xml2array($strData);
} }
/** /**
@ -299,7 +299,7 @@ class XMLDataFormatter extends DataFormatter
// This will throw an exception if the XML contains references to any internal entities // This will throw an exception if the XML contains references to any internal entities
// that were defined in an <!ENTITY /> before it was removed // that were defined in an <!ENTITY /> before it was removed
$xml = new SimpleXMLElement($val ?? ''); $xml = new SimpleXMLElement($val ?? '');
return self::recursiveXMLToArray($xml); return XMLDataFormatter::recursiveXMLToArray($xml);
} }
/** /**
@ -326,7 +326,7 @@ class XMLDataFormatter extends DataFormatter
} // for CDATA } // for CDATA
$r = []; $r = [];
foreach ($xml as $key => $value) { foreach ($xml as $key => $value) {
$r[$key] = self::recursiveXMLToArray($value); $r[$key] = XMLDataFormatter::recursiveXMLToArray($value);
} }
// Attributes // Attributes
if (isset($a)) { if (isset($a)) {

View File

@ -48,7 +48,7 @@ class RestfulServer extends Controller
/** /**
* If no extension is given in the request, resolve to this extension * If no extension is given in the request, resolve to this extension
* (and subsequently the {@link self::$default_mimetype}. * (and subsequently the {@link RestfulServer::$default_mimetype}.
* *
* @config * @config
* @var string * @var string
@ -362,7 +362,7 @@ class RestfulServer extends Controller
/** /**
* Returns a dataformatter instance based on the request * Returns a dataformatter instance based on the request
* extension or mimetype. Falls back to {@link self::$default_extension}. * extension or mimetype. Falls back to {@link RestfulServer::$default_extension}.
* *
* @param boolean $includeAcceptHeader Determines wether to inspect and prioritize any HTTP Accept headers * @param boolean $includeAcceptHeader Determines wether to inspect and prioritize any HTTP Accept headers
* @param string Classname of a DataObject * @param string Classname of a DataObject
@ -884,7 +884,7 @@ class RestfulServer extends Controller
protected function resolveClassName(HTTPRequest $request) protected function resolveClassName(HTTPRequest $request)
{ {
$className = $request->param('ClassName'); $className = $request->param('ClassName');
$aliases = self::config()->get('endpoint_aliases'); $aliases = static::config()->get('endpoint_aliases');
return empty($aliases[$className]) ? $this->unsanitiseClassName($className) : $aliases[$className]; return empty($aliases[$className]) ? $this->unsanitiseClassName($className) : $aliases[$className];
} }