Skip to content

Phalcon contracts

NOTE

All classes are prefixed with Phalcon

Contracts\Auth\Access\Access

Interface Source on GitHub

  • Phalcon\Contracts\Auth\Access\Access

Method Summary

Methods

Public · 7

allowedIf()

public function allowedIf(): bool;

getExceptActions()

public function getExceptActions(): array;

getOnlyActions()

public function getOnlyActions(): array;

isAllowed()

public function isAllowed( string $actionName ): bool;

redirectTo()

public function redirectTo(): array|null;

setExceptActions()

public function setExceptActions( array $exceptActions = [] ): void;

setOnlyActions()

public function setOnlyActions( array $onlyActions = [] ): void;

Contracts\Auth\Adapter\Adapter

Interface Source on GitHub

Authentication adapter contract.

Adapters look users up by credentials or by identifier and verify the password against the stored hash. The credential payload is intentionally unsealed: any user-row field may be used as the lookup key, plus an optional password entry that is ignored during the row match and consumed only by validateCredentials().

Uses Phalcon\Contracts\Auth\AuthUser · Phalcon\Contracts\Encryption\Security\Security

Method Summary

Methods

Public · 4

fromOptions()

public static function fromOptions(
    Security $hasher,
    array $options
): static;

Build an adapter from a flat options map. Used by ManagerFactory to wire adapters from the application config; each implementation is free to interpret the option keys it cares about.

retrieveByCredentials()

public function retrieveByCredentials( array $credentials ): AuthUser|null;

Find a user matching the given credentials (e.g. ['email' => 'a@b']). The 'password' key, if present, is ignored during the lookup. Returns null if no user matches.

retrieveById()

public function retrieveById( mixed $id ): AuthUser|null;

Find a user by their unique identifier.

validateCredentials()

public function validateCredentials(
    AuthUser $user,
    array $credentials
): bool;

Validate the provided credentials against the given user. Implementations typically verify the password hash held under the 'password' key.

Contracts\Auth\Adapter\AdapterConfig

Interface Source on GitHub

Authentication adapter configuration contract.

Per-adapter config shape is intentionally adapter-specific (e.g. Stream exposes getFile(), Memory exposes getUsers()); the only field shared across all adapters is the optional model class used during user hydration.

  • Phalcon\Contracts\Auth\Adapter\AdapterConfig

Method Summary

Methods

Public · 1

getModel()

public function getModel(): string|null;

Returns the user-model class name to hydrate, if configured.

Contracts\Auth\Adapter\RememberAdapter

Interface Source on GitHub

Capability extension implemented by adapters that support remember-me.

Uses Phalcon\Contracts\Auth\AuthUser · Phalcon\Contracts\Auth\RememberToken

Method Summary

Methods

Public · 2

createRememberToken()

public function createRememberToken( AuthUser $user ): RememberToken;

Create and persist a new remember token for the user.

retrieveByToken()

public function retrieveByToken(
    mixed $id,
    string $token,
    string $userAgent = null
): AuthUser|null;

Retrieve a user by the remember-me cookie payload.

Contracts\Auth\AuthRemember

Interface Source on GitHub

Implemented by authenticatable models that support remember-me tokens. This is intentionally separate from AuthUser so that adapters which do not support remember-me are not forced to implement it.

  • Phalcon\Contracts\Auth\AuthRemember

Method Summary

Methods

Public · 2

createRememberToken()

public function createRememberToken(
    string $token,
    string $userAgent = null
): RememberToken;

Persists a new remember token for the user.

getRememberToken()

public function getRememberToken( string $token ): RememberToken|null;

Returns the remember token entry matching the given token value, or null if not found.

Contracts\Auth\AuthUser

Interface Source on GitHub

Implemented by user models that can be authenticated.

  • Phalcon\Contracts\Auth\AuthUser

Method Summary

Methods

Public · 2

getAuthIdentifier()

public function getAuthIdentifier(): int|string;

Returns the unique identifier for the authenticatable user (e.g. the primary key). Implementations MUST return a non-null scalar; if a record cannot produce one, the implementation should fail at construction time rather than returning null.

getAuthPassword()

public function getAuthPassword(): string;

Returns the hashed password for the authenticatable user.

Contracts\Auth\Guard\BasicAuth

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been influenced by sinbadxiii/cphalcon-auth @link https://github.com/sinbadxiii/cphalcon-auth

  • Phalcon\Contracts\Auth\Guard\BasicAuth

Uses Phalcon\Contracts\Auth\AuthUser

Method Summary

Methods

Public · 2

basic()

public function basic(
    string $field = "email",
    array $extraConditions = []
): bool;

Authenticate against HTTP Basic credentials. Returns true on success.

onceBasic()

public function onceBasic(
    string $field = "email",
    array $extraConditions = []
): false|AuthUser;

Like basic() but does not persist; returns the resolved user on success or false on failure.

Contracts\Auth\Guard\Guard

Interface Source on GitHub

  • Phalcon\Contracts\Auth\Guard\Guard

Uses Phalcon\Contracts\Auth\Adapter\Adapter · Phalcon\Contracts\Auth\AuthUser · Phalcon\Contracts\Container\Service\Collection

Method Summary

Methods

Public · 9

check()

public function check(): bool;

Whether the current request is authenticated.

fromOptions()

public static function fromOptions(
    Adapter $adapter,
    Collection $container,
    array $options
): static;

Build a guard from an adapter, the application container, and a flat options map. Used by ManagerFactory to wire guards from the application config; each implementation resolves the framework services it needs from the container.

getLastUserAttempted()

public function getLastUserAttempted(): AuthUser|null;

Returns the last user the guard tried to authenticate during this request, regardless of success.

guest()

public function guest(): bool;

Whether the current request is unauthenticated.

hasUser()

public function hasUser(): bool;

Whether the guard currently holds a resolved user.

id()

public function id(): int|string|null;

Returns the authenticated user's identifier, or null when no authenticated user is present.

setUser()

public function setUser( AuthUser $user ): static;

Sets the current user explicitly. Returns $this for fluent chaining.

user()

public function user(): AuthUser|null;

Returns the resolved user for the current request, or null.

validate()

public function validate( array $credentials = [] ): bool;

Validates the given credentials without logging in.

Contracts\Auth\Guard\GuardConfig

Interface Source on GitHub

Authentication guard configuration contract.

Per-guard config shape is intentionally guard-specific (e.g. Token exposes getInputKey()/getStorageKey(); Session has no required config today). The contract carries no methods of its own - it only marks the type so AbstractGuard can accept any guard config uniformly.

  • Phalcon\Contracts\Auth\Guard\GuardConfig

Contracts\Auth\Guard\GuardStateful

Interface Source on GitHub

Implemented by guards backed by persistent state (sessions/cookies).

  • Phalcon\Contracts\Auth\Guard\GuardStateful

Uses Phalcon\Contracts\Auth\Adapter\Adapter · Phalcon\Contracts\Auth\AuthUser

Method Summary

Methods

Public · 5

attempt()

public function attempt(
    array $credentials = [],
    bool $remember = false
): bool;

Attempts to authenticate the user with the given credentials and, on success, persists the resulting state on the guard.

login()

public function login(
    AuthUser $user,
    bool $remember = false
): void;

loginById()

public function loginById(
    mixed $id,
    bool $remember = false
): false|AuthUser;

Logs in the user identified by $id. Returns the resolved user on success or false when no user matches the id.

logout()

public function logout(): void;

viaRemember()

public function viaRemember(): bool;

Contracts\Auth\Manager

Interface Source on GitHub

  • Phalcon\Contracts\Auth\Manager

Uses Phalcon\Auth\Exception · Phalcon\Contracts\Auth\Access\Access · Phalcon\Contracts\Auth\Adapter\Adapter · Phalcon\Contracts\Auth\Guard\Guard

Method Summary

Methods

Public · 18

access()

public function access( string $accessName ): self;

addAccessList()

public function addAccessList( array $accessList ): self;

addGuard()

public function addGuard(
    string $nameGuard,
    Guard $guard,
    bool $isDefault = false
): self;

attempt()

public function attempt(
    array $credentials = [],
    bool $remember = false
): bool;

check()

public function check(): bool;

Whether the default guard reports the current request as authenticated.

except()

public function except( string $actions ): self;

Restricts the active access gate to skip the listed action names.

getAccess()

public function getAccess(): Access|null;

getAccessList()

public function getAccessList(): array;

getDefaultGuard()

public function getDefaultGuard(): Guard|null;

getGuards()

public function getGuards(): array;

guard()

public function guard( string $name = null ): Guard;

Returns the named guard, or the default guard when $name is null.

id()

public function id(): int|string|null;

Returns the authenticated user's identifier from the default guard, or null when no authenticated user is present.

logout()

public function logout(): void;

Logs the current user out via the default guard.

only()

public function only( string $actions ): self;

Restricts the active access gate to apply only to the listed action names.

setAccess()

public function setAccess( Access $access ): self;

