diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 81076b6cf..d65945a72 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,9 +1,21 @@ name: "Code Linting" on: push: + paths: + - .php-cs-fixer.dist.php + - autoload.php + - lib/** + - data/** + - tests/** branches: - master pull_request: + paths: + - .php-cs-fixer.dist.php + - autoload.php + - lib/** + - data/** + - tests/** jobs: php-cs-fixer: @@ -15,17 +27,17 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.2 - tools: php-cs-fixer:3.45, cs2pr + php-version: 7.4 + tools: php-cs-fixer:3.51, cs2pr - uses: actions/cache@v4 with: path: '.php-cs-fixer.cache' - key: ${{ github.repository }}-8.2-phpcsfixer-${{ github.ref_name }} + key: ${{ github.repository }}-7.4-phpcsfixer-${{ github.ref_name }} restore-keys: | - ${{ github.repository }}-8.2-phpcsfixer-master - ${{ github.repository }}-8.2-phpcsfixer- + ${{ github.repository }}-7.4-phpcsfixer-master + ${{ github.repository }}-7.4-phpcsfixer- - name: Run PHP-CS-Fixer # Using cs2pr settings, see: https://github.com/shivammathur/setup-php#tools-with-checkstyle-support - run: 'php-cs-fixer fix --dry-run --format checkstyle | cs2pr' + run: 'php-cs-fixer fix --dry-run --format=checkstyle | cs2pr' diff --git a/.gitignore b/.gitignore index 3c17d4767..1c5624fa2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.cache/ + /test/functional/fixtures/cache /test/functional/fixtures/log /lib/plugins/sfDoctrinePlugin/test/functional/fixtures/lib/*/doctrine/base/ @@ -6,4 +8,3 @@ lib/plugins/sfDoctrinePlugin/test/functional/fixtures/log/ /vendor /composer.lock -.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f5e11f987..1212fe9b4 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -5,7 +5,7 @@ ->in(__DIR__.'/lib') ->in(__DIR__.'/data/bin') ->in(__DIR__.'/test') - ->append(array(__FILE__)) + ->append([__FILE__]) // Exclude PHP classes templates/generators, which are not valid PHP files ->exclude('task/generator/skeleton/') ->exclude('plugins/sfDoctrinePlugin/data/generator/') @@ -15,14 +15,13 @@ ; $config = new PhpCsFixer\Config(); -$config->setRules(array( - '@PhpCsFixer' => true, - '@Symfony' => true, - 'array_syntax' => array( - 'syntax' => 'long', - ), -)) - ->setCacheFile('.php-cs-fixer.cache') +$config + ->setRules([ + '@PhpCsFixer' => true, + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + ]) + ->setCacheFile('.cache/php-cs-fixer.cache') ->setFinder($finder) ; diff --git a/data/bin/changelog.php b/data/bin/changelog.php index 4eaf5868a..6a3218a4b 100644 --- a/data/bin/changelog.php +++ b/data/bin/changelog.php @@ -36,10 +36,10 @@ list($out, $err) = $filesystem->execute('svn info --xml'); $info = new SimpleXMLElement($out); -list($out, $err) = $filesystem->execute(vsprintf('svn log %s --xml %s', array_map('escapeshellarg', array( +list($out, $err) = $filesystem->execute(vsprintf('svn log %s --xml %s', array_map('escapeshellarg', [ $argv[1], (string) $info->entry->repository->root.$argv[2], -)))); +]))); $log = new SimpleXMLElement($out); foreach ($log->logentry as $logentry) { diff --git a/data/bin/release.php b/data/bin/release.php index df6dec94f..ad652a3bf 100644 --- a/data/bin/release.php +++ b/data/bin/release.php @@ -73,7 +73,7 @@ // add class files $finder = sfFinder::type('file')->relative(); $xml_classes = ''; -$dirs = array('lib' => 'php', 'data' => 'data'); +$dirs = ['lib' => 'php', 'data' => 'data']; foreach ($dirs as $dir => $role) { $class_files = $finder->in($dir); foreach ($class_files as $file) { @@ -82,12 +82,12 @@ } // replace tokens -$filesystem->replaceTokens(getcwd().DIRECTORY_SEPARATOR.'package.xml', '##', '##', array( +$filesystem->replaceTokens(getcwd().DIRECTORY_SEPARATOR.'package.xml', '##', '##', [ 'SYMFONY_VERSION' => $version, 'CURRENT_DATE' => date('Y-m-d'), 'CLASS_FILES' => $xml_classes, 'STABILITY' => $stability, -)); +]); list($results) = $filesystem->execute('pear package'); echo $results; diff --git a/data/bin/sandbox_installer.php b/data/bin/sandbox_installer.php index 576b28c01..3f35604aa 100644 --- a/data/bin/sandbox_installer.php +++ b/data/bin/sandbox_installer.php @@ -23,7 +23,7 @@ chmod(sfConfig::get('sf_data_dir').'/sandbox.db', 0777); $this->logSection('install', 'add an empty file in empty directories'); -$seen = array(); +$seen = []; foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(sfConfig::get('sf_root_dir')), RecursiveIteratorIterator::CHILD_FIRST) as $path => $item) { if (!isset($seen[$path]) && $item->isDir() && !$item->isLink()) { touch($item->getRealPath().'/.sf'); diff --git a/lib/action/sfAction.class.php b/lib/action/sfAction.class.php index ae969441e..cabab27f0 100644 --- a/lib/action/sfAction.class.php +++ b/lib/action/sfAction.class.php @@ -20,7 +20,7 @@ */ abstract class sfAction extends sfComponent { - protected $security = array(); + protected $security = []; /** * Initializes this action. @@ -122,7 +122,7 @@ public function redirect404() public function forward($module, $action) { if (sfConfig::get('sf_logging_enabled')) { - $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Forward to action "%s/%s"', $module, $action)))); + $this->dispatcher->notify(new sfEvent($this, 'application.log', [sprintf('Forward to action "%s/%s"', $module, $action)])); } $this->getController()->forward($module, $action); @@ -184,7 +184,7 @@ public function redirect($url, $statusCode = 302) { // compatibility with url_for2() style signature if (is_object($statusCode) || is_array($statusCode)) { - $url = array_merge(array('sf_route' => $url), is_object($statusCode) ? array('sf_subject' => $statusCode) : $statusCode); + $url = array_merge(['sf_route' => $url], is_object($statusCode) ? ['sf_subject' => $statusCode] : $statusCode); $statusCode = func_num_args() >= 3 ? func_get_arg(2) : 302; } @@ -211,7 +211,7 @@ public function redirectIf($condition, $url, $statusCode = 302) if ($condition) { // compatibility with url_for2() style signature $arguments = func_get_args(); - call_user_func_array(array($this, 'redirect'), array_slice($arguments, 1)); + call_user_func_array([$this, 'redirect'], array_slice($arguments, 1)); } } @@ -233,7 +233,7 @@ public function redirectUnless($condition, $url, $statusCode = 302) if (!$condition) { // compatibility with url_for2() style signature $arguments = func_get_args(); - call_user_func_array(array($this, 'redirect'), array_slice($arguments, 1)); + call_user_func_array([$this, 'redirect'], array_slice($arguments, 1)); } } @@ -430,7 +430,7 @@ public function getCredential() public function setTemplate($name, $module = null) { if (sfConfig::get('sf_logging_enabled')) { - $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change template to "%s/%s"', null === $module ? 'CURRENT' : $module, $name)))); + $this->dispatcher->notify(new sfEvent($this, 'application.log', [sprintf('Change template to "%s/%s"', null === $module ? 'CURRENT' : $module, $name)])); } if (null !== $module) { @@ -468,7 +468,7 @@ public function getTemplate() public function setLayout($name) { if (sfConfig::get('sf_logging_enabled')) { - $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Change layout to "%s"', $name)))); + $this->dispatcher->notify(new sfEvent($this, 'application.log', [sprintf('Change layout to "%s"', $name)])); } sfConfig::set('symfony.view.'.$this->getModuleName().'_'.$this->getActionName().'_layout', $name); diff --git a/lib/action/sfActionStack.class.php b/lib/action/sfActionStack.class.php index bdb812a40..09242f6ef 100644 --- a/lib/action/sfActionStack.class.php +++ b/lib/action/sfActionStack.class.php @@ -19,7 +19,7 @@ class sfActionStack { /** @var sfActionStackEntry[] */ - protected $stack = array(); + protected $stack = []; /** * Adds an entry to the action stack. diff --git a/lib/action/sfActions.class.php b/lib/action/sfActions.class.php index d6a571e13..2950780fc 100644 --- a/lib/action/sfActions.class.php +++ b/lib/action/sfActions.class.php @@ -41,13 +41,13 @@ public function execute($request) throw new sfInitializationException(sprintf('sfAction initialization failed for module "%s". There was no action given.', $this->getModuleName())); } - if (!is_callable(array($this, $actionToRun))) { + if (!is_callable([$this, $actionToRun])) { // action not found throw new sfInitializationException(sprintf('sfAction initialization failed for module "%s", action "%s". You must create a "%s" method.', $this->getModuleName(), $this->getActionName(), $actionToRun)); } if (sfConfig::get('sf_logging_enabled')) { - $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Call "%s->%s()"', get_class($this), $actionToRun)))); + $this->dispatcher->notify(new sfEvent($this, 'application.log', [sprintf('Call "%s->%s()"', get_class($this), $actionToRun)])); } // run action diff --git a/lib/action/sfComponent.class.php b/lib/action/sfComponent.class.php index c25299521..fb7ee72ed 100644 --- a/lib/action/sfComponent.class.php +++ b/lib/action/sfComponent.class.php @@ -62,7 +62,7 @@ public function __construct($context, $moduleName, $actionName) * * @return string The translated string */ - public function __($string, $args = array(), $catalogue = 'messages') + public function __($string, $args = [], $catalogue = 'messages') { return $this->context->getI18N()->__($string, $args, $catalogue); } @@ -128,7 +128,7 @@ public function __unset($name) */ public function __call($method, $arguments) { - $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'component.method_not_found', array('method' => $method, 'arguments' => $arguments))); + $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'component.method_not_found', ['method' => $method, 'arguments' => $arguments])); if (!$event->isProcessed()) { throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method)); } @@ -247,7 +247,7 @@ final public function getLogger() public function logMessage($message, $priority = 'info') { if (sfConfig::get('sf_logging_enabled')) { - $this->dispatcher->notify(new sfEvent($this, 'application.log', array($message, 'priority' => constant('sfLogger::'.strtoupper($priority))))); + $this->dispatcher->notify(new sfEvent($this, 'application.log', [$message, 'priority' => constant('sfLogger::'.strtoupper($priority))])); } } @@ -339,7 +339,7 @@ public function getController() * * @return string The URL */ - public function generateUrl($route, $params = array(), $absolute = false) + public function generateUrl($route, $params = [], $absolute = false) { return $this->context->getRouting()->generate($route, $params, $absolute); } diff --git a/lib/addon/sfData.class.php b/lib/addon/sfData.class.php index 0af1760b4..4d5e4e448 100644 --- a/lib/addon/sfData.class.php +++ b/lib/addon/sfData.class.php @@ -17,7 +17,7 @@ abstract class sfData { protected $deleteCurrentData = true; - protected $object_references = array(); + protected $object_references = []; /** * Sets a flag to indicate if the current data in the database @@ -66,7 +66,7 @@ public function getFiles($element = null) $element = sfConfig::get('sf_data_dir').'/fixtures'; } - $files = array(); + $files = []; if (is_array($element)) { foreach ($element as $e) { $files = array_merge($files, $this->getFiles($e)); @@ -106,8 +106,8 @@ protected function doLoadDataFromFile($file) */ protected function doLoadData(array $files) { - $this->object_references = array(); - $this->maps = array(); + $this->object_references = []; + $this->maps = []; foreach ($files as $file) { $this->doLoadDataFromFile($file); diff --git a/lib/addon/sfPager.class.php b/lib/addon/sfPager.class.php index acb547842..9f97829ea 100644 --- a/lib/addon/sfPager.class.php +++ b/lib/addon/sfPager.class.php @@ -23,7 +23,7 @@ abstract class sfPager implements Iterator, Countable protected $tableName = ''; protected $objects; protected $cursor = 1; - protected $parameters = array(); + protected $parameters = []; protected $currentMaxLink = 1; protected $parameterHolder; protected $maxRecordLimit = false; @@ -97,7 +97,7 @@ public function setMaxRecordLimit($limit) */ public function getLinks($nb_links = 5) { - $links = array(); + $links = []; $tmp = $this->page - floor($nb_links / 2); $check = $this->lastPage - $nb_links + 1; $limit = $check > 0 ? $check : 1; diff --git a/lib/autoload/sfAutoload.class.php b/lib/autoload/sfAutoload.class.php index f3f5843f2..de53e724c 100644 --- a/lib/autoload/sfAutoload.class.php +++ b/lib/autoload/sfAutoload.class.php @@ -21,8 +21,8 @@ class sfAutoload protected static $freshCache = false; protected static $instance; - protected $overriden = array(); - protected $classes = array(); + protected $overriden = []; + protected $classes = []; protected function __construct() { @@ -51,7 +51,7 @@ public static function register() { ini_set('unserialize_callback_func', 'spl_autoload_call'); - if (false === spl_autoload_register(array(self::getInstance(), 'autoload'))) { + if (false === spl_autoload_register([self::getInstance(), 'autoload'])) { throw new sfException(sprintf('Unable to register %s::autoload as an autoloading method.', get_class(self::getInstance()))); } } @@ -61,7 +61,7 @@ public static function register() */ public static function unregister() { - spl_autoload_unregister(array(self::getInstance(), 'autoload')); + spl_autoload_unregister([self::getInstance(), 'autoload']); } /** diff --git a/lib/autoload/sfAutoloadAgain.class.php b/lib/autoload/sfAutoloadAgain.class.php index 29f6c4b72..a2771e604 100644 --- a/lib/autoload/sfAutoloadAgain.class.php +++ b/lib/autoload/sfAutoloadAgain.class.php @@ -65,7 +65,7 @@ public function autoload($class) } } } else { - $position = array_search(array(__CLASS__, 'autoload'), $autoloads, true); + $position = array_search([__CLASS__, 'autoload'], $autoloads, true); } if (isset($autoloads[$position + 1])) { @@ -102,7 +102,7 @@ public function isRegistered() public function register() { if (!$this->isRegistered()) { - spl_autoload_register(array($this, 'autoload')); + spl_autoload_register([$this, 'autoload']); $this->registered = true; } } @@ -112,7 +112,7 @@ public function register() */ public function unregister() { - spl_autoload_unregister(array($this, 'autoload')); + spl_autoload_unregister([$this, 'autoload']); $this->registered = false; } } diff --git a/lib/autoload/sfCoreAutoload.class.php b/lib/autoload/sfCoreAutoload.class.php index 843925d33..91bbd192e 100755 --- a/lib/autoload/sfCoreAutoload.class.php +++ b/lib/autoload/sfCoreAutoload.class.php @@ -28,7 +28,7 @@ class sfCoreAutoload // Don't edit this property by hand. // To update it, use sfCoreAutoload::make() - protected $classes = array( + protected $classes = [ 'sfaction' => 'action/sfAction.class.php', 'sfactionstack' => 'action/sfActionStack.class.php', 'sfactionstackentry' => 'action/sfActionStackEntry.class.php', @@ -389,7 +389,7 @@ class sfCoreAutoload 'sfyamldumper' => 'yaml/sfYamlDumper.class.php', 'sfyamlinline' => 'yaml/sfYamlInline.class.php', 'sfyamlparser' => 'yaml/sfYamlParser.class.php', - ); + ]; protected function __construct() { @@ -422,7 +422,7 @@ public static function register() } ini_set('unserialize_callback_func', 'spl_autoload_call'); - if (false === spl_autoload_register(array(self::getInstance(), 'autoload'))) { + if (false === spl_autoload_register([self::getInstance(), 'autoload'])) { throw new sfException(sprintf('Unable to register %s::autoload as an autoloading method.', get_class(self::getInstance()))); } @@ -434,7 +434,7 @@ public static function register() */ public static function unregister() { - spl_autoload_unregister(array(self::getInstance(), 'autoload')); + spl_autoload_unregister([self::getInstance(), 'autoload']); self::$registered = false; } diff --git a/lib/autoload/sfSimpleAutoload.class.php b/lib/autoload/sfSimpleAutoload.class.php index f65804d6b..85674e7a0 100755 --- a/lib/autoload/sfSimpleAutoload.class.php +++ b/lib/autoload/sfSimpleAutoload.class.php @@ -24,10 +24,10 @@ class sfSimpleAutoload protected $cacheFile; protected $cacheLoaded = false; protected $cacheChanged = false; - protected $dirs = array(); - protected $files = array(); - protected $classes = array(); - protected $overriden = array(); + protected $dirs = []; + protected $files = []; + protected $classes = []; + protected $overriden = []; protected function __construct($cacheFile = null) { @@ -66,12 +66,12 @@ public static function register() } ini_set('unserialize_callback_func', 'spl_autoload_call'); - if (false === spl_autoload_register(array(self::getInstance(), 'autoload'))) { + if (false === spl_autoload_register([self::getInstance(), 'autoload'])) { throw new sfException(sprintf('Unable to register %s::autoload as an autoloading method.', get_class(self::getInstance()))); } if (self::getInstance()->cacheFile) { - register_shutdown_function(array(self::getInstance(), 'saveCache')); + register_shutdown_function([self::getInstance(), 'saveCache']); } self::$registered = true; @@ -82,7 +82,7 @@ public static function register() */ public static function unregister() { - spl_autoload_unregister(array(self::getInstance(), 'autoload')); + spl_autoload_unregister([self::getInstance(), 'autoload']); self::$registered = false; } @@ -140,7 +140,7 @@ public function saveCache() { if ($this->cacheChanged) { if (is_writable(dirname($this->cacheFile))) { - file_put_contents($this->cacheFile, serialize(array($this->classes, $this->dirs, $this->files))); + file_put_contents($this->cacheFile, serialize([$this->classes, $this->dirs, $this->files])); } $this->cacheChanged = false; @@ -152,7 +152,7 @@ public function saveCache() */ public function reload() { - $this->classes = array(); + $this->classes = []; $this->cacheLoaded = false; foreach ($this->dirs as $dir) { diff --git a/lib/cache/sfAPCCache.class.php b/lib/cache/sfAPCCache.class.php new file mode 100644 index 000000000..a337bfa51 --- /dev/null +++ b/lib/cache/sfAPCCache.class.php @@ -0,0 +1,192 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Cache class that stores cached content in APC. + * + * @author Fabien Potencier + */ +class sfAPCCache extends sfCache +{ + protected $enabled; + + /** + * Initializes this sfCache instance. + * + * Available options: + * + * * see sfCache for options available for all drivers + * + * @see sfCache + */ + public function initialize($options = []) + { + parent::initialize($options); + + $this->enabled = function_exists('apc_store') && ini_get('apc.enabled'); + } + + /** + * @see sfCache + * + * @param mixed|null $default + */ + public function get($key, $default = null) + { + if (!$this->enabled) { + return $default; + } + + $value = $this->fetch($this->getOption('prefix').$key, $has); + + return $has ? $value : $default; + } + + /** + * @see sfCache + */ + public function has($key) + { + if (!$this->enabled) { + return false; + } + + $this->fetch($this->getOption('prefix').$key, $has); + + return $has; + } + + /** + * @see sfCache + * + * @param mixed|null $lifetime + */ + public function set($key, $data, $lifetime = null) + { + if (!$this->enabled) { + return true; + } + + return apc_store($this->getOption('prefix').$key, $data, $this->getLifetime($lifetime)); + } + + /** + * @see sfCache + */ + public function remove($key) + { + if (!$this->enabled) { + return true; + } + + return apc_delete($this->getOption('prefix').$key); + } + + /** + * @see sfCache + */ + public function clean($mode = sfCache::ALL) + { + if (!$this->enabled) { + return true; + } + + if (sfCache::ALL === $mode) { + return apc_clear_cache('user'); + } + } + + /** + * @see sfCache + */ + public function getLastModified($key) + { + if ($info = $this->getCacheInfo($key)) { + return $info['creation_time'] + $info['ttl'] > time() ? $info['mtime'] : 0; + } + + return 0; + } + + /** + * @see sfCache + */ + public function getTimeout($key) + { + if ($info = $this->getCacheInfo($key)) { + return $info['creation_time'] + $info['ttl'] > time() ? $info['creation_time'] + $info['ttl'] : 0; + } + + return 0; + } + + /** + * @see sfCache + */ + public function removePattern($pattern) + { + if (!$this->enabled) { + return true; + } + + $infos = apc_cache_info('user'); + if (!is_array($infos['cache_list'])) { + return; + } + + $regexp = self::patternToRegexp($this->getOption('prefix').$pattern); + + foreach ($infos['cache_list'] as $info) { + if (preg_match($regexp, $info['info'])) { + apc_delete($info['info']); + } + } + } + + /** + * Gets the cache info. + * + * @param string $key The cache key + * + * @return string + */ + protected function getCacheInfo($key) + { + if (!$this->enabled) { + return false; + } + + $infos = apc_cache_info('user'); + + if (is_array($infos['cache_list'])) { + foreach ($infos['cache_list'] as $info) { + if ($this->getOption('prefix').$key == $info['info']) { + return $info; + } + } + } + + return null; + } + + private function fetch($key, &$success) + { + $has = null; + $value = apc_fetch($key, $has); + // the second argument was added in APC 3.0.17. If it is still null we fall back to the value returned + if (null !== $has) { + $success = $has; + } else { + $success = false !== $value; + } + + return $value; + } +} diff --git a/lib/cache/sfAPCuCache.class.php b/lib/cache/sfAPCuCache.class.php index 34c51ec3a..0afaddfa4 100644 --- a/lib/cache/sfAPCuCache.class.php +++ b/lib/cache/sfAPCuCache.class.php @@ -27,7 +27,7 @@ class sfAPCuCache extends sfCache * * @see sfCache */ - public function initialize($options = array()) + public function initialize($options = []) { parent::initialize($options); diff --git a/lib/cache/sfCache.class.php b/lib/cache/sfCache.class.php index 4f0c022ac..60b9a2858 100644 --- a/lib/cache/sfCache.class.php +++ b/lib/cache/sfCache.class.php @@ -19,7 +19,7 @@ abstract class sfCache public const ALL = 2; public const SEPARATOR = ':'; - protected $options = array(); + protected $options = []; /** * Class constructor. @@ -28,7 +28,7 @@ abstract class sfCache * * @param array $options */ - public function __construct($options = array()) + public function __construct($options = []) { $this->initialize($options); } @@ -50,13 +50,13 @@ public function __construct($options = array()) * * @throws sfInitializationException If an error occurs while initializing this sfCache instance */ - public function initialize($options = array()) + public function initialize($options = []) { - $this->options = array_merge(array( + $this->options = array_merge([ 'automatic_cleaning_factor' => 1000, 'lifetime' => 86400, 'prefix' => md5(__DIR__), - ), $options); + ], $options); $this->options['prefix'] .= self::SEPARATOR; } @@ -149,7 +149,7 @@ abstract public function getLastModified($key); */ public function getMany($keys) { - $data = array(); + $data = []; foreach ($keys as $key) { $data[$key] = $this->get($key); } @@ -220,8 +220,8 @@ public function setOption($name, $value) protected function patternToRegexp($pattern) { $regexp = str_replace( - array('\\*\\*', '\\*'), - array('.+?', '[^'.preg_quote(sfCache::SEPARATOR, '#').']+'), + ['\\*\\*', '\\*'], + ['.+?', '[^'.preg_quote(sfCache::SEPARATOR, '#').']+'], preg_quote($pattern, '#') ); diff --git a/lib/cache/sfEAcceleratorCache.class.php b/lib/cache/sfEAcceleratorCache.class.php new file mode 100644 index 000000000..96b7643c9 --- /dev/null +++ b/lib/cache/sfEAcceleratorCache.class.php @@ -0,0 +1,170 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Cache class that stores cached content in EAccelerator. + * + * @author Fabien Potencier + */ +class sfEAcceleratorCache extends sfCache +{ + /** + * Initializes this sfCache instance. + * + * Available options: + * + * * see sfCache for options available for all drivers + * + * @see sfCache + * + * @param array $options + * + * @throws sfInitializationException + */ + public function initialize($options = []) + { + parent::initialize($options); + + if (!function_exists('eaccelerator_put') || !ini_get('eaccelerator.enable')) { + throw new sfInitializationException('You must have EAccelerator installed and enabled to use sfEAcceleratorCache class (or perhaps you forgot to add --with-eaccelerator-shared-memory when installing).'); + } + } + + /** + * @see sfCache + * + * @param string $key + * @param mixed|null $default + * + * @return string|null + */ + public function get($key, $default = null) + { + $value = eaccelerator_get($this->getOption('prefix').$key); + + return null === $value ? $default : $value; + } + + /** + * @see sfCache + * + * @param string $key + * + * @return bool + */ + public function has($key) + { + return null !== eaccelerator_get($this->getOption('prefix'.$key)); + } + + /** + * @see sfCache + * + * @param string $key + * @param string $data + * @param int|null $lifetime + * + * @return bool + */ + public function set($key, $data, $lifetime = null) + { + return eaccelerator_put($this->getOption('prefix').$key, $data, $this->getLifetime($lifetime)); + } + + /** + * @see sfCache + */ + public function remove($key) + { + return eaccelerator_rm($this->getOption('prefix').$key); + } + + /** + * @see sfCache + */ + public function removePattern($pattern) + { + $infos = eaccelerator_list_keys(); + + if (is_array($infos)) { + $regexp = self::patternToRegexp($this->getOption('prefix').$pattern); + + foreach ($infos as $info) { + if (preg_match($regexp, $info['name'])) { + eaccelerator_rm($this->getOption('prefix').$key); + } + } + } + } + + /** + * @see sfCache + */ + public function clean($mode = sfCache::ALL) + { + if (sfCache::OLD === $mode) { + return eaccelerator_gc(); + } + + $infos = eaccelerator_list_keys(); + if (is_array($infos)) { + foreach ($infos as $info) { + if (false !== strpos($info['name'], $this->getOption('prefix'))) { + // eaccelerator bug (http://eaccelerator.net/ticket/287) + $key = 0 === strpos($info['name'], ':') ? substr($info['name'], 1) : $info['name']; + if (!eaccelerator_rm($key)) { + return false; + } + } + } + } + + return true; + } + + /** + * @see sfCache + */ + public function getLastModified($key) + { + if ($info = $this->getCacheInfo($key)) { + return $info['created']; + } + + return 0; + } + + /** + * @see sfCache + */ + public function getTimeout($key) + { + if ($info = $this->getCacheInfo($key)) { + return -1 == $info['ttl'] ? 0 : $info['created'] + $info['ttl']; + } + + return 0; + } + + protected function getCacheInfo($key) + { + $infos = eaccelerator_list_keys(); + + if (is_array($infos)) { + foreach ($infos as $info) { + if ($this->getOption('prefix').$key == $info['name']) { + return $info; + } + } + } + + return null; + } +} diff --git a/lib/cache/sfFileCache.class.php b/lib/cache/sfFileCache.class.php index 4807a493b..cace55f59 100644 --- a/lib/cache/sfFileCache.class.php +++ b/lib/cache/sfFileCache.class.php @@ -32,7 +32,7 @@ class sfFileCache extends sfCache * * @see sfCache */ - public function initialize($options = array()) + public function initialize($options = []) { parent::initialize($options); @@ -105,7 +105,7 @@ public function removePattern($pattern) $pattern = str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $pattern).self::EXTENSION; $regexp = self::patternToRegexp($pattern); - $paths = array(); + $paths = []; foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->getOption('cache_dir'))) as $path) { if (preg_match($regexp, str_replace($this->getOption('cache_dir').DIRECTORY_SEPARATOR, '', $path))) { $paths[] = $path; @@ -262,7 +262,7 @@ protected function write($path, $data, $timeout) $cacheDir = dirname($path); if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) { - throw new \sfCacheException(sprintf('Cache was not able to create a directory "%s".', $cacheDir)); + throw new sfCacheException(sprintf('Cache was not able to create a directory "%s".', $cacheDir)); } $tmpFile = tempnam($cacheDir, basename($path)); diff --git a/lib/cache/sfFunctionCache.class.php b/lib/cache/sfFunctionCache.class.php index e0508fe66..8d890099d 100644 --- a/lib/cache/sfFunctionCache.class.php +++ b/lib/cache/sfFunctionCache.class.php @@ -45,7 +45,7 @@ public function __construct(sfCache $cache) * @throws Exception * @throws sfException */ - public function call($callable, $arguments = array()) + public function call($callable, $arguments = []) { // Generate a cache id $key = $this->computeCacheKey($callable, $arguments); @@ -54,7 +54,7 @@ public function call($callable, $arguments = array()) if (null !== $serialized) { $data = unserialize($serialized); } else { - $data = array(); + $data = []; if (!is_callable($callable)) { throw new sfException('The first argument to call() must be a valid callable.'); @@ -99,7 +99,7 @@ public function getCache() * * @return string The associated cache key */ - public function computeCacheKey($callable, $arguments = array()) + public function computeCacheKey($callable, $arguments = []) { return md5(serialize($callable).serialize($arguments)); } diff --git a/lib/cache/sfMemcacheCache.class.php b/lib/cache/sfMemcacheCache.class.php index 3886a3452..1d948877e 100644 --- a/lib/cache/sfMemcacheCache.class.php +++ b/lib/cache/sfMemcacheCache.class.php @@ -35,7 +35,7 @@ class sfMemcacheCache extends sfCache * * @see sfCache */ - public function initialize($options = array()) + public function initialize($options = []) { parent::initialize($options); @@ -195,7 +195,7 @@ public function removePattern($pattern) */ public function getMany($keys) { - $values = array(); + $values = []; $prefix = $this->getOption('prefix'); $prefixed_keys = array_map(function ($k) use ($prefix) { return $prefix.$k; }, $keys); @@ -226,7 +226,7 @@ protected function getMetadata($key) */ protected function setMetadata($key, $lifetime) { - $this->memcache->set($this->getOption('prefix').'_metadata'.self::SEPARATOR.$key, array('lastModified' => time(), 'timeout' => time() + $lifetime), false, time() + $lifetime); + $this->memcache->set($this->getOption('prefix').'_metadata'.self::SEPARATOR.$key, ['lastModified' => time(), 'timeout' => time() + $lifetime], false, time() + $lifetime); } /** @@ -239,7 +239,7 @@ protected function setCacheInfo($key, $delete = false) { $keys = $this->memcache->get($this->getOption('prefix').'_metadata'); if (!is_array($keys)) { - $keys = array(); + $keys = []; } if ($delete) { @@ -264,7 +264,7 @@ protected function getCacheInfo() { $keys = $this->memcache->get($this->getOption('prefix').'_metadata'); if (!is_array($keys)) { - return array(); + return []; } return $keys; diff --git a/lib/cache/sfSQLiteCache.class.php b/lib/cache/sfSQLiteCache.class.php index 2f6d99ad6..30484ad2d 100644 --- a/lib/cache/sfSQLiteCache.class.php +++ b/lib/cache/sfSQLiteCache.class.php @@ -30,7 +30,7 @@ class sfSQLiteCache extends sfCache * * @see sfCache */ - public function initialize($options = array()) + public function initialize($options = []) { if (!extension_loaded('SQLite') && !extension_loaded('pdo_SQLite')) { throw new sfConfigurationException('sfSQLiteCache class needs "sqlite" or "pdo_sqlite" extension to be loaded.'); @@ -196,8 +196,8 @@ public function removePatternRegexpCallback($regexp, $key) public function getMany($keys) { if ($this->isSqLite3()) { - $data = array(); - if ($results = $this->dbh->query(sprintf("SELECT key, data FROM cache WHERE key IN ('%s') AND timeout > %d", implode('\', \'', array_map(array($this->dbh, 'escapeString'), $keys)), time()))) { + $data = []; + if ($results = $this->dbh->query(sprintf("SELECT key, data FROM cache WHERE key IN ('%s') AND timeout > %d", implode('\', \'', array_map([$this->dbh, 'escapeString'], $keys)), time()))) { while ($row = $results->fetchArray()) { $data[$row['key']] = $row['data']; } @@ -208,7 +208,7 @@ public function getMany($keys) $rows = $this->dbh->arrayQuery(sprintf("SELECT key, data FROM cache WHERE key IN ('%s') AND timeout > %d", implode('\', \'', array_map('sqlite_escape_string', $keys)), time())); - $data = array(); + $data = []; foreach ($rows as $row) { $data[$row['key']] = $row['data']; } @@ -255,7 +255,7 @@ protected function setDatabase($database) } } - $this->dbh->createFunction('regexp', array($this, 'removePatternRegexpCallback'), 2); + $this->dbh->createFunction('regexp', [$this, 'removePatternRegexpCallback'], 2); if ($new) { $this->createSchema(); @@ -269,7 +269,7 @@ protected function setDatabase($database) */ protected function createSchema() { - $statements = array( + $statements = [ 'CREATE TABLE [cache] ( [key] VARCHAR(255), [data] LONGVARCHAR, @@ -277,7 +277,7 @@ protected function createSchema() [last_modified] TIMESTAMP )', 'CREATE UNIQUE INDEX [cache_unique] ON [cache] ([key])', - ); + ]; foreach ($statements as $statement) { if (false === $this->dbh->query($statement)) { diff --git a/lib/cache/sfXCacheCache.class.php b/lib/cache/sfXCacheCache.class.php new file mode 100644 index 000000000..aaecf81ef --- /dev/null +++ b/lib/cache/sfXCacheCache.class.php @@ -0,0 +1,201 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Cache class that stores cached content in XCache. + * + * @author Fabien Potencier + */ +class sfXCacheCache extends sfCache +{ + /** + * Initializes this sfCache instance. + * + * Available options: + * + * * see sfCache for options available for all drivers + * + * @see sfCache + */ + public function initialize($options = []) + { + parent::initialize($options); + + if (!function_exists('xcache_set')) { + throw new sfInitializationException('You must have XCache installed and enabled to use sfXCacheCache class.'); + } + + if (!ini_get('xcache.var_size')) { + throw new sfInitializationException('You must set the "xcache.var_size" variable to a value greater than 0 to use sfXCacheCache class.'); + } + } + + /** + * @see sfCache + * + * @param mixed|null $default + */ + public function get($key, $default = null) + { + $set = $this->getBaseValue($key); + + if (!is_array($set) || !array_key_exists('data', $set)) { + return $default; + } + + return $set['data']; + } + + /** + * @see sfCache + */ + public function has($key) + { + return xcache_isset($this->getOption('prefix').$key); + } + + /** + * @see sfCache + * + * @param mixed|null $lifetime + */ + public function set($key, $data, $lifetime = null) + { + $lifetime = $this->getLifetime($lifetime); + + $set = [ + 'timeout' => time() + $lifetime, + 'data' => $data, + 'ctime' => time(), + ]; + + return xcache_set($this->getOption('prefix').$key, $set, $lifetime); + } + + /** + * @see sfCache + */ + public function remove($key) + { + return xcache_unset($this->getOption('prefix').$key); + } + + /** + * @see sfCache + */ + public function clean($mode = sfCache::ALL) + { + if (sfCache::ALL !== $mode) { + return true; + } + + $this->checkAuth(); + + for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; ++$i) { + if (false === xcache_clear_cache(XC_TYPE_VAR, $i)) { + return false; + } + } + + return true; + } + + /** + * @see sfCache + */ + public function getLastModified($key) + { + $set = $this->getBaseValue($key); + + if (!is_array($set) || !array_key_exists('ctime', $set)) { + return 0; + } + + return $set['ctime']; + } + + /** + * @see sfCache + */ + public function getTimeout($key) + { + $set = $this->getBaseValue($key); + + if (!is_array($set) || !array_key_exists('timeout', $set)) { + return 0; + } + + return $set['timeout']; + } + + /** + * @param string $key + * + * @return mixed|null + */ + public function getBaseValue($key) + { + return xcache_isset($this->getOption('prefix').$key) ? xcache_get($this->getOption('prefix').$key) : null; + } + + /** + * @see sfCache + */ + public function removePattern($pattern) + { + $this->checkAuth(); + + $regexp = self::patternToRegexp($this->getOption('prefix').$pattern); + + for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; ++$i) { + $infos = xcache_list(XC_TYPE_VAR, $i); + if (!is_array($infos['cache_list'])) { + return; + } + + foreach ($infos['cache_list'] as $info) { + if (preg_match($regexp, $info['name'])) { + xcache_unset($info['name']); + } + } + } + } + + /** + * @param string $key + * + * @return array|null + */ + public function getCacheInfo($key) + { + $this->checkAuth(); + + for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; ++$i) { + $infos = xcache_list(XC_TYPE_VAR, $i); + + if (is_array($infos['cache_list'])) { + foreach ($infos['cache_list'] as $info) { + if ($this->getOption('prefix').$key == $info['name']) { + return $info; + } + } + } + } + + return null; + } + + protected function checkAuth() + { + if (ini_get('xcache.admin.enable_auth')) { + throw new sfConfigurationException('To use all features of the "sfXCacheCache" class, you must set "xcache.admin.enable_auth" to "Off" in your php.ini.'); + } + } +} diff --git a/lib/command/cli.php b/lib/command/cli.php index 8b423443c..e5f6904e9 100644 --- a/lib/command/cli.php +++ b/lib/command/cli.php @@ -25,7 +25,7 @@ $dispatcher = new sfEventDispatcher(); $logger = new sfCommandLogger($dispatcher); - $application = new sfSymfonyCommandApplication($dispatcher, null, array('symfony_lib_dir' => realpath(__DIR__.'/..'))); + $application = new sfSymfonyCommandApplication($dispatcher, null, ['symfony_lib_dir' => realpath(__DIR__.'/..')]); $statusCode = $application->run(); } catch (Exception $e) { if (!isset($application)) { diff --git a/lib/command/sfAnsiColorFormatter.class.php b/lib/command/sfAnsiColorFormatter.class.php index 14ce12586..6bb298b84 100644 --- a/lib/command/sfAnsiColorFormatter.class.php +++ b/lib/command/sfAnsiColorFormatter.class.php @@ -15,15 +15,15 @@ */ class sfAnsiColorFormatter extends sfFormatter { - protected $styles = array( - 'ERROR' => array('bg' => 'red', 'fg' => 'white', 'bold' => true), - 'INFO' => array('fg' => 'green', 'bold' => true), - 'COMMENT' => array('fg' => 'yellow'), - 'QUESTION' => array('bg' => 'cyan', 'fg' => 'black', 'bold' => false), - ); - protected $options = array('bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8); - protected $foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37); - protected $background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47); + protected $styles = [ + 'ERROR' => ['bg' => 'red', 'fg' => 'white', 'bold' => true], + 'INFO' => ['fg' => 'green', 'bold' => true], + 'COMMENT' => ['fg' => 'yellow'], + 'QUESTION' => ['bg' => 'cyan', 'fg' => 'black', 'bold' => false], + ]; + protected $options = ['bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8]; + protected $foreground = ['black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37]; + protected $background = ['black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47]; /** * Sets a new style. @@ -31,7 +31,7 @@ class sfAnsiColorFormatter extends sfFormatter * @param string $name The style name * @param array $options An array of options */ - public function setStyle($name, $options = array()) + public function setStyle($name, $options = []) { $this->styles[$name] = $options; } @@ -44,7 +44,7 @@ public function setStyle($name, $options = array()) * * @return string The styled text */ - public function format($text = '', $parameters = array()) + public function format($text = '', $parameters = []) { if (!is_array($parameters) && 'NONE' == $parameters) { return $text; @@ -54,7 +54,7 @@ public function format($text = '', $parameters = array()) $parameters = $this->styles[$parameters]; } - $codes = array(); + $codes = []; if (isset($parameters['fg'])) { $codes[] = $this->foreground[$parameters['fg']]; } diff --git a/lib/command/sfCommandApplication.class.php b/lib/command/sfCommandApplication.class.php index ea05eef59..15bad631d 100644 --- a/lib/command/sfCommandApplication.class.php +++ b/lib/command/sfCommandApplication.class.php @@ -37,7 +37,7 @@ abstract class sfCommandApplication protected $version = 'UNKNOWN'; /** @var array */ - protected $tasks = array(); + protected $tasks = []; /** @var sfTask */ protected $currentTask; @@ -46,7 +46,7 @@ abstract class sfCommandApplication protected $dispatcher; /** @var array */ - protected $options = array(); + protected $options = []; /** @var sfFormatter */ protected $formatter; @@ -60,7 +60,7 @@ abstract class sfCommandApplication * @param sfFormatter $formatter A sfFormatter instance * @param array $options An array of options */ - public function __construct(sfEventDispatcher $dispatcher, sfFormatter $formatter = null, $options = array()) + public function __construct(sfEventDispatcher $dispatcher, ?sfFormatter $formatter = null, $options = []) { $this->dispatcher = $dispatcher; $this->formatter = null === $formatter ? $this->guessBestFormatter(STDOUT) : $formatter; @@ -68,17 +68,17 @@ public function __construct(sfEventDispatcher $dispatcher, sfFormatter $formatte $this->fixCgi(); - $argumentSet = new sfCommandArgumentSet(array( + $argumentSet = new sfCommandArgumentSet([ new sfCommandArgument('task', sfCommandArgument::REQUIRED, 'The task to execute'), - )); - $optionSet = new sfCommandOptionSet(array( + ]); + $optionSet = new sfCommandOptionSet([ new sfCommandOption('--help', '-H', sfCommandOption::PARAMETER_NONE, 'Display this help message.'), new sfCommandOption('--quiet', '-q', sfCommandOption::PARAMETER_NONE, 'Do not log messages to standard output.'), new sfCommandOption('--trace', '-t', sfCommandOption::PARAMETER_NONE, 'Turn on invoke/execute tracing, enable full backtrace.'), new sfCommandOption('--version', '-V', sfCommandOption::PARAMETER_NONE, 'Display the program version.'), new sfCommandOption('--color', '', sfCommandOption::PARAMETER_NONE, 'Forces ANSI color output.'), new sfCommandOption('--no-debug', '', sfCommandOption::PARAMETER_NONE, 'Disable debug'), - )); + ]); $this->commandManager = new sfCommandManager($argumentSet, $optionSet); $this->configure(); @@ -129,7 +129,7 @@ public function setFormatter(sfFormatter $formatter) public function clearTasks() { - $this->tasks = array(); + $this->tasks = []; } /** @@ -181,7 +181,7 @@ public function registerTask(sfTask $task) */ public function autodiscoverTasks() { - $tasks = array(); + $tasks = []; foreach (get_declared_classes() as $class) { $r = new ReflectionClass($class); @@ -327,11 +327,11 @@ public function isDebug() */ public function help() { - $messages = array( + $messages = [ $this->formatter->format('Usage:', 'COMMENT'), sprintf(" %s [options] task_name [arguments]\n", $this->getName()), $this->formatter->format('Options:', 'COMMENT'), - ); + ]; foreach ($this->commandManager->getOptionSet()->getOptions() as $option) { $messages[] = sprintf( @@ -354,13 +354,13 @@ public function renderException($e) { $title = sprintf(' [%s] ', get_class($e)); $len = $this->strlen($title); - $lines = array(); + $lines = []; foreach (explode("\n", $e->getMessage()) as $line) { $lines[] = sprintf(' %s ', $line); $len = max($this->strlen($line) + 4, $len); } - $messages = array(str_repeat(' ', $len)); + $messages = [str_repeat(' ', $len)]; if ($this->trace) { $messages[] = $title.str_repeat(' ', $len - $this->strlen($title)); @@ -388,12 +388,12 @@ public function renderException($e) // exception related properties $trace = $e->getTrace(); - array_unshift($trace, array( + array_unshift($trace, [ 'function' => '', 'file' => null != $e->getFile() ? $e->getFile() : 'n/a', 'line' => null != $e->getLine() ? $e->getLine() : 'n/a', - 'args' => array(), - )); + 'args' => [], + ]); for ($i = 0, $count = count($trace); $i < $count; ++$i) { $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : ''; @@ -427,7 +427,7 @@ public function getTaskToExecute($name) $namespace = substr($name, 0, $pos); $name = substr($name, $pos + 1); - $namespaces = array(); + $namespaces = []; foreach ($this->tasks as $task) { if ($task->getNamespace() && !in_array($task->getNamespace(), $namespaces)) { $namespaces[] = $task->getNamespace(); @@ -448,7 +448,7 @@ public function getTaskToExecute($name) } // name - $tasks = array(); + $tasks = []; foreach ($this->tasks as $taskName => $task) { if ($taskName == $task->getFullName() && $task->getNamespace() == $namespace) { $tasks[] = $task->getName(); @@ -461,7 +461,7 @@ public function getTaskToExecute($name) } // aliases - $aliases = array(); + $aliases = []; foreach ($this->tasks as $taskName => $task) { if ($taskName == $task->getFullName()) { foreach ($task->getAliases() as $alias) { @@ -592,8 +592,8 @@ protected function fixCgi() */ protected function getAbbreviations($names) { - $abbrevs = array(); - $table = array(); + $abbrevs = []; + $table = []; foreach ($names as $name) { for ($len = strlen($name) - 1; $len > 0; --$len) { @@ -607,7 +607,7 @@ protected function getAbbreviations($names) $seen = $table[$abbrev]; if (1 == $seen) { // We're the first word so far to have this abbreviation. - $abbrevs[$abbrev] = array($name); + $abbrevs[$abbrev] = [$name]; } elseif (2 == $seen) { // We're the second word to have this abbreviation, so we can't use it. // unset($abbrevs[$abbrev]); @@ -621,7 +621,7 @@ protected function getAbbreviations($names) // Non-abbreviations always get entered, even if they aren't unique foreach ($names as $name) { - $abbrevs[$name] = array($name); + $abbrevs[$name] = [$name]; } return $abbrevs; diff --git a/lib/command/sfCommandArgument.class.php b/lib/command/sfCommandArgument.class.php index 470a9e707..3d6d2515c 100644 --- a/lib/command/sfCommandArgument.class.php +++ b/lib/command/sfCommandArgument.class.php @@ -95,7 +95,7 @@ public function setDefault($default = null) if ($this->isArray()) { if (null === $default) { - $default = array(); + $default = []; } elseif (!is_array($default)) { throw new sfCommandException('A default value for an array argument must be an array.'); } diff --git a/lib/command/sfCommandArgumentSet.class.php b/lib/command/sfCommandArgumentSet.class.php index efdd0b012..3e7f882d3 100644 --- a/lib/command/sfCommandArgumentSet.class.php +++ b/lib/command/sfCommandArgumentSet.class.php @@ -15,7 +15,7 @@ */ class sfCommandArgumentSet { - protected $arguments = array(); + protected $arguments = []; protected $requiredCount = 0; protected $hasAnArrayArgument = false; protected $hasOptional = false; @@ -25,7 +25,7 @@ class sfCommandArgumentSet * * @param array $arguments An array of sfCommandArgument objects */ - public function __construct($arguments = array()) + public function __construct($arguments = []) { $this->setArguments($arguments); } @@ -35,9 +35,9 @@ public function __construct($arguments = array()) * * @param array $arguments An array of sfCommandArgument objects */ - public function setArguments($arguments = array()) + public function setArguments($arguments = []) { - $this->arguments = array(); + $this->arguments = []; $this->requiredCount = 0; $this->hasOptional = false; $this->addArguments($arguments); @@ -48,7 +48,7 @@ public function setArguments($arguments = array()) * * @param array $arguments An array of sfCommandArgument objects */ - public function addArguments($arguments = array()) + public function addArguments($arguments = []) { if (null !== $arguments) { foreach ($arguments as $argument) { @@ -158,7 +158,7 @@ public function getArgumentRequiredCount() */ public function getDefaults() { - $values = array(); + $values = []; foreach ($this->arguments as $argument) { $values[$argument->getName()] = $argument->getDefault(); } diff --git a/lib/command/sfCommandLogger.class.php b/lib/command/sfCommandLogger.class.php index 2233d2637..77673b5c1 100644 --- a/lib/command/sfCommandLogger.class.php +++ b/lib/command/sfCommandLogger.class.php @@ -19,9 +19,9 @@ class sfCommandLogger extends sfConsoleLogger * @param sfEventDispatcher $dispatcher A sfEventDispatcher instance * @param array $options an array of options */ - public function initialize(sfEventDispatcher $dispatcher, $options = array()) + public function initialize(sfEventDispatcher $dispatcher, $options = []) { - $dispatcher->connect('command.log', array($this, 'listenToLogEvent')); + $dispatcher->connect('command.log', [$this, 'listenToLogEvent']); return parent::initialize($dispatcher, $options); } diff --git a/lib/command/sfCommandManager.class.php b/lib/command/sfCommandManager.class.php index 2225a0ac8..aea4b6bf3 100644 --- a/lib/command/sfCommandManager.class.php +++ b/lib/command/sfCommandManager.class.php @@ -19,22 +19,22 @@ class sfCommandManager protected $arguments = ''; /** @var string[] */ - protected $errors = array(); + protected $errors = []; /** @var sfCommandOptionSet */ protected $optionSet; /** @var sfCommandArgumentSet */ - protected $argumentSet = array(); + protected $argumentSet = []; /** @var array */ - protected $optionValues = array(); + protected $optionValues = []; /** @var array */ - protected $argumentValues = array(); + protected $argumentValues = []; /** @var array */ - protected $parsedArgumentValues = array(); + protected $parsedArgumentValues = []; /** * Constructor. @@ -42,7 +42,7 @@ class sfCommandManager * @param sfCommandArgumentSet $argumentSet A sfCommandArgumentSet object * @param sfCommandOptionSet $optionSet A setOptionSet object */ - public function __construct(sfCommandArgumentSet $argumentSet = null, sfCommandOptionSet $optionSet = null) + public function __construct(?sfCommandArgumentSet $argumentSet = null, ?sfCommandOptionSet $optionSet = null) { if (null === $argumentSet) { $argumentSet = new sfCommandArgumentSet(); @@ -121,10 +121,10 @@ public function process($arguments = null) $this->arguments = $arguments; $this->optionValues = $this->optionSet->getDefaults(); $this->argumentValues = $this->argumentSet->getDefaults(); - $this->parsedArgumentValues = array(); - $this->errors = array(); + $this->parsedArgumentValues = []; + $this->errors = []; - while (!in_array($argument = array_shift($this->arguments), array('', null))) { + while (!in_array($argument = array_shift($this->arguments), ['', null])) { if ('--' == $argument) { // stop options parsing $this->parsedArgumentValues = array_merge($this->parsedArgumentValues, $this->arguments); diff --git a/lib/command/sfCommandOption.class.php b/lib/command/sfCommandOption.class.php index 6cdf8f6c7..d525aa7e9 100644 --- a/lib/command/sfCommandOption.class.php +++ b/lib/command/sfCommandOption.class.php @@ -143,7 +143,7 @@ public function setDefault($default = null) if ($this->isArray()) { if (null === $default) { - $default = array(); + $default = []; } elseif (!is_array($default)) { throw new sfCommandException('A default value for an array option must be an array.'); } diff --git a/lib/command/sfCommandOptionSet.class.php b/lib/command/sfCommandOptionSet.class.php index fe4a3ce4a..e8e00cb57 100644 --- a/lib/command/sfCommandOptionSet.class.php +++ b/lib/command/sfCommandOptionSet.class.php @@ -15,15 +15,15 @@ */ class sfCommandOptionSet { - protected $options = array(); - protected $shortcuts = array(); + protected $options = []; + protected $shortcuts = []; /** * Constructor. * * @param array $options An array of sfCommandOption objects */ - public function __construct($options = array()) + public function __construct($options = []) { $this->setOptions($options); } @@ -33,10 +33,10 @@ public function __construct($options = array()) * * @param array $options An array of sfCommandOption objects */ - public function setOptions($options = array()) + public function setOptions($options = []) { - $this->options = array(); - $this->shortcuts = array(); + $this->options = []; + $this->shortcuts = []; $this->addOptions($options); } @@ -45,7 +45,7 @@ public function setOptions($options = array()) * * @param array $options An array of sfCommandOption objects */ - public function addOptions($options = array()) + public function addOptions($options = []) { foreach ($options as $option) { $this->addOption($option); @@ -145,7 +145,7 @@ public function getOptionForShortcut($shortcut) */ public function getDefaults() { - $values = array(); + $values = []; foreach ($this->options as $option) { $values[$option->getName()] = $option->getDefault(); } diff --git a/lib/command/sfFormatter.class.php b/lib/command/sfFormatter.class.php index bc8ba4924..d37829c87 100644 --- a/lib/command/sfFormatter.class.php +++ b/lib/command/sfFormatter.class.php @@ -37,7 +37,7 @@ public function __construct($maxLineSize = null) * @param string $name The style name * @param array $options An array of options */ - public function setStyle($name, $options = array()) + public function setStyle($name, $options = []) { } @@ -49,7 +49,7 @@ public function setStyle($name, $options = array()) * * @return string The formatted text */ - public function format($text = '', $parameters = array()) + public function format($text = '', $parameters = []) { return $text; } diff --git a/lib/command/sfSymfonyCommandApplication.class.php b/lib/command/sfSymfonyCommandApplication.class.php index 29ac90e85..bec81a576 100644 --- a/lib/command/sfSymfonyCommandApplication.class.php +++ b/lib/command/sfSymfonyCommandApplication.class.php @@ -15,7 +15,7 @@ */ class sfSymfonyCommandApplication extends sfCommandApplication { - protected $taskFiles = array(); + protected $taskFiles = []; /** * Configures the current symfony command application. @@ -81,7 +81,7 @@ public function run($options = null) public function loadTasks(sfProjectConfiguration $configuration) { // Symfony core tasks - $dirs = array(sfConfig::get('sf_symfony_lib_dir').'/task'); + $dirs = [sfConfig::get('sf_symfony_lib_dir').'/task']; // Plugin tasks foreach ($configuration->getPluginPaths() as $path) { @@ -99,7 +99,7 @@ public function loadTasks(sfProjectConfiguration $configuration) } // register local autoloader for tasks - spl_autoload_register(array($this, 'autoloadTask')); + spl_autoload_register([$this, 'autoloadTask']); // require tasks foreach ($this->taskFiles as $task => $file) { @@ -108,7 +108,7 @@ class_exists($task, true); } // unregister local autoloader - spl_autoload_unregister(array($this, 'autoloadTask')); + spl_autoload_unregister([$this, 'autoloadTask']); } /** diff --git a/lib/config/sfApplicationConfiguration.class.php b/lib/config/sfApplicationConfiguration.class.php index 0baa1a595..cab2df13c 100644 --- a/lib/config/sfApplicationConfiguration.class.php +++ b/lib/config/sfApplicationConfiguration.class.php @@ -16,13 +16,13 @@ abstract class sfApplicationConfiguration extends ProjectConfiguration { protected static $coreLoaded = false; - protected static $loadedHelpers = array(); + protected static $loadedHelpers = []; protected $configCache; protected $application; protected $environment; protected $debug = false; - protected $config = array(); + protected $config = []; protected $cache; /** @@ -33,7 +33,7 @@ abstract class sfApplicationConfiguration extends ProjectConfiguration * @param string $rootDir The project root directory * @param sfEventDispatcher $dispatcher An event dispatcher */ - public function __construct($environment, $debug, $rootDir = null, sfEventDispatcher $dispatcher = null) + public function __construct($environment, $debug, $rootDir = null, ?sfEventDispatcher $dispatcher = null) { $this->environment = $environment; $this->debug = (bool) $debug; @@ -101,7 +101,7 @@ public function initConfiguration() } // autoloader(s) - $this->dispatcher->connect('autoload.filter_config', array($this, 'filterAutoloadConfig')); + $this->dispatcher->connect('autoload.filter_config', [$this, 'filterAutoloadConfig']); sfAutoload::getInstance()->register(); if ($this->isDebug()) { sfAutoloadAgain::getInstance()->register(); @@ -135,7 +135,7 @@ public function initConfiguration() // the error log, then errors are displayed (display_errors is set to 1). if ( !$this->isDebug() - || !in_array(PHP_SAPI, array('cli', 'phpdbg', 'embed'), true) + || !in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ) { ini_set('display_errors', 0); } elseif ( @@ -196,12 +196,12 @@ public function checkLock() || $this->hasLockFile(sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.$this->getApplication().'_'.$this->getEnvironment().'.lck') ) { // application is not available - we'll find the most specific unavailable page... - $files = array( + $files = [ sfConfig::get('sf_app_config_dir').'/unavailable.php', sfConfig::get('sf_config_dir').'/unavailable.php', sfConfig::get('sf_web_dir').'/errors/unavailable.php', $this->getSymfonyLibDir().'/exception/data/unavailable.php', - ); + ]; foreach ($files as $file) { if (is_readable($file)) { @@ -227,12 +227,12 @@ public function setRootDir($rootDir) { parent::setRootDir($rootDir); - sfConfig::add(array( + sfConfig::add([ 'sf_app' => $this->getApplication(), 'sf_environment' => $this->getEnvironment(), 'sf_debug' => $this->isDebug(), 'sf_cli' => PHP_SAPI === 'cli', - )); + ]); $this->setAppDir(sfConfig::get('sf_apps_dir').DIRECTORY_SEPARATOR.$this->getApplication()); } @@ -244,7 +244,7 @@ public function setRootDir($rootDir) */ public function setAppDir($appDir) { - sfConfig::add(array( + sfConfig::add([ 'sf_app_dir' => $appDir, // SF_APP_DIR directory structure @@ -253,7 +253,7 @@ public function setAppDir($appDir) 'sf_app_module_dir' => $appDir.DIRECTORY_SEPARATOR.'modules', 'sf_app_template_dir' => $appDir.DIRECTORY_SEPARATOR.'templates', 'sf_app_i18n_dir' => $appDir.DIRECTORY_SEPARATOR.'i18n', - )); + ]); } /** @@ -263,7 +263,7 @@ public function setCacheDir($cacheDir) { parent::setCacheDir($cacheDir); - sfConfig::add(array( + sfConfig::add([ 'sf_app_base_cache_dir' => $cacheDir.DIRECTORY_SEPARATOR.$this->getApplication(), 'sf_app_cache_dir' => $appCacheDir = $cacheDir.DIRECTORY_SEPARATOR.$this->getApplication().DIRECTORY_SEPARATOR.$this->getEnvironment(), @@ -273,7 +273,7 @@ public function setCacheDir($cacheDir) 'sf_config_cache_dir' => $appCacheDir.DIRECTORY_SEPARATOR.'config', 'sf_test_cache_dir' => $appCacheDir.DIRECTORY_SEPARATOR.'test', 'sf_module_cache_dir' => $appCacheDir.DIRECTORY_SEPARATOR.'modules', - )); + ]); } /** @@ -286,7 +286,7 @@ public function setCacheDir($cacheDir) public function getControllerDirs($moduleName) { if (!isset($this->cache['getControllerDirs'][$moduleName])) { - $dirs = array(); + $dirs = []; $dirs[sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/actions'] = false; // application @@ -315,7 +315,7 @@ public function getControllerDirs($moduleName) */ public function getLibDirs($moduleName) { - $dirs = array(); + $dirs = []; $dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/lib'; // application $dirs = array_merge($dirs, $this->getPluginSubPaths('/modules/'.$moduleName.'/lib')); // plugins @@ -334,7 +334,7 @@ public function getLibDirs($moduleName) */ public function getTemplateDirs($moduleName) { - $dirs = array(); + $dirs = []; $dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/templates'; // application $dirs = array_merge($dirs, $this->getPluginSubPaths('/modules/'.$moduleName.'/templates')); // plugins @@ -353,7 +353,7 @@ public function getTemplateDirs($moduleName) */ public function getHelperDirs($moduleName = '') { - $dirs = array(); + $dirs = []; if ($moduleName) { $dirs[] = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/lib/helper'; // module @@ -363,12 +363,12 @@ public function getHelperDirs($moduleName = '') return array_merge( $dirs, - array( + [ sfConfig::get('sf_app_lib_dir').'/helper', // application sfConfig::get('sf_lib_dir').'/helper', // project - ), + ], $this->getPluginSubPaths('/lib/helper'), // plugins - array($this->getSymfonyLibDir().'/helper') // symfony + [$this->getSymfonyLibDir().'/helper'] // symfony ); } @@ -430,7 +430,7 @@ public function getPluginPaths() */ public function getDecoratorDirs() { - return array(sfConfig::get('sf_app_template_dir')); + return [sfConfig::get('sf_app_template_dir')]; } /** @@ -456,7 +456,7 @@ public function getDecoratorDir($template) */ public function getI18NGlobalDirs() { - $dirs = array(); + $dirs = []; // application if (is_dir($dir = sfConfig::get('sf_app_i18n_dir'))) { @@ -476,7 +476,7 @@ public function getI18NGlobalDirs() */ public function getI18NDirs($moduleName) { - $dirs = array(); + $dirs = []; // module if (is_dir($dir = sfConfig::get('sf_app_module_dir').'/'.$moduleName.'/i18n')) { @@ -506,9 +506,9 @@ public function getConfigPaths($configPath) { $globalConfigPath = basename(dirname($configPath)).'/'.basename($configPath); - $files = array( + $files = [ $this->getSymfonyLibDir().'/config/'.$globalConfigPath, // symfony - ); + ]; foreach ($this->getPluginPaths() as $path) { if (is_file($file = $path.'/'.$globalConfigPath)) { @@ -516,12 +516,12 @@ public function getConfigPaths($configPath) } } - $files = array_merge($files, array( + $files = array_merge($files, [ $this->getRootDir().'/'.$globalConfigPath, // project $this->getRootDir().'/'.$configPath, // project sfConfig::get('sf_app_dir').'/'.$globalConfigPath, // application sfConfig::get('sf_app_cache_dir').'/'.$configPath, // generated modules - )); + ]); foreach ($this->getPluginPaths() as $path) { if (is_file($file = $path.'/'.$configPath)) { @@ -531,7 +531,7 @@ public function getConfigPaths($configPath) $files[] = sfConfig::get('sf_app_dir').'/'.$configPath; // module - $configs = array(); + $configs = []; foreach (array_unique($files) as $file) { if (is_readable($file)) { $configs[] = $file; @@ -576,7 +576,7 @@ public function loadHelpers($helpers, $moduleName = '') } if (!$included) { - throw new InvalidArgumentException(sprintf('Unable to load "%sHelper.php" helper in: %s.', $helperName, implode(', ', array_map(array('sfDebug', 'shortenFilePath'), $dirs)))); + throw new InvalidArgumentException(sprintf('Unable to load "%sHelper.php" helper in: %s.', $helperName, implode(', ', array_map(['sfDebug', 'shortenFilePath'], $dirs)))); } } diff --git a/lib/config/sfAutoloadConfigHandler.class.php b/lib/config/sfAutoloadConfigHandler.class.php index e307aea15..2b7cb7a5c 100755 --- a/lib/config/sfAutoloadConfigHandler.class.php +++ b/lib/config/sfAutoloadConfigHandler.class.php @@ -28,9 +28,9 @@ class sfAutoloadConfigHandler extends sfYamlConfigHandler public function execute($configFiles) { // set our required categories list and initialize our handler - $this->initialize(array('required_categories' => array('autoload'))); + $this->initialize(['required_categories' => ['autoload']]); - $data = array(); + $data = []; foreach ($this->parse($configFiles) as $name => $mapping) { $data[] = sprintf("\n // %s", $name); @@ -51,7 +51,7 @@ public function execute($configFiles) public function evaluate($configFiles) { - $mappings = array(); + $mappings = []; foreach ($this->parse($configFiles) as $mapping) { foreach ($mapping as $class => $file) { $mappings[$class] = $file; @@ -63,7 +63,7 @@ public function evaluate($configFiles) public static function parseFile($path, $file, $prefix) { - $mapping = array(); + $mapping = []; preg_match_all('~^\s*(?:abstract\s+|final\s+)?(?:class|interface|trait)\s+(\w+)~mi', file_get_contents($file), $classes); foreach ($classes[1] as $class) { $localPrefix = ''; @@ -89,7 +89,7 @@ public static function getConfiguration(array $configFiles) $configuration = sfProjectConfiguration::getActive(); $pluginPaths = $configuration->getPluginPaths(); - $pluginConfigFiles = array(); + $pluginConfigFiles = []; // move plugin files to front foreach ($configFiles as $i => $configFile) { @@ -122,9 +122,9 @@ protected function parse(array $configFiles) // parse the yaml $config = static::getConfiguration($configFiles); - $mappings = array(); + $mappings = []; foreach ($config['autoload'] as $name => $entry) { - $mapping = array(); + $mapping = []; // file mapping or directory mapping? if (isset($entry['files'])) { diff --git a/lib/config/sfCacheConfigHandler.class.php b/lib/config/sfCacheConfigHandler.class.php index 6e1ca0ce8..b531d9555 100644 --- a/lib/config/sfCacheConfigHandler.class.php +++ b/lib/config/sfCacheConfigHandler.class.php @@ -15,7 +15,7 @@ */ class sfCacheConfigHandler extends sfYamlConfigHandler { - protected $cacheConfig = array(); + protected $cacheConfig = []; /** * Executes this configuration handler. @@ -34,7 +34,7 @@ public function execute($configFiles) $this->yamlConfig = static::getConfiguration($configFiles); // iterate through all action names - $data = array(); + $data = []; $first = true; foreach ($this->yamlConfig as $actionName => $values) { if ('all' == $actionName) { @@ -78,7 +78,7 @@ public static function getConfiguration(array $configFiles) */ protected function addCache($actionName = '') { - $data = array(); + $data = []; // enabled? $enabled = $this->getConfigValue('enabled', $actionName); @@ -96,9 +96,9 @@ protected function addCache($actionName = '') $contextual = $this->getConfigValue('contextual', $actionName) ? 'true' : 'false'; // vary - $vary = $this->getConfigValue('vary', $actionName, array()); + $vary = $this->getConfigValue('vary', $actionName, []); if (!is_array($vary)) { - $vary = array($vary); + $vary = [$vary]; } // add cache information to cache manager diff --git a/lib/config/sfCompileConfigHandler.class.php b/lib/config/sfCompileConfigHandler.class.php index 5a70c27ce..7bbd8cffb 100644 --- a/lib/config/sfCompileConfigHandler.class.php +++ b/lib/config/sfCompileConfigHandler.class.php @@ -51,13 +51,13 @@ public function execute($configFiles) } // strip php tags - $contents = sfToolkit::pregtr($contents, array('/^\s*<\?(php\s*)?/m' => '', '/^\s*\?>/m' => '')); + $contents = sfToolkit::pregtr($contents, ['/^\s*<\?(php\s*)?/m' => '', '/^\s*\?>/m' => '']); // replace windows and mac format with unix format $contents = str_replace("\r", "\n", $contents); // replace multiple new lines with a single newline - $contents = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $contents); + $contents = preg_replace(['/\s+$/Sm', '/\n+/S'], "\n", $contents); // append file data $data .= "\n".$contents; @@ -79,7 +79,7 @@ public function execute($configFiles) */ public static function getConfiguration(array $configFiles) { - $config = array(); + $config = []; foreach ($configFiles as $configFile) { $config = array_merge($config, static::parseYaml($configFile)); } diff --git a/lib/config/sfConfig.class.php b/lib/config/sfConfig.class.php index 40e160fca..2ad673ea7 100644 --- a/lib/config/sfConfig.class.php +++ b/lib/config/sfConfig.class.php @@ -15,7 +15,7 @@ */ class sfConfig { - protected static $config = array(); + protected static $config = []; /** * Retrieves a config parameter. @@ -63,7 +63,7 @@ public static function set($name, $value) * * @param array $parameters An associative array of config parameters and their associated values */ - public static function add($parameters = array()) + public static function add($parameters = []) { self::$config = array_merge(self::$config, $parameters); } @@ -83,6 +83,6 @@ public static function getAll() */ public static function clear() { - self::$config = array(); + self::$config = []; } } diff --git a/lib/config/sfConfigCache.class.php b/lib/config/sfConfigCache.class.php index e7c1dea01..23de85854 100644 --- a/lib/config/sfConfigCache.class.php +++ b/lib/config/sfConfigCache.class.php @@ -20,8 +20,8 @@ class sfConfigCache { protected $configuration; - protected $handlers = array(); - protected $userHandlers = array(); + protected $handlers = []; + protected $userHandlers = []; /** * Constructor. @@ -67,7 +67,7 @@ public function checkConfig($configPath, $optional = false) if (!sfToolkit::isPathAbsolute($configPath)) { $files = $this->configuration->getConfigPaths($configPath); } else { - $files = is_readable($configPath) ? array($configPath) : array(); + $files = is_readable($configPath) ? [$configPath] : []; } if (!isset($files[0])) { @@ -123,7 +123,7 @@ public function getCacheName($config) } // replace unfriendly filename characters with an underscore - $config = str_replace(array('\\', '/', ' '), '_', $config); + $config = str_replace(['\\', '/', ' '], '_', $config); $config .= '.php'; return sfConfig::get('sf_config_cache_dir').'/'.$config; @@ -161,7 +161,7 @@ public function import($config, $once = true, $optional = false) * @param class $class A configuration handler class * @param string $params An array of options for the handler class initialization */ - public function registerConfigHandler($handler, $class, $params = array()) + public function registerConfigHandler($handler, $class, $params = []) { $this->userHandlers[$handler] = new $class($params); } @@ -204,8 +204,8 @@ protected function callHandler($handler, $configs, $cache) // let's see if we have any wildcard handlers registered that match this basename foreach (array_keys($this->handlers) as $key) { // replace wildcard chars in the configuration - $pattern = strtr($key, array('.' => '\.', '*' => '(.*?)')); - $matches = array(); + $pattern = strtr($key, ['.' => '\.', '*' => '(.*?)']); + $matches = []; // create pattern from config if (preg_match('#'.$pattern.'$#', $handler, $matches)) { @@ -268,7 +268,7 @@ protected function loadConfigHandlers() } // ignore names - $ignore = array('.', '..', 'CVS', '.svn'); + $ignore = ['.', '..', 'CVS', '.svn']; // create a file pointer to the module dir $fp = opendir($sf_app_module_dir); @@ -283,7 +283,7 @@ protected function loadConfigHandlers() if (is_readable($configPath)) { // initialize the root configuration handler with this module name - $params = array('module_level' => true, 'module_name' => $directory); + $params = ['module_level' => true, 'module_name' => $directory]; $this->handlers['config_handlers.yml']->initialize($params); @@ -313,7 +313,7 @@ protected function writeCacheFile($config, $cache, $data) $current_umask = umask(0000); $cacheDir = dirname($cache); if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) { - throw new \sfCacheException(sprintf('Failed to make cache directory "%s" while generating cache for configuration file "%s".', $cacheDir, $config)); + throw new sfCacheException(sprintf('Failed to make cache directory "%s" while generating cache for configuration file "%s".', $cacheDir, $config)); } $tmpFile = tempnam($cacheDir, basename($cache)); @@ -347,6 +347,6 @@ protected function mergeUserConfigHandlers() // user defined configuration handlers $this->handlers = array_merge($this->handlers, $this->userHandlers); - $this->userHandlers = array(); + $this->userHandlers = []; } } diff --git a/lib/config/sfDatabaseConfigHandler.class.php b/lib/config/sfDatabaseConfigHandler.class.php index 38473ca4b..c1ed33ac6 100644 --- a/lib/config/sfDatabaseConfigHandler.class.php +++ b/lib/config/sfDatabaseConfigHandler.class.php @@ -60,7 +60,7 @@ public function evaluate($configFiles) require_once $include; } - $databases = array(); + $databases = []; foreach ($data as $name => $database) { $databases[$name] = new $database[0]($database[1]); } @@ -90,9 +90,9 @@ protected function parse($configFiles) $config = static::getConfiguration($configFiles); // init our data and includes arrays - $data = array(); - $databases = array(); - $includes = array(); + $data = []; + $databases = []; + $includes = []; // get a list of database connections foreach ($config as $name => $dbConfig) { @@ -123,16 +123,16 @@ protected function parse($configFiles) } // parse parameters - $parameters = array(); + $parameters = []; if (isset($dbConfig['param'])) { $parameters = $dbConfig['param']; } $parameters['name'] = $name; // append new data - $data[$name] = array($dbConfig['class'], $parameters); + $data[$name] = [$dbConfig['class'], $parameters]; } - return array($includes, $data); + return [$includes, $data]; } } diff --git a/lib/config/sfDefineEnvironmentConfigHandler.class.php b/lib/config/sfDefineEnvironmentConfigHandler.class.php index aaeaae4e5..b43dd0b1a 100644 --- a/lib/config/sfDefineEnvironmentConfigHandler.class.php +++ b/lib/config/sfDefineEnvironmentConfigHandler.class.php @@ -39,7 +39,7 @@ public function execute($configFiles) // parse the yaml $config = static::getConfiguration($configFiles); - $values = array(); + $values = []; foreach ($config as $category => $keys) { $values = array_merge($values, $this->getValues($prefix, $category, $keys)); } @@ -83,10 +83,10 @@ protected function getValues($prefix, $category, $keys) if (!is_array($keys)) { list($key, $value) = $this->fixCategoryValue($prefix.strtolower($category), '', $keys); - return array($key => $value); + return [$key => $value]; } - $values = array(); + $values = []; $category = $this->fixCategoryName($category, $prefix); @@ -110,7 +110,7 @@ protected function getValues($prefix, $category, $keys) */ protected function fixCategoryValue($category, $key, $value) { - return array($category.$key, $value); + return [$category.$key, $value]; } /** diff --git a/lib/config/sfFactoryConfigHandler.class.php b/lib/config/sfFactoryConfigHandler.class.php index 83544652e..95e067f7b 100644 --- a/lib/config/sfFactoryConfigHandler.class.php +++ b/lib/config/sfFactoryConfigHandler.class.php @@ -34,11 +34,11 @@ public function execute($configFiles) $config = static::getConfiguration($configFiles); // init our data and includes arrays - $includes = array(); - $instances = array(); + $includes = []; + $instances = []; // available list of factories - $factories = array('view_cache_manager', 'logger', 'i18n', 'controller', 'request', 'response', 'routing', 'storage', 'user', 'view_cache', 'mailer', 'service_container'); + $factories = ['view_cache_manager', 'logger', 'i18n', 'controller', 'request', 'response', 'routing', 'storage', 'user', 'view_cache', 'mailer', 'service_container']; // let's do our fancy work foreach ($factories as $factory) { @@ -64,7 +64,7 @@ public function execute($configFiles) } // parse parameters - $parameters = array(); + $parameters = []; if (isset($keys['param'])) { if (!is_array($keys['param'])) { throw new InvalidArgumentException(sprintf('The "param" key for the "%s" factory must be an array (in %s).', $class, $configFiles[0])); @@ -94,7 +94,7 @@ public function execute($configFiles) break; case 'storage': - $defaultParameters = array(); + $defaultParameters = []; $defaultParameters[] = sprintf("'auto_shutdown' => false, 'session_id' => \$this->getRequest()->getParameter('%s'),", $parameters['session_name']); if (is_subclass_of($class, 'sfDatabaseSessionStorage')) { $defaultParameters[] = sprintf("'database' => \$this->getDatabaseManager()->getDatabase('%s'),", isset($parameters['database']) ? $parameters['database'] : 'default'); diff --git a/lib/config/sfFilterConfigHandler.class.php b/lib/config/sfFilterConfigHandler.class.php index b4ba963ee..d9d221e27 100644 --- a/lib/config/sfFilterConfigHandler.class.php +++ b/lib/config/sfFilterConfigHandler.class.php @@ -33,8 +33,8 @@ public function execute($configFiles) $config = static::getConfiguration($configFiles); // init our data and includes arrays - $data = array(); - $includes = array(); + $data = []; + $includes = []; $execution = false; $rendering = false; @@ -123,7 +123,7 @@ public static function getConfiguration(array $configFiles) // we get the order of the new file and merge with the previous configurations $previous = $config; - $config = array(); + $config = []; foreach (static::parseYaml($configFile) as $key => $value) { $value = (array) $value; $config[$key] = isset($previous[$key]) ? sfToolkit::arrayDeepMerge($previous[$key], $value) : $value; diff --git a/lib/config/sfGeneratorConfigHandler.class.php b/lib/config/sfGeneratorConfigHandler.class.php index 524c94630..32279c9c1 100644 --- a/lib/config/sfGeneratorConfigHandler.class.php +++ b/lib/config/sfGeneratorConfigHandler.class.php @@ -44,7 +44,7 @@ public function execute($configFiles) throw new sfParseException(sprintf('Configuration file "%s" must specify a generator class section under the generator section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0])); } - foreach (array('fields', 'list', 'edit') as $section) { + foreach (['fields', 'list', 'edit'] as $section) { if (isset($config[$section])) { throw new sfParseException(sprintf('Configuration file "%s" can specify a "%s" section but only under the param section.', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0], $section)); } @@ -54,7 +54,7 @@ public function execute($configFiles) $generatorManager = new sfGeneratorManager(sfContext::getInstance()->getConfiguration()); // generator parameters - $generatorParam = (isset($config['param']) ? $config['param'] : array()); + $generatorParam = (isset($config['param']) ? $config['param'] : []); // hack to find the module name (look for the last /modules/ in path) preg_match('#.*/modules/([^/]+)/#', str_replace('\\', '/', $configFiles[0]), $match); diff --git a/lib/config/sfPluginConfiguration.class.php b/lib/config/sfPluginConfiguration.class.php index d6d5467ce..aa80e077d 100644 --- a/lib/config/sfPluginConfiguration.class.php +++ b/lib/config/sfPluginConfiguration.class.php @@ -106,9 +106,9 @@ public function initializeAutoload() $autoload = sfSimpleAutoload::getInstance(sfConfig::get('sf_cache_dir').'/project_autoload.cache'); if (is_readable($file = $this->rootDir.'/config/autoload.yml')) { - $this->configuration->getEventDispatcher()->connect('autoload.filter_config', array($this, 'filterAutoloadConfig')); - $autoload->loadConfiguration(array($file)); - $this->configuration->getEventDispatcher()->disconnect('autoload.filter_config', array($this, 'filterAutoloadConfig')); + $this->configuration->getEventDispatcher()->connect('autoload.filter_config', [$this, 'filterAutoloadConfig']); + $autoload->loadConfiguration([$file]); + $this->configuration->getEventDispatcher()->disconnect('autoload.filter_config', [$this, 'filterAutoloadConfig']); } else { $autoload->addDirectory($this->rootDir.'/lib'); } @@ -125,22 +125,22 @@ public function filterAutoloadConfig(sfEvent $event, array $config) { // use array_merge so config is added to the front of the autoload array if (!isset($config['autoload'][$this->name.'_lib'])) { - $config['autoload'] = array_merge(array( - $this->name.'_lib' => array( + $config['autoload'] = array_merge([ + $this->name.'_lib' => [ 'path' => $this->rootDir.'/lib', 'recursive' => true, - ), - ), $config['autoload']); + ], + ], $config['autoload']); } if (!isset($config['autoload'][$this->name.'_module_libs'])) { - $config['autoload'] = array_merge(array( - $this->name.'_module_libs' => array( + $config['autoload'] = array_merge([ + $this->name.'_module_libs' => [ 'path' => $this->rootDir.'/modules/*/lib', 'recursive' => true, 'prefix' => 1, - ), - ), $config['autoload']); + ], + ], $config['autoload']); } return $config; @@ -151,7 +151,7 @@ public function filterAutoloadConfig(sfEvent $event, array $config) */ public function connectTests() { - $this->dispatcher->connect('task.test.filter_test_files', array($this, 'filterTestFiles')); + $this->dispatcher->connect('task.test.filter_test_files', [$this, 'filterTestFiles']); } /** @@ -167,7 +167,7 @@ public function filterTestFiles(sfEvent $event, $files) if ($task instanceof sfTestAllTask) { $directory = $this->rootDir.'/test'; - $names = array(); + $names = []; } elseif ($task instanceof sfTestFunctionalTask) { $directory = $this->rootDir.'/test/functional'; $names = $event['arguments']['controller']; @@ -177,7 +177,7 @@ public function filterTestFiles(sfEvent $event, $files) } if (!count($names)) { - $names = array('*'); + $names = ['*']; } foreach ($names as $name) { diff --git a/lib/config/sfProjectConfiguration.class.php b/lib/config/sfProjectConfiguration.class.php index 64526f31d..68f006e20 100644 --- a/lib/config/sfProjectConfiguration.class.php +++ b/lib/config/sfProjectConfiguration.class.php @@ -25,16 +25,16 @@ class sfProjectConfiguration protected $dispatcher; /** @var array */ - protected $plugins = array(); + protected $plugins = []; /** @var array */ - protected $pluginPaths = array(); + protected $pluginPaths = []; /** @var array */ - protected $overriddenPluginPaths = array(); + protected $overriddenPluginPaths = []; /** @var sfPluginConfiguration[] */ - protected $pluginConfigurations = array(); + protected $pluginConfigurations = []; /** @var bool */ protected $pluginsLoaded = false; @@ -48,7 +48,7 @@ class sfProjectConfiguration * @param string $rootDir The project root directory * @param sfEventDispatcher $dispatcher The event dispatcher */ - public function __construct($rootDir = null, sfEventDispatcher $dispatcher = null) + public function __construct($rootDir = null, ?sfEventDispatcher $dispatcher = null) { if (null === self::$active || $this instanceof sfApplicationConfiguration) { self::$active = $this; @@ -85,7 +85,7 @@ public function __construct($rootDir = null, sfEventDispatcher $dispatcher = nul */ public function __call($method, $arguments) { - $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'configuration.method_not_found', array('method' => $method, 'arguments' => $arguments))); + $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'configuration.method_not_found', ['method' => $method, 'arguments' => $arguments])); if (!$event->isProcessed()) { throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method)); } @@ -144,7 +144,7 @@ public function setRootDir($rootDir) { $this->rootDir = $rootDir; - sfConfig::add(array( + sfConfig::add([ 'sf_root_dir' => $rootDir, // global directory structure @@ -155,7 +155,7 @@ public function setRootDir($rootDir) 'sf_config_dir' => $rootDir.DIRECTORY_SEPARATOR.'config', 'sf_test_dir' => $rootDir.DIRECTORY_SEPARATOR.'test', 'sf_plugins_dir' => $rootDir.DIRECTORY_SEPARATOR.'plugins', - )); + ]); $this->setWebDir($rootDir.DIRECTORY_SEPARATOR.'web'); $this->setCacheDir($rootDir.DIRECTORY_SEPARATOR.'cache'); @@ -198,11 +198,11 @@ public function setLogDir($logDir) */ public function setWebDir($webDir) { - sfConfig::add(array( + sfConfig::add([ 'sf_web_dir' => $webDir, 'sf_upload_dir_name' => $uploadDirName = 'uploads', 'sf_upload_dir' => $webDir.DIRECTORY_SEPARATOR.$uploadDirName, - )); + ]); } /** @@ -215,7 +215,7 @@ public function getModelDirs() { return array_merge( $this->getPluginSubPaths('/lib/model'), // plugins - array(sfConfig::get('sf_lib_dir').'/model') // project + [sfConfig::get('sf_lib_dir').'/model'] // project ); } @@ -230,9 +230,9 @@ public function getModelDirs() public function getGeneratorTemplateDirs($class, $theme) { return array_merge( - array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/template'), // project + [sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/template'], // project $this->getPluginSubPaths('/data/generator/'.$class.'/'.$theme.'/template'), // plugins - array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/default/template'), // project (default theme) + [sfConfig::get('sf_data_dir').'/generator/'.$class.'/default/template'], // project (default theme) $this->getPluginSubPaths('/data/generator/'.$class.'/default/template') // plugins (default theme) ); } @@ -248,9 +248,9 @@ public function getGeneratorTemplateDirs($class, $theme) public function getGeneratorSkeletonDirs($class, $theme) { return array_merge( - array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/skeleton'), // project + [sfConfig::get('sf_data_dir').'/generator/'.$class.'/'.$theme.'/skeleton'], // project $this->getPluginSubPaths('/data/generator/'.$class.'/'.$theme.'/skeleton'), // plugins - array(sfConfig::get('sf_data_dir').'/generator/'.$class.'/default/skeleton'), // project (default theme) + [sfConfig::get('sf_data_dir').'/generator/'.$class.'/default/skeleton'], // project (default theme) $this->getPluginSubPaths('/data/generator/'.$class.'/default/skeleton') // plugins (default theme) ); } @@ -289,9 +289,9 @@ public function getConfigPaths($configPath) { $globalConfigPath = basename(dirname($configPath)).'/'.basename($configPath); - $files = array( + $files = [ $this->getSymfonyLibDir().'/config/'.$globalConfigPath, // symfony - ); + ]; foreach ($this->getPluginPaths() as $path) { if (is_file($file = $path.'/'.$globalConfigPath)) { @@ -299,10 +299,10 @@ public function getConfigPaths($configPath) } } - $files = array_merge($files, array( + $files = array_merge($files, [ $this->getRootDir().'/'.$globalConfigPath, // project $this->getRootDir().'/'.$configPath, // project - )); + ]); foreach ($this->getPluginPaths() as $path) { if (is_file($file = $path.'/'.$configPath)) { @@ -310,7 +310,7 @@ public function getConfigPaths($configPath) } } - $configs = array(); + $configs = []; foreach (array_unique($files) as $file) { if (is_readable($file)) { $configs[] = $file; @@ -335,7 +335,7 @@ public function setPlugins(array $plugins) $this->plugins = $plugins; - $this->pluginPaths = array(); + $this->pluginPaths = []; } /** @@ -349,7 +349,7 @@ public function enablePlugins($plugins) if (func_num_args() > 1) { $plugins = func_get_args(); } else { - $plugins = array($plugins); + $plugins = [$plugins]; } } @@ -370,7 +370,7 @@ public function disablePlugins($plugins) } if (!is_array($plugins)) { - $plugins = array($plugins); + $plugins = [$plugins]; } foreach ($plugins as $plugin) { @@ -381,7 +381,7 @@ public function disablePlugins($plugins) } } - $this->pluginPaths = array(); + $this->pluginPaths = []; } /** @@ -391,7 +391,7 @@ public function disablePlugins($plugins) * * @throws LogicException If plugins have already been loaded */ - public function enableAllPluginsExcept($plugins = array()) + public function enableAllPluginsExcept($plugins = []) { if ($this->pluginsLoaded) { throw new LogicException('Plugins have already been loaded.'); @@ -427,7 +427,7 @@ public function getPluginSubPaths($subPath = '') return $this->pluginPaths[$subPath]; } - $this->pluginPaths[$subPath] = array(); + $this->pluginPaths[$subPath] = []; $pluginPaths = $this->getPluginPaths(); foreach ($pluginPaths as $pluginPath) { if (is_dir($pluginPath.$subPath)) { @@ -450,7 +450,7 @@ public function getPluginPaths() if (!isset($this->pluginPaths[''])) { $pluginPaths = $this->getAllPluginPaths(); - $this->pluginPaths[''] = array(); + $this->pluginPaths[''] = []; foreach ($this->getPlugins() as $plugin) { if (isset($pluginPaths[$plugin])) { $this->pluginPaths[''][] = $pluginPaths[$plugin]; @@ -470,15 +470,15 @@ public function getPluginPaths() */ public function getAllPluginPaths() { - $pluginPaths = array(); + $pluginPaths = []; // search for *Plugin directories representing plugins // follow links and do not recurse. No need to exclude VC because they do not end with *Plugin $finder = sfFinder::type('dir')->maxdepth(0)->ignore_version_control(false)->follow_link()->name('*Plugin'); - $dirs = array( + $dirs = [ $this->getSymfonyLibDir().'/plugins', sfConfig::get('sf_plugins_dir'), - ); + ]; foreach ($finder->in($dirs) as $path) { $pluginPaths[basename($path)] = $path; @@ -589,7 +589,7 @@ public static function guessRootDir() * * @return sfApplicationConfiguration A sfApplicationConfiguration instance */ - public static function getApplicationConfiguration($application, $environment, $debug, $rootDir = null, sfEventDispatcher $dispatcher = null) + public static function getApplicationConfiguration($application, $environment, $debug, $rootDir = null, ?sfEventDispatcher $dispatcher = null) { $class = $application.'Configuration'; diff --git a/lib/config/sfRootConfigHandler.class.php b/lib/config/sfRootConfigHandler.class.php index 4b9df5583..d7dfcbf9d 100644 --- a/lib/config/sfRootConfigHandler.class.php +++ b/lib/config/sfRootConfigHandler.class.php @@ -40,8 +40,8 @@ public function execute($configFiles) } // init our data and includes arrays - $data = array(); - $includes = array(); + $data = []; + $includes = []; // let's do our fancy work foreach ($config as $category => $keys) { diff --git a/lib/config/sfRoutingConfigHandler.class.php b/lib/config/sfRoutingConfigHandler.class.php index 9978334ab..f917bd4ab 100644 --- a/lib/config/sfRoutingConfigHandler.class.php +++ b/lib/config/sfRoutingConfigHandler.class.php @@ -28,14 +28,14 @@ public function execute($configFiles) $options = $this->getOptions(); unset($options['cache']); - $data = array(); + $data = []; foreach ($this->parse($configFiles) as $name => $routeConfig) { $r = new ReflectionClass($routeConfig[0]); /** @var sfRoute $route */ $route = $r->newInstanceArgs($routeConfig[1]); - $routes = $route instanceof sfRouteCollection ? $route : array($name => $route); + $routes = $route instanceof sfRouteCollection ? $route : [$name => $route]; foreach (sfPatternRouting::flattenRoutes($routes) as $name => $route) { $route->setDefaultOptions($options); $data[] = sprintf('$this->routes[\'%s\'] = %s;', $name, var_export(serialize($route), true)); @@ -55,7 +55,7 @@ public function evaluate($configFiles) { $routeDefinitions = $this->parse($configFiles); - $routes = array(); + $routes = []; foreach ($routeDefinitions as $name => $route) { $r = new ReflectionClass($route[0]); $routes[$name] = $r->newInstanceArgs($route[1]); @@ -85,24 +85,24 @@ protected function parse($configFiles) $config = static::getConfiguration($configFiles); // collect routes - $routes = array(); + $routes = []; foreach ($config as $name => $params) { if ( (isset($params['type']) && 'collection' == $params['type']) || (isset($params['class']) && false !== strpos($params['class'], 'Collection')) ) { - $options = isset($params['options']) ? $params['options'] : array(); + $options = isset($params['options']) ? $params['options'] : []; $options['name'] = $name; - $options['requirements'] = isset($params['requirements']) ? $params['requirements'] : array(); + $options['requirements'] = isset($params['requirements']) ? $params['requirements'] : []; - $routes[$name] = array(isset($params['class']) ? $params['class'] : 'sfRouteCollection', array($options)); + $routes[$name] = [isset($params['class']) ? $params['class'] : 'sfRouteCollection', [$options]]; } else { - $routes[$name] = array(isset($params['class']) ? $params['class'] : 'sfRoute', array( + $routes[$name] = [isset($params['class']) ? $params['class'] : 'sfRoute', [ $params['url'] ?: '/', - isset($params['params']) ? $params['params'] : (isset($params['param']) ? $params['param'] : array()), - isset($params['requirements']) ? $params['requirements'] : array(), - isset($params['options']) ? $params['options'] : array(), - )); + isset($params['params']) ? $params['params'] : (isset($params['param']) ? $params['param'] : []), + isset($params['requirements']) ? $params['requirements'] : [], + isset($params['options']) ? $params['options'] : [], + ]]; } } diff --git a/lib/config/sfServiceConfigHandler.class.php b/lib/config/sfServiceConfigHandler.class.php index 66b421884..0735f5fa6 100644 --- a/lib/config/sfServiceConfigHandler.class.php +++ b/lib/config/sfServiceConfigHandler.class.php @@ -32,10 +32,10 @@ public function execute($configFiles) $loader->load(static::getConfiguration($configFiles)); $dumper = new sfServiceContainerDumperPhp($serviceContainerBuilder); - $code = $dumper->dump(array( + $code = $dumper->dump([ 'class' => $class, 'base_class' => $this->parameterHolder->get('base_class'), - )); + ]); // compile data $retval = sprintf( diff --git a/lib/config/sfViewConfigHandler.class.php b/lib/config/sfViewConfigHandler.class.php index 68bb6e543..4df6dd7e4 100644 --- a/lib/config/sfViewConfigHandler.class.php +++ b/lib/config/sfViewConfigHandler.class.php @@ -32,7 +32,7 @@ public function execute($configFiles) $this->yamlConfig = static::getConfiguration($configFiles); // init our data array - $data = array(); + $data = []; $data[] = "\$response = \$this->context->getResponse();\n\n"; @@ -123,7 +123,7 @@ protected function addComponentSlots($viewName = '') $components = $this->mergeConfigValue('components', $viewName); foreach ($components as $name => $component) { if (!is_array($component) || count($component) < 1) { - $component = array(null, null); + $component = [null, null]; } $data .= " \$this->setComponentSlot('{$name}', '{$component[0]}', '{$component[1]}');\n"; @@ -213,7 +213,7 @@ protected function addLayout($viewName = '') */ protected function addHtmlHead($viewName = '') { - $data = array(); + $data = []; foreach ($this->mergeConfigValue('http_metas', $viewName) as $httpequiv => $content) { $data[] = sprintf(" \$response->addHttpMeta('%s', '%s', false);", $httpequiv, str_replace('\'', '\\\'', $content)); @@ -255,7 +255,7 @@ protected function addHtmlAsset($viewName = '') */ protected function addEscaping($viewName = '') { - $data = array(); + $data = []; $escaping = $this->getConfigValue('escaping', $viewName); @@ -269,16 +269,16 @@ protected function addEscaping($viewName = '') protected static function mergeConfig($config) { // merge javascripts and stylesheets - $config['all']['stylesheets'] = array_merge(isset($config['default']['stylesheets']) && is_array($config['default']['stylesheets']) ? $config['default']['stylesheets'] : array(), isset($config['all']['stylesheets']) && is_array($config['all']['stylesheets']) ? $config['all']['stylesheets'] : array()); + $config['all']['stylesheets'] = array_merge(isset($config['default']['stylesheets']) && is_array($config['default']['stylesheets']) ? $config['default']['stylesheets'] : [], isset($config['all']['stylesheets']) && is_array($config['all']['stylesheets']) ? $config['all']['stylesheets'] : []); unset($config['default']['stylesheets']); - $config['all']['javascripts'] = array_merge(isset($config['default']['javascripts']) && is_array($config['default']['javascripts']) ? $config['default']['javascripts'] : array(), isset($config['all']['javascripts']) && is_array($config['all']['javascripts']) ? $config['all']['javascripts'] : array()); + $config['all']['javascripts'] = array_merge(isset($config['default']['javascripts']) && is_array($config['default']['javascripts']) ? $config['default']['javascripts'] : [], isset($config['all']['javascripts']) && is_array($config['all']['javascripts']) ? $config['all']['javascripts'] : []); unset($config['default']['javascripts']); // merge default and all $config['all'] = sfToolkit::arrayDeepMerge( - isset($config['default']) && is_array($config['default']) ? $config['default'] : array(), - isset($config['all']) && is_array($config['all']) ? $config['all'] : array() + isset($config['default']) && is_array($config['default']) ? $config['default'] : [], + isset($config['all']) && is_array($config['all']) ? $config['all'] : [] ); unset($config['default']); @@ -296,7 +296,7 @@ protected static function mergeConfig($config) */ private function addAssets($type, $assets) { - $tmp = array(); + $tmp = []; foreach ((array) $assets as $asset) { $position = ''; if (is_array($asset)) { @@ -309,11 +309,11 @@ private function addAssets($type, $assets) } } else { $key = $asset; - $options = array(); + $options = []; } if ('-*' == $key) { - $tmp = array(); + $tmp = []; } elseif ('-' == $key[0]) { unset($tmp[substr($key, 1)]); } else { diff --git a/lib/config/sfYamlConfigHandler.class.php b/lib/config/sfYamlConfigHandler.class.php index 35837b45d..d1ea1e798 100644 --- a/lib/config/sfYamlConfigHandler.class.php +++ b/lib/config/sfYamlConfigHandler.class.php @@ -28,10 +28,10 @@ abstract class sfYamlConfigHandler extends sfConfigHandler */ public static function parseYamls($configFiles) { - $config = array(); + $config = []; foreach ($configFiles as $configFile) { // the first level is an environment and its value must be an array - $values = array(); + $values = []; foreach (static::parseYaml($configFile) as $env => $value) { if (null !== $value) { $values[$env] = $value; @@ -69,14 +69,14 @@ public static function parseYaml($configFile) throw new sfParseException(sprintf('Configuration file "%s" could not be parsed', $configFile)); } - return null === $config ? array() : $config; + return null === $config ? [] : $config; } public static function flattenConfiguration($config) { $config['all'] = sfToolkit::arrayDeepMerge( - isset($config['default']) && is_array($config['default']) ? $config['default'] : array(), - isset($config['all']) && is_array($config['all']) ? $config['all'] : array() + isset($config['default']) && is_array($config['default']) ? $config['default'] : [], + isset($config['all']) && is_array($config['all']) ? $config['all'] : [] ); unset($config['default']); @@ -94,9 +94,9 @@ public static function flattenConfiguration($config) public static function flattenConfigurationWithEnvironment($config) { return sfToolkit::arrayDeepMerge( - isset($config['default']) && is_array($config['default']) ? $config['default'] : array(), - isset($config['all']) && is_array($config['all']) ? $config['all'] : array(), - isset($config[sfConfig::get('sf_environment')]) && is_array($config[sfConfig::get('sf_environment')]) ? $config[sfConfig::get('sf_environment')] : array() + isset($config['default']) && is_array($config['default']) ? $config['default'] : [], + isset($config['all']) && is_array($config['all']) ? $config['all'] : [], + isset($config[sfConfig::get('sf_environment')]) && is_array($config[sfConfig::get('sf_environment')]) ? $config[sfConfig::get('sf_environment')] : [] ); } @@ -110,7 +110,7 @@ public static function flattenConfigurationWithEnvironment($config) */ protected function mergeConfigValue($keyName, $category) { - $values = array(); + $values = []; if (isset($this->yamlConfig['all'][$keyName]) && is_array($this->yamlConfig['all'][$keyName])) { $values = $this->yamlConfig['all'][$keyName]; diff --git a/lib/controller/default/templates/defaultLayout.php b/lib/controller/default/templates/defaultLayout.php index 1898f65a8..8aa94057f 100644 --- a/lib/controller/default/templates/defaultLayout.php +++ b/lib/controller/default/templates/defaultLayout.php @@ -18,7 +18,7 @@
- 'symfony PHP Framework', 'class' => 'sfTLogo', 'size' => '186x39')), 'http://www.symfony-project.org/'); ?> + 'symfony PHP Framework', 'class' => 'sfTLogo', 'size' => '186x39']), 'http://www.symfony-project.org/'); ?>
diff --git a/lib/controller/default/templates/disabledSuccess.php b/lib/controller/default/templates/disabledSuccess.php index 1f76fbff2..d52ff435b 100644 --- a/lib/controller/default/templates/disabledSuccess.php +++ b/lib/controller/default/templates/disabledSuccess.php @@ -1,7 +1,7 @@
- 'module disabled', 'class' => 'sfTMessageIcon', 'size' => '48x48')); ?> + 'module disabled', 'class' => 'sfTMessageIcon', 'size' => '48x48']); ?>

