Skip to content

Commit

Permalink
used PHP 5.4 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed May 20, 2015
1 parent f6f92ee commit 926df8e
Show file tree
Hide file tree
Showing 34 changed files with 255 additions and 255 deletions.
16 changes: 8 additions & 8 deletions src/Bridges/HttpDI/HttpExtension.php
Expand Up @@ -17,14 +17,14 @@
*/
class HttpExtension extends Nette\DI\CompilerExtension
{
public $defaults = array(
'proxy' => array(),
'headers' => array(
public $defaults = [
'proxy' => [],
'headers' => [
'X-Powered-By' => 'Nette Framework',
'Content-Type' => 'text/html; charset=utf-8',
),
],
'frames' => 'SAMEORIGIN', // X-Frame-Options
);
];


public function loadConfiguration()
Expand All @@ -34,7 +34,7 @@ public function loadConfiguration()

$container->addDefinition($this->prefix('requestFactory'))
->setClass('Nette\Http\RequestFactory')
->addSetup('setProxy', array($config['proxy']));
->addSetup('setProxy', [$config['proxy']]);

$container->addDefinition($this->prefix('request'))
->setClass('Nette\Http\Request')
Expand Down Expand Up @@ -71,12 +71,12 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
} elseif (preg_match('#^https?:#', $frames)) {
$frames = "ALLOW-FROM $frames";
}
$initialize->addBody('header(?);', array("X-Frame-Options: $frames"));
$initialize->addBody('header(?);', ["X-Frame-Options: $frames"]);
}