setDefaultGuard()

public function setDefaultGuard( Guard $guard ): self;

user()

public function user(): AuthUser|null;

Returns the resolved user from the default guard, or null.

validate()

public function validate( array $credentials = [] ): bool;

Validates the given credentials against the default guard without logging in.

Contracts\Auth\RememberToken

Interface Source on GitHub

A persisted remember-me token row.

  • Phalcon\Contracts\Auth\RememberToken

Method Summary

Methods

Public · 3

delete()

public function delete(): bool;

Deletes the token from storage.

getToken()

public function getToken(): string;

Returns the token value stored for this remember entry.

getUserAgent()

public function getUserAgent(): string|null;

Returns the user agent associated with this token, if any.

Contracts\Container\Ioc\IocContainer

Interface Source on GitHub

[IocContainer][] affords obtaining services by name.

  • Notes:

    • This interface does not afford service management. The container will need to obtain services somehow, e.g. from a [Service-Interop][] implementation.

Method Summary

Methods

Public · 2

getService()

public function getService( string $serviceName ): object;

Returns an instance of the $serviceName.

  • Directives:

    • Implementations MUST throw [IocThrowable][] if the container cannot return an instance of the $serviceName.
  • Notes:

    • The logic for this method is expressly unspecified. Retrieval may be accomplished via a service management subsystem, or by some other means.

    • The returned instance may be new or shared. The retrieval logic defines the service lifetime, not the container (per se) and not the caller requesting the service.

hasService()

public function hasService( string $serviceName ): bool;

Is the container able to return an instance of the $serviceName?

  • Notes:

    • The logic for this method is expressly unspecified. The ability check may be accomplished by querying a service management subsystem, or by some other means.

Contracts\Container\Ioc\IocContainerFactory

Interface Source on GitHub

[IocContainerFactory][] affords obtaining a new instance of [IocContainer][].

  • Phalcon\Contracts\Container\Ioc\IocContainerFactory

Method Summary

Methods

Public · 1

newContainer()

public function newContainer(): IocContainer;

Returns a new instance of [IocContainer][].

  • Notes:

    • Container instantiation logic is not specified. Implementations might use providers, configuration files, attribute or annotation collection, or some other means to create and populate a container. Implementations might also choose to return a compiled or otherwise reconstituted container.

Contracts\Container\Ioc\IocThrowable

Interface Source on GitHub

[IocThrowable][] extends [Throwable][] to mark an [Exception][] as IOC-related.

It adds no class members.

Uses Throwable

Contracts\Container\Ioc\IocTypeAliases

Interface Source on GitHub

  • Phalcon\Contracts\Container\Ioc\IocTypeAliases

Contracts\Container\Resolver\ReflectionMethodResolver

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been heavily influenced by CapsulePHP. Additionally, there are implementations from ioc-interop, which is a Composer dependency, and from service-interop and resolver-interop. They are copied and re-implemented here because we need to support PHP 8.1. Once we move to min 8.4 and packages become available and compatible, the copies will be replaced with the actual Composer dependencies.

@link https://github.com/capsulephp/di @license https://github.com/capsulephp/di/blob/3.x/LICENSE.md

@link https://github.com/ioc-interop/interface @license https://github.com/ioc-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/service-interop/interface @license https://github.com/service-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/resolver-interop/interface/tree/1.x @license https://github.com/resolver-interop/interface/blob/1.x/LICENSE.md

  • Phalcon\Contracts\Container\Resolver\ReflectionMethodResolver

Uses Phalcon\Contracts\Container\Ioc\IocContainer · ReflectionMethod

Method Summary

Methods

Public · 1

resolveMethod()

public function resolveMethod(
    IocContainer $ioc,
    ReflectionMethod $method,
    object $instance
): void;

Contracts\Container\Resolver\ReflectionParameterResolver

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been heavily influenced by CapsulePHP. Additionally, there are implementations from ioc-interop, which is a Composer dependency, and from service-interop and resolver-interop. They are copied and re-implemented here because we need to support PHP 8.1. Once we move to min 8.4 and packages become available and compatible, the copies will be replaced with the actual Composer dependencies.

@link https://github.com/capsulephp/di @license https://github.com/capsulephp/di/blob/3.x/LICENSE.md

@link https://github.com/ioc-interop/interface @license https://github.com/ioc-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/service-interop/interface @license https://github.com/service-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/resolver-interop/interface/tree/1.x @license https://github.com/resolver-interop/interface/blob/1.x/LICENSE.md

Uses Phalcon\Contracts\Container\Ioc\IocContainer · ReflectionParameter

Method Summary

Methods

Public · 1

resolveParameter()

public function resolveParameter(
    IocContainer $ioc,
    ReflectionParameter $parameter
): mixed;

Contracts\Container\Resolver\Resolvable

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been heavily influenced by CapsulePHP. Additionally, there are implementations from ioc-interop, which is a Composer dependency, and from service-interop and resolver-interop. They are copied and re-implemented here because we need to support PHP 8.1. Once we move to min 8.4 and packages become available and compatible, the copies will be replaced with the actual Composer dependencies.

@link https://github.com/capsulephp/di @license https://github.com/capsulephp/di/blob/3.x/LICENSE.md

@link https://github.com/ioc-interop/interface @license https://github.com/ioc-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/service-interop/interface @license https://github.com/service-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/resolver-interop/interface/tree/1.x @license https://github.com/resolver-interop/interface/blob/1.x/LICENSE.md

  • Phalcon\Contracts\Container\Resolver\Resolvable

Uses Phalcon\Contracts\Container\Ioc\IocContainer

Method Summary

Methods

Public · 1

resolve()

public function resolve( IocContainer $ioc ): mixed;

Contracts\Container\Resolver\ResolverService

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been heavily influenced by CapsulePHP. Additionally, there are implementations from ioc-interop, which is a Composer dependency, and from service-interop and resolver-interop. They are copied and re-implemented here because we need to support PHP 8.1. Once we move to min 8.4 and packages become available and compatible, the copies will be replaced with the actual Composer dependencies.

@link https://github.com/capsulephp/di @license https://github.com/capsulephp/di/blob/3.x/LICENSE.md

@link https://github.com/ioc-interop/interface @license https://github.com/ioc-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/service-interop/interface @license https://github.com/service-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/resolver-interop/interface/tree/1.x @license https://github.com/resolver-interop/interface/blob/1.x/LICENSE.md

Uses Phalcon\Contracts\Container\Ioc\IocContainer · ReflectionMethod · ReflectionParameter · ReflectionType

Method Summary

Methods

Public · 6

isResolvableClass()

public function isResolvableClass( string $className ): bool;

resolveCall()

public function resolveCall(
    IocContainer $ioc,
    callable $callableObject,
    array $arguments
): mixed;

resolveClass()

public function resolveClass(
    IocContainer $ioc,
    string $className,
    array $arguments
): object;

resolveMethod()

public function resolveMethod(
    IocContainer $ioc,
    ReflectionMethod $method,
    object $instance
): void;

resolveParameters()

public function resolveParameters(
    IocContainer $ioc,
    array $parameters,
    array $arguments
): array;

resolveType()

public function resolveType(
    IocContainer $ioc,
    ReflectionType $type
): mixed;

Contracts\Container\Resolver\ResolverThrowable

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been heavily influenced by CapsulePHP. Additionally, there are implementations from ioc-interop, which is a Composer dependency, and from service-interop and resolver-interop. They are copied and re-implemented here because we need to support PHP 8.1. Once we move to min 8.4 and packages become available and compatible, the copies will be replaced with the actual Composer dependencies.

@link https://github.com/capsulephp/di @license https://github.com/capsulephp/di/blob/3.x/LICENSE.md

@link https://github.com/ioc-interop/interface @license https://github.com/ioc-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/service-interop/interface @license https://github.com/service-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/resolver-interop/interface/tree/1.x @license https://github.com/resolver-interop/interface/blob/1.x/LICENSE.md

  • Throwable
    • Phalcon\Contracts\Container\Resolver\ResolverThrowable

Uses Throwable

Contracts\Container\Service\Collection

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been heavily influenced by CapsulePHP. Additionally, there are implementations from ioc-interop, which is a Composer dependency, and from service-interop and resolver-interop. They are copied and re-implemented here because we need to support PHP 8.1. Once we move to min 8.4 and packages become available and compatible, the copies will be replaced with the actual Composer dependencies.

@link https://github.com/capsulephp/di @license https://github.com/capsulephp/di/blob/3.x/LICENSE.md

@link https://github.com/ioc-interop/interface @license https://github.com/ioc-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/service-interop/interface @license https://github.com/service-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/resolver-interop/interface/tree/1.x @license https://github.com/resolver-interop/interface/blob/1.x/LICENSE.md

Uses Closure · Phalcon\Container\Definition\ServiceDefinition · Phalcon\Container\Resolver\Resolver · Phalcon\Contracts\Container\Ioc\IocContainer

Method Summary

Methods

Public · 30

bind()

