Upgrade Guide


Upgrading to v4

So you have decided to upgrade to v4! Congratulations!!

Phalcon v4 contains a lot of changes to components, including changes to interfaces, strict types, removal of components and additions of new ones. This document is an effort to help you upgrade your existing Phalcon application to v4. We will outline the areas that you need to pay attention to and make necessary alterations so that your code can run as smoothly as it has been with v3. Although the changes are significant, it is more of a methodical task than a daunting one.

Requirements

PHP 7.2

Phalcon v4 supports only PHP 7.2 and above. PHP 7.1 was released 2 years ago and its active support has lapsed, so we decided to follow actively supported PHP versions.

PSR

Phalcon requires the PSR extension. The extension can be downloaded and compiled from this GitHub repository. Installation instructions are available in the README of the repository. Once the extension has been compiled and is available in your system, you will need to load it to your php.ini. You will need to add this line:

  1. extension=psr.so

before

  1. extension=phalcon.so

Alternatively some distributions add a number prefix on ini files. If that is the case, choose a high number for Phalcon (e.g. 50-phalcon.ini).

Installation

Download the latest zephir.phar from here. Add it to a folder that can be accessed by your system.

Clone the repository

  1. git clone https://github.com/phalcon/cphalcon

Compile Phalcon

  1. cd cphalcon/
  2. git checkout tags/v4.0.0-alpha1 ./
  3. zephir fullclean
  4. zephir build

Check the module

  1. php -m | grep phalcon

General Notes

Applications

  • The Phalcon\Mvc\Application, Phalcon\Mvc\Micro and Phalcon\Mvc\Router now must have a URI to process

Exceptions

  • Changed catch Exception to Throwable

Components

ACL

Status: changes required

Usage: ACL Documentation

The ACL component has had some methods and components renamed. The functionality remains the same as in previous versions.

Overview

The components needed for the ACL to work have been renamed. In particular Resource has been renamed to Component in all relevant interfaces, classes and methods that this component uses.

Added

  • Phalcon\Acl\Adapter\AbstractAdapter
  • Acl\Enum

Removed

  • Phalcon\Acl
  • Phalcon\Acl\Adapter

Changed

  • Renamed Phalcon\Acl\Resource to Phalcon\Acl\Component
  • Renamed Phalcon\Acl\ResourceInterface to Phalcon\Acl\ComponentInterface
  • Renamed Phalcon\Acl\ResourceAware to Phalcon\Acl\ComponentAware
  • Renamed Phalcon\Acl\AdapterInterface::isResource to Phalcon\Acl\AdapterInterface::isComponent
  • Renamed Phalcon\Acl\AdapterInterface::addResource to Phalcon\Acl\AdapterInterface::addComponent
  • Renamed Phalcon\Acl\AdapterInterface::addResourceAccess to Phalcon\Acl\AdapterInterface::addComponentAccess
  • Renamed Phalcon\Acl\AdapterInterface::dropResourceAccess to Phalcon\Acl\AdapterInterface::dropComponentAccess
  • Renamed Phalcon\Acl\AdapterInterface::getActiveResource to Phalcon\Acl\AdapterInterface::getActiveComponent
  • Renamed Phalcon\Acl\AdapterInterface::getResources to Phalcon\Acl\AdapterInterface::getComponents
  • Renamed Phalcon\Acl\Adapter::getActiveResource to Phalcon\Acl\AdapterInterface::getActiveComponent
  • Renamed Phalcon\Acl\Adapter\Memory::isResource to Phalcon\Acl\Adapter\Memory::isComponent
  • Renamed Phalcon\Acl\Adapter\Memory::addResource to Phalcon\Acl\Adapter\Memory::addComponent
  • Renamed Phalcon\Acl\Adapter\Memory::addResourceAccess to Phalcon\Acl\Adapter\Memory::addComponentAccess
  • Renamed Phalcon\Acl\Adapter\Memory::dropResourceAccess to Phalcon\Acl\Adapter\Memory::dropComponentAccess
  • Renamed Phalcon\Acl\Adapter\Memory::getResources to Phalcon\Acl\Adapter\Memory::getComponents

Acl\Adapter\Memory

  • Added getActiveKey, activeFunctionCustomArgumentsCount and getActiveFunction to get latest key, number of custom arguments, and function used to acquire access
  • Added addOpertion support multiple inherited

Acl\Enum (Constants)

Example:

  1. use Phalcon\Acl\Enum;
  2. echo Enum::ALLOW; //prints 1
  3. echo Enum::DENY; //prints 0

Assets

Status: changes required

Usage: Assets Documentation

CSS and JS filters have been removed from the Assets component. Due to license limitations, the CSS and JS minifiers (filters) have been removed for v4. In future versions with the help of the community we can introduce these filters again. You can always implement your own using the supplied Phalcon\Assets\FilterInterface.

Removed

  • Removed Phalcon\Assets\Filters\CssMin
  • Removed Phalcon\Assets\Filters\JsMin

Renamed

  • Renamed Phalcon\Assets\Resource to Phalcon\Assets\Asset
  • Renamed Phalcon\Assets\ResourceInterface to Phalcon\Assets\AssetInterface
  • Renamed Phalcon\Assets\Manager::addResource to Phalcon\Assets\Manager::addAsset
  • Renamed Phalcon\Assets\Manager::addResourceByType to Phalcon\Assets\Manager::addAssetByType
  • Renamed Phalcon\Assets\Manager::collectionResourcesByType to Phalcon\Assets\Manager::collectionAssetsByType

Cache

Status: changes required

