The Release Of Phalcon 1.2.0



We are pleased announce the release of the new version Phalcon.

A little more than two months since the release of previous version, and the development team represents one of the largest and most serious releases fastest framework for PHP written as a C extension.
The new version contains many new features, bug fixes and optimizations. We also updated the website and prepare for major updates to the documentation and API descriptions.

Innovations Phalcon 1.2.0:
    the
  1. Dynamic paths for the compiled Volt templates
  2. the
  3. empower Volt
  4. the
  5. Links to static and dynamic routes in Phalcon\Mvc\Url
  6. the
  7. Phalcon\Mvc\View\Simple
  8. the
  9. Improved JSON
  10. the
  11. Support for Many-To-Many ORM
  12. the
  13. virtual foreign keys
  14. the
  15. Minification of Javascript and CSS
  16. the
  17. the Ban variables (literals) in PHQL
  18. the
  19. Expanded Partials
  20. the
  21. Use Phalcon\Tag as a service
  22. the
  23. Macros in Volt
  24. the
  25. BadMethodCallException instead of warnings
  26. the
  27. Component debug

Download
the New motto
Gratitude


so, what was implemented in Phalcon 1.2.0



1. Dynamic path for the compiled Volt templates

Option "compiledPath" in the parameters of the templating engine Volt now accepts an anonymous function to perform the necessary actions before writing the cache file of the template.
the
// Add the extension .php to template files
$volt- > setOptions([
'compiledPath' = > function($templatePath) { 
return $templatePath . '.php';
}
]);

// Create required subdirectories for files
$volt- > setOptions([
'compiledPath' = > function($templatePath) {
$dirName = dirname($templatePath);
if (!is_dir(CACHE_DIR . $dirName)) {
mkdir(CACHE_DIR . $dirName,0755,true);
}
return CACHE_DIR . $dirName . '/'. $templatePath . '.php';
}
]);


2. Empowerment Volt

For our template engine you can now add any required functionality, change behavior, and operators to add functions and filters. The class below allows to use any template php function:
the
class PhpFunctionExtension
{
public function compileFunction($name, $arguments)
{
if (function_exists($name)) {
return $name . '('. $arguments . ')';
} 
}
}

Add this extension:
the
$volt- > getCompiler()->addExtension(new PHPFunctionExtension());


3. Links for static and dynamic routes in Phalcon\Mvc\Url

You can now specify different paths for links to static files: images, or, for example, js files and page links. This capability will be especially relevant when using a CDN.
the
$di['url'] = function() {
$url = new Phalcon\Mvc\Url();

// Dynamic URIs without mod-rewrite
$url- > setBaseUri('/index.php?_url=');

// Static URI for CSS/Javascript/Images
$url->setStaticUri('/static/');

return $url;
};


4. Phalcon\Mvc\View\Simple

A component is a lighter alternative Phalcon\Mvc\View, without the support of the template hierarchy. It will be important for the use in micro applications and receive submissions as a string.
the
// View service
$di['view'] = function() {

$view = new Phalcon\Mvc\View\Simple();
$view->setViewsDir(APP_PATH . '/views/');
return $view;
};

The use of micro-apps:
the
$app->map('/login', function() use ($app) {

echo $app->view->render('security/login', array(
'form' => new LoginForm(), 
));

});

The component supports different template engines and template caching.
5. Improved JSON

To receive and send data in JSON format has become much easier. Passing data in Phalcon\Http\Response, they will automatically be sent in JSON format:
the
$app->post('/api/robots', function() use ($app) {

$data = $app->request->getJsonRawBody();

$robot = new Robots();
$robot- > name = $data->name;
$robot- > type = $data->type; 

$response = new Phalcon\Http\Response();

// check save
if ($robot- > success() == true) {

$response->setJsonContent([
'status' => 'OK' 
'id' => $robot- > id
]);

} else {

// setting the HTTP status
$response- > setStatusCode(500, "Internal Error");

$response->setJsonContent([
'status' => 'ERROR', 
'messages' => $status->getMessages()
]);

}

return $response;
});


6. Support Many-To-Many ORM

Our ORM started to support a many-to-many. This allows you to establish direct relationships between two models using the third model, intermediate:
the
class Artists extends Phalcon\Mvc\Model
{
public $id;

public $name;

public function initialize()
{
$this- > hasManyToMany(
'id', 
'ArtistsSongs', 
'artists_id', 'songs_id', 
'Songs', 
'id'
);
}
}

Songs artists can be accessed through the alias relations
the
$artist = Artists::findFirst();

// get all songs of an artist
foreach ($artist- > songs as $song) {
echo $song- > name;
}

Relationship many-to-many can be worked in PHQL ( this is an add-on to SQL to simplify the use of models and the construction of a sql query ):
the
$phql = 'SELECT Artists.name, Songs.name FROM Artists JOIN Songs WHERE Artists.genre = "Trip-Hop"';
$result = $this- > modelsManager- > query($phql);

Related data can be added immediately when you create the model, all the necessary intermediate glue records will be created automatically:
the
$songs = array()

$song = new Song();
$song- > name = 'Get Lucky';
$songs[] = $song;

$song = new Song();
$song- > name = 'Instant Crush';
$songs[] = $song;

$artist = new Artists();
$artist- > name = 'Daft Punk';
$artist- > songs = $songs; // assign related items
$artist- > save();


