Phalcon 2.1.0 RC1 released

We are excited to announce the immediate availability of Phalcon 2.1 RC 1!

This version is our first LTS version and it will be supported 3 years from its final release date. Also, this will be our last release candidate before the final version of Phalcon 2.1.

Phalcon 2.1 introduces a great number of improvements, striving to make Phalcon even a better framework. Final version will be available in two weeks.

NOTE: Some of these changes will break existing Phalcon 2.x applications. Please ensure that you have tested your application sufficiently before migrating your application to 2.1 for production purposes.

Changes in Phalcon 2.1

  • PHP 5.3 is no longer supported
  • Phalcon\Mvc\Model\Validation is now deprecated in favor of Phalcon\Validation
  • The default encrypt mode in Phalcon\Crypt is now changed to MCRYPT_MODE_CFB
  • Changed default hash algorithm in Phalcon\Security to CRYPT_BLOWFISH_Y
  • Changed constructor of Phalcon\Mvc\Model allowing you to pass an array of initialization data
  • Removed support for prefixes strategy in Phalcon\Loader
  • Phalcon\Mvc\View now supports many views directories
  • An absolute path can now be used for Mvc\View::setLayoutsDir
  • Fixed odd view behavior #1933 related to setLayout() and pick()
  • Phalcon\Di is now bound to service closures allowing use Phalcon\Di as $this to access services within the closures
  • If an object is returned after firing the event beforeServiceResolve in Phalcon\Di it overrides the default service localization process
  • Placeholders :controller and :action in Mvc\Router now default to /([\\w0-9\_\-]+) instead of /([\\a-zA-Z0-9\_\-]+)
  • Modifier #u (PCRE_UTF8) is now the default in regex based routes in Mvc\Router
  • Return false from an action disables the view component (same as $this->view->disable())
  • Return a string from an action takes it as the body of the response (same as return $this->response->setContent('Hello world'))
  • Return a string from an Mvc\Micro handler takes it as the body of the response
  • Mvc\Router\Route now escapes characters such as . or + to avoid unexpected behaviors
  • Closures used as handlers inMvc\Micro are now bound to the $app instance
  • Routes now can have an associated callback that can override the default dispatcher and view behavior
  • Phalcon\Mvc\Model now implements JsonSerializable making easy serialize model instances
  • When destructing a Mvc\Model\Manager PHQL cache is cleared
  • Method isSetOption in Phalcon\Validation\ValidatorInterface marked as deprecated. You can now use hasOption instead
  • Added internal check allowEmpty before calling a validator. If it option is true and the value of empty, the validator is skipped
  • Added default header: Content-Type: "application/json; charset=UTF-8" in method Phalcon\Http\Response::setJsonContent
  • Phalcon\Events\Event now implements Phalcon\Events\EventInterface
  • Phalcon\Events\Event::getCancelable renamed to Phalcon\Events\Event::isCancelable
  • Removed Phalcon\Events\Manager::dettachAll in favor of Phalcon\Events\Manager::detachAll
  • Phalcon\Mvc\Model\Criteria::getOrder is renamed to Phalcon\Mvc\Model\Criteria::getOrderBy
  • Added method getOption() in Phalcon\Mvc\Model\RelationInterface
  • Added ability to spoof the HTTP request method
  • Added FULLTEXT index type to Phalcon\Db\Adapter\Pdo\Mysql
  • Fixed the use of the annotation router with namespaced controllers
  • Added Phalcon\Acl\RoleAware and Phalcon\Acl\ResourceAware Interfaces. You can now pass objects to Phalcon\Acl\AdapterInterface::isAllowed as roleName and resourceName, which will be automatically passed to the function defined in Phalcon\Acl\AdapterInterface::allow or Phalcon\Acl\AdapterInterface::deny by type
  • Phalcon\Acl\AdapterInterface::allow and Phalcon\Acl\AdapterInterface::deny have now a 4th argument - function, which will be called when using Phalcon\Acl\AdapterInterface::isAllowed
  • Phalcon\Acl\AdapterInterface::isAllowed has now a 4th argument - parameters; You can pass arguments for function defined in Phalcon\Acl\AdapterInterface:allow or Phalcon\Acl\AdapterInterface::deny as associative array where key is the argument name
  • Added method getActionSuffix() in Phalcon\DispatcherInterface
  • CLI parameters are now handled consistently
  • Added Phalcon\Mvc\Controller\BindModelInterface and associated model type hint loading through dispatcher.
  • Added Phalcon\Dispatcher::hasParam()
  • Phalcon\Cli\Console and Phalcon\Mvc\Application now inherit Phalcon\Application.
  • Fixed afterFetch event not being sent to behaviors
  • Fixed issue with radio not being checked when default value is 0 #11358
  • Fixed issue with Model::__set that was bypassing setters #11286
  • Fixed issue with Model::__set that was setting hidden attributes directly when setters are not declared #11286
  • Added Phalcon\Cli\DispatcherInterface, Phalcon\Cli\TaskInterface, Phalcon\Cli\RouterInterface and Phalcon\Cli\Router\RouteInterface.
  • Added Phalcon\Mvc\Collection::update, Phalcon\Mvc\Collection::create and Phalcon\Mvc\Collection::createIfNotExist
  • Removed __construct from all interfaces #11410
  • Fire the dispatch:beforeException event when there is an exception during dispatching #11458
  • Added OR operator for Phalcon\Mvc\Model\Query\Builder methods: betweenWhere, notBetweenWhere, inWhere and notInWhere
  • Fixed bug of destroy method of Phalcon\Session\Adapter\Libmemcached
  • Added Phalcon\Cache\Backend\Memcache::addServers to enable pool of servers for memcache
  • Added setLastModified method to Phalcon\Http\Response
  • Added Phalcon\Validation\Validator\Date
  • Mcrypt is replaced with openssl in Phalcon\Crypt
  • Removed methods setMode(), getMode(), getAvailableModes() in Phalcon\CryptInterface
  • Added Phalcon\Assets\Manager::exists() to check if collection exists

