Skip to content

Models

Resolves configured PhalconKit model instances without magic methods.

Applications can replace core model classes through the models config map. This service turns those configured class names into cached model instances while validating the contracts expected by each typed getter. Invalid app mappings are reported as ServiceException failures so production runtimes behave consistently even when PHP assertions are disabled.

The service intentionally constructs models directly instead of resolving them from the DI container because Phalcon models normally receive their runtime services through the model manager and default DI integration.


Properties

instances

Cached model instances keyed by the original core model class name.

public array<string,\PhalconKit\Mvc\Model> $instances

The cache key remains the core class requested by the framework, not the mapped replacement class. This lets callers swap implementations through config while preserving stable lookup and unsetInstance() semantics.


Methods

__construct

Build the model resolver with an optional explicit model class map.

public __construct(array<string,string>|null $mapping = null): mixed

Passing null loads the models map from the bootstrap config service via ModelsMap::setModelsMap(). Tests and service providers can pass an explicit array to bypass the config lookup and validate local mappings.

Parameters:

Parameter Type Description
$mapping array|null Core model class names mapped
to replacement model class names, or null to load from config.

Throws:

When the config-backed model map cannot be loaded from the DI container. - ServiceException


getInstances

Return every model instance that has already been resolved.

public getInstances(): array<string,\PhalconKit\Mvc\Model>

Return Value:

Cached instances keyed by the original core model class name requested by the framework.


setInstance

Store a resolved model instance for a core model class.

public setInstance(string $class, \PhalconKit\Mvc\Model $instance): void

This method is public so tests or advanced applications can pre-seed the cache with custom instances. The supplied instance is not revalidated against a typed getter contract until that getter is called.

Parameters:

Parameter Type Description
$class string Original core model class used as the cache key.
$instance \PhalconKit\Mvc\Model Model instance to reuse for future lookups.

unsetInstance

Remove a cached model instance for a core model class.

public unsetInstance(string $map): void

The configured class map is left intact. The next lookup for the same class will instantiate the currently configured mapped model again.

Parameters:

Parameter Type Description
$map string Original core model class used as the cache key.

getInstance

Return a cached instance of the configured model class for a core class.

public getInstance(string $class): \PhalconKit\Mvc\Model

The requested class is first translated through the model map. The mapped class must exist, be instantiable with its default constructor, and extend PhalconKit\Mvc\Model; otherwise a stable framework exception is thrown before a native PHP error or disabled assertion can leak to callers.

Parameters:

Parameter Type Description
$class string Original core model class name.

Return Value:

Instance of the configured mapped model class.

Throws:

When the mapped class cannot be loaded, instantiated, or does not extend the PhalconKit base model. - ServiceException


getTypedInstance

Return a mapped model instance that implements a specific framework contract.

private getTypedInstance(string $class, class-string<\PhalconKit\Support\T> $expectedType): \PhalconKit\Support\T

Typed getters call this helper after resolving the mapped model. This keeps every public getter concise while ensuring a wrong-but-valid model class, such as mapping User::class to Backup::class, fails with a precise ServiceException instead of a late PHP return-type error.

Parameters:

Parameter Type Description
$class string Original core model class name.
$expectedType class-string<\PhalconKit\Support\T> Required model interface or class.

Return Value:

Model instance implementing the requested contract.

Throws:

When the configured model does not implement the contract required by the typed getter. - ServiceException


getBackup

Return the configured backup model instance.

public getBackup(): \PhalconKit\Models\Interfaces\BackupInterface

Return Value:

Cached instance for Backup::class.

Throws:

When the configured model does not implement the backup model contract. - ServiceException


getAudit

Return the configured audit model instance.

public getAudit(): \PhalconKit\Models\Interfaces\AuditInterface

Return Value:

Cached instance for Audit::class.

Throws:

When the configured model does not implement the audit model contract. - ServiceException


getAuditDetail

Return the configured audit-detail model instance.

public getAuditDetail(): \PhalconKit\Models\Interfaces\AuditDetailInterface

Return Value:

Cached instance for AuditDetail::class.

Throws:

When the configured model does not implement the audit-detail model contract. - ServiceException


getLog

Return the configured log model instance.

public getLog(): \PhalconKit\Models\Interfaces\LogInterface

Return Value:

Cached instance for Log::class.

Throws:

When the configured model does not implement the log model contract. - ServiceException


getEmail

Return the configured email model instance.

public getEmail(): \PhalconKit\Models\Interfaces\EmailInterface

Return Value:

Cached instance for Email::class.

Throws:

When the configured model does not implement the email model contract. - ServiceException


getJob

Return the configured job model instance.

public getJob(): \PhalconKit\Models\Interfaces\JobInterface

Return Value:

Cached instance for Job::class.

Throws:

When the configured model does not implement the job model contract. - ServiceException


getFile

Return the configured file model instance.

public getFile(): \PhalconKit\Models\Interfaces\FileInterface

Return Value:

Cached instance for File::class.

Throws:

When the configured model does not implement the file model contract. - ServiceException


getSession

Return the configured persisted-session model instance.

public getSession(): \PhalconKit\Models\Interfaces\SessionInterface

Return Value:

Cached instance for Session::class.

Throws:

When the configured model does not implement the persisted-session model contract. - ServiceException


getFlag

Return the configured feature-flag model instance.

public getFlag(): \PhalconKit\Models\Interfaces\FlagInterface

Return Value:

Cached instance for Flag::class.

Throws:

When the configured model does not implement the feature-flag model contract. - ServiceException


getSetting

Return the configured setting model instance.

public getSetting(): \PhalconKit\Models\Interfaces\SettingInterface

Return Value:

Cached instance for Setting::class.

Throws:

When the configured model does not implement the setting model contract. - ServiceException


getLang

Return the configured language model instance.

public getLang(): \PhalconKit\Models\Interfaces\LangInterface

Return Value:

Cached instance for Lang::class.

Throws:

When the configured model does not implement the language model contract. - ServiceException


getTranslate

Return the configured translation model instance.

public getTranslate(): \PhalconKit\Models\Interfaces\TranslateInterface

Return Value:

Cached instance for Translate::class.

Throws:

When the configured model does not implement the translation model contract. - ServiceException


getWorkspace

Return the configured workspace model instance.

public getWorkspace(): \PhalconKit\Models\Interfaces\WorkspaceInterface

Return Value:

Cached instance for Workspace::class.

Throws:

When the configured model does not implement the workspace model contract. - ServiceException


getWorkspaceLang

Return the configured workspace-language model instance.

public getWorkspaceLang(): \PhalconKit\Models\Interfaces\WorkspaceLangInterface

Return Value:

Cached instance for WorkspaceLang::class.

Throws:

When the configured model does not implement the workspace-language model contract. - ServiceException


getPage

Return the configured page model instance.

public getPage(): \PhalconKit\Models\Interfaces\PageInterface

Return Value:

Cached instance for Page::class.

Throws:

When the configured model does not implement the page model contract. - ServiceException


getPost

Return the configured post model instance.

public getPost(): \PhalconKit\Models\Interfaces\PostInterface

Return Value:

Cached instance for Post::class.

Throws:

When the configured model does not implement the post model contract. - ServiceException


getTemplate

Return the configured template model instance.

public getTemplate(): \PhalconKit\Models\Interfaces\TemplateInterface

Return Value:

Cached instance for Template::class.

Throws:

When the configured model does not implement the template model contract. - ServiceException


getTable

Return the configured table model instance.

public getTable(): \PhalconKit\Models\Interfaces\TableInterface

Return Value:

Cached instance for Table::class.

Throws:

When the configured model does not implement the table model contract. - ServiceException


getProfile

Return the configured profile model instance.

public getProfile(): \PhalconKit\Models\Interfaces\ProfileInterface

Return Value:

Cached instance for Profile::class.

Throws:

When the configured model does not implement the profile model contract. - ServiceException


getOauth2

Return the configured OAuth2 identity model instance.

public getOauth2(): \PhalconKit\Models\Interfaces\Oauth2Interface

Return Value:

Cached instance for Oauth2::class.

Throws:

When the configured model does not implement the OAuth2 identity model contract. - ServiceException


getUser

Return the configured user model instance.

public getUser(): \PhalconKit\Models\Interfaces\UserInterface

Return Value:

Cached instance for User::class.

Throws:

When the configured model does not implement the user model contract. - ServiceException


getUserType

Return the configured user-type model instance.

public getUserType(): \PhalconKit\Models\Interfaces\UserTypeInterface

Return Value:

Cached instance for UserType::class.

Throws:

When the configured model does not implement the user-type model contract. - ServiceException


getUserGroup

Return the configured user-group model instance.

public getUserGroup(): \PhalconKit\Models\Interfaces\UserGroupInterface

Return Value:

Cached instance for UserGroup::class.

Throws:

When the configured model does not implement the user-group model contract. - ServiceException


getUserRole

Return the configured user-role model instance.

public getUserRole(): \PhalconKit\Models\Interfaces\UserRoleInterface

Return Value:

Cached instance for UserRole::class.

Throws:

When the configured model does not implement the user-role model contract. - ServiceException


getUserFeature

Return the configured user-feature model instance.

public getUserFeature(): \PhalconKit\Models\Interfaces\UserFeatureInterface

Return Value:

Cached instance for UserFeature::class.

Throws:

When the configured model does not implement the user-feature model contract. - ServiceException


getRole

Return the configured role model instance.