public function bind(
    string $interfaceName,
    string $concrete
): ServiceDefinition;

callableGet()

public function callableGet( string $name ): Closure;

callableNew()

public function callableNew( string $name ): Closure;

extend()

public function extend(
    string $name,
    callable $callableObject
): void;

get()

public function get( string $name ): mixed;

getAlias()

public function getAlias( string $name ): string;

getByTag()

public function getByTag( string $tag ): array;

getDefinition()

public function getDefinition( string $name ): ServiceDefinition;

getInstance()

public function getInstance( string $name ): object;

getParameter()

public function getParameter( string $name ): mixed;

getResolver()

public function getResolver(): Resolver;

has()

public function has( string $name ): bool;

hasAlias()

public function hasAlias( string $name ): bool;

hasDefinition()

public function hasDefinition( string $name ): bool;

hasInstance()

public function hasInstance( string $name ): bool;

hasParameter()

public function hasParameter( string $name ): bool;

isAutowireEnabled()

public function isAutowireEnabled(): bool;

new()

public function new( string $name ): mixed;

newDefinition()

public function newDefinition( string $name ): ServiceDefinition;

set()

public function set(
    string $name,
    mixed $definition
): ServiceDefinition;

setAlias()

public function setAlias(
    string $name,
    string $alias
): static;

setAutowire()

public function setAutowire( bool $enabled ): static;

setDefinition()

public function setDefinition(
    string $name,
    ServiceDefinition $definition
): static;

setInstance()

public function setInstance(
    string $name,
    object $instance,
    string $lifetime
): static;

setParameter()

public function setParameter(
    string $name,
    mixed $value
): static;

unsetAlias()

public function unsetAlias( string $name ): void;

unsetDefinition()

public function unsetDefinition( string $name ): void;

unsetInstance()

public function unsetInstance( string $name ): void;

unsetInstances()

public function unsetInstances( string $lifetime ): void;

unsetParameter()

public function unsetParameter( string $name ): void;

Contracts\Container\Service\Definition

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been heavily influenced by CapsulePHP. Additionally, there are implementations from ioc-interop, which is a Composer dependency, and from service-interop and resolver-interop. They are copied and re-implemented here because we need to support PHP 8.1. Once we move to min 8.4 and packages become available and compatible, the copies will be replaced with the actual Composer dependencies.

@link https://github.com/capsulephp/di @license https://github.com/capsulephp/di/blob/3.x/LICENSE.md

@link https://github.com/ioc-interop/interface @license https://github.com/ioc-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/service-interop/interface @license https://github.com/service-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/resolver-interop/interface/tree/1.x @license https://github.com/resolver-interop/interface/blob/1.x/LICENSE.md

  • Phalcon\Contracts\Container\Service\Definition

Uses Phalcon\Contracts\Container\Ioc\IocContainer

Method Summary

Methods

Public · 17

addExtender()

public function addExtender( callable $extender ): static;

buildService()

public function buildService( IocContainer $ioc ): object;

getClass()

public function getClass(): string;

getExtenders()

public function getExtenders(): array;

getFactory()

public function getFactory(): callable;

getLifetime()

public function getLifetime(): string;

getServiceName()

public function getServiceName(): string;

hasClass()

public function hasClass(): bool;

hasExtenders()

public function hasExtenders(): bool;

hasFactory()

public function hasFactory(): bool;

setClass()

public function setClass( string $className ): static;

setExtenders()

public function setExtenders( array $extenders ): static;

setFactory()

public function setFactory( callable $factory ): static;

setLifetime()

public function setLifetime( string $lifetime ): static;

unsetClass()

public function unsetClass(): static;

unsetExtenders()

public function unsetExtenders(): static;

unsetFactory()

public function unsetFactory(): static;

Contracts\Container\Service\Provider

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been heavily influenced by CapsulePHP. Additionally, there are implementations from ioc-interop, which is a Composer dependency, and from service-interop and resolver-interop. They are copied and re-implemented here because we need to support PHP 8.1. Once we move to min 8.4 and packages become available and compatible, the copies will be replaced with the actual Composer dependencies.

@link https://github.com/capsulephp/di @license https://github.com/capsulephp/di/blob/3.x/LICENSE.md

@link https://github.com/ioc-interop/interface @license https://github.com/ioc-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/service-interop/interface @license https://github.com/service-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/resolver-interop/interface/tree/1.x @license https://github.com/resolver-interop/interface/blob/1.x/LICENSE.md

  • Phalcon\Contracts\Container\Service\Provider

Method Summary

Methods

Public · 1

provide()

public function provide( Collection $services ): void;

Contracts\Container\Service\Throwable

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Implementation of this file has been heavily influenced by CapsulePHP. Additionally, there are implementations from ioc-interop, which is a Composer dependency, and from service-interop and resolver-interop. They are copied and re-implemented here because we need to support PHP 8.1. Once we move to min 8.4 and packages become available and compatible, the copies will be replaced with the actual Composer dependencies.

@link https://github.com/capsulephp/di @license https://github.com/capsulephp/di/blob/3.x/LICENSE.md

@link https://github.com/ioc-interop/interface @license https://github.com/ioc-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/service-interop/interface @license https://github.com/service-interop/interface/blob/1.x/LICENSE.md

@link https://github.com/resolver-interop/interface/tree/1.x @license https://github.com/resolver-interop/interface/blob/1.x/LICENSE.md

  • PhpThrowable
    • Phalcon\Contracts\Container\Service\Throwable

Uses Throwable

Contracts\Db\Adapter\Adapter

Interface Source on GitHub

Canonical contract for Phalcon\Db adapters.

@todo v7 - these will become required interface members. They are omitted from the v5 line to avoid breaking third-party implementors: - addCheck() : bool - createMaterializedView() : bool - dropCheck() : bool - dropMaterializedView() : bool - onConflictUpdate() : string - refreshMaterializedView() : bool - returning() : string

Uses Phalcon\Db\ColumnInterface · Phalcon\Db\DialectInterface · Phalcon\Db\IndexInterface · Phalcon\Db\RawValue · Phalcon\Db\ReferenceInterface · Phalcon\Db\ResultInterface

Method Summary