foreach ($config['headers'] as $key => $value) {
if ($value != NULL) { // intentionally ==
$initialize->addBody('header(?);', array("$key: $value"));
$initialize->addBody('header(?);', ["$key: $value"]);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/Bridges/HttpDI/SessionExtension.php
Expand Up @@ -17,11 +17,11 @@
*/
class SessionExtension extends Nette\DI\CompilerExtension
{
public $defaults = array(
public $defaults = [
'debugger' => FALSE,
'autoStart' => 'smart', // true|false|smart
'expiration' => NULL,
);
];

/** @var bool */
private $debugMode;
Expand All @@ -43,18 +43,18 @@ public function loadConfiguration()
->setClass('Nette\Http\Session');

if ($config['expiration']) {
$session->addSetup('setExpiration', array($config['expiration']));
$session->addSetup('setExpiration', [$config['expiration']]);
}

if ($this->debugMode && $config['debugger']) {
$session->addSetup('@Tracy\Bar::addPanel', array(
$session->addSetup('@Tracy\Bar::addPanel', [
new Nette\DI\Statement('Nette\Bridges\HttpTracy\SessionPanel')
));
]);
}

unset($config['expiration'], $config['autoStart'], $config['debugger']);
if (!empty($config)) {
$session->addSetup('setOptions', array($config));
$session->addSetup('setOptions', [$config]);
}

if ($this->name === 'session') {
Expand All @@ -74,10 +74,10 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
$name = $this->prefix('session');

if ($config['autoStart'] === 'smart') {
$initialize->addBody('$this->getService(?)->exists() && $this->getService(?)->start();', array($name, $name));
$initialize->addBody('$this->getService(?)->exists() && $this->getService(?)->start();', [$name, $name]);

} elseif ($config['autoStart']) {
$initialize->addBody('$this->getService(?)->start();', array($name));
$initialize->addBody('$this->getService(?)->start();', [$name]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/HttpTracy/templates/SessionPanel.panel.phtml
Expand Up @@ -26,7 +26,7 @@ use Nette,
</style>

<div class="nette-SessionPanel">
<h1>Session #<?php echo htmlspecialchars(session_id(), ENT_IGNORE, 'UTF-8') ?> (Lifetime: <?php echo htmlspecialchars(ini_get('session.cookie_lifetime'), ENT_NOQUOTES, 'UTF-8'); ?>)</h1>
<h1>Session #<?= htmlspecialchars(session_id(), ENT_IGNORE, 'UTF-8') ?> (Lifetime: <?= htmlspecialchars(ini_get('session.cookie_lifetime'), ENT_NOQUOTES, 'UTF-8'); ?>)</h1>

<div class="tracy-inner">
<?php if (empty($_SESSION)):?>
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/HttpTracy/templates/SessionPanel.tab.phtml
Expand Up @@ -5,6 +5,6 @@ namespace Nette\Bridges\HttpTracy;
use Nette;

?>
<span title="Session #<?php echo htmlspecialchars(session_id(), ENT_IGNORE | ENT_QUOTES, 'UTF-8') ?>">
<span title="Session #<?= htmlspecialchars(session_id(), ENT_IGNORE | ENT_QUOTES, 'UTF-8') ?>">
<svg viewBox="0 0 2048 2048"><path fill="#52362c" d="m1691 1396-67 394h-133s2-446 0-586v-4c0-109 89-197 200-197 110 0 200 88 200 197s-89 197-200 197zm-1131-192c-2 141 0 586 0 586h-133l-67-394h-1c-110 0-199-88-199-197s89-197 200-197c110 0 200 88 200 197v4zm865 61v394h-399-403v-394c262-27 529-27 802 0zm0-66c-273-27-541-27-802 0-2-163-119-258-266-262-176-545 233-693 669-693 440 0 841 149 665 693-148 4-265 99-266 263z"/></svg>
</span>
4 changes: 2 additions & 2 deletions src/Http/FileUpload.php
Expand Up @@ -46,7 +46,7 @@ class FileUpload extends Nette\Object

public function __construct($value)
{
foreach (array('name', 'type', 'size', 'tmp_name', 'error') as $key) {
foreach (['name', 'type', 'size', 'tmp_name', 'error'] as $key) {
if (!isset($value[$key]) || !is_scalar($value[$key])) {
$this->error = UPLOAD_ERR_NO_FILE;
return; // or throw exception?
Expand Down Expand Up @@ -166,7 +166,7 @@ public function move($dest)
*/
public function isImage()
{
return in_array($this->getContentType(), array('image/gif', 'image/png', 'image/jpeg'), TRUE);
return in_array($this->getContentType(), ['image/gif', 'image/png', 'image/jpeg'], TRUE);
}


Expand Down
6 changes: 3 additions & 3 deletions src/Http/Helpers.php
Expand Up @@ -44,7 +44,7 @@ public static function ipMatch($ip, $mask)
if (($ipv4 xor strpos($mask, '.')) || $size < 0 || $size > $max) {
return FALSE;
} elseif ($ipv4) {
$arr = array(ip2long($ip), ip2long($mask));
$arr = [ip2long($ip), ip2long($mask)];
} else {
$arr = unpack('N*', inet_pton($ip) . inet_pton($mask));
$size = $size === '' ? 0 : $max - $size;
Expand All @@ -67,7 +67,7 @@ public static function removeDuplicateCookies()
return;
}

$flatten = array();
$flatten = [];
foreach (headers_list() as $header) {
if (preg_match('#^Set-Cookie: .+?=#', $header, $m)) {
$flatten[$m[0]] = $header;
Expand All @@ -85,7 +85,7 @@ public static function removeDuplicateCookies()
*/
public static function stripSlashes($arr, $onlyKeys = FALSE)
{
$res = array();
$res = [];
foreach ($arr as $k => $v) {
$res[stripslashes($k)] = is_array($v)
? self::stripSlashes($v, $onlyKeys)
Expand Down
28 changes: 14 additions & 14 deletions src/Http/RequestFactory.php
Expand Up @@ -22,16 +22,16 @@ class RequestFactory extends Nette\Object
const CHARS = '\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}';

/** @var array */
public $urlFilters = array(
'path' => array('#/{2,}#' => '/'), // '%20' => ''
'url' => array(), // '#[.,)]\z#' => ''
);
public $urlFilters = [
'path' => ['#/{2,}#' => '/'], // '%20' => ''
'url' => [], // '#[.,)]\z#' => ''
];

/** @var bool */
private $binary = FALSE;

/** @var array */
private $proxies = array();
private $proxies = [];


/**
Expand Down Expand Up @@ -100,11 +100,11 @@ public function createHttpRequest()
$url->setScriptPath($path);

// GET, POST, COOKIE
$useFilter = (!in_array(ini_get('filter.default'), array('', 'unsafe_raw')) || ini_get('filter.default_flags'));
$useFilter = (!in_array(ini_get('filter.default'), ['', 'unsafe_raw']) || ini_get('filter.default_flags'));

$query = $url->getQueryParameters();
$post = $useFilter ? filter_input_array(INPUT_POST, FILTER_UNSAFE_RAW) : (empty($_POST) ? array() : $_POST);
$cookies = $useFilter ? filter_input_array(INPUT_COOKIE, FILTER_UNSAFE_RAW) : (empty($_COOKIE) ? array() : $_COOKIE);
$post = $useFilter ? filter_input_array(INPUT_POST, FILTER_UNSAFE_RAW) : (empty($_POST) ? [] : $_POST);
$cookies = $useFilter ? filter_input_array(INPUT_COOKIE, FILTER_UNSAFE_RAW) : (empty($_COOKIE) ? [] : $_COOKIE);

if (get_magic_quotes_gpc()) {
$post = Helpers::stripslashes($post, $useFilter);
Expand All @@ -114,7 +114,7 @@ public function createHttpRequest()
// remove invalid characters
$reChars = '#^[' . self::CHARS . ']*+\z#u';
if (!$this->binary) {
$list = array(& $query, & $post, & $cookies);
$list = [& $query, & $post, & $cookies];
while (list($key, $val) = each($list)) {
foreach ($val as $k => $v) {
if (is_string($k) && (!preg_match($reChars, $k) || preg_last_error())) {
Expand All @@ -135,8 +135,8 @@ public function createHttpRequest()


// FILES and create FileUpload objects
$files = array();
$list = array();
$files = [];
$list = [];
if (!empty($_FILES)) {
foreach ($_FILES as $k => $v) {
if (!$this->binary && is_string($k) && (!preg_match($reChars, $k) || preg_last_error())) {
Expand Down Expand Up @@ -168,14 +168,14 @@ public function createHttpRequest()
if (!$this->binary && is_string($k) && (!preg_match($reChars, $k) || preg_last_error())) {
continue;
}
$list[] = array(
$list[] = [
'name' => $v['name'][$k],
'type' => $v['type'][$k],
'size' => $v['size'][$k],
'tmp_name' => $v['tmp_name'][$k],
'error' => $v['error'][$k],
'@' => & $v['@'][$k],
);
];
}
}

Expand All @@ -184,7 +184,7 @@ public function createHttpRequest()
if (function_exists('apache_request_headers')) {
$headers = apache_request_headers();
} else {
$headers = array();
$headers = [];
foreach ($_SERVER as $k => $v) {
if (strncmp($k, 'HTTP_', 5) == 0) {
$k = substr($k, 5);
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Response.php
Expand Up @@ -214,7 +214,7 @@ public function getHeader($header, $default = NULL)
*/
public function getHeaders()
{
$headers = array();
$headers = [];
foreach (headers_list() as $header) {
$a = strpos($header, ':');
$headers[substr($header, 0, $a)] = (string) substr($header, $a + 2);
Expand All @@ -238,7 +238,7 @@ public static function date($time = NULL)
public function __destruct()
{
if (self::$fixIE && isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== FALSE
&& in_array($this->code, array(400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505), TRUE)
&& in_array($this->code, [400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505], TRUE)
&& preg_match('#^text/html(?:;|$)#', $this->getHeader('Content-Type', 'text/html'))
) {
echo Nette\Utils\Random::generate(2e3, " \t\r\n"); // sends invisible garbage for IE
Expand Down
34 changes: 17 additions & 17 deletions src/Http/Session.php
Expand Up @@ -35,7 +35,7 @@ class Session extends Nette\Object
private static $started;

/** @var array default configuration */
private $options = array(
private $options = [
// security
'referer_check' => '', // must be disabled because PHP implementation is invalid
'use_cookies' => 1, // must be enabled to prevent Session Hijacking and Fixation
Expand All @@ -55,7 +55,7 @@ class Session extends Nette\Object
'cache_expire' => NULL, // (default "180")
'hash_function' => NULL, // (default "0", means MD5)
'hash_bits_per_character' => NULL, // (default "4")
);
];

/** @var IRequest */
private $request;
Expand Down Expand Up @@ -96,7 +96,7 @@ public function start()

try {
// session_start returns FALSE on failure only sometimes
Nette\Utils\Callback::invokeSafe('session_start', array(), function ($message) use (& $e) {
Nette\Utils\Callback::invokeSafe('session_start', [], function ($message) use (& $e) {
$e = new Nette\InvalidStateException($message);
});
} catch (\Exception $e) {
Expand Down Expand Up @@ -158,7 +158,7 @@ public function start()
$this->regenerateId();
}

register_shutdown_function(array($this, 'clean'));
register_shutdown_function([$this, 'clean']);
}


Expand Down Expand Up @@ -260,9 +260,9 @@ public function setName($name)
}

session_name($name);
return $this->setOptions(array(
return $this->setOptions([
'name' => $name,
));
]);
}


Expand Down Expand Up @@ -396,7 +396,7 @@ public function getOptions()
*/
private function configure(array $config)
{
$special = array('cache_expire' => 1, 'cache_limiter' => 1, 'save_path' => 1, 'name' => 1);
$special = ['cache_expire' => 1, 'cache_limiter' => 1, 'save_path' => 1, 'name' => 1];

foreach ($config as $key => $value) {
if (!strncmp($key, 'session.', 8)) { // back compatibility
Expand Down Expand Up @@ -454,17 +454,17 @@ private function configure(array $config)
public function setExpiration($time)
{
if (empty($time)) {
return $this->setOptions(array(
return $this->setOptions([
'gc_maxlifetime' => self::DEFAULT_FILE_LIFETIME,
'cookie_lifetime' => 0,
));
]);

} else {
$time = Nette\Utils\DateTime::from($time)->format('U') - time();
return $this->setOptions(array(
return $this->setOptions([
'gc_maxlifetime' => $time,
'cookie_lifetime' => $time,
));
]);
}
}

Expand All @@ -478,11 +478,11 @@ public function setExpiration($time)
*/
public function setCookieParameters($path, $domain = NULL, $secure = NULL)
{
return $this->setOptions(array(
return $this->setOptions([
'cookie_path' => $path,
'cookie_domain' => $domain,
'cookie_secure' => $secure
));
]);
}


Expand All @@ -502,9 +502,9 @@ public function getCookieParameters()
*/
public function setSavePath($path)
{
return $this->setOptions(array(
return $this->setOptions([
'save_path' => $path,
));
]);
}


Expand All @@ -518,8 +518,8 @@ public function setStorage(ISessionStorage $storage)
throw new Nette\InvalidStateException('Unable to set storage when session has been started.');
}
session_set_save_handler(
array($storage, 'open'), array($storage, 'close'), array($storage, 'read'),
array($storage, 'write'), array($storage, 'remove'), array($storage, 'clean')
[$storage, 'open'], [$storage, 'close'], [$storage, 'read'],
[$storage, 'write'], [$storage, 'remove'], [$storage, 'clean']
);
return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Http/SessionSection.php
Expand Up @@ -196,7 +196,7 @@ public function setExpiration($time, $variables = NULL)
$whenBrowserIsClosed = FALSE;
}

foreach (is_array($variables) ? $variables : array($variables) as $variable) {
foreach (is_array($variables) ? $variables : [$variables] as $variable) {
$this->meta[$variable]['T'] = $time;
$this->meta[$variable]['B'] = $whenBrowserIsClosed;
}
Expand All @@ -212,7 +212,7 @@ public function setExpiration($time, $variables = NULL)
public function removeExpiration($variables = NULL)
{
$this->start();
foreach (is_array($variables) ? $variables : array($variables) as $variable) {
foreach (is_array($variables) ? $variables : [$variables] as $variable) {
unset($this->meta['']['T'], $this->meta['']['B']);
}
}
Expand Down

1 comment on commit 926df8e

@JanTvrdik
Copy link
Contributor

Choose a reason for hiding this comment

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

馃憤

Please sign in to comment.