Installation:
composer require ais/slotbundle:dev-master
Ensure your composer.json includes the required dependencies (e.g., fos/rest-bundle, nelmio/api-doc-bundle).
Register the Bundle:
Add to app/AppKernel.php:
new Ais\SlotBundle\AisSlotBundle(),
Include required bundles (e.g., NelmioApiDocBundle, FOSRestBundle, JMSSerializerBundle).
Routing:
Add to app/config/routing.yml:
ais_slots:
type: rest
prefix: /api
resource: "@AisSlotBundle/Resources/config/routes.yml"
First Use Case:
Access the API docs at /api/doc (e.g., http://localhost/web/app_dev.php/api/doc) to explore available endpoints.
Slot Management:
GET /api/slots, POST /api/slots) to create, read, update, or delete slots.FOSRestBundle for standardized API responses (e.g., JSON, HTTP status codes).Serialization:
JMSSerializerBundle to handle slot entity serialization/deserialization. Example:
# app/config/config.yml
jms_serializer:
metadata:
directories:
AisSlotBundle:
namespace_prefix: "Ais\\SlotBundle\\Entity"
path: "@AisSlotBundle/Resources/config/serializer"
API Documentation:
NelmioApiDocBundle auto-generates Swagger docs. Annotate controllers with @SWG\* tags for clarity:
use Nelmio\ApiDocBundle\Annotation\SWG;
/**
* @SWG\Get(
* path="/api/slots",
* summary="List all slots"
* )
*/
public function getSlotsAction()
{
// ...
}
Dependency Injection:
use Ais\SlotBundle\Service\SlotManager;
class SlotController extends FOS\RestController
{
public function __construct(SlotManager $slotManager)
{
$this->slotManager = $slotManager;
}
}
Ais\SlotBundle\Entity\Slot for custom fields or behaviors.@Assert\NotBlank) in slot entities.LiipFunctionalTestBundle for API endpoint testing:
$client = static::createClient();
$client->request('GET', '/api/slots');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
Symfony Version Mismatch:
symfony/symfony:2.7.* in composer.json.Missing Dependencies:
NelmioApiDocBundle, FOSRestBundle, and JMSSerializerBundle. Forgetting to register these will break routes/API docs.AppKernel.php and composer.json.Route Conflicts:
ais_slots prefix (/api) may clash with existing routes. Customize in routing.yml if needed:
ais_slots:
prefix: /custom-prefix
Serialization Issues:
jms_serializer config.@ORM\Entity, @Serializer\ExclusionPolicy).php bin/console debug:serializer to validate mappings.API Docs Not Loading:
NelmioApiDocBundle is registered after FOSRestBundle in AppKernel.php.php bin/console cache:clear
404 Errors:
php bin/console debug:router | grep ais_slots
ais_slots vs. ais_slot).Custom Slot Types:
Ais\SlotBundle\Entity\Slot and override methods (e.g., getTitle()).# app/config/doctrine/orm.yml
entity_managers:
default:
mappings:
AisSlotBundle: ~
AppBundle: # Your custom entities
type: annotation
dir: "%kernel.root_dir%/../src/AppBundle/Entity"
prefix: "AppBundle\Entity"
alias: AppBundle
Event Listeners:
slot.create) via Symfony’s event dispatcher:
services:
app.slot_listener:
class: AppBundle\EventListener\SlotListener
tags:
- { name: kernel.event_listener, event: slot.create, method: onSlotCreate }
API Extensions:
Ais\SlotBundle\Controller\SlotController.class CustomSlotController extends SlotController
{
public function customAction()
{
return $this->handleView($this->view(['data' => 'custom']));
}
}
Register the new route in routing.yml:
custom_slot:
path: /api/slots/custom
defaults: { _controller: AppBundle\Controller\CustomSlotController::customAction }
Parameter Handling:
incenteev/composer-parameter-handler to manage bundle parameters dynamically.php bin/console debug:config ais_slot
Asset Management:
AsseticBundle for CSS/JS. Configure in config.yml:
assetic:
bundles: [AisSlotBundle]
How can I help you explore Laravel packages today?