This Module is Unavailable

This module has been disabled.
diff --git a/lib/controller/default/templates/error404Success.php b/lib/controller/default/templates/error404Success.php index 919af7520..9a65929a1 100644 --- a/lib/controller/default/templates/error404Success.php +++ b/lib/controller/default/templates/error404Success.php @@ -1,7 +1,7 @@
- 'page not found', 'class' => 'sfTMessageIcon', 'size' => '48x48')); ?> + 'page not found', 'class' => 'sfTMessageIcon', 'size' => '48x48']); ?>

Oops! Page Not Found

The server returned a 404 response.
diff --git a/lib/controller/default/templates/indexSuccess.php b/lib/controller/default/templates/indexSuccess.php index b50638f39..9d887fb63 100644 --- a/lib/controller/default/templates/indexSuccess.php +++ b/lib/controller/default/templates/indexSuccess.php @@ -1,7 +1,7 @@
- 'ok', 'class' => 'sfTMessageIcon', 'size' => '48x48')); ?> + 'ok', 'class' => 'sfTMessageIcon', 'size' => '48x48']); ?>

Symfony Project Created

Congratulations! You have successfully created your symfony project.
diff --git a/lib/controller/default/templates/loginSuccess.php b/lib/controller/default/templates/loginSuccess.php index f1b5c7e0e..ea2603779 100644 --- a/lib/controller/default/templates/loginSuccess.php +++ b/lib/controller/default/templates/loginSuccess.php @@ -1,7 +1,7 @@
- 'login required', 'class' => 'sfTMessageIcon', 'size' => '48x48')); ?> + 'login required', 'class' => 'sfTMessageIcon', 'size' => '48x48']); ?>

