Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Move various classes to more appropriate namespaces #11370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
68 changes: 2 additions & 66 deletions src/ORM/ArrayLib.php → src/Core/ArrayLib.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
<?php

namespace SilverStripe\ORM;
namespace SilverStripe\Core;

use Generator;
use SilverStripe\Dev\Deprecation;
use InvalidArgumentException;

/**
* Library of static methods for manipulating arrays.
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib
*/
class ArrayLib
{
public function __construct()
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib', Deprecation::SCOPE_CLASS);
});
}

/**
* Inverses the first and second level keys of an associative
* array, keying the result by the second level, and combines
Expand Down Expand Up @@ -54,14 +45,9 @@ public function __construct()
*
* @param array $arr
* @return array
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::invert()
*/
public static function invert($arr)
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::invert()');
});

if (!$arr) {
return [];
}
Expand All @@ -82,14 +68,9 @@ public static function invert($arr)
*
* @param $arr array
* @return array
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::valuekey()
*/
public static function valuekey($arr)
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::valuekey()');
});

return array_combine($arr ?? [], $arr ?? []);
}

Expand All @@ -98,14 +79,9 @@ public static function valuekey($arr)
*
* @param array $array
* @return array
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_values_recursive()
*/
public static function array_values_recursive($array)
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::invearray_values_recursivert()');
});

return ArrayLib::flatten($array, false);
}

Expand All @@ -117,14 +93,9 @@ public static function array_values_recursive($array)
* @param $keys array
*
* @return array
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::filter_keys()
*/
public static function filter_keys($arr, $keys)
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::filter_keys()');
});

foreach ($arr as $key => $v) {
if (!in_array($key, $keys ?? [])) {
unset($arr[$key]);
Expand All @@ -143,14 +114,9 @@ public static function filter_keys($arr, $keys)
* @param array $array
*
* @return boolean
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::is_associative()
*/
public static function is_associative($array)
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::is_associative()');
});

$isAssociative = !empty($array)
&& is_array($array)
&& ($array !== array_values($array ?? []));
Expand All @@ -169,14 +135,9 @@ public static function is_associative($array)
* @param boolean $strict
*
* @return boolean
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::in_array_recursive()
*/
public static function in_array_recursive($needle, $haystack, $strict = false)
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::in_array_recursive()');
});

if (!is_array($haystack)) {
return false;
}
Expand All @@ -202,14 +163,9 @@ public static function in_array_recursive($needle, $haystack, $strict = false)
* @param $f callback to apply
* @param $array array
* @return array
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_map_recursive()
*/
public static function array_map_recursive($f, $array)
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::array_map_recursive()');
});

$applyOrRecurse = function ($v) use ($f) {
return is_array($v) ? ArrayLib::array_map_recursive($f, $v) : call_user_func($f, $v);
};
Expand All @@ -228,14 +184,9 @@ public static function array_map_recursive($f, $array)
* @param array $array
*
* @return array
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::array_merge_recursive()
*/
public static function array_merge_recursive($array)
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::array_merge_recursive()');
});

$arrays = func_get_args();
$merged = [];

Expand All @@ -248,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 Expand Up @@ -278,14 +229,9 @@ public static function array_merge_recursive($array)
* @param array $out
*
* @return array
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::flatten()
*/
public static function flatten($array, $preserveKeys = true, &$out = [])
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::flatten()');
});

array_walk_recursive(
$array,
function ($value, $key) use (&$out, $preserveKeys) {
Expand All @@ -310,14 +256,9 @@ function ($value, $key) use (&$out, $preserveKeys) {
*
* @param array $list
* @return Generator
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::iterateVolatile()
*/
public static function iterateVolatile(array &$list)
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::iterateVolatile()');
});

// Keyed by already-iterated items
$iterated = [];
// Get all items not yet iterated
Expand All @@ -337,14 +278,9 @@ public static function iterateVolatile(array &$list)
/**
* Similar to shuffle, but retains the existing association between the keys and the values.
* Shuffles the array in place.
* @deprecated 5.4.0 Will be renamed to SilverStripe\Core\ArrayLib::shuffleAssociative()
*/
public static function shuffleAssociative(array &$array): void
{
Deprecation::withNoReplacement(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::shuffleAssociative()');
});

$shuffledArray = [];
$keys = array_keys($array);
shuffle($keys);
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
Loading
Loading