Usage: Cache Documentation

xcache, apc and memcache adapters have been deprecated and removed. The first two are not supported for PHP 7.2+. apc has been replaced with apcu and memcache can be replaced with the libmemcached one.

  • Removed Phalcon\Annotations\Adapter\Apc
  • Removed Phalcon\Annotations\Adapter\Xcache
  • Removed Phalcon\Cache\Backend\Apc
  • Removed Phalcon\Cache\Backend\Memcache
  • Removed Phalcon\Cache\Backend\Xcache
  • Removed Phalcon\Mvc\Model\Metadata\Apc
  • Removed Phalcon\Mvc\Model\Metadata\Memcache
  • Removed Phalcon\Mvc\Model\Metadata\XcacheThe Cache component has been rewritten to comply with PSR-16. This allows you to use the Phalcon\Cache to any application that utilizes a PSR-16 cache, not just Phalcon based ones.

In v3, the cache was split into two components, the Frontend and the Backend. This did create a bit of confusion but it was functional. In order to create a cache component you had to create the Frontend first and then inject that to the relevant Backend (which acted as an adapter also).

For v4, we rewrote the component completely. We first created a Storage class which is the basis of the Cache classes. We created Serializer classes whose sole responsibility is to serialize and unserialize the data before they are saved in the cache adapter and after they are retrieved. These classes are injected (based on the developer’s choice) to an Adapter object which connects to a backend (Memcached, Redis etc.), while abiding by a common adapter interface.

The Cache class implements PSR-16 and accepts an adapter in its constructor, which in turn is doing all the heavy lifting with connecting to the back end and manipulating data.

For a more detailed explanation on how the new Cache component works, please visit the relevant page in our documentation.

Creating a cache

  1. <?php
  2. use Phalcon\Cache;
  3. use Phalcon\Cache\Adapter\AdapterFactory;
  4. use Phalcon\Storage\Serializer\SerializerFactory;
  5. $serializerFactory = new SerializerFactory();
  6. $adapterFactory = new AdapterFactory($serializerFactory);
  7. $options = [
  8. 'defaultSerializer' => 'Json',
  9. 'lifetime' => 7200
  10. ];
  11. $adapter = $adapterFactory->newInstance('apcu', $options);
  12. $cache = new Cache($adapter);

Registering it in the DI

  1. <?php
  2. use Phalcon\Cache;
  3. use Phalcon\Cache\Adapter\AdapterFactory;
  4. use Phalcon\Storage\Serializer\SerializerFactory;
  5. $container = new Di();
  6. $container->set(
  7. 'cache',
  8. function () {
  9. $options = [
  10. 'defaultSerializer' => 'Json',
  11. 'lifetime' => 7200
  12. ];
  13. $adapter = (new AdapterFactory(new SerializerFactory()))
  14. ->newInstance('apcu', $options);
  15. return new Cache($adapter);
  16. }
  17. );

CLI

Status: changes required

Usage: CLI Documentation

Parameters

Parameters now behave the same way as MVC controllers. Whilst previously they all existed in the $params property, you can now name them appropriately:

  1. use Phalcon\Cli\Task;
  2. class MainTask extends Task
  3. {
  4. public function testAction(string $yourName, string $myName)
  5. {
  6. echo sprintf(
  7. 'Hello %s!' . PHP_EOL,
  8. $yourName
  9. );
  10. echo sprintf(
  11. 'Best regards, %s' . PHP_EOL,
  12. $myName
  13. );
  14. }
  15. }

Cli\Console

  • Removed Phalcon\Cli\Console::addModules in favor of Phalcon\Cli\Console::registerModules

Cli\Router\RouteInterface

  • Added delimiter, getDelimiter

Cli\Dispatcher

  • Added getTaskSuffix(), setTaskSuffix()

Cli\DispatcherInterface

  • Added setOptions, getOptions

Container

  • Added Phalcon\Container, a proxy container class to the Phalcon\DI implementing PSR-11

Debug

  • Removed Phalcon\Debug::getMajorVersion

Db

  • Added global setting orm.case_insensitive_column_map to attempt to find value in the column map case-insensitively. Can be also enabled by setting caseInsensitiveColumnMap key in \Phalcon\Mvc\Model::setup()
  • Removed Phalcon\Db namespace. Replaced by Phalcon\Db\AbstractDb for necessary methods and Phalcon\Db\Enum for constants, i.e.:
  1. use Phalcon\Db\Enum;
  2. echo Enum::FETCH_ASSOC;

Db\AdapterInterface

  • Added fetchColumn, insertAsDict, updateAsDict

Db\Adapter\Pdo

  • Added more column types for the Mysql adapter. The adapters support-TYPE_BIGINTEGER
    • TYPE_BIT
    • TYPE_BLOB
    • TYPE_BOOLEAN
    • TYPE_CHAR
    • TYPE_DATE
    • TYPE_DATETIME
    • TYPE_DECIMAL
    • TYPE_DOUBLE
    • TYPE_ENUM
    • TYPE_FLOAT
    • TYPE_INTEGER
    • TYPE_JSON
    • TYPE_JSONB
    • TYPE_LONGBLOB
    • TYPE_LONGTEXT
    • TYPE_MEDIUMBLOB
    • TYPE_MEDIUMINTEGER
    • TYPE_MEDIUMTEXT
    • TYPE_SMALLINTEGER
    • TYPE_TEXT
    • TYPE_TIME
    • TYPE_TIMESTAMP
    • TYPE_TINYBLOB
    • TYPE_TINYINTEGER
    • TYPE_TINYTEXT
    • TYPE_VARCHAR Some adapters do not support certain types. For instance JSON is not supported for Sqlite. It will be automatically changed to VARCHAR.

