Installation:
composer require ais/matakuliahbundle:dev-master
Ensure your composer.json includes the required dependencies (FOSRestBundle, JMSSerializerBundle, NelmioApiDocBundle).
Register the Bundle:
Add to app/AppKernel.php:
new Ais\MatakuliahBundle\AisMatakuliahBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
Configure Routing:
Add to app/config/routing.yml:
ais_matakuliahs:
type: rest
prefix: /api
resource: "@AisMatakuliahBundle/Resources/config/routes.yml"
Verify API Docs:
Access /api/doc to see the generated API documentation (requires NelmioApiDocBundle).
The bundle provides RESTful endpoints for Matakuliah (course) entities. Test with:
# Create a course
curl -X POST -H "Content-Type: application/json" -d '{
"name": "Database Systems",
"code": "CS401",
"credits": 3
}' http://localhost/api/matakuliah
# Fetch all courses
curl http://localhost/api/matakuliah
# Fetch a single course
curl http://localhost/api/matakuliah/1
Entity Management:
Ais\MatakuliahBundle\Entity\Matakuliah for custom fields or logic.@ORM\Entity annotations).API Integration:
FOSRestBundle for request/response handling (e.g., @Route("/matakuliah", name="matakuliah_list")).JMS\Serializer (e.g., @Serializer\ExclusionPolicy("ALL")).Validation:
Matakuliah entity (e.g., @Assert\NotBlank for required fields).FOSRestBundle's FormHandler for validation in controllers.Testing:
LiipFunctionalTestBundle (dev dependency).Guzzle (dev dependency).Database Migrations:
Matakuliah entity:
php app/console doctrine:schema:update --force
Custom Controllers:
Ais\MatakuliahBundle\Controller\MatakuliahController.Event Listeners:
prePersist) for business logic:
// src/Acme/AppBundle/EventListener/MatakuliahListener.php
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
class MatakuliahListener implements EventSubscriber {
public function prePersist(LifecycleEventArgs $args) { ... }
}
API Documentation:
NelmioApiDocBundle annotations for custom API docs:
# app/config/config.yml
nelmio_api_doc:
areas: { path_patterns: ["^/api"] }
Symfony Version Mismatch:
Missing Dependencies:
NelmioApiDocBundle, FOSRestBundle, and JMSSerializerBundle are required but not auto-installed.composer.json and AppKernel.php.Route Conflicts:
/api/matakuliah prefix may clash with existing routes.routing.yml or use route namespaces.Serialization Issues:
Matakuliah fields may break JMS\Serializer if not annotated.@Serializer\Type("string") or @Serializer\ExclusionPolicy.Enable Profiler:
# app/config/config_dev.yml
framework:
profiler: { only_exceptions: false }
Access /_profiler to inspect requests/responses.
Doctrine Logging:
// app/config/config_dev.yml
doctrine:
orm:
logging: true
Logs appear in var/log/doctrine.log.
API Response Validation:
bin/console debug:router to verify routes.curl -v for HTTP headers/body inspection.Custom Fields:
// src/Acme/AppBundle/Entity/ExtendedMatakuliah.php
use Ais\MatakuliahBundle\Entity\Matakuliah;
class ExtendedMatakuliah extends Matakuliah {
/**
* @ORM\Column(type="string")
* @Serializer\Type("string")
*/
private $customField;
}
Business Logic:
MatakuliahController methods (e.g., postAction).API Extensions:
routes.yml:
# src/Acme/AppBundle/Resources/config/routing.yml
acme_matakuliah_extended:
type: rest
resource: "@AcmeAppBundle/Resources/config/routing.yml"
Testing:
MatakuliahRepository in unit tests:
$repository = $this->getMockBuilder('Ais\MatakuliahBundle\Entity\MatakuliahRepository')
->disableOriginalConstructor()
->getMock();
How can I help you explore Laravel packages today?