PHP 7 support

Phalcon 2.1.x has beta PHP7 support, we expect to fix any blocking bug in the next two weeks before the final release. You can try Phalcon running on PHP7 by compiling from the 2.1.x branch using Zephir:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
git checkout 2.1.x
zephir build --backend=ZendEngine3

After this, you only have to add extension=phalcon.so to your php.ini file.

New Package Infrastructure

We would like to share with you, our community, our plans for moving forward with regards to packaging and distributing Phalcon.

We have been researching many options to make the whole process easy, transparent and automated as possible. Our goal is to be able to use a continuous delivery system that will compile and package Phalcon immediately after each release. To achieve this, we chose to use the Packagecloud service to distribute Phalcon binaries.

This move will increase the availability of Phalcon in more Linux operating systems than currently available, and users will be able to use any built-in package manager of their operating system to install the framework. The available operating systems will be:

  • Debian
  • CentOS
  • RedHat
  • Amazon Linux
  • Fedora
  • LinuxMint
  • Oracle Linux
  • Raspbian
  • Scientific Linux
  • Ubuntu
  • elementary OS

In addition to the above, automation will reduce the human interaction currently needed to create each Phalcon distribution.

For the time being, each distribution will be manually compiled by the Phalcon Team. Our goal is not to change the framework and the way it works for the community, but rather the way it is distributed. For that we will ensure that the new delivery mechanism is tested sufficiently, before we fully switch to Packagecloud and deprecate our Launchpad repository.

This move will make Phalcon available to a much wider variety of Linux based operating systems and reduce the time needed to produce those packages.

We will announce in our blog when this change will happen, so for the time being you can keep getting new versions as you have been in the past.

Update/Upgrade

Phalcon 2.1 RC1 can be installed from the 2.1.x branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
git checkout 2.1.x
sudo ./install

If you have Zephir installed:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
git checkout 2.1.x
zephir build

Note that running the installation script will replace any version of Phalcon installed before.

Windows DLLs are available in the download page.

As always, many thanks to everyone involved in this release and thanks for choosing Phalcon!

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Phalcon 2.0.10 released

We are excited to announce the immediate availability of Phalcon 2.0.10!

This is the tenth maintenance release in the 2.0.x series, adding more fixes
and improvements to make the most of Phalcon.

Changes in 2.0.10

  • ORM: Added support for DATE columns in Oracle
  • Fixed wrong total_items and total_pages in Paginator when the query builder has set groupBy()
  • Fixed Phalcon\Acl\Memory::allow #11210 related to the inconsistent behavior with access specified as string and array
  • Added quoting column in Phalcon\Db\Dialect\MySQL::addColumn when define position of the column
  • Added support to define position of the column in Phalcon\Db\Dialect\MySQL::modifyColumn
  • Fixed Phalcon\Mvc\Model\Query\Builder #11298 related to resetting limit to null
  • Fixed Phalcon\Tag::getTitle #11185. Now a title will be automatically escaped.
  • Fixed Phalcon\Translate\Adapter\Gettext::exists #11310 related to the wrong returned value (always true)
  • Fixed Phalcon\Translate\Adapter\Gettext::setLocale #11311 related to the incorrect setting locale
  • Added ability to persistent connection in Phalcon\Queue\Beanstalk::connect
  • Fixed Phalcon\Http\Response::redirect #11324. Incorrect initialization local array of status codes
  • Fixed cache backends #11322 related to saving number 0
  • Fixed Phalcon\Db\Dialect::escape #11359. Added ability to use the database name with dots.

Update/Upgrade

This version can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

If you have Zephir installed:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
zephir build

Note that running the installation script will replace any version of Phalcon installed before.

Windows DLLs are available in the download page.

