Skip to content

Lib Layer – API Reference

Namespace: Alxarafe\Lib

Utility libraries providing cross-cutting concerns: authentication, translations, messaging, routing, and HTTP helpers.


Auth (abstract)

Source: [Auth.php](file:///home/rsanjose/Desarrollo/Alxarafe/alxarafe/src/Core/Lib/Auth.php)

Cookie-based authentication with JWT support. Manages user sessions via secure HTTP-only cookies.

Properties

PropertyTypeDescription
$user?Modules\Admin\Model\UserCurrently authenticated user (static)

Methods

MethodSignatureDescription
isLogged()static isLogged(): boolChecks if user is authenticated via cookie token.
login()static login(string $username, string $password): boolAuthenticates with username and password. Sets cookie on success.
logout()static logout(): voidClears authentication cookies and resets $user.
setLoginCookie()static setLoginCookie($userId): voidCreates auth cookies for a specific user ID.
getSecurityKey()static getSecurityKey(): ?stringReturns JWT secret key from config (auto-generates if missing).

Example

php
use Alxarafe\Lib\Auth;

if (Auth::isLogged()) {
    echo "Hello, " . Auth::$user->name;
} else {
    Auth::login('admin', 'password123');
}

Trans (abstract)

Source: [Trans.php](file:///home/rsanjose/Desarrollo/Alxarafe/alxarafe/src/Core/Lib/Trans.php)

Internationalization layer wrapping Symfony Translator with YAML file loading. Supports 18 languages and hierarchical fallback (e.g., es_AResen).

Constants

ConstantValueDescription
FALLBACK_LANG'en'Default language

Methods

MethodSignatureDescription
_()static _(string $message, array $parameters = [], ?string $locale = null): stringTranslate a key. Parameters use %name% syntax.
trans()static trans($message, array $parameters = [], $locale = null): stringAlias for _().
initialize()static initialize(): boolInitializes the Symfony Translator singleton.
setLang()static setLang($lang): voidSets active language and loads YAML files from all modules.
getLocale()static getLocale(): stringReturns current locale code.
wasSet()static wasSet(): boolReturns true if setLang() has been called.
getAvailableLanguages()static getAvailableLanguages(): arrayReturns [code => name] from DB or YAML scan.
getAvailableLanguagesWithFlags()static getAvailableLanguagesWithFlags(): arrayReturns [code => ['name', 'flag']] for UI rendering.
getMissingStrings()static getMissingStrings(): arrayReturns untranslated keys (debug use).
getAll()static getAll(): arrayReturns all loaded translations.

Translation File Loading Order

  1. Core framework: ALX_PATH/src/Lang/{lang}.yaml
  2. Application: APP_PATH/Lang/{lang}.yaml
  3. Each module: Modules/{Module}/Lang/{lang}.yaml
  4. Active module override (from $_GET['module'])

Example

php
use Alxarafe\Lib\Trans;

Trans::setLang('es');
echo Trans::_('welcome_message', ['name' => 'Juan']);
// Output: "Bienvenido, Juan" (from es.yaml)

Messages (abstract)

Source: [Messages.php](file:///home/rsanjose/Desarrollo/Alxarafe/alxarafe/src/Core/Lib/Messages.php)

Flash message system. Messages are accumulated during the request and rendered once via ViewController::afterAction().

Methods

MethodSignatureDescription
addMessage()static addMessage($message): voidAdd success message (green alert).
addAdvice()static addAdvice($message): voidAdd warning message (yellow alert).
addError()static addError($message): voidAdd error message (red alert).
getMessages()static getMessages(): arrayReturns and clears all messages as `[['type' => 'success

Functions (abstract)

Source: [Functions.php](file:///home/rsanjose/Desarrollo/Alxarafe/alxarafe/src/Core/Lib/Functions.php)

HTTP utilities, URL helpers, file operations, and theme discovery.

Methods

MethodSignatureDescription
getUrl()static getUrl(): stringAuto-detects the application base URL (protocol, host, path).
getIfIsset()static getIfIsset($postVar, $defaultValue): mixedReturns POST value or default.
defineIfNotDefined()static defineIfNotDefined(string $name, $value): voidDefines a constant only if not already defined.
htmlAttributes()static htmlAttributes(array $attributes): stringConverts ['key' => 'value'] to HTML attribute string.
getThemes()static getThemes(): arrayDiscovers installed themes from filesystem.
httpRedirect()static httpRedirect(string $url): voidSends HTTP redirect (throws exception in test mode).
exec()static exec(string $command): voidExecutes shell command with error handling.
recursiveRemove()static recursiveRemove(string $dir, bool $removeRoot = false): intRecursively deletes directory contents. Returns count.

Routes (abstract)

Source: [Routes.php](file:///home/rsanjose/Desarrollo/Alxarafe/alxarafe/src/Core/Lib/Routes.php)

Auto-discovers controllers, models, migrations, and seeders by scanning module directories.

Methods

MethodSignatureDescription
getAllRoutes()static getAllRoutes(): arrayReturns cached route map: ['Controller' => [...], 'Api' => [...], 'Model' => [...], 'Migrations' => [...], 'Seeders' => [...]].
addRoutes()static addRoutes(array $routes): voidAdds custom search paths (clears cache).
invalidateCache()static invalidateCache(): voidClears the route cache. Call after module activation changes.

Search Paths

NamespacePath
Modules\APP_PATH/Modules/
Modules\ALX_PATH/src/Modules/

Router (abstract)

Source: [Router.php](file:///home/rsanjose/Desarrollo/Alxarafe/alxarafe/src/Core/Lib/Router.php)

Friendly URL matching and generation. Provides named routes as an alternative to query string parameters.

Methods

MethodSignatureDescription
match()static match(string $uri): ?arrayMatches request URI to a registered route. Returns ['module', 'controller', 'action', 'params', 'name'] or null.
generate()static generate(string $module, string $controller, string $action, array $params = []): ?stringGenerates a friendly URL for a given route.