-
Notifications
You must be signed in to change notification settings - Fork 2k
Added PHP Nette Framework #7817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c149247
added nette framework [ci fw PHP/nette]
n0nag0n 6075e11
Update README.md
n0nag0n 50e1c6f
Update benchmark_config.json with suggested values
n0nag0n 16a7d11
Delete robots.txt
n0nag0n e26ec55
updated to php 8.2 [ci fw PHP/nette]
n0nag0n 6008e5e
Merge branch 'php-nette' of https://github.com/n0nag0n/FrameworkBench…
n0nag0n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Nette Benchmarking Test | ||
|
||
_Note: opcache.save_comments needs to be 1 in order for the framework to function properly._ | ||
|
||
### Test Type Implementation Source Code | ||
|
||
* [JSON](app/Presenters/SimplePresenter.php) | ||
* [PLAINTEXT](app/Presenters/SimplePresenter.php) | ||
* [DB](app/Presenters/DatabasePresenter.php) | ||
* [QUERY](app/Presenters/DatabasePresenter.php) | ||
* [UPDATE](app/Presenters/DatabasePresenter.php) | ||
* [FORTUNES](app/Presenters/DatabasePresenter.php) | ||
|
||
## Important Libraries | ||
The tests were run with: | ||
* [Nette](https://www.nette.org/) | ||
|
||
## Test URLs | ||
### JSON | ||
|
||
http://localhost:8080/simple/json | ||
|
||
### PLAINTEXT | ||
|
||
http://localhost:8080/simple/plaintext | ||
|
||
### DB | ||
|
||
http://localhost:8080/database/db | ||
|
||
### QUERY | ||
|
||
http://localhost:8080/database/query?queries= | ||
|
||
### UPDATE | ||
|
||
http://localhost:8080/database/update?queries= | ||
|
||
### FORTUNES | ||
|
||
http://localhost:8080/database/fortune |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
use Nette\Bootstrap\Configurator; | ||
|
||
|
||
class Bootstrap | ||
{ | ||
public static function boot(): Configurator | ||
{ | ||
$configurator = new Configurator; | ||
$appDir = dirname(__DIR__); | ||
|
||
//$configurator->setDebugMode('[email protected]'); // enable for your remote IP | ||
$configurator->enableTracy($appDir . '/log'); | ||
$configurator->setDebugMode(false); | ||
$configurator->setTimeZone('Europe/Prague'); | ||
$configurator->setTempDirectory($appDir . '/temp'); | ||
|
||
$configurator->createRobotLoader() | ||
->addDirectory(__DIR__) | ||
->register(); | ||
|
||
//$configurator->addConfig($appDir . '/config/common.neon'); | ||
$configurator->addConfig($appDir . '/config/services.neon'); | ||
//$configurator->addConfig($appDir . '/config/local.neon'); | ||
|
||
return $configurator; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Presenters; | ||
|
||
use Nette; | ||
|
||
|
||
final class DatabasePresenter extends Nette\Application\UI\Presenter | ||
{ | ||
|
||
private Nette\Database\Explorer $explorer; | ||
|
||
public function __construct(Nette\Database\Explorer $explorer) { | ||
$this->explorer = $explorer; | ||
} | ||
|
||
public function renderDb() { | ||
$random_id = mt_rand(1, 10000); | ||
$table = $this->explorer->table('World'); | ||
$row = $table->where('id', $random_id)->fetch(); | ||
$this->sendJson([ | ||
'id' => $row->id, | ||
'randomNumber' => $row->randomNumber | ||
]); | ||
} | ||
|
||
public function renderQuery() { | ||
$queries = $this->getHttpRequest()->getQuery('queries'); | ||
if (is_numeric($queries)) { | ||
$queries = max(1, min($queries, 500)); | ||
} else { | ||
$queries = 1; | ||
} | ||
|
||
$worlds = []; | ||
for ($i = 0; $i < $queries; ++$i) { | ||
$random_id = mt_rand(1, 10000); | ||
$table = $this->explorer->table('World'); | ||
$row = $table->where('id = ?', $random_id)->fetch(); | ||
$world = [ | ||
'id' => $row['id'], | ||
'randomNumber' => $row['randomNumber'] | ||
]; | ||
$worlds[] = $world; | ||
} | ||
$this->sendJson($worlds); | ||
} | ||
|
||
public function renderUpdate() { | ||
$queries = $this->getHttpRequest()->getQuery('queries'); | ||
if (is_numeric($queries)) { | ||
$queries = max(1, min($queries, 500)); | ||
} else { | ||
$queries = 1; | ||
} | ||
|
||
$worlds = []; | ||
for ($i = 0; $i < $queries; ++$i) { | ||
$random_id = mt_rand(1, 10000); | ||
$random_update_id = mt_rand(1, 10000); | ||
$update_result = $this->explorer->table('World')->where('id', $random_id); | ||
$update_row = $update_result->fetch(); | ||
$update_result->update([ | ||
'randomNumber' => $random_update_id | ||
]); | ||
$world = [ | ||
'id' => $update_row->id, | ||
'randomNumber' => $random_update_id | ||
]; | ||
$worlds[] = $world; | ||
} | ||
$this->sendJson($worlds); | ||
} | ||
|
||
public function renderFortune() { | ||
$fortunes = $this->explorer->table('Fortune')->fetchAll(); | ||
$fortunes = $this->addFortune($fortunes); | ||
$fortunes = $this->sortFortunes($fortunes); | ||
$this->template->fortunes = $fortunes; | ||
} | ||
|
||
protected function addFortune($fortunes) { | ||
$fortunes[] = (object) [ 'id' => 0, 'message' => 'Additional fortune added at request time.' ]; | ||
return $fortunes; | ||
} | ||
|
||
protected function sortFortunes(array $fortunes): array { | ||
usort($fortunes, function ($left, $right) { | ||
return $left->message <=> $right->message; | ||
}); | ||
|
||
return $fortunes; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Presenters; | ||
|
||
use Nette; | ||
|
||
final class SimplePresenter extends Nette\Application\UI\Presenter | ||
{ | ||
|
||
public function renderPlainText() { | ||
$this->getHttpResponse()->setContentType('text/plain', 'UTF-8'); | ||
$this->sendResponse(new \Nette\Application\Responses\TextResponse('Hello, World!')); | ||
} | ||
|
||
public function renderJson() { | ||
$this->sendJson(['message' => 'Hello, World!']); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
frameworks/PHP/nette/app/Presenters/templates/Database/fortune.latte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head><title>Fortunes</title></head> | ||
<body> | ||
<table> | ||
<tr> | ||
<th>id</th> | ||
<th>message</th> | ||
</tr> | ||
{foreach $fortunes as $fortune} | ||
<tr> | ||
<td>{$fortune->id}</td> | ||
<td>{$fortune->message}</td> | ||
</tr> | ||
{/foreach} | ||
</table> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Router; | ||
|
||
use Nette; | ||
use Nette\Application\Routers\RouteList; | ||
|
||
|
||
final class RouterFactory | ||
{ | ||
use Nette\StaticClass; | ||
|
||
public static function createRouter(): RouteList | ||
{ | ||
$router = new RouteList; | ||
$router->addRoute('<presenter>/<action>[/<id>]'); | ||
return $router; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"framework": "nette", | ||
"tests": [ | ||
{ | ||
"default": { | ||
"json_url": "/simple/json", | ||
"plaintext_url": "/simple/plaintext", | ||
"db_url": "/database/db", | ||
"query_url": "/database/query?queries=", | ||
"update_url": "/database/update?queries=", | ||
"fortune_url": "/database/fortune", | ||
"port": 8080, | ||
"approach": "Realistic", | ||
"classification": "Fullstack", | ||
"database": "mysql", | ||
"framework": "Nette", | ||
"language": "PHP", | ||
"flavor": "PHP8", | ||
"orm": "Full", | ||
"platform": "FPM/FastCGI", | ||
"webserver": "nginx", | ||
"os": "Linux", | ||
"database_os": "Linux", | ||
"display_name": "Nette", | ||
"notes": "", | ||
"versus": "php" | ||
} | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "nette/web-project", | ||
"description": "Nette: Standard Web Project", | ||
"keywords": ["nette"], | ||
"type": "project", | ||
"license": ["MIT", "BSD-3-Clause", "GPL-2.0", "GPL-3.0"], | ||
"require": { | ||
"php": ">= 7.2", | ||
"nette/application": "^3.1", | ||
"nette/bootstrap": "^3.1", | ||
"nette/caching": "^3.1", | ||
"nette/database": "^3.1", | ||
"nette/di": "^3.0", | ||
"nette/finder": "^2.5", | ||
"nette/forms": "^3.1", | ||
"nette/http": "^3.1", | ||
"nette/mail": "^3.1", | ||
"nette/robot-loader": "^3.3", | ||
"nette/security": "^3.1", | ||
"nette/utils": "^3.2", | ||
"latte/latte": "^2.11 || ^3.0", | ||
"tracy/tracy": "^2.8" | ||
}, | ||
"require-dev": { | ||
"nette/tester": "^2.3", | ||
"symfony/thanks": "^1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"App\\": "app" | ||
} | ||
}, | ||
"minimum-stability": "stable", | ||
"config": { | ||
"allow-plugins": { | ||
"symfony/thanks": true | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
search: | ||
default: | ||
in: %appDir% | ||
classes: | ||
- *Factory | ||
- *Facade | ||
|
||
services: | ||
- App\Router\RouterFactory::createRouter | ||
|
||
application: | ||
#errorPresenter: Error | ||
mapping: | ||
*: App\*Module\Presenters\*Presenter | ||
|
||
session: | ||
expiration: 14 days | ||
|
||
di: | ||
export: | ||
parameters: no | ||
tags: no | ||
|
||
database: | ||
dsn: 'mysql:host=tfb-database;port=3306;dbname=hello_world' | ||
user: 'benchmarkdbuser' | ||
password: 'benchmarkdbpass' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.