mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
API Strong typing for the view layer (#2994)
This commit is contained in:
parent
48c64e310b
commit
b40269c3c8
@ -401,11 +401,8 @@ class VirtualPage extends Page
|
||||
|
||||
/**
|
||||
* Use the target page's class name for fetching templates - as we need to take on its appearance
|
||||
*
|
||||
* @param string $suffix
|
||||
* @return array
|
||||
*/
|
||||
public function getViewerTemplates($suffix = '')
|
||||
public function getViewerTemplates(string $suffix = ''): array
|
||||
{
|
||||
$copy = $this->CopyContentFrom();
|
||||
if ($copy && $copy->exists()) {
|
||||
@ -418,11 +415,8 @@ class VirtualPage extends Page
|
||||
/**
|
||||
* Allow attributes on the master page to pass
|
||||
* through to the virtual page
|
||||
*
|
||||
* @param string $field
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($field)
|
||||
public function __get(string $field): mixed
|
||||
{
|
||||
if (parent::hasMethod($funcName = "get$field")) {
|
||||
return $this->$funcName();
|
||||
@ -436,7 +430,7 @@ class VirtualPage extends Page
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getField($field)
|
||||
public function getField(string $field): mixed
|
||||
{
|
||||
if ($this->isFieldVirtualised($field)) {
|
||||
return $this->CopyContentFrom()->getField($field);
|
||||
@ -484,17 +478,13 @@ class VirtualPage extends Page
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @return bool
|
||||
*/
|
||||
public function hasField($field)
|
||||
public function hasField(string $fieldName): bool
|
||||
{
|
||||
if (parent::hasField($field)) {
|
||||
if (parent::hasField($fieldName)) {
|
||||
return true;
|
||||
}
|
||||
$copy = $this->CopyContentFrom();
|
||||
return $copy && $copy->exists() && $copy->hasField($field);
|
||||
return $copy && $copy->exists() && $copy->hasField($fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -513,11 +503,8 @@ class VirtualPage extends Page
|
||||
/**
|
||||
* Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field
|
||||
* on this object.
|
||||
*
|
||||
* @param string $field
|
||||
* @return string|null
|
||||
*/
|
||||
public function castingHelper($field, bool $useFallback = true)
|
||||
public function castingHelper(string $field, bool $useFallback = true): ?string
|
||||
{
|
||||
$copy = $this->CopyContentFrom();
|
||||
if ($copy && $copy->exists() && ($helper = $copy->castingHelper($field, $useFallback))) {
|
||||
|
@ -29,7 +29,6 @@ class VirtualPageTest extends FunctionalTest
|
||||
VirtualPageTest_NotRoot::class,
|
||||
VirtualPageTest_PageExtension::class,
|
||||
VirtualPageTest_PageWithAllowedChildren::class,
|
||||
VirtualPageTest_TestDBField::class,
|
||||
VirtualPageTest_VirtualPageSub::class,
|
||||
];
|
||||
|
||||
|
@ -7,7 +7,7 @@ use SilverStripe\ORM\FieldType\DBVarchar;
|
||||
|
||||
class VirtualPageTest_TestDBField extends DBVarchar implements TestOnly
|
||||
{
|
||||
public function forTemplate()
|
||||
public function forTemplate(): string
|
||||
{
|
||||
return strtoupper($this->XML() ?? '');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user