menu_book Navigation menu

Classes & Enums

Pragma CMS follows a Context-Aware Static Architecture. Instead of complex dependency injection, we use State Objects to hold the current request data and Static Managers to interact with the database.

Core Context Objects (State)

These objects are globally available in your controllers and templates. They hold the "truth" of the current request.

$site (Site Object)

Represents the active website configuration.

  • Properties:
    • $site->id: (int) Unique site ID.
    • $site->url: (string) Fully qualified public URL.
    • $site->langCode: (string) Active 2-letter language code (e.g., 'en').
    • $site->settings: (array) All global settings defined in the Admin panel.
    • $site->activeTheme: (string) Name of the active theme folder.

$page (Page Object)

Represents the current rendered page context in the CMS, including metadata, layout structure, routing, content data, and view-level configuration.

Metadata

  • $page->section (mixed / enum)
    Current application section (e.g. Admin, Front, API). Defines global context behavior.
  • $page->langCode (string)
    Current language code used for localization (e.g. en, fr, de).
  • $page->metaTitle (string|null)
    SEO title of the page used in <title> and search engine results.
  • $page->metaDescription (string|null)
    SEO meta description for search engines and social previews.
  • $page->author (string|null)
    Optional author metadata for the page.

SEO / Open Graph / Social Media

  • $page->ogTitle (string|null)
    Open Graph title used for social sharing.
  • $page->ogDescription (string|null)
    Open Graph description for social previews.
  • $page->ogUrl (string|null)
    Canonical Open Graph URL of the page.
  • $page->ogType (string|null)
    Open Graph type (e.g. website, article).
  • $page->ogImage (string|null)
    Image URL used for Open Graph previews.
  • $page->twitterCard (string|null)
    Twitter card type (e.g. summary, summary_large_image).
  • $page->twitterTitle (string|null)
    Title used for Twitter sharing.
  • $page->twitterDescription (string|null)
    Description used for Twitter sharing.
  • $page->twitterImage (string|null)
    Image used for Twitter cards.

Canonical & Multilingual SEO

  • $page->canonicalUrl (string|null)
    Canonical URL of the page to avoid duplicate content issues.
  • $page->hreflangLinks (array)
    List of alternate language URLs for multilingual SEO.
    Example:
PHP
[
  'en' => '/en/page',
  'fr' => '/fr/page'
]

Assets (CSS & JavaScript)

  • $page->style (string)
    Inline CSS styles injected into the page.
  • $page->script (string)
    Inline JavaScript code injected into the page.
  • $page->cssFiles (array)
    List of CSS files to be injected into the <head> section.
  • $page->jsFiles (array)
    List of JavaScript files to be injected (usually in footer or head depending on configuration).

Layout Structure

Defines the structural composition of the rendered page.

  • $page->header (string)
    Header HTML content.
  • $page->nav (string|null)
    Navigation bar HTML content.
  • $page->footer (string)
    Footer HTML content.
  • $page->main (string)
    Main content area of the page.
  • $page->sidebarLeft (string|null)
    Left sidebar content (optional).
  • $page->sidebarRight (string|null)
    Right sidebar content (optional).

HTML Attributes

Used to dynamically customize the <body> and <main> tags.

  • $page->bodyId (string|null)
    ID attribute applied to <body>.
  • $page->bodyClass (string|null)
    CSS classes applied to <body>.
  • $page->mainId (string|null)
    ID attribute applied to <main> container.
  • $page->mainClass (string|null)
    CSS classes applied to <main> container.

Content System

  • $page->contentType (array)
    Configuration of the current content type.
    Retrieved via ContentTypeManager::get($handle).
    Example:
PHP
[
  'handle' => 'blog',
  'type' => 'single',
  'fields' => [...]
]
  • $page->entry (array)
    Primary CMS data entry for the page.
    Represents the main object being rendered (article, product, page, etc.).
  • $page->viewData (array)
    Additional data injected by controllers (filters, lists, related entities, UI helpers).

Template System

  • $page->template (string|null)
    Path to a specific template file used for rendering the page.

Routing & Permissions

  • $page->currentRoute (array)
    Information about the matched route.
    Includes:
    • route handle
    • parameters
    • resolved context
  • $page->permission (string)
    Required permission string for accessing the page.

Error Handling

  • $page->errors (array)
    Collection of errors generated during rendering, validation, or routing.

