Skip to content

Use short array syntax #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/cache-invalidator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Invalidate a URL with added header(s)::

$cacheInvalidator->invalidatePath(
'http://www.example.com/users',
array('Cookie' => 'foo=bar; fizz=bang')
['Cookie' => 'foo=bar; fizz=bang']
)->flush();

.. include:: includes/custom-headers.rst
Expand All @@ -75,7 +75,7 @@ Refresh a URL with added header(s)::

$cacheInvalidator->refreshPath(
'http://www.example.com/users',
array('Cookie' => 'foo=bar; fizz=bang')
['Cookie' => 'foo=bar; fizz=bang']
)->flush();

.. include:: includes/custom-headers.rst
Expand Down Expand Up @@ -105,7 +105,7 @@ caching proxy::
To invalidate all ``.png`` files on host example.com::

$cacheInvalidator
->invalidateRegex('.*', 'image/png', array('example.com'))
->invalidateRegex('.*', 'image/png', ['example.com'])
->flush()
;

Expand All @@ -124,7 +124,7 @@ default headers always present to simplify the cache configuration rules.

To invalidate on a custom header ``X-My-Header``, you would do::

$cacheInvalidator->invalidate(array('X-My-Header' => 'my-value'))->flush();
$cacheInvalidator->invalidate(['X-My-Header' => 'my-value'])->flush();

.. _flush:

Expand Down
4 changes: 2 additions & 2 deletions doc/invalidation-handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ With tags you can group related representations so it becomes easier to
invalidate them. You will have to make sure your web application adds the
correct tags on all responses. You can add tags to the handler using::

$tagHandler->addTags(array('tag-two', 'group-a'));
$tagHandler->addTags(['tag-two', 'group-a']);

Before any content is sent out, you need to send the tag header_::

Expand Down Expand Up @@ -67,7 +67,7 @@ Assume you sent four responses:

You can now invalidate some URLs using tags::

$tagHandler->invalidateTags(array('group-a', 'tag-four'));
$tagHandler->invalidateTags(['group-a', 'tag-four']);

This will ban all requests having either the tag ``group-a`` /or/ ``tag-four``.
In the above example, this will invalidate ``/two``, ``/three`` and ``/four``.
Expand Down
14 changes: 7 additions & 7 deletions doc/proxy-clients.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Varnish runs on if it is not port 80::

use FOS\HttpCache\ProxyClient\Varnish;

$servers = array('10.0.0.1', '10.0.0.2:6081'); // Port 80 assumed for 10.0.0.1
$servers = ['10.0.0.1', '10.0.0.2:6081']; // Port 80 assumed for 10.0.0.1
$varnish = new Varnish($servers);

This is sufficient for invalidating absolute URLs. If you also wish to
Expand All @@ -102,7 +102,7 @@ NGINX runs on if it is not the default::

use FOS\HttpCache\ProxyClient\Nginx;

$servers = array('10.0.0.1', '10.0.0.2:8088'); // Port 80 assumed for 10.0.0.1
$servers = ['10.0.0.1', '10.0.0.2:8088']; // Port 80 assumed for 10.0.0.1
$nginx = new Nginx($servers);

This is sufficient for invalidating absolute URLs. If you also wish to
Expand Down Expand Up @@ -134,7 +134,7 @@ the web server runs on if it is not the default::

use FOS\HttpCache\ProxyClient\Symfony;

$servers = array('10.0.0.1', '10.0.0.2:8088'); // Port 80 assumed for 10.0.0.1
$servers = ['10.0.0.1', '10.0.0.2:8088']; // Port 80 assumed for 10.0.0.1
$client = new Symfony($servers);

This is sufficient for invalidating absolute URLs. If you also wish to
Expand Down Expand Up @@ -193,7 +193,7 @@ You can specify HTTP headers as the second argument to ``purge()``.
For instance::