Thanks to everyone involved in this release and thanks for choosing Phalcon!

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Phalcon 2.0.9 released

We are excited to announce the immediate availability of Phalcon 2.0.9!

This is the ninth maintenance release in the 2.0.x series, adding more fixes
and improvements to make the most of Phalcon.

Changes in 2.0.9

  • Added Phalcon\Security\Random::base58 - to generate a random base58 string
  • Added Phalcon\Logger\Adapter::isTransaction() to check whether the logger is currently in transaction mode or not (Phalcon 1.3 behavior)
  • Phalcon\Session\Adapter now closes the session when the adapter is destroyed (Phalcon 1.3 behavior)
  • Fixed fetching of data in modes FETCH_CLASS, FETCH_INTO and FETCH_FUNC in Phalcon\Db
  • Added missing code property in Phalcon\Validation\Message available in Phalcon 1.3.x
  • Added Phalcon\Db\Column::TYPE_TIMESTAMP to allow migrations on these kind of columns
  • Added Phalcon\Db\ColumnInterface::hasDefault to check if a column has a default value declared in its database column definition
  • Fixed determining of default value for column in Phalcon\Db\Dialect\MySQL, Phalcon\Db\Dialect\Sqlite and Phalcon\Db\Dialect\Postgresql classes
  • Now Phalcon\Mvc\Model::__call invokes finders as in __callStatic
  • Fixed Phalcon\Db\Dialect\Postgresql::getColumnDefinition for BIGINT and BOOLEAN data types
  • Fixed BOOLEAN default value in Phalcon\Db\Dialect\Postgresql
  • Added Phalcon\Validation\Validator\CreditCard - validation credit card number using luhn algorithm

Update/Upgrade

This version can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

If you have Zephir installed:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
zephir build

Note that running the installation script will replace any version of Phalcon installed before.

Windows DLLs are available in the download page.

Thanks to everyone involved in this release and thanks for choosing Phalcon!

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Phalcon 2.0.8 and 2.1 beta 2 released

We are excited to announce the immediate availability of Phalcon 2.0.8 and Phalcon 2.1.0 beta 2!

This is the eighth maintenance release in the 2.0.x series. In regards to Phalcon 2.1,
the second beta introduces bug fixes and new features intended to stabilize our next
major release.

Changes in 2.0.8

  • Added Phalcon\Security\Random::base58 - to generate a random base58 string
  • Added Phalcon\Logger\Adapter::isTransaction() to check whether the logger is currently in transaction mode or not (Phalcon 1.3 behavior)
  • Phalcon\Session\Adapter now closes the session when the adapter is destroyed (Phalcon 1.3 behavior)
  • Fixed fetching of data in modes FETCH_CLASS, FETCH_INTO and FETCH_FUNC in Phalcon\Db
  • Added missing code property in Phalcon\Validation\Message available in Phalcon 1.3.x
  • Added Phalcon\Db\Column::TYPE_TIMESTAMP to allow migrations on these kind of columns
  • Added Phalcon\Db\ColumnInterface::hasDefault to check if a column has a default value declared in its database column definition
  • Fixed determining of default value for column in Phalcon\Db\Dialect\MySQL, Phalcon\Db\Dialect\Sqlite and Phalcon\Db\Dialect\Postgresql classes
  • Now Phalcon\Mvc\Model::__call invokes finders as in __callStatic
  • Fixed Phalcon\Db\Dialect\Postgresql::getColumnDefinition for BIGINT and BOOLEAN data types
  • Fixed BOOLEAN default value in Phalcon\Db\Dialect\Postgresql
  • Added Phalcon\Validation\Validator\CreditCard - validation credit card number using luhn algorithm

Changes in 2.1.0 beta 2

  • Phalcon\Mvc\Model now implements JsonSerializable making easy serialize model instances
  • When destroying a Mvc\Model\Manager object the PHQL cache is clean
  • Method isSetOption in Phalcon\Validation\ValidatorInterface marked as deprecated, please use hasOption
  • Added internal check "allowEmpty" before calling a validator. If it option is true and the value of empty, the validator is skipped
  • Added default header: Content-Type: "application/json; charset=UTF-8" in method Phalcon\Http\Response::setJsonContent
  • Loop structure in Volt now can be passed to macros and functions as loop.self

Last month, important improvements to support PHP7 have been done by the Zephir Team, so we expect to have a usable version of Phalcon for PHP7 soon.

Update/Upgrade

This version can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

If you have Zephir installed:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
zephir build

Note that running the installation script will replace any version of Phalcon installed before.

Windows DLLs are available in the download page.

Thanks to everyone involved in this release and thanks for choosing Phalcon!

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Phalcon 2.1.0 beta 1 released

We're excited to announce the first beta release of Phalcon 2.1!

The 2.1.x series are going to be supported for a much longer period than previous versions, thus it is marked as our first Long Term Support LTS release!

