Quantcast
Channel: Phalcon Framework Blog
Viewing all 109 articles
Browse latest View live

Phalcon 2.0.6 released!

$
0
0

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


Phalcon 2.0.7 released!

$
0
0

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

Phalcon 2.1 beta released

$
0
0

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:

<?php

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:

<?php

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

Phalcon 2.0.8 and 2.1 beta 2 released

$
0
0

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

Phalcon 2.0.9 released

$
0
0

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

Phalcon 2.0.10 released

$
0
0

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 bug#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 bug#11298 related to resetting limit to null
  • Fixed Phalcon\Tag::getTitle bug#11185. Now a title will be automatically escaped.
  • Fixed Phalcon\Translate\Adapter\Gettext::exists bug#11310 related to the wrong returned value (always true)
  • Fixed Phalcon\Translate\Adapter\Gettext::setLocale bug#11311 related to the incorrect setting locale
  • Added ability to persistent connection in Phalcon\Queue\Beanstalk::connect
  • Fixed Phalcon\Http\Response::redirect bug#11324. Incorrect initialization local array of status codes
  • Fixed cache backends bug#11322 related to saving number 0
  • Fixed Phalcon\Db\Dialect::escape bug#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

Phalcon 2.1.0 RC1 released

$
0
0

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

Phalcon 2.0.13 released

$
0
0

Phalcon 2.0.13 released

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

This maintenance release number of bug fixes (outlined below). We had 2 more minor releases providing minor fixes since our last blog post, and the CHANGELOG for those is listed below:

2.0.11 (2016-05-04)

  • Fixed Model magic set functionality to maintain variable visibility and utilize setter methods.#11286
  • Added a prepareSave event to model saving
  • Added support for OnUpdate and OnDelete foreign key events to the MySQL adapter
  • Added ability to setLogLevel on multiple logs #10429
  • Fixed regression changes for Phalcon\Translate\Adapter\Gettext::prepareOptions #11429
  • Fixed Phalcon\Mvc\View\Engine\Volt::callMacro bug. Now it's correctly calling call_user_func_array instead of call_user_func
  • Fixed undefined method call Phalcon\Mvc\Collection\Manager::getConnectionService. Now Phalcon\Mvc\Collection::getConnectionService works correctly in according to documentation

2.0.12 (2016-05-16)

  • Fixed regression changes for Phalcon\Mvc\View\Engine\Volt::callMacro #11745
  • Fixed the argument type of Phalcon\Flash::success #11764

2.0.13 (2016-05-19)

  • Restored Phalcon\Text::camelize behavior #11767
  • Used Zephir v0.9.2 to maintain backwards compatibility

Update/Upgrade

Phalcon 2.0.13 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.

Phalcon 2.1.x

As you know, we had plans to release 2.1.0 some weeks ago but we faced some blocking bugs running Phalcon in PHP7 that delayed the launch. Most of these bugs have been fixed and the tests are passing in Travis. We have a few more bugs to address, so we expect to release it soon. If you want to try it out install it from the 2.1.x branch:

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

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

<3 Phalcon Team


Phalcon 3.0.0 released

$
0
0

Phalcon 3.0.0 final (LTS) released

The Phalcon team is very excited to share some news with our community!

The last few months, we have been working hard to push 2.1 out, which contains significant enhancements as well as some API changes that require attention so as not to break compatibility with your application.
On top of that we have been working in making Zephir PHP7 compatible so that you can enjoy Phalcon in your PHP7 application. Some news first though:

Versioning

