Installation:
composer require ais/kontrakdosenbundle: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\KontrakDosenBundle\AisKontrakDosenBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
Configure Routing:
Add to app/config/routing.yml:
ais_kontrakdosens:
type: rest
prefix: /api
resource: "@AisKontrakDosenBundle/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 to explore endpoints (e.g., GET /api/kontrakdosens).
CRUD Operations:
Leverage FOSRestBundle annotations (e.g., @Route, @Method) for RESTful endpoints. Example:
use FOS\RestBundle\Controller\Annotations\Route;
use FOS\RestBundle\Controller\Annotations\Method;
/**
* @Route("/kontrakdosens", name="get_kontrakdosens")
* @Method("GET")
*/
public function getKontrakDosenAction()
{
return $this->get('kontrak_dosen.manager')->findAll();
}
Serialization: Use JMS Serializer for DTOs. Example:
# app/config/config.yml
jms_serializer:
metadata:
directories:
FOSUser:
namespace_prefix: "Ais\\KontrakDosenBundle\\Serializer"
path: "%kernel.root_dir%/Resources/config/serializer"
API Documentation:
NelmioApiDocBundle auto-generates docs. Customize with nelmio_api_doc config:
nelmio_api_doc:
areas: [api] # Your routing prefix
sandbox: ~
Dependency Injection: Inject services via constructor or setter. Example:
public function __construct(KontrakDosenManager $manager)
{
$this->manager = $manager;
}
kontrak_dosen.manager (likely a custom service) for database operations.Symfony\Validator with custom constraints (e.g., @Assert\Valid()).LiipFunctionalTestBundle for API tests:
$client = static::createClient();
$client->request('GET', '/api/kontrakdosens');
Symfony 2.7 Legacy:
Resources/config/routes.yml.Missing Documentation:
AisKontrakDosenBundle/Resources/config/services.yml for services.kontrak_dosen.manager is undefined, check for typos or missing service definitions.NelmioApiDocBundle Dependency:
NelmioApiDocBundle registered. Ensure fos/rest-bundle is also installed.Dev-Master Instability:
dev-master branch may break. Fork and pin a version if needed.php app/console cache:clear
php app/console debug:container | grep kontrak
jms_serializer configuration for custom handlers.Custom Controllers:
Extend existing controllers (e.g., AisKontrakDosenBundle\Controller\KontrakDosenController) by overriding methods.
Event Listeners:
Add listeners for Doctrine lifecycle events (e.g., prePersist):
# app/config/services.yml
services:
kontrak_dosen.listener:
class: AppBundle\EventListener\KontrakDosenListener
tags:
- { name: doctrine.event_listener, event: prePersist }
API Extensions:
Add new routes in app/config/routing.yml and extend the bundle’s routes.yml.
Testing:
Mock the kontrak_dosen.manager in PHPUnit tests:
$manager = $this->createMock(KontrakDosenManager::class);
$this->get('kontrak_dosen.manager') = $manager;
How can I help you explore Laravel packages today?