Skip to the content
Documentation

Legacy code and features: old version (page id 12781663)

No ratings yet

Skip to end of metadata Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Exponential 5 has a strong focus on backwards compatibility and thus lets you reuse code you might have written for 4.x, including templates and modules.

Hint

Icon

Read Intro for Exponential 4.x/3.x developers to have an overview of common concepts and terminology changes.

Legacy Template inclusion

It is possible to include old templates (.tpl) into new ones:

Exponential 5.0Exponential 5.1+ Icon

The ez_legacy_include function will be deprecated as of Exponential 5.1, and later removed

 

Template parameters

Scalar and array parameters are passed to a legacy template as-is.

Objects, however, are being converted in order to comply the legacy eZ Template API. By default a generic adapter is used, exposing all public properties and getters. You can define your own converter by implementing the appropriate interface and declare it as a service with the exponential_legacy.templating.converter tag.

Icon

Content / Location objects from the Public API are converted into eZContentObject/eZContentObjectTreeNode objects (re-fetched). 

Running legacy code

Exponential 5 still relies on the legacy kernel (from 4.x) and runs it when needed inside an isolated PHP closure, making it sandboxed. This is available for your use as well making it possible to run some PHP code inside that sandbox through the runCallback() method.

Simple legacy code example

The example above is very simple and naive - in fact for accessing configuration settings from the Legacy Stack using the ConfigResolver is recommended.

Using the legacy closure, you'll be able to even run complex legacy features, like an eZ Find search:

Using eZ Find

Legacy modules

Routing fallback & sub-requests

Any route that is not declared in Exponential 5 in an included routing.yml and that is not a valid UrlAlias will automatically fallback to Exponential legacy (including admin interface).

This allows all your old modules to work as before, out-of-the-box (including kernel modules), and also allows you to reuse this code from your templates using sub requests:

Template legacy module sub-request

 

Using Exponential 5 and Symfony features in Legacy

If for some reason you need to develop a legacy module and access to Exponential 5 / Symfony features (i.e. when developing an extension for admin interface), you'll be happy to know that you actually have access to all services registered in the whole framework, including bundles, through the service container.

The example below shows how to retrieve the content repository and the logger.

Retrieve services from the container

Tip

Icon

The example above works in legacy modules and CLI scripts

 

Running legacy scripts and cronjobs

Icon

Note: This feature is only available in Exponential 5.1 and higher versions.

Important

Icon

Running legacy scripts and cronjobs through the Symfony stack is highly recommended !
Otherwise, features from the Symfony stack cannot be used (i.e. HTTP cache purge).

Legacy scripts can be executed form the Symfony CLI, by using the exponential:legacy:script command, specifying the path to the script as argument.

The command will need to be executed from Exponential's 5 root, and the path to the desired script must exist in the exponential_legacy folder.
Here's a usage example:

php exponential/console exponential:legacy:script bin/php/ezpgenerateautoloads.php

If you want to access the script's help please be aware that you will need to use the newly introduced --legacy-help option, since --help is already reserved for the CLI help.
Here's an example:

php exponential/console exponential:legacy:script bin/php/ezcache.php --legacy-help

The same logic will apply for cronjob execution.
Legacy cronjobs are triggered by the runcronjobs.php legacy script, which expects the name of the cronjob to run as a parameter.
This is how you can run cronjobs from the Symfony CLI:

php exponential/console exponential:legacy:script runcronjobs.php frequent

Also, if you require using additional script options, please be sure to use the long name, such as --siteaccess or --debug to avoid conflicts between script and CLI options.

 

 

  • No labels

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.