Informačné technológieInformation Technologies / Týždeň 1Week 1

Technológie, ktoré budeme používaťThe technologies we will use

Ako to fungujeHow it works Prvé cvičenieThe first lab Pojmy a termínyTerms and definitions

Nástroje, s ktorými pracujeme celý semester, sa ukážu na prednáške a nastavia na prvom cvičení. Postup krok za krokom je v Návodoch a nástrojoch, tu je prehľad toho, ako predmet funguje, čo si na prvom cvičení pripravíš, a tabuľka pojmov.

The tools we work with all semester are shown in the lecture and set up in the first lab. Step-by-step instructions are in Guides and tools; this page gives an overview of how the course works, what you prepare in the first lab, and the table of terms.

Ako to fungujeHow it works

Celý semester staviaš jednu aplikáciu. Na prednáške sa každý týždeň vysvetlí jedna téma a ukáže sa na vzorovom projekte, ktorý rastie rovnako ako tvoj. Na cvičení tú istú vec doplníš do vlastného projektu. Vzorový projekt sú recepty; tvoj projekt má inú tému, ale rovnakú stavbu. Preto je návrh dátového modelu v 2. týždni taký dôležitý: ak má tvoja databáza rovnaký tvar ako vzor, každý týždeň vieš prenášať postup zo vzoru do svojho projektu bez toho, aby si musel vymýšľať niečo iné.

Kód píšeš vo VS Code v Kubeflow. Každé uloženie v editore ide cez SFTP na sigma.tuke.sk samo, súbory mimo editora doplní Upload Folder; na sigma.tuke.sk aplikácia beží so skutočným PHP 8.1 a databázou MariaDB. Odovzdávanie je commit a push na GitHub. sigma.tuke.sk a GitHub o sebe nevedia, obidve dostávajú kód z Kubeflow. Na sigma.tuke.sk sa nič neupravuje.

Vo webovom priestore na sigma.tuke.sk aj v Kubeflow používaš rovnakú štruktúru priečinkov: it/cv01, it/cv02, … pre týždenné zadania a it/projekt pre semestrálne zadanie. Priečinok ~/web v Kubeflow je zrkadlom ~/public_html na sigma.tuke.sk.

Po prvom cvičení sa dá celý pracovný postup overiť tromi krokmi. Ak niektorý nefunguje, rieš ho skôr, než pôjdeš ďalej.

1. V Kubeflow ulož súbor  ~/web/it/test.php
   → na sigma.tuke.sk sa objaví   ~/public_html/it/test.php     (SFTP, samo pri uložení)
   → v prehliadači beží   https://sigma.tuke.sk/student/meno.priezvisko/it/test.php

2. GitHub: si v organizácii tuke-fberg-stehlikova
   → ssh -T git@github.com v termináli Kubeflow odpovie tvojím GitHub menom

3. Adminer: https://sigma.tuke.sk/student/meno.priezvisko/adminer.php
   → prihlásenie do databázy meno_priezvisko, zatiaľ bez tabuliek

You build one application for the whole semester. Each week the lecture explains one topic and demonstrates it on a sample project, which grows the same way yours does. In the lab you add the same thing to your own project. The sample project is recipes; your project has a different topic but the same structure. That is why the data model design in week 2 matters so much: if your database has the same shape as the sample, every week you can transfer the procedure from the sample to your project without inventing something different.

You write code in VS Code in Kubeflow. Every save in the editor goes over SFTP to sigma.tuke.sk by itself; files outside the editor are added with Upload Folder; on sigma.tuke.sk the application runs with real PHP 8.1 and a MariaDB database. Submitting means commit and push to GitHub. sigma.tuke.sk and GitHub do not know about each other; both receive the code from Kubeflow. Nothing is edited on sigma.tuke.sk.

In your web space on sigma.tuke.sk and in Kubeflow you use the same folder structure: it/cv01, it/cv02, … for weekly assignments and it/projekt for the semester project. The folder ~/web in Kubeflow mirrors ~/public_html on sigma.tuke.sk.

After the first lab the whole workflow can be checked in three steps. If any of them fails, fix it before going further.

1. In Kubeflow save the file   ~/web/it/test.php
   → it appears on sigma.tuke.sk as    ~/public_html/it/test.php     (SFTP, by itself on save)
   → it runs in the browser at https://sigma.tuke.sk/student/name.surname/it/test.php

2. GitHub: you are in the organization tuke-fberg-stehlikova
   → ssh -T git@github.com in the Kubeflow terminal replies with your GitHub username

3. Adminer: https://sigma.tuke.sk/student/name.surname/adminer.php
   → sign in to the database name_surname, no tables yet

Prvé cvičenieThe first lab