public bool addColumn(string $tableName,string $schemaName,ColumnInterface $column) Adds a column to a table public bool addForeignKey(string $tableName,string $schemaName,ReferenceInterface $reference) Adds a foreign key to a table public bool addIndex(string $tableName,string $schemaName,IndexInterface $index) Adds an index to a table public bool addPrimaryKey(string $tableName,string $schemaName,IndexInterface $index) Adds a primary key to a table public int affectedRows() Returns the number of affected rows by the last INSERT/UPDATE/DELETE public bool begin( bool $nesting = true ) Starts a transaction in the connection public void close() Closes active connection returning success. Phalcon automatically closes public bool commit( bool $nesting = true ) Commits the active transaction in the connection public void connect( array $descriptor = [] ) This method is automatically called in \Phalcon\Db\Adapter\Pdo public bool createSavepoint( string $name ) Creates a new savepoint public bool createTable(string $tableName,string $schemaName,array $definition) Creates a table public bool createView(string $viewName,array $definition,string $schemaName = null) Creates a view public bool delete(mixed $table,string $whereCondition = null,array $placeholders = [],array $dataTypes = []) Deletes data from a table using custom RDBMS SQL syntax public ColumnInterface[] describeColumns(string $table,string $schema = null) Returns an array of Phalcon\Db\Column objects describing a table public IndexInterface[] describeIndexes(string $table,string $schema = null) Lists table indexes public ReferenceInterface[] describeReferences(string $table,string $schema = null) Lists table references public bool dropColumn(string $tableName,string $schemaName,string $columnName) Drops a column from a table public bool dropForeignKey(string $tableName,string $schemaName,string $referenceName) Drops a foreign key from a table public bool dropIndex(string $tableName,string $schemaName,string $indexName) Drop an index from a table public bool dropPrimaryKey(string $tableName,string $schemaName) Drops primary key from a table public bool dropTable(string $tableName,string $schemaName = null,bool $ifExists = true) Drops a table from a schema/database public bool dropView(string $viewName,string $schemaName = null,bool $ifExists = true) Drops a view public string escapeIdentifier( mixed $identifier ) Escapes a column/table/schema name public string escapeString( string $str ) Escapes a value to avoid SQL injections public bool execute(string $sqlStatement,array $bindParams = [],array $bindTypes = []) Sends SQL statements to the database server returning the success state. public array fetchAll(string $sqlQuery,int $fetchMode = 2,array $bindParams = [],array $bindTypes = []) Dumps the complete result of a query into an array public string|bool fetchColumn(string $sqlQuery,array $placeholders = [],mixed $column = 0) Returns the n'th field of first row in a SQL query result public array fetchOne(string $sqlQuery,int $fetchMode = 2,array $bindParams = [],array $bindTypes = []) Returns the first row in a SQL query result public string forUpdate(string $sqlQuery,string $modifier = "") Returns a SQL modified with a FOR UPDATE clause. The optional modifier public string getColumnDefinition( ColumnInterface $column ) Returns the SQL column definition from a column public string getColumnList( mixed $columnList ) Gets a list of columns public int getConnectionId() Gets the active connection unique identifier public RawValue getDefaultIdValue() Return the default identity value to insert in an identity column public RawValue|null getDefaultValue() Returns the default value to make the RBDM use the default value declared public array getDescriptor() Return descriptor used to connect to the active database public DialectInterface getDialect() Returns internal dialect instance public string getDialectType() Returns the name of the dialect used public mixed getInternalHandler() Return internal PDO handler public string getNestedTransactionSavepointName() Returns the savepoint name to use for nested transactions public string getRealSQLStatement() Active SQL statement in the object without replace bound parameters public array getSQLBindTypes() Active SQL statement in the object public string getSQLStatement() Active SQL statement in the object public array getSQLVariables() Active SQL statement in the object public string getType() Returns type of database system the adapter is used for public bool insert(string $table,array $values,mixed $fields = null,mixed $dataTypes = null) Inserts data into a table using custom RDBMS SQL syntax public bool insertAsDict(string $table,mixed $data,mixed $dataTypes = null) Inserts data into a table using custom RBDM SQL syntax public bool isNestedTransactionsWithSavepoints() Returns if nested transactions should use savepoints public bool isUnderTransaction() Checks whether connection is under database transaction public string|bool lastInsertId( string $name = null ) Returns insert id for the auto_increment column inserted in the last SQL public string limit(string $sqlQuery,mixed $number) Appends a LIMIT clause to sqlQuery argument public array listTables( string $schemaName = null ) List all tables on a database public array listViews( string $schemaName = null ) List all views on a database public bool modifyColumn(string $tableName,string $schemaName,ColumnInterface $column,ColumnInterface $currentColumn = null) Modifies a table column based on a definition public ResultInterface|bool query(string $sqlStatement,array $bindParams = [],array $bindTypes = []) Sends SQL statements to the database server returning the success state. public bool releaseSavepoint( string $name ) Releases given savepoint public bool rollback( bool $nesting = true ) Rollbacks the active transaction in the connection public bool rollbackSavepoint( string $name ) Rollbacks given savepoint public \Phalcon\Db\Adapter\AdapterInterface setNestedTransactionsWithSavepoints( bool $nestedTransactionsWithSavepoints ) Set if nested transactions should use savepoints public string sharedLock(string $sqlQuery,string $modifier = "") Returns a SQL modified with a shared-lock clause. See the dialect's public bool supportSequences() Check whether the database system requires a sequence to produce public bool supportsDefaultValue() SQLite does not support the DEFAULT keyword public bool tableExists(string $tableName,string $schemaName = null) Generates SQL checking for the existence of a schema.table public array tableOptions(string $tableName,string $schemaName = null) Gets creation options from a table public bool update(string $table,mixed $fields,mixed $values,mixed $whereCondition = null,mixed $dataTypes = null) Updates data on a table using custom RDBMS SQL syntax public bool updateAsDict(string $table,mixed $data,mixed $whereCondition = null,mixed $dataTypes = null) Updates data on a table using custom RBDM SQL syntax public bool useExplicitIdValue() Check whether the database system requires an explicit value for identity public bool viewExists(string $viewName,string $schemaName = null) Generates SQL checking for the existence of a schema.view

Methods

Public · 67

addColumn()

public function addColumn(
    string $tableName,
    string $schemaName,
    ColumnInterface $column
): bool;

Adds a column to a table

addForeignKey()

public function addForeignKey(
    string $tableName,
    string $schemaName,
    ReferenceInterface $reference
): bool;

Adds a foreign key to a table

addIndex()

public function addIndex(
    string $tableName,
    string $schemaName,
    IndexInterface $index
): bool;

Adds an index to a table

addPrimaryKey()

public function addPrimaryKey(
    string $tableName,
    string $schemaName,
    IndexInterface $index
): bool;

Adds a primary key to a table

affectedRows()

public function affectedRows(): int;

Returns the number of affected rows by the last INSERT/UPDATE/DELETE reported by the database system

begin()

public function begin( bool $nesting = true ): bool;

Starts a transaction in the connection

close()

public function close(): void;

Closes active connection returning success. Phalcon automatically closes and destroys active connections within Phalcon\Db\Pool

commit()

public function commit( bool $nesting = true ): bool;

Commits the active transaction in the connection

connect()

public function connect( array $descriptor = [] ): void;

This method is automatically called in \Phalcon\Db\Adapter\Pdo constructor. Call it when you need to restore a database connection

createSavepoint()

public function createSavepoint( string $name ): bool;

Creates a new savepoint

createTable()

public function createTable(
    string $tableName,
    string $schemaName,
    array $definition
): bool;

Creates a table

createView()

public function createView(
    string $viewName,
    array $definition,
    string $schemaName = null
): bool;

Creates a view

delete()

public function delete(
    mixed $table,
    string $whereCondition = null,
    array $placeholders = [],
    array $dataTypes = []
): bool;

Deletes data from a table using custom RDBMS SQL syntax

describeColumns()

public function describeColumns(
    string $table,
    string $schema = null
): ColumnInterface[];

Returns an array of Phalcon\Db\Column objects describing a table

describeIndexes()

public function describeIndexes(
    string $table,
    string $schema = null
): IndexInterface[];

Lists table indexes

describeReferences()

public function describeReferences(
    string $table,
    string $schema = null
): ReferenceInterface[];

Lists table references

dropColumn()

public function dropColumn(
    string $tableName,
    string $schemaName,
    string $columnName
): bool;

Drops a column from a table

dropForeignKey()

public function dropForeignKey(
    string $tableName,
    string $schemaName,
    string $referenceName
): bool;

Drops a foreign key from a table

dropIndex()

public function dropIndex(
    string $tableName,
    string $schemaName,
    string $indexName
): bool;

Drop an index from a table

dropPrimaryKey()

public function dropPrimaryKey(
    string $tableName,
    string $schemaName
): bool;

Drops primary key from a table

dropTable()

public function dropTable(
    string $tableName,
    string $schemaName = null,
    bool $ifExists = true
): bool;

Drops a table from a schema/database

dropView()

public function dropView(
    string $viewName,
    string $schemaName = null,
    bool $ifExists = true
): bool;

Drops a view

escapeIdentifier()

public function escapeIdentifier( mixed $identifier ): string;

Escapes a column/table/schema name

escapeString()

public function escapeString( string $str ): string;

Escapes a value to avoid SQL injections

execute()

public function execute(
    string $sqlStatement,
    array $bindParams = [],
    array $bindTypes = []
): bool;

Sends SQL statements to the database server returning the success state. Use this method only when the SQL statement sent to the server does not return any rows

fetchAll()

public function fetchAll(
    string $sqlQuery,
    int $fetchMode = 2,
    array $bindParams = [],
    array $bindTypes = []
): array;

Dumps the complete result of a query into an array

fetchColumn()

public function fetchColumn(
    string $sqlQuery,
    array $placeholders = [],
    mixed $column = 0
): string|bool;

Returns the n'th field of first row in a SQL query result

// Getting count of robots
$robotsCount = $connection->fetchColumn("SELECT COUNT(*) FROM robots");
print_r($robotsCount);

// Getting name of last edited robot
$robot = $connection->fetchColumn(
    "SELECT id, name FROM robots ORDER BY modified DESC",
    1
);
print_r($robot);

fetchOne()

public function fetchOne(
    string $sqlQuery,
    int $fetchMode = 2,
    array $bindParams = [],
    array $bindTypes = []
): array;

Returns the first row in a SQL query result

forUpdate()

public function forUpdate(
    string $sqlQuery,
    string $modifier = ""
): string;

Returns a SQL modified with a FOR UPDATE clause. The optional modifier appends a row-lock disposition keyword - pass Dialect::LOCK_NOWAIT or Dialect::LOCK_SKIP_LOCKED (or leave as Dialect::LOCK_NONE).

getColumnDefinition()

public function getColumnDefinition( ColumnInterface $column ): string;

Returns the SQL column definition from a column

getColumnList()

public function getColumnList( mixed $columnList ): string;

Gets a list of columns

getConnectionId()

public function getConnectionId(): int;

Gets the active connection unique identifier

getDefaultIdValue()

public function getDefaultIdValue(): RawValue;

Return the default identity value to insert in an identity column

getDefaultValue()

public function getDefaultValue(): RawValue|null;

Returns the default value to make the RBDM use the default value declared in the table definition

// Inserting a new robot with a valid default value for the column 'year'
$success = $connection->insert(
    "robots",
    [
        "Astro Boy",
        $connection->getDefaultValue()
    ],
    [
        "name",
        "year",
    ]
);

@todo Return NULL if this is not supported by the adapter

getDescriptor()

public function getDescriptor(): array;

Return descriptor used to connect to the active database

getDialect()

public function getDialect(): DialectInterface;

