Skip to content

Commit

Permalink
Merge branch '4' into 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Nov 21, 2022
2 parents 8e16b57 + ad116c6 commit a52c779
Show file tree
Hide file tree
Showing 73 changed files with 548 additions and 276 deletions.
4 changes: 0 additions & 4 deletions _config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use SilverStripe\Dev\Deprecation;
use SilverStripe\View\Shortcodes\EmbedShortcodeProvider;
use SilverStripe\View\Parsers\ShortcodeParser;

Expand All @@ -14,6 +13,3 @@

ShortcodeParser::get('default')
->register('embed', [EmbedShortcodeProvider::class, 'handle_shortcode']);

// Set to 5.0.0 to show APIs marked for removal at that version
Deprecation::notification_version('4.0.0');
4 changes: 2 additions & 2 deletions _config/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Name: basei18n
Before: '#defaulti18n'
---
SilverStripe\i18n\Data\Sources:
SilverStripe\Core\Manifest\ModuleManifest:
module_priority:
- silverstripe\admin
- silverstripe\framework
---
Name: defaulti18n
---
SilverStripe\i18n\Data\Sources:
SilverStripe\Core\Manifest\ModuleManifest:
module_priority:
- other_modules
---
Expand Down
3 changes: 0 additions & 3 deletions src/Control/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,9 @@ private function cookieIsSecure(string $sameSite, bool $secure): bool

/**
* Get the correct samesite value - Session cookies use a different configuration variable.
*
* @deprecated 4.12.0 The relevant methods will include a `$sameSite` parameter instead.
*/
private function getSameSite(string $name): string
{
Deprecation::notice('4.12.0', 'The relevant methods will include a `$sameSite` parameter instead.');
if ($name === session_name()) {
return Session::config()->get('cookie_samesite');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static function mockRequest(
? $cookies
: Injector::inst()->createWithArgs(Cookie_Backend::class, [$cookies ?: []]);
$newVars['_COOKIE'] = $cookieJar->getAll(false);
Cookie::config()->update('report_errors', false);
Cookie::config()->set('report_errors', false);
Injector::inst()->registerService($cookieJar, Cookie_Backend::class);

// Backup requirements
Expand Down
36 changes: 19 additions & 17 deletions src/Control/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static function absoluteURLs($html)
if (preg_match('/^\w+:/', $url ?? '')) {
return $url;
}
return Director::absoluteURL($url, true);
return Director::absoluteURL($url);
});
}

