Commit c5ec5245 authored by Fabien Potencier's avatar Fabien Potencier

switched to short array notation

parent 08d04b40
......@@ -6,7 +6,7 @@ return PhpCsFixer\Config::create()
'@Symfony:risky' => true,
'@PHPUnit48Migration:risky' => true,
'php_unit_no_expectation_annotation' => false, // part of `PHPUnitXYMigration:risky` ruleset, to be enabled when PHPUnit 4.x support will be dropped, as we don't want to rewrite exceptions handling twice
'array_syntax' => array('syntax' => 'long'),
'array_syntax' => array('syntax' => 'short'),
'protected_to_private' => false,
))
->setRiskyAllowed(true)
......
......@@ -46,7 +46,7 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
const EARLY_EVENT = 512;
const LATE_EVENT = -512;
protected $providers = array();
protected $providers = [];
protected $booted = false;
/**
......@@ -56,7 +56,7 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
*
* @param array $values the parameters or objects
*/
public function __construct(array $values = array())
public function __construct(array $values = [])
{
parent::__construct();
......@@ -83,7 +83,7 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
*
* @return Application
*/
public function register(ServiceProviderInterface $provider, array $values = array())
public function register(ServiceProviderInterface $provider, array $values = [])
{
$this->providers[] = $provider;
......@@ -311,7 +311,7 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
* @param string $message The status message
* @param array $headers An array of HTTP headers
*/
public function abort($statusCode, $message = '', array $headers = array())
public function abort($statusCode, $message = '', array $headers = [])
{
throw new HttpException($statusCode, $message, null, $headers);
}
......@@ -385,7 +385,7 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
*
* @return StreamedResponse
*/
public function stream($callback = null, $status = 200, array $headers = array())
public function stream($callback = null, $status = 200, array $headers = [])
{
return new StreamedResponse($callback, $status, $headers);
}
......@@ -414,7 +414,7 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
*
* @return JsonResponse
*/
public function json($data = array(), $status = 200, array $headers = array())
public function json($data = [], $status = 200, array $headers = [])
{
return new JsonResponse($data, $status, $headers);
}
......@@ -429,7 +429,7 @@ class Application extends Container implements HttpKernelInterface, TerminableIn
*
* @return BinaryFileResponse
*/
public function sendFile($file, $status = 200, array $headers = array(), $contentDisposition = null)
public function sendFile($file, $status = 200, array $headers = [], $contentDisposition = null)
{
return new BinaryFileResponse($file, $status, $headers, true, $contentDisposition);
}
......
......@@ -32,7 +32,7 @@ trait FormTrait
*
* @return FormBuilder
*/
public function form($data = null, array $options = array(), $type = null)
public function form($data = null, array $options = [], $type = null)
{
return $this['form.factory']->createBuilder($type ?: FormType::class, $data, $options);
}
......@@ -47,7 +47,7 @@ trait FormTrait
*
* @return FormBuilder
*/
public function namedForm($name, $data = null, array $options = array(), $type = null)
public function namedForm($name, $data = null, array $options = [], $type = null)
{
return $this['form.factory']->createNamedBuilder($name, $type ?: FormType::class, $data, $options);
}
......
......@@ -29,7 +29,7 @@ trait MonologTrait
*
* @return bool Whether the record has been processed
*/
public function log($message, array $context = array(), $level = Logger::INFO)
public function log($message, array $context = [], $level = Logger::INFO)
{
return $this['monolog']->addRecord($level, $message, $context);
}
......
......@@ -28,7 +28,7 @@ trait TranslationTrait
*
* @return string The translated string
*/
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
public function trans($id, array $parameters = [], $domain = 'messages', $locale = null)
{
return $this['translator']->trans($id, $parameters, $domain, $locale);
}
......@@ -44,7 +44,7 @@ trait TranslationTrait
*
* @return string The translated string
*/
public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
public function transChoice($id, $number, array $parameters = [], $domain = 'messages', $locale = null)
{
return $this['translator']->transChoice($id, $number, $parameters, $domain, $locale);
}
......
......@@ -32,7 +32,7 @@ trait TwigTrait
*
* @return Response A Response instance
*/
public function render($view, array $parameters = array(), Response $response = null)
public function render($view, array $parameters = [], Response $response = null)
{
$twig = $this['twig'];
......@@ -58,7 +58,7 @@ trait TwigTrait
*
* @return string The rendered view
*/
public function renderView($view, array $parameters = array())
public function renderView($view, array $parameters = [])
{
return $this['twig']->render($view, $parameters);
}
......
......@@ -28,7 +28,7 @@ trait UrlGeneratorTrait
*
* @return string The generated path
*/
public function path($route, $parameters = array())
public function path($route, $parameters = [])
{
return $this['url_generator']->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
}
......@@ -41,7 +41,7 @@ trait UrlGeneratorTrait
*
* @return string The generated URL
*/
public function url($route, $parameters = array())
public function url($route, $parameters = [])
{
return $this['url_generator']->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL);
}
......
......@@ -49,7 +49,7 @@ class CallbackResolver
{
if (preg_match(static::SERVICE_PATTERN, $name)) {
list($service, $method) = explode(':', $name, 2);
$callback = array($this->app[$service], $method);
$callback = [$this->app[$service], $method];
} else {
$service = $name;
$callback = $this->app[$name];
......
......@@ -91,7 +91,7 @@ class Controller
throw new \BadMethodCallException(sprintf('Method "%s::%s" does not exist.', get_class($this->route), $method));
}
call_user_func_array(array($this->route, $method), $arguments);
call_user_func_array([$this->route, $method], $arguments);
return $this;
}
......@@ -111,7 +111,7 @@ class Controller
$methods = implode('_', $this->route->getMethods()).'_';
$routeName = $methods.$prefix.$this->route->getPath();
$routeName = str_replace(array('/', ':', '|', '-'), '_', $routeName);
$routeName = str_replace(['/', ':', '|', '-'], '_', $routeName);
$routeName = preg_replace('/[^a-z0-9A-Z_.]+/', '', $routeName);
// Collapse consecutive underscores down into a single underscore.
......
......@@ -39,7 +39,7 @@ use Symfony\Component\HttpFoundation\Request;
*/
class ControllerCollection
{
protected $controllers = array();
protected $controllers = [];
protected $defaultRoute;
protected $defaultController;
protected $prefix;
......@@ -184,10 +184,10 @@ class ControllerCollection
throw new \BadMethodCallException(sprintf('Method "%s::%s" does not exist.', get_class($this->defaultRoute), $method));
}
call_user_func_array(array($this->defaultRoute, $method), $arguments);
call_user_func_array([$this->defaultRoute, $method], $arguments);
foreach ($this->controllers as $controller) {
call_user_func_array(array($controller, $method), $arguments);
call_user_func_array([$controller, $method], $arguments);
}
return $this;
......@@ -233,7 +233,7 @@ class ControllerCollection
}
}
$this->controllers = array();
$this->controllers = [];
return $routes;
}
......
......@@ -59,8 +59,8 @@ class ConverterListener implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
return [
KernelEvents::CONTROLLER => 'onKernelController',
);
];
}
}
......@@ -116,19 +116,19 @@ class LogListener implements EventSubscriberInterface
*/
protected function logException(\Exception $e)
{
$this->logger->log(call_user_func($this->exceptionLogFilter, $e), sprintf('%s: %s (uncaught exception) at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), array('exception' => $e));
$this->logger->log(call_user_func($this->exceptionLogFilter, $e), sprintf('%s: %s (uncaught exception) at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), ['exception' => $e]);
}
public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => array('onKernelRequest', 0),
KernelEvents::RESPONSE => array('onKernelResponse', 0),
return [
KernelEvents::REQUEST => ['onKernelRequest', 0],
KernelEvents::RESPONSE => ['onKernelResponse', 0],
/*
* Priority -4 is used to come after those from SecurityServiceProvider (0)
* but before the error handlers added with Silex\Application::error (defaults to -8)
*/
KernelEvents::EXCEPTION => array('onKernelException', -4),
);
KernelEvents::EXCEPTION => ['onKernelException', -4],
];
}
}
......@@ -87,10 +87,10 @@ class MiddlewareListener implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
return [
// this must be executed after the late events defined with before() (and their priority is -512)
KernelEvents::REQUEST => array('onKernelRequest', -1024),
KernelEvents::RESPONSE => array('onKernelResponse', 128),
);
KernelEvents::REQUEST => ['onKernelRequest', -1024],
KernelEvents::RESPONSE => ['onKernelResponse', 128],
];
}
}
......@@ -44,8 +44,8 @@ class StringToResponseListener implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
KernelEvents::VIEW => array('onKernelView', -10),
);
return [
KernelEvents::VIEW => ['onKernelView', -10],
];
}
}
......@@ -51,6 +51,6 @@ class ExceptionHandler implements EventSubscriberInterface
*/
public static function getSubscribedEvents()
{
return array(KernelEvents::EXCEPTION => array('onSilexError', -255));
return [KernelEvents::EXCEPTION => ['onSilexError', -255]];
}
}
......@@ -32,11 +32,11 @@ class AssetServiceProvider implements ServiceProviderInterface
public function register(Container $app)
{
$app['assets.packages'] = function ($app) {
$packages = array();
$packages = [];
foreach ($app['assets.named_packages'] as $name => $package) {
$version = $app['assets.strategy_factory'](isset($package['version']) ? $package['version'] : null, isset($package['version_format']) ? $package['version_format'] : null, isset($package['json_manifest_path']) ? $package['json_manifest_path'] : null, $name);
$packages[$name] = $app['assets.package_factory'](isset($package['base_path']) ? $package['base_path'] : '', isset($package['base_urls']) ? $package['base_urls'] : array(), $version, $name);
$packages[$name] = $app['assets.package_factory'](isset($package['base_path']) ? $package['base_path'] : '', isset($package['base_urls']) ? $package['base_urls'] : [], $version, $name);
}
return new Packages($app['assets.default_package'], $packages);
......@@ -53,12 +53,12 @@ class AssetServiceProvider implements ServiceProviderInterface
};
$app['assets.base_path'] = '';
$app['assets.base_urls'] = array();
$app['assets.base_urls'] = [];
$app['assets.version'] = null;
$app['assets.version_format'] = null;
$app['assets.json_manifest_path'] = null;
$app['assets.named_packages'] = array();
$app['assets.named_packages'] = [];
// prototypes
......
......@@ -27,13 +27,13 @@ class DoctrineServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app['db.default_options'] = array(
$app['db.default_options'] = [
'driver' => 'pdo_mysql',
'dbname' => null,
'host' => 'localhost',
'user' => 'root',
'password' => null,
);
];
$app['dbs.options.initializer'] = $app->protect(function () use ($app) {
static $initialized = false;
......@@ -45,7 +45,7 @@ class DoctrineServiceProvider implements ServiceProviderInterface
$initialized = true;
if (!isset($app['dbs.options'])) {
$app['dbs.options'] = array('default' => isset($app['db.options']) ? $app['db.options'] : array());
$app['dbs.options'] = ['default' => isset($app['db.options']) ? $app['db.options'] : []];
}
$tmp = $app['dbs.options'];
......
......@@ -52,7 +52,7 @@ class SilexFormExtension implements FormExtensionInterface
public function getTypeExtensions($name)
{
return isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : array();
return isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : [];
}
public function hasTypeExtensions($name)
......@@ -66,7 +66,7 @@ class SilexFormExtension implements FormExtensionInterface
$this->guesserLoaded = true;
if ($this->guessers) {
$guessers = array();
$guessers = [];
foreach ($this->guessers as $guesser) {
if (!is_object($guesser)) {
$guesser = $this->app[$guesser];
......@@ -82,7 +82,7 @@ class SilexFormExtension implements FormExtensionInterface
private function setTypes(array $types)
{
$this->types = array();
$this->types = [];
foreach ($types as $type) {
if (!is_object($type)) {
if (!isset($this->app[$type])) {
......@@ -97,7 +97,7 @@ class SilexFormExtension implements FormExtensionInterface
private function setTypeExtensions(array $typeExtensions)
{
$this->typeExtensions = array();
$this->typeExtensions = [];
foreach ($typeExtensions as $extension) {
if (!is_object($extension)) {
if (!isset($this->app[$extension])) {
......@@ -111,7 +111,7 @@ class SilexFormExtension implements FormExtensionInterface
private function setGuessers(array $guessers)
{
$this->guessers = array();
$this->guessers = [];
foreach ($guessers as $guesser) {
if (!is_object($guesser) && !isset($this->app[$guesser])) {
throw new InvalidArgumentException(sprintf('Invalid form type guesser. The silex service "%s" does not exist.', $guesser));
......
......@@ -34,15 +34,15 @@ class FormServiceProvider implements ServiceProviderInterface
}
$app['form.types'] = function ($app) {
return array();
return [];
};
$app['form.type.extensions'] = function ($app) {
return array();
return [];
};
$app['form.type.guessers'] = function ($app) {
return array();
return [];
};
$app['form.extension.csrf'] = function ($app) {
......@@ -58,9 +58,9 @@ class FormServiceProvider implements ServiceProviderInterface
};
$app['form.extensions'] = function ($app) {
$extensions = array(
$extensions = [
new HttpFoundationExtension(),
);
];
if (isset($app['csrf.token_manager'])) {
$extensions[] = $app['form.extension.csrf'];
......
......@@ -31,9 +31,9 @@ class HttpCacheServiceProvider implements ServiceProviderInterface, EventListene
{
$app['http_cache'] = function ($app) {
$app['http_cache.options'] = array_replace(
array(
[
'debug' => $app['debug'],
), $app['http_cache.options']
], $app['http_cache.options']
);
return new HttpCache($app, $app['http_cache.store'], $app['http_cache.esi'], $app['http_cache.options']);
......@@ -51,7 +51,7 @@ class HttpCacheServiceProvider implements ServiceProviderInterface, EventListene
return new SurrogateListener($app['http_cache.esi']);
};
$app['http_cache.options'] = array();
$app['http_cache.options'] = [];
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
......
......@@ -69,7 +69,7 @@ class HttpFragmentServiceProvider implements ServiceProviderInterface, EventList
$app['fragment.path'] = '/_fragment';
$app['fragment.renderer.hinclude.global_template'] = null;
$app['fragment.renderers'] = function ($app) {
$renderers = array($app['fragment.renderer.inline'], $app['fragment.renderer.hinclude']);
$renderers = [$app['fragment.renderer.inline'], $app['fragment.renderer.hinclude']];
if (isset($app['http_cache.esi'])) {
$renderers[] = $app['fragment.renderer.esi'];
......
......@@ -48,16 +48,16 @@ class HttpKernelServiceProvider implements ServiceProviderInterface, EventListen
};
$app['argument_value_resolvers'] = function ($app) {
if (Kernel::VERSION_ID < 30200) {
return array(
return [
new AppArgumentValueResolver($app),
new RequestAttributeValueResolver(),
new RequestValueResolver(),
new DefaultValueResolver(),
new VariadicValueResolver(),
);
];
}
return array_merge(array(new AppArgumentValueResolver($app)), ArgumentResolver::getDefaultArgumentValueResolvers());
return array_merge([new AppArgumentValueResolver($app)], ArgumentResolver::getDefaultArgumentValueResolvers());
};
}
......
......@@ -75,10 +75,10 @@ class LocaleListener implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
return [
// must be registered after the Router to have access to the _locale
KernelEvents::REQUEST => array(array('onKernelRequest', 16)),
KernelEvents::FINISH_REQUEST => array(array('onKernelFinishRequest', 0)),
);
KernelEvents::REQUEST => [['onKernelRequest', 16]],
KernelEvents::FINISH_REQUEST => [['onKernelFinishRequest', 0]],
];
}
}
......@@ -46,7 +46,7 @@ class MonologServiceProvider implements ServiceProviderInterface, BootableProvid
if (isset($app['request_stack'])) {
$app['monolog.not_found_activation_strategy'] = function () use ($app) {
return new NotFoundActivationStrategy($app['request_stack'], array('^/'), $app['monolog.level']);
return new NotFoundActivationStrategy($app['request_stack'], ['^/'], $app['monolog.level']);
};
}
}
......@@ -88,7 +88,7 @@ class MonologServiceProvider implements ServiceProviderInterface, BootableProvid
};
$app['monolog.handlers'] = function () use ($app, $defaultHandler) {
$handlers = array();
$handlers = [];
// enables the default handler if a logfile was set or the monolog.handler service was redefined
if ($app['monolog.logfile'] || $defaultHandler !== $app->raw('monolog.handler')) {
......
......@@ -54,17 +54,17 @@ class RememberMeServiceProvider implements ServiceProviderInterface, EventListen
$app['security.authentication_provider.'.$name.'.remember_me'] = $app['security.authentication_provider.remember_me._proto']($name, $options);
}
return array(
return [
'security.authentication_provider.'.$name.'.remember_me',
'security.authentication_listener.'.$name.'.remember_me',
null, // entry point
'remember_me',
);
];
});
$app['security.remember_me.service._proto'] = $app->protect(function ($providerKey, $options) use ($app) {
return function () use ($providerKey, $options, $app) {
$options = array_replace(array(
$options = array_replace([
'name' => 'REMEMBERME',
'lifetime' => 31536000,
'path' => '/',
......@@ -73,9 +73,9 @@ class RememberMeServiceProvider implements ServiceProviderInterface, EventListen
'httponly' => true,
'always_remember_me' => false,
'remember_me_parameter' => '_remember_me',
), $options);
], $options);
return new TokenBasedRememberMeServices(array($app['security.user_provider.'.$providerKey]), $options['key'], $providerKey, $options, $app['logger']);
return new TokenBasedRememberMeServices([$app['security.user_provider.'.$providerKey]], $options['key'], $providerKey, $options, $app['logger']);
};
});
......
......@@ -46,10 +46,10 @@ class RedirectableUrlMatcher extends BaseRedirectableUrlMatcher
}
}
return array(
return [
'_controller' => function ($url) { return new RedirectResponse($url, 301); },
'_route' => $route,
'url' => $url,
);
];
}
}
......@@ -40,11 +40,11 @@ class SerializerServiceProvider implements ServiceProviderInterface
};
$app['serializer.encoders'] = function () {
return array(new JsonEncoder(), new XmlEncoder());
return [new JsonEncoder(), new XmlEncoder()];
};
$app['serializer.normalizers'] = function () {
return array(new CustomNormalizer(), new GetSetMethodNormalizer());
return [new CustomNormalizer(), new GetSetMethodNormalizer()];
};
}
}
......@@ -68,7 +68,7 @@ class SessionServiceProvider implements ServiceProviderInterface, EventListenerP
return new TestSessionListener($app);
};
$app['session.storage.options'] = array();
$app['session.storage.options'] = [];
$app['session.default_locale'] = 'en';
$app['session.storage.save_path'] = null;
$app['session.attribute_bag'] = null;
......
......@@ -28,7 +28,7 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe
{
public function register(Container $app)
{
$app['swiftmailer.options'] = array();
$app['swiftmailer.options'] = [];
$app['swiftmailer.use_spool'] = true;
$app['mailer.initialized'] = false;
......@@ -51,19 +51,19 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe
$app['swiftmailer.transport'] = function ($app) {
$transport = new \Swift_Transport_EsmtpTransport(
$app['swiftmailer.transport.buffer'],
array($app['swiftmailer.transport.authhandler']),
[$app['swiftmailer.transport.authhandler']],
$app['swiftmailer.transport.eventdispatcher']
);
$options = $app['swiftmailer.options'] = array_replace(array(
$options = $app['swiftmailer.options'] = array_replace([
'host' => 'localhost',
'port' => 25,
'username' => '',
'password' => '',
'encryption' => null,
'auth_mode' => null,
'stream_context_options' => array(),
), $app['swiftmailer.options']);
'stream_context_options' => [],
], $app['swiftmailer.options']);
$transport->setHost($options['host']);
$transport->setPort($options['port']);
......@@ -81,11 +81,11 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe
};
$app['swiftmailer.transport.authhandler'] = function () {
return new \Swift_Transport_Esmtp_AuthHandler(array(
return new \Swift_Transport_Esmtp_AuthHandler([
new \Swift_Transport_Esmtp_Auth_CramMd5Authenticator(),
new \Swift_Transport_Esmtp_Auth_LoginAuthenticator(),
new \Swift_Transport_Esmtp_Auth_PlainAuthenticator(),
));
]);
};
$app['swiftmailer.transport.eventdispatcher'] = function ($app) {
......@@ -112,12 +112,12 @@ class SwiftmailerServiceProvider implements ServiceProviderInterface, EventListe
};
$app['swiftmailer.plugins'] = function ($app) {
return array();
return [];
};
$app['swiftmailer.sender_address'] = null;
$app['swiftmailer.delivery_addresses'] = array();
$app['swiftmailer.delivery_whitelist'] = array();
$app['swiftmailer.delivery_addresses'] = [];
$app['swiftmailer.delivery_whitelist'] = [];
}
public function subscribe(Container $app, EventDispatcherInterface $dispatcher)
......
......@@ -81,11 +81,11 @@ class TranslationServiceProvider implements ServiceProviderInterface, EventListe
};
$app['translator.resources'] = function ($app) {
return array();
return [];
};
$app['translator.domains'] = array();
$app['locale_fallbacks'] = array('en');
$app['translator.domains'] = [];
$app['locale_fallbacks'] = ['en'];
$app['translator.cache_dir'] = null;
}
......
<
......@@ -38,10 +38,10 @@ class TwigServiceProvider implements ServiceProviderInterface
{
public function register(Container $app)
{
$app['twig.options'] = array();
$app['twig.form.templates'] = array('form_div_layout.html.twig');
$app['twig.path'] = array();
$app['twig.templates'] = array();
$app['twig.options'] = [];