Returns internal dialect instance

getDialectType()

public function getDialectType(): string;

Returns the name of the dialect used

getInternalHandler()

public function getInternalHandler(): mixed;

Return internal PDO handler

getNestedTransactionSavepointName()

public function getNestedTransactionSavepointName(): string;

Returns the savepoint name to use for nested transactions

getRealSQLStatement()

public function getRealSQLStatement(): string;

Active SQL statement in the object without replace bound parameters

getSQLBindTypes()

public function getSQLBindTypes(): array;

Active SQL statement in the object

getSQLStatement()

public function getSQLStatement(): string;

Active SQL statement in the object

getSQLVariables()

public function getSQLVariables(): array;

Active SQL statement in the object

getType()

public function getType(): string;

Returns type of database system the adapter is used for

insert()

public function insert(
    string $table,
    array $values,
    mixed $fields = null,
    mixed $dataTypes = null
): bool;

Inserts data into a table using custom RDBMS SQL syntax

insertAsDict()

public function insertAsDict(
    string $table,
    mixed $data,
    mixed $dataTypes = null
): bool;

Inserts data into a table using custom RBDM SQL syntax

// Inserting a new robot
$success = $connection->insertAsDict(
    "robots",
    [
        "name" => "Astro Boy",
        "year" => 1952,
    ]
);

// Next SQL sentence is sent to the database system
INSERT INTO `robots` (`name`, `year`) VALUES ("Astro boy", 1952);

isNestedTransactionsWithSavepoints()

public function isNestedTransactionsWithSavepoints(): bool;

Returns if nested transactions should use savepoints

isUnderTransaction()

public function isUnderTransaction(): bool;

Checks whether connection is under database transaction

lastInsertId()

public function lastInsertId( string $name = null ): string|bool;

Returns insert id for the auto_increment column inserted in the last SQL statement

limit()

public function limit(
    string $sqlQuery,
    mixed $number
): string;

Appends a LIMIT clause to sqlQuery argument

listTables()

public function listTables( string $schemaName = null ): array;

List all tables on a database

listViews()

public function listViews( string $schemaName = null ): array;

List all views on a database

modifyColumn()

public function modifyColumn(
    string $tableName,
    string $schemaName,
    ColumnInterface $column,
    ColumnInterface $currentColumn = null
): bool;

Modifies a table column based on a definition

query()

public function query(
    string $sqlStatement,
    array $bindParams = [],
    array $bindTypes = []
): ResultInterface|bool;

Sends SQL statements to the database server returning the success state. Use this method only when the SQL statement sent to the server returns rows

releaseSavepoint()

public function releaseSavepoint( string $name ): bool;

Releases given savepoint

rollback()

public function rollback( bool $nesting = true ): bool;

Rollbacks the active transaction in the connection

rollbackSavepoint()

public function rollbackSavepoint( string $name ): bool;

Rollbacks given savepoint

setNestedTransactionsWithSavepoints()

public function setNestedTransactionsWithSavepoints( bool $nestedTransactionsWithSavepoints ): \Phalcon\Db\Adapter\AdapterInterface;

Set if nested transactions should use savepoints

sharedLock()

public function sharedLock(
    string $sqlQuery,
    string $modifier = ""
): string;

Returns a SQL modified with a shared-lock clause. See the dialect's sharedLock() for per-engine semantics. The optional modifier is passed straight through (use Dialect::LOCK_NOWAIT / Dialect::LOCK_SKIP_LOCKED for PostgreSQL).

supportSequences()

public function supportSequences(): bool;

Check whether the database system requires a sequence to produce auto-numeric values

supportsDefaultValue()

public function supportsDefaultValue(): bool;

SQLite does not support the DEFAULT keyword

@deprecated Will re removed in the next version

tableExists()

public function tableExists(
    string $tableName,
    string $schemaName = null
): bool;

Generates SQL checking for the existence of a schema.table

tableOptions()

public function tableOptions(
    string $tableName,
    string $schemaName = null
): array;

Gets creation options from a table

update()

public function update(
    string $table,
    mixed $fields,
    mixed $values,
    mixed $whereCondition = null,
    mixed $dataTypes = null
): bool;

Updates data on a table using custom RDBMS SQL syntax

updateAsDict()

public function updateAsDict(
    string $table,
    mixed $data,
    mixed $whereCondition = null,
    mixed $dataTypes = null
): bool;

Updates data on a table using custom RBDM SQL syntax Another, more convenient syntax

// Updating existing robot
$success = $connection->updateAsDict(
    "robots",
    [
        "name" => "New Astro Boy",
    ],
    "id = 101"
);

// Next SQL sentence is sent to the database system
UPDATE `robots` SET `name` = "Astro boy" WHERE id = 101

useExplicitIdValue()

public function useExplicitIdValue(): bool;

Check whether the database system requires an explicit value for identity columns

viewExists()

public function viewExists(
    string $viewName,
    string $schemaName = null
): bool;

Generates SQL checking for the existence of a schema.view

Contracts\Db\Check

Interface Source on GitHub

Canonical contract for Phalcon\Db\Check.

Method Summary

Methods

Public · 2

getExpression()

public function getExpression(): string;

Gets the CHECK expression (the SQL boolean predicate).

getName()

public function getName(): string;

Gets the constraint name. An empty string indicates an unnamed CHECK constraint - the dialect will emit the clause without a CONSTRAINT prefix in that case.

Contracts\Db\Column

Interface Source on GitHub

Canonical contract for Phalcon\Db\Column.

@todo v7 - these will become required interface members. They are omitted from the v5 line to avoid breaking third-party implementors: - getGenerationExpression() : string | null - isArray() : bool - isGenerated() : bool - isGenerationStored() : bool - isInvisible() : bool

Method Summary

Methods

Public · 16

getAfterPosition()

public function getAfterPosition(): string|null;

Check whether field absolute to position in table

getBindType()

public function getBindType(): int;

Returns the type of bind handling

getDefault()

public function getDefault(): mixed;

Returns default value of column

getName()

public function getName(): string;

Returns column name

getScale()

public function getScale(): int;

Returns column scale

getSize()

public function getSize(): int|string;

Returns column size

getType()

public function getType(): int|string;

Returns column type

getTypeReference()

public function getTypeReference(): int;

Returns column type reference

getTypeValues()

public function getTypeValues(): array|string|int;

Returns column type values

hasDefault()

public function hasDefault(): bool;

Check whether column has default value

isAutoIncrement()

public function isAutoIncrement(): bool;

Auto-Increment

isFirst()

public function isFirst(): bool;

Check whether column have first position in table

isNotNull()

public function isNotNull(): bool;

Not null

isNumeric()

public function isNumeric(): bool;

Check whether column have an numeric type

isPrimary()

public function isPrimary(): bool;

Column is part of the primary key?

isUnsigned()

public function isUnsigned(): bool;

Returns true if number column is unsigned

Contracts\Db\Dialect

Interface Source on GitHub

Canonical contract for Phalcon\Db dialects.

@todo v7 - these will become required interface members. They are omitted from the v5 line to avoid breaking third-party implementors: - addCheck() : string - createMaterializedView() : string - dropCheck() : string - dropMaterializedView() : string - onConflictUpdate() : string - refreshMaterializedView() : string - returning() : string

Uses Phalcon\Db\ColumnInterface · Phalcon\Db\IndexInterface · Phalcon\Db\ReferenceInterface

Method Summary

public string addColumn(string $tableName,string $schemaName,ColumnInterface $column) Generates SQL to add a column to a table public string addForeignKey(string $tableName,string $schemaName,ReferenceInterface $reference) Generates SQL to add an index to a table public string addIndex(string $tableName,string $schemaName,IndexInterface $index) Generates SQL to add an index to a table public string addPrimaryKey(string $tableName,string $schemaName,IndexInterface $index) Generates SQL to add the primary key to a table public string createSavepoint( string $name ) Generate SQL to create a new savepoint public string createTable(string $tableName,string $schemaName,array $definition) Generates SQL to create a table public string createView(string $viewName,array $definition,string $schemaName = null) Generates SQL to create a view public string describeColumns(string $table,string $schema = null) Generates SQL to describe a table public string describeIndexes(string $table,string $schema = null) Generates SQL to query indexes on a table public string describeReferences(string $table,string $schema = null) Generates SQL to query foreign keys on a table public string dropColumn(string $tableName,string $schemaName,string $columnName) Generates SQL to delete a column from a table public string dropForeignKey(string $tableName,string $schemaName,string $referenceName) Generates SQL to delete a foreign key from a table public string dropIndex(string $tableName,string $schemaName,string $indexName) Generates SQL to delete an index from a table public string dropPrimaryKey(string $tableName,string $schemaName) Generates SQL to delete primary key from a table public string dropTable(string $tableName,string $schemaName,bool $ifExists = true) Generates SQL to drop a table public string dropView(string $viewName,string $schemaName = null,bool $ifExists = true) Generates SQL to drop a view public string forUpdate(string $sqlQuery,string $modifier = "") Returns a SQL modified with a FOR UPDATE clause. The optional modifier public string getColumnDefinition( ColumnInterface $column ) Gets the column name in RDBMS public string getColumnList( array $columnList ) Gets a list of columns public array getCustomFunctions() Returns registered functions public string getSqlExpression(array $expression,string $escapeChar = null,array $bindCounts = []) Transforms an intermediate representation for an expression into a public string limit(string $sqlQuery,mixed $number) Generates the SQL for LIMIT clause public string listTables( string $schemaName = null ) List all tables in database public string modifyColumn(string $tableName,string $schemaName,ColumnInterface $column,ColumnInterface $currentColumn = null) Generates SQL to modify a column in a table public \Phalcon\Db\Dialect registerCustomFunction(string $name,callable $customFunction) Registers custom SQL functions public string releaseSavepoint( string $name ) Generate SQL to release a savepoint public string rollbackSavepoint( string $name ) Generate SQL to rollback a savepoint public string select( array $definition ) Builds a SELECT statement public string sharedLock(string $sqlQuery,string $modifier = "") Returns a SQL modified with a shared-lock clause. MySQL emits public bool supportsReleaseSavepoints() Checks whether the platform supports releasing savepoints. public bool supportsSavepoints() Checks whether the platform supports savepoints public string tableExists(string $tableName,string $schemaName = null) Generates SQL checking for the existence of a schema.table public string tableOptions(string $table,string $schema = null) Generates the SQL to describe the table creation options public string viewExists(string $viewName,string $schemaName = null) Generates SQL checking for the existence of a schema.view

