no message

This commit is contained in:
BarboraFleg
2019-04-04 18:34:40 +02:00
commit ce48ca4a21
589 changed files with 82184 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
$configurator = new Nette\Configurator;
//$configurator->setDebugMode('23.75.345.200'); // enable for your remote IP
$configurator->enableTracy(__DIR__ . '/../log');
$configurator->setTimeZone('Europe/Prague');
$configurator->setTempDirectory(__DIR__ . '/../temp');
$configurator->createRobotLoader()
->addDirectory(__DIR__)
->register();
$configurator->addConfig(__DIR__ . '/config/config.neon');
$configurator->addConfig(__DIR__ . '/config/config.local.neon');
$container = $configurator->createContainer();
return $container;
+7
View File
@@ -0,0 +1,7 @@
parameters:
database:
dsn: 'mysql:host=127.0.0.1;dbname=test'
user:
password:
+16
View File
@@ -0,0 +1,16 @@
parameters:
application:
errorPresenter: Error
mapping:
*: App\*Module\Presenters\*Presenter
session:
expiration: 14 days
services:
router: App\RouterFactory::createRouter
- App\Model\CalculatorManager
+128
View File
@@ -0,0 +1,128 @@
<?php
/*
MODEL
// kalkulačka
// 4 základní operace
//tj. sčítání, odčítání, násobení a dělení
//trida CalculatorManager (class)
//1. pouziva php trait Nette/SmartObject ()
//TRAITS: mechanism for code reuse in single inheritance
//intended to reduce some limitations of single inheritance
//by enabling a developer to reuse sets of methods freely in
//several independent classes living in different class hierarchies
//*similar to a class,but only intended to group functionality in a fine-grained and consistent way
//e.g:
/*
trait ezcReflectionReturnInfo {
function getReturnType() { }
function getReturnDescription() { }
}
class ezcReflectionMethod extends ReflectionMethod {
use ezcReflectionReturnInfo;
}
//2. definuje 4 operace: sčítání, odčítání, násobení a dělení
*/
namespace App\Model;
use Nette\SmartObject;
/**
* Model operací kalkulačky.
* @package App\Model
*/
class CalculatorManager{
use SmartObject;
/** Definice konstant pro operace. */
const
ADD = 1,
SUBTRACT = 2,
MULTIPLY = 3,
DIVIDE = 4;
/**
* Getter pro existující operace.
* @return array asociativní pole konstant pro operace a jejich slovního pojmenování
*/
public function getOperations(){
return array(
self::ADD => 'Sčítání',
self::SUBTRACT => 'Odčítání',
self::MULTIPLY => 'Násobení',
self::DIVIDE => 'Dělení'
);
}
/**
* Zavolá zadanou operaci a vrátí její výsledek.
* @param int $operation zadaná operace
* @param int $x první číslo pro operaci
* @param int $y druhé číslo pro operaci
* @return int|null výsledek operace nebo null, pokud zadaná operace neexistuje
*/
public function calculate($operation, $x, $y){
switch ($operation) {
case self::ADD:
return $this->add($x, $y);
case self::SUBTRACT:
return $this->subtract($x, $y);
case self::MULTIPLY:
return $this->multiply($x, $y);
case self::DIVIDE:
return $this->divide($x, $y);
default:
return null;
}
}
/**
* Sečte daná čísla a vrátí výsledek.
* @param int $x první číslo
* @param int $y druhé číslo
* @return int výsledek po sčítání
*/
public function add($x, $y){
return $x + $y;
}
/**
* Odečte druhé číslo od prvního a vrátí výsledek.
* @param int $x první číslo
* @param int $y druhé číslo
* @return int výsledek po odčítání
*/
public function subtract($x, $y)
{
return $x - $y;
}
/**
* Vynásobí daná čísla a vrátí výsledek.
* @param int $x první číslo
* @param int $y druhé číslo
* @return int výsledek po násobení
*/
public function multiply($x, $y)
{
return $x * $y;
}
/**
* Vydělí první číslo druhým bezezbytku a vrátí výsledek.
* @param int $x první číslo
* @param int $y druhé číslo; nesmí být 0
* @return int výsledek po dělení bezezbytku
*/
public function divide($x, $y)
{
return round($x / $y);
}
}
+81
View File
@@ -0,0 +1,81 @@
<?php
namespace App\Presenters;
use Nette\Application\UI\Presenter;
use App\Model\CalculatorManager;
use Nette\Application\UI\Form;
use Nette\Utils\ArrayHash;
/**
* Presenter kalkulačky.
* @package App\Presenters
*/
class CalculatorPresenter extends Presenter{
const
FORM_MSG_REQUIRED = 'Tohle pole je povinné.',
FORM_MSG_RULE = 'Tohle pole má neplatný formát.';
/** @var CalculatorManager Instance třídy modelu pro práci s operacemi kalkulačky. */
private $calculatorManager;
/** @var int|null výsledek operace nebo null */
private $result = null;
public function __construct(CalculatorManager $calculatorManager){
parent::__construct();
$this->calculatorManager = $calculatorManager;
}
/** Výchozí vykreslovací metoda tohoto presenteru. */
public function renderDefault(){
// Předání výsledku do šablony.
$this->template->result = $this->result;
}
/**
* Vrátí formulář kalkulačky.
* @return Form formulář kalkulačky
*/
protected function createComponentCalculatorForm(){
$form = new Form;
// Získáme existující operace kalkulačky a dáme je do výběru operací.
$form->addRadioList('operation', 'Operace:', $this->calculatorManager->getOperations())
->setDefaultValue(CalculatorManager::ADD)
->setRequired(self::FORM_MSG_REQUIRED);
$form->addText('x', 'První číslo:')
->setType('number')
->setDefaultValue(0)
->setRequired(self::FORM_MSG_REQUIRED)
->addRule(Form::INTEGER, self::FORM_MSG_RULE);
$form->addText('y', 'Druhé číslo:')
->setType('number')
->setDefaultValue(0)
->setRequired(self::FORM_MSG_REQUIRED)
->addRule(Form::INTEGER, self::FORM_MSG_RULE)
// Ošetříme dělení nulou.
->addConditionOn($form['operation'], Form::EQUAL, CalculatorManager::DIVIDE)
->addRule(Form::PATTERN, 'Nelze dělit nulou.', '^[^0].*');
$form->addSubmit('calculate', 'Spočítej výsledek');
$form->onSuccess[] = [$this, 'calculatorFormSucceeded'];
return $form;
}
/**
* Funkce se vykonaná při úspěšném odeslání formuláře kalkulačky a zpracuje odeslané hodnoty.
* @param Form $form formulář kalkulačky
* @param ArrayHash $values odeslané hodnoty formuláře
*/
public function calculatorFormSucceeded($form, $values) {
// Necháme si vypočítat výsledek podle zvolené operace a zadaných hodnot.
$this->result = $this->calculatorManager->calculate($values->operation, $values->x, $values->y);
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace App\Presenters;
use Nette;
final class Error4xxPresenter extends Nette\Application\UI\Presenter
{
public function startup(): void
{
parent::startup();
if (!$this->getRequest()->isMethod(Nette\Application\Request::FORWARD)) {
$this->error();
}
}
public function renderDefault(Nette\Application\BadRequestException $exception): void
{
// load template 403.latte or 404.latte or ... 4xx.latte
$file = __DIR__ . "/templates/Error/{$exception->getCode()}.latte";
$this->template->setFile(is_file($file) ? $file : __DIR__ . '/templates/Error/4xx.latte');
}
}
+43
View File
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Presenters;
use Nette;
use Nette\Application\Responses;
use Nette\Http;
use Tracy\ILogger;
final class ErrorPresenter implements Nette\Application\IPresenter
{
use Nette\SmartObject;
/** @var ILogger */
private $logger;
public function __construct(ILogger $logger)
{
$this->logger = $logger;
}
public function run(Nette\Application\Request $request): Nette\Application\IResponse
{
$exception = $request->getParameter('exception');
if ($exception instanceof Nette\Application\BadRequestException) {
[$module, , $sep] = Nette\Application\Helpers::splitName($request->getPresenterName());
return new Responses\ForwardResponse($request->setPresenterName($module . $sep . 'Error4xx'));
}
$this->logger->log($exception, ILogger::EXCEPTION);
return new Responses\CallbackResponse(function (Http\IRequest $httpRequest, Http\IResponse $httpResponse): void {
if (preg_match('#^text/html(?:;|$)#', (string) $httpResponse->getHeader('Content-Type'))) {
require __DIR__ . '/templates/Error/500.phtml';
}
});
}
}
+19
View File
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>{ifset title}{include title|stripHtml} | {/ifset}Nette Web</title>
</head>
<body>
<div n:foreach="$flashes as $flash" n:class="flash, $flash->type">{$flash->message}</div>
{include content}
{block scripts}
<script src="https://nette.github.io/resources/js/3/netteForms.min.js"></script>
{/block}
</body>
</html>
@@ -0,0 +1,33 @@
{block content}
<div id="banner">
<h1 n:block=title>Calculator!</h1>
</div>
<div id="content">
<h3 n:ifset=$result>Result is: {$result}</h3>
{control calculatorForm}
</div>
<style>
html { font: normal 18px/1.3 Georgia, "New York CE", utopia, serif; color: #666; -webkit-text-stroke: 1px rgba(0,0,0,0); overflow-y: scroll; }
body { background: #3484d2; color: #333; margin: 2em auto; padding: 0 .5em; max-width: 600px; min-width: 320px; }
a { color: #006aeb; padding: 3px 1px; }
a:hover, a:active, a:focus { background-color: #006aeb; text-decoration: none; color: white; }
#banner { border-radius: 12px 12px 0 0; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAB5CAMAAADPursXAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAGBQTFRFD1CRDkqFDTlmDkF1D06NDT1tDTNZDk2KEFWaDTZgDkiCDTtpDT5wDkZ/DTBVEFacEFOWD1KUDTRcDTFWDkV9DkR7DkN4DkByDTVeDC9TDThjDTxrDkeADkuIDTRbDC9SbsUaggAAAEdJREFUeNqkwYURgAAQA7DH3d3335LSKyxAYpf9vWCpnYbf01qcOdFVXc14w4BznNTjkQfsscAdU3b4wIh9fDVYc4zV8xZgAAYaCMI6vPgLAAAAAElFTkSuQmCC); }
h1 { font: inherit; color: white; font-size: 50px; line-height: 121px; margin: 0; padding-left: 4%; background: url(https://files.nette.org/images/logo-nette@2.png) no-repeat 95%; background-size: 130px auto; text-shadow: 1px 1px 0 rgba(0, 0, 0, .9); }
@media (max-width: 600px) {
h1 { background: none; font-size: 40px; }
}
#content { background: white; border: 1px solid #eff4f7; border-radius: 0 0 12px 12px; padding: 10px 4%; overflow: hidden; }
h2 { font: inherit; padding: 1.2em 0; margin: 0; }
img { border: none; float: right; margin: 0 0 1em 3em; }
</style>
{/block}
+7
View File
@@ -0,0 +1,7 @@
{block content}
<h1 n:block=title>Access Denied</h1>
<p>You do not have permission to view this page. Please try contact the web
site administrator if you believe you should be able to view this page.</p>
<p><small>error 403</small></p>
+8
View File
@@ -0,0 +1,8 @@
{block content}
<h1 n:block=title>Page Not Found</h1>
<p>The page you requested could not be found. It is possible that the address is
incorrect, or that the page no longer exists. Please use a search engine to find
what you are looking for.</p>
<p><small>error 404</small></p>
+6
View File
@@ -0,0 +1,6 @@
{block content}
<h1 n:block=title>Method Not Allowed</h1>
<p>The requested method is not allowed for the URL.</p>
<p><small>error 405</small></p>
+6
View File
@@ -0,0 +1,6 @@
{block content}
<h1 n:block=title>Page Not Found</h1>
<p>The page you requested has been taken off the site. We apologize for the inconvenience.</p>
<p><small>error 410</small></p>
+4
View File
@@ -0,0 +1,4 @@
{block content}
<h1 n:block=title>Oops...</h1>
<p>Your browser sent a request that this server could not understand or process.</p>
+27
View File
@@ -0,0 +1,27 @@
<!DOCTYPE html><!-- "' --></textarea></script></style></pre></xmp></a></audio></button></canvas></datalist></details></dialog></iframe></listing></meter></noembed></noframes></noscript></optgroup></option></progress></rp></select></table></template></title></video>
<meta charset="utf-8">
<meta name="robots" content="noindex">
<title>Server Error</title>
<style>
#nette-error { all: initial; position: absolute; top: 0; left: 0; right: 0; height: 70vh; min-height: 400px; display: flex; align-items: center; justify-content: center; z-index: 1000 }
#nette-error div { all: initial; max-width: 550px; background: white; color: #333; display: block }
#nette-error h1 { all: initial; font: bold 50px/1.1 sans-serif; display: block; margin: 40px }
#nette-error p { all: initial; font: 20px/1.4 sans-serif; margin: 40px; display: block }
#nette-error small { color: gray }
</style>
<div id=nette-error>
<div>
<h1>Server Error</h1>
<p>We're sorry! The server encountered an internal error and
was unable to complete your request. Please try again later.</p>
<p><small>error 500</small></p>
</div>
</div>
<script>
document.body.insertBefore(document.getElementById('nette-error'), document.body.firstChild);
</script>
+24
View File
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
header('HTTP/1.1 503 Service Unavailable');
header('Retry-After: 300'); // 5 minutes in seconds
?>
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="robots" content="noindex">
<meta name="generator" content="Nette Framework">
<style>
body { color: #333; background: white; width: 500px; margin: 100px auto }
h1 { font: bold 47px/1.5 sans-serif; margin: .6em 0 }
p { font: 21px/1.5 Georgia,serif; margin: 1.5em 0 }
</style>
<title>Site is temporarily down for maintenance</title>
<h1>We're Sorry</h1>
<p>The site is temporarily down for maintenance. Please try again in a few minutes.</p>
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App;
use Nette\Application\Routers\IRoute;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;
use Nette\StaticClass;
class RouterFactory
{
use StaticClass;
/**
* @return IRouter
*/
public static function createRouter()
{
$router = new RouteList;
$router[]= new Route('<presenter>/<action>[/<id>]', 'Calculator:default');
return $router;
}
}