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.
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
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.
The 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.
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.
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:
NOTE: 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
The constants that the v3 Phalcon\Filter have somewhat changed.
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
FILTER_SPECIAL_CHARS has changed been removed - replaced by FILTER_SPECIAL
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
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.
<?phpusePhalcon\Image\Enum;// Resizing constraintsechoEnum::AUTO;// prints 4echoEnum::HEIGHT;// prints 3echoEnum::INVERSE;// prints 5echoEnum::NONE;// prints 1echoEnum::PRECISE;// prints 6echoEnum::TENSILE;// prints 7echoEnum::WIDTH;// prints 2// Flipping directionsechoEnum::HORIZONTAL;// prints 11echoEnum::VERTICAL;// prints 12
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. また、複数のアダプタへのロギングを実現できるように、複数のアダプタをロギングコンポーネントに簡単に接続する方法も提供します。 この実装を使用することで、このコンポーネントに必要なコードを削減し、古い Logger\Multiple コンポーネントを削除しました。
<?phpusePhalcon\Logger;usePhalcon\Logger\Adapter\Stream;$adapter=newStream('/logs/application.log');$logger=newLogger('messages',['main'=>$adapter,]);$logger->error('Something went wrong');
<?phpusePhalcon\Logger;usePhalcon\Logger\Adapter\Stream;$adapter1=newStream('/logs/first-log.log');$adapter2=newStream('/remote/second-log.log');$adapter3=newStream('/manager/third-log.log');$logger=newLogger('messages',['local'=>$adapter1,'remote'=>$adapter2,'manager'=>$adapter3,]);// Log to all adapters$logger->error('Something went wrong');
Phalcon\Messages\Message そして、その複数形のPhalcon\Messages\Messages コレクションは、モデルと検証のためのメッセージを処理する新しいコンポーネントです。 過去には検証用とモデル用の2つのコンポーネントがありました。 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
You can no longer assign data to models while saving them
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.
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.
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\Group in favor of Phalcon\Messages\Messages
Validator messages have been moved inside each validator
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.
View caching along with the viewCache service have been removed from the framework because they were incompatible with the new Cache component. Developers can easily utilize a view cache from external services such as Varnish, Cloudflare etc. Additionally, developers can cache fragments by either using the Phalcon\Mvc\View\Simple::render() or the Phalcon\Mvc\View::toString(). Those two methods return the produced HTML that can be cached in the cache backend of your choice.