This guide provides step-by-step instructions for AI assistants to rename a Sylius plugin from the default skeleton name to a custom name.
Before renaming the plugin, ensure that:
- The plugin is in a clean state - All example/demo code should be removed first
- Run CLEANUP_GUIDE.md first if the plugin still contains example code
- Backup your work - Commit any important changes before starting the rename process
- Close any running servers - Stop Symfony server, Docker containers, etc.
The default plugin skeleton uses:
- Company namespace:
Acme - Plugin name:
SyliusExamplePlugin - Full namespace:
Acme\SyliusExamplePlugin
Sylius plugins should follow this naming pattern:
- Format:
{CompanyName}\{PluginName} - Plugin name should start with
Syliusprefix - Example:
Acme\SyliusShopUserCleanupPlugin
To ensure a smooth renaming process, follow this order:
- Rename PHP files - Start with the physical file renames
- Update PHP namespaces - Update all namespace declarations and class names
- Update composer.json - Change package name and autoload configurations
- Update configuration files - Modify all YAML/XML configurations
- Update environment files - Change database names and bundle references
- Update documentation - Modify CLAUDE.md and other docs
- Validate and cleanup - Run composer commands and verify changes
-
Main plugin class file:
src/AcmeSyliusExamplePlugin.php → src/{CompanyName}{PluginName}.php -
DependencyInjection extension file:
src/DependencyInjection/AcmeSyliusExampleExtension.php → src/DependencyInjection/{CompanyName}{PluginName}Extension.php
Update in tests/TestApplication/.env:
DATABASE_URL=mysql://root:root@127.0.0.1/{company_name_snake}_{plugin_name_snake}_%kernel.environment%
CONFIGS_TO_IMPORT="@{CompanyName}{PluginName}/tests/TestApplication/config/config.yaml"
ROUTES_TO_IMPORT="@{CompanyName}{PluginName}/config/shop_routing.yaml"Update in tests/TestApplication/.env.test:
DATABASE_URL=mysql://root:root@127.0.0.1/{company_name_snake}_{plugin_name_snake}_%kernel.environment%Note: The {company_name_snake}_{plugin_name_snake} should be the snake_case version of your plugin name, e.g., acme_sylius_shop_user_cleanup_plugin.
Update package metadata and PSR-4 autoload mappings:
Package Information:
{
"name": "{company-name-kebab}/{plugin-name-kebab}",
"description": "Brief description of your Sylius plugin functionality",
"type": "sylius-plugin"
}PSR-4 Autoload Mappings:
"autoload": {
"psr-4": {
"{CompanyName}\\{PluginName}\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\{CompanyName}\\{PluginName}\\": ["tests/", "tests/TestApplication/src/"]
}
}Important Notes:
- Package name should use kebab-case format:
{company-name}/{plugin-name} - Company name in package should be lowercase
- Plugin name should be descriptive and include
syliusprefix - Description should briefly explain what the plugin does
Update namespace declarations in:
src/{CompanyName}{PluginName}.phpsrc/DependencyInjection/{CompanyName}{PluginName}Extension.phpsrc/DependencyInjection/Configuration.php- Important: Often missed!src/Controller/*.php- Any other PHP files in src/
Also update:
- Class names to match new plugin name
- Twig namespace references from
@AcmeSyliusExamplePluginto@{CompanyName}{PluginName} - In
Configuration.php, update the TreeBuilder parameter:$treeBuilder = new TreeBuilder('{company_name_snake}_{plugin_name_snake}');
Update Twig namespace references in:
config/app/twig_hooks/admin.yamlconfig/app/twig_hooks/shop.yamltests/TestApplication/config/config.yamltests/TestApplication/config/services_test.php
Update in tests/TestApplication/config/bundles.php:
return [
{CompanyName}\{PluginName}\{CompanyName}{PluginName}::class => ['all' => true],
];Update CLAUDE.md to reflect the new plugin name and namespace.
| Find | Replace |
|---|---|
Acme\SyliusExamplePlugin |
{CompanyName}\{PluginName} |
AcmeSyliusExamplePlugin |
{CompanyName}{PluginName} |
AcmeSyliusExampleExtension |
{CompanyName}{PluginName}Extension |
@AcmeSyliusExamplePlugin |
@{CompanyName}{PluginName} |
Tests\Acme\SyliusExamplePlugin |
Tests\{CompanyName}\{PluginName} |
| Field | Value |
|---|---|
name |
{company-name-kebab}/{plugin-name-kebab} |
description |
Brief plugin description |
Don't forget to also check and update:
tests/TestApplication/.env.local(if exists)- Any other
.env.*files in the test application tests/Behat/Resources/services.xml- may contain old service references- All XML files in
tests/directory - they might have namespace references phpspec.yml.dist(if exists) - contains namespace configuration- Any custom configuration files you may have added
- Database names should use snake_case format
After renaming, verify:
-
Validate composer.json:
composer validate
Note: Warning about composer.lock being out of date is normal and expected
-
Regenerate autoload files:
composer dump-autoload
-
Search for remaining old references:
grep -r "SyliusExamplePlugin\|sylius_example" . --exclude-dir=vendor --exclude-dir=var --exclude-dir=.git
Only documentation files (like this guide) should contain these references
-
Check all critical files:
- Ensure composer.json has package name and description
- Verify all PHP files have correct namespace declarations
- Confirm environment variables are updated in all
.env*files - Check that
TreeBuilderparameter in Configuration.php uses snake_case
-
Clear Symfony cache (if in a Sylius app):
bin/console cache:clear
-
Test the plugin:
- Try to install it in a test Sylius application
- Check that bundle is properly registered
- Verify routes are accessible
From default skeleton:
Acme\SyliusExamplePlugin\AcmeSyliusExamplePlugin@AcmeSyliusExamplePlugin/templates/...
To custom plugin (example):
MyCompany\SyliusAwesomeFeaturePlugin\MyCompanySyliusAwesomeFeaturePlugin@MyCompanySyliusAwesomeFeaturePlugin/templates/...
Problem: Class not found errors after renaming
Solution:
composer dump-autoload
rm -rf var/cache/* # Clear Symfony cacheProblem: PHP fatal errors about namespaces Solution:
- Check all PHP files have correct
namespacedeclarations - Verify composer.json autoload paths match your namespaces
- Ensure class names match file names
Problem: Plugin doesn't appear to be registered Solution:
- Check
tests/TestApplication/config/bundles.phphas correct class reference - Verify all configuration imports use new namespace
@NewPluginName - Clear cache and restart server
Problem: Cannot connect to database during tests Solution:
- Ensure all
.env*files have updated database names - Database names should use snake_case format
- Check that database actually exists
Problem: composer validate shows warnings
Solution:
- "Lock file out of date" is normal after renaming
- Missing package name: Add
"name"field to composer.json - Missing description: Add meaningful
"description"field
-
composer.json package information - The skeleton doesn't include package name and description:
- Add
"name"field using kebab-case format - Add
"description"field with meaningful description - Package name is required for publishing or private repositories
- Add
-
Configuration.php - This file is often missed because PHPStan excludes it. Always check:
- Namespace is updated
- TreeBuilder parameter uses snake_case format without
_pluginsuffix
-
Environment files - All
.env*files intests/TestApplication/need updating -
Database names - Should use snake_case format with full plugin name
-
Test files cleanup - Don't forget to update or remove:
tests/Behat/Resources/services.xml- may contain old service references- Any remaining example/demo test files
-
Not removing example code first - Always run CLEANUP_GUIDE.md before renaming:
- Example code can cause confusion with old references
- Clean slate makes renaming much easier
-
Forgetting autoload regeneration - Always run after changes:
composer dump-autoloadto regenerate class maps- Clear Symfony cache if working in Sylius environment
- Always maintain the
Syliusprefix in the plugin name - Keep the company name consistent across all files
- The DependencyInjection extension class must end with
Extension - Twig namespaces use
@prefix followed by the full plugin class name - Don't forget to update test configurations in
tests/TestApplication/ - The Configuration TreeBuilder name should match the extension alias (snake_case)
- Package name in composer.json is mandatory for proper plugin identification and distribution