Breadcrumb System

  • $page->breadcrumbs (array)
    Navigation trail for the current page.

Structure:

PHP
[
  [
    'label' => 'Home',
    'url' => '/'
  ],
  [
    'label' => 'Blog',
    'url' => '/blog'
  ]
]

Methods:

  • $page->addBreadcrumb(string $label, ?string $url = null): void
    Adds an item to the breadcrumb trail.
    • $label: Display name of the breadcrumb item
    • $url: Optional link (null = non-clickable item)

$platform (Platform Object)

Active only during Platform Management.

  • $platform->settings: Global engine configurations.

Static Managers

Managers are stateless classes. They handle raw SQL mapping, data hydration, and caching.

AssetManager

Manages the registration and publication of CSS/JS files.

  • publishCoreAssets(): Synchronizes engine assets to the public folder.

BreadcrumbManager

Constructs the hierarchical path (<ol><li>) for SEO and UI navigation.

ContentTypeManager

Handles content blueprints (Collections, Singles).

  • get(string $handle): Returns the schema configuration.
  • slugExistsForContentType(...): Validates a slug against a specific schema.

Database

The secure PDO-based database layer used by the CMS to execute all SQL operations safely and consistently.

It provides a simple API for querying, writing data, and handling transactions without exposing low-level PDO complexity.

Query Methods

  • fetch(string $sql, array $params = [])
    Returns a single row from the database.
    • Uses prepared statements (secure by default)
    • Returns array|null
    • Used for retrieving a single entity (user, page, setting, etc.)
  • fetchAll(string $sql, array $params = [])
    Returns multiple rows.
    • Uses prepared statements
    • Returns array
    • Used for lists, collections, search results, dashboards
  • fetchColumn(string $sql, array $params = [])
    Returns a single scalar value.
    • Useful for aggregates (COUNT, SUM, MAX, etc.)
    • Returns mixed

Write Operations

  • updateTable(string $sql, array $params = [])
    Executes INSERT, UPDATE, or DELETE queries.
    • Fully parameterized (SQL injection safe)
    • Returns bool (success/failure)
    • Core method for all data mutations

Schema Operations (Advanced / Internal Use)

These methods are mainly used for migrations, installers, or system-level operations.

  • createTable(string $sql)
    Creates a database table.
    • Used during installation or migrations
  • alterTable(string $sql)
    Executes schema modifications (ALTER, DROP, etc.).
    • Used for migration system and upgrades
  • dropTable(string $tableName)
    Safely removes a table if it exists.
    • Wrapper around DROP TABLE IF EXISTS

Transactions

  • beginTransaction()
    Starts a database transaction.
    • Groups multiple operations into a single atomic unit
  • commit()
    Commits the current transaction.
    • Persists all changes
  • rollBack()
    Cancels the current transaction.
    • Restores database state on failure
  • inTransaction()
    Checks if a transaction is currently active.
    • Prevents invalid nested transaction states

Error Handling

  • getError()
    Returns information about the last SQL error.
    • Includes SQLSTATE and driver message
    • Used for debugging and logging
  • hasError()
    Checks whether the last executed query failed.
    • Returns true if an error occurred
    • Useful for conditional error handling

Connection Management

  • connect(array $config)
    Creates a PDO connection to the database.
    • Requires host, database name, user, password
    • Uses UTF-8 (utf8mb4) encoding
    • Returns true on success, false on failure
  • reconnect(array $config)
    Resets and reinitializes the database connection.
    • Useful for runtime configuration changes or multi-tenant setups

EntryManager

The primary API for retrieving dynamic content (Articles, Products) and hydrating Custom Fields.

  • getEntries(string $handle, array $params = []): Fetches a list of entries from a collection. Supports limit, offset, and order.
  • getEntryBySlug(string $slug, int $langId): Retrieves a single entry with all its custom fields hydrated.

ExtensionManager

Handles the lifecycle (Install, Enable, Uninstall) of third-party plugins.

FieldManager

Processes Custom Field data for forms and content types.

FormManager

Renders frontend forms and processes user submissions.

  • renderForm(string $handle, array $options): Generates the frontend form HTML.
  • processSubmission(int $formId, array $data): Handles post-submit logic.

Hooks

The Event Dispatcher (Publish/Subscribe pattern) for addAction and addFilter.

  • addAction(string $hook, callable $callback): Triggers logic.
  • addFilter(string $hook, callable $callback): Modifies data.