Db\DialectInterface

  • Added registerCustomFunction, getCustomFunctions, getSqlExpression

Db\Dialect\Postgresql

  • Changed addPrimaryKey to make primary key constraints names unique by prefixing them with the table name.

DI

Di\ServiceInterface

  • Added getParameter, isResolved

Di\Service

  • Changed Phalcon\Di\Service constructor to no longer takes the name of the service.

Dispatcher

  • Removed Phalcon\Dispatcher::setModelBinding() in favor of Phalcon\Dispatcher::setModelBinder()
  • Added getHandlerSuffix(), setHandlerSuffix()

Events

Events\ManagerInterface

  • Added hasListeners

Flash

  • Added ability to set a custom template for the Flash Messenger.
  • Constructor no longer accepts an array for the CSS classes. You will need to use setCssClasses() to set your custom CSS classes for the component
  • The constructor now accepts an optional Phalcon\Escaper object, as well as a Phalcon\Session\Manager object (in the case of Phalcon\Flash\Session), in case you do not wish to use the DI and set it yourself.

Filter

Status: changes required

Usage: Filter Documentation

The Filter component has been rewritten, utilizing a service locator. Each sanitizer is now enclosed on its own class and lazy loaded to provide maximum performance and the lowest resource usage as possible.

Overview

The Phalcon\Filter object has been rewritten to act as a service locator for different sanitizers. This object allows you to sanitize input as before using the sanitize() method.

The values sanitized are automatically cast to the relevant types. This is the default behavior for the int, bool and float filters.

When instantiating the filter object, it does not know about any sanitizers. You have two options:

Load all the default sanitizers

You can load all the Phalcon supplied sanitizers by utilizing the Phalcon\Filter\FilterFactory component.

  1. <?php
  2. use Phalcon\Filter\FilterFactory;
  3. $factory = new FilterFactory();
  4. $locator = $factory->newInstance();

CallingnewInstance() will return a Phalcon\Filter object with all the sanitizers registered. The sanitizers are lazy loaded so they are instantiated only when called from the locator.

Load only sanitizers you want

You can instantiate the Phalcon\Filter component and either use the set() method to set all the sanitizers you need, or pass an array in the constructor with the sanitizers you want to register.

Using the FactoryDefault

If you use the Phalcon\Di\FactoryDefault container, then the Phalcon\Filter is automatically loaded in the container. You can then continue to use the service in your controllers or components as you did before. The name of the service in the Di is filter, just as before.

Also components that utilize the filter service, such as the Request object, transparently use the new filter locator. No additional changes required for those components.

Using a custom Di

If you have set up all the services in the Phalcon\Di yourself and need the filter service, you will need to change its registration as follows:

  1. <?php
  2. use Phalcon\Di;
  3. use Phalcon\Filter\FilterFactory;
  4. $container = new Di();
  5. $container->set(
  6. 'filter',
  7. function () {
  8. $factory = new FilterFactory();
  9. return $factory->newInstance();
  10. }
  11. );

Note that even if you register the filter service manually, the name of the service must be filter so that other components can use it

Constants

The constants that the v3 Phalcon\Filter have somewhat changed.

Removed

  • FILTER_INT_CAST (int!)
  • FILTER_FLOAT_CAST (float!)By default the service sanitizers cast the value to the appropriate type so these are obsolete

  • FILTER_APHANUM has been removed - replaced by FILTER_ALNUM

Changed

  • FILTER_SPECIAL_CHARS has changed been removed - replaced by FILTER_SPECIAL

Added

  • FILTER_ALNUM - replaced FILTER_ALPHANUM
  • FILTER_ALPHA - sanitize only alpha characters
  • FILTER_BOOL - sanitize boolean including “yes”, “no”, etc.
  • FILTER_LOWERFIRST - sanitze using lcfirst
  • FILTER_REGEX - sanitize based on a pattern (preg_replace)
  • FILTER_REMOVE - sanitize by removing characters (str_replace)
  • FILTER_REPLACE - sanitize by replacing characters (str_replace)
  • FILTER_SPECIAL - replaced FILTER_SPECIAL_CHARS
  • FILTER_SPECIALFULL - sanitize special chars (filter_var)
  • FILTER_UPPERFIRST - sanitize using ucfirst
  • FILTER_UPPERWORDS - sanitize using ucwords

Forms

Forms\Form

  • Phalcon\Forms\Form::clear will no longer call Phalcon\Forms\Element::clear, instead it will clear/set default value itself, and Phalcon\Forms\Element::clear will now call Phalcon\Forms\Form::clear if it’s assigned to the form, otherwise it will just clear itself.
  • Phalcon\Forms\Form::getValue will now also try to get the value by calling Tag::getValue or element’s getDefault method before returning null, and Phalcon\Forms\Element::getValue calls Tag::getDefault only if it’s not added to the form.

Html

Html\Breadcrumbs

  • Added Phalcon\Html\Breadcrumbs, a component that creates HTML code for breadcrumbs.

Html\Tag

  • Added Phalcon\Html\Tag, a component that creates HTML elements. It will replace Phalcon\Tag in a future version. This component does not use static method calls.

Http\RequestInterface

  • Removed isSecureRequest in favor of isSecure
  • Removed isSoapRequested in favor of isSoap