Na prvom cvičení si pripravíš všetko, s čím budeš pracovať celý semester. Každý krok má svoj návod; tu je len poradie a kontrola, že sa podaril.

  1. GitHub konto, 2FA, pozvánka do organizácie – návod 01 GitHub. Kontrola: vidíš organizáciu tuke-fberg-stehlikova.
  2. Kubeflow a VS Code – návod 02 Kubeflow: notebook, rozšírenia, nastavenie Git, SSH kľúč pre GitHub. Kontrola: ssh -T git@github.com v termináli odpovie tvojím GitHub menom.
  3. sigma.tuke.sk a SFTP – návod 03 Sigma: public_html, v ňom priečinok it, SSH kľúč na sigma.tuke.sk, nastavenie SFTP vo VS Code. Kontrola: súbor uložený v ~/web/it/ sa objaví v ~/public_html/it/ a dá sa otvoriť v prehliadači.
  4. Adminer – návod 05 Databáza: adminer.php v public_html, prihlásenie do databázy meno_priezvisko. Heslo dostaneš na cvičení. Kontrola: Adminer ukáže prázdnu databázu.
  5. Zadanie od prijatia po odovzdanie – návod 04 Odovzdávanie si prečítaj, od 2. týždňa ho používaš pri každom cvičení.

Prvý týždeň nemá zadanie ani body. Kto nestihol všetko na cvičení, dokončí to podľa návodov do 2. týždňa.

In the first lab you prepare everything you will work with all semester. Every step has its guide; here is only the order and the check that it worked.

  1. GitHub account, 2FA, invitation to the organization – guide 01 GitHub. Check: you can see the organization tuke-fberg-stehlikova.
  2. Kubeflow and VS Code – guide 02 Kubeflow: notebook, extensions, Git configuration, SSH key for GitHub. Check: ssh -T git@github.com in the terminal replies with your GitHub username.
  3. sigma.tuke.sk and SFTP – guide 03 Sigma: public_html with the folder it in it, SSH key on sigma.tuke.sk, SFTP set up in VS Code. Check: a file saved in ~/web/it/ appears in ~/public_html/it/ and opens in the browser.
  4. Adminer – guide 05 Database: adminer.php in public_html, sign-in to the database name_surname. You get the password in the lab. Check: Adminer shows an empty database.
  5. An assignment from accepting to submitting – read guide 04 Submitting; from week 2 on you use it in every lab.

The first week has no assignment and no points. If you did not finish everything in the lab, complete it with the guides before week 2.

Pojmy a termínyTerms and definitions

Tabuľka pojmov celého predmetu. Každý týždeň do nej pribudnú nové, na konci semestra bude úplná. Týždenné stránky pojmy neopakujú, len na túto tabuľku odkazujú.