Constants

string LOCK_NONE = "" No row-lock modifier - the default behavior for forUpdate().
string LOCK_NOWAIT = "NOWAIT" Append NOWAIT to the FOR UPDATE clause - the query fails immediately if a row it needs is locked instead of blocking. MySQL 8.0+ and PostgreSQL 9.5+ recognize this. SQLite has no row-level locking and silently ignores the modifier.
string LOCK_SKIP_LOCKED = "SKIP LOCKED" Append SKIP LOCKED to the FOR UPDATE clause - the query returns rows that are not currently locked and silently skips ones that are. MySQL 8.0+ and PostgreSQL 9.5+ recognize this. SQLite ignores it.

Methods

Public · 34

addColumn()

public function addColumn(
    string $tableName,
    string $schemaName,
    ColumnInterface $column
): string;

Generates SQL to add a column to a table

addForeignKey()

public function addForeignKey(
    string $tableName,
    string $schemaName,
    ReferenceInterface $reference
): string;

Generates SQL to add an index to a table

addIndex()

public function addIndex(
    string $tableName,
    string $schemaName,
    IndexInterface $index
): string;

Generates SQL to add an index to a table

addPrimaryKey()

public function addPrimaryKey(
    string $tableName,
    string $schemaName,
    IndexInterface $index
): string;

Generates SQL to add the primary key to a table

createSavepoint()

public function createSavepoint( string $name ): string;

Generate SQL to create a new savepoint

createTable()

public function createTable(
    string $tableName,
    string $schemaName,
    array $definition
): string;

Generates SQL to create a table

createView()

public function createView(
    string $viewName,
    array $definition,
    string $schemaName = null
): string;

Generates SQL to create a view

describeColumns()

public function describeColumns(
    string $table,
    string $schema = null
): string;

Generates SQL to describe a table

describeIndexes()

public function describeIndexes(
    string $table,
    string $schema = null
): string;

Generates SQL to query indexes on a table

describeReferences()

public function describeReferences(
    string $table,
    string $schema = null
): string;

Generates SQL to query foreign keys on a table

dropColumn()

public function dropColumn(
    string $tableName,
    string $schemaName,
    string $columnName
): string;

Generates SQL to delete a column from a table

dropForeignKey()

public function dropForeignKey(
    string $tableName,
    string $schemaName,
    string $referenceName
): string;

Generates SQL to delete a foreign key from a table

dropIndex()

public function dropIndex(
    string $tableName,
    string $schemaName,
    string $indexName
): string;

Generates SQL to delete an index from a table

dropPrimaryKey()

public function dropPrimaryKey(
    string $tableName,
    string $schemaName
): string;

Generates SQL to delete primary key from a table

dropTable()

public function dropTable(
    string $tableName,
    string $schemaName,
    bool $ifExists = true
): string;

Generates SQL to drop a table

dropView()

public function dropView(
    string $viewName,
    string $schemaName = null,
    bool $ifExists = true
): string;

Generates SQL to drop a view

forUpdate()

public function forUpdate(
    string $sqlQuery,
    string $modifier = ""
): string;

Returns a SQL modified with a FOR UPDATE clause. The optional modifier appends a row-lock disposition keyword - pass Dialect::LOCK_NOWAIT or Dialect::LOCK_SKIP_LOCKED (or leave as Dialect::LOCK_NONE).

getColumnDefinition()

public function getColumnDefinition( ColumnInterface $column ): string;

Gets the column name in RDBMS

getColumnList()

public function getColumnList( array $columnList ): string;

Gets a list of columns

getCustomFunctions()

public function getCustomFunctions(): array;

Returns registered functions

getSqlExpression()

public function getSqlExpression(
    array $expression,
    string $escapeChar = null,
    array $bindCounts = []
): string;

Transforms an intermediate representation for an expression into a database system valid expression

limit()

public function limit(
    string $sqlQuery,
    mixed $number
): string;

Generates the SQL for LIMIT clause

listTables()

public function listTables( string $schemaName = null ): string;

List all tables in database

modifyColumn()

public function modifyColumn(
    string $tableName,
    string $schemaName,
    ColumnInterface $column,
    ColumnInterface $currentColumn = null
): string;

Generates SQL to modify a column in a table

registerCustomFunction()

public function registerCustomFunction(
    string $name,
    callable $customFunction
): \Phalcon\Db\Dialect;

Registers custom SQL functions

releaseSavepoint()

public function releaseSavepoint( string $name ): string;

Generate SQL to release a savepoint

rollbackSavepoint()

public function rollbackSavepoint( string $name ): string;

Generate SQL to rollback a savepoint

select()

public function select( array $definition ): string;

Builds a SELECT statement

sharedLock()

public function sharedLock(
    string $sqlQuery,
    string $modifier = ""
): string;

Returns a SQL modified with a shared-lock clause. MySQL emits LOCK IN SHARE MODE; PostgreSQL emits FOR SHARE; SQLite returns the original query unchanged. The optional modifier appends a row-lock disposition keyword (Dialect::LOCK_NOWAIT / Dialect::LOCK_SKIP_LOCKED) for PostgreSQL - MySQL's legacy LOCK IN SHARE MODE does not support modifiers, so non-empty values are silently ignored on MySQL.

supportsReleaseSavepoints()

public function supportsReleaseSavepoints(): bool;

Checks whether the platform supports releasing savepoints.

supportsSavepoints()

public function supportsSavepoints(): bool;

Checks whether the platform supports savepoints

tableExists()

public function tableExists(
    string $tableName,
    string $schemaName = null
): string;

Generates SQL checking for the existence of a schema.table

tableOptions()

public function tableOptions(
    string $table,
    string $schema = null
): string;

Generates the SQL to describe the table creation options

viewExists()

public function viewExists(
    string $viewName,
    string $schemaName = null
): string;

Generates SQL checking for the existence of a schema.view

Contracts\Db\Index

Interface Source on GitHub

Canonical contract for Phalcon\Db\Index.

@todo v7 - these will become required interface members. They are omitted from the v5 line to avoid breaking third-party implementors: - getDirections() : array - getWhere() : string - isConcurrent() : bool - isInvisible() : bool

Method Summary

Methods

Public · 3

getColumns()

public function getColumns(): array;

Gets the columns that corresponds the index

getName()

public function getName(): string;

Gets the index name

getType()

public function getType(): string;

Gets the index type

Contracts\Db\Reference

Interface Source on GitHub

Canonical contract for Phalcon\Db\Reference.

Method Summary

Methods

Public · 8

getColumns()

public function getColumns(): array;

Gets local columns which reference is based

getName()

public function getName(): string;

Gets the index name

getOnDelete()

public function getOnDelete(): string|null;

Gets the referenced on delete

getOnUpdate()

public function getOnUpdate(): string|null;

Gets the referenced on update

getReferencedColumns()

public function getReferencedColumns(): array;

Gets referenced columns

getReferencedSchema()

public function getReferencedSchema(): string|null;

Gets the schema where referenced table is

getReferencedTable()

public function getReferencedTable(): string;

Gets the referenced table

getSchemaName()

public function getSchemaName(): string|null;

Gets the schema where referenced table is

Contracts\Db\Result

Interface Source on GitHub

Canonical contract for Phalcon\Db result objects.

Method Summary

Methods

Public · 8

dataSeek()

public function dataSeek( int $number );

Moves internal resultset cursor to another position letting us to fetch a certain row

execute()

