Skip to content

Commit

Permalink
Merge branch '5.2' into 5
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Core/ClassInfo.php
#	src/ORM/FieldType/DBForeignKey.php
  • Loading branch information
GuySartorelli committed Jun 20, 2024
2 parents b7e2a6e + 23c1a0f commit dcace43
Show file tree
Hide file tree
Showing 134 changed files with 802 additions and 776 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/add-prs-to-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Add new PRs to github project

on:
pull_request_target:
types:
- opened
- ready_for_review

permissions: {}

jobs:
addprtoproject:
name: Add PR to GitHub Project
# Only run on the silverstripe account
if: github.repository_owner == 'silverstripe'
runs-on: ubuntu-latest
steps:
- name: Add PR to github project
uses: silverstripe/gha-add-pr-to-project@v1
with:
app_id: ${{ vars.PROJECT_PERMISSIONS_APP_ID }}
private_key: ${{ secrets.PROJECT_PERMISSIONS_APP_PRIVATE_KEY }}
2 changes: 1 addition & 1 deletion src/Control/ContentNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static function setEnabled($enabled)
*/
public static function process(HTTPResponse $response)
{
if (!self::enabled_for($response)) {
if (!ContentNegotiator::enabled_for($response)) {
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Control/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,16 +573,16 @@ public function pushCurrent()
{
// Ensure this controller has a valid session
$this->getRequest()->getSession();
array_unshift(self::$controller_stack, $this);
array_unshift(Controller::$controller_stack, $this);
}

/**
* Pop this controller off the top of the stack.
*/
public function popCurrent()
{
if ($this === self::$controller_stack[0]) {
array_shift(self::$controller_stack);
if ($this === Controller::$controller_stack[0]) {
array_shift(Controller::$controller_stack);
} else {
$class = static::class;
user_error(
Expand Down Expand Up @@ -693,7 +693,7 @@ public static function normaliseTrailingSlash(string $url): string
}

// Normlise trailing slash
$shouldHaveTrailingSlash = self::config()->uninherited('add_trailing_slash');
$shouldHaveTrailingSlash = Controller::config()->uninherited('add_trailing_slash');
if ($shouldHaveTrailingSlash
&& !str_ends_with($url, '/')
&& !preg_match('/^(.*)\.([^\/]*)$/', Director::makeRelative($url))
Expand Down
18 changes: 9 additions & 9 deletions src/Control/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Cookie
* Must be "Strict", "Lax", or "None"
* @config
*/
private static string $default_samesite = self::SAMESITE_LAX;
private static string $default_samesite = Cookie::SAMESITE_LAX;

/**
* Fetch the current instance of the cookie backend.
Expand Down Expand Up @@ -67,7 +67,7 @@ public static function set(
$secure = false,
$httpOnly = true
) {
return self::get_inst()->set($name, $value, $expiry, $path, $domain, $secure, $httpOnly);
return Cookie::get_inst()->set($name, $value, $expiry, $path, $domain, $secure, $httpOnly);
}

/**
Expand All @@ -80,7 +80,7 @@ public static function set(
*/
public static function get($name, $includeUnsent = true)
{
return self::get_inst()->get($name, $includeUnsent);
return Cookie::get_inst()->get($name, $includeUnsent);
}

/**
Expand All @@ -92,7 +92,7 @@ public static function get($name, $includeUnsent = true)
*/
public static function get_all($includeUnsent = true)
{
return self::get_inst()->getAll($includeUnsent);
return Cookie::get_inst()->getAll($includeUnsent);
}

/**
Expand All @@ -104,7 +104,7 @@ public static function get_all($includeUnsent = true)
*/
public static function force_expiry($name, $path = null, $domain = null, $secure = false, $httpOnly = true)
{
return self::get_inst()->forceExpiry($name, $path, $domain, $secure, $httpOnly);
return Cookie::get_inst()->forceExpiry($name, $path, $domain, $secure, $httpOnly);
}

/**
Expand All @@ -116,14 +116,14 @@ public static function force_expiry($name, $path = null, $domain = null, $secure
public static function validateSameSite(string $sameSite): void
{
$validValues = [
self::SAMESITE_STRICT,
self::SAMESITE_LAX,
self::SAMESITE_NONE,
Cookie::SAMESITE_STRICT,
Cookie::SAMESITE_LAX,
Cookie::SAMESITE_NONE,
];
if (!in_array($sameSite, $validValues)) {
throw new LogicException('Cookie samesite must be "Strict", "Lax", or "None"');
}
if ($sameSite === self::SAMESITE_NONE && !Director::is_https(self::getRequest())) {
if ($sameSite === Cookie::SAMESITE_NONE && !Director::is_https(Cookie::getRequest())) {
Injector::inst()->get(LoggerInterface::class)->warning('Cookie samesite cannot be "None" for non-https requests.');
}
}
Expand Down
60 changes: 30 additions & 30 deletions src/Control/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static function mockRequest(

// Ensure URL is properly made relative.
// Example: url passed is "/ss31/my-page" (prefixed with BASE_URL), this should be changed to "my-page"
$url = self::makeRelative($url);
$url = Director::makeRelative($url);
if (strpos($url ?? '', '?') !== false) {
list($url, $getVarsEncoded) = explode('?', $url ?? '', 2);
parse_str($getVarsEncoded ?? '', $newVars['_GET']);
Expand Down Expand Up @@ -371,7 +371,7 @@ public function handleRequest(HTTPRequest $request)
*/
public static function get_current_page()
{
return self::$current_page ? self::$current_page : Controller::curr();
return Director::$current_page ? Director::$current_page : Controller::curr();
}

/**
Expand All @@ -381,7 +381,7 @@ public static function get_current_page()
*/
public static function set_current_page($page)
{
self::$current_page = $page;
Director::$current_page = $page;
}

/**
Expand All @@ -394,7 +394,7 @@ public static function set_current_page($page)
* - REQUEST - Resolve this path to the current url (i.e. behaves as though no `<base>` tag is provided in a html document)
* - ROOT - Treat this as though it was an absolute path, and append it to the protocol and hostname.
*/
public static function absoluteURL(string $url, string $relativeParent = self::BASE): string|bool
public static function absoluteURL(string $url, string $relativeParent = Director::BASE): string|bool
{
// Check if there is already a protocol given
if (preg_match('/^http(s?):\/\//', $url ?? '')) {
Expand All @@ -404,22 +404,22 @@ public static function absoluteURL(string $url, string $relativeParent = self::B
// Absolute urls without protocol are added
// E.g. //google.com -> http://google.com
if (strpos($url ?? '', '//') === 0) {
return Controller::normaliseTrailingSlash(self::protocol() . substr($url ?? '', 2));
return Controller::normaliseTrailingSlash(Director::protocol() . substr($url ?? '', 2));
}

// Determine method for mapping the parent to this relative url
if ($relativeParent === self::ROOT || self::is_root_relative_url($url)) {
if ($relativeParent === Director::ROOT || Director::is_root_relative_url($url)) {
// Root relative urls always should be evaluated relative to the root
$parent = self::protocolAndHost();
} elseif ($relativeParent === self::REQUEST) {
$parent = Director::protocolAndHost();
} elseif ($relativeParent === Director::REQUEST) {
// Request relative urls rely on the REQUEST_URI param (old default behaviour)
if (!isset($_SERVER['REQUEST_URI'])) {
return false;
}
$parent = dirname($_SERVER['REQUEST_URI'] . 'x');
} else {
// Default to respecting site base_url
$parent = self::absoluteBaseURL();
$parent = Director::absoluteBaseURL();
}

// Map empty urls to relative slash and join to base
Expand Down Expand Up @@ -489,7 +489,7 @@ protected static function validateUserAndPass($url)
public static function host(HTTPRequest $request = null)
{
// Check if overridden by alternate_base_url
if ($baseURL = self::config()->get('alternate_base_url')) {
if ($baseURL = static::config()->get('alternate_base_url')) {
$baseURL = Injector::inst()->convertServiceProperty($baseURL);
$host = static::parseHost($baseURL);
if ($host) {
Expand All @@ -508,7 +508,7 @@ public static function host(HTTPRequest $request = null)
}

// Check base url
if ($baseURL = self::config()->uninherited('default_base_url')) {
if ($baseURL = static::config()->uninherited('default_base_url')) {
$baseURL = Injector::inst()->convertServiceProperty($baseURL);
$host = static::parseHost($baseURL);
if ($host) {
Expand Down Expand Up @@ -566,7 +566,7 @@ public static function protocolAndHost(HTTPRequest $request = null)
*/
public static function protocol(HTTPRequest $request = null)
{
return (self::is_https($request)) ? 'https://' : 'http://';
return (Director::is_https($request)) ? 'https://' : 'http://';
}

/**
Expand All @@ -578,7 +578,7 @@ public static function protocol(HTTPRequest $request = null)
public static function is_https(HTTPRequest $request = null)
{
// Check override from alternate_base_url
if ($baseURL = self::config()->uninherited('alternate_base_url')) {
if ($baseURL = static::config()->uninherited('alternate_base_url')) {
$baseURL = Injector::inst()->convertServiceProperty($baseURL);
$protocol = parse_url($baseURL ?? '', PHP_URL_SCHEME);
if ($protocol) {
Expand All @@ -593,7 +593,7 @@ public static function is_https(HTTPRequest $request = null)
}

// Check default_base_url
if ($baseURL = self::config()->uninherited('default_base_url')) {
if ($baseURL = static::config()->uninherited('default_base_url')) {
$baseURL = Injector::inst()->convertServiceProperty($baseURL);
$protocol = parse_url($baseURL ?? '', PHP_URL_SCHEME);
if ($protocol) {
Expand All @@ -612,7 +612,7 @@ public static function is_https(HTTPRequest $request = null)
public static function baseURL()
{
// Check override base_url
$alternate = self::config()->get('alternate_base_url');
$alternate = static::config()->get('alternate_base_url');
if ($alternate) {
$alternate = Injector::inst()->convertServiceProperty($alternate);
return rtrim(parse_url($alternate ?? '', PHP_URL_PATH) ?? '', '/') . '/';
Expand Down Expand Up @@ -659,8 +659,8 @@ public static function publicDir()
*/
public static function publicFolder()
{
$folder = self::baseFolder();
$publicDir = self::publicDir();
$folder = Director::baseFolder();
$publicDir = Director::publicDir();
if ($publicDir) {
return Path::join($folder, $publicDir);
}
Expand Down Expand Up @@ -694,7 +694,7 @@ public static function makeRelative($url)
}

// Remove base folder or url
foreach ([self::publicFolder(), self::baseFolder(), self::baseURL()] as $base) {
foreach ([Director::publicFolder(), Director::baseFolder(), Director::baseURL()] as $base) {
// Ensure single / doesn't break comparison (unless it would make base empty)
$base = rtrim($base ?? '', '\\/') ?: $base;
if (stripos($url ?? '', $base ?? '') === 0) {
Expand Down Expand Up @@ -827,7 +827,7 @@ public static function is_site_url($url)
}

// Relative urls always are site urls
return self::is_relative_url($url);
return Director::is_relative_url($url);
}

/**
Expand All @@ -840,20 +840,20 @@ public static function is_site_url($url)
public static function getAbsFile($file)
{
// If already absolute
if (self::is_absolute($file)) {
if (Director::is_absolute($file)) {
return $file;
}

// If path is relative to public folder search there first
if (self::publicDir()) {
$path = Path::join(self::publicFolder(), $file);
if (Director::publicDir()) {
$path = Path::join(Director::publicFolder(), $file);
if (file_exists($path ?? '')) {
return $path;
}
}

// Default to base folder
return Path::join(self::baseFolder(), $file);
return Path::join(Director::baseFolder(), $file);
}

/**
Expand All @@ -877,9 +877,9 @@ public static function fileExists($file)
*/
public static function absoluteBaseURL()
{
$baseURL = self::absoluteURL(
self::baseURL(),
self::ROOT
$baseURL = Director::absoluteURL(
Director::baseURL(),
Director::ROOT
);
return Controller::normaliseTrailingSlash($baseURL);
}
Expand Down Expand Up @@ -986,7 +986,7 @@ public static function forceWWW(HTTPRequest $request = null)
*/
public static function is_ajax(HTTPRequest $request = null)
{
$request = self::currentRequest($request);
$request = Director::currentRequest($request);
if ($request) {
return $request->isAjax();
}
Expand Down Expand Up @@ -1054,7 +1054,7 @@ public static function get_session_environment_type(HTTPRequest $request = null)
*/
public static function isLive()
{
return self::get_environment_type() === 'live';
return Director::get_environment_type() === 'live';
}

/**
Expand All @@ -1065,7 +1065,7 @@ public static function isLive()
*/
public static function isDev()
{
return self::get_environment_type() === 'dev';
return Director::get_environment_type() === 'dev';
}

/**
Expand All @@ -1076,7 +1076,7 @@ public static function isDev()
*/
public static function isTest()
{
return self::get_environment_type() === 'test';
return Director::get_environment_type() === 'test';
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Control/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ private static function mergeConfiguredAddresses(string $configKey, string $envK
{
$addresses = [];
$config = (array) static::config()->get($configKey);
$addresses = self::convertConfigToAddreses($config);
$addresses = Email::convertConfigToAddreses($config);
$env = Environment::getEnv($envKey);
if ($env) {
$addresses = array_merge($addresses, self::convertConfigToAddreses($env));
$addresses = array_merge($addresses, Email::convertConfigToAddreses($env));
}
return $addresses;
}
Expand Down Expand Up @@ -403,7 +403,7 @@ public function getHTMLTemplate(): string
}

return ThemeResourceLoader::inst()->findTemplate(
SSViewer::get_templates_by_class(static::class, '', self::class),
SSViewer::get_templates_by_class(static::class, '', Email::class),
SSViewer::get_themes()
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Control/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public static function setGetVar($varname, $varvalue, $currentURL = null, $separ
*/
public static function RAW_setGetVar($varname, $varvalue, $currentURL = null)
{
$url = self::setGetVar($varname, $varvalue, $currentURL);
$url = HTTP::setGetVar($varname, $varvalue, $currentURL);
return Convert::xml2raw($url);
}

Expand Down Expand Up @@ -268,7 +268,7 @@ public static function findByTagAndAttribute($content, $attributes)
*/
public static function getLinksIn($content)
{
return self::findByTagAndAttribute($content, ["a" => "href"]);
return HTTP::findByTagAndAttribute($content, ["a" => "href"]);
}

/**
Expand All @@ -278,7 +278,7 @@ public static function getLinksIn($content)
*/
public static function getImagesIn($content)
{
return self::findByTagAndAttribute($content, ["img" => "src"]);
return HTTP::findByTagAndAttribute($content, ["img" => "src"]);
}

/**
Expand Down
Loading

0 comments on commit dcace43

Please sign in to comment.