APPNETOS is under active development This website and its documentation are being prepared for public launch. Content and features may change.
Select Theme
Loading

Css

Registers public CSS resources, collects application files and inline code, and supports context-specific caching and minification.

Purpose

Core\Css manages CSS resources for the active APPNETOS runtime context. Public URLs can be registered directly, while private application files are resolved and either collected as inline code or published as generated cache files.

Resources from multiple applications can be accumulated through the same controller. The controller returns resource data; the layout or rendering templates decide where to output file tags and inline code (for example, in the document head or at the end of the DOM).

Registering resources

  • add() registers a public or external source directly, with a priority and media attribute.
  • addFile() detects public URLs and root-relative public paths; local or private paths are delegated to appendFile().
  • appendFile() resolves a local file and processes it through the cache or inline pipeline.
  • append() stores inline code without creating a generated cache file.

The add(), addFile() and appendFile() methods support a media attribute (default all). Deduplication uses source plus media; registering the same combination again replaces its metadata.

Public resources are returned in ascending priority order. The code does not automatically download, bundle or minify directly registered external URLs.

Private application files

Private files are resolved in this order: an existing physical file path, Core\Files::getCss(), then a path relative to APPNETOS_ROOT. Missing or unreadable files are logged; unresolved files are not registered.

When caching is disabled, each resolved file is read and appended to the inline collection. With caching enabled, APPNETOS first looks for a valid generated public file and creates one when needed. If generation fails, it falls back to inline code.

Caching and minification

Each private source file is processed independently, not merged into one bundle. Generated resources are written to public/appnetos/cache/<context>/css/ and exposed at /appnetos/cache/<context>/css/. Filenames contain a newly generated random hash; the generic Core\Cache stores the source-to-public-file mapping under Cache::TYPE_CSS.

If the generated file is missing, its cache mapping is removed so it can be generated again. An existing generated file is reused while its cache mapping remains valid; these base classes do not compare source modification times or content hashes before reuse.

When minification is enabled, new generated files and inline code are passed to Core\Css\Minifier. Previously generated cached files are reused without being minified again. Directly registered public or external sources are not processed by the minifier.

Example registration

The following PHP illustrates the resource registration API. Replace the example paths with files available in your application.

$css = Registry::get(\Core\Css::class);
$css->add('/src/example/css/site.css', priority: -10);
$css->add('https://cdn.example.org/theme.css', media: 'screen');
$css->addFile('example/app/css/component.css');
$css->append('.component { display: flex; }');
$resources = $css->getAll();

Public API Reference

Core\Css

Class & Registry

Class: Core\Css

Extends: Core\Css\Base

use Core\Css;
use Core\Registry;

$css = Registry::get(Css::class);
Method Behavior
init(): void Resolve Core services and register context-specific static files once.
add(string $source, int $priority = 0, string $media = 'all'): void Register a public or external resource directly; does not read or minify the URL.
append(string $style): void Collect inline code; minify first when enabled.
appendFile(string $file, int $priority = 0, string $media = 'all'): void Resolve a private file; reuse or generate a public cached file, otherwise append inline.
addFile(string $file, int $priority = 0, string $media = 'all'): void Route public/external sources to add() and local/private files to appendFile().
getFiles(): array Return deduplicated public resources ordered by ascending priority.
getInline(): array Return collected inline code snippets in insertion order.
getAll(): array Return an array with files and inline collections.

getAll() returns files and inline. The file entries contain their source, priority and media attribute; inline entries are strings.

Context configuration and output

Context-specific implementations can override getStaticFiles(), getCssCache() and getCssMinify(). Static sources are registered during init(). The shared base implementations default to no generated-file caching and no minification.

APPNETOS collects resources independently of their HTML placement. The application layout is responsible for rendering public file references and inline snippets at the desired positions.

Next Steps

Previous

Js

Explore Js

Next

Localization

Explore Localization