mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Update based on feedback
This commit is contained in:
parent
d20ab50f9d
commit
f699650b5f
@ -111,9 +111,8 @@ property. The controller which does the work should be registered under the
|
|||||||
SilverStripe\Control\Director:
|
SilverStripe\Control\Director:
|
||||||
rules:
|
rules:
|
||||||
special\section:
|
special\section:
|
||||||
Controller: SpecialRouteMiddleware
|
Controller: %$SpecialRouteMiddleware
|
||||||
|
|
||||||
## API Documentation
|
## API Documentation
|
||||||
|
|
||||||
* [api:SilverStripe\Control\HTTPMiddleware]
|
* [api:SilverStripe\Control\HTTPMiddleware]
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ class Director implements TemplateGlobalProvider
|
|||||||
|
|
||||||
// Note that if a different request was previously registered, this will now be lost
|
// Note that if a different request was previously registered, this will now be lost
|
||||||
// In these cases it's better to use Kernel::nest() prior to kicking off a nested request
|
// In these cases it's better to use Kernel::nest() prior to kicking off a nested request
|
||||||
Injector::inst()->unregisterNamedObject(HTTPRequest::class, true);
|
Injector::inst()->unregisterNamedObject(HTTPRequest::class);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
@ -82,17 +82,13 @@ class TrustedProxyMiddleware implements HTTPMiddleware
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the array of headers from which to lookup the hostname
|
* Set the array of headers from which to lookup the hostname.
|
||||||
* Can also specify comma-separated list as a single string.
|
|
||||||
*
|
*
|
||||||
* @param array|string $proxyHostHeaders
|
* @param array $proxyHostHeaders
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setProxyHostHeaders($proxyHostHeaders)
|
public function setProxyHostHeaders($proxyHostHeaders)
|
||||||
{
|
{
|
||||||
if (is_string($proxyHostHeaders)) {
|
|
||||||
$proxyHostHeaders = preg_split('/ *, */', $proxyHostHeaders);
|
|
||||||
}
|
|
||||||
$this->proxyHostHeaders = $proxyHostHeaders ?: [];
|
$this->proxyHostHeaders = $proxyHostHeaders ?: [];
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -108,17 +104,13 @@ class TrustedProxyMiddleware implements HTTPMiddleware
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the array of headers from which to lookup the client IP
|
* Set the array of headers from which to lookup the client IP.
|
||||||
* Can also specify comma-separated list as a single string.
|
|
||||||
*
|
*
|
||||||
* @param array|string $proxyIPHeaders
|
* @param array $proxyIPHeaders
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setProxyIPHeaders($proxyIPHeaders)
|
public function setProxyIPHeaders($proxyIPHeaders)
|
||||||
{
|
{
|
||||||
if (is_string($proxyIPHeaders)) {
|
|
||||||
$proxyIPHeaders = preg_split('/ *, */', $proxyIPHeaders);
|
|
||||||
}
|
|
||||||
$this->proxyIPHeaders = $proxyIPHeaders ?: [];
|
$this->proxyIPHeaders = $proxyIPHeaders ?: [];
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -137,14 +129,11 @@ class TrustedProxyMiddleware implements HTTPMiddleware
|
|||||||
* Set array of headers from which to lookup the client scheme (http/https)
|
* Set array of headers from which to lookup the client scheme (http/https)
|
||||||
* Can also specify comma-separated list as a single string.
|
* Can also specify comma-separated list as a single string.
|
||||||
*
|
*
|
||||||
* @param array|string $proxySchemeHeaders
|
* @param array $proxySchemeHeaders
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setProxySchemeHeaders($proxySchemeHeaders)
|
public function setProxySchemeHeaders($proxySchemeHeaders)
|
||||||
{
|
{
|
||||||
if (is_string($proxySchemeHeaders)) {
|
|
||||||
$proxySchemeHeaders = preg_split('/ *, */', $proxySchemeHeaders);
|
|
||||||
}
|
|
||||||
$this->proxySchemeHeaders = $proxySchemeHeaders ?: [];
|
$this->proxySchemeHeaders = $proxySchemeHeaders ?: [];
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -210,7 +199,7 @@ class TrustedProxyMiddleware implements HTTPMiddleware
|
|||||||
// Validate IP address
|
// Validate IP address
|
||||||
$ip = $request->getIP();
|
$ip = $request->getIP();
|
||||||
if ($ip) {
|
if ($ip) {
|
||||||
return IPUtils::checkIP($ip, preg_split('/ *, */', $trustedIPs));
|
return IPUtils::checkIP($ip, preg_split('/\s*,\s*/', $trustedIPs));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -851,15 +851,12 @@ class Injector implements ContainerInterface
|
|||||||
* by the inject
|
* by the inject
|
||||||
*
|
*
|
||||||
* @param string $name The name to unregister
|
* @param string $name The name to unregister
|
||||||
* @param bool $flushSpecs Set to true to clear spec for this service
|
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function unregisterNamedObject($name, $flushSpecs = false)
|
public function unregisterNamedObject($name)
|
||||||
{
|
{
|
||||||
unset($this->serviceCache[$name]);
|
unset($this->serviceCache[$name]);
|
||||||
if ($flushSpecs) {
|
unset($this->specs[$name]);
|
||||||
unset($this->specs[$name]);
|
|
||||||
}
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -867,10 +864,9 @@ class Injector implements ContainerInterface
|
|||||||
* Clear out objects of one or more types that are managed by the injetor.
|
* Clear out objects of one or more types that are managed by the injetor.
|
||||||
*
|
*
|
||||||
* @param array|string $types Base class of object (not service name) to remove
|
* @param array|string $types Base class of object (not service name) to remove
|
||||||
* @param bool $flushSpecs Set to true to clear spec for this service
|
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function unregisterObjects($types, $flushSpecs = false)
|
public function unregisterObjects($types)
|
||||||
{
|
{
|
||||||
if (!is_array($types)) {
|
if (!is_array($types)) {
|
||||||
$types = [ $types ];
|
$types = [ $types ];
|
||||||
@ -884,7 +880,7 @@ class Injector implements ContainerInterface
|
|||||||
throw new InvalidArgumentException("Global unregistration is not allowed");
|
throw new InvalidArgumentException("Global unregistration is not allowed");
|
||||||
}
|
}
|
||||||
if ($object instanceof $filterClass) {
|
if ($object instanceof $filterClass) {
|
||||||
$this->unregisterNamedObject($key, $flushSpecs);
|
$this->unregisterNamedObject($key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -811,15 +811,8 @@ class InjectorTest extends SapphireTest
|
|||||||
$this->assertTrue($injector->has('NamedService'));
|
$this->assertTrue($injector->has('NamedService'));
|
||||||
$this->assertEquals($service, $injector->get('NamedService'));
|
$this->assertEquals($service, $injector->get('NamedService'));
|
||||||
|
|
||||||
// Unregister by name only: New instance of the
|
// Unregister service by name
|
||||||
// old class will be constructed
|
|
||||||
$injector->unregisterNamedObject('NamedService');
|
$injector->unregisterNamedObject('NamedService');
|
||||||
$this->assertTrue($injector->has('NamedService'));
|
|
||||||
$this->assertNotEquals($service, $injector->get(TestObject::class));
|
|
||||||
|
|
||||||
// Unregister name and spec, injector forgets about this
|
|
||||||
// service spec altogether
|
|
||||||
$injector->unregisterNamedObject('NamedService', true);
|
|
||||||
$this->assertFalse($injector->has('NamedService'));
|
$this->assertFalse($injector->has('NamedService'));
|
||||||
|
|
||||||
// Test registered with class name
|
// Test registered with class name
|
||||||
@ -827,15 +820,8 @@ class InjectorTest extends SapphireTest
|
|||||||
$this->assertTrue($injector->has(TestObject::class));
|
$this->assertTrue($injector->has(TestObject::class));
|
||||||
$this->assertEquals($service, $injector->get(TestObject::class));
|
$this->assertEquals($service, $injector->get(TestObject::class));
|
||||||
|
|
||||||
// Unregister by name only: New instance of the
|
// Unregister service by class
|
||||||
// old class will be constructed
|
|
||||||
$injector->unregisterNamedObject(TestObject::class);
|
$injector->unregisterNamedObject(TestObject::class);
|
||||||
$this->assertTrue($injector->has(TestObject::class));
|
|
||||||
$this->assertNotEquals($service, $injector->get(TestObject::class));
|
|
||||||
|
|
||||||
// Unregister name and spec, injector forgets about this
|
|
||||||
// service spec altogether
|
|
||||||
$injector->unregisterNamedObject(TestObject::class, true);
|
|
||||||
$this->assertFalse($injector->has(TestObject::class));
|
$this->assertFalse($injector->has(TestObject::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user