Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added ROUTE::OPTIONAL_SECURED #1196

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Nette/Application/IRouter.php
Expand Up @@ -23,6 +23,9 @@ interface IRouter
/** HTTPS route */
const SECURED = 2;

/** HTTP & HTTPS route, depends if secured http request */
const OPTIONAL_SECURED = 4;
Copy link
Member

Choose a reason for hiding this comment

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

OPTIONALLY_SECURED is gramatically right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will commit grammatical fix later


/**
* Maps HTTP request to a Request object.
* @return Request|NULL
Expand Down
2 changes: 1 addition & 1 deletion Nette/Application/MicroPresenter.php
Expand Up @@ -116,7 +116,7 @@ public function createTemplate($class = NULL, $latteFactory = NULL)
$template->baseUrl = rtrim($url->getBaseUrl(), '/');
$template->basePath = rtrim($url->getBasePath(), '/');

$template->registerHelperLoader('Nette\Templating\Helpers::loader');
$template->registerHelperLoader('Nette\Latte\Runtime\Filters::loader');
$template->setCacheStorage($context->getService('nette.templateCacheStorage'));
$template->onPrepareFilters[] = function($template) use ($latteFactory) {
$template->registerFilter($latteFactory ? $latteFactory() : new Nette\Latte\Engine);
Expand Down
8 changes: 6 additions & 2 deletions Nette/Application/Routers/Route.php
Expand Up @@ -105,6 +105,8 @@ class Route extends Nette\Object implements Application\IRouter
/** @var int */
private $flags;

/** @var bool */
private $httpRequestSecured = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong coding style, should be in upper case.

Copy link
Contributor

Choose a reason for hiding this comment

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

...FALSE should be in uppercase for clarification


/**
* @param string URL mask, e.g. '<presenter>/<action>/<id \d{1,3}>'
Expand Down Expand Up @@ -251,13 +253,15 @@ public function match(Nette\Http\IRequest $httpRequest)
unset($params[self::PRESENTER_KEY]);
}

$this->httpRequestSecured = $httpRequest->isSecured();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not save the state here, it's not neccessary and makes it harder to test router.


return new Application\Request(
$presenter,
$httpRequest->getMethod(),
$params,
$httpRequest->getPost(),
$httpRequest->getFiles(),
array(Application\Request::SECURED => $httpRequest->isSecured())
array(Application\Request::SECURED => $this->httpRequestSecured)
);
}

Expand Down Expand Up @@ -404,7 +408,7 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
return NULL; // TODO: implement counterpart in match() ?
}

$url = ($this->flags & self::SECURED ? 'https:' : 'http:') . $url;
$url = ((($this->flags & self::SECURED) || (($this->flags & self::OPTIONAL_SECURED) && $this->httpRequestSecured)) ? 'https:' : 'http:') . $url;
Copy link
Contributor

Choose a reason for hiding this comment

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

So this wouldn't work correctly if match() isn't called? It seems to be wrong. Also I think brackets around bitwise operations are unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know about case when this would be used and match() isn't called? And brackets are for visual diff of conditions

Copy link
Contributor

Choose a reason for hiding this comment

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

Imagine you have 5 routes. You open a page which is matched by first route. Other four won't have match() called. Then, in your template, you want to generate a link to any of those four. :)


// build query string
if ($this->xlat) {
Expand Down
7 changes: 6 additions & 1 deletion Nette/Application/Routers/SimpleRouter.php
Expand Up @@ -33,6 +33,8 @@ class SimpleRouter extends Nette\Object implements Application\IRouter
/** @var int */
private $flags;

/** @var bool */
private $httpRequestSecured = false;

