Nette 2.2: Revolution without Side-Effects

10 years ago by Jan Smitka  

About two months ago, one of the most revolutionary versions of the Nette Framework was released. This new version brings a huge change in the structure of the framework – the main repository has been split into several standalone components.

The main repository has been physically split into the following repositories: Application, Bootstrap, Caching, ComponentModel, Nette Database, DI, Finder, Forms, Http, Latte, Mail, Neon, PhpGenerator, Reflection, RobotLoader, SafeStream, Security, Tokenizer, Tracy and Utils. Each repository represents one component and has its own history, releases, issues, pull-requests, and, of course, composer.json.

Some of the components also contain the src/Bridges directory, which provides integration with other parts of the framework. You do not need to install the referenced parts of the framework, use of the integration bridges is optional. All required dependencies are specified in the composer.json file.

Although the code repository has been dramatically split into several stand-alone components, there is no need to worry – you can still download the distribution package or install the whole framework by requiring nette/nette in your composer.json.

Besides, you can use each of the components on its own, without installing the rest of the framework. The preferred way of getting the packages is through Composer. It will also solve dependencies between packages.

Nette 2.2 also brings several changes in API and new features.

Latte

The Latte was an integral part of the framework for a long time, and it was integrated with the rest of the framework (mainly with the Nette\Templating namespace). In the new release, the Latte API was completely rewritten with stand-alone usage in mind:

$latte = new Latte\Engine; // not the Nette\Latte\Engine
$latte->setTempDirectory('/path/to/cache');

$latte->addFilter('money', function($val) { return ...; });
// addFilter() replaced registerHelper() from previous releases

$latte->onCompile[] = function($latte) {
	$latte->addMacro(...);
	// if you want add your own macros, see http://goo.gl/d5A1u2
};

$latte->render('template.latte', $parameters);
// or $html = $latte->renderToString('template.latte', $parameters);

Latte now handles template loading and caching. The original FileTemplate and the Nette\Templating namespaces have been deprecated.

Besides, Nette\Application provides its own Template class, which replaces FileTemplate, and TemplateFactory, which creates and initializes the templates for use in presenters and controls.

Tracy

The whole debugger and diagnostics classes were moved to the Tracy namespace. This means that the most important class, Nette\Diagnostics\Debugger, was renamed to much shorter Tracy\Debugger.

The prefix of the CSS classes in the debugger panel was changed from nette- to tracy- and the nette-toggle-collapsed CSS class was replaced by the pair of tracy-toggle and tracy-collapsed. In old extensions, these classes are automatically rewritten.

Other Changes

Classes ArrayHash, ArrayList, DateTime, Image and ObjectMixin are now part of the Utils package and they were moved from Nette to the Nette\Utils namespace. NetteLoader automatically creates aliases for these classes so they can be referenced by their old name. Aliases for other renamed classes are created at run-time (i.e. during the autoloading), and a warning is raised each time you use class by its old name.

Nette\Utils\MimeTypeDetector class was deprecated, the Fileinfo should be used directly since PHP 5.3.

Support for @serializationVersion annotation and custom annotation classes lookup was dropped since it was not used and only decreased the application performance.

When an error during link creation occurs, the returned path starts with #error: instead of error to prevent browser errors. If you are using CSS to highlight incorrect links, please update your CSS styles for invalid links.

New Features

The do parameter for forms is now transferred in the POST data to keep the URL more user-friendly. The form values are passed as the second parameter to the onSuccess callback, to spare you from writing $form->getValues(); in each form handler. New validators, Form::MIN and Form::MAX, were introduced.

data- attributes in Nette\Utils\Html now accepts arrays. They will be automatically encoded to JSON.

New function fetchAssoc() was added to the Nette\Database. The usage example can be found in test suite for ResultSet.fetchAssoc().

@inject annotations now respect aliases defined by use statements. This means you are no longer required to write fully qualified names when injecting dependencies.

Class Nette\Security\Passwords with static methods for password hashing and verification was introduced. This class uses the bcrypt algorithm and requires PHP 5.3.7 or higher. The bcrypt algorithm is more secure than traditionally used MD5 and SHA-* hashing, so we recommend using bcrypt functions instead. The semantics of these functions is compatible with the Password Hashing extension from PHP 5.5.

Last, but not least, when defining users in the config.neon file, you can specify role for each user:

nette:
	security:
		users:
			john:
				password: **********
				roles:
					- manager
					- reporter

Conclusion

Nette 2.2 splits the framework into smaller standalone components. Each component has its own repository with issue-tracking. You can install these components individually with Composer, or install the whole framework from distribution package or by requiring nette/nette in composer.json.

This version also introduces changes in Latte API to simplify its standalone usage, moves Tracy to its own namespace, and changes a few other classes.

Also, it brings new minor features to forms, HTML and database, improves @inject annotations used in dependency injection, and adds a new class for secure password hashing and verification.

Even though this version introduces changes in Nette structure, it was developed with compatibility in mind and without major BC breaks. Please update your applications and report any compatibility issues you encounter.

Comments (RSS)

  1. Thank for this summary!

    10 years ago

Sign in to submit a comment