ais/pertemuanmahasiswabundle
Install via Composer
Add to composer.json:
"require": {
"ais/pertemuanmahasiswabundle": "dev-master"
}
Run:
composer update
Register the Bundle
Add to app/AppKernel.php:
new Ais\PertemuanMahasiswaBundle\AisPertemuanMahasiswaBundle(),
Ensure dependencies (NelmioApiDocBundle, FOSRestBundle, JMSSerializerBundle) are also registered.
Configure Routing
Add to app/config/routing.yml:
ais_pertemuanmahasiswas:
type: rest
prefix: /api
resource: "@AisPertemuanMahasiswaBundle/Resources/config/routes.yml"
Access API Docs
Visit /api/doc (e.g., http://localhost/web/app_dev.php/api/doc) to explore endpoints.
PertemuanMahasiswaPOST to /api/pertemuanmahasiswas with JSON payload:
{
"nama_pertemuan": "Seminar AI",
"tanggal": "2023-12-01",
"deskripsi": "Diskusi tentang AI trends"
}
GET /api/pertemuanmahasiswas to retrieve all meetings or filter by ID (/api/pertemuanmahasiswas/{id}).RESTful API Integration
FOSRestBundle for standardized API responses (e.g., 201 Created on success, 404 Not Found for missing resources).NelmioApiDocBundle to auto-generate Swagger/OpenAPI docs for client-side SDKs.Entity Management
PertemuanMahasiswa entity (check src/Ais/PertemuanMahasiswaBundle/Entity/).// src/Ais/PertemuanMahasiswaBundle/EventListener/PertemuanListener.php
public function prePersist(PertemuanMahasiswa $pertemuan)
{
$pertemuan->setCreatedAt(new \DateTime());
}
Serialization
JMS Serializer (e.g., exclude sensitive fields):
# config/config.yml
jms_serializer:
metadata:
directories:
AisPertemuanMahasiswa:
namespace_prefix: "Ais\\PertemuanMahasiswaBundle\\Entity"
path: "%kernel.root_dir%/serializer"
Validation
PertemuanMahasiswa entity:
use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\NotBlank()
* @Assert\Length(min=3)
*/
private $nama_pertemuan;
php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate
LiipFunctionalTestBundle for API tests:
// Tests/AisPertemuanMahasiswaBundle/Controller/PertemuanControllerTest.php
public function testCreatePertemuan()
{
$client = static::createClient();
$client->request('POST', '/api/pertemuanmahasiswas', [
'json' => ['nama_pertemuan' => 'Test Meeting']
]);
$this->assertEquals(201, $client->getResponse()->getStatusCode());
}
fetch or axios to call the API:
// Example with Axios
axios.post('/api/pertemuanmahasiswas', {
nama_pertemuan: 'New Meeting',
tanggal: '2023-12-15'
});
Symfony 2.7 Legacy:
sensio/framework-extra-bundle for annotations if needed.Missing Documentation:
src/Ais/PertemuanMahasiswaBundle/Resources/config/routing.yml for endpoints.src/Ais/PertemuanMahasiswaBundle/Entity/PertemuanMahasiswa.php for entity structure.NelmioApiDocBundle Dependency:
# app/config/config.yml
nelmio_api_doc:
areas: [default]
Dev-Master Instability:
dev-master branch may break. Fork and pin a stable commit:
"ais/pertemuanmahasiswabundle": "dev-v1.0.0"
Enable Profiler:
Add to app/config/config_dev.yml:
web_profiler: { toolbar: true, intercept_redirects: false }
Doctrine Logging:
Enable SQL logging in config_dev.yml:
doctrine:
dbal:
logging: true
Common Errors:
routing.yml and AppKernel.php.app/logs/dev.log) for exceptions.Custom Controllers: Override the default controller:
// src/Ais/PertemuanMahasiswaBundle/Controller/PertemuanController.php
class PertemuanController extends ContainerAwareController
{
public function customAction()
{
return $this->json(['custom' => 'data']);
}
}
Update routing.yml to include the new route.
Event Subscribers:
Listen to prePersist/preUpdate events:
// src/Ais/PertemuanMahasiswaBundle/EventListener/AuditListener.php
class AuditListener implements EventSubscriber
{
public function getSubscribedEvents()
{
return ['prePersist', 'preUpdate'];
}
public function prePersist(LifecycleEventArgs $args)
{
$pertemuan = $args->getEntity();
$pertemuan->setUpdatedBy('current_user');
}
}
Custom Validation: Add constraints dynamically:
// src/Ais/PertemuanMahasiswaBundle/Validator/Constraints/TanggalValidator.php
class TanggalValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
if ($value < new \DateTime('today')) {
$this->context->buildViolation('Tanggal must be in the future')->addViolation();
}
}
}
API Extensions: Add new endpoints by extending the bundle’s routing:
# app/config/routing.yml
ais_pertemuan_custom:
type: rest
resource: "@AisPertemuanMahasiswaBundle/Resources/config/custom_routes.yml"
How can I help you explore Laravel packages today?