📜 ⬆️ ⬇️

Phalcon 2.0.3 release

As part of our schedule of regular releases, we are pleased to announce that Phalcon 2.0.3 has been released!

This version contains many fixes, as well as new features based on the feedback of the community.

Changes



Highlights


CASE / WHEN / ELSE support

Now the expressions `CASE / WHEN / ELSE` are available in PHQL :
')
$robots = $this->modelsManager->executeQuery(" SELECT CASE r.Type WHEN 'Mechanical' THEN 1 WHEN 'Virtual' THEN 2 ELSE 3 END FROM Store\Robots "); 

Aliases for Namespace

If you use namespaces to organize your models, you are often in a situation where you need to type a long namespace for a simple reference to a model. Now you can add pseudonyms for existing namespaces, speeding up your development:

 //  $data = $this->modelsManager->executeQuery(" SELECT r.*, rp.* FROM Store\Backend\Models\Robots AS r JOIN Store\Backend\Models\RobotsParts AS rp "); 

Defining aliases in the model manager:

 use Phalcon\Mvc\Model\Manager as ModelsManager; // ... $di->set( 'modelsManager', function() { $modelsManager = new ModelsManager(); $modelsManager->registerNamespaceAlias( 'bm', 'Store\Backend\Models\Robots' ); return $modelsManager; } ); 

And in requests:

 //  $data = $this->modelsManager->executeQuery(" SELECT r.*, rp.* FROM bm:Robots AS r JOIN bm:RobotsParts AS rp "); 

User Dialect Functions

This new functionality will help you expand PHQL using custom functions as you need. In the following example, we will implement MATCH / BINARY support from MySQL. First of all, you must instantiate the SQL dialect:

 use Phalcon\Db\Dialect\MySQL as SqlDialect; use Phalcon\Db\Adapter\Pdo\MySQL as Connection; $dialect = new SqlDialect(); // Register a new function called MATCH_AGAINST $dialect->registerCustomFunction( 'MATCH_AGAINST', function($dialect, $expression) { $arguments = $expression['arguments']; return sprintf( " MATCH (%s) AGAINST (%)", $dialect->getSqlExpression($arguments[0]), $dialect->getSqlExpression($arguments[1]) ); } ); //        $connection = new Connection( [ "host" => "localhost", "username" => "root", "password" => "", "dbname" => "test", "dialectClass" => $dialect ] ); 

Now you can use this function in PHQL and it translates it to the correct SQL:

 $phql = "SELECT * FROM Posts WHERE MATCH_AGAINST(title, :pattern:)"; $posts = $modelsManager->executeQuery($phql, ['pattern' => $pattern]); 

Subquery enhancements

PHQL subqueries were introduced in Phalcon 2.0.2. Support for this feature was improved in 2.0.3 by introducing the EXISTS operator:

 $phql = "SELECT c.* FROM Shop\Cars c WHERE EXISTS ( SELECT id FROM Shop\Brands b WHERE b.id = c.brandId )"; $cars = $this->modelsManager->executeQuery($phql); 

Update / Install


This version can be installed from the master branch. If you have not installed Zephir, run the following commands:

 git clone http://github.com/phalcon/cphalcon git checkout master cd ext sudo ./install 

The standard installation method also works:

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

If you already have Zephir installed:

 git clone http://github.com/phalcon/cphalcon git checkout master zephir fullclean zephir build 

Please note that when you run the installation script will replace the already installed version of Phalcon.

Windows DLLs are available on the download page .

See the upgrade guide if you want to upgrade to Phalcon 2.0.x from 1.3.x.


Thanks


Thanks to everyone who contributed to the creation of this version: to both the distributors and the community for the feedback!

Source: https://habr.com/ru/post/260141/


All Articles