public getRole(): \PhalconKit\Models\Interfaces\RoleInterface

Return Value:

Cached instance for Role::class.

Throws:

When the configured model does not implement the role model contract. - ServiceException


getRoleRole

Return the configured role-inheritance model instance.

public getRoleRole(): \PhalconKit\Models\Interfaces\RoleRoleInterface

Return Value:

Cached instance for RoleRole::class.

Throws:

When the configured model does not implement the role-inheritance model contract. - ServiceException


getRoleFeature

Return the configured role-feature model instance.

public getRoleFeature(): \PhalconKit\Models\Interfaces\RoleFeatureInterface

Return Value:

Cached instance for RoleFeature::class.

Throws:

When the configured model does not implement the role-feature model contract. - ServiceException


getGroup

Return the configured group model instance.

public getGroup(): \PhalconKit\Models\Interfaces\GroupInterface

Return Value:

Cached instance for Group::class.

Throws:

When the configured model does not implement the group model contract. - ServiceException


getGroupRole

Return the configured group-role model instance.

public getGroupRole(): \PhalconKit\Models\Interfaces\GroupRoleInterface

Return Value:

Cached instance for GroupRole::class.

Throws:

When the configured model does not implement the group-role model contract. - ServiceException


getGroupType

Return the configured group-type model instance.

public getGroupType(): \PhalconKit\Models\Interfaces\GroupTypeInterface

Return Value:

Cached instance for GroupType::class.

Throws:

When the configured model does not implement the group-type model contract. - ServiceException


getGroupFeature

Return the configured group-feature model instance.

public getGroupFeature(): \PhalconKit\Models\Interfaces\GroupFeatureInterface

Return Value:

Cached instance for GroupFeature::class.

Throws:

When the configured model does not implement the group-feature model contract. - ServiceException


getType

Return the configured type model instance.

public getType(): \PhalconKit\Models\Interfaces\TypeInterface

Return Value:

Cached instance for Type::class.

Throws:

When the configured model does not implement the type model contract. - ServiceException


getFeature

Return the configured feature model instance.

public getFeature(): \PhalconKit\Models\Interfaces\FeatureInterface

Return Value:

Cached instance for Feature::class.

Throws:

When the configured model does not implement the feature model contract. - ServiceException


Inherited methods

getDI

Return the DI container used to resolve config-backed mappings.

public getDI(): \Phalcon\Di\DiInterface

Implemented by PhalconKit\Di\Injectable consumers.

  • This method is abstract.

getConfig

Resolve the bootstrap config used for model class mappings.

public getConfig(): \PhalconKit\Bootstrap\Config

The backing DI must be a PhalconKit DI because model mapping is a framework-level integration point and should fail consistently when a native-only container is accidentally used.

Return Value:

Bootstrap config service.

Throws:

When the DI container or config service cannot be resolved through the PhalconKit DI contract. - ServiceException


setModelsMap

Replace the model mapping or load it from configuration.

public setModelsMap(array<string,string>|null $modelsMap = null): void

Passing an explicit array lets tests and service providers avoid a config lookup. Passing null loads models from the bootstrap config service and stores an empty array when no mapping is configured.

Parameters:

Parameter Type Description
$modelsMap array|null Mapping of core class names
to replacement class names, or null to load from config.

Throws:

When the config-backed mapping cannot be loaded. - ServiceException


getModelsMap

Return the currently configured model class map.

public getModelsMap(): array<string,string>

Return Value:

Mapping of original core class names to the class names that should be instantiated or referenced.


setClassMap

Add or replace one model class mapping.

public setClassMap(string $map, string $class): void

Parameters:

Parameter Type Description
$map string Original core class name or logical map key.
$class string Replacement class name to return for that key.

removeClassMap

Remove one model class mapping.

public removeClassMap(string $map): void

After removal, getClassMap() falls back to returning the requested class/key unchanged.

Parameters:

Parameter Type Description
$map string Original core class name or logical map key to remove.

getClassMap

Return the mapped class name for a core class or fallback to itself.

public getClassMap(string $class): string

Parameters:

Parameter Type Description
$class string Original core class name or logical map key.

Return Value:

Replacement class name when configured; otherwise the original value.


getBackupClass

Return the configured backup model class.

public getBackupClass(): string

Return Value:

Replacement for Backup::class, or the core class when no mapping is configured.


getAuditClass

Return the configured audit model class.

public getAuditClass(): string

Return Value:

Replacement for Audit::class, or the core class when no mapping is configured.


getAuditDetailClass

Return the configured audit-detail model class.

public getAuditDetailClass(): string

Return Value:

Replacement for AuditDetail::class, or the core class when no mapping is configured.


getLogClass

Return the configured log model class.

public getLogClass(): string

Return Value:

