Skip to content

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 6 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions frameworks/PHP/nette/README.md
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
33 changes: 33 additions & 0 deletions frameworks/PHP/nette/app/Bootstrap.php
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;
}
}
96 changes: 96 additions & 0 deletions frameworks/PHP/nette/app/Presenters/DatabasePresenter.php
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;
}
}
20 changes: 20 additions & 0 deletions frameworks/PHP/nette/app/Presenters/SimplePresenter.php
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!']);
}
}
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>
21 changes: 21 additions & 0 deletions frameworks/PHP/nette/app/Router/RouterFactory.php
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;
}
}
30 changes: 30 additions & 0 deletions frameworks/PHP/nette/benchmark_config.json
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"
}
}
]
}
39 changes: 39 additions & 0 deletions frameworks/PHP/nette/composer.json
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
}
}
}
27 changes: 27 additions & 0 deletions frameworks/PHP/nette/config/services.neon
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'
Loading