Update based on feedback

This commit is contained in:
Damian Mooyman 2017-06-27 10:19:51 +12:00
parent d20ab50f9d
commit f699650b5f
5 changed files with 14 additions and 44 deletions

View File

@ -111,9 +111,8 @@ property. The controller which does the work should be registered under the
SilverStripe\Control\Director:
rules:
special\section:
Controller: SpecialRouteMiddleware
Controller: %$SpecialRouteMiddleware
## API Documentation
* [api:SilverStripe\Control\HTTPMiddleware]

View File

@ -372,7 +372,7 @@ class Director implements TemplateGlobalProvider
// 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
Injector::inst()->unregisterNamedObject(HTTPRequest::class, true);
Injector::inst()->unregisterNamedObject(HTTPRequest::class);
return $response;
}

View File

@ -82,17 +82,13 @@ class TrustedProxyMiddleware implements HTTPMiddleware
}
/**
* Set the array of headers from which to lookup the hostname
* Can also specify comma-separated list as a single string.
* Set the array of headers from which to lookup the hostname.
*
* @param array|string $proxyHostHeaders
* @param array $proxyHostHeaders
* @return $this
*/
public function setProxyHostHeaders($proxyHostHeaders)
{
if (is_string($proxyHostHeaders)) {
$proxyHostHeaders = preg_split('/ *, */', $proxyHostHeaders);
}
$this->proxyHostHeaders = $proxyHostHeaders ?: [];
return $this;
}
@ -108,17 +104,13 @@ class TrustedProxyMiddleware implements HTTPMiddleware
}
/**
* Set the array of headers from which to lookup the client IP
* Can also specify comma-separated list as a single string.
* Set the array of headers from which to lookup the client IP.
*
* @param array|string $proxyIPHeaders
* @param array $proxyIPHeaders
* @return $this
*/
public function setProxyIPHeaders($proxyIPHeaders)
{
if (is_string($proxyIPHeaders)) {
$proxyIPHeaders = preg_split('/ *, */', $proxyIPHeaders);
}
$this->proxyIPHeaders = $proxyIPHeaders ?: [];
return $this;
}
@ -137,14 +129,11 @@ class TrustedProxyMiddleware implements HTTPMiddleware
* Set array of headers from which to lookup the client scheme (http/https)
* Can also specify comma-separated list as a single string.
*
* @param array|string $proxySchemeHeaders
* @param array $proxySchemeHeaders
* @return $this
*/
public function setProxySchemeHeaders($proxySchemeHeaders)
{
if (is_string($proxySchemeHeaders)) {
$proxySchemeHeaders = preg_split('/ *, */', $proxySchemeHeaders);
}
$this->proxySchemeHeaders = $proxySchemeHeaders ?: [];
return $this;
}
@ -210,7 +199,7 @@ class TrustedProxyMiddleware implements HTTPMiddleware
// Validate IP address
$ip = $request->getIP();
if ($ip) {
return IPUtils::checkIP($ip, preg_split('/ *, */', $trustedIPs));
return IPUtils::checkIP($ip, preg_split('/\s*,\s*/', $trustedIPs));
}
return false;

View File

@ -851,15 +851,12 @@ class Injector implements ContainerInterface
* by the inject
*
* @param string $name The name to unregister
* @param bool $flushSpecs Set to true to clear spec for this service
* @return $this
*/
public function unregisterNamedObject($name, $flushSpecs = false)
public function unregisterNamedObject($name)
{
unset($this->serviceCache[$name]);
if ($flushSpecs) {
unset($this->specs[$name]);
}
unset($this->specs[$name]);
return $this;
}
@ -867,10 +864,9 @@ class Injector implements ContainerInterface
* 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 bool $flushSpecs Set to true to clear spec for this service
* @return $this
*/
public function unregisterObjects($types, $flushSpecs = false)
public function unregisterObjects($types)
{
if (!is_array($types)) {
$types = [ $types ];
@ -884,7 +880,7 @@ class Injector implements ContainerInterface
throw new InvalidArgumentException("Global unregistration is not allowed");
}
if ($object instanceof $filterClass) {
$this->unregisterNamedObject($key, $flushSpecs);
$this->unregisterNamedObject($key);
break;
}
}

View File

@ -811,15 +811,8 @@ class InjectorTest extends SapphireTest
$this->assertTrue($injector->has('NamedService'));
$this->assertEquals($service, $injector->get('NamedService'));
// Unregister by name only: New instance of the
// old class will be constructed
// Unregister service by name
$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'));
// Test registered with class name
@ -827,15 +820,8 @@ class InjectorTest extends SapphireTest
$this->assertTrue($injector->has(TestObject::class));
$this->assertEquals($service, $injector->get(TestObject::class));
// Unregister by name only: New instance of the
// old class will be constructed
// Unregister service by 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));
}