$client
->purge('/some/path', array('X-Foo' => 'bar')
->purge('/some/path', ['X-Foo' => 'bar'])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some syntax errors here. 😉

->flush()
;

Expand Down Expand Up @@ -221,7 +221,7 @@ You can specify HTTP headers as the second argument to ``refresh()``. For
instance, to only refresh the JSON representation of an URL::

$client
->refresh('/some/path', array('Accept' => 'application/json')
->refresh('/some/path', ['Accept' => 'application/json'])
->flush()
;

Expand Down Expand Up @@ -256,11 +256,11 @@ Varnish client::

use FOS\HttpCache\ProxyClient\Varnish;

$varnish->ban(array(
$varnish->ban([
Varnish::HTTP_HEADER_URL => '.*\.png$',
Varnish::HTTP_HEADER_HOST => '.*example\.com',
Varnish::HTTP_HEADER_CACHE => 'my-tag',
));
]);

Make sure to add any headers that you want to ban on to your
:doc:`proxy configuration <proxy-configuration>`.
Expand Down
4 changes: 2 additions & 2 deletions doc/user-context.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ implement at least one ContextProvider and register that with the HashGenerator:

use FOS\HttpCache\UserContext\HashGenerator;

$hashGenerator = new HashGenerator(array(
$hashGenerator = new HashGenerator([
new IsAuthenticatedProvider(),
new RoleProvider(),
));
]);

Once all providers are registered, call ``generateHash()`` to get the hash for
the current user context.
Expand Down
12 changes: 6 additions & 6 deletions src/EventListener/LogSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public function __construct(LoggerInterface $logger)
*/
public static function getSubscribedEvents()
{
return array(
return [
Events::PROXY_UNREACHABLE_ERROR => 'onProxyUnreachableError',
Events::PROXY_RESPONSE_ERROR => 'onProxyResponseError'
);
Events::PROXY_RESPONSE_ERROR => 'onProxyResponseError',
];
}

public function onProxyUnreachableError(Event $event)
Expand All @@ -52,9 +52,9 @@ public function onProxyResponseError(Event $event)

private function log($level, \Exception $exception)
{
$context = array(
'exception' => $exception
);
$context = [
'exception' => $exception,
];

$this->logger->log($level, $exception->getMessage(), $context);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ProxyClient/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function __construct(
parent::__construct($servers, $baseUrl, $httpAdapter);

$resolver = new OptionsResolver();
$resolver->setDefaults(array(
$resolver->setDefaults([
'purge_method' => PurgeSubscriber::DEFAULT_PURGE_METHOD,
));
]);

$this->options = $resolver->resolve($options);
}
Expand Down
8 changes: 4 additions & 4 deletions src/SymfonyCache/PurgeSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public function __construct(array $options = [])
} else {
$resolver->setOptional(['purge_client_matcher', 'purge_client_ips', 'purge_method']);
}
$resolver->setDefaults(array(
$resolver->setDefaults([
'purge_client_matcher' => null,
'purge_client_ips' => null,
'purge_method' => static::DEFAULT_PURGE_METHOD,
));
]);

$this->options = $resolver->resolve($options);

Expand All @@ -74,9 +74,9 @@ public function __construct(array $options = [])
*/
public static function getSubscribedEvents()
{
return array(
return [
Events::PRE_INVALIDATE => 'handlePurge',
);
];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/SymfonyCache/RefreshSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class RefreshSubscriber extends AccessControlledSubscriber
public function __construct(array $options = [])
{
$resolver = new OptionsResolver();
$resolver->setDefaults(array(
$resolver->setDefaults([
'refresh_client_matcher' => null,
'refresh_client_ips' => null,
));
]);
$options = $resolver->resolve($options);

parent::__construct($options['refresh_client_matcher'], $options['refresh_client_ips']);
Expand All @@ -59,9 +59,9 @@ public function __construct(array $options = [])
*/
public static function getSubscribedEvents()
{
return array(
return [
Events::PRE_HANDLE => 'handleRefresh',
);
];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/SymfonyCache/UserContextSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ class UserContextSubscriber implements EventSubscriberInterface
public function __construct(array $options = [])
{
$resolver = new OptionsResolver();
$resolver->setDefaults(array(
$resolver->setDefaults([
'anonymous_hash' => '38015b703d82206ebc01d17a39c727e5',
'user_hash_accept_header' => 'application/vnd.fos.user-context-hash',
'user_hash_header' => 'X-User-Context-Hash',
'user_hash_uri' => '/_fos_user_context_hash',
'user_hash_method' => 'GET',
'session_name_prefix' => 'PHPSESSID',
));
]);

$this->options = $resolver->resolve($options);
}
Expand All @@ -76,9 +76,9 @@ public function __construct(array $options = [])
*/
public static function getSubscribedEvents()
{
return array(
return [
Events::PRE_HANDLE => 'preHandle',
);
];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Test/Proxy/NginxProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public function start()
{
$this->runCommand(
$this->getBinary(),
array(
'-c', $this->getConfigFile() ,
'-g', 'pid ' . $this->pid . ';'
)
[
'-c', $this->getConfigFile(),
'-g', 'pid ' . $this->pid . ';',
]
);

$this->waitFor($this->getIp(), $this->getPort(), 2000);
Expand Down
6 changes: 3 additions & 3 deletions src/Test/Proxy/VarnishProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function start()
{
$this->runCommand(
$this->getBinary(),
array(
[
'-a', $this->ip . ':' . $this->getPort(),
'-T', $this->ip . ':' . $this->getManagementPort(),
'-f', $this->getConfigFile(),
'-n', $this->getCacheDir(),
'-p', 'vcl_dir=' . $this->getConfigDir(),
'-P', $this->pid
)
'-P', $this->pid,
]
);

$this->waitFor($this->ip, $this->getPort(), 2000);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/CacheInvalidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public function testRefreshPath()

public function testInvalidate()
{
$headers = array(
$headers = [
'X-Header' => '^value.*$',
'Other-Header' => '^a|b|c$',
);
];

$ban = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\BanInterface')
->shouldReceive('ban')
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/SymfonyCache/EventDispatchingHttpCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ protected function getHttpCachePartialMock(array $mockedMethods = null)
;

// Force setting options property since we can't use original constructor.
$options = array(
$options = [
'debug' => false,
'default_ttl' => 0,
'private_headers' => [ 'Authorization', 'Cookie' ],
'allow_reload' => false,
'allow_revalidate' => false,
'stale_while_revalidate' => 2,
'stale_if_error' => 60,
);
];

$refHttpCache = new \ReflectionClass('Symfony\Component\HttpKernel\HttpCache\HttpCache');
// Workaround for Symfony 2.3 where $options property is not defined.
Expand Down Expand Up @@ -161,10 +161,10 @@ public function __construct($test, $kernel, $request)

public static function getSubscribedEvents()
{
return array(
return [
Events::PRE_HANDLE => 'preHandle',
Events::PRE_INVALIDATE => 'preInvalidate'
);
Events::PRE_INVALIDATE => 'preInvalidate',
];
}

public function preHandle(CacheEvent $event)
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/SymfonyCache/PurgeSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public function testOtherMethod()
->method('isRequestAllowed')
;

$purgeSubscriber = new PurgeSubscriber(array(
$purgeSubscriber = new PurgeSubscriber([
'purge_client_matcher' => $matcher,
'purge_method' => 'FOO',
));
]);
$request = Request::create('http://example.com/foo', 'PURGE');
$event = new CacheEvent($this->kernel, $request);

Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/SymfonyCache/UserContextSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ public function provideConfigOptions()
$prop->setAccessible(true);
$options = $prop->getValue($subscriber);

$custom = array(
$custom = [
'user_hash_uri' => '/test-uri',
'user_hash_header' => 'test/header',
'user_hash_accept_header' => 'test accept',
'anonymous_hash' => 'test hash',
);;
];

return array(
return [
[[], $options],
[$custom, $custom + $options]
);
];
}

/**
Expand Down Expand Up @@ -124,11 +124,11 @@ public function testUserHashUserWithSession($arg, $options)
$catch = true;
$sessionId1 = 'my_session_id';
$sessionId2 = 'another_session_id';
$cookies = array(
$cookies = [
'PHPSESSID' => $sessionId1,
'PHPSESSIDsdiuhsdf4535d4f' => $sessionId2,
'foo' => 'bar'
);
'foo' => 'bar',
];
$cookieString = "PHPSESSID=$sessionId1; foo=bar; PHPSESSIDsdiuhsdf4535d4f=$sessionId2";
$request = Request::create('/foo', 'GET', [], $cookies, [], ['Cookie' => $cookieString]);

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Test/Proxy/VarnishProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public function testStart()

$this->assertEquals('/usr/sbin/varnishd', $proxy->command);
$this->assertEquals(
array(
[
'-a', '192.168.0.1:6181',
'-T', '192.168.0.1:1331',
'-f', 'config.vcl',
'-n', '/tmp/cache/dir',
'-p', 'vcl_dir=/my/varnish/dir',
'-P', '/tmp/foshttpcache-varnish.pid',
),
],
$proxy->arguments
);
}
Expand Down
Loading