For any future Phalcon releases we are adopting SemVer (http://semver.org). In short:

Given a version number MAJOR.MINOR.PATCH, increment the:
* MAJOR version when you make incompatible API changes,
* MINOR version when you add functionality in a backwards-compatible manner, and
* PATCH version when you make backwards-compatible bug fixes.
* Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

Since 2.1 has many API changes, we decided that it would be best to not release it as is and start using SemVer to better communicate with the community and keep track of our releases.

2.1 is dead, all hail 3.0

As mentioned above, 2.1 will not be fully backwards compatible. As a result, we are changing the version number to 3.0.

PHP version support

The Phalcon team takes security very seriously and thus have decided to provide support to PHP versions that are supported. As of 3.0, PHP 5.3 and 5.4 will be deprecated. We are making a small exception to this rule and will continue to support 5.5 for a little while, but since its support has expired a few days ago, it will too be deprecated in a future release.

The goodie bag

So what does 3.0 offer? The changelog is extensive as you can see. Below are highlights of the changes as well as areas you need to concentrate.

• PHP 5.3 and 5.4 are fully deprecated.
You can compile the code on your own, but we will not be able to support it nor can we guarantee that it will work as you expect it to. PHP 5.3 support expired mid 2014 and 5.4 expired mid 2015. We need to ensure our applications have all known vulnerabilities on the PHP side fixed and patched, thus we will not support any unsupported PHP version. This excludes PHP 5.5, whose support expired a few days ago. We will deprecate 5.5 in a future release but will make sure that you all know beforehand so that you can prepare.

INCOMPATIBLE: You will need to upgrade your PHP installation to 5.6. You can always continue to use the Phalcon version you are using, but in 3.0 support for PHP 5.4 has been deprecated and we cannot guarantee that PHP 5.5 will be fully functional.

APPLICATION

Phalcon\Cli\Console and Phalcon\Mvc\Application now inherits Phalcon\Application.
This change makes the interfaces more uniformed and offers additional functionality to the respective applications (cli/mvc)

BEANSTALK

• Added \Phalcon\Queue\Beanstalk::ignore().
Removes the named tube from the watch list for the current connection.

• Added \Phalcon\Queue\Beanstalk::pauseTube().
Can delay any new job being reserved for a given time.

• Added \Phalcon\Queue\Beanstalk::kick().
It moves jobs into the ready queue. If there are any buried jobs, it will only kick buried jobs. Otherwise it will kick delayed jobs.

// Kick the job, it should move to the ready queue again
if (false !== $job->kick()) {
    $job = $this->client->peekReady();
}

• Added \Phalcon\Queue\Beanstalk::listTubeUsed().
Returns the tube currently being used by the client.

• Added \Phalcon\Queue\Beanstalk::listTubesWatched().
Returns a list tubes currently being watched by the client.

• Added \Phalcon\Queue\Beanstalk::peekDelayed().
Return the delayed job with the shortest delay left.

$this->client->put('testPutInTube', ['delay' => 2]);
$job = $this->client->peekDelayed();

• Added \Phalcon\Queue\Beanstalk::jobPeek().
Returns the next available job.

$this->client->choose(self::TUBE_NAME_1);
$jobId = $this->client->put('testPutInTube');
$job   = $this->client->jobPeek($jobId);
$this->assertEquals($jobId, $job->getId());

CACHE

• The cache backend adapters now return boolean when calling Phalcon\Cache\BackendInterface::save

// Returns true/false
$result = $backendCache->save('my_key', $content);

• Added Phalcon\Cache\Frontend\Msgpack. MsgPack is a new frontend cache. It is an efficient binary serialization format, which allows exchanging data among multiple languages like JSON.

use Phalcon\Cache\Backend\File;
use Phalcon\Cache\Frontend\Msgpack;

// Cache the files for 2 days using Msgpack frontend
$frontCache = new Msgpack(
    [
        'lifetime' => 172800,
    ]
);

// Create the component that will cache 'Msgpack' to a 'File' backend
// Set the cache file directory - important to keep the '/' at the end of
// of the value for the folder
$cache = new File(
    $frontCache,
    [
        'cacheDir' => '../app/cache/',
    ]
);

// Try to get cached records
$cacheKey = 'robots_order_id.cache';
$robots   = $cache->get($cacheKey);

if ($robots === null) {
    // $robots is null due to cache expiration or data do not exist
    // Make the database call and populate the variable
    $robots = Robots::find(['order' => 'id']);

    // Store it in the cache
    $cache->save($cacheKey, $robots);
}

// Use $robots
foreach ($robots as $robot) {
    echo $robot->name, "\n";
}

• Fixed bug of destroy method of Phalcon\Session\Adapter\Libmemcached

• Added Phalcon\Cache\Backend\Memcache::addServers to enable pool of servers for memcache

$memcache->addServers('10.4.6.10', 11000, true);
$memcache->addServers('10.4.6.11', 11000, true);
$memcache->addServers('10.4.6.12', 11000, true);

CRYPT

• Mcrypt is replaced with openssl in Phalcon\Crypt #11530#11486
Due to the lack of updates for mcrypt for a number of years, its slow performance and the fact that the PHP core team decided to deprecate mcrypt as soon as possible (version 7.1 onward), we have replaced it with the much faster and supported openssl.

• Default encrypt algorithm in Phalcon\Crypt is now changed to AES-256-CFB

• Removed methods setMode(), getMode(), getAvailableModes() in Phalcon\CryptInterface (no longer apply with openssl)

BACKWARDS INCOMPATIBLE: Backwards compatibility from openssl to mcrypt is problematic if not impossible. We had to remove several methods that are no longer applicable. Additionally the rijndael-256 from mcrypt is no longer valid in openssl. The default encryption algorithm is AES-256-CFB

If you have data that has already been encrypted with mcrypt, you will need first to decrypt it before upgrading to 3.0 and then encrypt it again using 3.0 and therefore openssl. Failure to do so will result in loss of data. A port is available in the incubator. Please see the code here

DATABASE

• Dropped support of Oracle #12008#12009
Support of Oracle has been dropped from the Phalcon Core for the following reasons:
•• The lack of Oracle maintainer
•• The lack of relevant experience among the Phalcon Core Team
•• Weak support or interest from the community
•• Incomplete implementation that creates only the illusion of support for Oracle
•• Some issues hampering for the support of PHP 7 in Phalcon

Oracle components will be ported to the Phalcon Incubator. If the adapter receives support and enhancements from the community, we will consider making it part of the core again.

DI

Phalcon\Di is now bound to services closures allowing use Phalcon\Di as $this to access services within them. Additionally, closures used as handlers inMvc\Micro are now bound to the $app instance

Old way:

$diContainer->setShared(
    'modelsCache',
    function () use ($config) {
        $frontend = '\Phalcon\Cache\Frontend\\' . $config->get('modelsCache')->frontend;
        $frontend = new $frontend(
            [
                'lifetime' => $config->get('modelsCache')->lifetime,
            ]
        );
        $config   = $config->get('modelsCache')->toArray();
        $backend  = '\Phalcon\Cache\Backend\\' . $config['backend'];

        return new $backend($frontend, $config);
    }
);

New way:

$diContainer->setShared(
    'modelsCache',
    function () {
        $frontend = '\Phalcon\Cache\Frontend\\' . $this->config->get('modelsCache')->frontend;
        $frontend = new $frontend(
            [
                'lifetime' => $this->config->get('modelsCache')->lifetime,
            ]
        );
        $config   = $this->config->get('modelsCache')->toArray();
        $backend  = '\Phalcon\Cache\Backend\\' . $config['backend'];

        return new $backend($frontend, $config);
    }
);

Also note the nested DI behavior:

$foo = function() {
    get_class($this); // DI
    $bar = function () {
        get_class($this); // DI
        $baz = function () {
            // etc
        }
    }
}

• If an object is returned after firing the event beforeServiceResolve in Phalcon\Di it overrides the default service localization process

DISPATCHER

• Added Phalcon\Dispatcher::hasParam().

public function testAction()
{
    if (true === $this->dispatcher->hasParam('foo')) {
        // Parameter exists
    }
}

• Added method getActionSuffix() in Phalcon\DispatcherInterface. This allows you change the 'Action' suffix in controller actions.

• Corrected behavior to fire the dispatch:beforeException event when there is any exception during dispatching #11458

• CLI parameters are now handled consistently.

• Added Phalcon\Mvc\Controller\BindModelInterface and associated model type hint loading through dispatcher.

• Added Phalcon\Mvc\Collection::update, Phalcon\Mvc\Collection::create and Phalcon\Mvc\Collection::createIfNotExist

public function createAction()
{
    /**
     * Creates a document based on the values in the attributes, if not found by criteria
     */
    $robot = new Robot();
    $robot->name = 'MyRobot';
    $robot->type = 'Droid';
    $robot->create();
}

public function createOverrideAction()
{
    /**
     * Create a document
     */
    $robot = new Robot();
    $robot->name = 'MyRobot';
    $robot->type = 'Droid';
    //create only if robot with same name and type does not exist
    $robot->createIfNotExist( array( 'name', 'type' ) );
}

public function updateAction()
{
    /**
     * Update a document
     */
    $robot = Robots::findFirst(['id' => 1]);
    $robot->name = 'MyRobot';
    $robot->type = 'Droid';
    $robot->update();
}

EVENTS

• Now Phalcon\Events\Event implements Phalcon\Events\EventInterface

Phalcon\Events\Event::getCancelable renamed to Phalcon\Events\Event::isCancelable

BACKWARDS INCOMPATIBLE: Any references to getCancelable will stop working. You will need to rename the function to isCancelable

Old way:

public function cancelAction()
{
    if (true === $this->eventsManager->getCancelable()) {
        // do something here
    }
}

New way:

public function cancelAction()
{
    if (true === $this->eventsManager->isCancelable()) {
        // do something here
    }
}

• Removed Phalcon\Events\Manager::dettachAll in favor of Phalcon\Events\Manager::detachAll

BACKWARDS INCOMPATIBLE: Any references to dettachAll will stop working. You will need to rename the function to detachAll

Old way:

public function destroyAction()
{
    $this->eventsManager->dettachAll()
}

New way:

public function destroyAction()
{
    $this->eventsManager->detachAll()
}

FLASH

• Added ability to autoescape Flash messages #11448

$flash = new Phalcon\Flash\Session;
$flash->setEscaperService(new Phalcon\Escaper);

$flash->success("<script>alert('This will execute as JavaScript!')</script>");
echo $flash->output();
// <div class="successMessage"><script>alert('This will execute as JavaScript!')</script></div>

• Fixed Phalcon\Session\Flash::getMessages.
Now it returns an empty array in case of non existent message type request #11941

Old result:

use Phalcon\Session\Flash as FlashSession;

$flash = new FlashSession();
$flash->error('Error Message');
var_dump($flash->getMessages('success', false));

array (size=1)
  'error' =>
    array (size=1)
      0 => string 'Error Message' (length=13)

New result:

use Phalcon\Session\Flash as FlashSession;

$flash = new FlashSession();
$flash->error('Error Message');
var_dump($flash->getMessages('success', false));

array (size=0)
  empty

HTTP REQUEST/RESPONSE

• Added default header: Content-Type: "application/json; charset=UTF-8" in method Phalcon\Http\Response::setJsonContent

Old way:

use Phalcon\Http\Response;

$data     = 'Phlying with Phalcon';
$response = new Response();
$response->setContentType('application/json;');
$response->setJsonContent($data)
$response->send();

New way:

$data     = 'Phlying with Phalcon';
$response = new Response();
$response->setJsonContent($data)
$response->send();

• Added ability to spoof the HTTP request method.
Most browsers do not support sending PUT and DELETE requests via the method attribute in an HTML form. If the X-HTTP-Method-Override header is set, and if the method is a POST, then it is used to determine the 'real' intended HTTP method. The _method request parameter can also be used to determine the HTTP method, but only if setHttpMethodParameterOverride(true) has been called. By including a _method parameter in the query string or parameters of an HTTP request, Phalcon will use this as the method when matching routes. Forms automatically include a hidden field for this parameter if their submission method is not GET or POST.

• Added support of CONNECT, TRACE and PURGE HTTP methods.
- CONNECT: A variation of HTTP tunneling when the originating request is behind a HTTP proxy server. With this mechanism, the client first requests the HTTP proxy server to forward the TCP connection to the final endpoint. The HTTP proxy server then establishes the connection on behalf of the client.
- TRACE: A method used for debugging which echoes input back to the user. Note that this method is dangerous, since it introduces a risk whereby an attacker could steal information such as cookies and possibly server credentials.
- PURGE: Although not defined in the HTTP RFCs, some HTTP servers and caching systems implement this method and use it to purge cached data.

• Refactored Phalcon\Http\Request::getHttpHost.
Now it always returns the hostname or empty an string. Optionally validates and cleans host name #2573#11921

• Renamed Phalcon\Http\Request::isSoapRequest to Phalcon\Http\Request::isSoap and Phalcon\Http\Request::isSecureRequest to Phalcon\Http\Request::isSecure.
Left the originals functions as aliases and marked them deprecated.

CAUTION: Any references to isSoapRequest need to be renamed to isSoap. Any references to isSecureRequest need to be renamed to isSecure.

Old way:

public function testAction()
{
    if (true === $this->request->isSoapRequest()) {
        //
    }

    if (true === $this->request->isSecureRequest()) {
        //
    }
}

New way:

public function testAction()
{
    if (true === $this->request->isSoap()) {
        //
    }

    if (true === $this->request->isSecure()) {
        //
    }
}

• Added Phalcon\Http\Request::setStrictHostCheck and Phalcon\Http\Request::isStrictHostCheck to manage strict validation of the host name.

use Phalcon\Http\Request;

$request = new Request;

$_SERVER['HTTP_HOST'] = 'example.com';
$request->getHttpHost(); // example.com

$_SERVER['HTTP_HOST'] = 'example.com:8080';
$request->getHttpHost(); // example.com:8080

$request->setStrictHostCheck(true);
$_SERVER['HTTP_HOST'] = 'ex=am~ple.com';
$request->getHttpHost(); // UnexpectedValueException

$_SERVER['HTTP_HOST'] = 'ExAmPlE.com';
$request->getHttpHost(); // example.com

• Added Phalcon\Http\Request::getPort.
Returns the port on which the request is made i.e. 80, 8080, 443 etc.

• Added setLastModified method to Phalcon\Http\Response
Sets the Last-Modified header

public function headerAction()
{
    $this->response->setLastModified(new DateTime());
}

• Add setContentLength method to Phalcon\Http\Response
Sets the response content-length

public function headerAction()
{
    $this->response->setContentLength(2048);
}

LOADER

• Removed support for prefixes strategy in Phalcon\Loader

BACKWARDS INCOMPATIBLE: In Phalcon 2, you could load classes using a specific prefix. This method was very popular before namespaces were introduced. For instance:

<?php

use Phalcon\Loader;

// Creates the autoloader
$loader = new Loader();

// Register some prefixes
$loader->registerPrefixes(
    array(
        "Example_Base"    => "vendor/example/base/",
        "Example_Adapter" => "vendor/example/adapter/",
        "Example_"        => "vendor/example/"
    )
);

// Register autoloader
$loader->register();

// The required class will automatically include the
// file vendor/example/adapter/Some.php
$some = new Example_Adapter_Some();

This functionality is no longer supported

• Added \Phalcon\Loader::registerFiles and \Phalcon\Loader::getFiles. registerFiles registers files that are "non-classes" hence need a "require". This is very useful for including files that only have functions. getFiles
returns the files currently registered in the autoloader

$loader->registerFiles(
    [
        'fuctions.php',
        'arrayFunctions.php',
    ]
);

MODELS

• Changed constructor of Phalcon\Mvc\Model to allow pass an array of initialization data

$customer = new Customer(
    [
        'Name'   => 'Peter',
        'Status' => 'active',
    ]
);
$customer->save();

Phalcon\Mvc\Model now implements JsonSerializable making easy serialize model instances

$customers = Customers::find();
echo json_encode($customers); // {['id':1,...],['id':2,...], ...}

Phalcon\Mvc\Model\Criteria::getOrder renamed to Phalcon\Mvc\Model\Criteria::getOrderBy

BACKWARDS INCOMPATIBLE: Any references to getOrder will stop working. You will need to rename the function to getOrderBy

• Added method getOption() in Phalcon\Mvc\Model\RelationInterface
Returns an option by the specified name. If the option does not exist null is returned

• Added OR operator for Phalcon\Mvc\Model\Query\Builder methods: betweenWhere, notBetweenWhere, inWhere and notInWhere

$builder->betweenWhere('price', 100.25, 200.50);     // Appends a BETWEEN condition
$builder->notBetweenWhere('price', 100.25, 200.50);  // Appends a NOT BETWEEN condition
$builder->inWhere('id', [1, 2, 3]);                  // Appends an IN condition
$builder->notInWhere('id', [1, 2, 3]);               // Appends an NOT IN condition

• Added new getter Phalcon\Mvc\Model\Query\Builder::getJoins()
Returns the join parts from query builder

• When destructing a Mvc\Model\Manager PHQL cache is cleaned

• Added FULLTEXT index type to Phalcon\Db\Adapter\Pdo\Mysql

• Fixed afterFetch event not being sent to behaviors

• Fixed issue with Model::__set that was bypassing setters #11286

• Fixed issue with Model::__set setting hidden attributes directly when setters are not declared #11286

Phalcon\Mvc\Model\Manager::load() now can load models from aliased namespaces

Phalcon\Mvc\Model\Transaction\Manager now correctly keeps account of transactions #11554

Phalcon\Db\Dialect\Sqlite now maps additional column types to SQLite columns equivalents.

• Fixed Phalcon\Mvc\Model\Resultset::update() - Removed endless loop queries

• Fixed Phalcon\Mvc\Model\Manager::_mergeFindParameters - Merging conditions fix

ROLES

• Added Phalcon\Acl\RoleAware and Phalcon\Acl\ResourceAware Interfaces. Now you can pass objects to Phalcon\Acl\AdapterInterface::isAllowed as roleName and resourceName, also they will be automatically passed to function defined in Phalcon\Acl\AdapterInterface::allow or Phalcon\Acl\AdapterInterface::deny by type

use UserRole;       // Class implementing RoleAware interface
use ModelResource;  // Class implementing ResourceAware interface

// Set access level for role into resources
$acl->allow('Guests', 'Customers', 'search');
$acl->allow('Guests', 'Customers', 'create');
$acl->deny('Guests', 'Customers', 'update');

// Create our objects providing roleName and resourceName
$customer     = new ModelResource(1, 'Customers', 2);
$designer     = new UserRole(1, 'Designers');
$guest        = new UserRole(2, 'Guests');
$anotherGuest = new UserRole(3, 'Guests');

// Check whether our user objects have access to the operation on model object
$acl->isAllowed($designer, $customer, 'search')     // Returns false
$acl->isAllowed($guest, $customer, 'search')        // Returns true
$acl->isAllowed($anotherGuest, $customer, 'search') // Returns true

Phalcon\Acl\AdapterInterface::allow and Phalcon\Acl\AdapterInterface::deny have 4th argument - function. It will be called when using Phalcon\Acl\AdapterInterface::isAllowed

Phalcon\Acl\AdapterInterface::isAllowed have 4th argument - parameters. You can pass arguments for a function defined in Phalcon\Acl\AdapterInterface:allow or Phalcon\Acl\AdapterInterface::deny as associative array where key is argument name

// Set access level for role into resources with custom function
$acl->allow(
    'Guests',
    'Customers',
    'search',
    function ($a) {
        return $a % 2 == 0;
    }
);

// Check whether role has access to the operation with custom function
$acl->isAllowed('Guests', 'Customers', 'search', ['a' => 4]); // Returns true
$acl->isAllowed('Guests', 'Customers', 'search', ['a' => 3]); // Returns false

• Fixed wildcard inheritance in Phalcon\Acl\Adapter\Memory #12004#12006

use Phalcon\Acl;
use Phalcon\Acl\Adapter\Memory as MemoryAcl;

$acl = new MemoryAcl();

$acl->setDefaultAction(Acl::DENY);

$roleGuest      = new Role("guest");
$roleUser       = new Role("user");
$roleAdmin      = new Role("admin");
$roleSuperAdmin = new Role("superadmin");

$acl->addRole($roleGuest);
$acl->addRole($roleUser, $roleGuest);
$acl->addRole($roleAdmin, $roleUser);
$acl->addRole($roleSuperAdmin, $roleAdmin);

$acl->addResource("payment", ["paypal", "facebook",]);

$acl->allow($roleGuest->getName(), "payment", "paypal");
$acl->allow($roleGuest->getName(), "payment", "facebook");

$acl->allow($roleUser->getName(), "payment", "*");

echo $acl->isAllowed($roleUser->getName(), "payment", "notSet");  // true
echo $acl->isAllowed($roleUser->getName(), "payment", "*");       // true
echo $acl->isAllowed($roleAdmin->getName(), "payment", "notSet"); // true
echo $acl->isAllowed($roleAdmin->getName(), "payment", "*");      // true

ROUTES

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

• Amended Phalcon\Mvc\RouterInterface and Phalcon\Mvc\Router. Added missed addPurge, addTrace and addConnect methods.
Added addConnect for the CONNECT HTTP method, addPurge for the PURGE HTTP method and addTrace for the TRACE HTTP method

• Placeholders :controller and :action in Mvc\Router now defaults to /([\\w0-9\_\-]+) instead of /([\\a-zA-Z0-9\_\-]+)

• Modifier #u (PCRE_UTF8) is now default in regex based routes in Mvc\Router

Mvc\Router\Route now escapes characters such as . or + to avoid unexpected behaviors

• Fixed the use of the annotation router with namespaced controllers

• Fixed matching host name by Phalcon\Mvc\Route::handle when using port on current host name #2573

SECURITY

• Added Phalcon\Security::hasLibreSsl and Phalcon\Security::getSslVersionNumber
Mostly these are used internally but can be used to get information about libreSsl.

• Changed default hash algorithm in Phalcon\Security to CRYPT_BLOWFISH_Y

Phalcon\Security is using now Phalcon\Security\Random

• Enforced that Phalcon\Security::getToken() and Phalcon\Security::getTokenKey() return a random value per request not per call

Phalcon\Security::getToken() and Phalcon\Security::getTokenKey() are using now Phalcon\Security::_numberBytes instead of passed as argument or hard coded value

Phalcon\Security::hash() corrected not working CRYPTSTDDES, CRYPTEXTDES, MD5, CRYPT_SHA256

Phalcon\Security::hash() CRYPT_SHA512 fixed wrong salt length

• Added missing unit-tests for Phalcon\Security

SESSION

• Removed Phalcon\Session #11340

BACKWARDS INCOMPATIBLE: Any references to Phalcon\Session have to be removed and replaced with the relevant adapter class

• Fixed the Session write callback #11733

TEXT

• Added ability to use custom delimiter for Phalcon\Text::camelize and Phalcon\Text::uncamelize #10396

use Phalcon\Text;

public function displayAction()
{
    echo Text::camelize('c+a+m+e+l+i+z+e', '+'); // CAMELIZE
}

• Fixed Phalcon\Text:dynamic() to allow custom separator #11215

VIEW

• An absolute path can now be used to Mvc\View::setLayoutsDir
You can now use one layout path for all the landing pages of your application for instance, even from separate projects

• Now Phalcon\Mvc\View supports many views directories at the same time

• Return false from an action disables the view component (same as $this->view->disable())

public function displayAction()
{
    // Do some stuff here

    return false; // Same as $this->view->disable();
}

• Return a string from an action takes it as the body of the response

• Return a string from an Mvc\Micro handler takes it as the body of the response

public function displayAction()
{
    // Do some stuff here

    // $this->response->setContent('<h1>Hello World</h1>');
    return '<h1>Hello World</h1>';
}

• Fixed odd view behavior #1933 related to setLayout() and pick()

VALIDATION

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.

Old way:

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;
        }
    }
}