public function execute(): bool;

Allows to execute the statement again. Some database systems don't support scrollable cursors. So, as cursors are forward only, we need to execute the cursor again to fetch rows from the beginning

fetch()

public function fetch(): mixed;

Fetches an array/object of strings that corresponds to the fetched row, or FALSE if there are no more rows. This method is affected by the active fetch flag set using Phalcon\Db\Result\Pdo::setFetchMode()

fetchAll()

public function fetchAll(): array;

Returns an array of arrays containing all the records in the result. This method is affected by the active fetch flag set using Phalcon\Db\Result\Pdo::setFetchMode()

fetchArray()

public function fetchArray(): mixed;

Returns an array of strings that corresponds to the fetched row, or FALSE if there are no more rows. This method is affected by the active fetch flag set using Phalcon\Db\Result\Pdo::setFetchMode()

getInternalResult()

public function getInternalResult(): \PDOStatement;

Gets the internal PDO result object

numRows()

public function numRows(): int;

Gets number of rows returned by a resultset

setFetchMode()

public function setFetchMode( int $fetchMode ): bool;

Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch()

Contracts\Encryption\Security\CryptoUtils

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Encryption\Security\Random

Method Summary

Methods

Public · 5

computeHmac()

public function computeHmac(
    string $data,
    string $key,
    string $algorithm,
    bool $raw = false
): string;

getRandom()

public function getRandom(): Random;

getRandomBytes()

public function getRandomBytes(): int;

getSaltBytes()

public function getSaltBytes( int $numberBytes = 0 ): string;

setRandomBytes()

public function setRandomBytes( int $randomBytes ): Security;

Contracts\Encryption\Security\CsrfProtection

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

  • Phalcon\Contracts\Encryption\Security\CsrfProtection

Method Summary

Methods

Public · 6

checkToken()

public function checkToken(
    string $tokenKey = null,
    mixed $tokenValue = null,
    bool $destroyIfValid = true
): bool;

destroyToken()

public function destroyToken(): Security;

getRequestToken()

public function getRequestToken(): string|null;

getSessionToken()

public function getSessionToken(): string|null;

getToken()

public function getToken(): string|null;

getTokenKey()

public function getTokenKey(): string|null;

Contracts\Encryption\Security\PasswordSecurity

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

  • Phalcon\Contracts\Encryption\Security\PasswordSecurity

Method Summary

Methods

Public · 8

checkHash()

public function checkHash(
    string $password,
    string $passwordHash,
    int $maxPassLength = 0
): bool;

getDefaultHash()

public function getDefaultHash(): int;

getHashInformation()

public function getHashInformation( string $hash ): array;

getWorkFactor()

public function getWorkFactor(): int;

hash()

public function hash(
    string $password,
    array $options = []
): string;

isLegacyHash()

public function isLegacyHash( string $passwordHash ): bool;

setDefaultHash()

public function setDefaultHash( int $defaultHash ): Security;

setWorkFactor()

public function setWorkFactor( int $workFactor ): Security;

Contracts\Encryption\Security\Security

Interface Source on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Contracts\Events\Event

Interface Source on GitHub

Canonical contract for Phalcon\Events\Event.

Method Summary

Methods

Public · 7

getData()

public function getData(): mixed;

Gets event data

getType()

public function getType(): mixed;

Gets event type

isCancelable()

public function isCancelable(): bool;

Check whether the event is cancelable

isStopped()

public function isStopped(): bool;

Check whether the event is currently stopped

setData()

public function setData( mixed $data = null ): Event;

Sets event data

setType()

public function setType( string $type ): Event;

Sets event type

stop()

public function stop(): Event;

Stops the event preventing propagation

Contracts\Events\EventsAware

Interface Source on GitHub

Canonical contract for Phalcon\Events\EventsAwareInterface. Implemented by components that accept an events manager and dispatch through it.

Cross-references the legacy ManagerInterface (not the canonical Manager contract) to preserve LSP for the many AbstractEventsAware subclasses that already type-hint ManagerInterface. ManagerInterface extends Manager, so this remains type-compatible with any code that needs the canonical surface.

Uses Phalcon\Events\ManagerInterface

Method Summary

Methods

Public · 2

getEventsManager()

public function getEventsManager(): ManagerInterface|null;

Returns the internal events manager

setEventsManager()

public function setEventsManager( ManagerInterface $eventsManager ): void;

Sets the events manager

Contracts\Events\Manager

Interface Source on GitHub

Canonical contract for Phalcon\Events\Manager.

Method Summary

public void addSubscriber( Subscriber $subscriber ) Registers an event subscriber. The subscriber's getSubscribedEvents() public bool arePrioritiesEnabled() Returns whether priority ordering is currently enabled. public void attach(string $eventType,mixed $handler,int $priority = self::DEFAULT_PRIORITY) Attach a listener to the events manager. public void clearSubscribers() Removes every registered subscriber and detaches each listener they public void collectResponses( bool $collect ) Toggle response collection on/off. public void detach(string $eventType,mixed $handler) Detach a listener from the events manager. public void detachAll( string $type = null ) Removes all listeners - globally or for a single event type. public void enablePriorities( bool $enablePriorities ) Toggle priority ordering on/off. public fire(string $eventType,object $source,mixed $data = null,bool $cancelable = true) Fires an event, notifying the active listeners. public array getListeners( string $type ) Returns all listeners attached to the given event type. public array getResponses() Returns the responses recorded during the last fire (when collecting). public array getSubscribers() Returns the list of registered subscriber instances. public bool hasListeners( string $type ) Check whether the given event type has any listeners. public bool isCollecting() Check whether the manager is currently collecting responses. public bool isValidHandler( mixed $handler ) Returns true when the given handler is an object or callable. public void removeSubscriber( Subscriber $subscriber ) Removes a previously registered subscriber. Detaches every listener the

Constants

int DEFAULT_PRIORITY = 100

Methods

Public · 16

addSubscriber()

public function addSubscriber( Subscriber $subscriber ): void;

Registers an event subscriber. The subscriber's getSubscribedEvents() map is parsed and each entry is attached through the regular listener pipeline.

arePrioritiesEnabled()

public function arePrioritiesEnabled(): bool;

Returns whether priority ordering is currently enabled.

attach()

public function attach(
    string $eventType,
    mixed $handler,
    int $priority = self::DEFAULT_PRIORITY
): void;

Attach a listener to the events manager.

clearSubscribers()

public function clearSubscribers(): void;

Removes every registered subscriber and detaches each listener they contributed. Listeners attached via attach() are untouched.

collectResponses()

public function collectResponses( bool $collect ): void;

Toggle response collection on/off.

detach()

public function detach(
    string $eventType,
    mixed $handler
): void;

Detach a listener from the events manager.

detachAll()

public function detachAll( string $type = null ): void;

Removes all listeners - globally or for a single event type.

enablePriorities()

public function enablePriorities( bool $enablePriorities ): void;

Toggle priority ordering on/off.

fire()

public function fire(
    string $eventType,
    object $source,
    mixed $data = null,
    bool $cancelable = true
);

Fires an event, notifying the active listeners.

getListeners()

public function getListeners( string $type ): array;

Returns all listeners attached to the given event type.

getResponses()

public function getResponses(): array;

Returns the responses recorded during the last fire (when collecting).

getSubscribers()

public function getSubscribers(): array;

Returns the list of registered subscriber instances.

hasListeners()

public function hasListeners( string $type ): bool;

Check whether the given event type has any listeners.

isCollecting()

public function isCollecting(): bool;

Check whether the manager is currently collecting responses.

isValidHandler()

public function isValidHandler( mixed $handler ): bool;

Returns true when the given handler is an object or callable.

removeSubscriber()

public function removeSubscriber( Subscriber $subscriber ): void;

Removes a previously registered subscriber. Detaches every listener the subscriber declared via getSubscribedEvents(). Idempotent.

Contracts\Events\Stoppable

Interface Source on GitHub

Phalcon's local mirror of PSR-14 StoppableEventInterface. Identical shape; not extended from the PSR interface because the Zephir extension cannot reference Composer-loaded interfaces at build time. A separate bridge package exposes a PSR-14 adapter.

  • Phalcon\Contracts\Events\Stoppable

Method Summary

Methods

Public · 1

isPropagationStopped()

public function isPropagationStopped(): bool;

Returns true when the event must stop propagating to subsequent listeners.

Contracts\Events\Subscriber

Interface Source on GitHub

Contract for event subscriber classes. A subscriber declares the events it wants to listen to via a static map; Events\Manager parses the map and attaches each entry as a regular listener.

Accepted value shapes per event key:

'event:name' => 'methodName' 'event:name' => ['methodName', priority] 'event:name' => [ ['methodName1'], ['methodName2', priority], ]

Keys can be either a Phalcon event string (e.g. "db:beforeQuery") or a fully qualified event class name.

Wildcard subscriptions: Phalcon's manager fires both the prefix queue and the full-name queue (e.g. "db" is fired before "db:beforeQuery"). To subscribe to every event of a component, use the prefix as the key:

