Installation Add the bundle via Composer:
composer require araise/core-bundle
Register the bundle in config/bundles.php:
Araise\CoreBundle\AraiseCoreBundle::class => ['all' => true],
First Use Case: Turbo Integration
Enable Turbo in config/packages/araise_core.yaml:
araise_core:
enable_turbo: true
Use Turbo event listeners in your JavaScript:
document.addEventListener('turbo:load', () => {
// Handle Turbo-loaded content
});
Key Components
__toString() with StringConverter:
use Araise\CoreBundle\Utils\StringConverter;
$converter = new StringConverter();
$string = $converter->convert($object);
FlashBagException for structured flash handling:
throw new FlashBagException('success', 'Operation completed!');
Twig Extensions
Use araise_core_to_string for seamless object-to-string conversion in templates:
{{ someObject|araise_core_to_string }}
Stimulus Controllers
Leverage pre-built controllers (e.g., combobox_controller.js for Tom Select):
// assets/controllers/combobox_controller.js
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
connect() { /* ... */ }
}
Attach to HTML:
<input data-controller="combobox">
Date Handling
Use datetime_controller.js for consistent date formatting:
// assets/controllers/datetime_controller.js
document.addEventListener('DOMContentLoaded', () => {
const controller = new DatetimeController();
controller.formatDate('2023-10-01', 'MM/DD/YYYY');
});
Input Masks
Apply masks (e.g., currency, security numbers) via input-mask_controller.js:
<input data-controller="input-mask" data-input-mask-mask="money">
Badge Formatting
Standardize badges with BadgeFormatter:
$badge = (new BadgeFormatter())->format('warning', 'Alert');
// Output: <span class="badge bg-warning">Alert</span>
Dependency Injection
Autowire services like StringConverter or BadgeFormatter:
public function __construct(private StringConverter $converter) {}
Configuration Inheritance
CoreBundle configs (e.g., enable_turbo) cascade to dependent bundles (e.g., CrudBundle). Centralize settings in araise_core.yaml.
Command-Line Tools
Extend BaseCommand for CLI tools (avoid deprecated getContainer()):
use Araise\CoreBundle\Command\BaseCommand;
class MyCommand extends BaseCommand {
protected function execute(InputInterface $input, OutputInterface $output): int {
// Use $this->getHelper('question') for interactive CLI.
}
}
Turbo Configuration Conflicts
enable_turbo: true may break Turbo-dependent bundles (e.g., CrudBundle).araise_core.yaml and test event listeners (turbo:load vs. DOMContentLoaded).Deprecated Methods
BaseCommand::getContainer() and BaseCommand::get() are deprecated. Use Symfony’s DI or helpers instead.$this->getApplication()->getKernel()->getContainer()->get('service_id');
Stimulus Controller Renaming
select_controller.js was refactored to combobox_controller.js. Old references break.<!-- Old (broken) -->
<input data-controller="select">
<!-- New -->
<input data-controller="combobox">
Flash Message Handling
FlashBagException requires explicit handling in controllers.try {
// Risky operation
} catch (FlashBagException $e) {
$this->addFlash($e->getType(), $e->getMessage());
return $this->redirectToRoute('home');
}
BackedEnum Support
BackedEnum in StringConverter.__toString() for custom enums.Turbo Debugging Use browser DevTools to inspect Turbo events:
document.addEventListener('turbo:load', (event) => {
console.log('Turbo load event:', event);
});
String Conversion Issues
Verify StringConverter supports your object type. Extend it for custom classes:
$converter->addConverter(MyClass::class, fn(MyClass $obj) => $obj->getLabel());
Stimulus Controller Errors Check the browser console for missing assets. Ensure controllers are compiled (e.g., via Vite/Webpack).
Custom String Conversion
Extend StringConverter for domain-specific objects:
$converter->addConverter(User::class, fn(User $user) => "User#{$user->id}");
Badge Customization
Override BadgeFormatter templates:
{% extends '@AraiseCore/Badge/badge.html.twig' %}
{% block badge_content %}{{ content }} (Custom){% endblock %}
Turbo Event Extensions Add custom Turbo listeners in JavaScript:
document.addEventListener('turbo:before-fetch', (event) => {
// Modify requests globally
});
Input Mask Patterns
Define new masks in input-mask_controller.js:
static get masks() {
return {
...super.masks,
'custom': { pattern: '[0-9]{3}-[0-9]{2}' }
};
}
Flash Message Types
Extend FlashBagException for custom types:
throw new FlashBagException('custom.type', 'Message', ['key' => 'value']);
Handle in Twig:
{% if app.flashes('custom.type') %}
<div class="alert alert-custom">{{ app.flashes('custom.type')[0] }}</div>
{% endif %}
How can I help you explore Laravel packages today?