From f9745d2d3e356a1da4f470806ed113bb8d669860 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 18 Jan 2017 18:01:03 +0100 Subject: [PATCH 1/9] composer: updated Nette to 3.0 --- CD-collection/composer.json | 20 ++++++++++---------- Fifteen/composer.json | 12 ++++++------ Micro-blog/composer.json | 14 +++++++------- Modules-Usage/composer.json | 12 ++++++------ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/CD-collection/composer.json b/CD-collection/composer.json index c70d4b1..81180fb 100644 --- a/CD-collection/composer.json +++ b/CD-collection/composer.json @@ -14,16 +14,16 @@ } ], "require": { - "php": ">=5.6", - "nette/application": "^2.4", - "nette/bootstrap": "^2.4.2", - "nette/database": "^2.4", - "nette/forms": "^2.4.3", - "nette/robot-loader": "^2.4", - "nette/security": "^2.4", - "nette/utils": "^2.4", - "latte/latte": "^2.4", + "php": ">=7.1", + "nette/application": "^3.0", + "nette/bootstrap": "^3.0", + "nette/database": "^3.0", + "nette/forms": "^3.0", + "nette/robot-loader": "^3.0", + "nette/security": "^3.0", + "nette/utils": "^3.0", + "latte/latte": "^3.0", "tracy/tracy": "^2.4" }, - "minimum-stability": "stable" + "minimum-stability": "dev" } diff --git a/Fifteen/composer.json b/Fifteen/composer.json index 95aabe6..1099e9e 100644 --- a/Fifteen/composer.json +++ b/Fifteen/composer.json @@ -14,12 +14,12 @@ } ], "require": { - "php": ">=5.6", - "nette/application": "^2.4", - "nette/bootstrap": "^2.4.2", - "nette/robot-loader": "^2.4", - "latte/latte": "^2.4", + "php": ">=7.1", + "nette/application": "^3.0", + "nette/bootstrap": "^3.0", + "nette/robot-loader": "^3.0", + "latte/latte": "^3.0", "tracy/tracy": "^2.4" }, - "minimum-stability": "stable" + "minimum-stability": "dev" } diff --git a/Micro-blog/composer.json b/Micro-blog/composer.json index 53e5a59..bc6a67d 100644 --- a/Micro-blog/composer.json +++ b/Micro-blog/composer.json @@ -14,15 +14,15 @@ } ], "require": { - "php": ">=5.6", - "nette/application": "^2.4", - "nette/bootstrap": "^2.4.2", - "nette/database": "^2.4", - "nette/robot-loader": "^2.4", - "latte/latte": "^2.4", + "php": ">=7.1", + "nette/application": "^3.0", + "nette/bootstrap": "^3.0", + "nette/database": "^3.0", + "nette/robot-loader": "^3.0", + "latte/latte": "^3.0", "tracy/tracy": "^2.4" }, - "minimum-stability": "stable", + "minimum-stability": "dev", "config": { "vendor-dir": "www/data/vendor" } diff --git a/Modules-Usage/composer.json b/Modules-Usage/composer.json index 3dd3738..fa11bca 100644 --- a/Modules-Usage/composer.json +++ b/Modules-Usage/composer.json @@ -14,12 +14,12 @@ } ], "require": { - "php": ">=5.6", - "nette/application": "^2.4", - "nette/bootstrap": "^2.4.2", - "nette/robot-loader": "^2.4", - "latte/latte": "^2.4", + "php": ">=7.1", + "nette/application": "^3.0", + "nette/bootstrap": "^3.0", + "nette/robot-loader": "^3.0", + "latte/latte": "^3.0", "tracy/tracy": "^2.4" }, - "minimum-stability": "stable" + "minimum-stability": "dev" } From 3fc62b975b44ff1dab4b9ebaea712432d4b1b23a Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 25 Jan 2017 04:01:40 +0100 Subject: [PATCH 2/9] compatibility with Nette 3 --- CD-collection/app/model/Authenticator.php | 3 +-- Fifteen/app/components/FifteenControl.php | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/CD-collection/app/model/Authenticator.php b/CD-collection/app/model/Authenticator.php index 7464f5d..60435a2 100644 --- a/CD-collection/app/model/Authenticator.php +++ b/CD-collection/app/model/Authenticator.php @@ -25,10 +25,9 @@ public function __construct(Nette\Database\Context $database) /** * Performs an authentication. - * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ - public function authenticate(array $credentials) + public function authenticate(array $credentials): Security\IIdentity { list($username, $password) = $credentials; $row = $this->database->table('users')->where('username', $username)->fetch(); diff --git a/Fifteen/app/components/FifteenControl.php b/Fifteen/app/components/FifteenControl.php index 3890962..1a89379 100644 --- a/Fifteen/app/components/FifteenControl.php +++ b/Fifteen/app/components/FifteenControl.php @@ -119,11 +119,9 @@ public function render() /** - * Loads params - * @param array - * @return void + * Loads params. */ - public function loadState(array $params) + public function loadState(array $params): void { if (isset($params['order'])) { $params['order'] = explode('.', (string) $params['order']); @@ -141,11 +139,9 @@ public function loadState(array $params) /** - * Save params - * @param array - * @return void + * Save params. */ - public function saveState(array &$params) + public function saveState(array &$params): void { parent::saveState($params); if (isset($params['order'])) { From a0adce7f380624482dd9e0043d4d1e7d2424b150 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 18 Jan 2017 18:02:28 +0100 Subject: [PATCH 3/9] added declare(strict_types=1); --- CD-collection/app/bootstrap.php | 2 ++ CD-collection/app/model/AlbumRepository.php | 2 ++ CD-collection/app/model/Authenticator.php | 2 ++ CD-collection/app/presenters/DashboardPresenter.php | 2 ++ CD-collection/app/presenters/SignPresenter.php | 2 ++ CD-collection/www/index.php | 2 ++ Fifteen/app/bootstrap.php | 2 ++ Fifteen/app/components/FifteenControl.php | 2 ++ Fifteen/app/presenters/DefaultPresenter.php | 2 ++ Fifteen/www/index.php | 2 ++ Micro-blog/www/data/TemplateRouter.php | 2 ++ Micro-blog/www/index.php | 2 ++ Modules-Usage/app/bootstrap.php | 2 ++ Modules-Usage/app/modules/Admin/DefaultPresenter.php | 2 ++ Modules-Usage/app/modules/Base/BasePresenter.php | 2 ++ Modules-Usage/app/modules/Front.Export/DefaultPresenter.php | 2 ++ Modules-Usage/app/modules/Front/CatalogListPresenter.php | 2 ++ Modules-Usage/app/modules/Front/DefaultPresenter.php | 2 ++ Modules-Usage/www/index.php | 2 ++ 19 files changed, 38 insertions(+) diff --git a/CD-collection/app/bootstrap.php b/CD-collection/app/bootstrap.php index fbb5fb1..b416cab 100644 --- a/CD-collection/app/bootstrap.php +++ b/CD-collection/app/bootstrap.php @@ -1,5 +1,7 @@ Date: Tue, 11 Jul 2017 02:46:27 +0200 Subject: [PATCH 4/9] coding style: fixed spaces & use statements order --- CD-collection/app/bootstrap.php | 1 - CD-collection/app/model/AlbumRepository.php | 2 -- CD-collection/app/model/Authenticator.php | 2 -- CD-collection/app/presenters/DashboardPresenter.php | 2 -- CD-collection/app/presenters/SignPresenter.php | 2 -- CD-collection/www/index.php | 1 - Fifteen/app/bootstrap.php | 1 - Fifteen/app/components/FifteenControl.php | 2 -- Fifteen/app/presenters/DefaultPresenter.php | 4 ---- Fifteen/www/index.php | 1 - Micro-blog/www/data/TemplateRouter.php | 3 --- Micro-blog/www/index.php | 1 - Modules-Usage/app/bootstrap.php | 1 - Modules-Usage/app/modules/Admin/DefaultPresenter.php | 2 -- Modules-Usage/app/modules/Base/BasePresenter.php | 3 --- Modules-Usage/app/modules/Front.Export/DefaultPresenter.php | 2 -- Modules-Usage/app/modules/Front/CatalogListPresenter.php | 2 -- Modules-Usage/app/modules/Front/DefaultPresenter.php | 2 -- Modules-Usage/www/index.php | 1 - 19 files changed, 35 deletions(-) diff --git a/CD-collection/app/bootstrap.php b/CD-collection/app/bootstrap.php index b416cab..9f70e45 100644 --- a/CD-collection/app/bootstrap.php +++ b/CD-collection/app/bootstrap.php @@ -1,5 +1,4 @@ findAll()->insert($values); } - } diff --git a/CD-collection/app/model/Authenticator.php b/CD-collection/app/model/Authenticator.php index 4353d6a..6ea91d5 100644 --- a/CD-collection/app/model/Authenticator.php +++ b/CD-collection/app/model/Authenticator.php @@ -1,5 +1,4 @@ id, NULL, $arr); } - } diff --git a/CD-collection/app/presenters/DashboardPresenter.php b/CD-collection/app/presenters/DashboardPresenter.php index 498838e..a7c9e74 100644 --- a/CD-collection/app/presenters/DashboardPresenter.php +++ b/CD-collection/app/presenters/DashboardPresenter.php @@ -1,5 +1,4 @@ redirect('default'); } - } diff --git a/CD-collection/app/presenters/SignPresenter.php b/CD-collection/app/presenters/SignPresenter.php index e7e4ae3..424bf6d 100644 --- a/CD-collection/app/presenters/SignPresenter.php +++ b/CD-collection/app/presenters/SignPresenter.php @@ -1,5 +1,4 @@ flashMessage('You have been signed out.'); $this->redirect('in'); } - } diff --git a/CD-collection/www/index.php b/CD-collection/www/index.php index 58e4c56..0e13d58 100644 --- a/CD-collection/www/index.php +++ b/CD-collection/www/index.php @@ -1,5 +1,4 @@ redrawControl('round'); @@ -31,5 +28,4 @@ public function gameOver($sender, $round) $this->template->flash = 'Congratulations!'; $this->redrawControl('flash'); } - } diff --git a/Fifteen/www/index.php b/Fifteen/www/index.php index 58e4c56..0e13d58 100644 --- a/Fifteen/www/index.php +++ b/Fifteen/www/index.php @@ -1,5 +1,4 @@ template->viewName = $this->getView(); @@ -24,5 +22,4 @@ protected function beforeRender() $this->template->presenterName = substr($this->getName(), $a + 1); } } - } diff --git a/Modules-Usage/app/modules/Front.Export/DefaultPresenter.php b/Modules-Usage/app/modules/Front.Export/DefaultPresenter.php index 2b01555..86956f0 100644 --- a/Modules-Usage/app/modules/Front.Export/DefaultPresenter.php +++ b/Modules-Usage/app/modules/Front.Export/DefaultPresenter.php @@ -1,10 +1,8 @@ Date: Tue, 11 Jul 2017 02:46:52 +0200 Subject: [PATCH 5/9] coding style: TRUE/FALSE/NULL -> true/false/null --- CD-collection/app/model/Authenticator.php | 2 +- Fifteen/app/components/FifteenControl.php | 14 +++++++------- Micro-blog/www/data/TemplateRouter.php | 8 ++++---- Modules-Usage/app/modules/Base/BasePresenter.php | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CD-collection/app/model/Authenticator.php b/CD-collection/app/model/Authenticator.php index 6ea91d5..5cdbcd3 100644 --- a/CD-collection/app/model/Authenticator.php +++ b/CD-collection/app/model/Authenticator.php @@ -42,6 +42,6 @@ public function authenticate(array $credentials): Security\IIdentity $arr = $row->toArray(); unset($arr['password']); - return new Security\Identity($row->id, NULL, $arr); + return new Security\Identity($row->id, null, $arr); } } diff --git a/Fifteen/app/components/FifteenControl.php b/Fifteen/app/components/FifteenControl.php index 5a685e3..458276f 100644 --- a/Fifteen/app/components/FifteenControl.php +++ b/Fifteen/app/components/FifteenControl.php @@ -68,30 +68,30 @@ public function getRound() } - public function isClickable($x, $y, &$rel = NULL) + public function isClickable($x, $y, &$rel = null) { - $rel = NULL; + $rel = null; $pos = $x + $y * $this->width; $empty = $this->searchEmpty(); $y = (int) ($empty / $this->width); $x = $empty % $this->width; if ($x > 0 && $pos === $empty - 1) { $rel = '-1,'; - return TRUE; + return true; } if ($x < $this->width - 1 && $pos === $empty + 1) { $rel = '+1,'; - return TRUE; + return true; } if ($y > 0 && $pos === $empty - $this->width) { $rel = ',-1'; - return TRUE; + return true; } if ($y < $this->width - 1 && $pos === $empty + $this->width) { $rel = ',+1'; - return TRUE; + return true; } - return FALSE; + return false; } diff --git a/Micro-blog/www/data/TemplateRouter.php b/Micro-blog/www/data/TemplateRouter.php index e1a0293..43b77fc 100644 --- a/Micro-blog/www/data/TemplateRouter.php +++ b/Micro-blog/www/data/TemplateRouter.php @@ -15,16 +15,16 @@ public function __construct($path, $cachePath) $routes = require $cacheFile; } else { $routes = $this->scanRoutes($path); - file_put_contents($cacheFile, ' $file) { $this[] = new Routers\Route($mask, function ($presenter) use ($file, $cachePath) { - return $presenter->createTemplate(NULL, function () use ($cachePath) { + return $presenter->createTemplate(null, function () use ($cachePath) { $latte = new Latte\Engine; $latte->setTempDirectory($cachePath . '/cache'); $macroSet = new Latte\Macros\MacroSet($latte->getCompiler()); - $macroSet->addMacro('url', function () {}, NULL, NULL, $macroSet::ALLOWED_IN_HEAD); // ignore + $macroSet->addMacro('url', function () {}, null, null, $macroSet::ALLOWED_IN_HEAD); // ignore return $latte; })->setFile($file); }); @@ -39,7 +39,7 @@ public function scanRoutes($path) $macroSet = new Latte\Macros\MacroSet($latte->getCompiler()); $macroSet->addMacro('url', function ($node) use (&$routes, &$file) { $routes[$node->args] = (string) $file; - }, NULL, NULL, $macroSet::ALLOWED_IN_HEAD); + }, null, null, $macroSet::ALLOWED_IN_HEAD); foreach (Nette\Utils\Finder::findFiles('*.latte')->from($path) as $file) { $latte->compile($file); } diff --git a/Modules-Usage/app/modules/Base/BasePresenter.php b/Modules-Usage/app/modules/Base/BasePresenter.php index 15d8164..322b6d5 100644 --- a/Modules-Usage/app/modules/Base/BasePresenter.php +++ b/Modules-Usage/app/modules/Base/BasePresenter.php @@ -11,10 +11,10 @@ abstract class BasePresenter extends Nette\Application\UI\Presenter protected function beforeRender() { $this->template->viewName = $this->getView(); - $this->template->root = isset($_SERVER['SCRIPT_FILENAME']) ? realpath(dirname(dirname($_SERVER['SCRIPT_FILENAME']))) : NULL; + $this->template->root = isset($_SERVER['SCRIPT_FILENAME']) ? realpath(dirname(dirname($_SERVER['SCRIPT_FILENAME']))) : null; $a = strrpos($this->getName(), ':'); - if ($a === FALSE) { + if ($a === false) { $this->template->moduleName = ''; $this->template->presenterName = $this->getName(); } else { From 6fbed8a83fc838ab7249d2cce6933dc4de660df8 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 28 Jul 2017 01:04:52 +0200 Subject: [PATCH 6/9] cs & strict code fixes --- CD-collection/app/bootstrap.php | 2 +- CD-collection/app/model/Authenticator.php | 2 +- Fifteen/app/components/FifteenControl.php | 4 ++-- Modules-Usage/app/bootstrap.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CD-collection/app/bootstrap.php b/CD-collection/app/bootstrap.php index 9f70e45..3a96fee 100644 --- a/CD-collection/app/bootstrap.php +++ b/CD-collection/app/bootstrap.php @@ -27,7 +27,7 @@ $container = $configurator->createContainer(); // Setup router using mod_rewrite detection -if (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules())) { +if (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules(), true)) { $router = $container->getByType(Nette\Application\IRouter::class); $router[] = new Route('index.php', 'Dashboard:default', Route::ONE_WAY); $router[] = new Route('/[/]', 'Dashboard:default'); diff --git a/CD-collection/app/model/Authenticator.php b/CD-collection/app/model/Authenticator.php index 5cdbcd3..647e548 100644 --- a/CD-collection/app/model/Authenticator.php +++ b/CD-collection/app/model/Authenticator.php @@ -30,7 +30,7 @@ public function __construct(Nette\Database\Context $database) */ public function authenticate(array $credentials): Security\IIdentity { - list($username, $password) = $credentials; + [$username, $password] = $credentials; $row = $this->database->table('users')->where('username', $username)->fetch(); if (!$row) { diff --git a/Fifteen/app/components/FifteenControl.php b/Fifteen/app/components/FifteenControl.php index 458276f..eed3fe7 100644 --- a/Fifteen/app/components/FifteenControl.php +++ b/Fifteen/app/components/FifteenControl.php @@ -106,7 +106,7 @@ private function move($x, $y) private function searchEmpty() { - return array_search(0, $this->order); + return array_search(0, $this->order, true); } @@ -125,7 +125,7 @@ public function render() public function loadState(array $params): void { if (isset($params['order'])) { - $params['order'] = explode('.', (string) $params['order']); + $params['order'] = array_map('intval', explode('.', (string) $params['order'])); // validate $copy = $params['order']; diff --git a/Modules-Usage/app/bootstrap.php b/Modules-Usage/app/bootstrap.php index 72d326b..074b966 100644 --- a/Modules-Usage/app/bootstrap.php +++ b/Modules-Usage/app/bootstrap.php @@ -28,7 +28,7 @@ $container = $configurator->createContainer(); // Setup router using mod_rewrite detection -if (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules())) { +if (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules(), true)) { $router = $container->getByType(Nette\Application\IRouter::class); $router[] = new Route('index.php', 'Front:Default:default', Route::ONE_WAY); From 82dd17cc483fff9da93f7e342293fa6bcb3ba18d Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 13 Jul 2017 19:08:23 +0200 Subject: [PATCH 7/9] travis: tested using Nette Coding Standard --- .travis.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59b9baf..fe225ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,16 @@ language: php php: - - 5.6 + - 7.1 -script: - - php code-checker/src/code-checker.php +install: + # Install Nette Code Checker + - travis_retry composer create-project nette/code-checker temp/code-checker ~2 --no-progress + # Install Nette Coding Standard + - travis_retry composer create-project nette/coding-standard temp/coding-standard --no-progress -before_script: - - travis_retry composer create-project nette/code-checker code-checker --no-interaction +script: + - php temp/code-checker/src/code-checker.php --short-arrays --strict-types + - php temp/coding-standard/ecs check . --config temp/coding-standard/coding-standard-php71.neon sudo: false From cbf733ec58031606e7e301acea04fc7126c9f0a7 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 9 Sep 2017 14:20:08 +0200 Subject: [PATCH 8/9] added example Books --- Books/composer.json | 9 +++ Books/demo/config/mysql.neon | 7 +++ Books/demo/config/postgresql.neon | 7 +++ Books/demo/config/sqlite.neon | 5 ++ Books/demo/config/sqlsrv.neon | 7 +++ Books/demo/demo.php | 48 ++++++++++++++ Books/demo/dump/mysql.sql | 93 +++++++++++++++++++++++++++ Books/demo/dump/postgresql.sql | 92 +++++++++++++++++++++++++++ Books/demo/dump/sqlite.sql | 93 +++++++++++++++++++++++++++ Books/demo/dump/sqlsrv.sql | 101 ++++++++++++++++++++++++++++++ Books/demo/log/.gitignore | 3 + Books/demo/temp/.gitignore | 3 + 12 files changed, 468 insertions(+) create mode 100644 Books/composer.json create mode 100644 Books/demo/config/mysql.neon create mode 100644 Books/demo/config/postgresql.neon create mode 100644 Books/demo/config/sqlite.neon create mode 100644 Books/demo/config/sqlsrv.neon create mode 100644 Books/demo/demo.php create mode 100644 Books/demo/dump/mysql.sql create mode 100644 Books/demo/dump/postgresql.sql create mode 100644 Books/demo/dump/sqlite.sql create mode 100644 Books/demo/dump/sqlsrv.sql create mode 100644 Books/demo/log/.gitignore create mode 100644 Books/demo/temp/.gitignore diff --git a/Books/composer.json b/Books/composer.json new file mode 100644 index 0000000..41f22b1 --- /dev/null +++ b/Books/composer.json @@ -0,0 +1,9 @@ +{ + "require": { + "php": ">=7.1", + "nette/database": "^3.0", + "nette/bootstrap": "^3.0", + "tracy/tracy": "^2.4" + }, + "minimum-stability": "dev" +} diff --git a/Books/demo/config/mysql.neon b/Books/demo/config/mysql.neon new file mode 100644 index 0000000..2ac672e --- /dev/null +++ b/Books/demo/config/mysql.neon @@ -0,0 +1,7 @@ +parameters: + dumpFile: %appDir%/dump/mysql.sql + +database: + dsn: 'mysql:host=127.0.0.1;dbname=nette_test' + user: root + password: diff --git a/Books/demo/config/postgresql.neon b/Books/demo/config/postgresql.neon new file mode 100644 index 0000000..15a87f5 --- /dev/null +++ b/Books/demo/config/postgresql.neon @@ -0,0 +1,7 @@ +parameters: + dumpFile: %appDir%/dump/postgresql.sql + +database: + dsn: 'pgsql:host=127.0.0.1;dbname=nette_test' + user: postgres + password: diff --git a/Books/demo/config/sqlite.neon b/Books/demo/config/sqlite.neon new file mode 100644 index 0000000..abb9cc8 --- /dev/null +++ b/Books/demo/config/sqlite.neon @@ -0,0 +1,5 @@ +parameters: + dumpFile: %appDir%/dump/sqlite.sql + +database: + dsn: 'sqlite::memory:' diff --git a/Books/demo/config/sqlsrv.neon b/Books/demo/config/sqlsrv.neon new file mode 100644 index 0000000..8ea9a22 --- /dev/null +++ b/Books/demo/config/sqlsrv.neon @@ -0,0 +1,7 @@ +parameters: + dumpFile: %appDir%/dump/sqlsrv.sql + +database: + dsn: 'sqlsrv:server=127.0.0.1;database=nette_test' + user: + password: diff --git a/Books/demo/demo.php b/Books/demo/demo.php new file mode 100644 index 0000000..bd6ce65 --- /dev/null +++ b/Books/demo/demo.php @@ -0,0 +1,48 @@ +enableTracy(__DIR__ . '/log'); + +// create DI container +$configurator->setTempDirectory(__DIR__ . '/temp'); +$configurator->addConfig(__DIR__ . '/config/sqlite.neon'); // for SQLite +//$configurator->addConfig(__DIR__ . '/config/mysql.neon'); // for MySQL +//$configurator->addConfig(__DIR__ . '/config/postgresql.neon'); // for PostgreSQL +//$configurator->addConfig(__DIR__ . '/config/sqlsrv.neon'); // for MS SQL Server +$container = $configurator->createContainer(); + +// get database from DI container +// see https://doc.nette.org/en/di-configuration +/** @var Nette\Database\Context $database */ +$database = $container->getByType(Nette\Database\Context::class); + +// load database dump +Nette\Database\Helpers::loadFromFile( + $database->getConnection(), + $container->parameters['dumpFile'] // defined in config file +); + +// lists the author's name for each book and all its tags: +// see https://doc.nette.org/en/database-explorer +$books = $database->table('book'); + +echo PHP_SAPI === 'cli' ? '' : ''; + +foreach ($books as $book) { + echo "title: {$book->title} \n"; + echo "written by: {$book->author->name} \n"; // $book->author is row from table 'author' + + echo 'tags: '; + foreach ($book->related('book_tag') as $bookTag) { + echo $bookTag->tag->name . ', '; // $bookTag->tag is row from table 'tag' + } + echo "\n\n"; +} + +echo PHP_SAPI === 'cli' ? '' : ''; diff --git a/Books/demo/dump/mysql.sql b/Books/demo/dump/mysql.sql new file mode 100644 index 0000000..b63befe --- /dev/null +++ b/Books/demo/dump/mysql.sql @@ -0,0 +1,93 @@ +SET FOREIGN_KEY_CHECKS = 0; + +DROP TABLE IF EXISTS `author`, `book`, `book_tag`, `book_tag_alt`, `note`, `tag`; + + +CREATE TABLE author ( + id int NOT NULL AUTO_INCREMENT, + name varchar(30) NOT NULL, + web varchar(100) NOT NULL, + born date DEFAULT NULL, + PRIMARY KEY(id) +) ENGINE=InnoDB AUTO_INCREMENT=13; + +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); + + + +CREATE TABLE tag ( + id int NOT NULL AUTO_INCREMENT, + name varchar(20) NOT NULL, + PRIMARY KEY (id) +) ENGINE=InnoDB AUTO_INCREMENT=25; + +INSERT INTO tag (id, name) VALUES (21, 'PHP'); +INSERT INTO tag (id, name) VALUES (22, 'MySQL'); +INSERT INTO tag (id, name) VALUES (23, 'JavaScript'); +INSERT INTO tag (id, name) VALUES (24, 'Neon'); + + + +CREATE TABLE book ( + id int NOT NULL AUTO_INCREMENT, + author_id int NOT NULL, + translator_id int, + title varchar(50) NOT NULL, + next_volume int, + PRIMARY KEY (id), + CONSTRAINT book_author FOREIGN KEY (author_id) REFERENCES author (id), + CONSTRAINT book_translator FOREIGN KEY (translator_id) REFERENCES author (id), + CONSTRAINT book_volume FOREIGN KEY (next_volume) REFERENCES book (id) +) ENGINE=InnoDB AUTO_INCREMENT=5; + +CREATE INDEX book_title ON book (title); + +INSERT INTO book (id, author_id, translator_id, title) VALUES (1, 11, 11, '1001 tipu a triku pro PHP'); +INSERT INTO book (id, author_id, translator_id, title) VALUES (2, 11, NULL, 'JUSH'); +INSERT INTO book (id, author_id, translator_id, title) VALUES (3, 12, 12, 'Nette'); +INSERT INTO book (id, author_id, translator_id, title) VALUES (4, 12, 12, 'Dibi'); + + + +CREATE TABLE book_tag ( + book_id int NOT NULL, + tag_id int NOT NULL, + PRIMARY KEY (book_id, tag_id), + CONSTRAINT book_tag_tag FOREIGN KEY (tag_id) REFERENCES tag (id), + CONSTRAINT book_tag_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE +) ENGINE=InnoDB; + +INSERT INTO book_tag (book_id, tag_id) VALUES (1, 21); +INSERT INTO book_tag (book_id, tag_id) VALUES (3, 21); +INSERT INTO book_tag (book_id, tag_id) VALUES (4, 21); +INSERT INTO book_tag (book_id, tag_id) VALUES (1, 22); +INSERT INTO book_tag (book_id, tag_id) VALUES (4, 22); +INSERT INTO book_tag (book_id, tag_id) VALUES (2, 23); + + + +CREATE TABLE book_tag_alt ( + book_id int NOT NULL, + tag_id int NOT NULL, + state varchar(30), + PRIMARY KEY (book_id, tag_id), + CONSTRAINT book_tag_alt_tag FOREIGN KEY (tag_id) REFERENCES tag (id), + CONSTRAINT book_tag_alt_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE +) ENGINE=InnoDB; + +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 21, 'public'); +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 22, 'private'); +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 23, 'private'); +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 24, 'public'); + + + +CREATE TABLE note ( + book_id int NOT NULL, + note varchar(100), + CONSTRAINT note_book FOREIGN KEY (book_id) REFERENCES book (id) +) ENGINE=InnoDB; + +SET FOREIGN_KEY_CHECKS = 1; diff --git a/Books/demo/dump/postgresql.sql b/Books/demo/dump/postgresql.sql new file mode 100644 index 0000000..33e4fb4 --- /dev/null +++ b/Books/demo/dump/postgresql.sql @@ -0,0 +1,92 @@ +DROP TABLE IF EXISTS `author`, `book`, `book_tag`, `book_tag_alt`, `note`, `tag`; + + +CREATE TABLE author ( + id serial NOT NULL, + name varchar(30) NOT NULL, + web varchar(100) NOT NULL, + born date DEFAULT NULL, + PRIMARY KEY(id) +); + +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); +SELECT setval('author_id_seq', 13, TRUE); + + + +CREATE TABLE tag ( + id serial NOT NULL, + name varchar(20) NOT NULL, + PRIMARY KEY (id) +); + +INSERT INTO tag (id, name) VALUES (21, 'PHP'); +INSERT INTO tag (id, name) VALUES (22, 'MySQL'); +INSERT INTO tag (id, name) VALUES (23, 'JavaScript'); +INSERT INTO tag (id, name) VALUES (24, 'Neon'); +SELECT setval('tag_id_seq', 24, TRUE); + + + +CREATE TABLE book ( + id serial NOT NULL, + author_id int NOT NULL, + translator_id int, + title varchar(50) NOT NULL, + next_volume INT, + PRIMARY KEY (id), + CONSTRAINT book_author FOREIGN KEY (author_id) REFERENCES author (id), + CONSTRAINT book_translator FOREIGN KEY (translator_id) REFERENCES author (id), + CONSTRAINT book_volume FOREIGN KEY (next_volume) REFERENCES book (id) +); + +CREATE INDEX book_title ON book (title); + + + +INSERT INTO book (id, author_id, translator_id, title) VALUES (1, 11, 11, '1001 tipu a triku pro PHP'); +INSERT INTO book (id, author_id, translator_id, title) VALUES (2, 11, NULL, 'JUSH'); +INSERT INTO book (id, author_id, translator_id, title) VALUES (3, 12, 12, 'Nette'); +INSERT INTO book (id, author_id, translator_id, title) VALUES (4, 12, 12, 'Dibi'); +SELECT setval('book_id_seq', 4, TRUE); + +CREATE TABLE book_tag ( + book_id int NOT NULL, + tag_id int NOT NULL, + PRIMARY KEY (book_id, tag_id), + CONSTRAINT book_tag_tag FOREIGN KEY (tag_id) REFERENCES tag (id), + CONSTRAINT book_tag_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE +); + +INSERT INTO book_tag (book_id, tag_id) VALUES (1, 21); +INSERT INTO book_tag (book_id, tag_id) VALUES (3, 21); +INSERT INTO book_tag (book_id, tag_id) VALUES (4, 21); +INSERT INTO book_tag (book_id, tag_id) VALUES (1, 22); +INSERT INTO book_tag (book_id, tag_id) VALUES (4, 22); +INSERT INTO book_tag (book_id, tag_id) VALUES (2, 23); + + + +CREATE TABLE book_tag_alt ( + book_id int NOT NULL, + tag_id int NOT NULL, + state varchar(30), + PRIMARY KEY (book_id, tag_id), + CONSTRAINT book_tag_alt_tag FOREIGN KEY (tag_id) REFERENCES tag (id), + CONSTRAINT book_tag_alt_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE +); + +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 21, 'public'); +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 22, 'private'); +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 23, 'private'); +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 24, 'public'); + + + +CREATE TABLE note ( + book_id int NOT NULL, + note varchar(100), + CONSTRAINT note_book FOREIGN KEY (book_id) REFERENCES book (id) +); diff --git a/Books/demo/dump/sqlite.sql b/Books/demo/dump/sqlite.sql new file mode 100644 index 0000000..a9331dd --- /dev/null +++ b/Books/demo/dump/sqlite.sql @@ -0,0 +1,93 @@ +DROP TABLE IF EXISTS note; +DROP TABLE IF EXISTS book_tag_alt; +DROP TABLE IF EXISTS book_tag; +DROP TABLE IF EXISTS book; +DROP TABLE IF EXISTS tag; +DROP TABLE IF EXISTS author; + + + + +CREATE TABLE author ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + name TEXT NOT NULL, + web TEXT NOT NULL, + born DATE +); + +INSERT INTO author (id, name, web, born) VALUES (11, 'Jakub Vrana', 'http://www.vrana.cz/', NULL); +INSERT INTO author (name, web, born) VALUES ('David Grudl', 'http://davidgrudl.com/', NULL); +INSERT INTO author (name, web, born) VALUES ('Geek', 'http://example.com', NULL); + + + +CREATE TABLE tag ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + name TEXT NOT NULL +); + +INSERT INTO tag (id, name) VALUES (21, 'PHP'); +INSERT INTO tag (name) VALUES ('MySQL'); +INSERT INTO tag (name) VALUES ('JavaScript'); +INSERT INTO tag (name) VALUES ('Neon'); + + + +CREATE TABLE book ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + author_id INTEGER NOT NULL, + translator_id INTEGER, + title TEXT NOT NULL, + next_volume INTEGER, + CONSTRAINT book_author FOREIGN KEY (author_id) REFERENCES author (id), + CONSTRAINT book_translator FOREIGN KEY (translator_id) REFERENCES author (id), + CONSTRAINT book_volume FOREIGN KEY (next_volume) REFERENCES book (id) +); + +CREATE INDEX book_title ON book (title); + +INSERT INTO book (author_id, translator_id, title) VALUES (11, 11, '1001 tipu a triku pro PHP'); +INSERT INTO book (author_id, translator_id, title) VALUES (11, NULL, 'JUSH'); +INSERT INTO book (author_id, translator_id, title) VALUES (12, 12, 'Nette'); +INSERT INTO book (author_id, translator_id, title) VALUES (12, 12, 'Dibi'); + + + +CREATE TABLE book_tag ( + book_id INTEGER NOT NULL, + tag_id INTEGER NOT NULL, + CONSTRAINT book_tag_tag FOREIGN KEY (tag_id) REFERENCES tag (id), + CONSTRAINT book_tag_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE, + PRIMARY KEY (book_id, tag_id) +); + +INSERT INTO book_tag (book_id, tag_id) VALUES (1, 21); +INSERT INTO book_tag (book_id, tag_id) VALUES (3, 21); +INSERT INTO book_tag (book_id, tag_id) VALUES (4, 21); +INSERT INTO book_tag (book_id, tag_id) VALUES (1, 22); +INSERT INTO book_tag (book_id, tag_id) VALUES (4, 22); +INSERT INTO book_tag (book_id, tag_id) VALUES (2, 23); + + + +CREATE TABLE book_tag_alt ( + book_id INTEGER NOT NULL, + tag_id INTEGER NOT NULL, + state TEXT, + PRIMARY KEY (book_id, tag_id), + CONSTRAINT book_tag_alt_tag FOREIGN KEY (tag_id) REFERENCES tag (id), + CONSTRAINT book_tag_alt_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE +); + +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 21, 'public'); +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 22, 'private'); +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 23, 'private'); +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES (3, 24, 'public'); + + + +CREATE TABLE note ( + book_id int NOT NULL, + note varchar(100), + CONSTRAINT note_book FOREIGN KEY (book_id) REFERENCES book (id) +); diff --git a/Books/demo/dump/sqlsrv.sql b/Books/demo/dump/sqlsrv.sql new file mode 100644 index 0000000..23911c2 --- /dev/null +++ b/Books/demo/dump/sqlsrv.sql @@ -0,0 +1,101 @@ +IF OBJECT_ID('note', 'U') IS NOT NULL DROP TABLE note; +IF OBJECT_ID('book_tag_alt', 'U') IS NOT NULL DROP TABLE book_tag_alt; +IF OBJECT_ID('book_tag', 'U') IS NOT NULL DROP TABLE book_tag; +IF OBJECT_ID('book', 'U') IS NOT NULL DROP TABLE book; +IF OBJECT_ID('tag', 'U') IS NOT NULL DROP TABLE tag; +IF OBJECT_ID('author', 'U') IS NOT NULL DROP TABLE author; + + + +CREATE TABLE author ( + id int NOT NULL IDENTITY(11,1), + name varchar(30) NOT NULL, + web varchar(100) NOT NULL, + born date, + PRIMARY KEY(id) +); + +INSERT INTO author (name, web, born) VALUES +('Jakub Vrana', 'http://www.vrana.cz/', NULL), +('David Grudl', 'http://davidgrudl.com/', NULL), +('Geek', 'http://example.com', NULL); + + + +CREATE TABLE tag ( + id int NOT NULL IDENTITY(21, 1), + name varchar(20) NOT NULL, + PRIMARY KEY (id) +); + +INSERT INTO tag (name) VALUES +('PHP'), +('MySQL'), +('JavaScript'), +('Neon'); + + + +CREATE TABLE book ( + id int NOT NULL IDENTITY(1,1), + author_id int NOT NULL, + translator_id int, + title varchar(50) NOT NULL, + next_volume int, + PRIMARY KEY (id), + CONSTRAINT book_author FOREIGN KEY (author_id) REFERENCES author (id), + CONSTRAINT book_translator FOREIGN KEY (translator_id) REFERENCES author (id), + CONSTRAINT book_volume FOREIGN KEY (next_volume) REFERENCES book (id) +); + +CREATE INDEX book_title ON book (title); + +INSERT INTO book (author_id, translator_id, title) VALUES +(11, 11, '1001 tipu a triku pro PHP'), +(11, NULL, 'JUSH'), +(12, 12, 'Nette'), +(12, 12, 'Dibi'); + + + +-- Add primary key manually, it is tested to name +CREATE TABLE book_tag ( + book_id int NOT NULL, + tag_id int NOT NULL, + CONSTRAINT book_tag_tag FOREIGN KEY (tag_id) REFERENCES tag (id), + CONSTRAINT book_tag_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE +); +ALTER TABLE book_tag ADD CONSTRAINT PK_book_tag PRIMARY KEY CLUSTERED (book_id, tag_id); + +INSERT INTO book_tag (book_id, tag_id) VALUES +(1, 21), +(3, 21), +(4, 21), +(1, 22), +(4, 22), +(2, 23); + + + +CREATE TABLE book_tag_alt ( + book_id int NOT NULL, + tag_id int NOT NULL, + state varchar(30), + PRIMARY KEY (book_id, tag_id), + CONSTRAINT book_tag_alt_tag FOREIGN KEY (tag_id) REFERENCES tag (id), + CONSTRAINT book_tag_alt_book FOREIGN KEY (book_id) REFERENCES book (id) ON DELETE CASCADE +); + +INSERT INTO book_tag_alt (book_id, tag_id, state) VALUES +(3, 21, 'public'), +(3, 22, 'private'), +(3, 23, 'private'), +(3, 24, 'public'); + + + +CREATE TABLE note ( + book_id int NOT NULL, + note varchar(100), + CONSTRAINT note_book FOREIGN KEY (book_id) REFERENCES book (id) +); diff --git a/Books/demo/log/.gitignore b/Books/demo/log/.gitignore new file mode 100644 index 0000000..4a7528a --- /dev/null +++ b/Books/demo/log/.gitignore @@ -0,0 +1,3 @@ +* +!.* +!*/.* \ No newline at end of file diff --git a/Books/demo/temp/.gitignore b/Books/demo/temp/.gitignore new file mode 100644 index 0000000..4a7528a --- /dev/null +++ b/Books/demo/temp/.gitignore @@ -0,0 +1,3 @@ +* +!.* +!*/.* \ No newline at end of file From 2415bd20a85a79f160a230d61de4cc6659dc461c Mon Sep 17 00:00:00 2001 From: GenesisTMS Date: Thu, 28 Sep 2017 17:07:47 +0200 Subject: [PATCH 9/9] proper name (#19) --- Fifteen/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fifteen/composer.json b/Fifteen/composer.json index 1099e9e..136cc85 100644 --- a/Fifteen/composer.json +++ b/Fifteen/composer.json @@ -1,5 +1,5 @@ { - "name": "nette-examples/cd-collection", + "name": "nette-examples/fifteen", "type": "project", "description": "A simple example showing components as the reusable stand-alone units.", "license": "BSD-3-Clause",