In the Phalcon 2.0.x series, we introduced a lot of new features as well as bug fixes. Our focus however has always been to keep backwards compatibility with Phalcon 1.3.x series, while at the same time encourage developers to upgrade to 2.0.x. This allowed ample time for developers to adjust their applications to work with the 2.0.x series.

Phalcon 2.1 introduces new features some of them incompatible with previous released versions, so make sure you test your application before upgrading a production system.

We are confident that the changes in this release warrant the upgrade :)

Deprecation for PHP 5.3

Phalcon 2.0.x is the latest series of releases supporting PHP 5.3 (>= 5.3.21). Due to this constraint, we were unable to include some performance enhancements to the framework.

From 2.1.x onwards we are deprecating support for PHP 5.3. We highly encourage developers to upgrade their installations to 5.6, since PHP 7 is just around the corner. We are working on PHP 7 support for Phalcon, but in the meantime the recommended PHP version with Phalcon is 5.6.

Phalcon\Mvc\Model\Validation is now deprecated

Phalcon\Mvc\Model\Validation is now deprecated in favor of Phalcon\Validation. The functionality of both components is merged into one, allowing us to reduce the codebase while offering the same functionality as before.

Previously validations were implemented as follows:

namespace Invo\Models;

use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Email as EmailValidator;
use Phalcon\Mvc\Model\Validator\Uniqueness as UniquenessValidator;

class Users extends Model
{
    public function validation()
    {
        $this->validate(
            new EmailValidator(
                [
                    'field' => 'email',
                ]
            )
        );

        $this->validate(
            new UniquenessValidator(
                [
                    'field'   => 'username',
                    'message' => 'Sorry, That username is already taken',
                ]
            )
        );

        if ($this->validationHasFailed() == true) {
            return false;
        }
    }
}

Introducing Phalcon\Validation, you will need to change the above to:

namespace Invo\Models;

use Phalcon\Mvc\Model;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Email as EmailValidator;
use Phalcon\Validation\Validator\Uniqueness as UniquenessValidator;

class Users extends Model
{
    public function validation()
    {
        $validator = new Validation();

        $validator->add(
            'email',
            new EmailValidator()
        );

        $validator->add(
            'username',
            new UniquenessValidator(
                [
                    'message' => 'Sorry, That username is already taken',
                ]
            )
        );

        return $this->validate();
    }
}

You will agree that this change makes the code much smaller and easier to read.

Changed the constructor of Phalcon\Mvc\Model

The constructor of model classes has been changed, to allow you to pass an array of initialization data:

$customer = new Customer(
    [
        'name'   => 'Peter',
        'status' => 'Active',
    ]
);

Using this method is the same as calling assign(), any setter available will be used and will fallback to property assignment.

Phalcon\Mvc\View supports many views directories

This has been one of the features that our community requested many times in the past. We are happy to announce that you can use any kind of folder hierarchy with your application for your view files. This is specially useful for reusing views and layouts between modules:

use Phalcon\Mvc\View;

// ...

$di->set(
    'view',
    function () {

        $view = new View();

        $view->setViewsDir(
            [
                '/var/www/htdocs/blog/modules/backend/views/',
                '/var/www/htdocs/blog/common/views/',
            ]
        );

        return $view;
    }
);

Phalcon\Mvc\View now supports absolute paths

An absolute path can now be used on Mvc\View::setLayoutsDir and Mvc\View::setPartialsDir. This allows the use of folders outside the main views folder:

use Phalcon\Mvc\View;

// ...

$di->set(
    'view',
    function () {

        $view = new View();

        $view->setViewsDir(
            [
                '/var/www/htdocs/blog/modules/backend/views/',
                '/var/www/htdocs/blog/common/views/',
            ]
        );

        $view->setLayoutsDir(
            '/var/www/htdocs/common/views/layouts/'
        );

        return $view;
    }
);

Phalcon\Di is now bound to services closures

In the past, we had to pass the dependency injector inside a service closure, if we had to perform some actions inside the closure. Examples of that were accessing the configuration object or the events manager. Now we can use $this to access the Phalcon\Di along with the registered services.

Code before:

use Phalcon\Mvc\Dispatcher;

// ...

$di->set(
    'dispatcher',
     function () use ($di) {
        $eventsManager = $di->getEventsManager();

        $eventsManager->attach(
            'dispatch:beforeException',
            new NotFoundPlugin()
        );

        $dispatcher = new Dispatcher;
        $dispatcher->setEventsManager($eventsManager);

        return $dispatcher;
    }
);

Now you can access services without passing $di:

use Phalcon\Mvc\Dispatcher;

// ...

$di->set(
    'dispatcher',
    function () {
        $eventsManager = $this->getEventsManager();

        $eventsManager->attach(
            'dispatch:beforeException',
            new NotFoundPlugin()
            );

        $dispatcher = new Dispatcher;
        $dispatcher->setEventsManager($eventsManager);
        return $dispatcher;
    }
);