New way:

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', //your field name
            new EmailValidator([
                'model' => $this,
                'message' => 'Please enter a correct email address'
            ])
        );

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

        return $this->validate($validator);
    }
}

• Method isSetOption in Phalcon\Validation\ValidatorInterface marked as deprecated, please use hasOption

CAUTION: Any references to isSetOption need to be renamed to hasOption

Old way:

if (true === $validation->isSetOption('my-option')) {
    //
}

New way:

if (true === $validation->hasOption('my-option')) {
    //
}

• Added internal check allowEmpty before calling a validator. If it option is true and the value of empty, the validator is skipped

• Added option to validate multiple fields with one validator (fix uniqueness validator as well), also removes unnecessary model => $this in Phalcon\Validation\Validator\Uniqueness.

Phalcon\Validation\Validator\Alpha now correctly validates non-ASCII characters #11386

• Added Phalcon\Validation\CombinedFieldsValidator, validation will pass array of fields to this validator if needed

Phalcon\Validation\Validator\Digit now correctly validates digits #11374

use Phalcon\Validation\Validator\Digit as DigitValidator;

$validator->add(
    'height',
    new DigitValidator(
        [
            'message' => ':field must be numeric',
        ]
    )
);

$validator->add(
    [
        'height',
        'width',
    ],
    new DigitValidator(
        [
            'message' => [
                'height' => 'height must be numeric',
                'width'  => 'width must be numeric',
            ]
        ]
    )
);