Http\Response

  • Added hasHeader() method to Phalcon\Http\Response to provide the ability to check if a header exists.
  • Added Phalcon\Http\Response\Cookies::getCookies
  • Changed setHeaders now merges the headers with any pre-existing ones in the internal collection
  • Added two new events response::beforeSendHeaders and response::afterSendHeaders

Image

Added

  • Phalcon\Image\Enum

Renamed

  • Phalcon\Image\Adapter is now Phalcon\Image\Adapter\AbstractAdapter

  • Phalcon\Image\Factory is now Phalcon\Image\ImageFactory

Removed

  • Phalcon\Image

Image\Enum (Constants)

Example:

  1. <?php
  2. use Phalcon\Image\Enum;
  3. // Resizing constraints
  4. echo Enum::AUTO; // prints 4
  5. echo Enum::HEIGHT; // prints 3
  6. echo Enum::INVERSE; // prints 5
  7. echo Enum::NONE; // prints 1
  8. echo Enum::PRECISE; // prints 6
  9. echo Enum::TENSILE; // prints 7
  10. echo Enum::WIDTH; // prints 2
  11. // Flipping directions
  12. echo Enum::HORIZONTAL; // prints 11
  13. echo Enum::VERTICAL; // prints 12

Logger

Status: changes required

Usage: Logger Documentation

The Logger component has been rewritten to comply with PSR-3. This allows you to use the Phalcon\Logger to any application that utilizes a PSR-3 logger, not just Phalcon based ones.

In v3, the logger was incorporating the adapter in the same component. So in essence when creating a logger object, the developer was creating an adapter (file, stream etc.) with logger functionality.

For v4, we rewrote the component to implement only the logging functionality and to accept one or more adapters that would be responsible for doing the work of logging. This immediately offers compatibility with PSR-3 and separates the responsibilities of the component. It also offers an easy way to attach more than one adapter to the logging component so that logging to multiple adapters can be achieved. By using this implementation we have reduced the code necessary for this component and removed the old Logger\Multiple component.

Creating a logger component

  1. <?php
  2. use Phalcon\Logger;
  3. use Phalcon\Logger\Adapter\Stream;
  4. $adapter = new Stream('/logs/application.log');
  5. $logger = new Logger(
  6. 'messages',
  7. [
  8. 'main' => $adapter,
  9. ]
  10. );
  11. $logger->error('Something went wrong');

Registering it in the DI

  1. <?php
  2. use Phalcon\Di;
  3. use Phalcon\Logger;
  4. use Phalcon\Logger\Adapter\Stream;
  5. $container = new Di();
  6. $container->set(
  7. 'logger',
  8. function () {
  9. $adapter = new Stream('/logs/application.log');
  10. $logger = new Logger(
  11. 'messages',
  12. [
  13. 'main' => $adapter,
  14. ]
  15. );
  16. return $logger;
  17. }
  18. );

Multiple loggers

The Phalcon\Logger\Multiple component has been removed. You can achieve the same functionality using the logger component and registering more than one adapter:

  1. <?php
  2. use Phalcon\Logger;
  3. use Phalcon\Logger\Adapter\Stream;
  4. $adapter1 = new Stream('/logs/first-log.log');
  5. $adapter2 = new Stream('/remote/second-log.log');
  6. $adapter3 = new Stream('/manager/third-log.log');
  7. $logger = new Logger(
  8. 'messages',
  9. [
  10. 'local' => $adapter1,
  11. 'remote' => $adapter2,
  12. 'manager' => $adapter3,
  13. ]
  14. );
  15. // Log to all adapters
  16. $logger->error('Something went wrong');

Messages

  • Phalcon\Messages\Message and its collection Phalcon\Messages\Messages are new components that handle messages for models and validation. In the past we had two components, one for validation and one for models. We have merged these two, so you should be getting back a MessageInterface[] back when calling save on a model or when retrieving validation messages.
    • Changed Phalcon\Mvc\Model to use the Phalcon\Messages\Message object for its messages
    • Changed Phalcon\Validation* to use the Phalcon\Messages\Message object for its messages

Transactions

Removed in version 4.0:

  • Removed $logger->begin()
  • Removed $logger->commit()

Log level

  • Removed $logger->setLogLevel()

Models

Status: changes required

Usage: Models Documentation

  • You can no longer assign data to models while saving them

Initialization

The getSource() method has been marked as final. As such you can no longer override this method in your model to set the corresponding table/source of the RDBMS. Instead, you can now use the initialize() method and setSource() to set the source of your model.

  1. <?php
  2. use Phalcon\Mvc\Model;
  3. class Users
  4. {
  5. public function initialize()
  6. {
  7. $this->setSource('Users');
  8. // ....
  9. }
  10. }

Criteria

The second parameter of Criteria::limit() (‘offset’) must now be an integer or null. Previously there was no type requirement.

  1. $criteria->limit(10);
  2. $criteria->limit(10, 5);
  3. $criteria->limit(10, null);

MVC

Status: changes required

Usage: MVC Documentation

Mvc\Collection

  • Removed Phalcon\Mvc\Collection::validationHasFailed
  • Removed calling Phalcon\Mvc\Collection::validate with object of type Phalcon\Mvc\Model\ValidatorInterface

Mvc\Micro\Lazyloader

  • Removed __call in favor of callMethod

Mvc\Model

  • Removed Phalcon\Model::reset
  • Added isRelationshipLoaded to check if relationship is loaded
  • Changed Phalcon\Model::assign parameters order to $data, $whiteList, $dataColumnMap

Mvc\Model\Criteria

  • Removed addWhere
  • Removed order
  • Removed order in favor of orderBy