Service Resolve overriding

If an object is returned after firing the event beforeServiceResolve in Phalcon\Di, the returned instance overrides the default service localization process.

The following example shows how to override the creation of the service response from a custom plugin:

use Phalcon\Di;
use Phalcon\Http\Response;
use Phalcon\Events\Manager;

use MyApp\Plugins\ResponseResolverInterceptor;

$di = new Di();

$eventsManager = new EventsManager;

// Intercept service creation
$eventsManager->attach(
    'di',
    new ResponseResolverInterceptor()
);

$di->set('response', Response::class);

$di->setInternalEventsManager($eventsManager);

The plugin can now intercept the creation of services:

namespace MyApp\Plugins;

use Phalcon\Http\Response;

class ResponseResolverInterceptor
{
    private $cache = false;

    public function beforeServiceResolve($event, $di, $parameters)
    {
        // Intercept creation of responses
        if ($parameters['name'] == 'response' && $this->cache == false) {
            $response = new Response();
            $response->setHeader('Cache-Control', 'no-cache, must-revalidate');

            return $response;
        }
    }
}

Disabling the view from an action

Sometimes the view must be disabled by calling $this->view->disable() within an action in order to avoid the Phalcon\Mvc\View component to process the relevant view(s).

Now this much easier; simply return false:

use Phalcon\Mvc\Controller;

class Api extends Controller
{
    public function loginAction()
    {
        if ($this->safeApp->isBanned()) {
            $this->response->setStatusCode(401, "Unauthorized");
            return false;
        }

        // ...
    }
}

Returning a string makes it the body of the response

Return a string from an action takes it as the body of the response:
(same as return $this->response->setContent('Hello world'))

use Phalcon\Mvc\Controller;

class Session extends Controller
{
    public function welcomeAction()
    {
        return '<h1>Hello world!</h1>';
    }
}

This feature is specially handy if Phalcon\Mvc\View\Simple is used instead of Phalcon\Mvc\View:

use Phalcon\Mvc\Controller;

class Session extends Controller
{
    public function welcomeAction($name)
    {
        return $this->view->render(
            'welcome/index',
            [
                'name' => $name,
            ]
        );
    }
}

This feature is also available in Mvc\Micro handlers:

use Phalcon\Mvc\Micro;

$app = new Micro();

// ...

$app->get(
    '/hello/{name}',
    function () {
        return $this->view->render(
            'hello',
            [
                'name' => $name,
            ]
        );
    }
);

Override dispatcher+view behavior in routes

Routes now can have an associated callback that can override the default dispatcher + view behavior:

// Make a redirection if the /help route is matched
$router->add('/help', [])->match(function () {
    return $this->getResponse()->redirect('https://support.google.com/');
});

// Return a string directly from the route
$router->add('/', [])->match(function () {
    return '<h1>It works</h1>';
});

See the full CHANGELOG for Phalcon 2.1.

Help with Testing

This version can be installed from the 2.1.x branch. If you don't have Zephir installed follow these instructions:

git clone https://github.com/phalcon/cphalcon
git checkout 2.1.x
cd cphalcon/ext
sudo ./install

If you have Zephir installed:

git clone https://github.com/phalcon/cphalcon
cd cphalcon/
git checkout 2.1.x
zephir build

We hope that you will enjoy these improvements and additions. We invite you to share your thoughts and questions about this version onĀ Phosphorum.

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Phalcon 2.0.7 released

We are excited to announce the release of Phalcon 2.0.7!
This is our seventh release in the 2.0.x series and it contains bug fixes and new features for your enjoyment!

Changes

  • Image\Adapter\Gd::save() no longer fails if the method or the instance is created with a filename without an extension
  • Fixed segfault and implementation of Image\Adapter\Imagick::text()
  • Exceptions thrown in Volt compiler are now Phalcon\Mvc\View\Engine\Exception
  • Now you can import macros from other files using {% include "file.volt" %}
  • Undefined function calls fall back to macro calls in Volt templates
  • Automatic bound parameters in Mvc\Model\Criteria now uses a different prefix
    than Mvc\Model\Query\Builder to avoid collisions
  • Added Cache\Multiple::flush() to flush the cache backends added to the multiple system
  • Fixed Session\Bag::remove()
  • Session\Bag::destroy() eliminates any temporary data in the variables bag
  • afterCreate/afterUpdate are only called if saving related records was successful
  • Added an optional parameter removeData to Session\Adapter::remove() to remove any data in $_SESSION that belongs to the uniqueId or the whole session data
  • Now session variables making use of unique prefixes use # as internal separator
  • Added parameter that changes the default operator for conditions in method Mvc\Model\Criteria::fromImput() #10749
  • Added \Phalcon\Queue\Beanstalk::listTubes() to get list of a tubes
  • Added a fix to avoid that a table present in many sub-queries causes invalid SQL generation
  • Add CookieInterface, update Cookie and Cookies to use this interface - Decoupling Cookies and Cookie - Check Session state before using it in Cookie. #10789
  • Fixed merge of two Phalcon\Config instances that contains object values different than Phalcon\Config compatible instances
  • When creating tables in Postgres, inline PRIMARY keys are now escaped properly #10797
  • Fixed incorrect generation of SELECT COUNT(*) causing unexpected exceptions when phqlLiterals is disabled
  • Added Phalcon\Security\Random - secure random number generator class. Provides secure random number generator which is suitable for generating session key in HTTP cookies, etc

