From bd7be63539213abbdc0c571400c7232f084434a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Tue, 3 Mar 2015 19:36:14 +0100 Subject: [PATCH 1/7] composer.json: removed DI --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f9550c424..7ca3e37a1 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,6 @@ "require": { "php": ">=5.3.1", "nette/component-model": "~2.2", - "nette/di": "~2.3", "nette/http": "~2.2", "nette/reflection": "~2.2", "nette/security": "~2.2", @@ -28,6 +27,7 @@ }, "require-dev": { "nette/tester": "~1.3", + "nette/di": "~2.3", "nette/forms": "~2.2", "nette/robot-loader": "~2.2", "latte/latte": "~2.3" From e828f97bfdd55990c6a963e4bac07b4b3b2ad3b5 Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Mon, 9 Mar 2015 17:28:17 +0100 Subject: [PATCH 2/7] MicroPresenter: fixed passing params to callback --- src/Application/MicroPresenter.php | 11 ++++++----- tests/Application/MicroPresenter.invoke.phpt | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Application/MicroPresenter.php b/src/Application/MicroPresenter.php index f5022bd45..2bb1dbe8e 100644 --- a/src/Application/MicroPresenter.php +++ b/src/Application/MicroPresenter.php @@ -78,14 +78,15 @@ public function run(Application\Request $request) $reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback)); $params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params); - foreach ($reflection->getParameters() as $param) { - if ($param->getClassName()) { - unset($params[$param->getPosition()]); + if ($this->context) { + foreach ($reflection->getParameters() as $param) { + if ($param->getClassName()) { + unset($params[$param->getPosition()]); + } } - } - if ($this->context) { $params = Nette\DI\Helpers::autowireArguments($reflection, $params, $this->context); + $params['presenter'] = $this; } $response = call_user_func_array($callback, $params); diff --git a/tests/Application/MicroPresenter.invoke.phpt b/tests/Application/MicroPresenter.invoke.phpt index 3b6b72f29..1222db3ca 100644 --- a/tests/Application/MicroPresenter.invoke.phpt +++ b/tests/Application/MicroPresenter.invoke.phpt @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php'; class Invokable extends Nette\Object { - public function __invoke($page, $id) + public function __invoke($page, $id, NetteModule\MicroPresenter $presenter) { Notes::add('Callback id ' . $id . ' page ' . $page); } @@ -21,10 +21,11 @@ class Invokable extends Nette\Object test(function() { - $presenter = new NetteModule\MicroPresenter; + $presenter = $p = new NetteModule\MicroPresenter; $presenter->run(new Request('Nette:Micro', 'GET', array( - 'callback' => function($id, $page) { + 'callback' => function($id, $page, $presenter) use ($p) { + Assert::same($p, $presenter); Notes::add('Callback id ' . $id . ' page ' . $page); }, 'id' => 1, From 5a2ed4f5050b05c8e0f9f049c07241a99718a600 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 9 Mar 2015 14:20:33 +0100 Subject: [PATCH 3/7] ApplicationExtension: uses file in temp dir to invalidate container --- src/Bridges/ApplicationDI/ApplicationExtension.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index 56992e2bc..8ff7a1f68 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -35,13 +35,17 @@ class ApplicationExtension extends Nette\DI\CompilerExtension /** @var int */ private $invalidLinkMode; + /** @var string */ + private $tempFile; - public function __construct($debugMode = FALSE, array $scanDirs = NULL) + + public function __construct($debugMode = FALSE, array $scanDirs = NULL, $tempDir = NULL) { $this->defaults['scanDirs'] = (array) $scanDirs; $this->defaults['scanComposer'] = class_exists('Composer\Autoload\ClassLoader'); $this->defaults['catchExceptions'] = !$debugMode; $this->debugMode = $debugMode; + $this->tempFile = $tempDir ? $tempDir . '/' . urlencode(__CLASS__) : NULL; } @@ -64,7 +68,7 @@ public function loadConfiguration() $application->addSetup('Nette\Bridges\ApplicationTracy\RoutingPanel::initializePanel'); } - $touch = $this->debugMode && $config['scanDirs'] ? reset($config['scanDirs']) : NULL; // dir added as dependency + $touch = $this->debugMode && $config['scanDirs'] ? $this->tempFile : NULL; $presenterFactory = $container->addDefinition($this->prefix('presenterFactory')) ->setClass('Nette\Application\IPresenterFactory') ->setFactory('Nette\Application\PresenterFactory', array(new Nette\DI\Statement( @@ -125,7 +129,7 @@ private function findPresenters() $robot->acceptFiles = '*' . $config['scanFilter'] . '*.php'; $robot->rebuild(); $classes = array_keys($robot->getIndexedClasses()); - $this->getContainerBuilder()->addDependency(reset($config['scanDirs'])); + $this->getContainerBuilder()->addDependency($this->tempFile); } if ($config['scanComposer']) { From 86f33245591d122ab89d862e23236ef13a3e859c Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 10 Mar 2015 11:40:21 +0100 Subject: [PATCH 4/7] Template::__toString refactoring --- src/Bridges/ApplicationLatte/Template.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Bridges/ApplicationLatte/Template.php b/src/Bridges/ApplicationLatte/Template.php index 5d0207e5b..ee8b81556 100644 --- a/src/Bridges/ApplicationLatte/Template.php +++ b/src/Bridges/ApplicationLatte/Template.php @@ -60,13 +60,9 @@ public function render($file = NULL, array $params = array()) */ public function __toString() { - ob_start(); try { - $this->render(); - return ob_get_clean(); - + return $this->latte->renderToString($this->file, $this->params); } catch (\Exception $e) { - ob_end_clean(); if (func_num_args()) { throw $e; } From afde987ede936c0110feb779f8e607f2269fae2e Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 11 Mar 2015 07:37:11 +0100 Subject: [PATCH 5/7] PresenterComponentReflection::parseAnnotation accepts `*@annotation` --- src/Application/UI/PresenterComponentReflection.php | 2 +- .../PresenterComponentReflection.parseAnnotation.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Application/UI/PresenterComponentReflection.php b/src/Application/UI/PresenterComponentReflection.php index f86f25393..69497ae80 100644 --- a/src/Application/UI/PresenterComponentReflection.php +++ b/src/Application/UI/PresenterComponentReflection.php @@ -169,7 +169,7 @@ public static function convertType(& $val, $type) */ public static function parseAnnotation(\Reflector $ref, $name) { - if (!preg_match_all("#\\s@$name(?:\(\\s*([^)]*)\\s*\))?#", $ref->getDocComment(), $m)) { + if (!preg_match_all("#[\\s*]@$name(?:\(\\s*([^)]*)\\s*\))?#", $ref->getDocComment(), $m)) { return FALSE; } $res = array(); diff --git a/tests/Application/PresenterComponentReflection.parseAnnotation.phpt b/tests/Application/PresenterComponentReflection.parseAnnotation.phpt index 0e5616e27..8f159e7ff 100644 --- a/tests/Application/PresenterComponentReflection.parseAnnotation.phpt +++ b/tests/Application/PresenterComponentReflection.parseAnnotation.phpt @@ -20,7 +20,7 @@ require __DIR__ . '/../bootstrap.php'; * @persistent(FALSE) * @persistent(null) * @author - * @renderable + *@renderable * @secured(role = "admin", level = 2) */ class TestClass {} From 45f4efb155ccf172aeab134de20b4794164d4f97 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 16 Mar 2015 14:11:50 +0100 Subject: [PATCH 6/7] typo --- src/Application/UI/Presenter.php | 4 ++-- src/Bridges/ApplicationLatte/TemplateFactory.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index b98e42a2b..3cd7b2ffa 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -756,7 +756,7 @@ public function lastModified($lastModified, $etag = NULL, $expire = NULL) if ($expire !== NULL) { $this->httpResponse->setExpiration($expire); } - $helper = new Nette\Http\Context($this->httpRequest, $this->httpResponse); + $helper = new Http\Context($this->httpRequest, $this->httpResponse); if (!$helper->isModified($lastModified, $etag)) { $this->terminate(); } @@ -1311,7 +1311,7 @@ public function getFlashSession() /********************* services ****************d*g**/ - public function injectPrimary(Nette\DI\Container $context = NULL, Nette\Application\IPresenterFactory $presenterFactory = NULL, Nette\Application\IRouter $router = NULL, + public function injectPrimary(Nette\DI\Container $context = NULL, Application\IPresenterFactory $presenterFactory = NULL, Application\IRouter $router = NULL, Http\IRequest $httpRequest, Http\IResponse $httpResponse, Http\Session $session = NULL, Nette\Security\User $user = NULL, ITemplateFactory $templateFactory = NULL) { if ($this->presenterFactory !== NULL) { diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 9253118f4..91b9e99fd 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -22,7 +22,7 @@ */ class TemplateFactory extends Nette\Object implements UI\ITemplateFactory { - /** @var Nette\Bridges\ApplicationLatte\ILatteFactory */ + /** @var ILatteFactory */ private $latteFactory; /** @var Nette\Http\IRequest */ From da500c81c8bcabe74a0e0f312002bd00a99367be Mon Sep 17 00:00:00 2001 From: foxycode Date: Wed, 18 Mar 2015 03:38:45 +0100 Subject: [PATCH 7/7] =?UTF-8?q?FileResponse:=20According=20to=20RFC=205987?= =?UTF-8?q?=20Content-Disposition=20filename=20should=20not=20contain=20no?= =?UTF-8?q?n-US-ASCII=20characters.=20Proper=20way=20to=20encode=20filenam?= =?UTF-8?q?e=20is=20this:=20"filename*=3Dutf-8''%C5%BElu%C5%A5ou%C4%8Dk%C3?= =?UTF-8?q?%BD%20k%C5%AF%C5%88.txt".=20Unfortunately,=20RFC=205987=20is=20?= =?UTF-8?q?not=20supported=20by=20all=20browsers,=20so=20for=20compatibili?= =?UTF-8?q?ty=20reasons,=20filename=20should=20be=20sent=20like=20this:=20?= =?UTF-8?q?"filename=3D=C5=BElu=C5=A5ou=C4=8Dk=C3=BD=20k=C5=AF=C5=88.txt;?= =?UTF-8?q?=20filename*=3Dutf-8''%C5%BElu%C5%A5ou%C4%8Dk%C3%BD%20k%C5%AF%C?= =?UTF-8?q?5%88.txt".?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Application/Responses/FileResponse.php | 4 +++- .../FileResponse.contentDisposition.phpt | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Application/Responses/FileResponse.php b/src/Application/Responses/FileResponse.php index fb3b6a2ff..86142655e 100644 --- a/src/Application/Responses/FileResponse.php +++ b/src/Application/Responses/FileResponse.php @@ -93,7 +93,9 @@ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $htt { $httpResponse->setContentType($this->contentType); $httpResponse->setHeader('Content-Disposition', - ($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->name . '"'); + ($this->forceDownload ? 'attachment' : 'inline') + . '; filename="' . $this->name . '"' + . '; filename*=utf-8\'\'' . rawurlencode($this->name)); $filesize = $length = filesize($this->file); $handle = fopen($this->file, 'r'); diff --git a/tests/Application/FileResponse.contentDisposition.phpt b/tests/Application/FileResponse.contentDisposition.phpt index 79993ea4f..673e9fb48 100644 --- a/tests/Application/FileResponse.contentDisposition.phpt +++ b/tests/Application/FileResponse.contentDisposition.phpt @@ -28,7 +28,7 @@ test(function() { $fileResponse->send(new Http\Request(new Http\UrlScript), $response = new Http\Response); Assert::same( $origData, ob_get_clean() ); - Assert::same( 'attachment; filename="' . $fileName . '"', $response->getHeader('Content-Disposition') ); + Assert::same( 'attachment; filename="' . $fileName . '"; filename*=utf-8\'\'' . rawurlencode($fileName), $response->getHeader('Content-Disposition') ); }); @@ -44,5 +44,19 @@ test(function() { $fileResponse->send(new Http\Request(new Http\UrlScript), $response = new Http\Response); Assert::same( $origData, ob_get_clean() ); - Assert::same('inline; filename="' . $fileName . '"', $response->getHeader('Content-Disposition')); + Assert::same('inline; filename="' . $fileName . '"; filename*=utf-8\'\'' . rawurlencode($fileName), $response->getHeader('Content-Disposition')); +}); + + +test(function() { + $file = __FILE__; + $fileName = 'žluťoučký kůň.txt'; + $fileResponse = new FileResponse($file, $fileName); + $origData = file_get_contents($file); + + ob_start(); + $fileResponse->send(new Http\Request(new Http\UrlScript), $response = new Http\Response); + + Assert::same( $origData, ob_get_clean() ); + Assert::same('attachment; filename="' . $fileName . '"; filename*=utf-8\'\'' . rawurlencode($fileName), $response->getHeader('Content-Disposition')); });