Installation
Add to composer.json:
"require": {
"ais/pertemuanbundle": "dev-master"
}
Run:
composer update ais/pertemuanbundle
Register Bundle
In AppKernel.php, add:
new Ais\PertemuanBundle\AisPertemuanBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
Configure Routing
In app/config/routing.yml:
ais_pertemuans:
type: rest
prefix: /api
resource: "@AisPertemuanBundle/Resources/config/routes.yml"
NelmioApiDocBundle:
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
prefix: /api/doc
First Use Case Access the API docs at:
http://localhost/web/app_dev.php/api/doc
Test endpoints (e.g., GET /api/pertemuans).
RESTful API Development
FOSRestBundle for standardized API responses (e.g., @Route, @QueryParam).NelmioApiDocBundle for auto-generated Swagger docs (document endpoints as you build).Entity Management
AisPertemuanBundle's base entities (e.g., Pertemuan) via Doctrine:
// src/Acme/AppBundle/Entity/CustomPertemuan.php
use Ais\PertemuanBundle\Entity\Pertemuan as BasePertemuan;
class CustomPertemuan extends BasePertemuan {
// Add custom fields/methods
}
Serialization
use JMS\Serializer\Annotation as Serializer;
class CustomPertemuan {
/**
* @Serializer\ExclusionPolicy("all")
*/
private $sensitiveData;
/**
* @Serializer\Expose
*/
public function getFormattedDate() { ... }
}
Validation
Validator with constraints:
use Symfony\Component\Validator\Constraints as Assert;
class CustomPertemuan {
/**
* @Assert\NotBlank
* @Assert\Length(min=3)
*/
private $topic;
}
Event Listeners
prePersist):
// src/Acme/AppBundle/EventListener/PertemuanListener.php
use Doctrine\Common\PersistenceEventArgs;
class PertemuanListener {
public function prePersist(Pertemuan $pertemuan, PersistenceEventArgs $args) {
$pertemuan->setCreatedAt(new \DateTime());
}
}
Register in services.yml:
services:
acme.listener.pertemuan:
class: Acme\AppBundle\EventListener\PertemuanListener
tags:
- { name: doctrine.event_listener, event: prePersist }
Symfony 2.7 Dependency
symfony/symfony:2.7.Missing Documentation
src/Ais/PertemuanBundle/Entity/ for base models.debug:container to list all services:
php app/console debug:container | grep pertemuan
NelmioApiDocBundle Dependency
NelmioApiDocBundle configured. Ensure:
fos_rest routes are properly prefixed.@ApiDoc annotations are added to controllers.JMS Serializer Conflicts
# app/config/config.yml
jms_serializer:
metadata:
directories:
Acme:
namespace_prefix: "Acme\\AppBundle\\Serializer"
path: "%kernel.root_dir%/serializer"
Dev-Master Instability
dev-master branch may break. Pin to a commit in composer.json:
"ais/pertemuanbundle": "dev-abc1234"
Enable Profiler
php app/console debug:router | grep pertemuan
Check the profiler for Doctrine queries or validation errors.
Log Serialization Issues
Add to config.yml:
jms_serializer:
handlers:
datetime:
default_format: "Y-m-d H:i:s"
format: "Y-m-d H:i:s"
Override Bundle Templates
Copy AisPertemuanBundle/Resources/views/ to AcmeAppBundle/Resources/AisPertemuanBundle/views/ to customize templates.
Custom Controllers
Extend the bundle’s controllers (e.g., PertemuanController) by:
Acme/AppBundle/Controller/PertemuanController.prepend/append in routing:
ais_pertemuans_custom:
type: rest
prefix: /api
resource: "@AcmeAppBundle/Resources/config/routing.yml"
requirements:
_controller: Acme\AppBundle\Controller\PertemuanController::*
Add Fields to Entities Use Doctrine inheritance:
// src/Acme/AppBundle/Entity/PertemuanExtension.php
use Ais\PertemuanBundle\Entity\Pertemuan as BasePertemuan;
class PertemuanExtension extends BasePertemuan {
/**
* @ORM\Column(type="string")
*/
private $customField;
}
Event Dispatching Trigger custom events for pertemuan actions:
// src/Acme/AppBundle/Event/PertemuanEvent.php
class PertemuanEvent extends Event {
protected $pertemuan;
}
Dispatch in a controller:
$event = new PertemuanEvent($pertemuan);
$this->get('event_dispatcher')->dispatch('pertemuan.create', $event);
How can I help you explore Laravel packages today?