Skip to content

Commit

Permalink
use addAnnotatedClassesToCompile (#4572)
Browse files Browse the repository at this point in the history
* Bundles can hint Symfony about which of their classes contain annotations so they are compiled when generating the application cache to improve the overall performance. Define the list of annotated classes to compile in the addAnnotatedClassesToCompile() method:

https://symfony.com/doc/current/bundles/extension.html#adding-classes-to-compile
  • Loading branch information
craigh authored Jan 1, 2021
1 parent 300ba37 commit 2127efa
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [DefaultTheme] Add new default theme (#4462).
- This looks the same as ZikulaBootstrapTheme but improves the templates in a way that is not BC.
- [General] Implemented `Twig\Extension\RuntimeExtensionInterface` for all Twig extensions, allowing them to dynamically load (#4522).
- [General] Added `addAnnotatedClassesToCompile` method to needed core classes to improve performance when activated.
- [ThemeModule] Add `Symfony\WebpackEncoreBundle` (#4571).
- Automatically adds webpack assets via a listener.

Expand Down
3 changes: 3 additions & 0 deletions couscous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ menu:
upgrade3to3:
text: Upgrade 3 to 3
relativeUrl: Setup/upgradefrom3to3.x.x.html
production:
text: Deployment
relativeUrl: Setup/production.html
configuration:
name: Configuration
items:
Expand Down
17 changes: 17 additions & 0 deletions docs/Setup/Production.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
currentMenu: install
---
# Production

In an ideal situation, you would test your installation of Zikula in a local (developmet) environment before
moving the entire site into "production". This process is called _deployment_.

Symfony provides documentation for this process [here](https://symfony.com/doc/current/deployment.html).

Before deploying your site, you should **remove all unused Zikula extensions**.

Another recommended step is to run `composer dump-autoload -a` (authoritative mode). This will allow all supported
Zikula core classes to load faster. (see composer's [autoloader optimization](https://getcomposer.org/doc/articles/autoloader-optimization.md)).
It will also pre-cache all annotation classes in supported classes which will also speed up loading.

Beware however, as classes that are generated at runtime will not autoload and this [could cause issues](https://getcomposer.org/doc/articles/autoloader-optimization.md#trade-offs-2).
8 changes: 8 additions & 0 deletions src/Zikula/CoreBundle/DependencyInjection/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Zikula\Bundle\CoreBundle\Controller\MainController;

class CoreExtension extends Extension implements PrependExtensionInterface
{
Expand All @@ -44,6 +45,13 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('datadir', $config['datadir']);
$container->setParameter('multisites', $config['multisites']);

$this->addAnnotatedClassesToCompile([
MainController::class,
'Zikula\\*Module\\Controller\\',
'Zikula\\*Theme\\Controller\\',
'Zikula\\*Module\\Entity\\',
]);
}

public function getNamespace(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');

$this->addAnnotatedClassesToCompile([
'Zikula\\Bundle\\CoreInstallerBundle\\Controller\\',
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Zikula\Bundle\HookBundle\Controller\HookController;
use Zikula\Bundle\HookBundle\Entity\HookBindingEntity;
use Zikula\Bundle\HookBundle\Entity\HookRuntimeEntity;
use Zikula\Bundle\HookBundle\HookProviderInterface;
use Zikula\Bundle\HookBundle\HookSubscriberInterface;

Expand All @@ -36,5 +39,11 @@ public function load(array $configs, ContainerBuilder $container)
$container->registerForAutoconfiguration(HookSubscriberInterface::class)
->addTag('zikula.hook_subscriber')
;

$this->addAnnotatedClassesToCompile([
HookController::class,
HookBindingEntity::class,
HookRuntimeEntity::class
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use function Symfony\Component\String\s;
use Zikula\Bundle\WorkflowBundle\Controller\EditorController;

/**
* Class ZikulaWorkflowExtension
Expand All @@ -34,6 +35,10 @@ public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');

$this->addAnnotatedClassesToCompile([
EditorController::class
]);
}

public function prepend(ContainerBuilder $container)
Expand Down

0 comments on commit 2127efa

Please sign in to comment.