Expand Down Expand Up @@ -474,6 +474,8 @@ public static function add_cache_headers($response = null)
* Ensure that all deprecated HTTP cache settings are respected
*
* @deprecated 4.2.0 Use HTTPCacheControlMiddleware instead
* Simply delete this method in CMS 5 and the calls to it from HTTPCacheControlMiddleware
*
* @throws \LogicException
* @param HTTPRequest $request
* @param HTTPResponse $response
Expand All @@ -491,32 +493,32 @@ public static function augmentState(HTTPRequest $request, HTTPResponse $response

// if http caching is disabled by config, disable it - used on dev environments due to frequently changing
// templates and other data. will be overridden by forced publicCache(true) or privateCache(true) calls
if ($config->get('disable_http_cache')) {
Deprecation::notice('5.0', 'Use HTTPCacheControlMiddleware.defaultState/.defaultForcingLevel instead');
$cacheControlMiddleware->disableCache();
}
Deprecation::withNoReplacement(function () use ($config, $cacheControlMiddleware) {
if ($config->get('disable_http_cache')) {
$cacheControlMiddleware->disableCache();
}
});

// if no caching ajax requests, disable ajax if is ajax request
if (!$config->get('cache_ajax_requests') && Director::is_ajax()) {
Deprecation::notice(
'5.0',
'HTTP.cache_ajax_requests config is deprecated. Use HTTPCacheControlMiddleware::disableCache() instead'
);
$cacheControlMiddleware->disableCache();
}
Deprecation::withNoReplacement(function () use ($config, $cacheControlMiddleware) {
if (!$config->get('cache_ajax_requests') && Director::is_ajax()) {
$cacheControlMiddleware->disableCache();
}
});

// Pass vary to middleware
$configVary = $config->get('vary');
$configVary = Deprecation::withNoReplacement(function () use ($config) {
return $config->get('vary');
});
if ($configVary) {
Deprecation::notice('5.0', 'Use HTTPCacheControlMiddleware.defaultVary instead');
$cacheControlMiddleware->addVary($configVary);
}

// Pass cache_control to middleware
$configCacheControl = $config->get('cache_control');
$configCacheControl = Deprecation::withNoReplacement(function () use ($config) {
return $config->get('cache_control');
});
if ($configCacheControl) {
Deprecation::notice('5.0', 'Use HTTPCacheControlMiddleware API instead');

$supportedDirectives = ['max-age', 'no-cache', 'no-store', 'must-revalidate'];
if ($foundUnsupported = array_diff(array_keys($configCacheControl ?? []), $supportedDirectives)) {
throw new \LogicException(
Expand Down
8 changes: 6 additions & 2 deletions src/Control/Middleware/FlushMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace SilverStripe\Control\Middleware;

use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\BaseKernel;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Flushable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Kernel;

/**
* Triggers a call to flush() on all implementors of Flushable.
Expand All @@ -14,7 +16,9 @@ class FlushMiddleware implements HTTPMiddleware
{
public function process(HTTPRequest $request, callable $delegate)
{
if (Director::isManifestFlushed()) {
/** @var BaseKernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
if ((method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) {
// Disable cache when flushing
HTTPCacheControlMiddleware::singleton()->disableCache(true);

Expand Down
5 changes: 4 additions & 1 deletion src/Control/Middleware/HTTPCacheControlMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Resettable;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Dev\Deprecation;

class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable
{
Expand Down Expand Up @@ -51,7 +52,9 @@ public function process(HTTPRequest $request, callable $delegate)
$this->augmentState($request, $response);

// Update state based on deprecated HTTP settings
HTTP::augmentState($request, $response);
Deprecation::withNoReplacement(function () use ($request, $response) {
HTTP::augmentState($request, $response);
});

// Add all headers to this response object
$this->applyToResponse($response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace SilverStripe\Control\Middleware\URLSpecialsMiddleware;

use SilverStripe\Core\BaseKernel;
use SilverStripe\Core\Kernel;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Startup\ScheduledFlushDiscoverer;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;

/**
Expand All @@ -30,11 +30,12 @@ public function scheduleFlush(HTTPRequest $request)
{
$flush = array_key_exists('flush', $request->getVars() ?? []) || ($request->getURL() === 'dev/build');

if (!$flush || Director::isManifestFlushed()) {
/** @var BaseKernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
if (!$flush || (method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) {
return false;
}

$kernel = Injector::inst()->get(Kernel::class);
ScheduledFlushDiscoverer::scheduleFlush($kernel);

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Control/RSS/RSSFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function Description()
public function outputToBrowser()
{
$prevState = SSViewer::config()->uninherited('source_file_comments');
SSViewer::config()->update('source_file_comments', false);
SSViewer::config()->set('source_file_comments', false);

$response = Controller::curr()->getResponse();

Expand All @@ -236,7 +236,7 @@ public function outputToBrowser()

$response->addHeader("Content-Type", "application/rss+xml; charset=utf-8");

SSViewer::config()->update('source_file_comments', $prevState);
SSViewer::config()->set('source_file_comments', $prevState);
return $this->renderWith($this->getTemplates());
}

Expand Down
4 changes: 3 additions & 1 deletion src/Control/RequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class RequestProcessor implements HTTPMiddleware
*/
public function __construct($filters = [])
{
Deprecation::notice('4.0.1', 'Use HTTPMiddleware directly instead.', Deprecation::SCOPE_CLASS);
Deprecation::withNoReplacement(function () {
Deprecation::notice('4.0.1', 'Use HTTPMiddleware directly instead.', Deprecation::SCOPE_CLASS);
});
$this->filters = $filters;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Control/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,11 @@ public function save(HTTPRequest $request)
* Recursively apply the changes represented in $data to $dest.
* Used to update $_SESSION
*
* @deprecated 4.1.0 Use recursivelyApplyChanges() instead
* @param array $data
* @param array $dest
*/
protected function recursivelyApply($data, &$dest)
{
Deprecation::notice('4.1.0', 'Use recursivelyApplyChanges() instead');
foreach ($data as $k => $v) {
if (is_array($v)) {
if (!isset($dest[$k]) || !is_array($dest[$k])) {
Expand Down
5 changes: 4 additions & 1 deletion src/Control/SimpleResourceURLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ public function urlForResource($relativePath)
// Determine lookup mechanism based on existence of public/ folder.
// From 5.0 onwards only resolvePublicResource() will be used.
if (!Director::publicDir()) {
list($exists, $absolutePath, $relativePath) = $this->resolveUnsecuredResource($relativePath);
$ret = Deprecation::withNoReplacement(function () use ($relativePath) {
return $this->resolveUnsecuredResource($relativePath);
});
list($exists, $absolutePath, $relativePath) = $ret;
} else {
list($exists, $absolutePath, $relativePath) = $this->resolvePublicResource($relativePath);
}
Expand Down
31 changes: 24 additions & 7 deletions src/Core/BaseKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,24 @@ protected function bootPHP()
protected function bootManifests($flush)
{
// Setup autoloader
$this->getClassLoader()->init($this->getIncludeTests(), $flush);
$ignoredCIConfigs = Deprecation::withNoReplacement(function () {
return $this->getIgnoredCIConfigs();
});

Deprecation::withNoReplacement(function () use ($flush, $ignoredCIConfigs) {
$this->getClassLoader()->init(
$this->getIncludeTests(),
$flush,
$ignoredCIConfigs
);

// Find modules
$this->getModuleLoader()->init($this->getIncludeTests(), $flush);
// Find modules
$this->getModuleLoader()->init(
$this->getIncludeTests(),
$flush,
$ignoredCIConfigs
);
});

// Flush config
if ($flush) {
Expand All @@ -201,7 +215,13 @@ protected function bootManifests($flush)
$defaultSet->setProject(
ModuleManifest::config()->get('project')
);
$defaultSet->init($this->getIncludeTests(), $flush);
Deprecation::withNoReplacement(function () use ($defaultSet, $flush, $ignoredCIConfigs) {
$defaultSet->init(
$this->getIncludeTests(),
$flush,
$ignoredCIConfigs
);
});
}
}

Expand Down Expand Up @@ -247,12 +267,9 @@ protected function bootErrorHandling()
* Get the environment type
*
* @return string
*
* @deprecated 4.12.0 Use Director::get_environment_type() instead
*/
public function getEnvironment()
{
Deprecation::notice('4.12.0', 'Use Director::get_environment_type() instead');
// Check set
if ($this->enviroment) {
return $this->enviroment;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public static function json2obj($val)
/**
* Convert a JSON string into an array.
*
* @deprecated 4.4.0 Use json_decode() instead
* @deprecated 4.4.0 Use json_decode($val, true) instead
* @param string $val JSON string to convert
* @return array|boolean
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Core/Manifest/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ public function init($includeTests = false, $forceRegen = false)
foreach ($this->manifests as $manifest) {
/** @var ClassManifest $instance */
$instance = $manifest['instance'];
$instance->init($includeTests, $forceRegen);
Deprecation::withNoReplacement(function () use ($instance, $includeTests, $forceRegen, $ignoredCIConfigs) {
$instance->init($includeTests, $forceRegen, $ignoredCIConfigs);
});
}

$this->registerAutoloader();
Expand Down
4 changes: 3 additions & 1 deletion src/Core/Manifest/ClassManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ public function init($includeTests = false, $forceRegen = false)
}

// Build
$this->regenerate($includeTests);
Deprecation::withNoReplacement(function () use ($includeTests, $ignoredCIConfigs) {
$this->regenerate($includeTests, $ignoredCIConfigs);
});
}

/**
Expand Down
Loading

0 comments on commit a52c779

Please sign in to comment.