Installation
Add the bundle to your composer.json under require:
"ais/kontrakmahasiswabundle": "dev-master"
Run:
composer update ais/kontrakmahasiswabundle
Register the Bundle
Add to AppKernel.php:
new Ais\KontrakMahasiswaBundle\AisKontrakMahasiswaBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
Configure Routing
Add to app/config/routing.yml:
ais_kontrakmahasiswas:
type: rest
prefix: /api
resource: "@AisKontrakMahasiswaBundle/Resources/config/routes.yml"
Access API Docs
Visit /api/doc to explore endpoints (e.g., http://localhost/web/app_dev.php/api/doc).
GET /api/contracts (or similar, check routes.yml).{ "id": 1, "student_name": "John Doe", "contract_date": "2023-10-01" }).NelmioApiDocBundle is configured for Swagger UI.CRUD Operations
@Route, @Method) for RESTful endpoints.use FOS\RestBundle\Controller\Annotations\Route;
use FOS\RestBundle\Controller\Annotations\Method;
/**
* @Route("/contracts/{id}", name="get_contract")
* @Method("GET")
*/
public function getContractAction($id) { ... }
Data Serialization
use JMS\Serializer\Annotation\Type;
/**
* @Type("array<string>")
*/
private $courses;
API Documentation
nelmio_api.yaml (e.g., title, host).Database Integration
Contract entity with @ORM\Entity).php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate
fos/rest-bundle) via composer.lock.phpunit (included in require-dev) for unit/functional tests.axios.get('/api/contracts').then(response => console.log(response.data));
Bundle Maturity
Symfony 2.7 Legacy
Missing Documentation
src/Ais/KontrakMahasiswaBundle/Resources/config/routing.yml and Entity/ for clues.Hard Dependencies
NelmioApiDocBundle, FOSRestBundle, and JMSSerializerBundle.composer.json.Enable Debug Mode
Set APP_DEBUG=true in .env to see detailed errors (e.g., missing routes).
Check Doctrine Migrations Run:
php app/console doctrine:schema:validate
Fix schema errors before testing.
API Doc Issues Clear cache if docs don’t load:
php app/console cache:clear
Serialization Errors Ensure entities are properly annotated for JMSSerializer:
use JMS\Serializer\Annotation as Serializer;
/**
* @Serializer\ExclusionPolicy("all")
* @Serializer\Expose
*/
class Contract { ... }
Custom Entities
Extend the Contract entity (e.g., add status field):
/**
* @ORM\Column(type="string")
* @Serializer\Type("string")
*/
private $status;
New Endpoints
Add routes in routing.yml:
contract_create:
path: /api/contracts
defaults: { _controller: AisKontrakMahasiswaBundle:Contract:new }
Validation Use Symfony’s Validator component:
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\NotBlank()
*/
private $studentId;
Event Listeners Hook into Doctrine lifecycle (e.g., log contract creation):
// src/Ais/KontrakMahasiswaBundle/EventListener/ContractListener.php
public function postPersist(LifecycleEventArgs $args) {
$entity = $args->getObject();
// Log logic here
}
How can I help you explore Laravel packages today?