Pojem English Vysvetlenie Týž.
Kubeflow Kubeflow školský cloud, v ktorom beží náš VS Code; otvára sa v prehliadači 1
VS Code VS Code editor, v ktorom píšeme kód 1
sigma sigma server, na ktorom beží tvoja aplikácia (Apache, PHP 8.1, MariaDB) 1
SSH SSH bezpečné pripojenie na vzdialený počítač cez príkazový riadok 1
SFTP SFTP prenos súborov cez to isté bezpečné pripojenie; VS Code ním kopíruje súbory na sigma.tuke.sk pri každom uložení 1
VPN VPN tunel do školskej siete; bez neho sa na sigma.tuke.sk z domu nedostaneš 1
Git Git nástroj, ktorý sleduje zmeny v súboroch 1
GitHub GitHub web, kam sa zmeny z Gitu posielajú a kde sa odovzdávajú zadania 1
repozitár (repo) repository (repo) priečinok projektu spravovaný Gitom 1
commit commit uložená verzia zmien s popisom 1
push push odoslanie commitov na GitHub 1
clone clone stiahnutie repozitára z GitHubu do Kubeflow 1
2FA two-factor authentication pri prihlásení okrem hesla aj kód z mobilu 1
zadanie (Classroom 50) assignment úloha od učiteľa; po prijatí dostaneš vlastný repozitár 1
Adminer Adminer práca s databázou v prehliadači; jeden PHP súbor v tvojom public_html 1
MariaDB MariaDB databázový server na sigma.tuke.sk, kompatibilný s MySQL 1
semestrálne zadanie semester project tvoja aplikácia, ktorá rastie celý semester v priečinku it/projekt 1
vzorový projekt sample project aplikácia z prednášok (recepty), z ktorej prenášaš postup do svojho projektu 2
míľnik milestone týždeň, v ktorom musí aplikácia fungovať v danom rozsahu; každý míľnik sa obhajuje 1
obhajoba defence rozhovor pri tvojom počítači: vysvetli, uprav, zdôvodni 1
live coding live coding úprava kódu naživo pred učiteľom 1
dátový model data model zoznam tabuliek a vzťahov medzi nimi 2
entita entity vec, o ktorej aplikácia ukladá údaje; v databáze jedna tabuľka 2
hlavná entita main entity tabuľka, okolo ktorej sa aplikácia točí; používateľ do nej pridáva a upravuje záznamy 2
číselník lookup table malá tabuľka s pevným zoznamom hodnôt, z ktorých sa vyberá 2
prepojka pivot table, junction table tabuľka, ktorá spája dve tabuľky vo vzťahu M:N 2
primárny kľúč primary key stĺpec id, ktorý jednoznačne určuje záznam 2
cudzí kľúč foreign key stĺpec s id záznamu z inej tabuľky 2
vzťah 1:N one-to-many jeden záznam patrí k mnohým; cudzí kľúč na strane N 2
vzťah M:N many-to-many mnoho k mnohým; potrebuje prepojku 2
ON DELETE ON DELETE pravidlo, čo sa stane so závislými záznamami pri mazaní: RESTRICT, CASCADE, SET NULL 2
atribút attribute stĺpec tabuľky; atribút prepojky je údaj o dvojici, napr. množstvo 2
README README súbor README.md v repozitári s popisom projektu; v cv01 je v ňom tvoja téma a dátový model 2
Composer Composer nástroj, ktorý sťahuje knižnice a vyrába autoloader; riadi sa súborom composer.json 3
vendor vendor priečinok s cudzím kódom (knižnice, od týždňa 6 Twig) a s autoloaderom; vyrobí ho composer install alebo composer require; nejde do repository, na sigma ide 3
autoloader autoloader súbor vendor/autoload.php od Composeru; index.php ho načíta a odvtedy PHP pri neznámej triede z jej názvu zloží cestu k súboru a načíta ho – naše App\… zo src/ aj Twig\… z vendor/ 3
namespace namespace adresa triedy, napr. App\Model; plné meno triedy je App\Model\RecipeModel 3
use use riadok na začiatku súboru, ktorým povieš, ktorú triedu z ktorej adresy používaš 3
PSR-4 PSR-4 dohoda: namespace = priečinok, meno triedy = názov súboru; App\ je src/ 3
interface interface zoznam metód, ktoré trieda musí mať; bez kódu 3
abstraktná trieda abstract class trieda len na dedenie, new sa na ňu nedá použiť 3
singleton singleton trieda, ktorá dovolí jediný objekt; u nás Database s jedným PDO 3
DSN DSN (data source name) reťazec, kam sa pripojiť: mysql:host=localhost;dbname=...;charset=utf8mb4 3
schema.sql schema.sql súbor s CREATE TABLE pre všetky tabuľky; dá sa spustiť opakovane 3
seed.sql seed.sql súbor s testovacími dátami (INSERT) 3
.gitignore .gitignore zoznam súborov, ktoré Git do repository nedáva: config.php, vendor/ 3
.htaccess .htaccess súbor s nastavením servera Apache pre jeden priečinok; u nás chráni kód a heslo 3
cp cp príkaz na kopírovanie súborov a priečinkov: cp -r cv02/src cv03/ skopíruje priečinok aj s obsahom 3
obhajoba: vysvetli code walkthrough vysvetlenie vlastného kódu riadok po riadku 3
obhajoba: uprav live coding malá zmena kódu naživo pred učiteľom 3
obhajoba: zdôvodni design decision odpoveď, prečo je riešenie navrhnuté tak a nie inak 3
Definition of Done Definition of Done zoznam podmienok, kedy je úloha hotová; na konci každého týždňa 3
HTTP HTTP pravidlá rozhovoru prehliadača a servera: požiadavka a odpoveď 4
požiadavka request text, ktorý prehliadač pošle serveru: metóda, cesta, hlavičky 4
odpoveď response text, ktorý server vráti: stavový kód, hlavičky, telo (HTML) 4
metóda požiadavky HTTP method druh požiadavky: GET (adresa, odkaz), POST (formulár), PUT, DELETE 4
cesta path časť adresy za názvom servera; v PHP $_SERVER['REQUEST_URI'] 4
stavový kód status code číslo v odpovedi: 200 nájdené, 404 nenájdené, 500 chyba PHP 4
direktíva directive jeden riadok v .htaccess: názov a parametre 4
mod_rewrite mod_rewrite modul Apache na prepisovanie ciest; RewriteEngine On, RewriteCond, RewriteRule 4
front controller front controller jediný PHP súbor, ktorý Apache spúšťa: index.php 4
prefix prefix spoločný začiatok všetkých adries aplikácie: /student/meno.priezvisko/it/cv03 4
relatívna adresa relative address cesta bez prefixu: /recipes/3; s ňou pracuje Router 4
Router Router trieda App\Router: zoznam route, metódy get() a dispatch() 4
route route jeden záznam v Routeri: relatívna adresa a kto ju obsluhuje (od 5. týždňa controller a metóda) 4
parameter route route parameter {id} v adrese route; Router ho nahradí regulárnym výrazom (\d+) a hodnotu pošle funkcii 4
regulárny výraz regular expression vzor pre text: \d+ je jedna alebo viac cifier; preg_match() ho porovná s textom 4
view view súbor vo views/ s HTML jednej stránky (do týždňa 5 .php, od týždňa 6 šablóna .twig); dostane dáta, nič nepočíta 4
layout layout views/layout.php (od týždňa 6 layout.twig): spoločný HTML rám, do ktorého sa vkladá obsah view 4
e(), url(), view() helpers pomocné funkcie v src/helpers.php: ošetrenie textu, odkaz s prefixom, výroba HTML stránky 4
ob_start() output buffering zachytávanie výstupu PHP do reťazca namiesto do prehliadača; ob_get_clean() ho vráti 4
composer.json “files” autoload files zoznam súborov, ktoré vendor/autoload.php načíta pri každej požiadavke; u nás src/helpers.php 4
MVC MVC (Model–View–Controller) rozdelenie kódu na modely (src/Model/), views (views/) a controllery (src/Controller/) 5
controller controller náš kód: trieda v src/Controller/, jedna na tabuľku; pre každú adresu jedna metóda, ktorá dostane Request a vráti Response 5
metóda controllera controller method / action verejná metóda controllera pre jednu adresu; dohoda: index zoznam, show jeden záznam 5
BaseController BaseController náš kód: rodič controllerov s metódami render() (z view vyrobí Response) a notFound() (stránka 404) 5
Request Request náš kód: trieda App\Http\Request, požiadavka ako objekt; method(), prefix(), path(), query(); vzniká cez Request::fromGlobals() 5
Response Response náš kód: trieda App\Http\Response, odpoveď ako objekt: stavový kód, hlavičky, telo; send() ju pošle 5
hlavička odpovede response header riadok odpovede pred telom, napr. Content-Type: text/html; charset=UTF-8; v PHP ju pošle header() 5
$_SERVER, $_GET superglobals polia z PHP, ktoré Apache naplní pri každej požiadavke: cesta, HTTP metóda, hodnoty za ? 5
parameter adresy query parameter dvojica názov=hodnota za ? v adrese: ?q=tofu; v PHP $_GET['q'], u nás $request->query('q') 5
:: scope resolution operator zápis „z triedy vezmi“ bez objektu (PHP): Database::getInstance(), PDO::FETCH_COLUMN, Trieda::class 5
::class ::class konštanta každej triedy (PHP) s celým názvom triedy ako text: CategoryController::class je 'App\Controller\CategoryController' 5
new $class() dynamic instantiation vytvorenie objektu triedy, ktorej názov je v premennej (PHP); takto Router vytvára controller 5
LIKE LIKE operátor SQL na porovnanie textu so vzorom; % je ľubovoľný text: title LIKE '%tofu%' 5
prepared statement prepared statement dotaz SQL s parametrami :q, ktoré PDO doplní až v execute(); text od používateľa sa nikdy nelepí do SQL (prepare() + execute()) 5
statická metóda static method metóda, ktorá patrí triede, nie objektu; volá sa Trieda::metoda(): Request::fromGlobals(), Response::redirect() 5
Twig Twig knižnica tried PHP na šablóny (cudzí kód vo vendor/twig/); zo šablóny .twig a hodnôt z controllera vyrobí HTML 6
template template súbor views/*.twig: HTML so značkami {{ }}, {% %}, {# #} na miestach hodnôt; nevidí databázu ani $_SERVER 6
filter filter úprava hodnoty v šablóne za zvislou čiarou: rows|length, row|keys, v|nl2br, old.title|default(''), row.created_at|date('d. m. Y') 6
extends, block template inheritance {% extends "layout.twig" %} a {% block content %}: stránka dedí rám z layout.twig a prepíše len blok 6
autoescape autoescape Twig každé {{ }} prevedie cez htmlspecialchars(); e() v šablónach netreba 6
Twig Environment Twig hlavná trieda Twigu; vo view() dostane loader (objekt, ktorý číta šablóny z views/) a nastavenia (cache, strict_variables); render('list.twig', $data) vráti HTML 6
knižnica library cudzí kód (triedy, funkcie), ktorý sa do projektu stiahne hotový namiesto písania; u nás Twig vo vendor/twig/ 6
black box black box kus kódu, od ktorého vieme len vstup a výstup; vnútro netreba poznať: PDO, Composer, Twig 6
XSS XSS (cross-site scripting) chyba, keď aplikácia vypíše text od používateľa neošetrený a prehliadač ho spustí ako HTML/JavaScript; Twig jej bráni automatickým ošetrením 6
pretypovanie type cast (int) '4' → 4: prevod textu z formulára na číslo v controlleri; 'abc' dá 0 6
composer require composer require príkaz Composeru: stiahne knižnicu z packagist.org do vendor/, zapíše ju do composer.json a composer.lock, prepíše autoloader 6
packagist.org Packagist verejný register balíkov PHP; názov balíka je vlastník/balík: twig/twig 6
composer.lock lock file presné verzie stiahnutých knižníc; ide na GitHub, composer install podľa neho vyrobí rovnaký vendor/ 6
HTTP metóda POST POST požiadavka „posielam dáta“: dáta sú v tele požiadavky, nie v adrese; pošle ju formulár s method="post" 6
telo požiadavky request body časť požiadavky za prázdnym riadkom; pri formulári title=Hummus&servings=4…; PHP z neho naplní $_POST 6
$_POST $_POST pole z PHP s hodnotami z tela požiadavky POST, všetko ako text; u nás $request->post('title') 6
route POST POST route $router->post('/recipes', [...]): route pre HTTP metódu POST; tá istá adresa môže mať aj GET route 6
create / store create / store dohoda pre názvy metód controllera: create zobrazí prázdny formulár (GET), store uloží dáta (POST) 6
formulár form <form method="post" action="…"> s poľami <input name>, <select>, <textarea> a <button type="submit">; name je kľúč v $_POST 6
<select> select pole formulára s možnosťami <option value="id">názov</option>; u nás zo záznamov číselníka 6
required required atribút poľa: prehliadač neodošle prázdne pole; kontrola v prehliadači sa dá obísť, preto kontroluje aj controller 6
INSERT INSERT príkaz SQL na vloženie riadku: INSERT INTO recipes (title, …) VALUES (:title, …); hodnoty cez parametre 6
lastInsertId() lastInsertId() metóda PDO: id, ktoré databáza pridelila naposledy vloženému riadku 6
presmerovanie redirect odpoveď so stavovým kódom 302 a hlavičkou Location; prehliadač sám pošle GET na novú adresu; u nás Response::redirect() 6
POST → redirect → GET PRG pattern po uložení dát z formulára vždy presmerovanie, aby F5 neposlal POST znova 6
stateless stateless HTTP si medzi požiadavkami nič nepamätá; každá požiadavka začína od začiatku index.php 7
cookie cookie dvojica meno=hodnota, ktorú server pošle v hlavičke Set-Cookie a prehliadač ju vracia v hlavičke Cookie pri každej požiadavke na tú doménu 7
PHPSESSID PHPSESSID meno cookie so session id; hodnota je náhodný text, podľa ktorého PHP nájde súbor session 7
session session pole $_SESSION, ktoré PHP uloží do súboru na serveri a pri ďalšej požiadavke toho istého prehliadača vráti naplnené 7
session_start() session_start() funkcia PHP: podľa cookie načíta súbor session do $_SESSION; v index.php pred Request::fromGlobals() 7
$_SESSION $_SESSION pole PHP, ktorého obsah prežije medzi požiadavkami; u nás user_id, flash, count 7
hash hesla password hash 60 znakov $2y$10$… vyrobených z hesla; heslo sa z neho nedá vypočítať, dá sa len overiť 7
password_hash() password_hash() funkcia PHP: z hesla vyrobí hash (bcrypt, náhodná soľ); výsledok ide do tabuľky users 7
password_verify() password_verify() funkcia PHP: overí heslo z formulára proti hashu z tabuľky; vráti true/false 7
soľ salt náhodný text, ktorý password_hash() pridá k heslu; preto má to isté heslo zakaždým iný hash 7
UNIQUE UNIQUE pravidlo stĺpca v SQL: hodnota môže byť v tabuľke najviac raz; porušenie = chyba 23000 7
registrácia registration založenie účtu: POST /register, password_hash(), INSERT do users 7
prihlásenie login overenie hesla (password_verify()) a zápis user_id do session: Auth::login() 7
odhlásenie logout zmazanie user_id zo session: Auth::logout(); v aplikácii len cez POST (tlačidlo) 7
Auth Auth naša trieda so static metódami login(), logout(), check(), id(), user(); jediné miesto, ktoré číta a píše $_SESSION['user_id'] 7
addGlobal() addGlobal() metóda Twigu: premenná dostupná v každom template bez poľa pre render(); u nás user a flash 7
flash správa flash message text uložený do session pred presmerovaním, zobrazený na najbližšej stránke a potom zmazaný 7
chránená stránka protected page metóda controllera, ktorá bez prihlásenia vráti redirect('/login'): if (!Auth::check()) 7
anonymné okno incognito window okno prehliadača s vlastnými cookies (Ctrl+Shift+N); začína bez session, hodí sa na test neprihláseného 7
autorizácia authorization rozhodnutie, čo smie prihlásený user urobiť; v controlleri porovnanie usera s autorom záznamu 8
oprávnenie permission právo urobiť akciu (upraviť, zmazať); má ho autor záznamu alebo admin 8
rola role stĺpec users.role s hodnotou ‘user’ alebo ‘admin’; admin má oprávnenie na všetko 8
403 Forbidden 403 Forbidden stavový kód HTTP: prihlásený user nemá na akciu oprávnenie (neprihlásený dostane redirect na /login) 8
requireLogin() requireLogin() metóda v BaseController: vráti null (prihlásený) alebo redirect na /login; volá sa na začiatku chránených metód 8
authorize() authorize() metóda v BaseController: vráti null (autor alebo admin) alebo stránku 403 8
CSRF CSRF Cross-Site Request Forgery: cudzia stránka odošle request s cookie prihláseného usera 8
CSRF token CSRF token náhodný text v session a v skrytom inpute formulára; Router ho pri POST porovná, inak 403 8
session fixation session fixation útok s podstrčeným id session; obrana je session_regenerate_id() pri prihlásení 8
session_regenerate_id() session_regenerate_id() funkcia PHP: nové id session; parameter true zmaže starý súbor 8
validácia validation kontrola hodnôt z formulára; chyby v poli $errors s kľúčom podľa políčka 8
same-origin policy same-origin policy pravidlo prehliadača: stránka z iného origin nemôže čítať obsah našej stránky 8
path (cookie) path (cookie) vlastnosť cookie: pre ktoré adresy ju prehliadač posiela; prefix aplikácie oddelí session 8
httponly httponly vlastnosť cookie: JavaScript ju neprečíta 8
samesite samesite vlastnosť cookie: Lax = nepošle sa s POST z iného site 8
foreign key foreign key stĺpec, ktorý ukazuje na id v inej tabuľke (recipes.user_id → users.id); ON DELETE RESTRICT bráni zmazaniu 8

The table of terms for the whole course. New terms are added every week; by the end of the semester it will be complete. Weekly pages do not repeat the terms, they only link to this table.

Term (SK) English Explanation Wk
Kubeflow Kubeflow the university cloud where our VS Code runs; opens in the browser 1
VS Code VS Code the editor we write code in 1
sigma sigma the server your application runs on (Apache, PHP 8.1, MariaDB) 1
SSH SSH a secure connection to a remote computer through the command line 1
SFTP SFTP file transfer over the same secure connection; VS Code uses it to copy files to sigma.tuke.sk on every save 1
VPN VPN a tunnel into the university network; without it you cannot reach sigma.tuke.sk from home 1
Git Git a tool that tracks changes in files 1
GitHub GitHub the website Git changes are sent to and where assignments are submitted 1
repozitár (repo) repository (repo) a project folder managed by Git 1
commit commit a saved version of changes with a description 1
push push sending commits to GitHub 1
clone clone downloading a repository from GitHub into Kubeflow 1
2FA two-factor authentication at sign-in a code from your phone in addition to the password 1
zadanie (Classroom 50) assignment a task from the teacher; accepting it gives you your own repository 1
Adminer Adminer database work in the browser; a single PHP file in your public_html 1
MariaDB MariaDB the database server on sigma.tuke.sk, compatible with MySQL 1
semestrálne zadanie semester project your application, which grows all semester in the folder it/projekt 1
vzorový projekt sample project the application from the lectures (recipes) from which you transfer the procedure to your project 2
míľnik milestone a week in which the application must work to a given extent; every milestone is defended 1
obhajoba defence a conversation at your computer: explain, modify, justify 1
live coding live coding changing code live in front of the teacher 1
dátový model data model the list of tables and the relationships between them 2
entita entity a thing the application stores data about; one table in the database 2
hlavná entita main entity the table the application revolves around; the user adds and edits its records 2
číselník lookup table a small table with a fixed list of values to choose from 2
prepojka pivot table, junction table a table that connects two tables in an M:N relationship 2
primárny kľúč primary key the column id that identifies a record uniquely 2
cudzí kľúč foreign key a column holding the id of a record from another table 2
vzťah 1:N one-to-many one record belongs to many; the foreign key is on the N side 2
vzťah M:N many-to-many many to many; needs a pivot table 2
ON DELETE ON DELETE the rule for dependent records on delete: RESTRICT, CASCADE, SET NULL 2
atribút attribute a column of a table; a pivot attribute is data about the pair, e.g. amount 2
README README the file README.md in the repository describing the project; in cv01 it holds your topic and data model 2
Composer Composer the tool that downloads libraries and generates the autoloader; driven by composer.json 3
vendor vendor the folder with third-party code (libraries, from week 6 Twig) and the autoloader; created by composer install or composer require; not in the repository, goes to sigma 3
autoloader autoloader the file vendor/autoload.php from Composer; index.php loads it and from then on, at an unknown class, PHP builds the file path from the class name and loads it – our App\… from src/ and Twig\… from vendor/ 3
namespace namespace the address of a class, e.g. App\Model; the full class name is App\Model\RecipeModel 3
use use a line at the top of a file saying which class from which address you use 3
PSR-4 PSR-4 the convention: namespace = folder, class name = file name; App\ is src/ 3
interface interface a list of methods a class must have; no code 3
abstraktná trieda abstract class a class meant only to be inherited; new cannot be used on it 3
singleton singleton a class that allows only one object; here Database with one PDO 3
DSN DSN (data source name) the string saying where to connect: mysql:host=localhost;dbname=...;charset=utf8mb4 3
schema.sql schema.sql the file with CREATE TABLE for all tables; can be run repeatedly 3
seed.sql seed.sql the file with test data (INSERT) 3
.gitignore .gitignore the list of files Git keeps out of the repository: config.php, vendor/ 3
.htaccess .htaccess the Apache server settings file for one folder; here it protects the code and the password 3
cp cp command for copying files and folders: cp -r cv02/src cv03/ copies a folder with its content 3
obhajoba: vysvetli code walkthrough explaining your own code line by line 3
obhajoba: uprav live coding a small code change made live in front of the teacher 3
obhajoba: zdôvodni design decision the answer why the solution is designed this way and not otherwise 3
Definition of Done Definition of Done the list of conditions for a task to be done; at the end of every week 3
HTTP HTTP the rules of the browser–server conversation: request and response 4
požiadavka request the text the browser sends to the server: method, path, headers 4
odpoveď response the text the server returns: status code, headers, body (HTML) 4
metóda požiadavky HTTP method kind of request: GET (address, link), POST (form), PUT, DELETE 4
cesta path the part of the address after the server name; in PHP $_SERVER['REQUEST_URI'] 4
stavový kód status code number in the response: 200 found, 404 not found, 500 PHP error 4
direktíva directive one line in .htaccess: name and parameters 4
mod_rewrite mod_rewrite Apache module for rewriting paths; RewriteEngine On, RewriteCond, RewriteRule 4
front controller front controller the only PHP file Apache runs: index.php 4
prefix prefix common start of all addresses of the application: /student/meno.priezvisko/it/cv03 4
relatívna adresa relative address path without the prefix: /recipes/3; the Router works with it 4
Router Router the class App\Router: list of routes, methods get() and dispatch() 4
route route one entry in the Router: relative address and who handles it (from week 5 a controller and method) 4
parameter route route parameter {id} in a route address; the Router replaces it with the regular expression (\d+) and passes the value to the function 4
regulárny výraz regular expression pattern for text: \d+ is one or more digits; preg_match() compares it with text 4
view view a file in views/ with the HTML of one page (until week 5 .php, from week 6 a .twig template); receives data, computes nothing 4
layout layout views/layout.php (from week 6 layout.twig): shared HTML frame into which the view content is inserted 4
e(), url(), view() helpers helper functions in src/helpers.php: text escaping, link with prefix, building the page HTML 4
ob_start() output buffering capturing PHP output into a string instead of the browser; ob_get_clean() returns it 4
composer.json “files” autoload files list of files vendor/autoload.php loads on every request; here src/helpers.php 4
MVC MVC (Model–View–Controller) splitting the code into models (src/Model/), views (views/) and controllers (src/Controller/) 5
controller controller our code: a class in src/Controller/, one per table; for every address one method that receives a Request and returns a Response 5
metóda controllera controller method / action public controller method for one address; convention: index list, show one record 5
BaseController BaseController our code: parent of controllers with the methods render() (builds a Response from a view) and notFound() (404 page) 5
Request Request our code: the class App\Http\Request, the request as an object; method(), prefix(), path(), query(); created by Request::fromGlobals() 5
Response Response our code: the class App\Http\Response, the response as an object: status code, headers, body; send() sends it 5
hlavička odpovede response header a response line before the body, e.g. Content-Type: text/html; charset=UTF-8; in PHP sent by header() 5
$_SERVER, $_GET superglobals PHP arrays Apache fills on every request: path, HTTP method, values after ? 5
parameter adresy query parameter a name=value pair after ? in the address: ?q=tofu; in PHP $_GET['q'], here $request->query('q') 5
:: scope resolution operator “take from the class” without an object (PHP): Database::getInstance(), PDO::FETCH_COLUMN, Class::class 5
::class ::class a constant of every class (PHP) with the full class name as text: CategoryController::class is 'App\Controller\CategoryController' 5
new $class() dynamic instantiation creating an object of the class whose name is in a variable (PHP); this is how the Router creates a controller 5
LIKE LIKE SQL operator comparing text with a pattern; % is any text: title LIKE '%tofu%' 5
prepared statement prepared statement an SQL query with parameters :q that PDO fills in only in execute(); text from the user is never glued into SQL (prepare() + execute()) 5
statická metóda static method a method that belongs to the class, not to an object; called as Class::method(): Request::fromGlobals(), Response::redirect() 5
Twig Twig a library of PHP classes for templates (foreign code in vendor/twig/); builds HTML from a .twig template and values from the controller 6
template template a file views/*.twig: HTML with the tags {{ }}, {% %}, {# #} in the places of values; sees neither the database nor $_SERVER 6
filter filter an adjustment of a value in a template after a vertical bar: rows|length, row|keys, v|nl2br, old.title|default(''), row.created_at|date('d. m. Y') 6
extends, block template inheritance {% extends "layout.twig" %} and {% block content %}: a page inherits the frame from layout.twig and overrides only the block 6
autoescape autoescape Twig passes every {{ }} through htmlspecialchars(); e() is not needed in templates 6
Twig Environment Twig the main class of Twig; in view() it gets a loader (an object that reads templates from views/) and settings (cache, strict_variables); render('list.twig', $data) returns HTML 6
knižnica library foreign code (classes, functions) downloaded into the project ready-made instead of being written; here Twig in vendor/twig/ 6
black box black box a piece of code of which we know only the input and the output; the inside need not be known: PDO, Composer, Twig 6
XSS XSS (cross-site scripting) the bug when an application prints text from the user unescaped and the browser runs it as HTML/JavaScript; Twig prevents it by automatic escaping 6
pretypovanie type cast (int) '4' → 4: converting text from a form to a number in the controller; 'abc' gives 0 6
composer require composer require a Composer command: downloads a library from packagist.org into vendor/, writes it into composer.json and composer.lock, rewrites the autoloader 6
packagist.org Packagist the public registry of PHP packages; a package name is owner/package: twig/twig 6
composer.lock lock file the exact versions of the downloaded libraries; goes to GitHub, composer install makes the same vendor/ from it 6
HTTP metóda POST POST the request “I am sending data”: the data is in the request body, not in the address; a form with method="post" sends it 6
telo požiadavky request body the part of a request after the empty line; for a form title=Hummus&servings=4…; PHP fills $_POST from it 6
$_POST $_POST an array from PHP with the values from the body of a POST request, all as text; here $request->post('title') 6
route POST POST route $router->post('/recipes', [...]): a route for the HTTP method POST; the same address can have a GET route too 6
create / store create / store a convention for controller method names: create shows the empty form (GET), store saves the data (POST) 6
formulár form <form method="post" action="…"> with the fields <input name>, <select>, <textarea> and <button type="submit">; name is the key in $_POST 6
<select> select a form field with the options <option value="id">name</option>; here from the records of a lookup table 6
required required a field attribute: the browser does not submit an empty field; the browser check can be bypassed, so the controller checks too 6
INSERT INSERT the SQL command for inserting a row: INSERT INTO recipes (title, …) VALUES (:title, …); values through parameters 6
lastInsertId() lastInsertId() a PDO method: the id the database assigned to the last inserted row 6
presmerovanie redirect a response with the status code 302 and the header Location; the browser itself sends GET to the new address; here Response::redirect() 6
POST → redirect → GET PRG pattern after saving form data always a redirect, so that F5 does not send the POST again 6
stateless stateless HTTP remembers nothing between requests; every request starts from the beginning of index.php 7
cookie cookie a name=value pair the server sends in the header Set-Cookie and the browser returns in the header Cookie at every request to that domain 7
PHPSESSID PHPSESSID the name of the cookie with the session id; the value is a random text by which PHP finds the session file 7
session session the array $_SESSION, which PHP stores in a file on the server and returns filled at the next request of the same browser 7
session_start() session_start() a PHP function: loads the session file into $_SESSION according to the cookie; in index.php before Request::fromGlobals() 7
$_SESSION $_SESSION a PHP array whose content survives between requests; here user_id, flash, count 7
hash hesla password hash 60 characters $2y$10$… made from the password; the password cannot be computed from it, only verified 7
password_hash() password_hash() a PHP function: makes a hash from a password (bcrypt, random salt); the result goes into the table users 7
password_verify() password_verify() a PHP function: verifies the password from the form against the hash from the table; returns true/false 7
soľ salt a random text that password_hash() adds to the password; that is why the same password has a different hash every time 7
UNIQUE UNIQUE a column rule in SQL: the value may be in the table at most once; a violation = error 23000 7
registrácia registration creating an account: POST /register, password_hash(), INSERT into users 7
prihlásenie login password check (password_verify()) and writing user_id into the session: Auth::login() 7
odhlásenie logout deleting user_id from the session: Auth::logout(); in the application only through POST (a button) 7
Auth Auth our class with the static methods login(), logout(), check(), id(), user(); the only place that reads and writes $_SESSION['user_id'] 7
addGlobal() addGlobal() a Twig method: a variable available in every template without the array for render(); here user and flash 7
flash správa flash message a text stored in the session before a redirect, shown on the next page and then deleted 7
chránená stránka protected page a controller method that returns redirect('/login') without login: if (!Auth::check()) 7
anonymné okno incognito window a browser window with its own cookies (Ctrl+Shift+N); it starts without a session, good for testing a visitor without login 7
autorizácia authorization deciding what a logged-in user may do; in the controller, comparing the user with the record’s author 8
oprávnenie permission the right to do an action (edit, delete); the record’s author or an admin has it 8
rola role the column users.role with value ‘user’ or ‘admin’; an admin has permission for everything 8
403 Forbidden 403 Forbidden HTTP status code: a logged-in user has no permission for the action (a logged-out one gets a redirect to /login) 8
requireLogin() requireLogin() a method in BaseController: returns null (logged in) or a redirect to /login; called at the start of protected methods 8
authorize() authorize() a method in BaseController: returns null (author or admin) or the 403 page 8
CSRF CSRF Cross-Site Request Forgery: a foreign page sends a request with the logged-in user’s cookie 8
CSRF token CSRF token a random text in the session and in a form’s hidden input; the Router compares it at POST, otherwise 403 8
session fixation session fixation an attack with a planted session id; the defence is session_regenerate_id() at login 8
session_regenerate_id() session_regenerate_id() a PHP function: a new session id; the parameter true deletes the old file 8
validácia validation checking values from a form; errors in the array $errors keyed by field name 8
same-origin policy same-origin policy a browser rule: a page from another origin cannot read the content of our page 8
path (cookie) path (cookie) a cookie property: which addresses the browser sends it to; the application prefix separates sessions 8
httponly httponly a cookie property: JavaScript cannot read it 8
samesite samesite a cookie property: Lax = not sent with a POST from another site 8
foreign key foreign key a column pointing to id in another table (recipes.user_id → users.id); ON DELETE RESTRICT blocks deletion 8