• Added Phalcon\Validation\Validator\Date

use Phalcon\Validation\Validator\Date as DateValidator;

$validator->add(
    'date',
    new DateValidator(
        [
            'format'  => 'd-m-Y',
            'message' => 'The date is not valid',
        ]
    )
);

$validator->add(
    [
        'date',
        'anotherDate',
    ],
    new DateValidator(
        [
            'format'  => [
                'date'        => 'd-m-Y',
                'anotherDate' => 'Y-m-d',
            ],
            'message' => [
                'date'        => 'The date is invalid',
                'anotherDate' => 'The another date is invalid',
            ]
        ]
    )
);

• Fixed Phalcon\Validation::appendMessage to allow append message to the empty stack #10405

• Added convert option to the Phalcon\Validation\Validator\Uniqueness to convert values to the database lookup #12005#12030

use Phalcon\Validation\Validator\Uniqueness;

$validator->add(
    'username',
    new Uniqueness(
        [
            'convert' => function (array $values) {
                $values['username'] = strtolower($values['username']);

                return $values;
            }
        ]
    )
);

INTERFACES

• Removed __construct from all interfaces #11410#11441

• Added Phalcon\Cli\DispatcherInterface, Phalcon\Cli\TaskInterface, Phalcon\Cli\RouterInterface and Phalcon\Cli\Router\RouteInterface.

DOCUMENTATION

• Added Indonesian translation #840

VARIOUS

• Added Phalcon\Assets\Manager::exists() to check if collection exists

• Fixed Filter::add method handler #11581

• Fixed issue with radio not being checked when default value is 0 #11358

• Phalcon\Tag::getTitle() shows a title depending on prependTitle and appendTitle

• Using a settable variable for the Mongo Connection Service name instead of a hard coded string #11725

Phalcon\Debug\Dump skip debugging di, fix detecting private/protected properties

• Added new setter Phalcon\Escaper::setDoubleEncode() - to allow setting/disabling double encoding

• Fixed Phalcon\Config::merge for working with php7

PHP7

Phalcon 3.0 supports PHP7! In subsequent releases we will focus on the development of the framework to implove the compatibility and take advantage of the performance enhancements that PHP7 offers. You can install the framework in php7 using the usual installation instructions.

Support

Phalcon 3.0 Long Term Support (LTS) version is out, and it’s packed with new features to help you better create web applications with PHP. This version of the framework will be maintained for 3 years from now.

Acknowledgments

We want to greatly thank everyone who has contributed to accomplish and achieve the completion of this release. Special thanks to our friends around the world that have made possible this release:

Conclusion

Phalcon 3.0 takes a step forward towards a modern framework for PHP. We'll continue working making it more useful and performant for developers. Thank you once more to our wonderful community and users!

Installation

You can install Phalcon 3.0 for either PHP 5.5/5.6/7.0 using the following instructions:

git clone --depth=5 https://github.com/phalcon/cphalcon
cd cphalcon/build
sudo ./install

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

2017 Survey results

$
0
0

Hello everyone!

Back in March, we asked our community to fill in a short survey, in order to gauge why people are using Phalcon, what we should be doing better etc.

The survey was very brief and consisted of the following questions:

  • Why did you choose to use Phalcon (main reason but also expand please)? *
  • Do you use Phalcon in production? (elaborate) *
  • Comments for the team (optional)
  • Github username (optional)

We received 103 replies and we thank you all of you that took the time to give us input.

Results

Why did you choose to use Phalcon

  • 90.29% (93/103) responses chose Performance which is one of the main attributes of Phalcon.
  • 61.17% (63/103) also chose Flexibility/Simplicity
  • 3.88% (4/103) chose the Community
  • 2.91% (3/103) stated that they liked it
Clearly the above percentages do not add to 100% because many users chose more than one attribute of Phalcon as the reason they chose it

Do you use Phalcon in production?

79.61% (82/103) replied Yes. There were also a frew "planning to in the future" and of course some "no".

The above was a welcomed surprise. Survey takers in some cases informed us of their websites, which was awesome to see.

This data makes us redouble our efforts to ensure that our users have a high quality and fast framework that can help them and their applications.

Thank you all!

Comments for the team (optional)

The comments ranged from praise to some complains about the documentation (we are working on it).

A sample is below:

Keep up the good work.
It's my favorite framework
With Phalcon comes great responsibility :)
View's file structure needs a bit more documentation. I had to look up on stackoverflow to get the gist of it's file structure.
Excellent work guys, I love you team
Add full features look like laravel, big project orm important and needed
Keep up the improvement of docs and tutorials
Better documentation
Follow Uncle Bob's clean code rules .. your class and methods are to damn long! Aside from that though, God bless you and thank you so much for the work you do! :)
They did a great job and I would love to complete what I am learning now and start contributing
Phalcon team is awesome. But i think, developments should be more frequent.
Please, improve documentation...
Great work guys! Everything works like a charm, with Postgres or MySQL, with Nginx or Apache, and the documentation is awesome!
Maybe you need a bigger team, more communication, less open bugs, shared hostings support, easier way to debug for beginners like me ...
Currently I am using BoltCMS for a new project (mostly because the backend and documentation is easy for me to use/understand) but I would really love to use a similar project if it was done using Phalcon. Another thing missing is a solid e-commerce platform based on Phalcon (I would gladly pay to use/support something like that)
In my mind you should concentrate on examples where are used good practices, maybe CQRS or other architecture solution. Important thing is multimodule architecutre. In my mind its way to make Phalcon more popular for serious projects. Currently are some issues in this architecture, for example dispatching and security check. Make it php 7.1 compatible :)
Maybe a more Laravel kind of documentation.
Documentation needs some work. A lot of the powerful features of phalcon are not well documented (eg the validation class). Some more extensive examples would be nice too...
I really miss a proper tutorial..and there are like 5 ways to bootstrap your application and all look amateurish and messy
Great work! Please continue to expand PHQL, its great but can be quite limiting in its capabilities sometimes.
Hopefully there's gonna be updated video tutorials.
Very nice job and a big thank you for your work!

Conclusion

We intend on having these user surveys in regular intervals (say every six months or so) in order to get feedback from our community.

Clearly from this survey two things stand out:

  1. Speed/Performance is very important
  2. The documentation needs a lot of work

We will ensure that speed/performance are number one in our priority list, while keeping the framework feature rich. Indeed our documentation has not been stellar and more importantly not uniformed. Work on this has already started in Q1 where a total revamp of the documentation is scheduled at the end of this quarter (Q2) or earlier if possible.

We are also working on our Q2 goals (new blog post coming shortly) which take the above in consideration.

Appendix

Raw data file

Creating a New Phalcon App with Nanobox

$
0
0

This is a guest post from Scott Anderson at Nanobox.

Nanobox is a portable, micro platform for developing and deploying apps. When working locally, Nanobox uses Docker to spin up and configure a virtual development environment configured to your specific needs. When you're ready to deploy to live servers, Nanobox will take that same environment and spin it up on your cloud provider of choice, where you can then manage and scale your app through the Nanobox dashboard.

In this post, we'll walk through getting a brand new Phalcon app up and running locally, with nothing installed other than Nanobox. First create a free Nanobox account, then download and run the Nanobox installer.

Create a New Project

Create a project folder and cd into it:

mkdir nanobox-phalcon && cd nanobox-phalcon

Add a boxfile.yml

Nanobox uses the boxfile.yml to build and configure your app's runtime and environment. In the root of your project, create a boxfile.yml with the following:

run.config:
  engine: php
  engine.config:
    runtime: php-7.1
    document_root: public
    extensions:
      - phalcon
  extra_steps:
    - echo "alias phalcon=\'phalcon.php\'" >> /data/var/home/gonano/.bashrc

This tells Nanobox to:

  • Use the PHP engine, a set of scripts that build your app's runtime.
  • Use PHP 7.1.
  • Set the Apache document root to public.
  • Include the Phalcon extension. Nanobox takes a bare-bones approach to extensions, so you'll likely need to include other extensions. More information can be found here.
  • Add a bash alias for Phalcon Devtools so you can just use the phalcon command.

