Installation
Add the package to your composer.json under require:
"require": {
"ais/ruangbundle": "dev-master"
}
Run composer update to install dependencies.
Register the Bundle
Add Ais\RuangBundle\AisRuangBundle() to your AppKernel.php under registerBundles():
new Ais\RuangBundle\AisRuangBundle(),
Enable Required Dependencies
Ensure these bundles are also registered (required by ais-ruangbundle):
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
Configure Routing
Add the bundle’s routes to app/config/routing.yml:
ais_ruangs:
type: rest
prefix: /api
resource: "@AisRuangBundle/Resources/config/routes.yml"
Access API Documentation
Visit /api/doc (e.g., http://localhost/web/app_dev.php/api/doc) to explore the API endpoints via NelmioApiDocBundle.
The bundle likely provides RESTful endpoints for "Ruang" (Indonesian for "space" or "room"). Test a basic GET request to fetch all resources:
curl -X GET http://localhost/web/app_dev.php/api/ruangs
Expected response: A JSON array of Ruang entities (if the bundle follows standard FOSRest conventions).
RESTful API Development
@Route, @Get, @Post) to define endpoints in controllers.use FOS\RestBundle\Controller\Annotations\Route;
use FOS\RestBundle\Controller\Annotations\Get;
/**
* @Route("/ruangs/{id}", name="get_ruang")
* @Get()
*/
public function getRuangAction($id) {
// Fetch and return a single Ruang entity
}
Serialization with JMS
@JMS\Serializer\Annotation\Type for automatic JSON serialization:
use JMS\Serializer\Annotation as Serializer;
class Ruang {
/**
* @Serializer\Type("string")
*/
private $name;
}
Documentation-Driven Development
/**
* @ApiDoc(
* resource=true,
* description="Returns a list of Ruang entities",
* output="Ais\RuangBundle\Entity\Ruang[]"
* )
*/
Form Handling with FOSRest
FOS\RestBundle\Form\Handler\AbstractFormHandler for form submission:
$formHandler = new FormHandler($this->get('form.factory'), $this->get('request'), $ruang, $formType);
if ($formHandler->process()) {
// Handle success
}
Ruang entity extends Doctrine\ORM\Mapping\Entity and is mapped in config.yml:
doctrine:
orm:
entity_managers:
default:
mappings:
AisRuangBundle: ~
config.yml:
assetic:
bundles: [AisRuangBundle]
swiftmailer in config.yml:
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
Symfony 2.7 Dependency
Missing Dependencies
composer.json:
"nelmio/api-doc-bundle": "^3.0",
"friendsofsymfony/rest-bundle": "^2.0",
"jms/serializer-bundle": "^1.0"
Route Conflicts
routes.yml may conflict with existing routes. Prefix routes explicitly:
ais_ruangs:
prefix: /api/v1
Dev-Master Instability
dev-master. Expect breaking changes. Pin a specific commit in composer.json:
"ais/ruangbundle": "dev-commit-hash"
Enable Profiler
Add %kernel.debug%: true to app/config/parameters.yml to access Symfony’s profiler for debugging routes/controllers.
Check Doctrine Mappings
Run php app/console doctrine:schema:validate to ensure entities are mapped correctly.
API Doc Issues Clear the cache if docs fail to load:
php app/console cache:clear
Custom Entities
Extend the Ruang entity by overriding its methods or adding new fields. Example:
namespace Ais\RuangBundle\Entity;
class CustomRuang extends Ruang {
/**
* @ORM\Column(type="string")
*/
private $customField;
}
Event Listeners
Use Symfony’s event system to hook into lifecycle events (e.g., prePersist):
// src/Ais/RuangBundle/EventListener/RuangListener.php
class RuangListener {
public function onPrePersist(Ruang $ruang) {
$ruang->setCreatedAt(new \DateTime());
}
}
Register the listener in services.yml:
services:
ais_ruang.listener.ruang:
class: Ais\RuangBundle\EventListener\RuangListener
tags:
- { name: doctrine.event_listener, event: prePersist }
Custom Controllers
Override bundle controllers by creating a Controller directory in your bundle and using override: true in services.yml:
services:
ais_ruang.controller.ruang:
class: Your\Bundle\Controller\RuangController
parent: ais_ruang.controller.ruang_base
tags: ['controller.service_arguments']
How can I help you explore Laravel packages today?