Skip to content

Commit

Permalink
API Move various classes to more appropriate namespaces
Browse files Browse the repository at this point in the history
Also rename ViewableData to ModelData ahead of the template layer
lift-and-shift
  • Loading branch information
GuySartorelli committed Sep 11, 2024
1 parent 1a53bc1 commit 37efc3a
Show file tree
Hide file tree
Showing 266 changed files with 947 additions and 812 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
"SilverStripe\\i18n\\Tests\\": "tests/php/i18n/",
"SilverStripe\\Logging\\": "src/Logging/",
"SilverStripe\\Logging\\Tests\\": "tests/php/Logging/",
"SilverStripe\\Model\\": "src/Model/",
"SilverStripe\\Model\\Tests\\": "tests/php/Model/",
"SilverStripe\\ORM\\": "src/ORM/",
"SilverStripe\\ORM\\Tests\\": "tests/php/ORM/",
"SilverStripe\\Security\\": "src/Security/",
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected function prepareResponse($response)
}
$this->setResponse($response);
} else {
// Could be Controller, or ViewableData_Customised controller wrapper
// Could be Controller, or ModelDataCustomised controller wrapper
if (ClassInfo::hasMethod($response, 'getViewer')) {
if (isset($_REQUEST['debug_request'])) {
$class = static::class;
Expand Down
14 changes: 7 additions & 7 deletions src/Control/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\View\ArrayData;
use Silverstripe\Model\ArrayData;
use SilverStripe\View\Requirements;
use SilverStripe\View\SSViewer;
use SilverStripe\View\ThemeResourceLoader;
use SilverStripe\View\ViewableData;
use SilverStripe\Model\ModelData;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email as SymfonyEmail;
Expand Down Expand Up @@ -56,9 +56,9 @@ class Email extends SymfonyEmail

/**
* Additional data available in a template.
* Used in the same way than {@link ViewableData->customize()}.
* Used in the same way than {@link ModelData->customize()}.
*/
private ViewableData $data;
private ModelData $data;

private bool $dataHasBeenSet = false;

Expand Down Expand Up @@ -194,7 +194,7 @@ public function __construct(
if ($returnPath) {
$this->setReturnPath($returnPath);
}
$this->data = ViewableData::create();
$this->data = ModelData::create();
}

private function getDefaultFrom(): string|array
Expand Down Expand Up @@ -336,7 +336,7 @@ public function addAttachmentFromData(string $data, string $name, string $mime =
* IsEmail: used to detect if rendering an email template rather than a page template
* BaseUrl: used to get the base URL for the email
*/
public function getData(): ViewableData
public function getData(): ModelData
{
$extraData = [
'IsEmail' => true,
Expand All @@ -357,7 +357,7 @@ public function getData(): ViewableData
*
* Calling setData() once means that any content set via text()/html()/setBody() will have no effect
*/
public function setData(array|ViewableData $data)
public function setData(array|ModelData $data)
{
if (is_array($data)) {
$data = ArrayData::create($data);
Expand Down
2 changes: 1 addition & 1 deletion src/Control/HTTPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use BadMethodCallException;
use InvalidArgumentException;
use SilverStripe\Core\ClassInfo;
use SilverStripe\ORM\ArrayLib;
use SilverStripe\Core\ArrayLib;

/**
* Represents a HTTP-request, including a URL that is tokenised for parsing, and a request method
Expand Down
8 changes: 4 additions & 4 deletions src/Control/RSS/RSSFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
namespace SilverStripe\Control\RSS;

use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Model\List\SS_List;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Core\Convert;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTP;
use SilverStripe\View\Requirements;
use SilverStripe\View\SSViewer;
use SilverStripe\View\ViewableData;
use SilverStripe\Model\ModelData;

/**
* RSSFeed class
*
* This class is used to create an RSS feed.
*/
class RSSFeed extends ViewableData
class RSSFeed extends ModelData
{

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Control/RSS/RSSFeed_Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SilverStripe\Control\Director;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\View\ViewableData;
use SilverStripe\Model\ModelData;
use BadMethodCallException;

/**
Expand All @@ -15,7 +15,7 @@
*
* @see RSSFeed
*/
class RSSFeed_Entry extends ViewableData
class RSSFeed_Entry extends ModelData
{
/**
* Name of the title field of feed entries
Expand All @@ -40,7 +40,7 @@ class RSSFeed_Entry extends ViewableData

/**
* Create a new RSSFeed entry.
* @param ViewableData $entry
* @param ModelData $entry
* @param string $titleField
* @param string $descriptionField
* @param string $authorField
Expand Down
10 changes: 5 additions & 5 deletions src/Control/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionFailureException;
use SilverStripe\Security\Security;
use SilverStripe\View\ViewableData;
use SilverStripe\Model\ModelData;

/**
* This class is the base class of any SilverStripe object that can be used to handle HTTP requests.
Expand Down Expand Up @@ -45,7 +45,7 @@
*
* {@link RequestHandler::handleRequest()} is where this behaviour is implemented.
*/
class RequestHandler extends ViewableData
class RequestHandler extends ModelData
{

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ public function __construct()
/**
* Handles URL requests.
*
* - ViewableData::handleRequest() iterates through each rule in {@link RequestHandler::$url_handlers}.
* - ModelData::handleRequest() iterates through each rule in {@link RequestHandler::$url_handlers}.
* - If the rule matches, the named method will be called.
* - If there is still more URL to be processed, then handleRequest()
* is called on the object that that method returns.
Expand Down Expand Up @@ -248,8 +248,8 @@ protected function findAction($request)
{
$handlerClass = static::class;

// We stop after RequestHandler; in other words, at ViewableData
while ($handlerClass && $handlerClass != ViewableData::class) {
// We stop after RequestHandler; in other words, at ModelData
while ($handlerClass && $handlerClass != ModelData::class) {
$urlHandlers = Config::inst()->get($handlerClass, 'url_handlers', Config::UNINHERITED);

if ($urlHandlers) {
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/ArrayLib.php → src/Core/ArrayLib.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\ORM;
namespace SilverStripe\Core;

use Generator;

Expand Down Expand Up @@ -199,7 +199,7 @@ public static function array_merge_recursive($array)

if (!is_array($array)) {
trigger_error(
'SilverStripe\ORM\ArrayLib::array_merge_recursive() encountered a non array argument',
'SilverStripe\Core\ArrayLib::array_merge_recursive() encountered a non array argument',
E_USER_WARNING
);
return [];
Expand Down
4 changes: 2 additions & 2 deletions src/Core/ClassInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use SilverStripe\Core\Manifest\ClassLoader;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\View\ViewableData;
use SilverStripe\Model\ModelData;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Core\Flushable;
use SilverStripe\Core\Injector\Injector;
Expand Down Expand Up @@ -585,7 +585,7 @@ public static function classesWithExtension(

// only keep classes with the Extension applied
$classes = array_filter($classes ?? [], function ($class) use ($extensionClass) {
return ViewableData::has_extension($class, $extensionClass);
return ModelData::has_extension($class, $extensionClass);
});

return $classes;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* html: HTML source suitable for use in a page or email
* text: Plain-text content, suitable for display to a user as-is, or insertion in a plaintext email.
*
* Objects of type {@link ViewableData} can have an "escaping type",
* Objects of type {@link ModelData} can have an "escaping type",
* which determines if they are automatically escaped before output by {@link SSViewer}.
*/
class Convert
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Extensible.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use InvalidArgumentException;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\View\ViewableData;
use SilverStripe\Model\ModelData;

/**
* Allows an object to have extensions applied to it.
Expand Down Expand Up @@ -43,7 +43,7 @@ trait Extensible
* @var array
*/
private static $unextendable_classes = [
ViewableData::class,
ModelData::class,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Validation/ConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SilverStripe\Core\Validation;

use InvalidArgumentException;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\Core\Validation\ValidationResult;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\Validation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\ORM;
namespace SilverStripe\Core\Validation;

use Exception;
use InvalidArgumentException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\ORM;
namespace SilverStripe\Core\Validation;

use InvalidArgumentException;
use SilverStripe\Core\Injector\Injectable;
Expand Down
4 changes: 2 additions & 2 deletions src/Dev/BulkLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Environment;
use SilverStripe\ORM\DataObject;
use SilverStripe\View\ViewableData;
use SilverStripe\Model\ModelData;

/**
* A base for bulk loaders of content into the SilverStripe database.
Expand All @@ -16,7 +16,7 @@
* @see http://tools.ietf.org/html/rfc4180
* @author Ingo Schommer, Silverstripe Ltd. (<firstname>@silverstripe.com)
*/
abstract class BulkLoader extends ViewableData
abstract class BulkLoader extends ModelData
{
private bool $checkPermissions = false;

Expand Down
4 changes: 2 additions & 2 deletions src/Dev/BulkLoader_Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace SilverStripe\Dev;

use SilverStripe\Core\Injector\Injectable;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Model\List\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\View\ArrayData;
use Silverstripe\Model\ArrayData;

/**
* Encapsulates the result of a {@link BulkLoader} import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\ExpectationFailedException;
use SilverStripe\Dev\TestOnly;
use SilverStripe\View\ViewableData;
use SilverStripe\Model\ModelData;
use SilverStripe\Dev\SapphireTest;

/**
* Constraint for checking if a ViewableData (e.g. ArrayData or any DataObject) contains fields matching the given
* Constraint for checking if a ModelData (e.g. ArrayData or any DataObject) contains fields matching the given
* key-value pairs.
*/
class ViewableDataContains extends Constraint implements TestOnly
class ModelDataContains extends Constraint implements TestOnly
{
/**
* @var array
*/
private $match;

/**
* ViewableDataContains constructor.
* ModelDataContains constructor.
*/
public function __construct(array $match)
{
Expand All @@ -44,7 +44,7 @@ public function __construct(array $match)
* a boolean value instead: true in case of success, false in case of a
* failure.
*
* @param ViewableData $other Value or object to evaluate.
* @param ModelData $other Value or object to evaluate.
* @param string $description Additional information about the test
* @param bool $returnResult Whether to return a result or throw an exception
*
Expand Down
8 changes: 4 additions & 4 deletions src/Dev/Constraint/SSListContains.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use PHPUnit\Framework\ExpectationFailedException;
use SilverStripe\Dev\SSListExporter;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\SS_List;
use SilverStripe\View\ViewableData;
use SilverStripe\Model\List\SS_List;
use SilverStripe\Model\ModelData;

/**
* Constraint for checking if a SS_List contains items matching the given
Expand Down Expand Up @@ -77,11 +77,11 @@ public function evaluate($other, $description = '', $returnResult = false): ?boo
return null;
}

protected function checkIfItemEvaluatesRemainingMatches(ViewableData $item): bool
protected function checkIfItemEvaluatesRemainingMatches(ModelData $item): bool
{
$success = false;
foreach ($this->matches as $key => $match) {
$constraint = new ViewableDataContains($match);
$constraint = new ModelDataContains($match);

if ($constraint->evaluate($item, '', true)) {
$success = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/Constraint/SSListContainsOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use PHPUnit\Framework\ExpectationFailedException;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\SS_List;
use SilverStripe\Model\List\SS_List;

/**
* Constraint for checking if a SS_List contains only items matching the given
Expand Down
6 changes: 3 additions & 3 deletions src/Dev/Constraint/SSListContainsOnlyMatchingItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PHPUnit\Framework\ExpectationFailedException;
use SilverStripe\Dev\SSListExporter;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\SS_List;
use SilverStripe\Model\List\SS_List;

/**
* Constraint for checking if every item in a SS_List matches a given match,
Expand All @@ -22,15 +22,15 @@ class SSListContainsOnlyMatchingItems extends Constraint implements TestOnly
protected SSListExporter $exporter;

/**
* @var ViewableDataContains
* @var ModelDataContains
*/
private $constraint;

public function __construct($match)
{
$this->exporter = new SSListExporter();

$this->constraint = new ViewableDataContains($match);
$this->constraint = new ModelDataContains($match);
$this->match = $match;
}

Expand Down
Loading

0 comments on commit 37efc3a

Please sign in to comment.