Add Phalcon Devtools to your composer.json

Create a composer.json file in the root of your project and add the phalcon/devtools package to your dev requirements:

{
    "require-dev": {
        "phalcon/devtools": "~3.0.3"
    }
}
NOTE: The version of Phalcon Devtools depends on which PHP version you're using

Start Nanobox and Generate a New Phalcon App

From the root of your project, run the following commands to start Nanobox and generate a new Phalcon app. As Nanobox starts, the PHP engine will automatically install and enable the Phalcon extension, run a composer install which will install Phalcon Devtools, then drop you into an interactive console inside the virtual environment. Your working directory is mounted into the /app directory in the VM, so as changes are made, they will be reflected both in the VM and in your local working directory.

# start nanobox and drop into a nanobox console
nanobox run

# cd into the /tmp directory
cd /tmp

# generate a new phalcon app
phalcon project myapp

# change back to the /app dir
cd -

# copy the generated app into your project
cp -a /tmp/myapp/* .

# exit the console
exit

Run the App Locally

Before actually running your new Phalcon app, we recommend using Nanobox to add a DNS alias. This will add an entry to your local hosts file pointing to your dev environment and provide a convenient way to access your app from a browser.

nanobox dns add local phalcon.dev

Nanobox provides a php-server helper script that starts both Apache (or Nginx depending on your boxfile.yml config) and PHP. When passed with the nanobox run command, it will start the local dev environment and immediately run your app.

nanobox run php-server

Once running, you can visit your app at phalcon.dev.

Check Out the Environment

Your virtual environment includes everything you need to run your Phalcon app. Feel free to poke around.

# drop into a Nanobox console
nanobox run

# check the php version
php -v

# check that phalcon devtools are available
phalcon info

# check that your local codebase is mounted
ls

# exit the console
exit

Phalcon & Nanobox

Nanobox gives you everything you need develop and run your Phalcon app in an isolated virtual environment. With the boxfile.yml in your project, collaborators can get up and running in minutes simply by running nanobox run.

Nanobox has a Phalcon Quickstart that includes everything covered in this post. They also have as guides for using Phalcon with Nanobox. In future posts, we'd like to cover other aspects of using Phalcon with Nanobox, including adding and connecting to a database, deploying Phalcon into production, etc. If you're interested let us know on Twitter.

Resources

Nanobox

Phalcon

Testimonial: How Phalcon helped r8em

$
0
0

We have received the following testimony from Michael Hanekom in our team email. Michael agreed to share his experience in our blog, and we are doing so without any edits:

Greetings to the Phalcon Team!

I am a 20 year veteran of corporate software development and I have followed Phalcon PHP with much excitement from it's early days till now.

Over the past 2 years we have created https://r8em.co.za as your platform to rate anything. Initially targeting local businesses and growing it into an international offering down the line.

The platform is a hybrid of technologies but uses a multi-module Phalcon setup running on Nginx servers scaling on AWS Elastic Beanstalk. We are also using Phalcon's database and caching abilities including a myriad of other features to deliver content to our expected 100,000+ concurrent users. Our current dataset includes roughly 30 million records on MariaDB and we serve high-speed sub-second searches using ElasticSearch. I am really happy that I made the move to Phalcon years ago and would recommend it to anyone considering themselves an expert in "best of breed" technologies.

Thank you Phalcon Team for all your hard work! You have made my life so much easier when it comes to deciding on a high-performance, feature-rich web development framework.

Looking forward to many more years and greater adoption of Phalcon PHP by some of the big players.

Best regards

Michael Hanekom Chief Technology Officer r8em - your platform to rate anything

Thank you Michael for your kind words! It is really rewarding to read that our work has helped Michael and his company perform their tasks better and faster.

We welcome any other testimonials so that we can spread the word about Phalcon and how it can help your projects/company.

<3 Phalcon Team

Phalcon 3.2.0 released - New docs

$
0
0

Hello everyone and Happy Father's day!

For our Father's day present, we are extremely happy to announce the release of our newest Phalcon version: 3.2.0.

Our Github issues page has well over 600 issues. However those are mostly New Feature Requests (NFRs), so we started clearing up more and more bugs as well as introducing suggested NFRs. Of course all this would not be feasible without the help of our amazing community: Thank you!

Documentation

Also as part of our goals for Q2, we are releasing our new documentation. We have been working hard to convert all the rst files (reStructuredText) to md (Markdown) and also have a first pass on identifying inconsistencies and enhancing the documentation. Of course a lot more is needed on that, but it will come in future versions.

We are now using Crowdin to help contributors translate our documents. The docs website has been updated but still needs a little bit of love with the stylesheet (coming very soon). Also you will note that the site mentions version 3.1; we will fix that this week coming to ensure that every document is properly versioned in Crowdin.

Our new documentation needs admittedly a little bit of fine tuning in terms of the CSS and the menus. This will be done in the upcoming week. Also, we are going through all the documents and ensuring the content is correct and accurate throughout. Examples and new functionality of new releases will also be added from now on, before we release so that the documents are up to date always.

NOTE: The documentation for previous versions is located here: https://olddocs.phalconphp.com.

Release

The release tag can be found here: 3.2.0. The Windows DLLs are in the releases Github page.

Changelog

  • Phalcon will now trigger E_DEPREACATED by using Phalcon\Mvc\Model\Criteria::addWhere, Phalcon\Debug::getMajorVersion, Phalcon\Dispatcher::setModelBinding, Phalcon\Tag::resetInput, Phalcon\Mvc\Model\Validator::__construct
  • Added Factory Adapter loaders #11001
  • Added ability to sanitize URL to Phalcon\Filter
  • Added missed $type argument to interface Phalcon\Mvc\Model\Query\BuilderInterface::join() to specify type join
  • Added Phalcon\Mvc\Model::hasUpdated and Phalcon\Mvc\Model:getUpdatedFields, way to check if fields were updated after create/save/update
  • Added support for having option in Phalcon\Paginator\Adapter\QueryBuilder #12111
  • Added Phalcon\Config::path to get a value using a dot separated path #12221
  • Added service provider interface to configure services by context #12783
  • Added the ability to load services from yaml (Phalcon\Di::loadFromYaml) and php array (Phalcon\Di::loadFromPhp) files, so we can keep the references cleanly separated from code #12784
  • Added Phalcon\Cache\Backend\Apcu to introduce pure support of APCu #12098, #11934
  • Added Phalcon\Annotations\Adapter\Apcu to introduce pure support of APCu #12098
  • Added option to disable snapshot update on create/save using Phalcon\Mvc\Model::setup(['updateSnapshotOnSave' => false]) or phalcon.orm.update_snapshot_on_save = 0 in php.ini
  • Added Phalcon\Mvc\Model\Manager::setModelPrefix and Phalcon\Mvc\Model\Manager::getModelPrefix to introduce tables prefixes #10328
  • Added methods Phalcon\Mvc\Model\Query\Builder::andHaving, Phalcon\Mvc\Model\Query\Builder::orHaving, Phalcon\Mvc\Model\Query\Builder::betweenHaving, Phalcon\Mvc\Model\Query\Builder::notBetweenHaving, Phalcon\Mvc\Model\Query\Builder::inHaving, Phalcon\Mvc\Model\Query\Builder::notInHaving
  • Added parameters skip_on_insert, skip_on_update and allow_empty_string and fixed a bug for renamed integer columns in Phalcon\Mvc\Model\MetaData\Strategy\Annotations::getMetaData
  • Added way to disable setters in Phalcon\Mvc\Model::assign by using Phalcon\Mvc\Model::setup or ini option
  • Added ability to sanitize special characters to Phalcon\Filter
  • Added a new Phalcon\Mvc\Model\Binder::findBoundModel method. Params fetched from cache are being added to internalCache class property in Phalcon\Mvc\Model\Binder::getParamsFromCache
  • Added Phalcon\Mvc\Model\Criteria::createBuilder to create a query builder from criteria
  • Added dispatcher::beforeForward event to allow forwarding request to the separated module #121, #12417
  • Added Phalcon\Security\Random:base62 to provide the largest value that can safely be used in URLs without needing to take extra characters into consideration #12105
  • Added Phalcon\Assets\ResourceInterface. So now Phalcon\Assets\Inline and Phalcon\Assets\Resource implements ResourceInterface
  • Added Phalcon\Assets\Collection::has to checks whether the resource is added to the collection or not
  • Added Phalcon\Cli\Dispatcher::getOption, Phalcon\Cli\Dispatcher::hasOption and the options as parameter to cli handlers
  • Added Phalcon\Config\Adapter\Grouped to allow usage of multiple configuration files/adapters in a simple format #12884
  • Added DISTINCT type for Phalcon\Text::random
  • Added autopadding feature for Phalcon\Crypt::encryptBase64 and Phalcon\Crypt::decryptBase64 #12490
  • Fixed Dispatcher forwarding when handling exception #11819, #12154
  • Fixed params view scope for PHP 7 #12648
  • Fixed Phalcon\Mvc\Micro::handle to prevent attemps to send response twice #12668
  • Fixed Di::set, Di::setShared to allow pass more than 10 arguments #12299
  • Fixed Phalcon\Mvc\Model\MetaData\Strategy\Annotations::getColumnMaps where only renamed columns where returned if there was one
  • Fixed Phalcon\Mvc\Micro:handle to correctly handle before handlers #10931
  • Fixed Phalcon\Mvc\Micro:handle to correctly handle afterBinding handlers
  • Fixed Phalcon\Mvc\Model::hasChanged to correctly use it with arrays #12669
  • Fixed Phalcon\Mvc\Model\Resultset::delete to return result depending on success #11133
  • Fixed Phalcon\Session\Adapter::destroy to correctly clear the $_SESSION superglobal #12326, #12835
  • Fixed Phalcon\Assets\Collection:add to avoid duplication of resources #10938, #2008
  • Fixed Phalcon\Mvc\View\Engine\Volt::compile to not throw exception in case of absence the file and stat option is true #12849
  • Fixed Phalcon\Mvc\Collection::getReservedAttributes to workaround for PHP 7/7.1 bug with static null when extending class phalcon/incubator#762, phalcon/incubator#760
  • Fixed Phalcon\Cache\Backend\Redis::__construct and Phalcon\Cache\Backend\Redis::_connect to correctly handle the Redis auth option #12736
  • Fixed Phalcon\Mvc\Collection::getReservedAttributes, added missing properties to reserved attributes phalcon/incubator#762, phalcon/incubator#760
  • Fixed Phalcon\Mvc\Router\Annotation::processActionAnnotation to support PATCH request

Update/Upgrade

Phalcon 3.2.0 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

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

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Windows DLLs are now available in our Github Release page.
PackageCloud will be updated shortly.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

Expanding on Phalcon 3.2.0 new features

$
0
0

With Phalcon 3.2.0 there were many new features and bugs fixed. Today we will write about most important things you need to know and show some code examples of new features.

Added Factory Adapter loaders #11001

With this feature you can load your services in more simplified way using for example ini file:

[database]
host = TEST_DB_MYSQL_HOST
username = TEST_DB_MYSQL_USER
password = TEST_DB_MYSQL_PASSWD
dbname = TEST_DB_MYSQL_NAME
port = TEST_DB_MYSQL_PORT
charset = TEST_DB_MYSQL_CHARSET
adapter = mysql
<?php

use Phalcon\Config\Adapter\Ini;
use Phalcon\Di;
use Phalcon\Db\Adapter\Pdo\Factory;

$di = new Di();
$config = new Ini('config.ini');

$di->set('config', $config);

$di->set(
    'db',
    function () {
        return Factory::load($this->config->database);
    }
);

This will properly create your database instance and you can change database adapter to another one if necessary in the ini file anytime without changing your code.

Added ability to sanitize URL to Phalcon\Filter

There were added new sanitize filter - url which allows you to clear your urls. For example:

<?php

use Phalcon\Filter;

$filter     = new Filter();
$wrongUrl   = 'http://juhara��.co�m';
$correctUrl = $filter->sanitize($wrongUrl, 'url');

echo $correctUrl; // displays 'http://juhara.com'

Added Phalcon\Mvc\Model::hasUpdated and Phalcon\Mvc\Model:getUpdatedFields, way to check if fields were updated after create/save/update, Added option to disable snapshot update on create/save using Phalcon\Mvc\Model::setup(['updateSnapshotOnSave' => false]) or phalcon.orm.update_snapshot_on_save = 0 in php.ini

In Phalcon 3.1.0 we changed the behavior of snapshots; they are now updated on model creation/update. This could potentially cause problems to your application if you execute Model::getChangedFields in afterUpdate(), afterSave() or afterCreate(). This change was done to fix other things also (for example dynamic update).

Right now you have two options:

  • change your methods from hasChanged(), getChangedFields(), getSnapshotData() to hasUpdated(), getUpdatedFields(), getOldSnapshotData() or
  • add phalcon.orm.update_snapshot_on_save = 0 to your php.ini to disable snapshot updating on save.
<?php

use Phalcon\Mvc\Model;

class User extends Model
{
  public function initialize()
  {
      $this->keepSnapshots(true);
  }
}

$user       = new User();
$user->name = 'Test User';
$user->create();
var_dump($user->getChangedFields());
$user->login = 'testuser';
var_dump($user->getChangedFields());
$user->update();
var_dump($user->getChangedFields());

On Phalcon 3.0.0 output was:

array(1) {
[0]=>
string(4) "name"
}
array(2) {
[0]=>
string(4) "name"
[1]=>
string(5) "login"
}
array(2) {
[0]=>
string(4) "name"
[1]=>
string(5) "login"
}

On Phalcon 3.1.0 and later it is:

array(0) {
}
array(1) {
[0]=>
string(5) "login"
}
array(0) {
}

Model::getUpdatedFields will properly return updated fields or as mentioned above you can go back to the previous behavior by setting the relevant ini value.

Added support for having option in Phalcon\Paginator\Adapter\QueryBuilder #12111

From now on you can use Phalcon\Mvc\Model\Query\Builder::having and Phalcon\Paginator\Adapter\QueryBuilder.

Let's assume you have such a table stock:

DROP TABLE IF EXISTS `stock`;
CREATE TABLE `stock` (
`id`    INT(11)     NOT NULL,
`name`  VARCHAR(32) NOT NULL,
`stock` INT(11)     NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

LOCK TABLES `stock` WRITE;
INSERT INTO `stock` (`id`, `name`, `stock`) VALUES
(1, 'Apple', 2),
(2, 'Carrot', 6)
(3, 'pear', 0);
UNLOCK TABLES;

ALTER TABLE `stock`
ADD PRIMARY KEY (`id`);

ALTER TABLE `stock`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

And this code:

<?php

use Phalcon\Di\FactoryDefault;
use Phalcon\Paginator\Adapter\QueryBuilder;

class Stock extends Phalcon\Mvc\Model {};

$di            = new FactoryDefault();
$modelsManager = $di->get('modelsManager');
$builder       = $modelsManager
                    ->createBuilder()
                    ->columns('*, COUNT(*) as stock_count')
                    ->from(['Stock' => Stock::class])
                    ->groupBy('name')
                    ->having('SUM(Stock.stock) > 0');

$paginate = (
    new QueryBuilder(
        [
            'builder' => $builder,
            'limit'   => 1,
            'page'    => 2
        ]
    )
)->getPaginate();
var_dump($paginate->total_pages); // now it will return 2, previously it was 3
var_dump($paginate->total_items); // now it will return 2, previously it was 3

Please note:

  • MySQL(and other databases) will need to select all rows and do a count on it.
  • We use groupBy to select columns for those rows.
  • If you don't have groupBy then you need to pass columns option to Phalcon\Paginator\Adapter\QueryBuilder:
<?php

use Phalcon\Di\FactoryDefault;
use Phalcon\Paginator\Adapter\QueryBuilder;

class Stock extends Phalcon\Mvc\Model {};

$di            = new FactoryDefault();
$modelsManager = $di->get('modelsManager');
$builder       = $modelsManager
                    ->createBuilder()
                    ->columns('*, COUNT(*) as stock_count')
                    ->from(['Stock' => Stock::class])
                    ->having('SUM(Stock.stock) > 0');

$paginate = (
    new QueryBuilder(
        [
            'builder' => $builder,
            'limit'   => 1,
            'page'    => 2,
            'columns' => 'id,stock' // this is required in this case
        ]
    )
)->getPaginate();
var_dump($paginate->total_pages); // now it will return 2, previously it was 3
var_dump($paginate->total_items); // now it will return 2, previously it was 3

Added Phalcon\Config::path to get a value using a dot separated path #12221

<?php

use Phalcon\Config;

$config = new Config(
    [
        'test' => [
            'parent' => [
                'property'  => 1,
                'property2' => 'yeah',
            ],
        ],
    ]
);

echo $config->path('test.parent.property'); // displays 1

Added service provider interface to configure services by context #12783

From now you can move all your $di->set() to classes like this:

<?php

use Phalcon\Di\ServiceProviderInterface;
use Phalcon\DiInterface;
use Phalcon\Di;
use Phalcon\Config\Adapter\Ini;

class SomeServiceProvider implements ServiceProviderInterface
{
    public function register(DiInterface $di)
    {
        $di->set(
            'config',
            function () {
                return new Ini('config.ini');
            }
        );
    }
}

$di = new Di();
$di->register(new SomeServiceProvider());
var_dump($di->get('config')); // will return properly our config

Added the ability to load services from yaml (Phalcon\Di::loadFromYaml) and php array (Phalcon\Di::loadFromPhp) files, so we can keep the references cleanly separated from code #12784

This feature will let you set your services in yaml files or just in plain php. For example you can load yaml file like this:

config:
  className: \Phalcon\Config
  shared: true
<?php

use Phalcon\Di;

$di = new Di();
$di->loadFromYaml('services.yml');
$di->get('config'); // will properly return config service

Added Phalcon\Cache\Backend\Apcu to introduce pure support of APCu #12098, #11934, Added Phalcon\Annotations\Adapter\Apcu to introduce pure support of APCu #12098

In PHP 7 to use phalcon apc based adapter classes you needed to install apcu and apcu_bc package from pecl. Now in Phalcon 3.2.0 you can switch your *\Apc classes to *\Apcu and remove apcu_bc. Keep in mind that in Phalcon 4 we will most likely remove all *\Apc classes.

Added Phalcon\Mvc\Model\Manager::setModelPrefix and Phalcon\Mvc\Model\Manager::getModelPrefix to introduce tables prefixes #10328

If you want all your tables to have certain prefix and without setting source in all models you can use Phalcon\Mvc\Model\Manager::setModelPrefix:

<?php

use Phalcon\Mvc\Model\Manager;
use Phalcon\Mvc\Model;

class Robots extends Model
{

}

$manager = new Manager();
$manager->setModelPrefix('wp_');
$robots = new Robots(null, null, $manager);
echo $robots->getSource(); // will return wp_robots

Added way to disable setters in Phalcon\Mvc\Model::assign by using Phalcon\Mvc\Model::setup or ini option

Phalcon\Mvc\Model::assign(which is used also when creating/updating/saving model) is always using setters if they exist when have data argument passed, even when it's not needed or not necessary. It can add not needed overhead to your application. From now you can change this behavior by adding phalcon.orm.disable_assign_setters = 1 to your ini file, it will just simply use this->property = value from now on. From Phalcon 4 we will set it to be default behavior.

Added dispatcher::beforeForward event to allow forwarding request to the separated module #121, #12417

With new event you can change module where to forward in easy and clean way:

<?php

use Phalcon\Di;
use Phalcon\Events\Manager;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Events\Event;

$di = new Di();

$modules = [
  'backend' => [
      'className' => 'App\Backend\Bootstrap',
      'path'      => '/app/Modules/Backend/Bootstrap.php',
      'metadata'  => [
          'controllersNamespace' => 'App\Backend\Controllers',
      ],
  ],
];

$manager = new Manager();

$manager->attach(
  'dispatch:beforeForward',
  function (Event $event, Dispatcher $dispatcher, array $forward) use ($modules) {
      $metadata = $modules[$forward['module']]['metadata'];
      $dispatcher->setModuleName($forward['module']);
      $dispatcher->setNamespaceName($metadata['controllersNamespace']);
  }
);

$dispatcher = new Dispatcher();
$dispatcher->setDI($di);
$dispatcher->setEventsManager($manager);
$di->set('dispatcher', $dispatcher);
$dispatcher->forward(
  [
      'module'     => 'backend',
      'controller' => 'posts',
      'action'     => 'index',
  ]
);

echo $dispatcher->getModuleName(); // will display properly 'backend'
Credit to Wojciech Ślawski for the article

Translating documentation and our website

$
0
0
TLDR; We released new docs, messed up, fixed it, enhancing it now, new translation platform.

Hello everyone!

Last week we have released a new Phalcon version 3.2 as well as our new documentation.

Well, that did not go as planned, since we ended up with a lot of angry developers, because the old documentation was not available (at least temporarily) and also we had a lot of broken links in search engines.

We tried to rectify the issue as fast as possible so we have several redirects that point old links to where they are supposed to. We have also created https://olddocs.phalconphp.com/ which contains all the old documents. That site will remain active for quite a long time, so you don't need to worry if you are behind in upgrating to a later version of Phalcon. :)

Changes

The biggest chance that we have been working on the last few months, was to change all of our documents to the markdown format from reStructured Text. Although this was not a huge task, it was time consuming. We also addressed the issue of broken links, image files left over from old documents etc.

Once that process was completed, we tied up the documentation to Crowdin in order to allow contributors translate our documentation in different languages. As with any new technology, we had some setup issues that were only identified after we released 3.2.

Note that there are indeed some CSS issues with the documentation that we expect to have them resolved by next week.

Docs

The docs repository had to be split into two. One (docs-app) would contain the Phalcon application that handles the documentation, contains the stylesheets etc. while the second one (docs) the one that contains all the markdown documents with the contents of our documentation.

The Crowdin team was simply amazing during this process. Not only have they fixed stuff we broke in our integration, but they also guided us on how to create an easy to maintain workflow so that we can easily release our new documentation, translated, whenever we release a new version.

You can find our docs-app repository here and the docs repository here.

For each release we will have a branch in the docs repository that will contain the documentation for that specific release with the added functionality.

The beauty of using Crowdin is that it identifies identical strings of text throughout branches. As a result if contributors say have translated all of the documents in Spanish for 3.2, when we release 3.3 only the changed text will appear as not translated.

We have to thank once again Crowdin for their tremendous help with our implementation and for hosting our translations/documents in their platform. We highly recommend their service:

Crowdin Logo

Phalcon Documentation: https://crowdin.com/project/phalcon-documentation

Website

We have also ported all of the translations from Transifex to Crowdin so that we can use only one platform for our translations. The Crowdin project is located here. We made an announcement in Transifex for all translators there, and hopefully we will see everyone migrate to the new platform.

As always any suggestions for new languages or even corrections in our text are more than welcome!

Thank you!

Thank you all for your contributions! You guys rock!

<3 Phalcon Team

References:


Phalcon 3.2.1 released

$
0
0

Hello community!!

We are releasing Phalcon 3.2.1 today, addressing several bugs.

Release

The release tag can be found here: 3.2.1. The Windows DLLs are in the releases Github page.

Changelog

  • Added Phalcon\Db\Dialect\Mysql::getForeignKeyChecks to generate a SQL to check the foreign key settings #2604, phalcon/phalcon-devtools#556
  • Fixed inconsistent behaviour of Phalcon\Config::merge across minor version of PHP7 #12779
  • Fixed visibility of Phalcon\Mvc\Model\Query\Builder methods: _conditionNotIn, _conditionIn, _conditionNotBetween and _conditionBetween to allow 3rd party libraries extend it
  • Fixed Phalcon\Assets\Manager::output, implemented missing resource type filtering for mixed resource collections #2408
  • Fixed Phalcon\Http\Response::getStatusCode to return (int) HTTP code only, instead of full string #12895
  • Fixed Phalcon\Db\Dialect\Postgresql::addForeignKey for proper creating the foreign key without a name
  • Fixed Phalcon\Cache\Backend\Apcu::flush to use APCu instead APC #12934
  • Fixed Phalcon\Db\Adapter\Pdo\Mysql::addForeignKey for proper creating the foreign key with a desired key name #2604, phalcon/phalcon-devtools#556
  • Fixed Phalcon\Db\Dialect\Mysql::addForeignKey to generate correct SQL #2604, phalcon/phalcon-devtools#556

Update/Upgrade

Phalcon 3.2.1 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

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

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Windows DLLs are now available in our Github Release page.
NOTE: PackageCloud (linux distributions) will be updated within an hour of this blog post.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

Helping with Documentation

$
0
0

Hello everyone!!

Often we get queries/requests on how someone can help with the documentation, and how they can set up the docs application on their local machine so as to see changes immediately on their screen before issuing a pull request with their changes.

This blog post outlines how to set up our docs app and how you can help with the documentation effort.

Overview

Our documentation is split into two repositories:

  • Docs App. This repo contains the application that handles our documentation (templates, CSS, etc.).
  • Docs. This repo contains the actual articles that are shown on screen (content).

These repositories have been set up to work together to offer an easy way to set up and maintain the documentation.

The docs repository has also been integrated with Crowdin, which handles all the translation efforts of our documentation.

Setup

So you want to set up the docs application to have the documents application running on your local machine. Great! The steps are:

  • Fork the docs-app repository
  • Fork the docs repository
  • Clone the docs-app to your machine.
  • Install nanobox if you don't have it
  • Setup the .env file
  • Setup the app using nanobox
  • Run the deploy script
  • Run the app with nanobox
  • Launch the app on your browser :)

Fork the repositories

If you haven't done so already, fork the repositories from the phalcon github organization page https://github.com/phalcon. You will need the docs-app and docs repositories.

Clone the docs-app repository

In a suitable location on your machine clone the docs-app repository (the fork)

$ git clone git@github.com:niden/docs-app
NOTE Your repository URL will be different than the above command

Install nanobox

If you haven't done so already, visit nanobox.io and download and install the application. It will ask you some basic questions (usually we use Docker as the engine instead of Virtualbox) as part of its setup. If you don't meet the following requirements you should use VirtualBox.

Docker Requirements

Setup the .env file

In the docs-app folder (or wherever you have cloned the docs-app repository), make a copy of the .env.example file and rename it to .env. Open the file and edit:

  • APP_URL entry with a local domain. In this example we use docs.phalcon.ld.
  • DOCS_REPO entry to your fork of the docs repo. For example it will be something like this:
git@github.com:niden/docs

Setup the app using nanobox

In your folder (where you cloned docs-app) run the following command in a terminal:

$ nanobox run

After a while you will see something like this:

$ nanobox run
Preparing environment :

docs-app (local) :
...

Preparing environment :
...

Building dev environment :
  ✓ Starting docker container
  ✓ Configuring

      **
   *********
***************   Your command will run in an isolated Linux container
:: ********* ::   Code changes in either the container or desktop are mirrored
" ::: *** ::: "   ------------------------------------------------------------
  ""  :::  ""     If you run a server, access it at >> 172.18.0.4
    "" " ""
       "

Once nanobox finishes its tasks, you will be "inside" the container. Your prompt will be:

/app $

Run the deploy script

In the same terminal, (root folder of docs-app) run the deploy script

$ ./deploy

This script will start cloning the docs repository branches needed under the ./docs folder of your docs-app application (mind boggling - too many docs! :D). The output on the terminal will provide information about the process.

Type exit to exit the container.

Run the following command to create a hosts entry for your environment so that you can use the local domain:

$ nanobox dns add local docs.phalcon.ld

This command will be different in your system, depending on the name you chose for your local domain.

Run the app with nanobox

Run the following command:

$ nanobox run php-server

Launch the app in your browser

Open the http://docs.phalcon.ld URL in your browser and voila!!!

Modifications

If you wish to make changes to the application (docs-app), stylesheets or layout, feel free to do so and issue a pull request in the docs-app Phalcon repository.

You can also help with some of the English text located in the en folder under each version folder (docs/3.2/en, docs/3.1/en, etc.). These changes will be sent to the docs Phalcon repository.

Changes to a docs file (markdown) in any language other than English will not be accepted

Translations

For languages other than English, you will need to use Crowdin Project for the documentation:

https://crowdin.com/project/phalcon-documentation

The translated strings will be brought into the documentation via pull requests from Crowdin.

Enjoy!!

<3 Phalcon Team

Phalcon 3.2.2 released

$
0
0

Hello everyone!!!

We are releasing Phalcon 3.2.2 today, addressing several bugs.

Release

The release tag can be found here: 3.2.2. The Windows DLLs are in the releases Github page.

Changelog

  • Fixed Phalcon\Db\Adapter\Pdo\Postgresql::describeColumns to work properly with DOUBLE PRECISION and REAL data types #12842
  • Fixed Phalcon\Paginator\Adapter\QueryBuilder::getPaginate to use the db connection service of the model #12957
  • Fixed Phalcon\Paginator\Adapter\QueryBuilder::getPaginate to escape reserved words #12950
  • Fixed Phalcon\Dispatcher::dispatch to correct forward with the modified action suffix #12988
  • Fixed Phalcon\Forms\Element::_construct to prevent create form element with empty name #12954

Update/Upgrade

Phalcon 3.2.2 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

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

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Windows DLLs are now available in our Github Release page.
NOTE: PackageCloud (linux distributions) will be updated tomorrow 2017-08-14.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

Phalcon 3.2.3 released

$
0
0

Hello everyone!!!

We are releasing Phalcon 3.2.3 today, addressing several bugs.

Release

The release tag can be found here: 3.2.3. The Windows DLLs are in the releases Github page.

Changelog

  • Fixed Phalcon\Mvc\Model\Query::_executeSelect threw RuntimeException, if db:beforeQuery() returned false
  • Internal cookies property is now always an array #12978
  • Fixed Phalcon\Validation\Validator\File::validate to work properly with parameter message #12947
  • Fixed Phalcon\Mvc\View::render to render a view with params #13046
  • Fixed Phalcon\Mvc\Model\Manager::getRelationRecords to work properly with provided columns #12972
  • Mark as deprecated no longer used Phalcon\Mvc\Model\Query\Builder::$_with parameter #13023
  • Fixed Phalcon\Dispatcher::dispatch to ensure proper flow for all forward/exception/dispatch event hooks #12931

Update/Upgrade

Phalcon 3.2.3 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

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

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Our packaging system not longer supports Ubuntu 15.10 due to difficulties installing dependencies, updates and major security patches. Ubuntu 15.10 reached its end of life in July 28, 2016. We strongly suggest you upgrade your installation. If you cannot, you can always build the latest stable version of Phalcon from the source code.
NOTE: Windows DLLs are now available in our Github Release page.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

Phalcon 3.3.0 released and Merry Christmas

$
0
0

image

The Phalcon Team wishes all of our friends, contributors, developers and users of the framework a Merry Christmas!. We hope that the new year will bring health and happiness to you and your loved ones!

As a small gift for this holiday/celebration, we are releasing Phalcon 3.3.0.

This release concentrated on support for PHP 7.2, new features and fixing some bugs,

A huge thank you to all of our contributors and the community!!

The release tag can be found here: 3.3.0

Changelog

  • Added support of PHP 7.2 and initial support of PHP 7.3
  • Added support for switch/case syntax to the Volt Engine #13107
  • Added Phalcon\Logger\Adapter\Blackhole #13074
  • Added Phalcon\Http\Request::hasHeader to check if certain header exists
  • Added support of 103 (Early Hint) HTTP status code
  • Added router:beforeMount event to Router::mount #13158
  • Added Phalcon\Mvc\Application::sendHeadersOnHandleRequest to enable or disable sending headers by each request handling #13101
  • Added Phalcon\Mvc\Application::sendCookiesOnHandleRequest to enable or disable sending cookies by each request handling #13101
  • Added ability to use PDO option aliases on database connect #13010
  • Added Phalcon\Mvc\Model\MetaData\Apcu #13078
  • Added ability to use string(file path) as a argument in Phalcon\Config\Factory::load()
  • Added Phalcon\Mvc\Mico\Collection::mapVia to map routes via methods
  • Added Phalcon\Mvc\Model::setOldSnapshotData to set old snapshot data separately to current snapshot data
  • Added Phalcon\Http\Response::removeHeader to remove specific header from response
  • Added Phalcon\Mvc\Query::setTransaction to enable an override transaction #13226
  • Fixed Phalcon\Mvc\Model\Query\Builder::getPhql to correct generate PHQL in argument's array when using order DESC or ASC #11827
  • Fixed Phalcon\Db\Dialect\Postgresql::createTable to produce valid SQL for table definition with BOOLEAN types #13132
  • Fixed Phalcon\Db\Dialect\Postgresql::_castDefault to return correct value for BOOLEAN type #13132, phalcon/phalcon-devtools#1118
  • Fixed Phalcon\Mvc\Model::_doLowInsert to correct save snapshot on creation/save identityless models #13166
  • Fixed Phalcon\Mvc\Model::_doLowUpdate to correctly work with Phalcon\Db\RawValue #13170
  • Fixed Phalcon\Mvc\Model::allowEmptyStringValues to correct works with saving empty string values when DEFAULT not set in SQL
  • Fixed Phalcon\Mvc\Model\Behavior\SoftDelete to correctly update snapshots after deleting item
  • Fixed Phalcon\Mvc\Model to set old snapshot when no fields are changed when dynamic update is enabled
  • Fixed Phalcon\Acl\Adapter\Memory::isAllowed to properly pass role and resource objects to custom function if they are objects of the same class
  • Changed Phalcon\Mvc\Model to allow to pass a transaction within the query context #13226

Highlights

The most notable additions are support for switch/case syntax in Volt, hasHeader in Request and the addition of the router:beforeMount event.

switch/case

You can now use the switch statement in Volt

{% switch foo %}
    {% case 0 %}
    {% case 1 %}
    {% case 2 %}
        "foo" is less than 3 but not negative
        {% break %}
    {% case 3 %}
        "foo" is 3
        {% break %}
    {% default %}
        "foo" is {{ foo }}
{% endswitch %}

The switch statement executes statement by statement, therefore the break statement is necessary in some cases. Any output (including whitespace) between a switch statement and the first case will result in a syntax error. Empty lines and whitespaces can therefore be cleared to reduce the number of errors see here.

case without switch

{% case EXPRESSION %}

Will throw Fatal error: Uncaught Phalcon\Mvc\View\Exception: Unexpected CASE.

switch without endswitch

{% switch EXPRESSION %}
Will throw `Fatal error: Uncaught Phalcon\Mvc\View\Exception: Syntax error, unexpected EOF in ..., there is a 'switch' block without 'endswitch'`.

default without switch

{% default %}

Will not throw an error because default is a reserved word for filters like {{ EXPRESSION | default(VALUE) }} but in this case the expression will only output an empty char '' .

nested switch

{% switch EXPRESSION %}
  {% switch EXPRESSION %}
  {% endswitch %}
{% endswitch %}

Will throw Fatal error: Uncaught Phalcon\Mvc\View\Exception: A nested switch detected. There is no nested switch-case statements support in ... on line ....

a switch without an expression

{% switch %}
  {% case EXPRESSION %}
      {% break %}
{% endswitch %}

Will throw Fatal error: Uncaught Phalcon\Mvc\View\Exception: Syntax error, unexpected token %} in ... on line ....

hasHeader in Phalcon\Http\Request

You can now use the hasHeader method, to check if a header has been set in the incoming request.

if ($request->hasHeader('myheader')) {
    echo 'Yay! Header was set!!';
}

router:beforeMount

Sometimes it is necessary to attach some logic to our application, before the routes are mounted in our Router object. The beforeMount event is perfect in these cases. You can now use it if your application requirements dictate so.

Update/Upgrade

Phalcon 3.3.0 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

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

PackageCloud.io has been updated to allow your package manager (for Linux machines) to upgrade to the new version seamlessly.

NOTE: Our packaging system not longer supports Ubuntu 15.10 due to difficulties installing dependencies, updates and major security patches. Ubuntu 15.10 reached its end of life in July 28, 2016. We strongly recommend you upgrade your installation. If you cannot, you can always build the latest stable version of Phalcon from the source code.
NOTE: Windows DLLs are now available in our Github Release page.

We encourage existing Phalcon 3 users to update to this version.

<3 Phalcon Team

Viewing all 109 articles
Browse latest View live