'db' => 'onAnyDbEvent' // fires for db:beforeQuery, db:afterQuery, ...

  • Phalcon\Contracts\Events\Subscriber

Method Summary

Methods

Public · 1

getSubscribedEvents()

public static function getSubscribedEvents(): array;

Returns a map of event name => listener config. Called once per Manager::addSubscriber() / removeSubscriber() call.

Contracts\Forms\Schema

Interface Source on GitHub

Contract for objects that supply a normalized list of form element definitions. Implementations may source the definitions from a PHP array, a JSON document, a YAML file, or any other format.

Each returned definition must be an associative array containing at least: - 'type' (string) - element type key (e.g. 'text', 'select', 'checkgroup') - 'name' (string) - the HTML name attribute value

Optional keys per definition: - 'label' (string) - visible label text - 'default' (mixed) - pre-populated default value - 'attributes' (array) - additional HTML attributes - 'filters' (array|string) - filter names applied on bind() - 'validators' (array) - ValidatorInterface instances - 'options' (array) - choices for select / checkgroup / radiogroup

  • Phalcon\Contracts\Forms\Schema

Method Summary

Methods

Public · 1

load()

public function load(): array;

Returns an ordered list of normalized element definitions.

Contracts\Html\Helper\Input\SelectData

Interface Source on GitHub

Interface for SELECT option data providers.

Return format: [value => label] for flat options; [groupLabel => [value => label, ...]] for optgroups.

  • Phalcon\Contracts\Html\Helper\Input\SelectData

Method Summary

Methods

Public · 2

getAttributes()

public function getAttributes(): array;

Returns the per-option attribute map.

Format: [optionValue => [attrName => stringValue, ...]]. Implementations must return resolved string values; no escaping, ordering, or rendering is performed here.

getOptions()

public function getOptions(): array;

Contracts\Mvc\Model\Relation\CacheKeyProvider

Interface Source on GitHub

Interface for models that provide a custom unique key for the reusable records cache in the Model Manager. Implement this interface when the default object-identity based key (unique_key) does not produce stable cache hits across multiple object instances that represent the same database record.

  • Phalcon\Contracts\Mvc\Model\Relation\CacheKeyProvider

Method Summary

Methods

Public · 1

getUniqueKey()

public function getUniqueKey(): string;

Returns a string that uniquely identifies this model instance for use as the key in the reusable records cache.

Contracts\Paginator\Adapter

Interface Source on GitHub

Interface for Phalcon\Paginator adapters

Uses Phalcon\Paginator\Adapter\AdapterInterface

Method Summary

Methods

Public · 4

getLimit()

public function getLimit(): int;

Get current rows limit

paginate()

public function paginate(): Repository;

Returns a slice of the resultset to show in the pagination

setCurrentPage()

public function setCurrentPage( int $page ): AdapterInterface;

Set the current page number

setLimit()

public function setLimit( int $limit ): AdapterInterface;

Set current rows limit

Contracts\Paginator\Repository

Interface Source on GitHub

Interface for the repository of current state Phalcon\Paginator\AdapterInterface::paginate()

Method Summary

Constants

string PROPERTY_CURRENT_PAGE = "current"
string PROPERTY_FIRST_PAGE = "first"
string PROPERTY_ITEMS = "items"
string PROPERTY_LAST_PAGE = "last"
string PROPERTY_LIMIT = "limit"
string PROPERTY_NEXT_PAGE = "next"
string PROPERTY_PREVIOUS_PAGE = "previous"
string PROPERTY_TOTAL_ITEMS = "total_items"

Methods

Public · 11

getAliases()

public function getAliases(): array;

Gets the aliases for properties repository

getCurrent()

public function getCurrent(): int;

Gets number of the current page

getFirst()

public function getFirst(): int;

Gets number of the first page

getItems()

public function getItems(): mixed;

Gets the items on the current page

getLast()

public function getLast(): int;

Gets number of the last page

getLimit()

public function getLimit(): int;

Gets current rows limit

getNext()

public function getNext(): int;

Gets number of the next page

getPrevious()

public function getPrevious(): int;

Gets number of the previous page

getTotalItems()

public function getTotalItems(): int;

Gets the total number of items

setAliases()

public function setAliases( array $aliases ): Repository;

Sets the aliases for properties repository

setProperties()

public function setProperties( array $properties ): Repository;

Sets values for properties of the repository

Contracts\Support\Collection

Interface Source on GitHub

Canonical contract for Phalcon\Support\Collection.

@extends ArrayAccess @extends IteratorAggregate

Uses ArrayAccess · IteratorAggregate

Method Summary

public mixed __get( string $element ) public bool __isset( string $element ) public void __set(string $element,mixed $value) public void __unset( string $element ) public void clear() Clears the internal collection. public array column( string $propertyOrMethod ) Returns the values from a single property/method extracted from every public static each( callable $callback ) Invokes the callback for every item in the collection. public static filter( callable $callback ) Returns a new collection of items for which the callback returns true. public mixed first() Returns the first value in the collection or null when empty. public mixed get(string $element,mixed $defaultValue = null,string $cast = null) Returns an element from the collection. public array getKeys( bool $insensitive = true ) Returns the keys (insensitive or not) of the collection. public string|null getType() Returns the configured runtime type guard, or null when not set. public array getValues() Returns the values of the internal array. public bool has( string $element ) Checks whether an element exists in the collection. public void init( array $data = [] ) Initializes the internal array. public bool isEmpty() Returns true when the collection has no entries. public array keys( bool $insensitive = true ) Returns the keys (insensitive or not) of the collection. public mixed last() Returns the last value in the collection or null when empty. public static map( callable $callback ) Returns a new collection with the callback applied to every value. public mixed reduce(callable $callback,mixed $initial = null) Reduces the collection to a single value using the callback. public void remove( string $element ) Removes the element from the collection. public void replace( array $data ) Replaces the collection data with a new array, clearing first. public void set(string $element,mixed $value) Stores an element in the collection. public static sort(callable $callback = null,int $order = 4) Returns a new collection sorted by value, preserving keys. public array toArray() Returns the collection as an array. public string toJson( int $options = 4194383 ) Returns the collection serialized as a JSON string. public array values() Returns the values of the internal array. public static where(string $propertyOrMethod,mixed $value) Returns a new collection containing only the items whose

Methods

Public · 28

__get()

public function __get( string $element ): mixed;

__isset()

public function __isset( string $element ): bool;

__set()

public function __set(
    string $element,
    mixed $value
): void;

__unset()

public function __unset( string $element ): void;

clear()

public function clear(): void;

Clears the internal collection.

column()

public function column( string $propertyOrMethod ): array;

Returns the values from a single property/method extracted from every item in the collection, keyed by the original collection key.

each()

public function each( callable $callback ): static;

Invokes the callback for every item in the collection.

filter()

public function filter( callable $callback ): static;

Returns a new collection of items for which the callback returns true.

first()

public function first(): mixed;

Returns the first value in the collection or null when empty.

get()

public function get(
    string $element,
    mixed $defaultValue = null,
    string $cast = null
): mixed;

Returns an element from the collection.

getKeys()

public function getKeys( bool $insensitive = true ): array;

Returns the keys (insensitive or not) of the collection.

@deprecated Use {@see self::keys()} instead. Will be removed in a future major release.

getType()

public function getType(): string|null;

Returns the configured runtime type guard, or null when not set.

getValues()

public function getValues(): array;

Returns the values of the internal array.

@deprecated Use {@see self::values()} instead. Will be removed in a future major release.

has()

public function has( string $element ): bool;

Checks whether an element exists in the collection.

init()

public function init( array $data = [] ): void;

Initializes the internal array.

isEmpty()

public function isEmpty(): bool;

Returns true when the collection has no entries.

keys()

public function keys( bool $insensitive = true ): array;

Returns the keys (insensitive or not) of the collection.

last()

public function last(): mixed;

Returns the last value in the collection or null when empty.

map()

public function map( callable $callback ): static;

Returns a new collection with the callback applied to every value.

reduce()

public function reduce(
    callable $callback,
    mixed $initial = null
): mixed;

Reduces the collection to a single value using the callback.

remove()

public function remove( string $element ): void;

Removes the element from the collection.

replace()

public function replace( array $data ): void;

Replaces the collection data with a new array, clearing first.

set()

public function set(
    string $element,
    mixed $value
): void;

Stores an element in the collection.

sort()

public function sort(
    callable $callback = null,
    int $order = 4
): static;

Returns a new collection sorted by value, preserving keys.

toArray()

public function toArray(): array;

Returns the collection as an array.

toJson()

public function toJson( int $options = 4194383 ): string;

Returns the collection serialized as a JSON string.

values()

public function values(): array;

Returns the values of the internal array.

where()

public function where(
    string $propertyOrMethod,
    mixed $value
): static;

Returns a new collection containing only the items whose propertyOrMethod strictly equals $value.