Update/Upgrade

This version can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

If you have Zephir installed:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
zephir build

Note that running the installation script will replace any version of Phalcon installed before.

Windows DLLs are available in the download page.

Thanks to everyone involved in this release and thanks for choosing Phalcon!

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Phalcon 2.0.6 released

We are excited to announce the release of Phalcon 2.0.6!

This version contains mostly bug fixes as well as improvements to the 2.0.x series.

Changes

  • Builds in TravisCI now uses Docker to perform faster builds
  • Added Http\Response::setCache() to easily set cache headers.
  • When a beanstalkd connection is closed, the adapter does not produce a notice anymore
  • Default separator in Text::increment is now _ (underscore)
  • Using tel_field in Volt now generates correct PHP code
  • SQL generated by PostgreSQL dialect in dropTable and dropView is now correct
  • Errors generated in Cache\Backend\Memcached now shows the result code to easily debug problems
  • Fixed LIMIT/OFFSET SQL generation in Mvc\Model\Query\Builder
  • Fixed Logger\Formatter\Line to match 1.3.x behavior
  • Fixed warning when castOnHydrate is true #10648
  • Added name before int/float/numeric/string/bool/null/other variables in Debug\Dump::output
  • Now Validation\Validator\Identical allows both 'accepted' and 'value' as value to keep backwards compatibility
  • Added \Phalcon\Mvc\Model\MetaData\Redis adapter.
  • Added Redis Session adapter
  • Fixed bug in Mvc\Model\Criteria::fromInput preventing it from using renamed columns
  • Fixed bug in Http\Request getRawBody()/getPut() clears input buffer #10694

Update/Upgrade

This version can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

If you have Zephir installed:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
zephir build

Note that running the installation script will replace any version of Phalcon installed before.

Windows DLLs are available in the download page.

See the upgrading guide for more information about upgrading to Phalcon 2.0.x from 1.3.x.

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Phalcon 2.0.5 released

We are happy to announce that Phalcon 2.0.5 is released.

This version contains bug fixes and small improvements to the 2.0.x series.

Changes

  • Fixed a bug that makes that attaching an events manager to a Mvc\Application causes view->render() not being called
  • Fixed bug that makes generated SQL statements using FOR UPDATE not being parsed correctly
  • The email filter now no longer removes the ' character #10603
  • When an array is bound the cached representation in PHQL makes the SQL being incorrectly generated the second time.
  • Added Mvc\Model\MetaData\Memcache and Mvc\Model\MetaData\Libmemcached adapters
  • Fixed a bug that makes macro can't be called recursively in Volt

Update/Upgrade

This version can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

If you have Zephir installed:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
zephir build

Note that running the installation script will replace any version of Phalcon installed before.

Windows DLLs are available in the download page.

See the upgrading guide for more information about upgrading to Phalcon 2.0.x from 1.3.x.

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Phalcon 2.0.4 released

As part of our three to five weeks minor release schedule, we are excited to announce that Phalcon 2.0.4 has been released!

The number of improvements and bug fixes are a lot more compared to other releases in the 2.0.x series:

Changes

  • Fixed bug in Phalcon\Mvc\Model::update() that mistakenly throws an exception when the record does exist
  • Now links in Phalcon\Debug point to https://api.phalconphp.com instead of https://docs.phalconphp.com
  • Implemented a more versatile way to assign variables in Volt allowing to assign properties and array indexes
  • Improved generation of macros in Volt using anonymous functions instead of plain PHP functions, which allows binding the adapter object and injecting services within them
  • Fixed generation and validation of default parameters in Volt's macros
  • Added Phalcon\Assets\Manager::getCollections() to return all collections registered #2488
  • Now Phalcon\Mvc\Url::getStatic() generates URLs from routes
  • Introduced Phalcon\Mvc\EntityInterface to allow parameters receive both Phalcon\Mvc\Model and Phalcon\Mvc\Collection instances. This interface allows Mvc\Model\Validators to be used in Mvc\Collection
  • Added Phalcon\Session\Adapter::setName() to change the session name
  • Added BIGINT column type support in Phalcon\Db
  • Added new types Phalcon\Db\Column::BLOB and Phalcon\Db\Column::DOUBLE #10506
  • Automatic binding of Large Object data (LOB) in the ORM
  • Support for BIT types in MySQL with binding as booleans
  • Added Phalcon\Flash\Direct::output() allowing to place flash messages in a specific place of the view #629
  • Added 'autoescape' option that allows to globally enable autoescape in any Volt template
  • Added readAttribute/writeAttribute to Phalcon\Mvc\Collection\Document
  • Added toArray to Phalcon\Mvc\Collection\Document
  • Global setting db.force_casting now forces casting bound parameters to specified bind types
  • Introduced new placeholders in PHQL enclosed in brackets that allow to set the type: {name:str} or {names:array}
  • Now you can bind arrays in bound parameters in PHQL
  • Global setting orm.cast_on_hydrate allows casting hydrated attributes to the original types in the mapped tables instead of using strings
  • Values in LIMIT/OFFSET clause are now passed using bound parameters in PHQL
  • Allowing late state binding in both Simple/Complex results to allow override Mvc\Model::cloneResultMap
  • Added method distinct() in Phalcon\Mvc\Model\Criteria #10536
  • Added global setting orm.ignore_unknown_columns to ignore unexpected columns when hydrating instances in the ORM. This fixes extra auxiliary columns used in Db\Adapter\Pdo\Oracle
  • Added support for afterFetch in Mvc\Collection
  • Added beforeMatch parameter in @Route annotation of Mvc\Router\Annotations
  • Added groupBy/getGroupBy/having/getHaving to Mvc\Model\Criteria
  • Phalcon\Mvc\Model::count() now return values as integer
  • Removed __construct from Phalcon\Mvc\View\EngineInterface
  • Added Phalcon\Debug\Dump::toJson() to return an JSON string of information about a single variable
  • Instances in Phalcon\Di are built using internal optimizers instead of \ReflectionClass (PHP 5.6)
  • Added Phalcon\Mvc\Model\Validator\IP from incubator
  • Added parameter return defaultValue in Phalcon\Mvc\Model\Validator::getOption()
  • Developers can now define relationships based on conditionals

Highlights

Typed Placeholders in the ORM

Before this version, only standard placeholders (strings and numerical) were supported in PHQL. Placeholders allowed you to bind parameters to avoid SQL injections:

$phql = "SELECT * FROM Store\Robots WHERE id > :id:";
$robots = $this->modelsManager->executeQuery($phql, ['id' => 100]);

However, some database systems require additional actions when using placeholders like specify the bind type:

use Phalcon\Db\Column;

// ...

$phql = "SELECT * FROM Store\Robots LIMIT :number:";
$robots = $this->modelsManager->executeQuery(
    $phql,
    ['number' => 10],
    Column::BIND_PARAM_INT
);

To make this task easy, Phalcon 2.0.4 introduces typed placeholders, these work exactly as the other supported ones but additionally you can specify the type:

$phql = "SELECT * FROM Store\Robots LIMIT {number:int}";
$robots = $this->modelsManager->executeQuery(
    $phql,
    ['number' => 10]
);

$phql = "SELECT * FROM Store\Robots WHERE name <> {name:str}";
$robots = $this->modelsManager->executeQuery(
    $phql,
    ['name' => $name]
);

You can also omit the type if you don't need to specify it:

$phql = "SELECT * FROM Store\Robots WHERE name <> {name}";
$robots = $this->modelsManager->executeQuery(
    $phql,
    ['name' => $name]
);

Typed placeholders are also more powerful, since we can now bind a static array without having to pass each element independently as a placeholder:

$phql = "SELECT * FROM Store\Robots WHERE id IN ({ids:array})";
$robots = $this->modelsManager->executeQuery(
    $phql,
    ['ids' => [1, 2, 3, 4]]
);

The following types are available:

Bind Type Bind Type Constant Example
str Column::BIND_PARAM_STR {name:str}
int Column::BIND_PARAM_INT {number:int}
double Column::BIND_PARAM_DECIMAL {price:double}
bool Column::BIND_PARAM_BOOL {enabled:bool}
blob Column::BIND_PARAM_BLOB {image:blob}
null Column::BIND_PARAM_NULL {exists:null}
array Array of Column::BIND_PARAM_STR {codes:array}
array-str Array of Column::BIND_PARAM_STR {names:array}
array-int Array of Column::BIND_PARAM_INT {flags:array}

Cast bound parameters values

By default, bound parameters aren't casted in the PHP userland to the specified bind types, this option allows you to make Phalcon cast values before bind them with PDO.

A classic situation when this problem raises is passing a string in a LIMIT/OFFSET placeholder:

$number = '100';
$robots = $modelsManager->executeQuery(
    'SELECT * FROM Some\Robots LIMIT {number:int}',
    ['number' => $number]
);

This causes the following exception:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:
Syntax error or access violation: 1064 You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right
syntax to use near ''100'' at line 1' in /Users/scott/demo.php:78