Mvc\Model\CriteriaInterface

  • Added distinct, leftJoin, innerJoin, rightJoin, groupBy, having, cache, getColumns, getGroupBy, getHaving

Mvc\Model\Manager

  • Load no longer reuses already initialized models

Mvc\Model\ManagerInterface

  • Added isVisibleModelProperty, keepSnapshots, isKeepingSnapshots, useDynamicUpdate, isUsingDynamicUpdate, addHasManyToMany, existsHasManyToMany, getRelationRecords, getHasManyToMany, registerNamespaceAlias, getNamespaceAlias

Mvc\Model\MessageInterface

  • Added setModel, getModel, setCode, getCode

Mvc\Model\QueryInterface

  • Added getSingleResult, setBindParams, getBindParams, setBindTypes, setSharedLock, getBindTypes, getSql

Mvc\Model\Query\BuilderInterface

  • Added offset

Mvc\Model\Query\Builder

  • Added bind support. The Query Builder has the same methods as Phalcon\Mvc\Model\Query; getBindParams, setBindParams, getBindTypes and setBindTypes.
  • Changed addFrom to remove third parameter $with

Mvc\Model\Query\BuilderInterface

  • Added distinct, getDistinct, forUpdate, offset, getOffset

Mvc\Model\RelationInterface

  • Added getParams

Mvc\Model\ResultsetInterface

  • Added setHydrateMode, getHydrateMode, getMessages, update, delete, filter

Mvc\Model\Transaction\ManagerInterface

  • Added setDbService, getDbService, setRollbackPendent, getRollbackPendent

Mvc\Model\Validator*

  • Removed Phalcon\Mvc\Model\Validator* in favor of Phalcon\Validation\Validator*

Mvc\ModelInterface

  • Added getModelsMetaData

Mvc\RouterInterface

  • Added attach

Mvc\Router\RouteInterface

  • Added convert so that calling add will return an instance that has convert method

Mvc\Router\RouteInterface

  • Added response handler to Phalcon\Mvc\Micro, Phalcon\Mvc\Micro::setResponseHandler, to allow use of a custom response handler.

Mvc\User

  • Removed Phalcon\Mvc\User\Component - use Phalcon\Di\Injectable instead
  • Removed Phalcon\Mvc\User\Module - use Phalcon\Di\Injectable instead
  • Removed Phalcon\Mvc\User\Plugin - use Phalcon\Di\Injectable instead

Mvc\View

  • Removed getParams

Paginator

  • getPaginate not becomes paginate
  • $before is removed and replaced with $previous
  • $total_pages is removed since it contained the same information as $last
  • Added Phalcon\Paginator\RepositoryInterface for repository the current state of paginator and also optional sets the aliases for properties repository

Router

You can add CONNECT, PURGE, TRACE routes to the Router Group. They function the same as they do in the normal Router:

  1. use Phalcon\Mvc\Router\Group;
  2. $group = new Group();
  3. $group->addConnect(
  4. '/api',
  5. [
  6. 'controller' => 'api',
  7. 'action' => 'connect',
  8. ]
  9. );
  10. $group->addPurge(
  11. '/api',
  12. [
  13. 'controller' => 'api',
  14. 'action' => 'purge',
  15. ]
  16. );
  17. $group->addTrace(
  18. '/api',
  19. [
  20. 'controller' => 'api',
  21. 'action' => 'trace',
  22. ]
  23. );

Security

  • Removed hasLibreSsl
  • Removed getSslVersionNumber
  • Added setPadding
  • Added a retainer for the current token to be used during the checks, so when getToken is called the token used for checks does not change

Session

Status: changes required

Usage: Session Documentation

Session and Session\Bag no longer get loaded by default in Phalcon\DI\FactoryDefault. Session was refactored.

Added

  • Phalcon\Session\Adapter\AbstractAdapter
  • Phalcon\Session\Adapter\Noop
  • Phalcon\Session\Adapter\Stream
  • Phalcon\Session\Manager
  • Phalcon\Session\ManagerInterface

Removed

  • Phalcon\Session\Adapter - replaced by Phalcon\Session\AbstractAdapter
  • Phalcon\Session\AdapterInterface
  • Phalcon\Session\Adapter\Files - replaced by Phalcon\Session\Adapter\Stream
  • Phalcon\Session\Adapter\Memcache
  • Phalcon\Session\BagInterface
  • Phalcon\Session\Factory

Session\Adapter

Each adapter implements PHP’s SessionHandlerInterface. Available adapters are:

  • Phalcon\Session\Adapter\AbstractAdapter
  • Phalcon\Session\Adapter\Libmemcached
  • Phalcon\Session\Adapter\Noop
  • Phalcon\Session\Adapter\Redis
  • Phalcon\Session\Adapter\Stream

Session\Manager

  • Now is the single component that offers session manipulation by using adapters (see above). Each adapter implements PHP’s SessionHandlerInterface
  • Developers can add any adapter that implements SessionHandlerInterface

Tag

  • Added renderTitle() that renders the title enclosed in <title> tags.
  • Changed getTitle. It returns only the text. It accepts prepend, append booleans to prepend or append the relevant text to the title.
  • Changed textArea to use htmlspecialchars to prevent XSS injection.

Text

Status: changes required

Usage: Str Documentation

The Phalcon\Text component has been removed in favor of the Phalcon\Helper\Str. The functionality offered by Phalcon\Text in v3 is replicated and enhanced in the new class: Phalcon\Helper\Str.


Validation

Validation\Message

  • Removed Phalcon\Validation\Message and Phalcon\Mvc\Model\Message in favor of Phalcon\Messages\Message
  • Removed Phalcon\Validation\MessageInterface and Phalcon\Mvc\Model\MessageInterface in favor of Phalcon\Messages\MessageInterface
  • Removed Phalcon\Validation\Message and Phalcon\Mvc\Model\Message in favor of Phalcon\Messages\Message
  • Removed Phalcon\Validation\Message\Group in favor of Phalcon\Messages\Messages

Validation\Validator

  • Removed isSetOption

Validation\Validator\Ip

  • Added Phalcon\Validation\Validator\Ip, class used to validate ip address fields. It allows to validate a field selecting IPv4 or IPv6, allowing private or reserved ranges and empty values if necessary.

Url

Status: changes required

Usage: Url Documentation

The Phalcon\Mvc\Url component has been renamed to Phalcon\Url. The functionality remains the same.

Cheat Sheet

Acl

3.4.xState4.0.x
Phalcon\AclRemoved
Phalcon\Acl\AdapterRenamed toPhalcon\Acl\Adapter\AbstractAdapter
Phalcon\Acl\ResourceRenamed toPhalcon\Acl\Component
NewPhalcon\Acl\Enum

Annotations

3.4.xState4.0.x
Phalcon\Annotations\AdapterRenamed toPhalcon\Annotations\Adapter\AbstractAdapter
Phalcon\Annotations\Adapter\ApcRemoved
Phalcon\Annotations\Adapter\FilesRenamed toPhalcon\Annotations\Adapter\Stream
Phalcon\Annotations\Adapter\XcacheRemoved
Phalcon\Annotations\FactoryRenamed toPhalcon\Annotations\AnnotationsFactory

Application

3.4.xState4.0.x
Phalcon\ApplicationRenamed toPhalcon\Application\AbstractApplication

Assets

3.4.xState4.0.x
Phalcon\Assets\ResourceRenamed toPhalcon\Assets\Asset
Phalcon\Assets\Resource\CssRenamed toPhalcon\Assets\Asset\Css
Phalcon\Assets\Resource\JsRenamed toPhalcon\Assets\Asset\Js

Cache

3.4.xState4.0.x
Phalcon\Cache\Backend\ApcRemoved
Phalcon\Cache\BackendRenamed toPhalcon\Cache
Phalcon\Cache\Backend\FactoryRenamed toPhalcon\Cache\AdapterFactory
Phalcon\Cache\Backend\ApcuRenamed toPhalcon\Cache\Adapter\Apcu
Phalcon\Cache\Backend\FileRenamed toPhalcon\Cache\Adapter\Stream
Phalcon\Cache\Backend\LibmemcachedRenamed toPhalcon\Cache\Adapter\Libmemcached
Phalcon\Cache\Backend\MemcacheRemoved
Phalcon\Cache\Backend\MemoryRenamed toPhalcon\Cache\Adapter\Memory
Phalcon\Cache\Backend\MongoRemoved
Phalcon\Cache\Backend\RedisRenamed toPhalcon\Cache\Adapter\Redis
NewPhalcon\Cache\CacheFactory
Phalcon\Cache\Backend\XcacheRemoved
Phalcon\Cache\ExceptionRenamed toPhalcon\Cache\Exception\Exception
NewPhalcon\Cache\Exception\InvalidArgumentException
Phalcon\Cache\Frontend\Base64Removed
Phalcon\Cache\Frontend\DataRemoved
Phalcon\Cache\Frontend\FactoryRemoved
Phalcon\Cache\Frontend\IgbinaryRemoved
Phalcon\Cache\Frontend\JsonRemoved
Phalcon\Cache\Frontend\MsgpackRemoved
Phalcon\Cache\Frontend\NoneRemoved
Phalcon\Cache\Frontend\OutputRemoved
Phalcon\Cache\MultipleRemoved

Collection

3.4.xState4.0.x
NewPhalcon\Collection
NewPhalcon\Collection\Exception
NewPhalcon\Collection\ReadOnly

Config

3.4.xState4.0.x
Phalcon\Config\FactoryRenamed toPhalcon\Config\ConfigFactory

Container

3.4.xState4.0.x
NewPhalcon\Container

Db

3.4.xState4.0.x
Phalcon\DbRenamed toPhalcon\Db\AbstractDb
Phalcon\Db\AdapterRenamed toPhalcon\Db\Adapter\AbstractAdapter
Phalcon\Db\Adapter\PdoRenamed toPhalcon\Db\Adapter\Pdo\AbstractPdo
Phalcon\Db\Adapter\Pdo\FactoryRenamed toPhalcon\Db\Adapter\PdoFactory
NewPhalcon\Db\Enum

Dispatcher

3.4.xState4.0.x
Phalcon\DispatcherRenamed toPhalcon\Dispatcher\AbstractDispatcher
NewPhalcon\Dispatcher\Exception

Di

3.4.xState4.0.x
NewPhalcon\Di\Exception\ServiceResolutionException

Domain

3.4.xState4.0.x
NewPhalcon\Domain\Payload\Payload
NewPhalcon\Domain\Payload\PayloadFactory
NewPhalcon\Domain\Payload\Status

Factory

3.4.xState4.0.x
Phalcon\FactoryRenamed toPhalcon\Factory\AbstractFactory

Filter

3.4.xState4.0.x
NewPhalcon\Filter\FilterFactory
NewPhalcon\Filter\Sanitize\AbsInt
NewPhalcon\Filter\Sanitize\Alnum
NewPhalcon\Filter\Sanitize\Alpha
NewPhalcon\Filter\Sanitize\BoolVal
NewPhalcon\Filter\Sanitize\Email
NewPhalcon\Filter\Sanitize\FloatVal
NewPhalcon\Filter\Sanitize\IntVal
NewPhalcon\Filter\Sanitize\Lower
NewPhalcon\Filter\Sanitize\LowerFirst
NewPhalcon\Filter\Sanitize\Regex
NewPhalcon\Filter\Sanitize\Remove
NewPhalcon\Filter\Sanitize\Replace
NewPhalcon\Filter\Sanitize\Special
NewPhalcon\Filter\Sanitize\SpecialFull
NewPhalcon\Filter\Sanitize\StringVal
NewPhalcon\Filter\Sanitize\Striptags
NewPhalcon\Filter\Sanitize\Trim
NewPhalcon\Filter\Sanitize\Upper
NewPhalcon\Filter\Sanitize\UpperFirst
NewPhalcon\Filter\Sanitize\UpperWords
NewPhalcon\Filter\Sanitize\Url

Firewall

3.4.xState4.0.x
NewPhalcon\Firewall\Adapter\AbstractAdapter
NewPhalcon\Firewall\Adapter\Acl
NewPhalcon\Firewall\Adapter\Annotations
NewPhalcon\Firewall\Adapter\Micro\Acl
NewPhalcon\Firewall\Exception

Flash

3.4.xState4.0.x
Phalcon\FlashRenamed toPhalcon\Flash\AbstractFlash

Forms

3.4.xState4.0.x
Phalcon\Forms\ElementRenamed toPhalcon\Forms\Element\AbstractElement

Helper

3.4.xState4.0.x
NewPhalcon\Helper\Arr
NewPhalcon\Helper\Exception
NewPhalcon\Helper\Number
NewPhalcon\Helper\Str

Html

3.4.xState4.0.x
NewPhalcon\Html\Attributes
NewPhalcon\Html\Breadcrumbs
NewPhalcon\Html\Exception
NewPhalcon\Html\Helper\AbstractHelper
NewPhalcon\Html\Helper\Anchor
NewPhalcon\Html\Helper\AnchorRaw
NewPhalcon\Html\Helper\Body
NewPhalcon\Html\Helper\Button
NewPhalcon\Html\Helper\Close
NewPhalcon\Html\Helper\Element
NewPhalcon\Html\Helper\ElementRaw
NewPhalcon\Html\Helper\Form
NewPhalcon\Html\Helper\Img
NewPhalcon\Html\Helper\Label
NewPhalcon\Html\Helper\TextArea
NewPhalcon\Html\Tag
NewPhalcon\Html\TagFactory

Http

3.4.xState4.0.x
NewPhalcon\Http\Message\AbstractCommon
NewPhalcon\Http\Message\AbstractMessage
NewPhalcon\Http\Message\AbstractRequest
NewPhalcon\Http\Message\Exception\InvalidArgumentException
NewPhalcon\Http\Message\Request
NewPhalcon\Http\Message\RequestFactory
NewPhalcon\Http\Message\Response
NewPhalcon\Http\Message\ResponseFactory
NewPhalcon\Http\Message\ServerRequest
NewPhalcon\Http\Message\ServerRequestFactory
NewPhalcon\Http\Message\Stream
NewPhalcon\Http\Message\StreamFactory
NewPhalcon\Http\Message\Stream\Input
NewPhalcon\Http\Message\Stream\Memory
NewPhalcon\Http\Message\Stream\Temp
NewPhalcon\Http\Message\UploadedFile
NewPhalcon\Http\Message\UploadedFileFactory
NewPhalcon\Http\Message\Uri
NewPhalcon\Http\Message\UriFactory
NewPhalcon\Http\Server\AbstractMiddleware
NewPhalcon\Http\Server\AbstractRequestHandler

Image

3.4.xState4.0.x
Phalcon\ImageRemoved
Phalcon\Image\AdapterRenamed toPhalcon\Image\Adapter\AbstractAdapter
NewPhalcon\Image\Enum
Phalcon\Image\FactoryRenamed toPhalcon\Image\ImageFactory

Logger

3.4.xState4.0.x
Phalcon\LoggerRenamed toPhalcon\Logger\Logger
NewPhalcon\Logger\AdapterFactory
Phalcon\Logger\AdapterRenamed toPhalcon\Logger\Adapter\AbstractAdapter
Phalcon\Logger\Adapter\BlackholeRenamed toPhalcon\Logger\Adapter\Noop
Phalcon\Logger\Adapter\FileRenamed toPhalcon\Logger\Adapter\Stream
Phalcon\Logger\Adapter\FirephpRemoved
Phalcon\Logger\FactoryRenamed toPhalcon\Logger\LoggerFactory
Phalcon\Logger\FormatterRenamed toPhalcon\Logger\Formatter\AbstractFormatter
Phalcon\Logger\Formatter\FirephpRemoved
Phalcon\Logger\MultipleRemoved

Message (new in v4, formerly Phalcon\Validation\Message in 3.4)

3.4.xState4.0.x
NewPhalcon\Messages\Exception
NewPhalcon\Messages\Message
NewPhalcon\Messages\Messages

Mvc

3.4.xState4.0.x
Phalcon\Mvc\Model\MessageRenamed toPhalcon\Messages\Message
Phalcon\Mvc\Model\MetaData\ApcRemoved
Phalcon\Mvc\Model\MetaData\FilesRenamed toPhalcon\Mvc\Model\MetaData\Stream
Phalcon\Mvc\Model\MetaData\MemcacheRemoved
Phalcon\Mvc\Model\MetaData\SessionRemoved
Phalcon\Mvc\Model\MetaData\XcacheRemoved
Phalcon\Mvc\Model\ValidatorRenamed toPhalcon\Validation\Validator
Phalcon\Mvc\Model\Validator\EmailRenamed toPhalcon\Validation\Validator\Email
Phalcon\Mvc\Model\Validator\ExclusioninRenamed toPhalcon\Validation\Validator\ExclusionIn
Phalcon\Mvc\Model\Validator\InclusioninRenamed toPhalcon\Validation\Validator\InclusionIn
Phalcon\Mvc\Model\Validator\IpRenamed toPhalcon\Validation\Validator\Ip
Phalcon\Mvc\Model\Validator\NumericalityRenamed toPhalcon\Validation\Validator\Numericality
Phalcon\Mvc\Model\Validator\PresenceOfRenamed toPhalcon\Validation\Validator\PresenceOf
Phalcon\Mvc\Model\Validator\RegexRenamed toPhalcon\Validation\Validator\Regex
Phalcon\Mvc\Model\Validator\StringLengthRenamed toPhalcon\Validation\Validator\StringLength
Phalcon\Mvc\Model\Validator\UniquenessRenamed toPhalcon\Validation\Validator\Uniqueness
Phalcon\Mvc\Model\Validator\UrlRenamed toPhalcon\Validation\Validator\Url
Phalcon\Mvc\UrlRenamed toPhalcon\Url
Phalcon\Mvc\Url\ExceptionRenamed toPhalcon\Url\Exception
Phalcon\Mvc\User\ComponentRenamed toPhalcon\Plugin
Phalcon\Mvc\User\ModuleRenamed toPhalcon\Plugin
Phalcon\Mvc\User\PluginRenamed toPhalcon\Plugin
Phalcon\Mvc\View\EngineRenamed toPhalcon\Mvc\View\Engine\AbstractEngine

Paginator

3.4.xState4.0.x
Phalcon\Paginator\AdapterRenamed toPhalcon\Paginator\Adapter\AbstractAdapter
Phalcon\Paginator\FactoryRenamed toPhalcon\Paginator\PaginatorFactory
NewPhalcon\Paginator\Repository

Plugin

3.4.xState4.0.x
NewPhalcon\Plugin

Queue

3.4.xState4.0.x
Phalcon\Queue\BeanstalkRemoved
Phalcon\Queue\Beanstalk\ExceptionRemoved
Phalcon\Queue\Beanstalk\JobRemoved

Session

3.4.xState4.0.x
Phalcon\Session\AdapterRenamed toPhalcon\Session\Adapter\AbstractAdapter
Phalcon\Session\Adapter\FilesRenamed toPhalcon\Session\Adapter\Stream
NewPhalcon\Session\Adapter\Noop
Phalcon\Session\Adapter\MemcacheRemoved
Phalcon\Session\BagInterfaceRemoved
Phalcon\Session\FactoryRenamed toPhalcon\Session\Manager

Storage

3.4.xState4.0.x
NewPhalcon\Storage\AdapterFactory
NewPhalcon\Storage\Adapter\AbstractAdapter
NewPhalcon\Storage\Adapter\Apcu
NewPhalcon\Storage\Adapter\Libmemcached
NewPhalcon\Storage\Adapter\Memory
NewPhalcon\Storage\Adapter\Redis
NewPhalcon\Storage\Adapter\Stream
NewPhalcon\Storage\Exception
NewPhalcon\Storage\SerializerFactory
NewPhalcon\Storage\Serializer\AbstractSerializer
NewPhalcon\Storage\Serializer\Base64
NewPhalcon\Storage\Serializer\Igbinary
NewPhalcon\Storage\Serializer\Json
NewPhalcon\Storage\Serializer\Msgpack
NewPhalcon\Storage\Serializer\None
NewPhalcon\Storage\Serializer\Php

Translate

3.4.xState4.0.x
Phalcon\TranslateRemoved
Phalcon\Translate\AdapterRenamed toPhalcon\Translate\Adapter\AbstractAdapter
NewPhalcon\Translate\InterpolatorFactory
Phalcon\Translate\FactoryRenamed toPhalcon\Translate\TranslateFactory

Url

3.4.xState4.0.x
NewPhalcon\Url
NewPhalcon\Url\Exception

Validation

3.4.xState4.0.x
Phalcon\Validation\CombinedFieldsValidatorRenamed toPhalcon\Validation\AbstractCombinedFieldsValidator
Phalcon\Validation\MessageRenamed toPhalcon\Messages\Message
Phalcon\Validation\Message\GroupRenamed toPhalcon\Messages\Messages
Phalcon\Validation\ValidatorRenamed toPhalcon\Validation\AbstractValidator
NewPhalcon\Validation\AbstractValidatorComposite
NewPhalcon\Validation\Exception
NewPhalcon\Validation\ValidatorFactory
NewPhalcon\Validation\Validator\File\AbstractFile
NewPhalcon\Validation\Validator\File\MimeType
NewPhalcon\Validation\Validator\File\Resolution\Equal
NewPhalcon\Validation\Validator\File\Resolution\Max
NewPhalcon\Validation\Validator\File\Resolution\Min
NewPhalcon\Validation\Validator\File\Size\Equal
NewPhalcon\Validation\Validator\File\Size\Max
NewPhalcon\Validation\Validator\File\Size\Min
NewPhalcon\Validation\Validator\StringLength\Max
NewPhalcon\Validation\Validator\StringLength\Min