Skip to content

Commit

Permalink
Merge branch '5' into feature-5-trailing-slash-config-and-redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
xini committed Oct 25, 2022
2 parents 60fc9aa + e11216d commit ba80f36
Show file tree
Hide file tree
Showing 103 changed files with 1,354 additions and 2,617 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Requires a [`silverstripe-installer`](https://github.com/silverstripe/silverstri

## Installation ##

See [installation on different platforms](https://doc.silverstripe.org/framework/en/installation/),
and [installation from source](https://doc.silverstripe.org/framework/en/installation/from-source).
See [getting started](https://docs.silverstripe.org/en/4/getting_started/),
for instructions on how to start the installation process.

## Bugtracker ##

Expand Down
12 changes: 0 additions & 12 deletions _config/email.yml

This file was deleted.

28 changes: 28 additions & 0 deletions _config/mailer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
Name: mailer
---
SilverStripe\Core\Injector\Injector:
Symfony\Component\Mailer\MailerInterface:
class: Symfony\Component\Mailer\Mailer
constructor:
transport: '%$Symfony\Component\Mailer\Transport\TransportInterface'
Symfony\Component\EventDispatcher\EventDispatcherInterface.mailer:
class: Symfony\Component\EventDispatcher\EventDispatcher
calls:
- [addSubscriber, ['%$SilverStripe\Control\Email\MailerSubscriber']]
Symfony\Component\Mailer\Transport\TransportInterface:
factory: Symfony\Component\Mailer\Transport
factory_method: fromDsn
constructor:
dsn: 'sendmail://default'
dispatcher: '%$Symfony\Component\EventDispatcher\EventDispatcherInterface.mailer'
---
Name: mailer-dsn-env
After: '*'
Only:
envvarset: MAILER_DSN
---
SilverStripe\Core\Injector\Injector:
Symfony\Component\Mailer\Transport\TransportInterface:
constructor:
dsn: '`MAILER_DSN`'
20 changes: 8 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@
"require": {
"php": "^8.1",
"bramus/monolog-colored-line-formatter": "^2.0.3",
"composer/installers": "^2.1.1",
"guzzlehttp/guzzle": "^7.4.5",
"composer/installers": "^2.2",
"guzzlehttp/guzzle": "^7.5.0",
"guzzlehttp/psr7": "^2.4.0",
"embed/embed": "^4.4.4",
"league/csv": "^9.8.0",
"m1/env": "^2.2.0",
"monolog/monolog": "^1.27.1",
"nikic/php-parser": "^4.14.0",
"psr/container": "^1.1.2",
"monolog/monolog": "^3.2.0",
"nikic/php-parser": "^4.15.0",
"psr/container": "^2.0",
"silverstripe/config": "^2",
"silverstripe/assets": "^2",
"silverstripe/vendor-plugin": "^2",
"sminnee/callbacklist": "^0.1.1",
"swiftmailer/swiftmailer": "^6.3.0",
"symfony/cache": "^6.1",
"symfony/config": "^6.1",
"symfony/filesystem": "^6.1",
"symfony/mailer": "^6.1",
"symfony/mime": "^6.1",
"symfony/translation": "^6.1",
"symfony/yaml": "^6.1",
"ext-ctype": "*",
Expand Down Expand Up @@ -96,14 +97,9 @@
},
"files": [
"src/includes/constants.php"
],
"classmap": [
"thirdparty/swiftmailer"
]
},
"include-path": [
"src/",
"src/includes/",
"thirdparty/"
],
"scripts": {
Expand All @@ -113,4 +109,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
48 changes: 18 additions & 30 deletions src/Control/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ class Controller extends RequestHandler implements TemplateGlobalProvider
* The response object that the controller returns.
*
* Set in {@link handleRequest()}.
*
* @var HTTPResponse
*/
protected $response;
protected HTTPResponse $response;

/**
* Default URL handlers.
Expand All @@ -95,6 +93,12 @@ class Controller extends RequestHandler implements TemplateGlobalProvider
'handleIndex',
];

public function __construct()
{
parent::__construct();
$this->setResponse(HTTPResponse::create());
}

/**
* If true, a trailing slash is added to the end of URLs, e.g. from {@link Controller::join_links()}
*/
Expand Down Expand Up @@ -147,12 +151,11 @@ public function doInit()
*
* Also set the URLParams
*/
public function setRequest($request)
public function setRequest(HTTPRequest $request): static
{
$return = parent::setRequest($request);
parent::setRequest($request);
$this->setURLParams($this->getRequest()->allParams());

return $return;
return $this;
}

/**
Expand Down Expand Up @@ -197,11 +200,8 @@ protected function afterHandleRequest()
* Important: If you are going to overload handleRequest,
* make sure that you start the method with $this->beforeHandleRequest()
* and end the method with $this->afterHandleRequest()
*
* @param HTTPRequest $request
* @return HTTPResponse
*/
public function handleRequest(HTTPRequest $request)
public function handleRequest(HTTPRequest $request): HTTPResponse
{
if (!$request) {
throw new \RuntimeException('Controller::handleRequest() not passed a request!');
Expand Down Expand Up @@ -337,14 +337,9 @@ public function getURLParams()
/**
* Returns the HTTPResponse object that this controller is building up. Can be used to set the
* status code and headers.
*
* @return HTTPResponse
*/
public function getResponse()
public function getResponse(): HTTPResponse
{
if (!$this->response) {
$this->setResponse(new HTTPResponse());
}
return $this->response;
}

Expand Down Expand Up @@ -538,15 +533,11 @@ public function render($params = null)
* called before Controller::init(). That is, you must call it in your controller's init method
* before it calls parent::init().
*
* @deprecated 4.1.0:5.0.0 Add this controller's url to
* SilverStripe\Security\BasicAuthMiddleware.URLPatterns injected property instead of setting false
* @deprecated 4.1.0 Add this controller's url to SilverStripe\Security\BasicAuthMiddleware.URLPatterns injected property instead
*/
public function disableBasicAuth()
{
Deprecation::notice(
'5.0',
'Add this controller\'s url to ' . BasicAuthMiddleware::class . '.URLPatterns injected property instead'
);
Deprecation::notice('4.1.0', 'Add this controller\'s url to SilverStripe\Security\BasicAuthMiddleware.URLPatterns injected property instead');
$this->basicAuthEnabled = false;
}

Expand Down Expand Up @@ -633,17 +624,14 @@ public function popCurrent()

/**
* Redirect to the given URL.
*
* @param string $url
* @param int $code
* @return HTTPResponse
*/
public function redirect($url, $code = 302)
public function redirect(string $url, int $code = 302): HTTPResponse
{
if ($this->getResponse()->getHeader('Location') && $this->getResponse()->getHeader('Location') != $url) {
$response = $this->getResponse();
if ($response->getHeader('Location') && $response->getHeader('Location') != $url) {
user_error("Already directed to " . $this->getResponse()->getHeader('Location')
. "; now trying to direct to $url", E_USER_WARNING);
return null;
return $response;
}
$response = parent::redirect($url, $code);
$this->setResponse($response);
Expand Down
4 changes: 3 additions & 1 deletion src/Control/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Control;

use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBDatetime;
use LogicException;

Expand Down Expand Up @@ -200,10 +201,11 @@ private function cookieIsSecure(string $sameSite, bool $secure): bool
/**
* Get the correct samesite value - Session cookies use a different configuration variable.
*
* @deprecated 5.0 The relevant methods will include a `$sameSite` parameter instead.
* @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
3 changes: 2 additions & 1 deletion src/Control/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,11 @@ public function handleRequest(HTTPRequest $request)
*
* @return bool
*
* @deprecated 5.0 Kernel::isFlushed to be used instead
* @deprecated 4.12.0 Use Kernel::isFlushed instead
*/
public static function isManifestFlushed()
{
Deprecation::notice('4.12.0', 'Use Kernel::isFlushed instead');
$kernel = Injector::inst()->get(Kernel::class);

// Only CoreKernel implements this method at the moment
Expand Down
Loading

0 comments on commit ba80f36

Please sign in to comment.