7. Using virtual foreign keys

When you specify Virtual foreign keys all associated with the main entry dependent items will be removed:
the
php use Phalcon\Mvc\Model
Phalcon\Mvc\Model\Relation;

class Artists extends Model
{

public $id;

public $name;

public function initialize()
{
$this->hasMany('id', 'Songs', 'artists_id', [
'foreignKey' => [
'action' = > Relation::ACTION_CASCADE 
]
]);
}

}

If you delete the contractor removed all his songs:
the
$artist = Artists::findFirst();

$artist- > delete(); // will be removed with all the songs


8. Minification of Javascript and CSS

We taught component Phalcon\Assets is not only flexibly manage static resources, group and filter them, but also to compress JS/CSS (beneficiality). For such responsible work, we have used ready-made solutions from Douglas Crockford Jsmin and CSSMin by Ryan Day.
the
$manager = new Phalcon\Assets\Manager(array(
'sourceBasePath' => './js/',
'targetBasePath' => './js/production/'
));

$manager

// collect the Javascripts at the bottom of the page 
->collection('jsFooter')

// name of the result file
- >setTargetPath('final.js')

// address of
->setTargetUri('production/final.js')

// can use external files, even without filtration
->addJs('code.jquery.com/jquery-1.10.0.min.js', true, false)

// local files have to pass through the filter
->addJs('common-functions.js')
->addJs('page-functions.js')

// all files should be collected in one ( final.js )
->join(true)

// use the built-in Jsmin filter
->addFilter(new Phalcon\Assets\Filters\Jsmin())

// another filter, for in-house applications
->addFilter(new MyApp\Assets\Filters\LicenseStamper());

$manager->outputJs();


9. The ban variables (literals) in PHQL

Inside PHQL now you can't use the parameters directly, the following code will throw exceptions:
the
$artist = Artists::findFirst("name = '$name'");


10. Expanded Partials

The developer can now pass to the partials array of parameters:
the
<?php $this->partial('footer', ['links' => $myLinks]);

Volt supports this possibility:
the
 php{{ partial('footer', ['links': myLinks]) }}
{% include 'footer' with ['links': myLinks] %}


11. Use Phalcon\Tag as a service

We are carefully moving away from the use of any static methods, they still work, but their use is not desirable. The component Phalcon\Tag is now available as a service in the DI\FactoryDefault. Instead of:

You should use:
the
$this->tag->setDefault('name', $robot- > name);


12. Macros in Volt

Working with macros only just begun, then there will be more:
the
{%- macro input_text(name, attributes=null) -%}
{{- '<input type="' ~ name ~ '" ' -}}
{%- for key, value in attributes -%}
{{key ~ '="' ~ value|e '"' -}}
{%- endfor -%}
{{- '/>' -}}
{%- endmacro -%}

{{ input_text("telephone", ['placeholder': 'telephone Type']) }}


13. BadMethodCallException instead of warnings

To version 1.1.0 when transferring methods in an incorrect number of parameters were booked. Starting with version 1.2.0, in such situations an exception will be thrown BadMethodCallException with the ability to trace exactly where the error occurred:
the
<?php

$e = new Phalcon\Escaper();
$e->escapeCss('a {}', 1, 2, 3);

Appears:
the
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters' in test.php:4
Stack trace:
#0 test.php(4): Phalcon\Escaper- > escapeCss('a {}', 1, 2, 3)
#1 {main}


14. Component debugging

The component Phalcon\Debug generates debug stack, allowing the developer to trace in what place something went wrong. Data is presented in a structured way. To operate the component you want to remove try/catch blocks in the initialization file and specify its beginning:
the
(new Phalcon\Debug)- > listen();

We have prepared a short screencast demonstration of the operation of the component:


There are a few important innovations:
the
    the
  • Nested transactions in Phalcon\Db supports multiple connections
  • the
  • support for the adapter cache XCache/Igbinary for Cache/Annotations/ORM-MetaData
  • the
  • Support for PHP 5.5
  • the
  • Profiled Guided Optimizations

Full list of changes is available at CHANGELOG.

Download


To collect the new version on GitHub or download DLL library for Windows. Available also build to some linux.Documentation as updated.

the New motto


For a long time we worked under the motto "The fastest PHP Framework", it is completely matching and supporting the speed of Phalcon at the maximum. We have optimized all you can and looking for every opportunity to conserve memory and reduce overhead. But speed is not our only priority. From version to version, we tried to make Phalcon even more convenient and to include the most useful features. This allowed the project to grow into one of the fastest and most functional products in the world of open source.
Moving forward, we decided to change our motto for more accurate positioning Phalcon. With version 1.2.0 we work under the slogan "The best balance of speed and functionality". Our primary goal is the preservation of an optimal balance between the speed of the framework and functionality that it provides. We really want to not only be the fastest framework for PHP, but also the most optimal in terms of speed and functionality.

Acknowledgement


We want to thank all members of the community of developers, voting for new features and help with their implementation and verification. All who help with testing and improving the documentation.
Thanks to everyone who helps to develop Phalcon and involved in community life.
Thank you!
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Fresh hay from the cow, or 3000 icons submitted!

Knowledge base. Part 2. Freebase: make requests to the Google Knowledge Graph

Group edit the resources (documents) using MIGXDB