Phalcon 2.0.3 Release

    As part of our regular release schedule, 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 community feedback.

    Changes


    • Implemented aliases for namespace in PHQL
    • The ability to determine whether a virtual foreign key should ignore null values ​​or not
    • Added support for `Phalcon \ Mvc \ Collection` in behaviors (Behaviours)
    • Added `SoftDelete` and` Timestampable` behaviors in collections
    • Fixed bug adding double `?` To `Mvc \ Url :: get` when using parameters # 10421
    • String attributes in models now have optional support for empty string values # 440
    • Added ability to return SQL generated in instances of `Mvc \ Model \ Query` # 1908
    • Correction of incorrectly generated request in `Phalcon \ Db \ Dialect :: select ()` # 10439
    • Double type support added in MySQL
    • `Phalcon \ Tag \ Select` now processes an array of string values, avoiding taking zero for an empty string # 2921
    • PHQL now supports CASE / WHEN / ELSE # 651 expressions
    • Fixed a bug that occurred when adding non-string values ​​to `Phalcon \ Crypt :: encrypt` from` Phalcon \ Http \ Cookies`
    • Fixed bug of not passing schema name (PostgreSQL)
    • The persistent attribute has been removed from the DNS attributes for PDO connections in order to avoid errors in PostgreSQL # 10484

    Highlights


    CASE / WHEN / ELSE Support

    Now the `CASE / WHEN / ELSE` expressions 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 often find yourself in a situation where you need to type a long namespace for a simple reference to the model. Now you can add aliases 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
    ");
    

    Custom Dialect Features

    This new functionality will help you extend PHQL with custom functions as you need. In the following example, we 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 into the correct SQL:

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

    Subquery Enhancements

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

    $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 / Installation


    This version can be installed from the master branch. If you do not have Zephir installed, 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.


    Acknowledgments


    Thanks to everyone who contributed to this release: Contributors and the community for their feedback!

    Also popular now: