HttpCodes
extends Base
in package
Table of Contents
Properties
- $_app : IMvcApplication
- $_router : Router|null
Methods
- __call() : string|null
- Magic method to provide Rails-style URL helper methods in controllers.
- __construct() : mixed
- code401() : string
- code403() : string
- code404() : string
- code500() : string
- getApplication() : IMvcApplication
- getRouter() : Router
- register() : void
- This method registers routes for any of the standard methods that are currently implemented in the class.
- renderHtml() : string
- Renders an HTML response.
- renderHtmlWithCacheKey() : string
- Render HTML with separate cache key data.
- renderJson() : string
- Renders a JSON response.
- renderMarkdown() : string
- Renders a Markdown response.
- renderMarkdownWithCacheKey() : string
- Render Markdown with separate cache key data.
- renderXml() : string
- Renders an XML response.
- setApplication() : Base
- setRouter() : Base
- getControllerName() : string
- Get the controller name for cache key generation.
- getControllerViewPath() : string
- Get the controller view path accounting for namespace hierarchy.
- getViewCache() : string|null
- Get cached view content if available.
- getViewCacheByKey() : string|null
- Get cached view content using only cache key data.
- hasViewCache() : bool
- Check if a view cache exists for the given page and data.
- hasViewCacheByKey() : bool
- Check if a view cache exists using only cache key data.
- initializeViewCache() : ViewCache|null
- Initialize ViewCache if not already present in Registry.
- injectHelpers() : array<string|int, mixed>
- Inject URL helpers and other view helpers into view data.
- isCacheEnabledByDefault() : bool
- Check if cache is enabled by default in system settings.
- registerAdd() : void
- registerCreate() : void
- registerDelete() : void
- registerEdit() : void
- registerIndex() : void
- registerShow() : void
- registerUpdate() : void
- routeExists() : bool
- Check if a named route exists.
- urlFor() : string|null
- Generate a relative URL for a named route.
- urlForAbsolute() : string|null
- Generate an absolute URL for a named route.
- urlHelper() : UrlHelper|null
- Create a new UrlHelper instance for use in controllers.
- view() : ViewContext
- Create a new fluent ViewContext for building and rendering views.
- storeCachedView() : void
- Store rendered content in view cache.
Properties
$_app
private
IMvcApplication
$_app
$_router
private
Router|null
$_router
= null
Methods
__call()
Magic method to provide Rails-style URL helper methods in controllers.
public
__call(string $method, array<string|int, mixed> $arguments) : string|null
Supports patterns like:
$this->userProfilePath(['id' => 123])-> generates relative URL for 'user_profile' route$this->userProfileUrl(['id' => 123])-> generates absolute URL for 'user_profile' route
Parameters
- $method : string
-
The method name (e.g., 'userProfilePath', 'userProfileUrl')
- $arguments : array<string|int, mixed>
-
Method arguments, first should be parameters array
Tags
Return values
string|null —Generated URL or null if route not found
__construct()
public
__construct(IMvcApplication $app) : mixed
Parameters
- $app : IMvcApplication
code401()
public
code401(Request $request) : string
Parameters
- $request : Request
Return values
stringcode403()
public
code403(Request $request) : string
Parameters
- $request : Request
Return values
stringcode404()
public
code404(Request $request) : string
Parameters
- $request : Request
Return values
stringcode500()
public
code500(Request $request) : string
Parameters
- $request : Request
Return values
stringgetApplication()
public
getApplication() : IMvcApplication
Return values
IMvcApplicationgetRouter()
public
getRouter() : Router
Return values
Routerregister()
This method registers routes for any of the standard methods that are currently implemented in the class.
public
static register(IMvcApplication $app[, string $route = '' ]) : void
Index Add Show Create Edit Update Delete
Parameters
- $app : IMvcApplication
- $route : string = ''
Tags
renderHtml()
Renders an HTML response.
public
renderHtml(HttpResponseStatus $responseCode[, array<string|int, mixed> $data = [] ][, string $page = "index" ][, string $layout = "default" ][, bool|null $cacheEnabled = null ]) : string
Parameters
- $responseCode : HttpResponseStatus
- $data : array<string|int, mixed> = []
- $page : string = "index"
- $layout : string = "default"
- $cacheEnabled : bool|null = null
Tags
Return values
stringrenderHtmlWithCacheKey()
Render HTML with separate cache key data.
public
renderHtmlWithCacheKey(HttpResponseStatus $responseCode[, array<string|int, mixed> $viewData = [] ][, array<string|int, mixed> $cacheKeyData = [] ][, string $page = "index" ][, string $layout = "default" ][, bool|null $cacheEnabled = null ]) : string
Allows checking/using cache without fetching full view data.
Parameters
- $responseCode : HttpResponseStatus
-
HTTP response status
- $viewData : array<string|int, mixed> = []
-
Full data for rendering (can be empty if using cache)
- $cacheKeyData : array<string|int, mixed> = []
-
Minimal data for cache key generation
- $page : string = "index"
-
Page template name
- $layout : string = "default"
-
Layout template name
- $cacheEnabled : bool|null = null
-
Whether to enable caching
Tags
Return values
string —Rendered HTML content
renderJson()
Renders a JSON response.
public
renderJson(HttpResponseStatus $responseCode[, array<string|int, mixed> $data = [] ]) : string
Parameters
- $responseCode : HttpResponseStatus
- $data : array<string|int, mixed> = []
Return values
stringrenderMarkdown()
Renders a Markdown response.
public
renderMarkdown(HttpResponseStatus $responseCode[, array<string|int, mixed> $data = [] ][, string $page = "index" ][, string $layout = "default" ][, bool|null $cacheEnabled = null ]) : string
Parameters
- $responseCode : HttpResponseStatus
- $data : array<string|int, mixed> = []
- $page : string = "index"
- $layout : string = "default"
- $cacheEnabled : bool|null = null
Tags
Return values
stringrenderMarkdownWithCacheKey()
Render Markdown with separate cache key data.
public
renderMarkdownWithCacheKey(HttpResponseStatus $responseCode[, array<string|int, mixed> $viewData = [] ][, array<string|int, mixed> $cacheKeyData = [] ][, string $page = "index" ][, string $layout = "default" ][, bool|null $cacheEnabled = null ]) : string
Allows checking/using cache without fetching full view data.
Parameters
- $responseCode : HttpResponseStatus
-
HTTP response status
- $viewData : array<string|int, mixed> = []
-
Full data for rendering (can be empty if using cache)
- $cacheKeyData : array<string|int, mixed> = []
-
Minimal data for cache key generation
- $page : string = "index"
-
Page template name
- $layout : string = "default"
-
Layout template name
- $cacheEnabled : bool|null = null
-
Whether to enable caching
Tags
Return values
string —Rendered Markdown content
renderXml()
Renders an XML response.
public
renderXml(HttpResponseStatus $responseCode[, array<string|int, mixed> $data = [] ]) : string
Parameters
- $responseCode : HttpResponseStatus
- $data : array<string|int, mixed> = []
Return values
stringsetApplication()
public
setApplication(IMvcApplication $app) : Base
Parameters
- $app : IMvcApplication
Return values
BasesetRouter()
public
setRouter(Router|null $router) : Base
Parameters
- $router : Router|null
Return values
BasegetControllerName()
Get the controller name for cache key generation.
protected
getControllerName() : string
Returns the short class name (without namespace). This matches how the framework's render methods set the controller name.
Return values
string —The controller class name without namespace
getControllerViewPath()
Get the controller view path accounting for namespace hierarchy.
protected
getControllerViewPath() : string
Converts controller namespace and class name to snake_case directory structure.
Examples:
- Neuron\Cms\Controllers\Admin\Posts -> admin/posts
- Neuron\Cms\Controllers\PostController -> post (backwards compatible with "Controller" suffix)
- Neuron\Cms\Controllers\Dashboard -> dashboard
Return values
string —The view path (e.g., "admin/posts", "dashboard")
getViewCache()
Get cached view content if available.
protected
getViewCache(string $page[, array<string|int, mixed> $data = [] ]) : string|null
Initializes ViewCache if needed.
Parameters
- $page : string
-
The page/view name
- $data : array<string|int, mixed> = []
-
The data that affects cache key generation
Return values
string|null —The cached content or null if not found
getViewCacheByKey()
Get cached view content using only cache key data.
protected
getViewCacheByKey(string $page[, array<string|int, mixed> $cacheKeyData = [] ]) : string|null
This allows retrieving the cache without fetching full view data.
Parameters
- $page : string
-
The page/view name
- $cacheKeyData : array<string|int, mixed> = []
-
The minimal data that determines cache uniqueness
Return values
string|null —The cached content or null if not found
hasViewCache()
Check if a view cache exists for the given page and data.
protected
hasViewCache(string $page[, array<string|int, mixed> $data = [] ]) : bool
Initializes ViewCache if needed.
Parameters
- $page : string
-
The page/view name
- $data : array<string|int, mixed> = []
-
The data that affects cache key generation
Return values
bool —True if a cache exists, false otherwise
hasViewCacheByKey()
Check if a view cache exists using only cache key data.
protected
hasViewCacheByKey(string $page[, array<string|int, mixed> $cacheKeyData = [] ]) : bool
This allows checking cache without fetching full view data.
Parameters
- $page : string
-
The page/view name
- $cacheKeyData : array<string|int, mixed> = []
-
The minimal data that determines cache uniqueness
Return values
bool —True if cache exists, false otherwise
initializeViewCache()
Initialize ViewCache if not already present in Registry.
protected
initializeViewCache() : ViewCache|null
This allows controllers to check cache before making expensive API calls.
Return values
ViewCache|null —The ViewCache instance or null if initialization fails
injectHelpers()
Inject URL helpers and other view helpers into view data.
protected
injectHelpers(array<string|int, mixed> $data) : array<string|int, mixed>
This method:
- Merges global view data from ViewDataProvider (if registered)
- Injects UrlHelper for route generation (if router available)
- Controller-specific data takes precedence over global data
Parameters
- $data : array<string|int, mixed>
-
The view data array
Return values
array<string|int, mixed> —Data array with helpers and global data injected
isCacheEnabledByDefault()
Check if cache is enabled by default in system settings.
protected
isCacheEnabledByDefault() : bool
Return values
bool —True if cache is enabled in settings, false otherwise
registerAdd()
protected
static registerAdd(Application $app, string $controller, string $route) : void
Parameters
- $app : Application
- $controller : string
- $route : string
Tags
registerCreate()
protected
static registerCreate(Application $app, string $controller, string $route) : void
Parameters
- $app : Application
- $controller : string
- $route : string
Tags
registerDelete()
protected
static registerDelete(Application $app, string $controller, string $route) : void
Parameters
- $app : Application
- $controller : string
- $route : string
Tags
registerEdit()
protected
static registerEdit(Application $app, string $controller, string $route) : void
Parameters
- $app : Application
- $controller : string
- $route : string
Tags
registerIndex()
protected
static registerIndex(Application $app, string $controller, string $route) : void
Parameters
- $app : Application
- $controller : string
- $route : string
Tags
registerShow()
protected
static registerShow(Application $app, string $controller, string $route) : void
Parameters
- $app : Application
- $controller : string
- $route : string
Tags
registerUpdate()
protected
static registerUpdate(Application $app, string $controller, string $route) : void
Parameters
- $app : Application
- $controller : string
- $route : string
Tags
routeExists()
Check if a named route exists.
protected
routeExists(string $routeName) : bool
Parameters
- $routeName : string
-
The route name to check
Return values
bool —True if route exists, false otherwise
urlFor()
Generate a relative URL for a named route.
protected
urlFor(string $routeName[, array<string|int, mixed> $parameters = [] ][, string|null $fallback = null ]) : string|null
Parameters
- $routeName : string
-
The name of the route
- $parameters : array<string|int, mixed> = []
-
Parameters to substitute in the route path
- $fallback : string|null = null
-
Fallback URL if route not found
Return values
string|null —The generated relative URL, fallback if provided, or null if route not found
urlForAbsolute()
Generate an absolute URL for a named route.
protected
urlForAbsolute(string $routeName[, array<string|int, mixed> $parameters = [] ][, string|null $fallback = null ]) : string|null
Parameters
- $routeName : string
-
The name of the route
- $parameters : array<string|int, mixed> = []
-
Parameters to substitute in the route path
- $fallback : string|null = null
-
Fallback URL if route not found
Return values
string|null —The generated absolute URL, fallback if provided, or null if route not found
urlHelper()
Create a new UrlHelper instance for use in controllers.
protected
urlHelper() : UrlHelper|null
Return values
UrlHelper|null —The URL helper instance or null if router not available
view()
Create a new fluent ViewContext for building and rendering views.
protected
view() : ViewContext
This provides a clean, chainable API for constructing view data and rendering.
Tags
Return values
ViewContext —A new view context instance
storeCachedView()
Store rendered content in view cache.
private
storeCachedView(string $page, array<string|int, mixed> $cacheKeyData, string $content, bool|null $cacheEnabled) : void
Handles cache initialization, temporary enablement, and error handling.
Parameters
- $page : string
-
The page/view name
- $cacheKeyData : array<string|int, mixed>
-
Data for cache key generation
- $content : string
-
The rendered content to cache
- $cacheEnabled : bool|null
-
Whether caching is explicitly enabled