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

Core Base

A shared developer convenience base that exposes frequently used APPNETOS Core functionality through protected methods.

Overview

Core\Base is an abstract PHP base class for application and custom classes. Developers can inherit its shortcuts instead of repeatedly resolving services through Core\Registry or accessing runtime helpers. The class delegates operations to the responsible Core implementations; it does not implement application business logic.

These shortcuts are protected and intended to be called from subclasses. They do not form an independently initialized Core service.

Context Availability

Context Independent

The implementation is shared at appnetos/shared/src/Core/Base.php. There is no separate Core\Base implementation for each context. A subclass can inherit the base across APPNETOS contexts, but individual shortcuts depend on whether their underlying services are available and initialized in the active context. For example, request and session helpers should not be assumed to work in cmd or worker.

Architecture

Developer classes inherit the shortcut methods. Registry-backed shortcuts resolve a Core service and delegate to it; other shortcuts access the runtime or use dedicated converter and validator classes.

Developer classes extend Core Base, which delegates to Core services through the Registry or runtime.
Simplified delegation overview. Not every shortcut passes through the Registry.

Usage Example

Inherit Core\Base in your own class and use the protected helpers. The example below assumes an app or admin runtime where the relevant request and session services are initialized.

namespace Example;

class PageController extends \Core\Base
{
    public function __construct()
    {
        parent::__construct();
    }

    public function readPage(): int
    {
        return $this->getGetInt('page');
    }

    public function storeName(): void
    {
        $name = $this->postGetString('name');
        $this->sessionSet('name', $name);
    }
}

object(string $class): object returns a Registry-resolved object. callObject() invokes a method on that object and returns null if the method does not exist.

Convenience Methods

All 81 protected methods declared by the current shared implementation are grouped below. Signatures are taken from the PHP source; the underlying services define the behavior and validation of delegated operations.

Registry & Runtime

Method Return type
object(string $class) object
callObject(string $class, string $method, array $parameters = []) mixed
runtime() object

Configuration & Context

Method Return type
config(string $key) mixed
getBaseUrl() string
getContextUrl() string
getApplication() string|null
getContext() string|null
getBaseContext() string|null

GET Input

Method Return type
getGet(string $key) mixed
getGetString(string $key) string
getGetInt(string $key) int
getGetFloat(string $key) float
getGetBool(string $key) bool
getGetArray(string $key) array
getHas(string $key) bool
getGetAll() array

POST Input

Method Return type
postGet(string $key) mixed
postGetString(string $key) string
postGetInt(string $key) int
postGetFloat(string $key) float
postGetBool(string $key) bool
postGetArray(string $key) array
postHas(string $key) bool
postGetAll() array

Combined Request Input

Method Return type
requestGet(string $key) mixed
requestGetString(string $key) string
requestGetInt(string $key) int
requestGetFloat(string $key) float
requestGetBool(string $key) bool
requestGetArray(string $key) array
requestHas(string $key) bool
requestGetAll() array

Cookies

Method Return type
cookieSet(string $key, string $value, int|null $expires = 2592000, string $path = '/', bool|null $secure = null, bool $httpOnly = true, string $sameSite = 'Lax') void
cookieGet(string $key) mixed
cookieGetString(string $key) string
cookieGetInt(string $key) int
cookieGetFloat(string $key) float
cookieGetBool(string $key) bool
cookieGetArray(string $key) array
cookieHas(string $key) bool
cookieRemove(string $key, string $path = '/') void
cookieClear() void
cookieGetAll() array

Sessions

Method Return type
sessionSet(string $key, mixed $value) void
sessionGet(string $key, mixed $default = null) mixed
sessionGetString(string $key) string
sessionGetInt(string $key) int
sessionGetFloat(string $key) float
sessionGetBool(string $key) bool
sessionGetArray(string $key) array
sessionHas(string $key) bool
sessionRemove(string $key) void
sessionClear() void
sessionRegenerate() void
sessionDestroy() void
sessionGetAll() object

Server & Client

Method Return type
serverGet(string $key) mixed
getRawIp() string
getUserAgent() string

Rendering & Responses

Method Return type
set(string $key, mixed $value) void
load(string $template, array $variables = []) string|null
render(string $template, array $variables = []) void
html() never
send() never
json(object|array|string $data) never
htmlResponse(string $html, int $status = 200) never
redirect(string|null $url = null, int $status = 302) never

Localization

Method Return type
trans(string $key) string|array|null
translate(string $key) string

Document Conversion & ObjectIds

Method Return type
documentToArray(object $document) array
documentToMongoDb(object $document) object
documentToTemplateData(object $document) array
mongoDbValueToDocumentValue(mixed $value) mixed
objectIdToString(object $objectId) string
objectIdsToStrings(array $objectIds) array
stringToObjectId(string $string) object
stringsToObjectIds(array $strings) array
objectIdInObjectIds(ObjectId $objectId, array $objectIds) bool
stringAsObjectId(string $string) bool

Runtime Control

Method Return type
exit() void

Extension & Limitations

Core\Base is designed for ordinary PHP inheritance: application classes may extend it and add their own methods. However, the source explicitly excludes Core\Base itself from the APPNETOS Class Extension System.

Registry-backed helpers may raise exceptions from registry resolution and reflection. Some methods have strict return types, so a missing underlying method or unavailable service can also cause runtime errors. Response helpers such as json(), send(), htmlResponse() and redirect() are terminal operations and must not be treated as ordinary return-value methods.

config($key) dynamically calls a corresponding get<Key>() method on Core\Config; it does not directly read arbitrary configuration array keys.

Next Steps

Previous

Core Fundamentals

Explore Core Fundamentals

Next

Registry

Explore Registry