Login Required

This page is not public.
diff --git a/lib/controller/default/templates/moduleSuccess.php b/lib/controller/default/templates/moduleSuccess.php index b4dc0bdcd..f26727222 100644 --- a/lib/controller/default/templates/moduleSuccess.php +++ b/lib/controller/default/templates/moduleSuccess.php @@ -1,7 +1,7 @@
- 'module created', 'class' => 'sfTMessageIcon', 'size' => '48x48')); ?> + 'module created', 'class' => 'sfTMessageIcon', 'size' => '48x48']); ?>

Module "get('module'); ?>" created

Congratulations! You have successfully created a symfony module.
diff --git a/lib/controller/default/templates/secureSuccess.php b/lib/controller/default/templates/secureSuccess.php index 3151ff665..912963b26 100644 --- a/lib/controller/default/templates/secureSuccess.php +++ b/lib/controller/default/templates/secureSuccess.php @@ -1,7 +1,7 @@
- 'credentials required', 'class' => 'sfTMessageIcon', 'size' => '48x48')); ?> + 'credentials required', 'class' => 'sfTMessageIcon', 'size' => '48x48']); ?>

Credentials Required

This page is in a restricted area.
diff --git a/lib/controller/sfController.class.php b/lib/controller/sfController.class.php index d484b350c..b420285fc 100644 --- a/lib/controller/sfController.class.php +++ b/lib/controller/sfController.class.php @@ -24,7 +24,7 @@ abstract class sfController protected $dispatcher; /** @var string[] */ - protected $controllerClasses = array(); + protected $controllerClasses = []; /** @var int */ protected $renderMode = sfView::RENDER_CLIENT; @@ -56,7 +56,7 @@ public function __construct($context) */ public function __call($method, $arguments) { - $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'controller.method_not_found', array('method' => $method, 'arguments' => $arguments))); + $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'controller.method_not_found', ['method' => $method, 'arguments' => $arguments])); if (!$event->isProcessed()) { throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method)); } @@ -129,7 +129,7 @@ public function forward($moduleName, $actionName) if (!$this->actionExists($moduleName, $actionName)) { // the requested action doesn't exist if (sfConfig::get('sf_logging_enabled')) { - $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Action "%s/%s" does not exist', $moduleName, $actionName)))); + $this->dispatcher->notify(new sfEvent($this, 'application.log', [sprintf('Action "%s/%s" does not exist', $moduleName, $actionName)])); } throw new sfError404Exception(sprintf('Action "%s/%s" does not exist.', $moduleName, $actionName)); @@ -161,13 +161,13 @@ public function forward($moduleName, $actionName) $filterChain = new sfFilterChain(); $filterChain->loadConfiguration($actionInstance); - $this->context->getEventDispatcher()->notify(new sfEvent($this, 'controller.change_action', array('module' => $moduleName, 'action' => $actionName))); + $this->context->getEventDispatcher()->notify(new sfEvent($this, 'controller.change_action', ['module' => $moduleName, 'action' => $actionName])); if ($moduleName == sfConfig::get('sf_error_404_module') && $actionName == sfConfig::get('sf_error_404_action')) { $this->context->getResponse()->setStatusCode(404); $this->context->getResponse()->setHttpHeader('Status', '404 Not Found'); - $this->dispatcher->notify(new sfEvent($this, 'controller.page_not_found', array('module' => $moduleName, 'action' => $actionName))); + $this->dispatcher->notify(new sfEvent($this, 'controller.page_not_found', ['module' => $moduleName, 'action' => $actionName])); } // process the filter chain @@ -281,7 +281,7 @@ public function getView($moduleName, $actionName, $viewName) public function getPresentationFor($module, $action, $viewName = null) { if (sfConfig::get('sf_logging_enabled')) { - $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Get presentation for action "%s/%s" (view class: "%s")', $module, $action, $viewName)))); + $this->dispatcher->notify(new sfEvent($this, 'application.log', [sprintf('Get presentation for action "%s/%s" (view class: "%s")', $module, $action, $viewName)])); } // get original render mode @@ -448,7 +448,7 @@ protected function controllerExists($moduleName, $controllerName, $extension, $t // send an exception if debug if ($throwExceptions && sfConfig::get('sf_debug')) { - $dirs = array_map(array('sfDebug', 'shortenFilePath'), array_keys($dirs)); + $dirs = array_map(['sfDebug', 'shortenFilePath'], array_keys($dirs)); throw new sfControllerException(sprintf('Controller "%s/%s" does not exist in: %s.', $moduleName, $controllerName, implode(', ', $dirs))); } diff --git a/lib/controller/sfFrontWebController.class.php b/lib/controller/sfFrontWebController.class.php index cddf17322..073dea69c 100644 --- a/lib/controller/sfFrontWebController.class.php +++ b/lib/controller/sfFrontWebController.class.php @@ -28,7 +28,7 @@ public function dispatch() { try { // reinitialize filters (needed for unit and functional tests) - sfFilter::$filterCalled = array(); + sfFilter::$filterCalled = []; // determine our module and action /** @var sfWebRequest $request */ diff --git a/lib/controller/sfWebController.class.php b/lib/controller/sfWebController.class.php index 80af2750a..74eb60d85 100644 --- a/lib/controller/sfWebController.class.php +++ b/lib/controller/sfWebController.class.php @@ -25,7 +25,7 @@ abstract class sfWebController extends sfController * * @return string A URL to a symfony resource */ - public function genUrl($parameters = array(), $absolute = false) + public function genUrl($parameters = [], $absolute = false) { $route = ''; $fragment = ''; @@ -82,7 +82,7 @@ public function convertUrlStringToParameters($url) { $givenUrl = $url; - $params = array(); + $params = []; $queryString = ''; $route = ''; @@ -137,7 +137,7 @@ public function convertUrlStringToParameters($url) } } - return array($route, $params); + return [$route, $params]; } /** @@ -161,7 +161,7 @@ public function redirect($url, $delay = 0, $statusCode = 302) $url = str_replace('&', '&', $url); if (sfConfig::get('sf_logging_enabled')) { - $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Redirect to "%s"', $url)))); + $this->dispatcher->notify(new sfEvent($this, 'application.log', [sprintf('Redirect to "%s"', $url)])); } // redirect diff --git a/lib/database/sfDatabase.class.php b/lib/database/sfDatabase.class.php index 61f13c391..a380050cd 100644 --- a/lib/database/sfDatabase.class.php +++ b/lib/database/sfDatabase.class.php @@ -34,7 +34,7 @@ abstract class sfDatabase * * @param array $parameters An associative array of initialization parameters */ - public function __construct($parameters = array()) + public function __construct($parameters = []) { $this->initialize($parameters); } @@ -46,7 +46,7 @@ public function __construct($parameters = array()) * * @throws sfInitializationException If an error occurs while initializing this sfDatabase object */ - public function initialize($parameters = array()) + public function initialize($parameters = []) { $this->parameterHolder = new sfParameterHolder(); $this->parameterHolder->add($parameters); diff --git a/lib/database/sfDatabaseManager.class.php b/lib/database/sfDatabaseManager.class.php index 96c95de7e..c293005ed 100644 --- a/lib/database/sfDatabaseManager.class.php +++ b/lib/database/sfDatabaseManager.class.php @@ -21,7 +21,7 @@ class sfDatabaseManager { /** @var sfProjectConfiguration */ protected $configuration; - protected $databases = array(); + protected $databases = []; /** * Class constructor. @@ -30,12 +30,12 @@ class sfDatabaseManager * * @param array $options */ - public function __construct(sfProjectConfiguration $configuration, $options = array()) + public function __construct(sfProjectConfiguration $configuration, $options = []) { $this->initialize($configuration); if (!isset($options['auto_shutdown']) || $options['auto_shutdown']) { - register_shutdown_function(array($this, 'shutdown')); + register_shutdown_function([$this, 'shutdown']); } } @@ -62,7 +62,7 @@ public function loadConfiguration() $databases = include $this->configuration->getConfigCache()->checkConfig('config/databases.yml'); } else { $configHandler = new sfDatabaseConfigHandler(); - $databases = $configHandler->evaluate(array($this->configuration->getRootDir().'/config/databases.yml')); + $databases = $configHandler->evaluate([$this->configuration->getRootDir().'/config/databases.yml']); } foreach ($databases as $name => $database) { diff --git a/lib/database/sfPDODatabase.class.php b/lib/database/sfPDODatabase.class.php index 996e43e97..73c02cbdb 100644 --- a/lib/database/sfPDODatabase.class.php +++ b/lib/database/sfPDODatabase.class.php @@ -27,7 +27,7 @@ class sfPDODatabase extends sfDatabase */ public function __call($method, $arguments) { - return call_user_func_array(array($this->getConnection(), $method), $arguments); + return call_user_func_array([$this->getConnection(), $method], $arguments); } /** @@ -48,7 +48,7 @@ public function connect() $password = $this->getParameter('password'); $persistent = $this->getParameter('persistent'); - $options = $persistent ? array(PDO::ATTR_PERSISTENT => true) : array(); + $options = $persistent ? [PDO::ATTR_PERSISTENT => true] : []; $this->connection = new $pdo_class($dsn, $username, $password, $options); } catch (PDOException $e) { diff --git a/lib/debug/sfDebug.class.php b/lib/debug/sfDebug.class.php index 09742e6b6..e671fe03a 100644 --- a/lib/debug/sfDebug.class.php +++ b/lib/debug/sfDebug.class.php @@ -22,10 +22,10 @@ class sfDebug */ public static function symfonyInfoAsArray() { - return array( + return [ 'version' => SYMFONY_VERSION, 'path' => sfConfig::get('sf_symfony_lib_dir'), - ); + ]; } /** @@ -35,11 +35,11 @@ public static function symfonyInfoAsArray() */ public static function phpInfoAsArray() { - $values = array( + $values = [ 'php' => phpversion(), 'os' => php_uname(), 'extensions' => get_loaded_extensions(), - ); + ]; natcasesort($values['extensions']); @@ -60,13 +60,13 @@ public static function phpInfoAsArray() */ public static function globalsAsArray() { - $values = array(); - foreach (array('cookie', 'server', 'get', 'post', 'files', 'env', 'session') as $name) { + $values = []; + foreach (['cookie', 'server', 'get', 'post', 'files', 'env', 'session'] as $name) { if (!isset($GLOBALS['_'.strtoupper($name)])) { continue; } - $values[$name] = array(); + $values[$name] = []; foreach ($GLOBALS['_'.strtoupper($name)] as $key => $value) { $values[$name][$key] = $value; } @@ -99,17 +99,17 @@ public static function settingsAsArray() * * @return array The request parameter holders */ - public static function requestAsArray(sfRequest $request = null) + public static function requestAsArray(?sfRequest $request = null) { if (!$request) { - return array(); + return []; } - return array( + return [ 'options' => $request->getOptions(), 'parameterHolder' => self::flattenParameterHolder($request->getParameterHolder(), true), 'attributeHolder' => self::flattenParameterHolder($request->getAttributeHolder(), true), - ); + ]; } /** @@ -119,22 +119,22 @@ public static function requestAsArray(sfRequest $request = null) * * @return array The response parameters */ - public static function responseAsArray(sfResponse $response = null) + public static function responseAsArray(?sfResponse $response = null) { if (!$response) { - return array(); + return []; } - return array( - 'status' => array('code' => $response->getStatusCode(), 'text' => $response->getStatusText()), + return [ + 'status' => ['code' => $response->getStatusCode(), 'text' => $response->getStatusText()], 'options' => $response->getOptions(), - 'cookies' => method_exists($response, 'getCookies') ? $response->getCookies() : array(), - 'httpHeaders' => method_exists($response, 'getHttpHeaders') ? $response->getHttpHeaders() : array(), - 'javascripts' => method_exists($response, 'getJavascripts') ? $response->getJavascripts('ALL') : array(), - 'stylesheets' => method_exists($response, 'getStylesheets') ? $response->getStylesheets('ALL') : array(), - 'metas' => method_exists($response, 'getMetas') ? $response->getMetas() : array(), - 'httpMetas' => method_exists($response, 'getHttpMetas') ? $response->getHttpMetas() : array(), - ); + 'cookies' => method_exists($response, 'getCookies') ? $response->getCookies() : [], + 'httpHeaders' => method_exists($response, 'getHttpHeaders') ? $response->getHttpHeaders() : [], + 'javascripts' => method_exists($response, 'getJavascripts') ? $response->getJavascripts('ALL') : [], + 'stylesheets' => method_exists($response, 'getStylesheets') ? $response->getStylesheets('ALL') : [], + 'metas' => method_exists($response, 'getMetas') ? $response->getMetas() : [], + 'httpMetas' => method_exists($response, 'getHttpMetas') ? $response->getHttpMetas() : [], + ]; } /** @@ -144,24 +144,24 @@ public static function responseAsArray(sfResponse $response = null) * * @return array The user parameters */ - public static function userAsArray(sfUser $user = null) + public static function userAsArray(?sfUser $user = null) { if (!$user) { - return array(); + return []; } - $data = array( + $data = [ 'options' => $user->getOptions(), 'attributeHolder' => self::flattenParameterHolder($user->getAttributeHolder(), true), 'culture' => $user->getCulture(), - ); + ]; if ($user instanceof sfBasicSecurityUser) { - $data = array_merge($data, array( + $data = array_merge($data, [ 'authenticated' => $user->isAuthenticated(), 'credentials' => $user->getCredentials(), 'lastRequest' => $user->getLastRequestTime(), - )); + ]); } return $data; @@ -177,10 +177,10 @@ public static function userAsArray(sfUser $user = null) */ public static function flattenParameterHolder($parameterHolder, $removeObjects = false) { - $values = array(); + $values = []; if ($parameterHolder instanceof sfNamespacedParameterHolder) { foreach ($parameterHolder->getNamespaces() as $ns) { - $values[$ns] = array(); + $values[$ns] = []; foreach ($parameterHolder->getAll($ns) as $key => $value) { $values[$ns][$key] = $value; } @@ -210,7 +210,7 @@ public static function flattenParameterHolder($parameterHolder, $removeObjects = */ public static function removeObjects($values) { - $nvalues = array(); + $nvalues = []; foreach ($values as $key => $value) { if (is_array($value)) { $nvalues[$key] = self::removeObjects($value); @@ -237,7 +237,7 @@ public static function shortenFilePath($file) return $file; } - foreach (array('sf_root_dir', 'sf_symfony_lib_dir') as $key) { + foreach (['sf_root_dir', 'sf_symfony_lib_dir'] as $key) { if (0 === strpos($file, $value = sfConfig::get($key))) { $file = str_replace($value, strtoupper($key), $file); diff --git a/lib/debug/sfTimerManager.class.php b/lib/debug/sfTimerManager.class.php index 5026484d0..e099797e2 100644 --- a/lib/debug/sfTimerManager.class.php +++ b/lib/debug/sfTimerManager.class.php @@ -16,7 +16,7 @@ class sfTimerManager { /** @var sfTimer[] */ - public static $timers = array(); + public static $timers = []; /** * Gets a sfTimer instance. @@ -56,6 +56,6 @@ public static function getTimers() */ public static function clearTimers() { - self::$timers = array(); + self::$timers = []; } } diff --git a/lib/debug/sfWebDebug.class.php b/lib/debug/sfWebDebug.class.php index 2e362e073..3e1d2258b 100644 --- a/lib/debug/sfWebDebug.class.php +++ b/lib/debug/sfWebDebug.class.php @@ -17,8 +17,8 @@ class sfWebDebug { protected $dispatcher; protected $logger; - protected $options = array(); - protected $panels = array(); + protected $options = []; + protected $panels = []; /** * Constructor. @@ -32,7 +32,7 @@ class sfWebDebug * @param sfVarLogger $logger The logger * @param array $options An array of options */ - public function __construct(sfEventDispatcher $dispatcher, sfVarLogger $logger, array $options = array()) + public function __construct(sfEventDispatcher $dispatcher, sfVarLogger $logger, array $options = []) { $this->dispatcher = $dispatcher; $this->logger = $logger; @@ -43,7 +43,7 @@ public function __construct(sfEventDispatcher $dispatcher, sfVarLogger $logger, } if (!isset($this->options['request_parameters'])) { - $this->options['request_parameters'] = array(); + $this->options['request_parameters'] = []; } $this->configure(); @@ -157,7 +157,7 @@ public function injectToolbar($content) } if (false !== $pos = $posFunction($content, '')) { - $styles = ''; + $styles = ''; $content = $substrFunction($content, 0, $pos).$styles.$substrFunction($content, $pos); } @@ -180,8 +180,8 @@ public function asHtml() { $current = isset($this->options['request_parameters']['sfWebDebugPanel']) ? $this->options['request_parameters']['sfWebDebugPanel'] : null; - $titles = array(); - $panels = array(); + $titles = []; + $panels = []; foreach ($this->panels as $name => $panel) { if ($title = $panel->getTitle()) { if (($content = $panel->getPanelContent()) || $panel->getTitleUrl()) { diff --git a/lib/debug/sfWebDebugPanel.class.php b/lib/debug/sfWebDebugPanel.class.php index 9c1d42334..487feac49 100644 --- a/lib/debug/sfWebDebugPanel.class.php +++ b/lib/debug/sfWebDebugPanel.class.php @@ -164,7 +164,7 @@ public function formatFileLink($file, $line = null, $text = null) // return a link return sprintf( '%s', - htmlspecialchars(strtr($linkFormat, array('%f' => $file, '%l' => $line)), ENT_QUOTES, sfConfig::get('sf_charset')), + htmlspecialchars(strtr($linkFormat, ['%f' => $file, '%l' => $line]), ENT_QUOTES, sfConfig::get('sf_charset')), htmlspecialchars($shortFile, ENT_QUOTES, sfConfig::get('sf_charset')), null === $text ? $shortFile : $text ); diff --git a/lib/debug/sfWebDebugPanelConfig.class.php b/lib/debug/sfWebDebugPanelConfig.class.php index d39cb371a..107281de1 100644 --- a/lib/debug/sfWebDebugPanelConfig.class.php +++ b/lib/debug/sfWebDebugPanelConfig.class.php @@ -27,7 +27,7 @@ public function getPanelTitle() public function getPanelContent() { - $config = array( + $config = [ 'debug' => sfConfig::get('sf_debug') ? 'on' : 'off', 'xdebug' => extension_loaded('xdebug') ? 'on' : 'off', 'logging' => sfConfig::get('sf_logging_enabled') ? 'on' : 'off', @@ -35,7 +35,7 @@ public function getPanelContent() 'compression' => sfConfig::get('sf_compressed') ? 'on' : 'off', 'tokenizer' => function_exists('token_get_all') ? 'on' : 'off', 'apc' => extension_loaded('apc') && ini_get('apc.enabled') ? 'on' : 'off', - ); + ]; $html = '
    '; foreach ($config as $key => $value) { diff --git a/lib/debug/sfWebDebugPanelLogs.class.php b/lib/debug/sfWebDebugPanelLogs.class.php index fc7928e11..e077bed56 100644 --- a/lib/debug/sfWebDebugPanelLogs.class.php +++ b/lib/debug/sfWebDebugPanelLogs.class.php @@ -59,7 +59,7 @@ class_exists($log['type'], false) ? $this->formatFileLink($log['type']) : $log[' } $html .= ''; - $types = array(); + $types = []; foreach ($this->webDebug->getLogger()->getTypes() as $type) { $types[] = ''.$type.''; } @@ -89,7 +89,7 @@ protected function formatLogLine($logLine) static $constants; if (!$constants) { - foreach (array('sf_app_dir', 'sf_root_dir', 'sf_symfony_lib_dir') as $constant) { + foreach (['sf_app_dir', 'sf_root_dir', 'sf_symfony_lib_dir'] as $constant) { $constants[realpath(sfConfig::get($constant)).DIRECTORY_SEPARATOR] = $constant.DIRECTORY_SEPARATOR; } } @@ -100,9 +100,9 @@ protected function formatLogLine($logLine) // replace constants value with constant name $logLine = str_replace(array_keys($constants), array_values($constants), $logLine); - $logLine = sfToolkit::pregtr($logLine, array('/"(.+?)"/s' => '"\\1"', + $logLine = sfToolkit::pregtr($logLine, ['/"(.+?)"/s' => '"\\1"', '/^(.+?)\(\)\:/S' => '\\1():', - '/line (\d+)$/' => 'line \\1')); + '/line (\d+)$/' => 'line \\1']); // special formatting for SQL lines $logLine = $this->formatSql($logLine); diff --git a/lib/debug/sfWebDebugPanelMailer.class.php b/lib/debug/sfWebDebugPanelMailer.class.php index 5b71b3b46..d1a7002f9 100644 --- a/lib/debug/sfWebDebugPanelMailer.class.php +++ b/lib/debug/sfWebDebugPanelMailer.class.php @@ -27,7 +27,7 @@ public function __construct(sfWebDebug $webDebug) { parent::__construct($webDebug); - $this->webDebug->getEventDispatcher()->connect('mailer.configure', array($this, 'listenForMailerConfigure')); + $this->webDebug->getEventDispatcher()->connect('mailer.configure', [$this, 'listenForMailerConfigure']); } public function getTitle() @@ -50,7 +50,7 @@ public function getPanelContent() return false; } - $html = array(); + $html = []; // configuration information $strategy = $this->mailer->getDeliveryStrategy(); @@ -86,7 +86,7 @@ protected function renderMessageInformation(Swift_Message $message) $to = null === $message->getTo() ? '' : implode(', ', array_keys($message->getTo())); - $html = array(); + $html = []; $html[] = sprintf('

    %s (to: %s) %s

    ', $message->getSubject(), $to, $this->getToggler('sfWebDebugMailTemplate'.$i)); $html[] = '
    '; $html[] = '
    '.htmlentities($message->toString(), ENT_QUOTES, $message->getCharset()).'
    '; diff --git a/lib/debug/sfWebDebugPanelTimer.class.php b/lib/debug/sfWebDebugPanelTimer.class.php index 7ce5af2ec..3eb90d6c8 100644 --- a/lib/debug/sfWebDebugPanelTimer.class.php +++ b/lib/debug/sfWebDebugPanelTimer.class.php @@ -26,7 +26,7 @@ public function __construct(sfWebDebug $webDebug) { parent::__construct($webDebug); - $this->webDebug->getEventDispatcher()->connect('debug.web.filter_logs', array($this, 'filterLogs')); + $this->webDebug->getEventDispatcher()->connect('debug.web.filter_logs', [$this, 'filterLogs']); } public function getTitle() @@ -55,7 +55,7 @@ public function getPanelContent() public function filterLogs(sfEvent $event, $logs) { - $newLogs = array(); + $newLogs = []; foreach ($logs as $log) { if ('sfWebDebugLogger' != $log['type']) { $newLogs[] = $log; diff --git a/lib/debug/sfWebDebugPanelView.class.php b/lib/debug/sfWebDebugPanelView.class.php index 7072ea25a..96af9c19f 100644 --- a/lib/debug/sfWebDebugPanelView.class.php +++ b/lib/debug/sfWebDebugPanelView.class.php @@ -17,8 +17,8 @@ */ class sfWebDebugPanelView extends sfWebDebugPanel { - protected $actions = array(); - protected $partials = array(); + protected $actions = []; + protected $partials = []; /** * Constructor. @@ -29,8 +29,8 @@ public function __construct(sfWebDebug $webDebug) { parent::__construct($webDebug); - $this->webDebug->getEventDispatcher()->connect('controller.change_action', array($this, 'listenForChangeAction')); - $this->webDebug->getEventDispatcher()->connect('template.filter_parameters', array($this, 'filterTemplateParameters')); + $this->webDebug->getEventDispatcher()->connect('controller.change_action', [$this, 'listenForChangeAction']); + $this->webDebug->getEventDispatcher()->connect('template.filter_parameters', [$this, 'filterTemplateParameters']); } /** @@ -38,8 +38,8 @@ public function __construct(sfWebDebug $webDebug) */ public function listenForChangeAction(sfEvent $event) { - $this->actions = array(); - $this->partials = array(); + $this->actions = []; + $this->partials = []; } /** @@ -51,12 +51,12 @@ public function listenForChangeAction(sfEvent $event) */ public function filterTemplateParameters(sfEvent $event, $parameters) { - $entry = array('parameters' => $parameters); + $entry = ['parameters' => $parameters]; if ('action' == $parameters['sf_type'] && $file = $this->getLastTemplate()) { - $this->actions[] = $entry + array('file' => $file); + $this->actions[] = $entry + ['file' => $file]; } elseif ('partial' == $parameters['sf_type'] && $file = $this->getLastTemplate('sfPartialView')) { - $this->partials[] = $entry + array('file' => $file); + $this->partials[] = $entry + ['file' => $file]; } return $parameters; @@ -85,7 +85,7 @@ public function getPanelTitle() */ public function getPanelContent() { - $html = array(); + $html = []; foreach ($this->actions as $action) { $html[] = $this->renderTemplateInformation($action['file'], $action['parameters']); @@ -135,7 +135,7 @@ protected function renderTemplateInformation($file, $parameters, $label = 'Templ $parameters = $this->filterCoreParameters($parameters); ++$i; - $html = array(); + $html = []; $html[] = sprintf('

    %s: %s %s

    ', $label, $this->formatFileLink($file, null, $this->shortenTemplatePath($file)), $this->getToggler('sfWebDebugViewTemplate'.$i)); $html[] = '
    '; if (count($parameters)) { @@ -143,7 +143,7 @@ protected function renderTemplateInformation($file, $parameters, $label = 'Templ $html[] = '
      '; foreach ($parameters as $name => $parameter) { $presentation = '
    • '.$this->formatParameterAsHtml($name, $parameter).'
    • '; - $html[] = $this->webDebug->getEventDispatcher()->filter(new sfEvent($this, 'debug.web.view.filter_parameter_html', array('parameter' => $parameter)), $presentation)->getReturnValue(); + $html[] = $this->webDebug->getEventDispatcher()->filter(new sfEvent($this, 'debug.web.view.filter_parameter_html', ['parameter' => $parameter]), $presentation)->getReturnValue(); } $html[] = '
    '; } else { @@ -204,7 +204,7 @@ protected function formatFormAsHtml($name, sfForm $form) $this->setStatus(sfLogger::NOTICE); } - $html = array(); + $html = []; $html[] = $this->getParameterDescription($name, $form, $form->hasErrors() ? '$%s' : null); $html[] = $this->getToggler('sfWebDebugViewForm'.$i); $html[] = '