Skip to main content

Upgrading from 0.2 to 0.3

simply-framework 0.3 moves to Symfony 7.4, rebuilds the cache reliably and makes the hooks declared with attributes lazy. It goes with simply-maker 0.4, simply-mvc 0.3 and the boilerplate 0.7. Read the release notes for the full list.

1. Composer constraints of your project​

In the root composer.json (created from the boilerplate):

"clementdecou/simply-framework": "^0.3",
"clementdecou/simply-maker": "^0.4",
"clementdecou/simply-mvc": "^0.3",
"symfony/dotenv": "^7.4"

(simply-mvc only if you use it), then:

composer update -W

Any other package of the project that requires Symfony 6 blocks the update. WordPress plugins that bundle an unscoped copy of Symfony load the same classes as Simply: check them as well.

2. Your code extending Symfony classes​

  • Console commands (in your plugins and theme): replace protected static $defaultName with the #[AsCommand] attribute, and declare execute(): int. Simply maker registers every command it finds: a single command without a name breaks the whole bin/console.
    use Symfony\Component\Console\Attribute\AsCommand;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;

    #[AsCommand(name: 'app:import', description: 'Import the products.')]
    class ImportCommand extends Command
    {
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
    return Command::SUCCESS;
    }
    }
  • Configuration classes: declare getConfigTreeBuilder(): TreeBuilder, otherwise the container build fails.
  • ContainerAwareInterface and ContainerAwareTrait no longer exist: inject the services you need.
  • ServiceSubscriberTrait is deprecated: use ServiceMethodsSubscriberTrait (see hooks).
  • See Symfony's UPGRADE-7.0 for the other changes.

3. Hooks declared with attributes​

  • The service is instantiated the first time WordPress runs one of its hooks, no longer on every request.
  • The WordPress callback is a LazyHookListener, no longer [$service, 'method']: remove_action() and has_filter() with [$service, 'method'] no longer find these hooks. See unhooking an attribute hook.
  • The build fails with an explicit message when a method with #[Action] or #[Filter] is not public, or takes a parameter by reference.
  • Removed: Simply\Core\Compiler\HookCompiler, setCallable() and register() on the Action and Filter attributes (which no longer implement HookableInterface), the simply.compile_hooks parameter. The HookManager constructor changed.

4. Cache​

The cache now lives in a sub-directory per fingerprint, and the compiled container class is CachedContainer_<fingerprint>. There is nothing to clear for the upgrade itself: the new package versions change the fingerprint.

The Redis cache now stores the values set without expiration (it stored nothing before 0.3.1): pass an expiration or delete the keys if your code relied on it.

5. Boilerplate configuration​

If you copy the new config/application.php of the boilerplate:

  • DB_PREFIX, DB_NAME, DB_USER and DB_PASSWORD must be defined;
  • DISABLE_WP_CRON=false now really enables the cron;
  • APP_DEBUG accepts true, 1, on and yes;
  • WP_SITEURL defaults to WP_HOME/wp.

See configuration.

6. Check​

On a staging environment, run php bin/console list and load a few pages before deploying.