Conn2Flow
Docs navigation

Reference / Libraries

recursos.php library

Static asset URLs: direct delivery from public_html/dist/ when the file was published, with a fallback to the arquivo-estatico controller.

Path in the Gestor bibliotecas/recursos.php

Resolves the URL of a static asset (JS, CSS, image, font) of the Gestor or of a module. Always loaded by config.php.

The Gestor code lives outside the public folder. An asset can reach the browser in two ways:

  1. Published to public_html/dist/: c2f assets:publish (called by resources:sync and by the deploy) copies the assets there and writes the dist/.manifest.json inventory. Nginx or Apache serve the file straight from disk, without PHP.

  2. Through the arquivo-estatico controller: without publication, the historical URL (<url-raiz>interface/interface.js) goes through PHP, which reads the file from gestor/assets/ or from the module.

recursos_url() picks dist/ only when the file is in the manifest. In development, on a fresh installation or with an asset not published yet, the URL stays the old one, and nothing breaks.

Usage

echo recursos_tag_js('interface/interface.js', $version, 'defer');
echo recursos_tag_css('admin-arquivos/css.css');
$url = recursos_url_versionada('images/logo.png');
Function Does
recursos_url($caminho, $base = null) URL in dist/ if published; otherwise <url-raiz or $base><path>
recursos_versao($caminho, $padrao = null) The content hash, from the manifest; otherwise $padrao; otherwise gestor_asset_version()
recursos_url_versionada() recursos_url() + ?v=<version>
recursos_tag_js() / recursos_tag_css() The ready <script> / <link rel="stylesheet"> tag
recursos_publicado($caminho) / recursos_dist_ativo() Lookups in the manifest loaded into $_GESTOR['dist-manifest']
recursos_caminho_normalizar($caminho) Strips ?/#, extra and leading slashes; rejects .. and null bytes ('')
recursos_dist_mapear_fonte($relativo) The source → dist/ contract, shared with assets:publish

The path contract

The path inside dist/ is the same as the public URL:

Source in the Gestor In dist/ and in the URL
assets/<path> <path>
modulos/<m>/<m>.js / <m>.css <m>/js.js / <m>/css.css
modulos/<m>/<m>.<option>.js <m>/<option>.js

.min.js has no path of its own: it is the preferred variant of the authored file, chosen at publication and, at runtime, by arquivo-estatico.

The dist/ folder uses url-raiz-sem-lang: the same file does not get one URL per language. dist-ativo turns on by itself in production and can be forced with ASSETS_DIST in the .env; PUBLIC_PATH tells where the public folder is when the Gestor runs from the CLI (global variables).

Functions

Generated from gestor/bibliotecas/recursos.php · 9 functions

9 of 9

recursos_caminho_normalizar

view source · line 43 ↗
recursos_caminho_normalizar(string $caminho): string

Normaliza um caminho de asset para a forma usada como chave do manifesto.

Parameters

$caminhostring
Caminho relativo do asset, como aparece na URL.

Returns

string
Caminho normalizado, ou '' quando o caminho é inválido.

recursos_publicado

view source · line 73 ↗
recursos_publicado(string $caminho): bool

Informa se um asset consta no manifesto publicado em dist/.

Parameters

$caminhostring
Caminho relativo do asset (com ou sem query string).

Returns

bool

recursos_url

view source · line 102 ↗
recursos_url(string $caminho, string|null $base = null): string

URL pública de um asset.

Parameters

$caminhostring
Caminho relativo do asset, opcionalmente com query string.
$basestring|null
Raiz pública usada no fallback; null usa url-raiz.

Returns

string
URL pronta para o atributo src/href.

recursos_versao

view source · line 128 ↗
recursos_versao(string $caminho, string|null $versaoPadrao = null): string

Token de cache busting de um asset publicado.

Parameters

$caminhostring
Caminho relativo do asset.
$versaoPadraostring|null
Versão usada quando o asset não está publicado.

Returns

string

recursos_url_versionada

view source · line 149 ↗
recursos_url_versionada(string $caminho, string|null $versao = null, string|null $base = null): string

URL de um asset já com o parâmetro de cache busting.

Parameters

$caminhostring
Caminho relativo do asset.
$versaostring|null
Versão a usar quando o asset não está publicado.
$basestring|null
Raiz pública do fallback; null usa url-raiz.

Returns

string

recursos_tag_js

view source · line 162 ↗
recursos_tag_js(string $caminho, string|null $versao = null, string $extra = '', string|null $base = null): string

Tag <script> de um asset do gestor.

Parameters

$caminhostring
Caminho relativo do asset.
$versaostring|null
Versão usada quando o asset não está publicado.
$extrastring
Atributos adicionais já formatados (ex.: defer).
$basestring|null
Raiz pública do fallback; null usa url-raiz.

Returns

string

recursos_tag_css

view source · line 177 ↗
recursos_tag_css(string $caminho, string|null $versao = null, string $extra = '', string|null $base = null): string

Tag <link rel="stylesheet"> de um asset do gestor.

Parameters

$caminhostring
Caminho relativo do asset.
$versaostring|null
Versão usada quando o asset não está publicado.
$extrastring
Atributos adicionais já formatados (ex.: data-c2f-css-role="quill").
$basestring|null
Raiz pública do fallback; null usa url-raiz.

Returns

string

recursos_dist_mapear_fonte

view source · line 204 ↗
recursos_dist_mapear_fonte(string $relativo): string

Contrato de mapeamento entre o arquivo FONTE no gestor e o caminho publicado em dist/.

Parameters

$relativostring
Caminho do arquivo relativo à raiz do gestor, com / como separador.

Returns

string
Caminho dentro de dist/, ou '' quando o arquivo não é publicável.

The Future is Hybrid: Human + AI.

Conn2Flow is the tool. If you need the Architect to design your company's strategy using this technology...

Hire Specialized Consulting