From 01e3e5941a552467272d5bfd6d037b9f4d8932ab Mon Sep 17 00:00:00 2001 From: JSifalda Date: Thu, 3 Jan 2013 16:34:13 +0100 Subject: [PATCH 01/47] Method __toString() must return a string value --- Nette/Application/UI/Link.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nette/Application/UI/Link.php b/Nette/Application/UI/Link.php index 4178865098..71da482212 100644 --- a/Nette/Application/UI/Link.php +++ b/Nette/Application/UI/Link.php @@ -104,7 +104,7 @@ public function getParameters() public function __toString() { try { - return $this->component->link($this->destination, $this->params); + return (string) $this->component->link($this->destination, $this->params); } catch (\Exception $e) { trigger_error("Exception in " . __METHOD__ . "(): {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", E_USER_ERROR); From 2e2d93a9b2cad34a05b379338fa335473f8a8df6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 4 Jan 2013 16:55:45 +0100 Subject: [PATCH 02/47] Forms: getHttpData() always returns array [Closes #531] --- Nette/Forms/Controls/BaseControl.php | 2 +- Nette/Forms/Form.php | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Nette/Forms/Controls/BaseControl.php b/Nette/Forms/Controls/BaseControl.php index 79955cae33..52d6510bcc 100644 --- a/Nette/Forms/Controls/BaseControl.php +++ b/Nette/Forms/Controls/BaseControl.php @@ -340,7 +340,7 @@ public function setDefaultValue($value) public function loadHttpData() { $path = explode('[', strtr(str_replace(array('[]', ']'), '', $this->getHtmlName()), '.', '_')); - $this->setValue(Nette\Utils\Arrays::get((array) $this->getForm()->getHttpData(), $path, NULL)); + $this->setValue(Nette\Utils\Arrays::get($this->getForm()->getHttpData(), $path, NULL)); } diff --git a/Nette/Forms/Form.php b/Nette/Forms/Form.php index f18dd5f424..ce0452ac2c 100644 --- a/Nette/Forms/Form.php +++ b/Nette/Forms/Form.php @@ -357,8 +357,7 @@ public function isAnchored() final public function isSubmitted() { if ($this->submittedBy === NULL && count($this->getControls())) { - $this->getHttpData(); - $this->submittedBy = $this->httpData !== NULL; + $this->submittedBy = (bool) $this->getHttpData(); } return $this->submittedBy; } @@ -453,7 +452,7 @@ protected function receiveHttpData() { $httpRequest = $this->getHttpRequest(); if (strcasecmp($this->getMethod(), $httpRequest->getMethod())) { - return; + return array(); } if ($httpRequest->isMethod('post')) { @@ -464,7 +463,7 @@ protected function receiveHttpData() if ($tracker = $this->getComponent(self::TRACKER_ID, FALSE)) { if (!isset($data[self::TRACKER_ID]) || $data[self::TRACKER_ID] !== $tracker->getValue()) { - return; + return array(); } } From 07030780ea44f3e1eaa6ed7ecd5fd7c73e2d12ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Sun, 18 Nov 2012 14:28:59 +0100 Subject: [PATCH 03/47] Forms: fix removeGroup if control is in container --- Nette/Forms/Form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nette/Forms/Form.php b/Nette/Forms/Form.php index ce0452ac2c..b229c9f61f 100644 --- a/Nette/Forms/Form.php +++ b/Nette/Forms/Form.php @@ -277,7 +277,7 @@ public function removeGroup($name) } foreach ($group->getControls() as $control) { - $this->removeComponent($control); + $control->getParent()->removeComponent($control); } unset($this->groups[$name]); From 0cf33aa23bf129ac87fa4963eabb77f263cf2b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Wed, 13 Feb 2013 17:28:57 +0100 Subject: [PATCH 04/47] Forms: allow adding errors in onValidate event --- Nette/Forms/Container.php | 2 +- tests/Nette/Forms/Container.validate().phpt | 29 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/Nette/Forms/Container.validate().phpt diff --git a/Nette/Forms/Container.php b/Nette/Forms/Container.php index fdcef1265b..77cfa3032f 100644 --- a/Nette/Forms/Container.php +++ b/Nette/Forms/Container.php @@ -145,12 +145,12 @@ public function isValid() public function validate() { $this->valid = TRUE; - $this->onValidate($this); foreach ($this->getControls() as $control) { if (!$control->getRules()->validate()) { $this->valid = FALSE; } } + $this->onValidate($this); } diff --git a/tests/Nette/Forms/Container.validate().phpt b/tests/Nette/Forms/Container.validate().phpt new file mode 100644 index 0000000000..f3689c0efe --- /dev/null +++ b/tests/Nette/Forms/Container.validate().phpt @@ -0,0 +1,29 @@ +addText('name', 'Text:', 10)->addRule($form::NUMERIC); +$form->onValidate[] = function (Container $container) { + $container['name']->addError('just fail'); +}; + +$form->setValues(array('name' => "invalid*input")); +$form->validate(); + +Assert::same(array( + 'Please enter a numeric value.', + 'just fail', +), $form['name']->getErrors()); From 52c13ff6e2fe262996bf2875b3bd140636c097d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Sebastian=20Fab=C3=ADk?= Date: Sun, 27 Jan 2013 20:34:29 +0100 Subject: [PATCH 05/47] Presenter: fixed throwing of confusing exception --- Nette/Application/UI/Presenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nette/Application/UI/Presenter.php b/Nette/Application/UI/Presenter.php index 624b3568e9..d504ccf1d7 100644 --- a/Nette/Application/UI/Presenter.php +++ b/Nette/Application/UI/Presenter.php @@ -307,7 +307,7 @@ public function processSignal() } catch (Nette\InvalidArgumentException $e) {} if (isset($e) || $component === NULL) { - throw new BadSignalException("The signal receiver component '$this->signalReceiver' is not found."); + throw new BadSignalException("The signal receiver component '$this->signalReceiver' is not found.", NULL, isset($e) ? $e : NULL); } elseif (!$component instanceof ISignalReceiver) { throw new BadSignalException("The signal receiver component '$this->signalReceiver' is not ISignalReceiver implementor."); From 4161da5356bc51c228ec3416069f291bff68d45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C2=9Aek?= Date: Mon, 7 Jan 2013 09:54:34 +0100 Subject: [PATCH 06/47] Debugger: Fixed PHP Warning encoding error --- Nette/Diagnostics/templates/bar.errors.panel.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nette/Diagnostics/templates/bar.errors.panel.phtml b/Nette/Diagnostics/templates/bar.errors.panel.phtml index 9dbc60465d..c522695908 100644 --- a/Nette/Diagnostics/templates/bar.errors.panel.phtml +++ b/Nette/Diagnostics/templates/bar.errors.panel.phtml @@ -19,7 +19,7 @@ use Nette; $count): list($message, $file, $line) = explode('|', $item) ?> -
+
From 1f49754d81a1be6700651d30a80c37fa1e295d0c Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 13 Feb 2013 22:26:55 +0100 Subject: [PATCH 07/47] Session: added validation for session ID value [Closes #965] --- Nette/Http/Session.php | 5 +++++ tests/Nette/Http/Session.invalidId.phpt | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/Nette/Http/Session.invalidId.phpt diff --git a/Nette/Http/Session.php b/Nette/Http/Session.php index 17556f6de0..0ae747b785 100644 --- a/Nette/Http/Session.php +++ b/Nette/Http/Session.php @@ -91,6 +91,11 @@ public function start() $this->configure($this->options); + $id = & $_COOKIE[session_name()]; + if (!is_string($id) || !preg_match('#^[0-9a-zA-Z,-]{22,128}\z#i', $id)) { + unset($_COOKIE[session_name()]); + } + set_error_handler(function($severity, $message) use (& $error) { // session_start returns FALSE on failure since PHP 5.3.0. if (($severity & error_reporting()) === $severity) { $error = $message; diff --git a/tests/Nette/Http/Session.invalidId.phpt b/tests/Nette/Http/Session.invalidId.phpt new file mode 100644 index 0000000000..3ac0d71210 --- /dev/null +++ b/tests/Nette/Http/Session.invalidId.phpt @@ -0,0 +1,23 @@ +setTempDirectory(TEMP_DIR)->createContainer(); + +$session = $container->session->start(); From 6d3422dab2138ca36da71a312e24590aa6d1d4c3 Mon Sep 17 00:00:00 2001 From: hrach Date: Mon, 14 Jan 2013 22:13:59 +0100 Subject: [PATCH 08/47] Database: added tests for reseted resultset iterator --- tests/Nette/Database/Table.cache.rows.phpt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Nette/Database/Table.cache.rows.phpt b/tests/Nette/Database/Table.cache.rows.phpt index cf239da0de..aa78b0755e 100644 --- a/tests/Nette/Database/Table.cache.rows.phpt +++ b/tests/Nette/Database/Table.cache.rows.phpt @@ -41,3 +41,17 @@ Assert::equal(array( 'http://davidgrudl.com/', 'http://www.vrana.cz/', ), array_keys($webs)); + + + +$bookSelection = $connection->table('book')->order('id'); +$book = $bookSelection->fetch(); +$book->author_id; +$bookSelection->__destruct(); + +$bookSelection = $connection->table('book')->order('id'); +$books = array(); +$books[] = $bookSelection->fetch()->toArray(); +$books[] = $bookSelection->fetch()->toArray(); +Assert::equal(1, $books[0]['id']); +Assert::equal(2, $books[1]['id']); From 05cf4b77e9b2c9311dbfd23d00300a8a4ea57f82 Mon Sep 17 00:00:00 2001 From: hrach Date: Mon, 14 Jan 2013 22:14:20 +0100 Subject: [PATCH 09/47] Database: fixed reseted resultset iterator --- Nette/Database/Table/Selection.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Nette/Database/Table/Selection.php b/Nette/Database/Table/Selection.php index 16cc7f3326..eaeb273cde 100644 --- a/Nette/Database/Table/Selection.php +++ b/Nette/Database/Table/Selection.php @@ -592,6 +592,11 @@ public function accessColumn($key, $selectColumn = TRUE) $this->previousAccessedColumns = FALSE; $this->emptyResultSet(); $this->dataRefreshed = TRUE; + + if ($key === NULL) { + // we need to move iterator in resultset + $this->fetch(); + } } } From 04ee55894eec353587c604ea9e7124a5131592d7 Mon Sep 17 00:00:00 2001 From: hrach Date: Tue, 15 Jan 2013 09:57:59 +0100 Subject: [PATCH 10/47] Database: enhanced iterator reseting --- Nette/Database/Table/Selection.php | 6 +++++- tests/Nette/Database/Table.cache.rows.phpt | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Nette/Database/Table/Selection.php b/Nette/Database/Table/Selection.php index eaeb273cde..f4257d60c8 100644 --- a/Nette/Database/Table/Selection.php +++ b/Nette/Database/Table/Selection.php @@ -584,6 +584,7 @@ public function accessColumn($key, $selectColumn = TRUE) if ($key === NULL) { $this->accessedColumns = FALSE; + $currentKey = key($this->data); } elseif ($this->accessedColumns !== FALSE) { $this->accessedColumns[$key] = $selectColumn; } @@ -595,7 +596,10 @@ public function accessColumn($key, $selectColumn = TRUE) if ($key === NULL) { // we need to move iterator in resultset - $this->fetch(); + $this->execute(); + while (key($this->data) !== $currentKey) { + next($this->data); + } } } } diff --git a/tests/Nette/Database/Table.cache.rows.phpt b/tests/Nette/Database/Table.cache.rows.phpt index aa78b0755e..fa2a632557 100644 --- a/tests/Nette/Database/Table.cache.rows.phpt +++ b/tests/Nette/Database/Table.cache.rows.phpt @@ -51,7 +51,9 @@ $bookSelection->__destruct(); $bookSelection = $connection->table('book')->order('id'); $books = array(); +$books[] = $bookSelection->fetch(); $books[] = $bookSelection->fetch()->toArray(); $books[] = $bookSelection->fetch()->toArray(); Assert::equal(1, $books[0]['id']); Assert::equal(2, $books[1]['id']); +Assert::equal(3, $books[2]['id']); From 6552c3a85d0b5922376a03ed6e7b1f0bb045c96f Mon Sep 17 00:00:00 2001 From: Jachym Tousek Date: Thu, 17 Jan 2013 22:09:46 +0100 Subject: [PATCH 11/47] Database: updated and enhanced database test data --- tests/Nette/Database/Table.backjoin.phpt | 1 + tests/Nette/Database/Table.fetchPairs().phpt | 2 +- tests/Nette/Database/Table.insert().phpt | 20 ++++++++++---------- tests/Nette/Database/Table.related().phpt | 10 +++++----- tests/Nette/Database/mysql-nette_test1.sql | 1 + tests/Nette/Database/pgsql-nette_test1.sql | 3 ++- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/Nette/Database/Table.backjoin.phpt b/tests/Nette/Database/Table.backjoin.phpt index 2b71c56755..381374bcf3 100644 --- a/tests/Nette/Database/Table.backjoin.phpt +++ b/tests/Nette/Database/Table.backjoin.phpt @@ -23,4 +23,5 @@ foreach ($connection->table('author')->select('author.name, COUNT(DISTINCT book: Assert::same(array( 'Jakub Vrana' => 3, 'David Grudl' => 2, + 'Geek' => 0, ), $authorTagsCount); diff --git a/tests/Nette/Database/Table.fetchPairs().phpt b/tests/Nette/Database/Table.fetchPairs().phpt index 5701c42cd2..188928c95f 100644 --- a/tests/Nette/Database/Table.fetchPairs().phpt +++ b/tests/Nette/Database/Table.fetchPairs().phpt @@ -37,7 +37,7 @@ Assert::same(array( $connection->table('author')->get(11)->update(array('born' => new DateTime('2002-02-20'))); $connection->table('author')->get(12)->update(array('born' => new DateTime('2002-02-02'))); -$list = $connection->table('author')->order('born')->fetchPairs('born', 'name'); +$list = $connection->table('author')->where('born IS NOT NULL')->order('born')->fetchPairs('born', 'name'); Assert::same(array( '2002-02-02 00:00:00' => 'David Grudl', '2002-02-20 00:00:00' => 'Jakub Vrana', diff --git a/tests/Nette/Database/Table.insert().phpt b/tests/Nette/Database/Table.insert().phpt index 716a07d98a..7d2ab80ab9 100644 --- a/tests/Nette/Database/Table.insert().phpt +++ b/tests/Nette/Database/Table.insert().phpt @@ -16,14 +16,14 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/{$driverName}-nett $connection->table('author')->insert(array( - 'id' => 13, + 'id' => 14, 'name' => 'Eddard Stark', 'web' => 'http://example.com', -)); // INSERT INTO `author` (`id`, `name`, `web`) VALUES (13, 'Edard Stark', 'http://example.com') +)); // INSERT INTO `author` (`id`, `name`, `web`) VALUES (14, 'Edard Stark', 'http://example.com') switch ($driverName) { case 'pgsql': - $connection->exec("SELECT setval('author_id_seq'::regclass, 13, TRUE)"); + $connection->exec("SELECT setval('author_id_seq'::regclass, 14, TRUE)"); break; } @@ -38,9 +38,9 @@ $connection->table('author')->insert($insert); // INSERT INTO `author` (`name`, -$catelynStark = $connection->table('author')->get(14); // SELECT * FROM `author` WHERE (`id` = ?) +$catelynStark = $connection->table('author')->get(15); // SELECT * FROM `author` WHERE (`id` = ?) Assert::equal(array( - 'id' => 14, + 'id' => 15, 'name' => 'Catelyn Stark', 'web' => 'http://example.com', 'born' => new Nette\DateTime('2011-11-11'), @@ -58,20 +58,20 @@ $book2 = $book->insert(array( 'author_id' => 11, )); // INSERT INTO `book` (`title`, `author_id`) VALUES ('Winterfell', 11) -Assert::same('Jakub Vrana', $book2->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (11, 14)) +Assert::same('Jakub Vrana', $book2->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (11, 15)) $book3 = $book->insert(array( 'title' => 'Dragonstone', - 'author_id' => $connection->table('author')->get(13), // SELECT * FROM `author` WHERE (`id` = ?) -)); // INSERT INTO `book` (`title`, `author_id`) VALUES ('Dragonstone', 13) + 'author_id' => $connection->table('author')->get(14), // SELECT * FROM `author` WHERE (`id` = ?) +)); // INSERT INTO `book` (`title`, `author_id`) VALUES ('Dragonstone', 14) -Assert::same('Eddard Stark', $book3->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (11, 14)) +Assert::same('Eddard Stark', $book3->author->name); // SELECT * FROM `author` WHERE (`author`.`id` IN (11, 15)) Assert::exception(function() use ($connection) { $connection->table('author')->insert(array( - 'id' => 14, + 'id' => 15, 'name' => 'Jon Snow', 'web' => 'http://example.com', )); diff --git a/tests/Nette/Database/Table.related().phpt b/tests/Nette/Database/Table.related().phpt index 0fc5a839b9..a28ccf98b4 100644 --- a/tests/Nette/Database/Table.related().phpt +++ b/tests/Nette/Database/Table.related().phpt @@ -18,15 +18,15 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/{$driverName}-nett $books1 = $books2 = $books3 = array(); foreach ($connection->table('author') as $author) { // SELECT * FROM `author` - foreach ($author->related('book', 'translator_id') as $book) { // SELECT * FROM `book` WHERE (`book`.`translator_id` IN (11, 12)) + foreach ($author->related('book', 'translator_id') as $book) { // SELECT * FROM `book` WHERE (`book`.`translator_id` IN (11, 12, 13)) $books1[$book->title] = $author->name; } - foreach ($author->related('book.author_id') as $book) { // SELECT * FROM `book` WHERE (`book`.`author_id` IN (11, 12)) + foreach ($author->related('book.author_id') as $book) { // SELECT * FROM `book` WHERE (`book`.`author_id` IN (11, 12, 13)) $books2[$book->title] = $author->name; } - foreach ($author->related('book') as $book) { // SELECT * FROM `book` WHERE (`book`.`author_id` IN (11, 12)) + foreach ($author->related('book') as $book) { // SELECT * FROM `book` WHERE (`book`.`author_id` IN (11, 12, 13)) $books3[$book->title] = $author->name; } } @@ -81,8 +81,8 @@ foreach($connection->table('author')->order('id') as $author) { $counts2[] = $author->related('book.author_id')->where('translator_id', NULL)->count('id'); } -Assert::same(array(2, 2), $counts1); -Assert::same(array(1, 0), $counts2); +Assert::same(array(2, 2, 0), $counts1); +Assert::same(array(1, 0, 0), $counts2); diff --git a/tests/Nette/Database/mysql-nette_test1.sql b/tests/Nette/Database/mysql-nette_test1.sql index 82fc366c45..72b0105900 100644 --- a/tests/Nette/Database/mysql-nette_test1.sql +++ b/tests/Nette/Database/mysql-nette_test1.sql @@ -17,6 +17,7 @@ CREATE TABLE author ( INSERT INTO author (id, name, web, born) VALUES (11, 'Jakub Vrana', 'http://www.vrana.cz/', NULL); INSERT INTO author (id, name, web, born) VALUES (12, 'David Grudl', 'http://davidgrudl.com/', NULL); +INSERT INTO author (id, name, web, born) VALUES (13, 'Geek', 'http://example.com', NULL); DROP TABLE IF EXISTS tag; CREATE TABLE tag ( diff --git a/tests/Nette/Database/pgsql-nette_test1.sql b/tests/Nette/Database/pgsql-nette_test1.sql index dad7fcfe70..a352823ce8 100644 --- a/tests/Nette/Database/pgsql-nette_test1.sql +++ b/tests/Nette/Database/pgsql-nette_test1.sql @@ -12,7 +12,8 @@ CREATE TABLE author ( INSERT INTO author (id, name, web, born) VALUES (11, 'Jakub Vrana', 'http://www.vrana.cz/', NULL); INSERT INTO author (id, name, web, born) VALUES (12, 'David Grudl', 'http://davidgrudl.com/', NULL); -SELECT setval('author_id_seq', 12, TRUE); +INSERT INTO author (id, name, web, born) VALUES (13, 'Geek', 'http://example.com', NULL); +SELECT setval('author_id_seq', 13, TRUE); CREATE TABLE tag ( id serial NOT NULL, From 1d17f0e10839f83e46ce32b828afc11084201f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Fri, 11 Jan 2013 00:44:21 +0100 Subject: [PATCH 12/47] Database: added new database caching test --- tests/Nette/Database/Table.cache2.phpt | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/Nette/Database/Table.cache2.phpt diff --git a/tests/Nette/Database/Table.cache2.phpt b/tests/Nette/Database/Table.cache2.phpt new file mode 100644 index 0000000000..9d566c500b --- /dev/null +++ b/tests/Nette/Database/Table.cache2.phpt @@ -0,0 +1,39 @@ +setCacheStorage($cacheStorage); +$connection->setDatabaseReflection(new Nette\Database\Reflection\DiscoveredReflection($cacheStorage)); + + + +for ($i = 1; $i <= 2; ++$i) { + + foreach ($connection->table('author') as $author) { + $author->name; + foreach ($author->related('book', 'author_id') as $book) { + $book->title; + } + } + + foreach ($connection->table('author')->where('id', 13) as $author) { + $author->name; + foreach ($author->related('book', 'author_id') as $book) { + $book->title; + } + } + +} From 8868c2858fb0742a5d10817f66e9fe65d6ed553e Mon Sep 17 00:00:00 2001 From: hrach Date: Thu, 17 Jan 2013 22:17:50 +0100 Subject: [PATCH 13/47] Database: fixed reinvalidating data in execute() state of execution. --- Nette/Database/Table/Selection.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Nette/Database/Table/Selection.php b/Nette/Database/Table/Selection.php index f4257d60c8..71d71cc813 100644 --- a/Nette/Database/Table/Selection.php +++ b/Nette/Database/Table/Selection.php @@ -834,7 +834,7 @@ public function valid() public function offsetSet($key, $value) { $this->execute(); - $this->data[$key] = $value; + $this->rows[$key] = $value; } @@ -847,7 +847,7 @@ public function offsetSet($key, $value) public function offsetGet($key) { $this->execute(); - return $this->data[$key]; + return $this->rows[$key]; } @@ -860,7 +860,7 @@ public function offsetGet($key) public function offsetExists($key) { $this->execute(); - return isset($this->data[$key]); + return isset($this->rows[$key]); } @@ -873,7 +873,7 @@ public function offsetExists($key) public function offsetUnset($key) { $this->execute(); - unset($this->data[$key]); + unset($this->rows[$key], $this->data[$key]); } } From 96dd0c8ebc1e37502f167de8f18b3339d2fb1942 Mon Sep 17 00:00:00 2001 From: hrach Date: Thu, 17 Jan 2013 00:31:51 +0100 Subject: [PATCH 14/47] Database: added test for caching joining column in case of empty join resultset --- tests/Nette/Database/Table.cache.phpt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Nette/Database/Table.cache.phpt b/tests/Nette/Database/Table.cache.phpt index 8c993e2aad..2e38946999 100644 --- a/tests/Nette/Database/Table.cache.phpt +++ b/tests/Nette/Database/Table.cache.phpt @@ -144,3 +144,19 @@ foreach ($relatedStack as $related) { // checks if instances have shared data of accessed columns Assert::same(array('id', 'author_id'), array_keys((array) $property->getValue($related))); } + + + +$cacheStorage->clean(array(Nette\Caching\Cache::ALL => TRUE)); + + + +$author = $connection->table('author')->get(11); +$books = $author->related('book')->where('translator_id', 99); // 0 rows +foreach ($books as $book) {} +$books->__destruct(); +unset($author); + +$author = $connection->table('author')->get(11); +$books = $author->related('book')->where('translator_id', 11); +Assert::same(array('id', 'author_id'), $books->getPreviousAccessedColumns()); From 60e49bdaaa397844f1cc41f7341bf28912cc3043 Mon Sep 17 00:00:00 2001 From: hrach Date: Thu, 17 Jan 2013 00:32:16 +0100 Subject: [PATCH 15/47] Database: fixed caching joining column in case of empty join resultset --- Nette/Database/Table/GroupedSelection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Nette/Database/Table/GroupedSelection.php b/Nette/Database/Table/GroupedSelection.php index 4fd809d131..8cdaa841d2 100644 --- a/Nette/Database/Table/GroupedSelection.php +++ b/Nette/Database/Table/GroupedSelection.php @@ -165,6 +165,7 @@ protected function execute() $this->sqlBuilder->setLimit($limit, NULL); $refData = array(); $offset = array(); + $this->accessColumn($this->column); foreach ((array) $this->rows as $key => $row) { $ref = & $refData[$row[$this->column]]; $skip = & $offset[$row[$this->column]]; From a8507bc75c4ffa1d795ae724f7a1bec572b7b909 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 22 Jan 2013 04:46:27 +0100 Subject: [PATCH 16/47] DiscoveredReflection: removed reference from getHasManyReference() and getBelongsToReference() [Closes #921] --- .../Reflection/DiscoveredReflection.php | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/Nette/Database/Reflection/DiscoveredReflection.php b/Nette/Database/Reflection/DiscoveredReflection.php index e604e9c730..4da58efff5 100644 --- a/Nette/Database/Reflection/DiscoveredReflection.php +++ b/Nette/Database/Reflection/DiscoveredReflection.php @@ -98,10 +98,9 @@ public function getPrimary($table) public function getHasManyReference($table, $key, $refresh = TRUE) { - $reference = & $this->structure['hasMany'][strtolower($table)]; - if (!empty($reference)) { + if (isset($this->structure['hasMany'][strtolower($table)])) { $candidates = $columnCandidates = array(); - foreach ($reference as $targetPair) { + foreach ($this->structure['hasMany'][strtolower($table)] as $targetPair) { list($targetColumn, $targetTable) = $targetPair; if (stripos($targetTable, $key) === FALSE) continue; @@ -125,42 +124,38 @@ public function getHasManyReference($table, $key, $refresh = TRUE) if (strtolower($targetTable) === strtolower($key)) return $candidate; } + } - if (!$refresh && !empty($candidates)) { - throw new \PDOException('Ambiguous joining column in related call.'); - } + if ($refresh) { + $this->reloadAllForeignKeys(); + return $this->getHasManyReference($table, $key, FALSE); } - if (!$refresh) { + if (empty($candidates)) { throw new \PDOException("No reference found for \${$table}->related({$key})."); + } else { + throw new \PDOException('Ambiguous joining column in related call.'); } - - $this->reloadAllForeignKeys(); - return $this->getHasManyReference($table, $key, FALSE); } public function getBelongsToReference($table, $key, $refresh = TRUE) { - $reference = & $this->structure['belongsTo'][strtolower($table)]; - if (!empty($reference)) { - foreach ($reference as $column => $targetTable) { + if (isset($this->structure['belongsTo'][strtolower($table)])) { + foreach ($this->structure['belongsTo'][strtolower($table)] as $column => $targetTable) { if (stripos($column, $key) !== FALSE) { - return array( - $targetTable, - $column, - ); + return array($targetTable, $column); } } } - if (!$refresh) { - throw new \PDOException("No reference found for \${$table}->{$key}."); + if ($refresh) { + $this->reloadForeignKeys($table); + return $this->getBelongsToReference($table, $key, FALSE); } - $this->reloadForeignKeys($table); - return $this->getBelongsToReference($table, $key, FALSE); + throw new \PDOException("No reference found for \${$table}->{$key}."); } @@ -173,8 +168,8 @@ protected function reloadAllForeignKeys() } } - foreach (array_keys($this->structure['hasMany']) as $table) { - uksort($this->structure['hasMany'][$table], function($a, $b) { + foreach ($this->structure['hasMany'] as & $table) { + uksort($table, function($a, $b) { return strlen($a) - strlen($b); }); } From ed817debc6688b405f6300ebb486c803902a2b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20=C5=A0=C3=ADma?= Date: Tue, 22 Jan 2013 16:20:06 +0100 Subject: [PATCH 17/47] Database: throws exception from wrong namespace #681 --- Nette/Database/Drivers/MsSqlDriver.php | 8 ++++---- Nette/Database/Drivers/OciDriver.php | 6 +++--- Nette/Database/Drivers/OdbcDriver.php | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Nette/Database/Drivers/MsSqlDriver.php b/Nette/Database/Drivers/MsSqlDriver.php index fad898dde9..b0119e2bae 100644 --- a/Nette/Database/Drivers/MsSqlDriver.php +++ b/Nette/Database/Drivers/MsSqlDriver.php @@ -116,7 +116,7 @@ public function normalizeRow($row, $statement) */ public function getTables() { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } @@ -126,7 +126,7 @@ public function getTables() */ public function getColumns($table) { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } @@ -136,7 +136,7 @@ public function getColumns($table) */ public function getIndexes($table) { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } @@ -146,7 +146,7 @@ public function getIndexes($table) */ public function getForeignKeys($table) { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } diff --git a/Nette/Database/Drivers/OciDriver.php b/Nette/Database/Drivers/OciDriver.php index 81db6162e7..5fa1a8b586 100644 --- a/Nette/Database/Drivers/OciDriver.php +++ b/Nette/Database/Drivers/OciDriver.php @@ -139,7 +139,7 @@ public function getTables() */ public function getColumns($table) { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } @@ -149,7 +149,7 @@ public function getColumns($table) */ public function getIndexes($table) { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } @@ -159,7 +159,7 @@ public function getIndexes($table) */ public function getForeignKeys($table) { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } diff --git a/Nette/Database/Drivers/OdbcDriver.php b/Nette/Database/Drivers/OdbcDriver.php index 743c75998c..3a5f3a2a23 100644 --- a/Nette/Database/Drivers/OdbcDriver.php +++ b/Nette/Database/Drivers/OdbcDriver.php @@ -115,7 +115,7 @@ public function normalizeRow($row, $statement) */ public function getTables() { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } @@ -125,7 +125,7 @@ public function getTables() */ public function getColumns($table) { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } @@ -135,7 +135,7 @@ public function getColumns($table) */ public function getIndexes($table) { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } @@ -145,7 +145,7 @@ public function getIndexes($table) */ public function getForeignKeys($table) { - throw new NotImplementedException; + throw new Nette\NotImplementedException; } From c545a43a7900aa2c45b48ec7859ceb03f47d63d5 Mon Sep 17 00:00:00 2001 From: hrach Date: Wed, 6 Feb 2013 17:04:16 +0100 Subject: [PATCH 18/47] Database: Selection::find() will be renamed to wherePrimary() --- Nette/Database/Table/ActiveRow.php | 4 ++-- Nette/Database/Table/Selection.php | 17 ++++++++++++++--- tests/Nette/Database/Table.cache.phpt | 8 ++++---- tests/Nette/Database/Table.delete().phpt | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Nette/Database/Table/ActiveRow.php b/Nette/Database/Table/ActiveRow.php index 923ae19238..85f074fcda 100644 --- a/Nette/Database/Table/ActiveRow.php +++ b/Nette/Database/Table/ActiveRow.php @@ -183,7 +183,7 @@ public function update($data = NULL) } return $this->table->getConnection() ->table($this->table->getName()) - ->find($this->getPrimary()) + ->wherePrimary($this->getPrimary()) ->update($data); } @@ -197,7 +197,7 @@ public function delete() { $res = $this->table->getConnection() ->table($this->table->getName()) - ->find($this->getPrimary()) + ->wherePrimary($this->getPrimary()) ->delete(); if ($res > 0 && ($signature = $this->getSignature(FALSE))) { diff --git a/Nette/Database/Table/Selection.php b/Nette/Database/Table/Selection.php index 71d71cc813..9828bef468 100644 --- a/Nette/Database/Table/Selection.php +++ b/Nette/Database/Table/Selection.php @@ -230,7 +230,7 @@ public function getSqlBuilder() public function get($key) { $clone = clone $this; - return $clone->find($key)->fetch(); + return $clone->wherePrimary($key)->fetch(); } @@ -285,11 +285,22 @@ public function select($columns) /** - * Selects by primary key. - * @param mixed + * Method is deprecated, use wherePrimary() instead. * @return Selection provides a fluent interface */ public function find($key) + { + return $this->wherePrimary($key); + } + + + + /** + * Adds condition for primary key. + * @param mixed + * @return Selection provides a fluent interface + */ + public function wherePrimary($key) { if (is_array($this->primary) && Nette\Utils\Validators::isList($key)) { foreach ($this->primary as $i => $primary) { diff --git a/tests/Nette/Database/Table.cache.phpt b/tests/Nette/Database/Table.cache.phpt index 2e38946999..63613666c1 100644 --- a/tests/Nette/Database/Table.cache.phpt +++ b/tests/Nette/Database/Table.cache.phpt @@ -22,7 +22,7 @@ $connection->setDatabaseReflection(new Nette\Database\Reflection\DiscoveredRefle // Testing Selection caching -$bookSelection = $connection->table('book')->find(2); +$bookSelection = $connection->table('book')->wherePrimary(2); switch ($driverName) { case 'mysql': Assert::same('SELECT * FROM `book` WHERE (`id` = ?)', $bookSelection->getSql()); @@ -37,7 +37,7 @@ $book = $bookSelection->fetch(); $book->title; $book->translator; $bookSelection->__destruct(); -$bookSelection = $connection->table('book')->find(2); +$bookSelection = $connection->table('book')->wherePrimary(2); switch ($driverName) { case 'mysql': Assert::same('SELECT `id`, `title`, `translator_id` FROM `book` WHERE (`id` = ?)', $bookSelection->getSql()); @@ -60,7 +60,7 @@ switch ($driverName) { } $bookSelection->__destruct(); -$bookSelection = $connection->table('book')->find(2); +$bookSelection = $connection->table('book')->wherePrimary(2); switch ($driverName) { case 'mysql': Assert::same('SELECT `id`, `title`, `translator_id`, `author_id` FROM `book` WHERE (`id` = ?)', $bookSelection->getSql()); @@ -140,7 +140,7 @@ foreach ($connection->table('author') as $author) { foreach ($relatedStack as $related) { $property = $related->reflection->getProperty('accessedColumns'); - $property->setAccessible(true); + $property->setAccessible(TRUE); // checks if instances have shared data of accessed columns Assert::same(array('id', 'author_id'), array_keys((array) $property->getValue($related))); } diff --git a/tests/Nette/Database/Table.delete().phpt b/tests/Nette/Database/Table.delete().phpt index 1c67e330f8..3ef06bc2e4 100644 --- a/tests/Nette/Database/Table.delete().phpt +++ b/tests/Nette/Database/Table.delete().phpt @@ -31,4 +31,4 @@ Assert::same(3, $count); $book->delete(); // DELETE FROM `book` WHERE (`id` = ?) -Assert::same(0, count($connection->table('book')->find(3))); // SELECT * FROM `book` WHERE (`id` = ?) +Assert::same(0, count($connection->table('book')->wherePrimary(3))); // SELECT * FROM `book` WHERE (`id` = ?) From 48626a022470bbd15f66c4ab29e1c8aaef5d5880 Mon Sep 17 00:00:00 2001 From: hrach Date: Mon, 18 Feb 2013 16:39:43 +0100 Subject: [PATCH 19/47] Database: implemented reflection exceptions --- Nette/Database/IReflection.php | 3 ++ .../Reflection/DiscoveredReflection.php | 6 ++-- Nette/Database/Reflection/exceptions.php | 32 +++++++++++++++++++ Nette/Loaders/NetteLoader.php | 2 ++ 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 Nette/Database/Reflection/exceptions.php diff --git a/Nette/Database/IReflection.php b/Nette/Database/IReflection.php index 454a1cdec2..a71784f26a 100644 --- a/Nette/Database/IReflection.php +++ b/Nette/Database/IReflection.php @@ -45,6 +45,8 @@ function getPrimary($table); * @param string source table * @param string referencing key * @return array array(referenced table, referenced column) + * @throws Reflection\MissingReferenceException + * @throws Reflection\AmbiguousReferenceKeyException */ function getHasManyReference($table, $key); @@ -57,6 +59,7 @@ function getHasManyReference($table, $key); * @param string source table * @param string referencing key * @return array array(referenced table, referencing column) + * @throws Reflection\MissingReferenceException */ function getBelongsToReference($table, $key); diff --git a/Nette/Database/Reflection/DiscoveredReflection.php b/Nette/Database/Reflection/DiscoveredReflection.php index 4da58efff5..57a4019d9d 100644 --- a/Nette/Database/Reflection/DiscoveredReflection.php +++ b/Nette/Database/Reflection/DiscoveredReflection.php @@ -132,9 +132,9 @@ public function getHasManyReference($table, $key, $refresh = TRUE) } if (empty($candidates)) { - throw new \PDOException("No reference found for \${$table}->related({$key})."); + throw new MissingReferenceException("No reference found for \${$table}->related({$key})."); } else { - throw new \PDOException('Ambiguous joining column in related call.'); + throw new AmbiguousReferenceKeyException('Ambiguous joining column in related call.'); } } @@ -155,7 +155,7 @@ public function getBelongsToReference($table, $key, $refresh = TRUE) return $this->getBelongsToReference($table, $key, FALSE); } - throw new \PDOException("No reference found for \${$table}->{$key}."); + throw new MissingReferenceException("No reference found for \${$table}->{$key}."); } diff --git a/Nette/Database/Reflection/exceptions.php b/Nette/Database/Reflection/exceptions.php new file mode 100644 index 0000000000..834c282860 --- /dev/null +++ b/Nette/Database/Reflection/exceptions.php @@ -0,0 +1,32 @@ + '/common/ArrayHash', 'Nette\ArrayList' => '/common/ArrayList', 'Nette\Callback' => '/common/Callback', + 'Nette\Database\Reflection\AmbiguousReferenceKeyException' => '/Database/Reflection/exceptions', + 'Nette\Database\Reflection\MissingReferenceException' => '/Database/Reflection/exceptions', 'Nette\DI\MissingServiceException' => '/DI/exceptions', 'Nette\DI\ServiceCreationException' => '/DI/exceptions', 'Nette\DateTime' => '/common/DateTime', From 57b60bd8dab1520606637673f9da5ed7daea8ab5 Mon Sep 17 00:00:00 2001 From: hrach Date: Mon, 18 Feb 2013 17:10:36 +0100 Subject: [PATCH 20/47] Database: added tests for reflection exceptions --- tests/Nette/Database/Table.basic.phpt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Nette/Database/Table.basic.phpt b/tests/Nette/Database/Table.basic.phpt index 964af6a0fc..a55055c552 100644 --- a/tests/Nette/Database/Table.basic.phpt +++ b/tests/Nette/Database/Table.basic.phpt @@ -82,3 +82,20 @@ switch ($driverName) { Assert::same('SELECT * FROM "book" WHERE ("id" = 1)', $sql); break; } + + + +$connection->setDatabaseReflection(new Nette\Database\Reflection\DiscoveredReflection); + +$book = $connection->table('book')->get(1); +Assert::throws(function() use ($book) { + $book->test; +}, 'Nette\MemberAccessException', 'Cannot read an undeclared column "test".'); + +Assert::throws(function() use ($book) { + $book->ref('test'); +}, 'Nette\Database\Reflection\MissingReferenceException', 'No reference found for $book->test.'); + +Assert::throws(function() use ($book) { + $book->related('test'); +}, 'Nette\Database\Reflection\MissingReferenceException', 'No reference found for $book->related(test).'); From 8922e20feec44652d241ce02a2c1e42f04e8e0a6 Mon Sep 17 00:00:00 2001 From: hrach Date: Mon, 18 Feb 2013 20:54:23 +0100 Subject: [PATCH 21/47] Database: reflection can return only NULL [Closes #778] --- Nette/Database/Table/ActiveRow.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Nette/Database/Table/ActiveRow.php b/Nette/Database/Table/ActiveRow.php index 85f074fcda..501663da82 100644 --- a/Nette/Database/Table/ActiveRow.php +++ b/Nette/Database/Table/ActiveRow.php @@ -11,7 +11,8 @@ namespace Nette\Database\Table; -use Nette; +use Nette, + Nette\Database\Reflection\MissingReferenceException; @@ -289,12 +290,14 @@ public function &__get($key) return $this->data[$key]; } - list($table, $column) = $this->table->getConnection()->getDatabaseReflection()->getBelongsToReference($this->table->getName(), $key); - $referenced = $this->getReference($table, $column); - if ($referenced !== FALSE) { - $this->accessColumn($key, FALSE); - return $referenced; - } + try { + list($table, $column) = $this->table->getConnection()->getDatabaseReflection()->getBelongsToReference($this->table->getName(), $key); + $referenced = $this->getReference($table, $column); + if ($referenced !== FALSE) { + $this->accessColumn($key, FALSE); + return $referenced; + } + } catch(MissingReferenceException $e) {} $this->removeAccessColumn($key); throw new Nette\MemberAccessException("Cannot read an undeclared column \"$key\"."); From d3c72503eb46275a1e4f7d801e5341e9af5e5bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Sebastian=20Fab=C3=ADk?= Date: Thu, 28 Feb 2013 15:57:27 +0100 Subject: [PATCH 22/47] Database: fixed title of connection panel for single query --- Nette/Database/Diagnostics/ConnectionPanel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nette/Database/Diagnostics/ConnectionPanel.php b/Nette/Database/Diagnostics/ConnectionPanel.php index 4b9b64d137..85edc6c80f 100644 --- a/Nette/Database/Diagnostics/ConnectionPanel.php +++ b/Nette/Database/Diagnostics/ConnectionPanel.php @@ -87,7 +87,7 @@ public function getTab() { return '' . '' - . count($this->queries) . ' queries' + . count($this->queries) . ' ' . (count($this->queries) === 1 ? 'query' : 'queries') . ($this->totalTime ? ' / ' . sprintf('%0.1f', $this->totalTime * 1000) . 'ms' : '') . ''; } From 3410e81e889da7a762fc0dea68a49e53772ff4e9 Mon Sep 17 00:00:00 2001 From: Ondrej Klejch Date: Sun, 3 Feb 2013 20:29:05 +0100 Subject: [PATCH 23/47] Database: fixed Sqlite3 bug in getForeignKeys [Closes #935] --- Nette/Database/Drivers/SqliteDriver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Nette/Database/Drivers/SqliteDriver.php b/Nette/Database/Drivers/SqliteDriver.php index 53e4c1acee..e93fd6b71d 100644 --- a/Nette/Database/Drivers/SqliteDriver.php +++ b/Nette/Database/Drivers/SqliteDriver.php @@ -216,9 +216,9 @@ public function getForeignKeys($table) $keys = array(); foreach ($this->connection->query("PRAGMA foreign_key_list({$this->delimite($table)})") as $row) { $keys[$row['id']]['name'] = $row['id']; // foreign key name - $keys[$row['id']]['local'][$row['seq']] = $row['from']; // local columns + $keys[$row['id']]['local'] = $row['from']; // local columns $keys[$row['id']]['table'] = $row['table']; // referenced table - $keys[$row['id']]['foreign'][$row['seq']] = $row['to']; // referenced columns + $keys[$row['id']]['foreign'] = $row['to']; // referenced columns $keys[$row['id']]['onDelete'] = $row['on_delete']; $keys[$row['id']]['onUpdate'] = $row['on_update']; From 7f2e374ea166ed8d8612b52d5dafea32af6832f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Wed, 6 Feb 2013 19:48:16 +0100 Subject: [PATCH 24/47] typos --- Nette/Caching/Storages/FileJournal.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Nette/Caching/Storages/FileJournal.php b/Nette/Caching/Storages/FileJournal.php index 76699b95a6..21ada67df7 100644 --- a/Nette/Caching/Storages/FileJournal.php +++ b/Nette/Caching/Storages/FileJournal.php @@ -118,7 +118,7 @@ public function __construct($dir) if (!$init) { clearstatcache(); if (!file_exists($this->file)) { - throw new Nette\InvalidStateException("Cannot create journal file $this->file."); + throw new Nette\InvalidStateException("Cannot create journal file '$this->file'."); } } else { $writen = fwrite($init, pack('N2', self::FILE_MAGIC, $this->lastNode)); @@ -136,7 +136,7 @@ public function __construct($dir) } if (!flock($this->handle, LOCK_SH)) { - throw new Nette\InvalidStateException('Cannot acquire shared lock on journal.'); + throw new Nette\InvalidStateException("Cannot acquire shared lock on journal file '$this->file'."); } $header = stream_get_contents($this->handle, 2 * self::INT32_SIZE, 0); @@ -418,7 +418,7 @@ private function cleanLinks(array $data, array &$toDelete) if ($node === FALSE) { if (self::$debug) { - throw new Nette\InvalidStateException('Cannot load node number ' . ($nodeId) . '.'); + throw new Nette\InvalidStateException("Cannot load node number $nodeId."); } ++$i; continue; @@ -429,7 +429,7 @@ private function cleanLinks(array $data, array &$toDelete) if (!isset($node[$link])) { if (self::$debug) { - throw new Nette\InvalidStateException("Link with ID $searchLink is not in node ". ($nodeId) . '.'); + throw new Nette\InvalidStateException("Link with ID $searchLink is not in node $nodeId."); } continue; } elseif (isset($this->deletedLinks[$link])) { @@ -710,7 +710,7 @@ private function saveNode($id, array $node) $prevNode = $this->getNode($nodeInfo[self::PREV_NODE]); if ($prevNode === FALSE) { if (self::$debug) { - throw new Nette\InvalidStateException('Cannot load node number ' . $nodeInfo[self::PREV_NODE] . '.'); + throw new Nette\InvalidStateException("Cannot load node number {$nodeInfo[self::PREV_NODE]}."); } } else { $prevNode[self::INFO][self::MAX] = -1; @@ -1130,11 +1130,11 @@ private function deleteAll() private function lock() { if (!$this->handle) { - throw new Nette\InvalidStateException('File journal file is not opened'); + throw new Nette\InvalidStateException('File journal file is not opened.'); } if (!flock($this->handle, LOCK_EX)) { - throw new Nette\InvalidStateException('Cannot acquire exclusive lock on journal.'); + throw new Nette\InvalidStateException("Cannot acquire exclusive lock on journal file '$this->file'."); } if ($this->lastModTime !== NULL) { From 354ae729ec30e75edfbb44b2927d7a76b8d4aac3 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Wed, 6 Feb 2013 19:16:31 +0100 Subject: [PATCH 25/47] FileJournal: typos and PHP docs fixes --- Nette/Caching/Storages/FileJournal.php | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Nette/Caching/Storages/FileJournal.php b/Nette/Caching/Storages/FileJournal.php index 21ada67df7..8b1ba9b72c 100644 --- a/Nette/Caching/Storages/FileJournal.php +++ b/Nette/Caching/Storages/FileJournal.php @@ -80,7 +80,7 @@ class FileJournal extends Nette\Object implements IJournal /** @var int Last modification time of journal file */ private $lastModTime = NULL; - /** @var array Cache and uncommited but changed nodes */ + /** @var array Cache and uncommitted but changed nodes */ private $nodeCache = array(); /** @var array */ @@ -112,7 +112,7 @@ public function __construct($dir) { $this->file = $dir . '/' . self::FILE; - // Create jorunal file when not exists + // Create journal file when not exists if (!file_exists($this->file)) { $init = @fopen($this->file, 'xb'); // intentionally @ if (!$init) { @@ -121,9 +121,9 @@ public function __construct($dir) throw new Nette\InvalidStateException("Cannot create journal file '$this->file'."); } } else { - $writen = fwrite($init, pack('N2', self::FILE_MAGIC, $this->lastNode)); + $written = fwrite($init, pack('N2', self::FILE_MAGIC, $this->lastNode)); fclose($init); - if ($writen !== self::INT32_SIZE * 2) { + if ($written !== self::INT32_SIZE * 2) { throw new Nette\InvalidStateException("Cannot write journal header."); } } @@ -161,7 +161,7 @@ public function __destruct() { if ($this->handle) { $this->headerCommit(); - flock($this->handle, LOCK_UN); // Since PHP 5.3.3 is manual unlock necesary + flock($this->handle, LOCK_UN); // Since PHP 5.3.3 is manual unlock necessary fclose($this->handle); $this->handle = FALSE; } @@ -197,7 +197,7 @@ public function write($key, array $dependencies) $this->saveNode($link >> self::BITROT, $dataNode); } $exists = TRUE; - } else { // Alredy exists, but with other tags or priority + } else { // Already exists, but with other tags or priority $toDelete = array(); foreach ($dataNode[$link][self::TAGS] as $tag) { $toDelete[self::TAGS][$tag][$link] = TRUE; @@ -288,7 +288,7 @@ public function clean(array $conditions) $this->nodeCache = $this->nodeChanged = $this->dataNodeFreeSpace = array(); $this->deleteAll(); $this->unlock(); - return; + return NULL; } $toDelete = array( @@ -320,6 +320,8 @@ public function clean(array $conditions) /** * Cleans entries from journal by tags. + * @param array + * @param array * @return array of removed items */ private function cleanTags(array $tags, array &$toDelete) @@ -627,7 +629,7 @@ private function getNode($id) return FALSE; } - list(, $magic, $lenght) = unpack('N2', $binary); + list(, $magic, $length) = unpack('N2', $binary); if ($magic !== self::INDEX_MAGIC && $magic !== self::DATA_MAGIC) { if (!empty($magic)) { if (self::$debug) { @@ -638,13 +640,13 @@ private function getNode($id) return FALSE; } - $data = substr($binary, 2 * self::INT32_SIZE, $lenght - 2 * self::INT32_SIZE); + $data = substr($binary, 2 * self::INT32_SIZE, $length - 2 * self::INT32_SIZE); $node = @unserialize($data); // intentionally @ if ($node === FALSE) { $this->deleteNode($id); if (self::$debug) { - throw new Nette\InvalidStateException("Cannot deserialize node number $id."); + throw new Nette\InvalidStateException("Cannot unserialize node number $id."); } return FALSE; } @@ -761,7 +763,7 @@ private function commit() * Prepare node to journal file structure. * @param integer * @param array|bool - * @return bool Sucessfully commited + * @return bool Successfully committed */ private function prepareNode($id, $node) { @@ -1074,7 +1076,7 @@ private function bisectNode($id, array $node) private function headerCommit() { fseek($this->handle, self::INT32_SIZE); - @fwrite($this->handle, pack('N', $this->lastNode)); // intentionally @, save is not necceseary + @fwrite($this->handle, pack('N', $this->lastNode)); // intentionally @, save is not necessary } @@ -1101,8 +1103,8 @@ private function deleteNode($id) } } else { fseek($this->handle, self::HEADER_SIZE + self::NODE_SIZE * $id); - $writen = fwrite($this->handle, pack('N', 0)); - if ($writen !== self::INT32_SIZE) { + $written = fwrite($this->handle, pack('N', 0)); + if ($written !== self::INT32_SIZE) { throw new Nette\InvalidStateException("Cannot delete node number $id from journal."); } } From bb95733a9db1609c278b2b640fd3f5f5a9ffed7e Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Wed, 6 Feb 2013 21:09:30 +0100 Subject: [PATCH 26/47] FileJournal: fixed bug when priority is zero --- Nette/Caching/Storages/FileJournal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nette/Caching/Storages/FileJournal.php b/Nette/Caching/Storages/FileJournal.php index 8b1ba9b72c..22a93e01b9 100644 --- a/Nette/Caching/Storages/FileJournal.php +++ b/Nette/Caching/Storages/FileJournal.php @@ -262,7 +262,7 @@ public function write($key, array $dependencies) } // ...and priority tree. - if ($priority) { + if ($priority !== FALSE) { list($nodeId, $node) = $this->findIndexNode(self::PRIORITY, $priority); $node[$priority][$dataNodeKey] = 1; $this->saveNode($nodeId, $node); From 76b014d78734f839b19be65f31853d5edb044d14 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Wed, 6 Feb 2013 21:25:46 +0100 Subject: [PATCH 27/47] FileJournal: code style --- Nette/Caching/Storages/FileJournal.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Nette/Caching/Storages/FileJournal.php b/Nette/Caching/Storages/FileJournal.php index 22a93e01b9..0bff0af8d1 100644 --- a/Nette/Caching/Storages/FileJournal.php +++ b/Nette/Caching/Storages/FileJournal.php @@ -320,8 +320,8 @@ public function clean(array $conditions) /** * Cleans entries from journal by tags. - * @param array - * @param array + * @param array + * @param array * @return array of removed items */ private function cleanTags(array $tags, array &$toDelete) From 6b1157885dd7d02402dc0bd57b675e29ef76d320 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Wed, 6 Feb 2013 22:31:48 +0100 Subject: [PATCH 28/47] FileJournal: possible fixed bug Undefined offset, fixes #930 --- Nette/Caching/Storages/FileJournal.php | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Nette/Caching/Storages/FileJournal.php b/Nette/Caching/Storages/FileJournal.php index 0bff0af8d1..c62838a7c7 100644 --- a/Nette/Caching/Storages/FileJournal.php +++ b/Nette/Caching/Storages/FileJournal.php @@ -238,7 +238,7 @@ public function write($key, array $dependencies) ); } - $dataNodeKey = ++$data[self::INFO][self::LAST_INDEX]; + $dataNodeKey = $this->findNextFreeKey($freeDataNode, $data); $data[$dataNodeKey] = array( self::KEY => $key, self::TAGS => $tags ? $tags : array(), @@ -1165,6 +1165,32 @@ private function unlock() + /** + * @param int $nodeId + * @param array $nodeData + * @return int + * @throws \Nette\InvalidStateException + */ + private function findNextFreeKey($nodeId, array &$nodeData) + { + $newKey = $nodeData[self::INFO][self::LAST_INDEX] + 1; + $maxKey = ($nodeId + 1) << self::BITROT; + + if ($newKey >= $maxKey) { + $start = $nodeId << self::BITROT; + for ($i = $start; $i < $maxKey; $i++) { + if (!isset($nodeData[$i])) { + return $i; + } + } + throw new Nette\InvalidStateException("Node $nodeId is full."); + } else { + return ++$nodeData[self::INFO][self::LAST_INDEX]; + } + } + + + /** * Append $append to $array. * This function is much faster then $array = array_merge($array, $append) @@ -1194,5 +1220,4 @@ private function arrayAppendKeys(array &$array, array $append) $array[$key] = $value; } } - } From 621819dea41f1057ac5fd9f3d1d16fb204d0159e Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Wed, 6 Feb 2013 22:34:10 +0100 Subject: [PATCH 29/47] FileJournal: fixes #932 bug Undefined index --- Nette/Caching/Storages/FileJournal.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Nette/Caching/Storages/FileJournal.php b/Nette/Caching/Storages/FileJournal.php index c62838a7c7..6e063d3680 100644 --- a/Nette/Caching/Storages/FileJournal.php +++ b/Nette/Caching/Storages/FileJournal.php @@ -207,9 +207,12 @@ public function write($key, array $dependencies) } $toDelete[self::ENTRIES][$keyHash][$link] = TRUE; $this->cleanFromIndex($toDelete); - $entriesNode = $this->getNode($entriesNodeId); // Node was changed, get again + unset($dataNode[$link]); $this->saveNode($link >> self::BITROT, $dataNode); + + // Node was changed but may be empty, find it again + list($entriesNodeId, $entriesNode) = $this->findIndexNode(self::ENTRIES, $keyHash); } break; } From aba042b5244de25a5ae33e3d4e76e1bc7f866d5e Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Wed, 13 Feb 2013 11:38:58 +0100 Subject: [PATCH 30/47] FileJournal: fixes #930 bug when multiple process works with file journal in same second --- Nette/Caching/Storages/FileJournal.php | 118 ++++++++++++++----------- 1 file changed, 64 insertions(+), 54 deletions(-) diff --git a/Nette/Caching/Storages/FileJournal.php b/Nette/Caching/Storages/FileJournal.php index 6e063d3680..2ce7bb27cc 100644 --- a/Nette/Caching/Storages/FileJournal.php +++ b/Nette/Caching/Storages/FileJournal.php @@ -77,8 +77,8 @@ class FileJournal extends Nette\Object implements IJournal /** @var int Last complete free node */ private $lastNode = 2; - /** @var int Last modification time of journal file */ - private $lastModTime = NULL; + /** @var string */ + private $processIdentifier; /** @var array Cache and uncommitted but changed nodes */ private $nodeCache = array(); @@ -104,52 +104,12 @@ class FileJournal extends Nette\Object implements IJournal ); - /** - * @param string Directory location with journal file + * @param string Directory containing journal file */ public function __construct($dir) { $this->file = $dir . '/' . self::FILE; - - // Create journal file when not exists - if (!file_exists($this->file)) { - $init = @fopen($this->file, 'xb'); // intentionally @ - if (!$init) { - clearstatcache(); - if (!file_exists($this->file)) { - throw new Nette\InvalidStateException("Cannot create journal file '$this->file'."); - } - } else { - $written = fwrite($init, pack('N2', self::FILE_MAGIC, $this->lastNode)); - fclose($init); - if ($written !== self::INT32_SIZE * 2) { - throw new Nette\InvalidStateException("Cannot write journal header."); - } - } - } - - $this->handle = fopen($this->file, 'r+b'); - - if (!$this->handle) { - throw new Nette\InvalidStateException("Cannot open journal file '$this->file'."); - } - - if (!flock($this->handle, LOCK_SH)) { - throw new Nette\InvalidStateException("Cannot acquire shared lock on journal file '$this->file'."); - } - - $header = stream_get_contents($this->handle, 2 * self::INT32_SIZE, 0); - - flock($this->handle, LOCK_UN); - - list(, $fileMagic, $this->lastNode) = unpack('N2', $header); - - if ($fileMagic !== self::FILE_MAGIC) { - fclose($this->handle); - $this->handle = FALSE; - throw new Nette\InvalidStateException("Malformed journal file '$this->file'."); - } } @@ -816,8 +776,8 @@ private function prepareNode($id, $node) private function commitNode($id, $str) { fseek($this->handle, self::HEADER_SIZE + self::NODE_SIZE * $id); - $writen = fwrite($this->handle, $str); - if ($writen === FALSE) { + $written = fwrite($this->handle, $str); + if ($written === FALSE) { throw new Nette\InvalidStateException("Cannot write node number $id to journal."); } } @@ -1117,7 +1077,7 @@ private function deleteNode($id) /** * Complete delete all nodes from file. - * @return void + * @throws \Nette\InvalidStateException */ private function deleteAll() { @@ -1130,24 +1090,76 @@ private function deleteAll() /** * Lock file for writing and reading and delete node cache when file has changed. - * @return void + * @throws \Nette\InvalidStateException */ private function lock() { if (!$this->handle) { - throw new Nette\InvalidStateException('File journal file is not opened.'); + $this->prepare(); } if (!flock($this->handle, LOCK_EX)) { throw new Nette\InvalidStateException("Cannot acquire exclusive lock on journal file '$this->file'."); } - if ($this->lastModTime !== NULL) { - clearstatcache(); - if ($this->lastModTime < @filemtime($this->file)) { // intentionally @ - $this->nodeCache = $this->dataNodeFreeSpace = array(); + $lastProcessIdentifier = stream_get_contents($this->handle, self::INT32_SIZE, self::INT32_SIZE * 2); + if ($lastProcessIdentifier !== $this->processIdentifier) { + $this->nodeCache = $this->dataNodeFreeSpace = array(); + + // Write current processIdentifier to file header + fseek($this->handle, self::INT32_SIZE * 2); + fwrite($this->handle, $this->processIdentifier); + } + } + + + + /** + * Open btfj.dat file (or create it if not exists) and load metainformation + * @throws \Nette\InvalidStateException + */ + private function prepare() + { + // Create journal file when not exists + if (!file_exists($this->file)) { + $init = @fopen($this->file, 'xb'); // intentionally @ + if (!$init) { + clearstatcache(); + if (!file_exists($this->file)) { + throw new Nette\InvalidStateException("Cannot create journal file '$this->file'."); + } + } else { + $written = fwrite($init, pack('N2', self::FILE_MAGIC, $this->lastNode)); + fclose($init); + if ($written !== self::INT32_SIZE * 2) { + throw new Nette\InvalidStateException("Cannot write journal header."); + } } } + + $this->handle = fopen($this->file, 'r+b'); + + if (!$this->handle) { + throw new Nette\InvalidStateException("Cannot open journal file '$this->file'."); + } + + if (!flock($this->handle, LOCK_SH)) { + throw new Nette\InvalidStateException('Cannot acquire shared lock on journal.'); + } + + $header = stream_get_contents($this->handle, 2 * self::INT32_SIZE, 0); + + flock($this->handle, LOCK_UN); + + list(, $fileMagic, $this->lastNode) = unpack('N2', $header); + + if ($fileMagic !== self::FILE_MAGIC) { + fclose($this->handle); + $this->handle = FALSE; + throw new Nette\InvalidStateException("Malformed journal file '$this->file'."); + } + + $this->processIdentifier = pack('N', mt_rand()); } @@ -1161,8 +1173,6 @@ private function unlock() if ($this->handle) { fflush($this->handle); flock($this->handle, LOCK_UN); - clearstatcache(); - $this->lastModTime = @filemtime($this->file); // intentionally @ } } From d12a892110378273c75e047af4df46898967397a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 19 Feb 2013 20:28:21 +0100 Subject: [PATCH 31/47] Latte: recognizes {Namespace\Class::member} --- Nette/Latte/Parser.php | 2 +- tests/Nette/Latte/Parser.parseMacroTag.phpt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Nette/Latte/Parser.php b/Nette/Latte/Parser.php index 5c3cbabb96..f8be476023 100644 --- a/Nette/Latte/Parser.php +++ b/Nette/Latte/Parser.php @@ -339,7 +339,7 @@ public function parseMacroTag($tag) { $match = Strings::match($tag, '~^ ( - (?P\?|/?[a-z]\w*+(?:[.:]\w+)*+(?!::|\())| ## ?, name, /name, but not function( or class:: + (?P\?|/?[a-z]\w*+(?:[.:]\w+)*+(?!::|\(|\\\\))| ## ?, name, /name, but not function( or class:: or namespace\ (?P!?)(?P/?[=\~#%^&_]?) ## !expression, !=expression, ... )(?P.*?) (?P\|[a-z](?:'.Parser::RE_STRING.'|[^\'"])*)? diff --git a/tests/Nette/Latte/Parser.parseMacroTag.phpt b/tests/Nette/Latte/Parser.parseMacroTag.phpt index 3893af2568..1f7261b93e 100644 --- a/tests/Nette/Latte/Parser.parseMacroTag.phpt +++ b/tests/Nette/Latte/Parser.parseMacroTag.phpt @@ -37,6 +37,7 @@ Assert::same( array('=', 'md5()', '|escape'), $parser->parseMacroTag('md5()') ); Assert::same( array('foo:bar', '', ''), $parser->parseMacroTag('foo:bar') ); Assert::same( array('=', ':bar', '|escape'), $parser->parseMacroTag(':bar') ); Assert::same( array('=', 'class::member', '|escape'), $parser->parseMacroTag('class::member') ); +Assert::same( array('=', 'Namespace\Class::member()', '|escape'), $parser->parseMacroTag('Namespace\Class::member()') ); Assert::same( array('Link', '$var', ''), $parser->parseMacroTag('Link $var') ); Assert::same( array('link', '$var', ''), $parser->parseMacroTag('link $var') ); Assert::same( array('link', '$var', ''), $parser->parseMacroTag('link$var') ); From b31d59a42923f292f451a162472f0b11e625585a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Wed, 22 Feb 2012 21:47:17 +0100 Subject: [PATCH 32/47] Config: support for constants in arguments [Closes #550] --- Nette/DI/ContainerBuilder.php | 3 ++ .../Nette/Config/Configurator.constants.phpt | 44 +++++++++++++++++++ .../Nette/Config/files/config.constants.neon | 12 +++++ 3 files changed, 59 insertions(+) create mode 100644 tests/Nette/Config/Configurator.constants.phpt create mode 100644 tests/Nette/Config/files/config.constants.neon diff --git a/Nette/DI/ContainerBuilder.php b/Nette/DI/ContainerBuilder.php index 061ba31059..035722efed 100644 --- a/Nette/DI/ContainerBuilder.php +++ b/Nette/DI/ContainerBuilder.php @@ -525,6 +525,9 @@ public function formatPhp($statement, $args, $self = NULL) } elseif ($service = $that->getServiceName($val, $self)) { $val = $service === $self ? '$service' : $that->formatStatement(new Statement($val)); $val = new PhpLiteral($val); + + } elseif (is_string($val) && preg_match('#^[\w\\\\]*::[A-Z][A-Z0-9_]*\z#', $val, $m)) { + $val = new PhpLiteral(ltrim($val, ':')); } }); return PhpHelpers::formatArgs($statement, $args); diff --git a/tests/Nette/Config/Configurator.constants.phpt b/tests/Nette/Config/Configurator.constants.phpt new file mode 100644 index 0000000000..58e5764e42 --- /dev/null +++ b/tests/Nette/Config/Configurator.constants.phpt @@ -0,0 +1,44 @@ +arg = $arg; + } +} + +define('MY_CONSTANT_TEST', "one"); + +$configurator = new Configurator; +$configurator->setTempDirectory(TEMP_DIR); +$container = $configurator->addConfig(__DIR__ . '/files/config.constants.neon', Configurator::NONE) + ->createContainer(); + +Assert::same( "one", $container->ipsum->arg ); +Assert::same( Lorem::DOLOR_SIT, $container->sit->arg ); +Assert::same( "MY_FAILING_CONSTANT_TEST", $container->consectetur->arg ); + +Assert::error(function () use ($container) { + $container->amet->arg; +}, E_NOTICE, "Use of undefined constant MY_FAILING_CONSTANT_TEST - assumed 'MY_FAILING_CONSTANT_TEST'"); diff --git a/tests/Nette/Config/files/config.constants.neon b/tests/Nette/Config/files/config.constants.neon new file mode 100644 index 0000000000..f9527c4430 --- /dev/null +++ b/tests/Nette/Config/files/config.constants.neon @@ -0,0 +1,12 @@ +services: + ipsum: + class: Lorem(::MY_CONSTANT_TEST) + + sit: + class: Lorem(Lorem::DOLOR_SIT) + + amet: + class: Lorem(::MY_FAILING_CONSTANT_TEST) + + consectetur: + class: Lorem(MY_FAILING_CONSTANT_TEST) From c4744cc46c97dcf8a5a81454b82bce1ebeda2bad Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 19 Feb 2013 16:44:57 +0100 Subject: [PATCH 33/47] FileUpload::move() - added unlink() as prevention for permission denied error in move_uploaded_file() --- Nette/Http/FileUpload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nette/Http/FileUpload.php b/Nette/Http/FileUpload.php index 480511fe20..94f9712865 100644 --- a/Nette/Http/FileUpload.php +++ b/Nette/Http/FileUpload.php @@ -165,7 +165,7 @@ public function isOk() public function move($dest) { @mkdir(dirname($dest), 0777, TRUE); // @ - dir may already exist - /*5.2*if (substr(PHP_OS, 0, 3) === 'WIN') { @unlink($dest); }*/ + @unlink($dest); // @ - file may not exists if (!call_user_func(is_uploaded_file($this->tmpName) ? 'move_uploaded_file' : 'rename', $this->tmpName, $dest)) { throw new Nette\InvalidStateException("Unable to move uploaded file '$this->tmpName' to '$dest'."); } From 9614041498c2072481774ae9ef8e3f86b6197968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20H=C5=AFla?= Date: Thu, 7 Feb 2013 11:54:22 +0100 Subject: [PATCH 34/47] Tests: fixed CacheStorage's sliding tests [Closing #958] These tests failed on Travis-ci.org accidentally. It's because sliding interval was so tight. I verified, that sliding functionality is working well in both cases (MemcachedStorage, FileStorage). The expiration of data is properly prolonged on every reading. But there is a potential weak place. Cache::completeDependencies() converts expiration time to relative amount of seconds. When user sets expiration at time() + 2, until Cache::completeDependencies() runs, time() value increase. So, expiration time is decreased by 1 second in consequence. I guess, this is a reason why tests failed on Travis (virtual server, time jitter, I/O rush). I hope, this feature needn't be fixed, Cache is not permanent data storage. And nobody complain. --- tests/Nette/Caching/FileStorage.sliding.phpt | 7 ++++--- tests/Nette/Caching/Memcached.sliding.phpt | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/Nette/Caching/FileStorage.sliding.phpt b/tests/Nette/Caching/FileStorage.sliding.phpt index 63ec936dff..2fbff8e6b2 100644 --- a/tests/Nette/Caching/FileStorage.sliding.phpt +++ b/tests/Nette/Caching/FileStorage.sliding.phpt @@ -24,21 +24,22 @@ $cache = new Cache(new FileStorage(TEMP_DIR)); // Writing cache... $cache->save($key, $value, array( - Cache::EXPIRATION => time() + 2, + Cache::EXPIRATION => time() + 3, Cache::SLIDING => TRUE, )); -for($i = 0; $i < 3; $i++) { +for ($i = 0; $i < 5; $i++) { // Sleeping 1 second sleep(1); clearstatcache(); + Assert::true( isset($cache[$key]), 'Is cached?' ); } // Sleeping few seconds... -sleep(3); +sleep(5); clearstatcache(); Assert::false( isset($cache[$key]), 'Is cached?' ); diff --git a/tests/Nette/Caching/Memcached.sliding.phpt b/tests/Nette/Caching/Memcached.sliding.phpt index 540fa8a69c..08cd134f5b 100644 --- a/tests/Nette/Caching/Memcached.sliding.phpt +++ b/tests/Nette/Caching/Memcached.sliding.phpt @@ -30,19 +30,20 @@ $cache = new Cache(new MemcachedStorage('localhost')); // Writing cache... $cache->save($key, $value, array( - Cache::EXPIRATION => time() + 2, + Cache::EXPIRATION => time() + 3, Cache::SLIDING => TRUE, )); -for($i = 0; $i < 3; $i++) { +for ($i = 0; $i < 5; $i++) { // Sleeping 1 second sleep(1); + Assert::true( isset($cache[$key]), 'Is cached?' ); } // Sleeping few seconds... -sleep(3); +sleep(5); Assert::false( isset($cache[$key]), 'Is cached?' ); From b30ec987d15ee422dc4c2dafc4d7c0d8295bea5f Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 21 Jan 2013 18:11:46 +0100 Subject: [PATCH 35/47] typos --- Nette/Database/Drivers/MsSqlDriver.php | 1 - Nette/Database/Drivers/OdbcDriver.php | 1 - Nette/Database/Drivers/PgSqlDriver.php | 7 ++++--- Nette/Database/Helpers.php | 9 +++++---- Nette/Database/Reflection/DiscoveredReflection.php | 9 ++++++--- Nette/Database/Table/Selection.php | 3 ++- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Nette/Database/Drivers/MsSqlDriver.php b/Nette/Database/Drivers/MsSqlDriver.php index b0119e2bae..88584c9815 100644 --- a/Nette/Database/Drivers/MsSqlDriver.php +++ b/Nette/Database/Drivers/MsSqlDriver.php @@ -85,7 +85,6 @@ public function formatLike($value, $pos) */ public function applyLimit(&$sql, $limit, $offset) { - // offset support is missing if ($limit >= 0) { $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t'; } diff --git a/Nette/Database/Drivers/OdbcDriver.php b/Nette/Database/Drivers/OdbcDriver.php index 3a5f3a2a23..b3299b06af 100644 --- a/Nette/Database/Drivers/OdbcDriver.php +++ b/Nette/Database/Drivers/OdbcDriver.php @@ -84,7 +84,6 @@ public function formatLike($value, $pos) */ public function applyLimit(&$sql, $limit, $offset) { - // offset support is missing if ($limit >= 0) { $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')'; } diff --git a/Nette/Database/Drivers/PgSqlDriver.php b/Nette/Database/Drivers/PgSqlDriver.php index ce6c6dc998..41726d818c 100644 --- a/Nette/Database/Drivers/PgSqlDriver.php +++ b/Nette/Database/Drivers/PgSqlDriver.php @@ -85,11 +85,12 @@ public function formatLike($value, $pos) */ public function applyLimit(&$sql, $limit, $offset) { - if ($limit >= 0) + if ($limit >= 0) { $sql .= ' LIMIT ' . (int) $limit; - - if ($offset > 0) + } + if ($offset > 0) { $sql .= ' OFFSET ' . (int) $offset; + } } diff --git a/Nette/Database/Helpers.php b/Nette/Database/Helpers.php index 90a7e86358..e2eac3a862 100644 --- a/Nette/Database/Helpers.php +++ b/Nette/Database/Helpers.php @@ -98,17 +98,18 @@ public static function dumpSql($sql) // syntax highlight $sql = htmlSpecialChars($sql); $sql = preg_replace_callback("#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is", function($matches) { - if (!empty($matches[1])) // comment + if (!empty($matches[1])) { // comment return '' . $matches[1] . ''; - if (!empty($matches[2])) // error + } elseif (!empty($matches[2])) { // error return '' . $matches[2] . ''; - if (!empty($matches[3])) // most important keywords + } elseif (!empty($matches[3])) { // most important keywords return '' . $matches[3] . ''; - if (!empty($matches[4])) // other keywords + } elseif (!empty($matches[4])) { // other keywords return '' . $matches[4] . ''; + } }, $sql); return '
' . trim($sql) . "
\n"; diff --git a/Nette/Database/Reflection/DiscoveredReflection.php b/Nette/Database/Reflection/DiscoveredReflection.php index 57a4019d9d..1aeaa15031 100644 --- a/Nette/Database/Reflection/DiscoveredReflection.php +++ b/Nette/Database/Reflection/DiscoveredReflection.php @@ -102,14 +102,16 @@ public function getHasManyReference($table, $key, $refresh = TRUE) $candidates = $columnCandidates = array(); foreach ($this->structure['hasMany'][strtolower($table)] as $targetPair) { list($targetColumn, $targetTable) = $targetPair; - if (stripos($targetTable, $key) === FALSE) + if (stripos($targetTable, $key) === FALSE) { continue; + } $candidates[] = array($targetTable, $targetColumn); if (stripos($targetColumn, $table) !== FALSE) { $columnCandidates[] = $candidate = array($targetTable, $targetColumn); - if (strtolower($targetTable) === strtolower($key)) + if (strtolower($targetTable) === strtolower($key)) { return $candidate; + } } } @@ -121,8 +123,9 @@ public function getHasManyReference($table, $key, $refresh = TRUE) foreach ($candidates as $candidate) { list($targetTable, $targetColumn) = $candidate; - if (strtolower($targetTable) === strtolower($key)) + if (strtolower($targetTable) === strtolower($key)) { return $candidate; + } } } diff --git a/Nette/Database/Table/Selection.php b/Nette/Database/Table/Selection.php index 9828bef468..02b3edbcf3 100644 --- a/Nette/Database/Table/Selection.php +++ b/Nette/Database/Table/Selection.php @@ -737,8 +737,9 @@ public function getReferencedTable($table, $column, $checkReferenced = FALSE) $this->checkReferenced = FALSE; $keys = array(); foreach ($this->rows as $row) { - if ($row[$column] === NULL) + if ($row[$column] === NULL) { continue; + } $key = $row[$column] instanceof ActiveRow ? $row[$column]->getPrimary() : $row[$column]; $keys[$key] = TRUE; From ce9daf0d155d81456e626f7f1bdd3f09eef7b3e6 Mon Sep 17 00:00:00 2001 From: greenyaptec Date: Tue, 29 Jan 2013 09:08:30 +0100 Subject: [PATCH 36/47] Fixed comment Someone may be confused --- Nette/Utils/Html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nette/Utils/Html.php b/Nette/Utils/Html.php index c151741cc7..80ca62326a 100644 --- a/Nette/Utils/Html.php +++ b/Nette/Utils/Html.php @@ -19,7 +19,7 @@ * HTML helper. * * - * $anchor = Html::el('a')->href($link)->setText('Nette'); + * $el = Html::el('a')->href($link)->setText('Nette'); * $el->class = 'myclass'; * echo $el; * From 42bb7fd54c4c0b73a3043e927910079d1e3e69e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Thu, 7 Feb 2013 19:17:43 +0100 Subject: [PATCH 37/47] typo --- Nette/Application/UI/Presenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nette/Application/UI/Presenter.php b/Nette/Application/UI/Presenter.php index d504ccf1d7..6c0c891bc1 100644 --- a/Nette/Application/UI/Presenter.php +++ b/Nette/Application/UI/Presenter.php @@ -221,7 +221,7 @@ public function run(Application\Request $request) } catch (Application\AbortException $e) { } if ($this->hasFlashSession()) { - $this->getFlashSession()->setExpiration($this->response instanceof Responses\RedirectResponse ? '+ 30 seconds': '+ 3 seconds'); + $this->getFlashSession()->setExpiration($this->response instanceof Responses\RedirectResponse ? '+ 30 seconds' : '+ 3 seconds'); } // SHUTDOWN From 72ce114b525062673cc95580c9a9a5227347654b Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 19 Feb 2013 17:23:52 +0100 Subject: [PATCH 38/47] typos, renamed some variables --- Nette/Caching/Cache.php | 16 ++++++++-------- Nette/Caching/IStorage.php | 2 +- Nette/Caching/OutputHelper.php | 4 ++-- Nette/Caching/Storages/DevNullStorage.php | 4 ++-- Nette/Caching/Storages/FileStorage.php | 10 +++++----- Nette/Caching/Storages/MemcachedStorage.php | 6 +++--- Nette/Caching/Storages/MemoryStorage.php | 6 +++--- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Nette/Caching/Cache.php b/Nette/Caching/Cache.php index e04d24f956..604f949c63 100644 --- a/Nette/Caching/Cache.php +++ b/Nette/Caching/Cache.php @@ -131,20 +131,20 @@ public function load($key, $fallback = NULL) * @return mixed value itself * @throws Nette\InvalidArgumentException */ - public function save($key, $data, array $dp = NULL) + public function save($key, $data, array $dependencies = NULL) { $this->release(); $key = $this->generateKey($key); if ($data instanceof Nette\Callback || $data instanceof \Closure) { $this->storage->lock($key); - $data = Nette\Callback::create($data)->invokeArgs(array(&$dp)); + $data = Nette\Callback::create($data)->invokeArgs(array(&$dependencies)); } if ($data === NULL) { $this->storage->remove($key); } else { - $this->storage->write($key, $data, $this->completeDependencies($dp, $data)); + $this->storage->write($key, $data, $this->completeDependencies($dependencies, $data)); return $data; } } @@ -215,10 +215,10 @@ public function remove($key) * @param array * @return void */ - public function clean(array $conds = NULL) + public function clean(array $conditions = NULL) { $this->release(); - $this->storage->clean((array) $conds); + $this->storage->clean((array) $conditions); } @@ -245,14 +245,14 @@ public function call($function) * @param array dependencies * @return Closure */ - public function wrap($function, array $dp = NULL) + public function wrap($function, array $dependencies = NULL) { $cache = $this; - return function() use ($cache, $function, $dp) { + return function() use ($cache, $function, $dependencies) { $key = array($function, func_get_args()); $data = $cache->load($key); if ($data === NULL) { - $data = $cache->save($key, Nette\Callback::create($function)->invokeArgs($key[1]), $dp); + $data = $cache->save($key, Nette\Callback::create($function)->invokeArgs($key[1]), $dependencies); } return $data; }; diff --git a/Nette/Caching/IStorage.php b/Nette/Caching/IStorage.php index cf67751af3..f03d4e9206 100644 --- a/Nette/Caching/IStorage.php +++ b/Nette/Caching/IStorage.php @@ -58,6 +58,6 @@ function remove($key); * @param array conditions * @return void */ - function clean(array $conds); + function clean(array $conditions); } diff --git a/Nette/Caching/OutputHelper.php b/Nette/Caching/OutputHelper.php index 34658ccf9e..7d710a9b1a 100644 --- a/Nette/Caching/OutputHelper.php +++ b/Nette/Caching/OutputHelper.php @@ -47,12 +47,12 @@ public function __construct(Cache $cache, $key) * @param array dependencies * @return void */ - public function end(array $dp = NULL) + public function end(array $dependencies = NULL) { if ($this->cache === NULL) { throw new Nette\InvalidStateException('Output cache has already been saved.'); } - $this->cache->save($this->key, ob_get_flush(), (array) $dp + (array) $this->dependencies); + $this->cache->save($this->key, ob_get_flush(), (array) $dependencies + (array) $this->dependencies); $this->cache = NULL; } diff --git a/Nette/Caching/Storages/DevNullStorage.php b/Nette/Caching/Storages/DevNullStorage.php index 1d6dfd1a80..e93f1333d1 100644 --- a/Nette/Caching/Storages/DevNullStorage.php +++ b/Nette/Caching/Storages/DevNullStorage.php @@ -52,7 +52,7 @@ public function lock($key) * @param array dependencies * @return void */ - public function write($key, $data, array $dp) + public function write($key, $data, array $dependencies) { } @@ -74,7 +74,7 @@ public function remove($key) * @param array conditions * @return void */ - public function clean(array $conds) + public function clean(array $conditions) { } diff --git a/Nette/Caching/Storages/FileStorage.php b/Nette/Caching/Storages/FileStorage.php index 915c6a0cdf..d3eb0dfa90 100644 --- a/Nette/Caching/Storages/FileStorage.php +++ b/Nette/Caching/Storages/FileStorage.php @@ -276,10 +276,10 @@ public function remove($key) * @param array conditions * @return void */ - public function clean(array $conds) + public function clean(array $conditions) { - $all = !empty($conds[Cache::ALL]); - $collector = empty($conds); + $all = !empty($conditions[Cache::ALL]); + $collector = empty($conditions); // cleaning using file iterator if ($all || $collector) { @@ -312,14 +312,14 @@ public function clean(array $conds) } if ($this->journal) { - $this->journal->clean($conds); + $this->journal->clean($conditions); } return; } // cleaning using journal if ($this->journal) { - foreach ($this->journal->clean($conds) as $file) { + foreach ($this->journal->clean($conditions) as $file) { $this->delete($file); } } diff --git a/Nette/Caching/Storages/MemcachedStorage.php b/Nette/Caching/Storages/MemcachedStorage.php index 5a7254983c..d57c776cbc 100644 --- a/Nette/Caching/Storages/MemcachedStorage.php +++ b/Nette/Caching/Storages/MemcachedStorage.php @@ -191,13 +191,13 @@ public function remove($key) * @param array conditions * @return void */ - public function clean(array $conds) + public function clean(array $conditions) { - if (!empty($conds[Cache::ALL])) { + if (!empty($conditions[Cache::ALL])) { $this->memcache->flush(); } elseif ($this->journal) { - foreach ($this->journal->clean($conds) as $entry) { + foreach ($this->journal->clean($conditions) as $entry) { $this->memcache->delete($entry, 0); } } diff --git a/Nette/Caching/Storages/MemoryStorage.php b/Nette/Caching/Storages/MemoryStorage.php index 34099e95af..61602854ef 100644 --- a/Nette/Caching/Storages/MemoryStorage.php +++ b/Nette/Caching/Storages/MemoryStorage.php @@ -57,7 +57,7 @@ public function lock($key) * @param array dependencies * @return void */ - public function write($key, $data, array $dp) + public function write($key, $data, array $dependencies) { $this->data[$key] = $data; } @@ -81,9 +81,9 @@ public function remove($key) * @param array conditions * @return void */ - public function clean(array $conds) + public function clean(array $conditions) { - if (!empty($conds[Nette\Caching\Cache::ALL])) { + if (!empty($conditions[Nette\Caching\Cache::ALL])) { $this->data = array(); } } From 5a459422835dec92de03fb2e5b3edf9021957e72 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 19 Feb 2013 17:20:59 +0100 Subject: [PATCH 39/47] typos --- Nette/Application/Request.php | 3 --- Nette/Application/UI/IStatePersistent.php | 2 -- Nette/Caching/Cache.php | 2 -- Nette/Config/Adapters/IniAdapter.php | 1 - Nette/Config/Adapters/NeonAdapter.php | 1 - Nette/Config/Adapters/PhpAdapter.php | 1 - Nette/Config/IAdapter.php | 1 - Nette/DI/ContainerBuilder.php | 2 -- Nette/Forms/Controls/BaseControl.php | 9 ++------ Nette/Forms/Controls/UploadControl.php | 2 +- Nette/Forms/Form.php | 2 +- Nette/Loaders/RobotLoader.php | 2 -- Nette/Mail/MimePart.php | 1 - Nette/Security/IAuthenticator.php | 1 - Nette/Security/SimpleAuthenticator.php | 1 - Nette/Templating/Template.php | 6 ------ Nette/Utils/Arrays.php | 25 +---------------------- Nette/Utils/Validators.php | 4 ---- Nette/common/ArrayHash.php | 5 ----- 19 files changed, 5 insertions(+), 66 deletions(-) diff --git a/Nette/Application/Request.php b/Nette/Application/Request.php index b4b6c4a5b0..cb085bfb79 100644 --- a/Nette/Application/Request.php +++ b/Nette/Application/Request.php @@ -104,7 +104,6 @@ public function getPresenterName() /** * Sets variables provided to the presenter. - * @param array * @return Request provides a fluent interface */ public function setParameters(array $params) @@ -147,7 +146,6 @@ function getParams() /** * Sets variables provided to the presenter via POST. - * @param array * @return Request provides a fluent interface */ public function setPost(array $params) @@ -172,7 +170,6 @@ public function getPost() /** * Sets all uploaded files. - * @param array * @return Request provides a fluent interface */ public function setFiles(array $files) diff --git a/Nette/Application/UI/IStatePersistent.php b/Nette/Application/UI/IStatePersistent.php index 598d42a392..8061fc2f3d 100644 --- a/Nette/Application/UI/IStatePersistent.php +++ b/Nette/Application/UI/IStatePersistent.php @@ -25,14 +25,12 @@ interface IStatePersistent /** * Loads state informations. - * @param array * @return void */ function loadState(array $params); /** * Saves state informations for next request. - * @param array * @return void */ function saveState(array & $params); diff --git a/Nette/Caching/Cache.php b/Nette/Caching/Cache.php index 604f949c63..d30bb16d83 100644 --- a/Nette/Caching/Cache.php +++ b/Nette/Caching/Cache.php @@ -211,8 +211,6 @@ public function remove($key) * - Cache::PRIORITY => (int) priority * - Cache::TAGS => (array) tags * - Cache::ALL => TRUE - * - * @param array * @return void */ public function clean(array $conditions = NULL) diff --git a/Nette/Config/Adapters/IniAdapter.php b/Nette/Config/Adapters/IniAdapter.php index 028607ebdd..8548601c51 100644 --- a/Nette/Config/Adapters/IniAdapter.php +++ b/Nette/Config/Adapters/IniAdapter.php @@ -98,7 +98,6 @@ public function load($file) /** * Generates configuration in INI format. - * @param array * @return string */ public function dump(array $data) diff --git a/Nette/Config/Adapters/NeonAdapter.php b/Nette/Config/Adapters/NeonAdapter.php index 077a43c893..17b69a5ad3 100644 --- a/Nette/Config/Adapters/NeonAdapter.php +++ b/Nette/Config/Adapters/NeonAdapter.php @@ -75,7 +75,6 @@ private function process(array $arr) /** * Generates configuration in NEON format. - * @param array * @return string */ public function dump(array $data) diff --git a/Nette/Config/Adapters/PhpAdapter.php b/Nette/Config/Adapters/PhpAdapter.php index a6c5cc8cf9..3cd1b6b72f 100644 --- a/Nette/Config/Adapters/PhpAdapter.php +++ b/Nette/Config/Adapters/PhpAdapter.php @@ -37,7 +37,6 @@ public function load($file) /** * Generates configuration in PHP format. - * @param array * @return string */ public function dump(array $data) diff --git a/Nette/Config/IAdapter.php b/Nette/Config/IAdapter.php index 0242ca590b..536c5bcb96 100644 --- a/Nette/Config/IAdapter.php +++ b/Nette/Config/IAdapter.php @@ -32,7 +32,6 @@ function load($file); /** * Generates configuration string. - * @param array * @return string */ function dump(array $data); diff --git a/Nette/DI/ContainerBuilder.php b/Nette/DI/ContainerBuilder.php index 035722efed..fd6e9f4edd 100644 --- a/Nette/DI/ContainerBuilder.php +++ b/Nette/DI/ContainerBuilder.php @@ -537,7 +537,6 @@ public function formatPhp($statement, $args, $self = NULL) /** * Expands %placeholders% in strings (recursive). - * @param mixed * @return mixed */ public function expand($value) @@ -572,7 +571,6 @@ public function normalizeEntity($entity) /** * Converts @service or @\Class -> service name and checks its existence. - * @param mixed * @return string of FALSE, if argument is not service name */ public function getServiceName($arg, $self = NULL) diff --git a/Nette/Forms/Controls/BaseControl.php b/Nette/Forms/Controls/BaseControl.php index 52d6510bcc..ed448ed261 100644 --- a/Nette/Forms/Controls/BaseControl.php +++ b/Nette/Forms/Controls/BaseControl.php @@ -98,7 +98,7 @@ public function __construct($caption = NULL) /** * This method will be called when the component becomes attached to Form. - * @param Nette\Forms\IComponent + * @param Nette\ComponentModel\IComponent * @return void */ protected function attached($form) @@ -284,7 +284,6 @@ public function translate($s, $count = NULL) /** * Sets control's value. - * @param mixed * @return BaseControl provides a fluent interface */ public function setValue($value) @@ -319,7 +318,6 @@ public function isFilled() /** * Sets control's default value. - * @param mixed * @return BaseControl provides a fluent interface */ public function setDefaultValue($value) @@ -465,7 +463,7 @@ public function addRule($operation, $message = NULL, $arg = NULL) /** * Adds a validation condition a returns new branch. * @param mixed condition type - * @param mixed optional condition arguments + * @param mixed optional condition arguments * @return Nette\Forms\Rules new branch */ public function addCondition($operation, $value = NULL) @@ -575,8 +573,6 @@ protected static function exportRules($rules) /** * Equal validator: are control's value and second parameter equal? - * @param Nette\Forms\IControl - * @param mixed * @return bool */ public static function validateEqual(IControl $control, $arg) @@ -596,7 +592,6 @@ public static function validateEqual(IControl $control, $arg) /** * Filled validator: is control filled? - * @param Nette\Forms\IControl * @return bool */ public static function validateFilled(IControl $control) diff --git a/Nette/Forms/Controls/UploadControl.php b/Nette/Forms/Controls/UploadControl.php index 82b546bcbf..ba182c6c58 100644 --- a/Nette/Forms/Controls/UploadControl.php +++ b/Nette/Forms/Controls/UploadControl.php @@ -38,7 +38,7 @@ public function __construct($label = NULL) /** * This method will be called when the component (or component's parent) * becomes attached to a monitored object. Do not call this method yourself. - * @param Nette\Forms\IComponent + * @param Nette\ComponentModel\IComponent * @return void */ protected function attached($form) diff --git a/Nette/Forms/Form.php b/Nette/Forms/Form.php index b229c9f61f..d4fc600140 100644 --- a/Nette/Forms/Form.php +++ b/Nette/Forms/Form.php @@ -137,7 +137,7 @@ public function __construct($name = NULL) /** * This method will be called when the component (or component's parent) * becomes attached to a monitored object. Do not call this method yourself. - * @param IComponent + * @param Nette\ComponentModel\IComponent * @return void */ protected function attached($obj) diff --git a/Nette/Loaders/RobotLoader.php b/Nette/Loaders/RobotLoader.php index b4f9ea7aa4..388fb0689b 100644 --- a/Nette/Loaders/RobotLoader.php +++ b/Nette/Loaders/RobotLoader.php @@ -54,8 +54,6 @@ class RobotLoader extends AutoLoader - /** - */ public function __construct() { if (!extension_loaded('tokenizer')) { diff --git a/Nette/Mail/MimePart.php b/Nette/Mail/MimePart.php index 5793a2f039..0673afc31f 100644 --- a/Nette/Mail/MimePart.php +++ b/Nette/Mail/MimePart.php @@ -227,7 +227,6 @@ public function addPart(MimePart $part = NULL) /** * Sets textual body. - * @param mixed * @return MimePart provides a fluent interface */ public function setBody($body) diff --git a/Nette/Security/IAuthenticator.php b/Nette/Security/IAuthenticator.php index a74bd726bd..7181fc7700 100644 --- a/Nette/Security/IAuthenticator.php +++ b/Nette/Security/IAuthenticator.php @@ -35,7 +35,6 @@ interface IAuthenticator /** * Performs an authentication against e.g. database. * and returns IIdentity on success or throws AuthenticationException - * @param array * @return IIdentity * @throws AuthenticationException */ diff --git a/Nette/Security/SimpleAuthenticator.php b/Nette/Security/SimpleAuthenticator.php index 2397062b76..1600b77d8a 100644 --- a/Nette/Security/SimpleAuthenticator.php +++ b/Nette/Security/SimpleAuthenticator.php @@ -39,7 +39,6 @@ public function __construct(array $userlist) /** * Performs an authentication against e.g. database. * and returns IIdentity on success or throws AuthenticationException - * @param array * @return IIdentity * @throws AuthenticationException */ diff --git a/Nette/Templating/Template.php b/Nette/Templating/Template.php index 52c201f5f1..6f72606cca 100644 --- a/Nette/Templating/Template.php +++ b/Nette/Templating/Template.php @@ -283,8 +283,6 @@ public function setTranslator(Nette\Localization\ITranslator $translator = NULL) /** * Adds new template parameter. - * @param string name - * @param mixed value * @return Template provides a fluent interface */ public function add($name, $value) @@ -344,8 +342,6 @@ function getParams() /** * Sets a template parameter. Do not call directly. - * @param string name - * @param mixed value * @return void */ public function __set($name, $value) @@ -357,7 +353,6 @@ public function __set($name, $value) /** * Returns a template parameter. Do not call directly. - * @param string name * @return mixed value */ public function &__get($name) @@ -373,7 +368,6 @@ public function &__get($name) /** * Determines whether parameter is defined. Do not call directly. - * @param string name * @return bool */ public function __isset($name) diff --git a/Nette/Utils/Arrays.php b/Nette/Utils/Arrays.php index 666d68bbdc..a9643141ac 100644 --- a/Nette/Utils/Arrays.php +++ b/Nette/Utils/Arrays.php @@ -34,11 +34,7 @@ final public function __construct() /** - * Returns array item or $default if item is not set. - * Example: $val = Arrays::get($arr, 'i', 123); - * @param mixed array - * @param mixed key - * @param mixed default value + * Returns item from array or $default if item is not set. * @return mixed */ public static function get(array $arr, $key, $default = NULL) @@ -60,8 +56,6 @@ public static function get(array $arr, $key, $default = NULL) /** * Returns reference to array item or $default if item is not set. - * @param mixed array - * @param mixed key * @return mixed */ public static function & getRef(& $arr, $key) @@ -80,8 +74,6 @@ public static function & getRef(& $arr, $key) /** * Recursively appends elements of remaining keys from the second array to the first. - * @param array - * @param array * @return array */ public static function mergeTree($arr1, $arr2) @@ -99,8 +91,6 @@ public static function mergeTree($arr1, $arr2) /** * Searches the array for a given key and returns the offset if successful. - * @param array input array - * @param mixed key * @return int offset if it is found, FALSE otherwise */ public static function searchKey($arr, $key) @@ -113,9 +103,6 @@ public static function searchKey($arr, $key) /** * Inserts new array before item specified by key. - * @param array input array - * @param mixed key - * @param array inserted array * @return void */ public static function insertBefore(array &$arr, $key, array $inserted) @@ -128,9 +115,6 @@ public static function insertBefore(array &$arr, $key, array $inserted) /** * Inserts new array after item specified by key. - * @param array input array - * @param mixed key - * @param array inserted array * @return void */ public static function insertAfter(array &$arr, $key, array $inserted) @@ -144,9 +128,6 @@ public static function insertAfter(array &$arr, $key, array $inserted) /** * Renames key in array. - * @param array - * @param mixed old key - * @param mixed new key * @return void */ public static function renameKey(array &$arr, $oldKey, $newKey) @@ -163,9 +144,6 @@ public static function renameKey(array &$arr, $oldKey, $newKey) /** * Returns array entries that match the pattern. - * @param array - * @param string - * @param int * @return array */ public static function grep(array $arr, $pattern, $flags = 0) @@ -186,7 +164,6 @@ public static function grep(array $arr, $pattern, $flags = 0) /** * Returns flattened array. - * @param array * @return array */ public static function flatten(array $arr) diff --git a/Nette/Utils/Validators.php b/Nette/Utils/Validators.php index 7d4ffe3968..9dc32455d5 100644 --- a/Nette/Utils/Validators.php +++ b/Nette/Utils/Validators.php @@ -163,7 +163,6 @@ public static function is($value, $expected) /** * Finds whether a value is an integer. - * @param mixed * @return bool */ public static function isNumericInt($value) @@ -175,7 +174,6 @@ public static function isNumericInt($value) /** * Finds whether a string is a floating point number in decimal base. - * @param mixed * @return bool */ public static function isNumeric($value) @@ -187,7 +185,6 @@ public static function isNumeric($value) /** * Finds whether a value is a syntactically correct callback. - * @param mixed * @return bool */ public static function isCallable($value) @@ -211,7 +208,6 @@ public static function isUnicode($value) /** * Finds whether a value is "falsy". - * @param mixed * @return bool */ public static function isNone($value) diff --git a/Nette/common/ArrayHash.php b/Nette/common/ArrayHash.php index 072d0e193d..b574c83f17 100644 --- a/Nette/common/ArrayHash.php +++ b/Nette/common/ArrayHash.php @@ -67,8 +67,6 @@ public function count() /** * Replaces or appends a item. - * @param mixed - * @param mixed * @return void */ public function offsetSet($key, $value) @@ -83,7 +81,6 @@ public function offsetSet($key, $value) /** * Returns a item. - * @param mixed * @return mixed */ public function offsetGet($key) @@ -95,7 +92,6 @@ public function offsetGet($key) /** * Determines whether a item exists. - * @param mixed * @return bool */ public function offsetExists($key) @@ -107,7 +103,6 @@ public function offsetExists($key) /** * Removes the element from this list. - * @param mixed * @return void */ public function offsetUnset($key) From 3f8646d4f0b101bd611f8ae65efac8b3dc59d599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Proch=C3=A1zka?= Date: Fri, 21 Dec 2012 15:18:08 +0100 Subject: [PATCH 40/47] .gitattributes: for ignoring folders when downloading from github --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..c3822b4f95 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore +tests export-ignore From b9c6eaf06ef8bc1869e39b9c02e22be85e26349e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20H=C5=AFla?= Date: Thu, 21 Feb 2013 21:47:59 +0100 Subject: [PATCH 41/47] tests: preserve *.sh EOL always as LF [Closes #947] Shell scripts EOL will be LF no matter what core.autocrlf is. --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index c3822b4f95..20c7d6b38b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,4 @@ .gitignore export-ignore .travis.yml export-ignore tests export-ignore +*.sh eol=lf From aaba15bfc6bf04dca717af5a2bfd7adf1df7993c Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 25 Feb 2013 15:26:11 +0100 Subject: [PATCH 42/47] tests: TEMP_DIR creation is based on PID (reverts ed9da2) --- tests/Nette/bootstrap.php | 2 +- tests/RunTests.bat | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Nette/bootstrap.php b/tests/Nette/bootstrap.php index e6db77c615..b1faee6d03 100644 --- a/tests/Nette/bootstrap.php +++ b/tests/Nette/bootstrap.php @@ -21,7 +21,7 @@ // create temporary directory -define('TEMP_DIR', __DIR__ . '/../tmp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid())); +define('TEMP_DIR', __DIR__ . '/../tmp/' . getmypid()); Tester\Helpers::purge(TEMP_DIR); diff --git a/tests/RunTests.bat b/tests/RunTests.bat index 19202c1fd9..024c86af84 100644 --- a/tests/RunTests.bat +++ b/tests/RunTests.bat @@ -11,3 +11,5 @@ IF NOT EXIST %testRunner% ( SET phpIni="%~dp0php.ini-win" php.exe -c %phpIni% %testRunner% -p php-cgi.exe -c %phpIni% -j 20 -log "%~dp0test.log" %* + +rmdir "%~dp0/tmp" /S /Q \ No newline at end of file From 285971e189013d693bd8363dbad1b8ac4c551b33 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 27 Feb 2013 16:41:54 +0100 Subject: [PATCH 43/47] tests: temp dir is created non-recursive --- tests/Nette/bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Nette/bootstrap.php b/tests/Nette/bootstrap.php index b1faee6d03..b1c6d57035 100644 --- a/tests/Nette/bootstrap.php +++ b/tests/Nette/bootstrap.php @@ -22,6 +22,7 @@ // create temporary directory define('TEMP_DIR', __DIR__ . '/../tmp/' . getmypid()); +@mkdir(dirname(TEMP_DIR)); // @ - directory may already exist Tester\Helpers::purge(TEMP_DIR); From ecef354021495715ade05055faaac40178060553 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 27 Feb 2013 16:44:49 +0100 Subject: [PATCH 44/47] mkdir() - 0777 is default --- Nette/Caching/Storages/FileStorage.php | 2 +- Nette/Config/Configurator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Nette/Caching/Storages/FileStorage.php b/Nette/Caching/Storages/FileStorage.php index d3eb0dfa90..bda70b0b01 100644 --- a/Nette/Caching/Storages/FileStorage.php +++ b/Nette/Caching/Storages/FileStorage.php @@ -154,7 +154,7 @@ public function lock($key) { $cacheFile = $this->getCacheFile($key); if ($this->useDirs && !is_dir($dir = dirname($cacheFile))) { - @mkdir($dir, 0777); // @ - directory may already exist + @mkdir($dir); // @ - directory may already exist } $handle = @fopen($cacheFile, 'r+b'); // @ - file may not exist if (!$handle) { diff --git a/Nette/Config/Configurator.php b/Nette/Config/Configurator.php index 7a7c08317f..5aa888660a 100644 --- a/Nette/Config/Configurator.php +++ b/Nette/Config/Configurator.php @@ -84,7 +84,7 @@ public function setTempDirectory($path) { $this->parameters['tempDir'] = $path; if (($cacheDir = $this->getCacheDirectory()) && !is_dir($cacheDir)) { - mkdir($cacheDir, 0777); + mkdir($cacheDir); } return $this; } From 33b1018d66152f097fad2ef23faf1b57d7f70898 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 6 Mar 2013 00:48:51 +0100 Subject: [PATCH 45/47] Released version 2.0.9 --- Nette/common/Framework.php | 2 +- Nette/loader.php | 4 ++-- version.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Nette/common/Framework.php b/Nette/common/Framework.php index d55e00ae29..a2beccd668 100644 --- a/Nette/common/Framework.php +++ b/Nette/common/Framework.php @@ -25,7 +25,7 @@ final class Framework /** Nette Framework version identification */ const NAME = 'Nette Framework', - VERSION = '2.0.8', + VERSION = '2.0.9', REVISION = '$WCREV$ released on $WCDATE$'; /** @var bool set to TRUE if your host has disabled function ini_set */ diff --git a/Nette/loader.php b/Nette/loader.php index 368df7c12c..fa0b2e2507 100644 --- a/Nette/loader.php +++ b/Nette/loader.php @@ -1,7 +1,7 @@ Date: Fri, 8 Mar 2013 16:43:38 +0100 Subject: [PATCH 46/47] Revert "Config: support for constants in arguments [Closes #550]" This reverts commit b31d59a42923f292f451a162472f0b11e625585a. --- Nette/DI/ContainerBuilder.php | 3 -- .../Nette/Config/Configurator.constants.phpt | 44 ------------------- .../Nette/Config/files/config.constants.neon | 12 ----- 3 files changed, 59 deletions(-) delete mode 100644 tests/Nette/Config/Configurator.constants.phpt delete mode 100644 tests/Nette/Config/files/config.constants.neon diff --git a/Nette/DI/ContainerBuilder.php b/Nette/DI/ContainerBuilder.php index fd6e9f4edd..941cf676a6 100644 --- a/Nette/DI/ContainerBuilder.php +++ b/Nette/DI/ContainerBuilder.php @@ -525,9 +525,6 @@ public function formatPhp($statement, $args, $self = NULL) } elseif ($service = $that->getServiceName($val, $self)) { $val = $service === $self ? '$service' : $that->formatStatement(new Statement($val)); $val = new PhpLiteral($val); - - } elseif (is_string($val) && preg_match('#^[\w\\\\]*::[A-Z][A-Z0-9_]*\z#', $val, $m)) { - $val = new PhpLiteral(ltrim($val, ':')); } }); return PhpHelpers::formatArgs($statement, $args); diff --git a/tests/Nette/Config/Configurator.constants.phpt b/tests/Nette/Config/Configurator.constants.phpt deleted file mode 100644 index 58e5764e42..0000000000 --- a/tests/Nette/Config/Configurator.constants.phpt +++ /dev/null @@ -1,44 +0,0 @@ -arg = $arg; - } -} - -define('MY_CONSTANT_TEST', "one"); - -$configurator = new Configurator; -$configurator->setTempDirectory(TEMP_DIR); -$container = $configurator->addConfig(__DIR__ . '/files/config.constants.neon', Configurator::NONE) - ->createContainer(); - -Assert::same( "one", $container->ipsum->arg ); -Assert::same( Lorem::DOLOR_SIT, $container->sit->arg ); -Assert::same( "MY_FAILING_CONSTANT_TEST", $container->consectetur->arg ); - -Assert::error(function () use ($container) { - $container->amet->arg; -}, E_NOTICE, "Use of undefined constant MY_FAILING_CONSTANT_TEST - assumed 'MY_FAILING_CONSTANT_TEST'"); diff --git a/tests/Nette/Config/files/config.constants.neon b/tests/Nette/Config/files/config.constants.neon deleted file mode 100644 index f9527c4430..0000000000 --- a/tests/Nette/Config/files/config.constants.neon +++ /dev/null @@ -1,12 +0,0 @@ -services: - ipsum: - class: Lorem(::MY_CONSTANT_TEST) - - sit: - class: Lorem(Lorem::DOLOR_SIT) - - amet: - class: Lorem(::MY_FAILING_CONSTANT_TEST) - - consectetur: - class: Lorem(MY_FAILING_CONSTANT_TEST) From c0332ac55877cc6e678a3cd0679caaa3fc48c55b Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 8 Mar 2013 16:44:18 +0100 Subject: [PATCH 47/47] Released version 2.0.10 --- Nette/common/Framework.php | 2 +- Nette/loader.php | 4 ++-- version.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Nette/common/Framework.php b/Nette/common/Framework.php index a2beccd668..b662045639 100644 --- a/Nette/common/Framework.php +++ b/Nette/common/Framework.php @@ -25,7 +25,7 @@ final class Framework /** Nette Framework version identification */ const NAME = 'Nette Framework', - VERSION = '2.0.9', + VERSION = '2.0.10', REVISION = '$WCREV$ released on $WCDATE$'; /** @var bool set to TRUE if your host has disabled function ini_set */ diff --git a/Nette/loader.php b/Nette/loader.php index fa0b2e2507..819d7d7c70 100644 --- a/Nette/loader.php +++ b/Nette/loader.php @@ -1,7 +1,7 @@