Skip to content

Commit

Permalink
improved coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 21, 2015
1 parent d699b3c commit 39c39f8
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 148 deletions.
15 changes: 8 additions & 7 deletions src/Bootstrap/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace Nette;

use Nette,
Nette\DI,
Tracy;
use Nette;
use Nette\DI;
use Tracy;


/**
Expand All @@ -31,7 +31,7 @@ class Configurator extends Object

const COOKIE_SECRET = 'nette-debug';

/** @var callable[] function(Configurator $sender, DI\Compiler $compiler); Occurs after the compiler is created */
/** @var callable[] function (Configurator $sender, DI\Compiler $compiler); Occurs after the compiler is created */
public $onCompile;

/** @var array */
Expand Down Expand Up @@ -124,7 +124,7 @@ protected function getDefaultParameters()
'container' => array(
'class' => 'SystemContainer',
'parent' => 'Nette\DI\Container',
)
),
);
}

Expand Down Expand Up @@ -171,7 +171,8 @@ public function addConfig($file, $section = NULL)
$loader->load($file, $this->parameters['environment']);
trigger_error("Config file '$file' has sections, call addConfig() with second parameter Configurator::AUTO.", E_USER_WARNING);
$section = $this->parameters['environment'];
} catch (\Exception $e) {}
} catch (\Exception $e) {
}
}
$this->files[] = array($file, $section === self::AUTO ? $this->parameters['environment'] : $section);
return $this;
Expand Down Expand Up @@ -209,7 +210,7 @@ protected function createContainerFactory()
}