Replacement for Log::class, or the core class when no mapping is configured.


getEmailClass

Return the configured email model class.

public getEmailClass(): string

Return Value:

Replacement for Email::class, or the core class when no mapping is configured.


getJobClass

Return the configured job model class.

public getJobClass(): string

Return Value:

Replacement for Job::class, or the core class when no mapping is configured.


getFileClass

Return the configured file model class.

public getFileClass(): string

Return Value:

Replacement for File::class, or the core class when no mapping is configured.


getSessionClass

Return the configured session model class.

public getSessionClass(): string

Return Value:

Replacement for Session::class, or the core class when no mapping is configured.


getFlagClass

Return the configured flag model class.

public getFlagClass(): string

Return Value:

Replacement for Flag::class, or the core class when no mapping is configured.


getSettingClass

Return the configured setting model class.

public getSettingClass(): string

Return Value:

Replacement for Setting::class, or the core class when no mapping is configured.


getLangClass

Return the configured language model class.

public getLangClass(): string

Return Value:

Replacement for Lang::class, or the core class when no mapping is configured.


getTranslateClass

Return the configured translate model class.

public getTranslateClass(): string

Return Value:

Replacement for Translate::class, or the core class when no mapping is configured.


getWorkspaceClass

Return the configured workspace model class.

public getWorkspaceClass(): string

Return Value:

Replacement for Workspace::class, or the core class when no mapping is configured.


getWorkspaceLangClass

Return the configured workspace-language model class.

public getWorkspaceLangClass(): string

Return Value:

Replacement for WorkspaceLang::class, or the core class when no mapping is configured.


getPageClass

Return the configured page model class.

public getPageClass(): string

Return Value:

Replacement for Page::class, or the core class when no mapping is configured.


getPostClass

Return the configured post model class.

public getPostClass(): string

Return Value:

Replacement for Post::class, or the core class when no mapping is configured.


getTemplateClass

Return the configured template model class.

public getTemplateClass(): string

Return Value:

Replacement for Template::class, or the core class when no mapping is configured.


getTableClass

Return the configured table model class.

public getTableClass(): string

Return Value:

Replacement for Table::class, or the core class when no mapping is configured.


getProfileClass

Return the configured profile model class.

public getProfileClass(): string

Return Value:

Replacement for Profile::class, or the core class when no mapping is configured.


getOauth2Class

Return the configured OAuth2 model class.

public getOauth2Class(): string

Return Value:

Replacement for Oauth2::class, or the core class when no mapping is configured.


getUserClass

Return the configured user model class.

public getUserClass(): string

Return Value:

Replacement for User::class, or the core class when no mapping is configured.


getUserTypeClass

Return the configured user-type model class.

public getUserTypeClass(): string

Return Value:

Replacement for UserType::class, or the core class when no mapping is configured.


getUserGroupClass

Return the configured user-group model class.

public getUserGroupClass(): string

Return Value:

Replacement for UserGroup::class, or the core class when no mapping is configured.


getUserRoleClass

Return the configured user-role model class.

public getUserRoleClass(): string

Return Value:

Replacement for UserRole::class, or the core class when no mapping is configured.


getUserFeatureClass

Return the configured user-feature model class.

public getUserFeatureClass(): string

Return Value:

Replacement for UserFeature::class, or the core class when no mapping is configured.


getRoleClass

Return the configured role model class.

public getRoleClass(): string

Return Value:

Replacement for Role::class, or the core class when no mapping is configured.


getRoleRoleClass

Return the configured role-role model class.

public getRoleRoleClass(): string

Return Value:

Replacement for RoleRole::class, or the core class when no mapping is configured.


getRoleFeatureClass

Return the configured role-feature model class.

public getRoleFeatureClass(): string

Return Value:

Replacement for RoleFeature::class, or the core class when no mapping is configured.


getGroupClass

Return the configured group model class.

public getGroupClass(): string

Return Value:

Replacement for Group::class, or the core class when no mapping is configured.


getGroupRoleClass

Return the configured group-role model class.

public getGroupRoleClass(): string

Return Value:

Replacement for GroupRole::class, or the core class when no mapping is configured.


getGroupTypeClass

Return the configured group-type model class.

public getGroupTypeClass(): string

Return Value:

Replacement for GroupType::class, or the core class when no mapping is configured.


getGroupFeatureClass

Return the configured group-feature model class.

public getGroupFeatureClass(): string

Return Value:

Replacement for GroupFeature::class, or the core class when no mapping is configured.


getTypeClass

Return the configured type model class.

public getTypeClass(): string

Return Value:

Replacement for Type::class, or the core class when no mapping is configured.


getFeatureClass

Return the configured feature model class.

public getFeatureClass(): string

Return Value:

Replacement for Feature::class, or the core class when no mapping is configured.