Installation Add the bundle to your Symfony project via Composer:
composer require amalricbzh/tools-bundle
Enable the bundle in config/bundles.php:
return [
// ...
AmalricBzh\ToolsBundle\AmalricBzhToolsBundle::class => ['all' => true],
];
Key Features Overview The bundle provides:
First Use Case: String Utilities
Access string helpers via the AmalricBzh\ToolsBundle\Helper\StringHelper service:
use AmalricBzh\ToolsBundle\Helper\StringHelper;
class MyController extends AbstractController {
public function index(StringHelper $stringHelper) {
$slug = $stringHelper->slugify('Hello World!');
// Returns: "hello-world"
}
}
Pattern: Extend Twig with reusable filters/filters. Example:
{{ 'Hello World'|slugify }} {# Output: "hello-world" #}
Integration Tip:
config/packages/amalricbzh_tools.yaml:
amalricbzh_tools:
twig:
extensions:
- 'App\Twig\CustomExtension'
Pattern: Use built-in form types or extend them. Example:
use AmalricBzh\ToolsBundle\Form\Type\AutoCompleteType;
$builder->add('search', AutoCompleteType::class, [
'choices' => $choices,
'placeholder' => 'Search...',
]);
Workflow:
services.yaml:
services:
App\Form\Type\CustomType:
tags: ['form.type']
Pattern: Use ServiceLocator or ParameterHelper.
Example:
use AmalricBzh\ToolsBundle\Helper\ServiceLocator;
class MyService {
public function __construct(private ServiceLocator $locator) {}
public function getMailer() {
return $this->locator->get('mailer');
}
}
Pattern: Subscribe to bundle events (e.g., tools.event).
Example:
use AmalricBzh\ToolsBundle\Event\ToolsEvent;
class MySubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
ToolsEvent::PRE_PROCESS => 'onPreProcess',
];
}
}
Namespace Conflicts
AmalricBzh\ToolsBundle namespace. Ensure your project doesn’t clash (e.g., avoid use AmalricBzh\ToolsBundle\Helper in custom classes).Twig Auto-Reloading
php bin/console cache:clear
Form Type Overrides
AutoCompleteType, ensure your class extends the base type:
class CustomAutoCompleteType extends AutoCompleteType { ... }
Enable Debug Mode
Set AMALRICBZH_TOOLS_DEBUG=true in .env to log helper usage:
AMALRICBZH_TOOLS_DEBUG=1
Check Service Availability Verify services are registered:
php bin/console debug:container amalricbzh_tools.helper.string
Custom Helpers
Register new helpers in config/packages/amalricbzh_tools.yaml:
amalricbzh_tools:
helpers:
- 'App\Helper\CustomHelper'
Override Default Config
Use config/packages/amalricbzh_tools.yaml to modify bundle behavior:
amalricbzh_tools:
twig:
enabled: false # Disable Twig extensions globally
Event Customization
Dispatch custom events by extending ToolsEvent:
class MyCustomEvent extends ToolsEvent { ... }
How can I help you explore Laravel packages today?