/**
* @param array default values
Expand Down Expand Up @@ -81,6 +83,8 @@ public function match(Nette\Http\IRequest $httpRequest)
$presenter = $this->module . $params[self::PRESENTER_KEY];
unset($params[self::PRESENTER_KEY]);

$this->httpRequestSecured = $httpRequest->isSecured();

return new Application\Request(
$presenter,
$httpRequest->getMethod(),
Expand Down Expand Up @@ -118,7 +122,8 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
}
}

$url = ($this->flags & self::SECURED ? 'https://' : 'http://') . $refUrl->getAuthority() . $refUrl->getPath();
$url = ((($this->flags & self::SECURED) || (($this->flags & self::OPTIONAL_SECURED) && $this->httpRequestSecured)) ? 'https://' : 'http://') . $refUrl->getAuthority() . $refUrl->getPath();

$sep = ini_get('arg_separator.input');
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
if ($query != '') { // intentionally ==
Expand Down
2 changes: 1 addition & 1 deletion Nette/Application/UI/Control.php
Expand Up @@ -59,7 +59,7 @@ protected function createTemplate($class = NULL)
$template = $class ? new $class : new Nette\Templating\FileTemplate;
$presenter = $this->getPresenter(FALSE);
$template->onPrepareFilters[] = $this->templatePrepareFilters;
$template->registerHelperLoader('Nette\Templating\Helpers::loader');
$template->registerHelperLoader('Nette\Latte\Runtime\Filters::loader');

// default parameters
$template->control = $template->_control = $this;
Expand Down
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\DI\Extensions;
namespace Nette\Bridges\DI;

use Nette;

Expand Down
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\DI\Extensions;
namespace Nette\Bridges\DI;

use Nette,
Nette\DI\ContainerBuilder,
Expand Down Expand Up @@ -171,7 +171,7 @@ private function setupSession(ContainerBuilder $container, array $config)

if ($container->parameters['debugMode'] && $config['debugger']) {
$session->addSetup('Nette\Diagnostics\Debugger::getBar()->addPanel(?)', array(
new Nette\DI\Statement('Nette\Http\Diagnostics\SessionPanel')
new Nette\DI\Statement('Nette\Bridges\Tracy\HttpSessionPanel')
));
}

Expand All @@ -194,7 +194,7 @@ private function setupSecurity(ContainerBuilder $container, array $config)

if ($container->parameters['debugMode'] && $config['debugger']) {
$user->addSetup('Nette\Diagnostics\Debugger::getBar()->addPanel(?)', array(
new Nette\DI\Statement('Nette\Security\Diagnostics\UserPanel')
new Nette\DI\Statement('Nette\Bridges\Tracy\SecurityUserPanel')
));
}

Expand Down Expand Up @@ -232,7 +232,7 @@ private function setupApplication(ContainerBuilder $container, array $config)
->addSetup('$errorPresenter', array($config['errorPresenter']));

if ($config['debugger']) {
$application->addSetup('Nette\Application\Diagnostics\RoutingPanel::initializePanel');
$application->addSetup('Nette\Bridges\Tracy\RoutingPanel::initializePanel');
}

$presenterFactory = $container->addDefinition($this->prefix('presenterFactory'))
Expand All @@ -258,7 +258,7 @@ private function setupRouting(ContainerBuilder $container, array $config)

if ($container->parameters['debugMode'] && $config['debugger']) {
$container->getDefinition('application')->addSetup('Nette\Diagnostics\Debugger::getBar()->addPanel(?)', array(
new Nette\DI\Statement('Nette\Application\Diagnostics\RoutingPanel')
new Nette\DI\Statement('Nette\Bridges\Tracy\RoutingPanel')
));
}
}
Expand Down Expand Up @@ -293,7 +293,7 @@ private function setupLatte(ContainerBuilder $container, array $config)
$container->addDefinition($this->prefix('template'))
->setClass('Nette\Templating\FileTemplate')
->addSetup('registerFilter', array($latte))
->addSetup('registerHelperLoader', array('Nette\Templating\Helpers::loader'))
->addSetup('registerHelperLoader', array('Nette\Latte\Runtime\Filters::loader'))
->setAutowired(FALSE);

foreach ($config['macros'] as $macro) {
Expand Down Expand Up @@ -336,7 +336,7 @@ private function setupDatabase(ContainerBuilder $container, array $config)
->setClass('Nette\Database\Connection', array($info['dsn'], $info['user'], $info['password'], $info['options']))
->setAutowired($info['autowired'])
->addSetup('Nette\Diagnostics\Debugger::getBlueScreen()->addPanel(?)', array(
'Nette\Database\Diagnostics\ConnectionPanel::renderException'
'Nette\Bridges\Tracy\DatabaseConnectionPanel::renderException'
));

if (!$info['reflection']) {
Expand Down Expand Up @@ -386,7 +386,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)

if ($container->parameters['debugMode']) {
if ($config['container']['debugger']) {
$config['debugger']['bar'][] = 'Nette\DI\Diagnostics\ContainerPanel';
$config['debugger']['bar'][] = 'Nette\Bridges\Tracy\DIContainerPanel';
}

foreach ((array) $config['debugger']['bar'] as $item) {
Expand Down
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\DI\Extensions;
namespace Nette\Bridges\DI;

use Nette;

Expand Down
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Latte\Macros;
namespace Nette\Bridges\Latte;

use Nette,
Nette\Latte;
Expand Down Expand Up @@ -39,7 +39,7 @@ public function initialize()
public function finalize()
{
if ($this->used) {
return array('Nette\Latte\Macros\CacheMacro::initRuntime($template, $_g);');
return array('Nette\Bridges\Latte\CacheMacro::initRuntime($template, $_g);');
}
}

Expand All @@ -53,7 +53,7 @@ public function nodeOpened(Latte\MacroNode $node)
$this->used = TRUE;
$node->isEmpty = FALSE;
$node->openingCode = Latte\PhpWriter::using($node)
->write('<?php if (Nette\Latte\Macros\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>',
->write('<?php if (Nette\Bridges\Latte\CacheMacro::createCache($netteCacheStorage, %var, $_g->caches, %node.array?)) { ?>',
Nette\Utils\Random::generate()
);
}
Expand Down
Expand Up @@ -5,13 +5,14 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Latte\Macros;
namespace Nette\Bridges\Latte;

use Nette,
Nette\Latte,
Nette\Latte\MacroNode,
Nette\Latte\PhpWriter,
Nette\Latte\CompileException,
Nette\Latte\Macros\MacroSet,
Nette\Forms\Form;


Expand All @@ -32,7 +33,7 @@ class FormMacros extends MacroSet
public static function install(Latte\Compiler $compiler)
{
$me = new static($compiler);
$me->addMacro('form', array($me, 'macroForm'), 'Nette\Latte\Macros\FormMacros::renderFormEnd($_form)');
$me->addMacro('form', array($me, 'macroForm'), 'Nette\Bridges\Latte\FormMacros::renderFormEnd($_form)');
$me->addMacro('formContainer', array($me, 'macroFormContainer'), '$_form = array_pop($_formStack)');
$me->addMacro('label', array($me, 'macroLabel'), array($me, 'macroLabelEnd'));
$me->addMacro('input', array($me, 'macroInput'), NULL, array($me, 'macroInputAttr'));
Expand All @@ -58,7 +59,7 @@ public function macroForm(MacroNode $node, PhpWriter $writer)
}
$node->tokenizer->reset();
return $writer->write(
'Nette\Latte\Macros\FormMacros::renderFormBegin($form = $_form = '
'Nette\Bridges\Latte\FormMacros::renderFormBegin($form = $_form = '
. ($name[0] === '$' ? 'is_object(%node.word) ? %node.word : ' : '')
. '$_control[%node.word], %node.array)'
);
Expand Down Expand Up @@ -157,7 +158,7 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer)

if ($tagName === 'form') {
return $writer->write(
'Nette\Latte\Macros\FormMacros::renderFormBegin($form = $_form = '
'Nette\Bridges\Latte\FormMacros::renderFormBegin($form = $_form = '
. ($name[0] === '$' ? 'is_object(%0.word) ? %0.word : ' : '')
. '$_control[%0.word], %1.var, FALSE)',
$name,
Expand Down Expand Up @@ -193,7 +194,7 @@ public function macroNameEnd(MacroNode $node, PhpWriter $writer)
{
preg_match('#^(.*? n:\w+>)(.*)(<[^?].*)\z#s', $node->content, $parts);
if (strtolower($node->htmlNode->name) === 'form') {
$node->content = $parts[1] . $parts[2] . '<?php Nette\Latte\Macros\FormMacros::renderFormEnd($_form, FALSE) ?>' . $parts[3];
$node->content = $parts[1] . $parts[2] . '<?php Nette\Bridges\Latte\FormMacros::renderFormEnd($_form, FALSE) ?>' . $parts[3];
} else { // select, textarea
$node->content = $parts[1] . '<?php echo $_input->getControl()->getHtml() ?>' . $parts[3];
}
Expand Down
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\DI\Diagnostics;
namespace Nette\Bridges\Tracy;

use Nette,
Nette\DI\Container;
Expand All @@ -16,7 +16,7 @@
*
* @author Patrik Votoček
*/
class ContainerPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
class DIContainerPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
{
/** @var Nette\DI\Container */
private $container;
Expand All @@ -35,7 +35,7 @@ public function __construct(Container $container)
public function getTab()
{
ob_start();
require __DIR__ . '/templates/ContainerPanel.tab.phtml';
require __DIR__ . '/templates/DIContainerPanel.tab.phtml';
return ob_get_clean();
}

Expand Down Expand Up @@ -66,7 +66,7 @@ public function getPanel()
}