This happens because 100 is a string variable. It is easily fixable by casting the value to integer first:

$number = '100';
$robots = $modelsManager->executeQuery(
    'SELECT * FROM Some\Robots LIMIT {number:int}',
    ['number' => (int) $number]
);

However this solution requires that the developer pays special attention about how bound parameters are passed and their types. To make this task easier and avoid unexpected exceptions you can instruct Phalcon to do this casting for you:

\Phalcon\Db::setup(['forceCasting' => true]);

The following actions are performed according to the bind type specified:

Bind Type Action
Column::BIND_PARAM_STR Cast the value as a native PHP string
Column::BIND_PARAM_INT Cast the value as a native PHP integer
Column::BIND_PARAM_BOOL Cast the value as a native PHP boolean
Column::BIND_PARAM_DECIMAL Cast the value as a native PHP double

Cast on Hydrate

Values returned from the database system are always represented as string values by PDO, no matter if the value belongs to a numerical or boolean type column. This happens because some column types cannot be represented with its corresponding PHP native types due to their size limitations.

For instance, a BIGINT in MySQL can store large integer numbers that cannot be represented as a 32bit integer in PHP. Because of that, PDO and the ORM by default, make the safe decision of leaving all values as strings.

However, some developers may find this unexpected and uncomfortable. From Phalcon 2.0.4, you can set up the ORM to automatically cast those types considered safe to their corresponding PHP native types:

\Phalcon\Mvc\Model::setup(['castOnHydrate' => true]);

This way you can use strict operators or make assumptions about the type of variables:

$robot = Robots::findFirst();
if ($robot->id === 11) {
    echo $robot->name;
}

Relationships with conditionals

With 2.0.4 you can create relationships based on conditionals. When querying based on the relationship the condition will be automatically appended to the query:

use Phalcon\Mvc\Model;

// Companies have invoices issued to them (paid/unpaid)

// Invoices model
class Invoices extends Model
{

}

// Companies model
class Companies extends Model
{
    public function initialize()
    {
        // All invoices relationship
        $this->hasMany('id', 'Invoices', 'inv_id', [
            'alias' => 'invoices'
        ]);

        // Paid invoices relationship
        $this->hasMany('id', 'Invoices', 'inv_id', [
            'alias'    => 'invoicesPaid',
            'params'   => [
              'conditions' => "inv_status = 'paid'"
            ]
          ]
        );

        // Unpaid invoices relationship + bound parameters
        $this->hasMany('id', 'Invoices', 'inv_id', [
            'alias'    => 'invoicesUnpaid',
            'params'   => [
              'conditions' => "inv_status <> :status:",
              'bind' => ['status' => 'unpaid']
            ]
          ]
        );
    }
}

Update/Upgrade

This version can be installed from the master branch, if you don't have Zephir installed follow these instructions:

git clone http://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

If you have Zephir installed:

git clone http://github.com/phalcon/cphalcon
cd cphalcon
zephir build

Note that running the installation script will replace any version of Phalcon
installed before.

Windows DLLs are available in the download page.

See the upgrading guide for more information about upgrading to Phalcon 2.0.x from 1.3.x.

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000

Phalcon's release process

Phalcon Process

The following post explain our release process:

Official Releases

Since version 0.5, release numbering works as follows:

  • Versions are numbered in the form A.B.C where A.B is the major version number and C is the minor version
  • Backwards compatibility is ensured between minor versions ie. A.B.C and A.B.C+1
  • Minor version is incremented for small releases

Each Phalcon release will have a tag indicating its version number. Before Phalcon 2, all versions including minor versions had their own branch, starting from Phalcon 2 major versions have their own branch, but minor versions all they share the branch of the major version.

Major release

Major release will happen between 6 and 9 months. These release contain new features, improvements and bug fixes. A major release may deprecate features from previous releases.

Minor release

Minor releases add bug and security fixes and new features. These releases are compatible with versions of the same major version. A.B.C+1 is compatible with A.B.C. These versions will happen between 3 and 5 weeks. We encourage all Phalcon users to update minor versions.

Supported versions

Development is isolated in each respective branch. The Master branch will always contain the current version released as stable. Each supported version will be updated with any minor revisions that happen in the current version. Older versions will receive only bug fixes and security updates.

If a new version has to have an API change which will change backwards compatibility then we will extend the support on older versions to allow users to adjust their code. Naturally any upcoming changes that will break backwards compatibility will be communicated with the community well in advance.

State of Phalcon versions

  • Phalcon 1.2.x: Supported until 2014-03-17. No longer supported.
  • Phalcon 1.3.x: Supported until 2015-05-08. No longer supported.
  • Phalcon 2.0.x: Supported until 2016-04-17 (1 year from release date)
  • Phalcon 2.1.x: LTS release. Supported until 2017-09-30 (2 years from release date)

<3 Phalcon Team

01010000011010000110000101101100011000110110111101101110010100000100100001010000