LanguageManager

Resolves translations and generates automated hreflang tags.

MediaManager

Handles file uploads, image variant generation, and alt-text localization.

  • getMediaById(int $id, int $langId): Returns the path and localized metadata (Alt, Legend) for a specific asset.

MenuItemManager

Queries navigation trees.

MenuManager

Queries menus.

  • getMenus(): Fetches all available menus.

NotificationManager

Controls the internal messaging system for the Admin dashboard.

PageManager

Retrieves data for Static and Builder pages.

  • getPageBySlug(string $slug, int $langId): Fetches static page content.

PlatformManager

Handles platform-level orchestration and environment configuration (multi-site / global runtime layer).

  • updateSiteCmsCore(string $handle, string $version): Orchestrates engine updates for a specific site instance.

RoleManager

Controls RBAC (Role-Based Access Control) and user sessions.

RouteCacheManager

Handles generation and management of route cache files for fast routing and URL resolution.

  • generate(?string $siteDir = null): bool: Clears existing cache and rebuilds all route cache files (per language) used by the router and URL generation system.

RouteManager

Compiles the database routes into the high-performance PHP cache file.

SearchManager

Executes global site searches across multiple content types.

  • search(string $query, int $langId): Performs a global index search.

SecurityManager

Handles master-key encryption/decryption for sensitive data (e.g., SMTP passwords).

SeoManager

Handles metadata resolution, Schema.org injection, and SEO fallback logic.

  • configureForSingleEntry(object $page, array $data, ...): Automatically computes SEO fallbacks for a specific piece of content.
  • addSchema(array $schema): Injects a custom JSON-LD block into the unified @graph.

SiteManager

Handles multi-tenant CRUD operations from the Platform level.

SitemapManager

Generates the multilingual sitemap.xml.

  • updateEntry(...): Manages dynamic entries in sitemap.xml.

TaxonomyManager

Retrieves hierarchical categories and tags.

TaxonomyTermManager

Retrieves hierarchical categories and tags.

TemplateEngine

Secure Twig rendering engine for user-generated template code with sandbox restrictions.

  • renderUserContent(string $templateCode, array $context = []): Renders Twig template code from the database in a sandboxed environment with whitelisted CMS functions and filters.

ThemeManager

Handles active theme configuration and updates the cached theme state used by the CMS runtime.

  • updateThemeCache(string $newThemeName): bool: Updates and writes the active theme into the system cache file used for fast theme loading.

UI

Backend-specific system for generating structured admin interface components such as media pickers, galleries, autocompletes, and layout elements.

  • renderCard(array $options): Generates a fully customizable CMS card component for admin dashboards and listings.
  • renderMediaGallery(): Displays the admin media library interface with upload, filtering, and selection tools.
  • renderMediaPicker(string $baseInputName, $currentValue = null, ?string $id = null): Renders a media selector for choosing a single image, video, or document.
  • renderIconGallery(): Opens the icon selection modal with search, pagination, and provider support.
  • renderIconPicker(string $namePrefix, ?string $idPrefix = null, ?string $iconLibrary = null, ?string $iconName = null): Generates an icon selector with live preview and hidden form binding.
  • renderGalleryPicker(string $baseInputName, ?array $mediaItems = [], ?string $id = null): Builds a sortable multi-media gallery field with metadata and link support.
  • renderRelationField(string $baseInputName, mixed $currentValue, array $options, bool $isMultiple = false): Creates an autocomplete field for linking entries, users, or categories (single or multiple selection).
  • renderAccordion(string $title, string $content, string $containerClass = '', string $itemClass = ''): Renders a collapsible accordion UI component for admin layouts.
  • renderEditorJs(array|string $content): Parses and renders Editor.js structured content into HTML output.

UpdateManager

Queries the core repository to fetch and apply OTA (Over-The-Air) engine updates.

UserManager

  • userHasPermission(string $key): Checks RBAC rules for the logged-in user.

Enums

Pragma CMS uses strict PHP Enums to prevent typos and ensure type safety across the system.

Hook

Used to reference system events safely.

  • Example: Hook::BEFORE_ENTRY_SAVE ensures you don't make typos in your plugin registrations.

Section

Determines the rendering environment.

  • Section::Admin: Used by base.php to include the sidebar and dashboard assets.