ob_start();
require __DIR__ . '/templates/ContainerPanel.panel.phtml';
require __DIR__ . '/templates/DIContainerPanel.panel.phtml';
return ob_get_clean();
}

Expand Down
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Database\Diagnostics;
namespace Nette\Bridges\Tracy;

use Nette,
Nette\Database\Helpers;
Expand All @@ -16,7 +16,7 @@
*
* @author David Grudl
*/
class ConnectionPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
class DatabaseConnectionPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
{
/** @var int */
public $maxQueries = 100;
Expand Down
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Http\Diagnostics;
namespace Nette\Bridges\Tracy;

use Nette;

Expand All @@ -15,7 +15,7 @@
*
* @author David Grudl
*/
class SessionPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
class HttpSessionPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
{

/**
Expand All @@ -25,7 +25,7 @@ class SessionPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
public function getTab()
{
ob_start();
require __DIR__ . '/templates/SessionPanel.tab.phtml';
require __DIR__ . '/templates/HttpSessionPanel.tab.phtml';
return ob_get_clean();
}

Expand All @@ -37,7 +37,7 @@ public function getTab()
public function getPanel()
{
ob_start();
require __DIR__ . '/templates/SessionPanel.panel.phtml';
require __DIR__ . '/templates/HttpSessionPanel.panel.phtml';
return ob_get_clean();
}

Expand Down
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Application\Diagnostics;
namespace Nette\Bridges\Tracy;

use Nette,
Nette\Application\Routers,
Expand Down
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/

namespace Nette\Security\Diagnostics;
namespace Nette\Bridges\Tracy;

use Nette;

Expand All @@ -15,7 +15,7 @@
*
* @author David Grudl
*/
class UserPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
class SecurityUserPanel extends Nette\Object implements Nette\Diagnostics\IBarPanel
{
/** @var Nette\Security\User */
private $user;
Expand All @@ -34,7 +34,7 @@ public function __construct(Nette\Security\User $user)
public function getTab()
{
ob_start();
require __DIR__ . '/templates/UserPanel.tab.phtml';
require __DIR__ . '/templates/SecurityUserPanel.tab.phtml';
return ob_get_clean();
}

Expand All @@ -46,7 +46,7 @@ public function getTab()
public function getPanel()
{
ob_start();
require __DIR__ . '/templates/UserPanel.panel.phtml';
require __DIR__ . '/templates/SecurityUserPanel.panel.phtml';
return ob_get_clean();
}

Expand Down