blixit/msf-bundle
blixit/msf-bundle is a Laravel/PHP bundle centered on MSF integration, providing packaged configuration and reusable components to help wire the service into your app. Intended as a lightweight starting point rather than a full-featured framework.
Installation
composer require blixit/msf-bundle
Enable the bundle in app/AppKernel.php:
new Blixit\MSFBundle\MSFBundle(),
Basic Configuration
Add to app/config/config.yml:
blixit_msf:
steps:
- { id: 'step1', label: 'Step 1' }
- { id: 'step2', label: 'Step 2' }
First Use Case: Simple Multi-Step Form Create a controller:
use Blixit\MSFBundle\Controller\MultiStepFormController;
class MyFormController extends MultiStepFormController
{
public function configureSteps()
{
return [
'step1' => ['template' => 'MyBundle:Form:step1.html.twig'],
'step2' => ['template' => 'MyBundle:Form:step2.html.twig'],
];
}
}
Define routes in routing.yml:
my_form:
resource: "@MyBundle/Controller/MyFormController.php"
type: annotation
Step Definition Use YAML/annotation/config to define steps:
blixit_msf:
steps:
- { id: 'personal', label: 'Personal Info', form: 'AppBundle\Form\PersonalType' }
- { id: 'payment', label: 'Payment', form: 'AppBundle\Form\PaymentType' }
Controller Integration
Extend MultiStepFormController and override:
public function getFormClass($stepId)
{
return 'AppBundle\Form\\' . ucfirst($stepId) . 'Type';
}
public function getFormOptions($stepId, array $options)
{
return array_merge($options, ['step_id' => $stepId]);
}
Template Structure
Use {{ form_start(form) }} in each step template (step1.html.twig):
<div class="step {{ step.id }}">
{{ form_widget(form) }}
{% if not step.isLast %}
<button type="submit" class="next">Next</button>
{% else %}
<button type="submit" class="submit">Submit</button>
{% endif %}
</div>
Data Persistence Store intermediate data in session:
$this->get('session')->set('msf_data', $form->getData());
onStepTransition().msf.step.enter/msf.step.leave for side effects.Session Management
$this->get('session')->set('msf_data', ...) after each step.Step ID Mismatches
configureSteps() returns match blixit_msf.steps config.Form Submission Quirks
{{ form_rest(form) }} or custom buttons with data-msf-next attributes.$this->getStep() in controller to verify current step.$this->get('session')->get('msf_data') for corrupted payloads.Custom Step Logic
Override onStepEnter()/onStepLeave() in controller:
public function onStepEnter($stepId)
{
if ($stepId === 'payment') {
$this->denyAccessUnlessGranted('ROLE_PREMIUM');
}
}
Dynamic Steps Load steps from database:
public function configureSteps()
{
$steps = $this->getDoctrine()->getRepository('AppBundle:Step')->findAll();
return array_map(function($step) {
return ['template' => $step->getTemplate()];
}, $steps);
}
CSRF Protection Disable per-step if needed (not recommended):
blixit_msf:
disable_csrf: true
How can I help you explore Laravel packages today?