Skip to content

Reference – Konvence a Funkce

Konfigurace

V config/data.yaml definujte adresář pro kontrolery dotazů:

dataDir: /app/DATA
dataRemoteUrl:

publicEndpoints:
  - CookiesBar/updateLog
  - Form/submit

Konvence Pojmenování Endpointů

Všechny endpointy mají tvar: {Entity}/{Action}.php

Pojmenování určuje účel a bezpečnost endpointu:

Formát Typ Volání z Příklady
Entity/Action.php (malé) Backend-specific Admin panel, PHP News/activate, Pages/info, Cubes/adminLoadCubes
Entity/Action.php (VELKÉ) CRUD Standard Admin panel, PHP News/List, Pages/Create, Cubes/Update, Admins/Delete
Entity/_action.php (prefix_) Frontend JavaScript (fetch), tagy v šablonách News/_latestThree, Pages/_pages, Cubes/_cubes

CRUD Standard (PascalCase)

Tyto operace musí existovat v každé entitě (pokud má admin panel):

Entity/List.php       ← POST, vrací seznam včetně filtrace do view
Entity/Create.php     ← POST, formulář pro vytvoření
Entity/Edit.php       ← GET, formulář pro úpravu
Entity/Update.php     ← POST, uloží změny
Entity/Delete.php     ← GET, smaže záznam

Backend-Specific Akce (lowercase)

Logika specifická pro danou entitu, volají se z adminu:

News/activate.php           ← aktivace
News/duplicate.php          ← duplikování
News/info.php               ← metadata/detail
Pages/noindex.php           ← nastavení noindex
Cubes/content/changeLabel   ← úprava
Slugs/checkDuplicity.php    ← validace

Frontend-Specific (_lowercase)

Custom logika pro frontend, volají se z JS nebo tagů v šablonách:

News/_latestThree.php       ← poslední tři články
Pages/_pages.php            ← struktura stránek
Cubes/_cubes.php            ← krychle obsahu
Menus/_getChildren.php      ← děti v menu
I18n/_translate.php         ← překlad

Funkce a Metody

Data\get($entryPoint): string

GET call to data endpoint. Volání z PHP bez HTTP middleware.

/**
 * GET call to data endpoint
 *
 * Used for calling endpoints from PHP (admin panel, tags, commands).
 * Performs direct require() of endpoint file - does NOT go through HTTP middleware.
 * Parameters passed via $_get global variable.
 *
 * @param string $entryPoint Endpoint name (e.g., 'News/List' or 'News/_latestThree?limit=5')
 * @return string JSON response from endpoint
 * @throws Exception If endpoint file not found
 */
function get(string $entryPoint): string

Data\post($entryPoint, $data): string

POST call to data endpoint. Volání z PHP bez HTTP middleware.

/**
 * POST call to data endpoint
 *
 * Used for calling endpoints from PHP (admin panel, tags, commands).
 * Performs direct require() of endpoint file - does NOT go through HTTP middleware.
 * Parameters passed via $_post global variable.
 *
 * @param string $entryPoint Endpoint name (e.g., 'News/Create' or 'News/_latestThree')
 * @param array $data POST data to pass to endpoint
 * @return string JSON response from endpoint
 * @throws Exception If endpoint file not found
 */
function post(string $entryPoint, $data): string

Data\outputJson($output): JsonResponse|array

Output JSON response. Automaticky detekuje, zda je volání z HTTP nebo z PHP.

/**
 * Output JSON response (handles both HTTP and direct PHP calls)
 *
 * When called via HTTP (from JS fetch), returns PSR-7 JsonResponse.
 * When called directly from PHP, echoes JSON and returns empty array.
 *
 * @param mixed $output Data to encode as JSON
 * @return JsonResponse|array PSR-7 response or empty array
 */
function outputJson($output): JsonResponse|array

Data\isGetDataUrl(): bool

Checks if current request is a data endpoint call (detekce /getData v URL).

/**
 * Checks if current request is a data endpoint call
 * @return bool
 */
function isGetDataUrl(): bool

Data\param($key, $default): mixed

Get input parameter from endpoint (unified GET/POST access).

Priorita: $_post$_POST$_get$_GET

Pracuje s oběma typy volání:

  • HTTP requests: přistupuje k $_GET a $_POST
  • Interní volání: přistupuje k $_get a $_post vytvořeným v localGet()
/**
 * Get input parameter from endpoint (unified GET/POST access)
 *
 * Priority: $_post → $_POST → $_get → $_GET
 * Works with both direct require() calls and HTTP requests.
 *
 * @param string $key Parameter name
 * @param mixed $default Default value if not found
 * @return mixed Parameter value or default
 *
 * @example
 * $web = param('web');
 * $title = param('title', 'Untitled');
 */
function param(string $key, mixed $default = null): mixed

Data\params(): array

Get all input parameters combined (GET + POST).

Kombinuje všechny dostupné parametry s prioritou interních (_get, _post) před HTTP (GET, POST).

/**
 * Get all input parameters combined (GET + POST)
 *
 * Priority: $_post overrides $_POST, $_get overrides $_GET
 *
 * @return array All parameters from all sources
 *
 * @example
 * $data = params();
 */
function params(): array

Data\get_value($key, $_get, $_post, $default): mixed

Utility funkce pro čtení hodnot z GET/POST s fallback.

/**
 * Get value from GET or POST (POST has priority)
 *
 * @param string $key Parameter name
 * @param array $_get GET parameters
 * @param array $_post POST parameters
 * @param float|int|array|string $default Default value if key not found
 * @return mixed Value from POST, GET, or default
 */
function get_value(string $key, array $_get, array $_post, float|int|array|string $default = ''): mixed