StaticFiles
in package
StaticFiles controller for serving controller-specific static files (JS, CSS, etc.)
Serves static files from tsugi/lib/src/Controllers/static/{ControllerName}/ with proper caching headers and MIME types.
Table of Contents
Constants
- ROUTE : mixed = '/static'
Properties
- $mimeTypes : mixed
Methods
- routes() : mixed
- serve() : Response
- Serve a controller static file
- url() : string
- Generate URL for a controller static file
Constants
ROUTE
public
mixed
ROUTE
= '/static'
Properties
$mimeTypes
private
static mixed
$mimeTypes
= ['js' => 'application/javascript', 'css' => 'text/css', 'json' => 'application/json', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'svg' => 'image/svg+xml', 'woff' => 'font/woff', 'woff2' => 'font/woff2', 'ttf' => 'font/ttf', 'eot' => 'application/vnd.ms-fontobject']
Methods
routes()
public
static routes(Application $app[, mixed $prefix = self::ROUTE ]) : mixed
Parameters
- $app : Application
- $prefix : mixed = self::ROUTE
serve()
Serve a controller static file
public
serve(Request $request, string $controller, string $filename) : Response
Parameters
- $request : Request
- $controller : string
-
Controller name (e.g., 'Announcements', 'Pages')
- $filename : string
-
Static filename (e.g., 'tsugi-announce.js')
Return values
Responseurl()
Generate URL for a controller static file
public
static url(string $controller, string $filename[, string|null $basePath = null ]) : string
Static helper method that can be used without instantiating the controller. When called from a Tool controller, basePath should be toolParent() . '/static'
Parameters
- $controller : string
-
Controller name (e.g., 'Announcements')
- $filename : string
-
Static filename (e.g., 'tsugi-announce.js')
- $basePath : string|null = null
-
Optional base path (defaults to determining from request using Tool::determineParentPath())
Return values
string —Full URL to the static file