$me = $this;
$factory->onCompile[] = function(DI\ContainerFactory $factory, DI\Compiler $compiler, $config) use ($me) {
$factory->onCompile[] = function (DI\ContainerFactory $factory, DI\Compiler $compiler, $config) use ($me) {
foreach ($me->defaultExtensions as $name => $class) {
if (class_exists($class)) {
$compiler->addExtension($name, new $class);
Expand Down
12 changes: 6 additions & 6 deletions src/Bridges/Framework/NetteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

namespace Nette\Bridges\Framework;

use Nette,
Nette\DI\ContainerBuilder,
Nette\Utils\Validators,
Latte;
use Nette;
use Nette\DI\ContainerBuilder;
use Nette\Utils\Validators;
use Latte;


/**
Expand Down Expand Up @@ -301,8 +301,8 @@ private function setupLatte(ContainerBuilder $container, array $config)
} else {
Validators::assert($macro, 'callable');
}
$latte->addSetup('?->onCompile[] = function($engine) { ' . $macro . '($engine->getCompiler()); }', array('@self'));
$latteFactory->addSetup('?->onCompile[] = function($engine) { ' . $macro . '($engine->getCompiler()); }', array('@self'));
$latte->addSetup('?->onCompile[] = function ($engine) { ' . $macro . '($engine->getCompiler()); }', array('@self'));
$latteFactory->addSetup('?->onCompile[] = function ($engine) { ' . $macro . '($engine->getCompiler()); }', array('@self'));
}

if (class_exists('Nette\Templating\FileTemplate')) {
Expand Down
22 changes: 11 additions & 11 deletions src/Bridges/Framework/TracyBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

namespace Nette\Bridges\Framework;

use Nette,
Nette\Framework,
Tracy,
Tracy\Helpers,
Tracy\BlueScreen,
Latte;
use Nette;
use Nette\Framework;
use Tracy;
use Tracy\Helpers;
use Tracy\BlueScreen;
use Latte;


/**
* Initializes Tracy
* Initializes Tracy.
*/
class TracyBridge
{
Expand All @@ -31,7 +31,7 @@ public static function initialize()
. (Framework::REVISION ? ' (' . Framework::REVISION . ')' : '');
}

$blueScreen->addPanel(function($e) {
$blueScreen->addPanel(function ($e) {
if ($e instanceof Latte\CompileException) {
return array(
'tab' => 'Template',
Expand All @@ -40,12 +40,12 @@ public static function initialize()
: '')
. '<pre>'
. BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine)
. '</pre>'
. '</pre>',
);
}
});

$blueScreen->addPanel(function($e) {
$blueScreen->addPanel(function ($e) {
if ($e instanceof Nette\Neon\Exception && preg_match('#line (\d+)#', $e->getMessage(), $m)
&& ($trace = Helpers::findTrace($e->getTrace(), 'Nette\Neon\Decoder::decode'))
) {
Expand All @@ -54,7 +54,7 @@ public static function initialize()
'panel' => ($trace2 = Helpers::findTrace($e->getTrace(), 'Nette\DI\Config\Adapters\NeonAdapter::load'))
? '<p><b>File:</b> ' . Helpers::editorLink($trace2['args'][0], $m[1]) . '</p>'
. BlueScreen::highlightFile($trace2['args'][0], $m[1])
: BlueScreen::highlightPhp($trace['args'][0], $m[1])
: BlueScreen::highlightPhp($trace['args'][0], $m[1]),
);
}
});
Expand Down
6 changes: 3 additions & 3 deletions tests/Bootstrap/Compiler.extension.nette.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\DI\Compiler: services setup.
*/

use Nette\DI,
Tester\Assert;
use Nette\DI;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand Down Expand Up @@ -61,7 +61,7 @@ require TEMP_DIR . '/code.php';
$container = new Container;


Assert::type( 'Latte\Engine', $container->createService('nette.latte') );
Assert::type('Latte\Engine', $container->createService('nette.latte'));
$container->createService('nette.latte')->setLoader(new Latte\Loaders\StringLoader)->compile('');

Assert::same(array(
Expand Down
6 changes: 3 additions & 3 deletions tests/Bootstrap/Configurator.autowireExcluded.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Configurator and autowiring blacklist
*/

use Nette\Configurator,
Tester\Assert;
use Nette\Configurator;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -19,7 +19,7 @@ class Foo extends stdClass
$configurator = new Configurator;
$configurator->setTempDirectory(TEMP_DIR);

$configurator->onCompile = function($configurator, $compiler) {
$configurator->onCompile = function ($configurator, $compiler) {
$compiler->getContainerBuilder()->addExcludedClasses(array('stdClass'));
};

Expand Down
18 changes: 9 additions & 9 deletions tests/Bootstrap/Configurator.basic.headers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Configurator and headers.
*/

use Nette\Configurator,
Tester\Assert;
use Nette\Configurator;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -28,19 +28,19 @@ $container = $configurator->createContainer();


$headers = headers_list();
Assert::contains( 'X-Frame-Options: SAMEORIGIN', $headers );
Assert::contains( 'Content-Type: text/html; charset=utf-8', $headers );
Assert::contains( 'X-Powered-By: Nette Framework', $headers );
Assert::contains( 'A: b', $headers );
Assert::notContains( 'C:', $headers );
Assert::contains('X-Frame-Options: SAMEORIGIN', $headers);
Assert::contains('Content-Type: text/html; charset=utf-8', $headers);
Assert::contains('X-Powered-By: Nette Framework', $headers);
Assert::contains('A: b', $headers);
Assert::notContains('C:', $headers);



echo ' '; @ob_flush(); flush();

Assert::true( headers_sent() );
Assert::true(headers_sent());

Assert::error(function(){
Assert::error(function () {
$configurator = new Configurator;
$configurator->setTempDirectory(TEMP_DIR);
$configurator->addParameters(array('container' => array('class' => 'Container2')));
Expand Down
22 changes: 11 additions & 11 deletions tests/Bootstrap/Configurator.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Test: Nette\Configurator and createContainer.
*/

use Nette\Configurator,
Tester\Assert;
use Nette\Configurator;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -23,16 +23,16 @@ $configurator->addParameters(array(
$container = $configurator->addConfig('files/configurator.basic.neon', 'production')
->createContainer();

Assert::same( 'overwritten', $container->parameters['wwwDir'] );
Assert::same( 'hello world', $container->parameters['foo'] );
Assert::same( 'hello world', $container->parameters['foo2'] );
Assert::same( 'overwritten', $container->parameters['foo3'] );
Assert::same( 'hello', $container->parameters['bar'] );
Assert::same( 'hello world', constant('BAR') );
Assert::same( 'Europe/Prague', date_default_timezone_get() );
Assert::same('overwritten', $container->parameters['wwwDir']);
Assert::same('hello world', $container->parameters['foo']);
Assert::same('hello world', $container->parameters['foo2']);
Assert::same('overwritten', $container->parameters['foo3']);
Assert::same('hello', $container->parameters['bar']);
Assert::same('hello world', constant('BAR'));
Assert::same('Europe/Prague', date_default_timezone_get());

Assert::same( array(
Assert::same(array(
'dsn' => 'sqlite2::memory:',
'user' => 'dbuser',
'password' => 'secret',
), $container->parameters['database'] );
), $container->parameters['database']);
72 changes: 36 additions & 36 deletions tests/Bootstrap/Configurator.debugMode.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,96 @@
* Test: Nette\Configurator and production mode.
*/

use Nette\Configurator,
Tester\Assert;
use Nette\Configurator;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';



test(function(){
test(function () {
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = 'xx';

$configurator = new Configurator;
Assert::false( $configurator->isDebugMode() );
Assert::false($configurator->isDebugMode());

$configurator->setDebugMode(TRUE);
Assert::true( $configurator->isDebugMode() );
Assert::true($configurator->isDebugMode());

$configurator->setDebugMode(FALSE);
Assert::false( $configurator->isDebugMode() );
Assert::false($configurator->isDebugMode());

$configurator->setDebugMode($_SERVER['REMOTE_ADDR']);
Assert::true( $configurator->isDebugMode() );
Assert::true($configurator->isDebugMode());
});


Assert::exception(function(){
Assert::exception(function () {
$configurator = new Configurator;
$configurator->setDebugMode(1);
}, 'Nette\InvalidArgumentException');


test(function(){ // localhost
test(function () { // localhost
unset($_SERVER['HTTP_X_FORWARDED_FOR']);

$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
Assert::true( Configurator::detectDebugMode() );
Assert::true( Configurator::detectDebugMode('192.168.1.1') );
Assert::true(Configurator::detectDebugMode());
Assert::true(Configurator::detectDebugMode('192.168.1.1'));

$_SERVER['REMOTE_ADDR'] = '::1';
Assert::true( Configurator::detectDebugMode() );
Assert::true(Configurator::detectDebugMode());

$_SERVER['REMOTE_ADDR'] = '192.168.1.1';
Assert::false( Configurator::detectDebugMode() );
Assert::false( Configurator::detectDebugMode('192.168.1.1.0') );
Assert::true( Configurator::detectDebugMode('192.168.1.1') );
Assert::true( Configurator::detectDebugMode('a,192.168.1.1,b') );
Assert::true( Configurator::detectDebugMode('a 192.168.1.1 b') );

Assert::false( Configurator::detectDebugMode(array()) );
Assert::true( Configurator::detectDebugMode(array('192.168.1.1')) );
Assert::false(Configurator::detectDebugMode());
Assert::false(Configurator::detectDebugMode('192.168.1.1.0'));
Assert::true(Configurator::detectDebugMode('192.168.1.1'));
Assert::true(Configurator::detectDebugMode('a,192.168.1.1,b'));
Assert::true(Configurator::detectDebugMode('a 192.168.1.1 b'));

Assert::false(Configurator::detectDebugMode(array()));
Assert::true(Configurator::detectDebugMode(array('192.168.1.1')));
});


test(function(){ // localhost + proxy
test(function () { // localhost + proxy
$_SERVER['HTTP_X_FORWARDED_FOR'] = 'xx';

$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
Assert::false( Configurator::detectDebugMode() );
Assert::false(Configurator::detectDebugMode());

$_SERVER['REMOTE_ADDR'] = '::1';
Assert::false( Configurator::detectDebugMode() );
Assert::false(Configurator::detectDebugMode());

$_SERVER['REMOTE_ADDR'] = '192.168.1.1';
Assert::false( Configurator::detectDebugMode() );
Assert::true( Configurator::detectDebugMode($_SERVER['REMOTE_ADDR']) );
Assert::false(Configurator::detectDebugMode());
Assert::true(Configurator::detectDebugMode($_SERVER['REMOTE_ADDR']));
});


test(function(){ // missing $_SERVER['REMOTE_ADDR']
test(function () { // missing $_SERVER['REMOTE_ADDR']
unset($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']);

Assert::false( Configurator::detectDebugMode() );
Assert::false( Configurator::detectDebugMode('127.0.0.1') );
Assert::false(Configurator::detectDebugMode());
Assert::false(Configurator::detectDebugMode('127.0.0.1'));

Assert::true( Configurator::detectDebugMode(php_uname('n')) );
Assert::true( Configurator::detectDebugMode(array(php_uname('n'))) );
Assert::true(Configurator::detectDebugMode(php_uname('n')));
Assert::true(Configurator::detectDebugMode(array(php_uname('n'))));
});


test(function(){ // secret
test(function () { // secret
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = '192.168.1.1';
$_COOKIE[Configurator::COOKIE_SECRET] = '*secret*';

Assert::false( Configurator::detectDebugMode() );
Assert::true( Configurator::detectDebugMode('192.168.1.1') );
Assert::false( Configurator::detectDebugMode('[email protected]') );
Assert::true( Configurator::detectDebugMode('*secret*@192.168.1.1') );
Assert::false(Configurator::detectDebugMode());
Assert::true(Configurator::detectDebugMode('192.168.1.1'));
Assert::false(Configurator::detectDebugMode('[email protected]'));
Assert::true(Configurator::detectDebugMode('*secret*@192.168.1.1'));

$_COOKIE[Configurator::COOKIE_SECRET] = array('*secret*');
Assert::false( Configurator::detectDebugMode('*secret*@192.168.1.1') );
Assert::false(Configurator::detectDebugMode('*secret*@192.168.1.1'));
});
Loading

0 comments on commit 39c39f8

Please sign in to comment.