Installation:
composer require ais/prestasibundle:dev-master
Ensure your composer.json includes the required dependencies (FOSRestBundle, JMSSerializerBundle, NelmioApiDocBundle).
Register the Bundle:
Add to app/AppKernel.php:
new Ais\PrestasiBundle\AisPrestasiBundle(),
new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
Configure Routing:
Add to app/config/routing.yml:
ais_prestasis:
type: rest
prefix: /api
resource: "@AisPrestasiBundle/Resources/config/routes.yml"
NelmioApiDocBundle:
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
prefix: /api/doc
First Use Case:
Access the API docs at /api/doc to explore available endpoints. The bundle likely provides RESTful endpoints for "Prestasi" (Indonesian for "achievement" or "performance") entities.
Entity Management:
The bundle likely abstracts CRUD operations for a Prestasi entity. Use FOSRestBundle annotations to define routes:
use FOS\RestBundle\Controller\Annotations\Route;
use FOS\RestBundle\Controller\Annotations\NamePrefix;
/**
* @NamePrefix("prestasi_")
*/
class PrestasiController extends FOS\RestBundle\Controller\FOSRestController
{
/**
* @Route("/prestasi", name="get_prestasi")
*/
public function getPrestasiAction()
{
// Fetch and return Prestasi entities
}
}
Serialization:
Leverage JMSSerializerBundle for custom serialization:
# app/config/config.yml
jms_serializer:
metadata:
directories:
AisPrestasiBundle:
namespace_prefix: "Ais\\PrestasiBundle\\Serializer"
path: "%kernel.root_dir%/../vendor/ais/prestasibundle/Resources/config/serializer"
API Documentation:
Use NelmioApiDocBundle to auto-generate Swagger docs. Annotate controllers:
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
/**
* @ApiDoc(
* resource=true,
* description="List all Prestasi"
* )
*/
public function getPrestasiAction()
Integration with Doctrine:
Extend the Prestasi entity (likely in Ais\PrestasiBundle\Entity\Prestasi) and use Doctrine repositories for complex queries:
$prestasi = $this->getDoctrine()
->getRepository('AisPrestasiBundle:Prestasi')
->findBy(['user' => $userId]);
Symfony Version Mismatch: The bundle targets Symfony 2.7.4. Ensure your project matches this version or fork the bundle for compatibility with Symfony 4/5/6.
symfony/symfony:2.7.* in composer.json or override dependencies.Missing Dependencies:
The bundle requires NelmioApiDocBundle, FOSRestBundle, and JMSSerializerBundle. Forgetting to install these will break routing/API docs.
composer require nelmio/api-doc-bundle fos/rest-bundle jms/serializer-bundle.Route Conflicts:
The prefix: /api in routing.yml may clash with other bundles. Use unique prefixes or namespaces.
prefix or use route namespacing:
ais_prestasi:
resource: "@AisPrestasiBundle/Resources/config/routes.yml"
type: rest
prefix: /v1/prestasi
Dev-Master Instability:
The bundle is in dev-master. Expect breaking changes or missing features.
composer.json.Check API Docs:
If endpoints aren’t visible in /api/doc, verify:
NelmioApiDocBundle is registered.@ApiDoc or @Route annotations.app/logs/dev.log).Doctrine Migrations: The bundle may include migrations. Run:
php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate
Serialization Issues: If responses are malformed, validate:
JMSSerializerBundle is configured in config.yml.@SerializedName or @Type.Custom Entities:
Extend the Prestasi entity by creating a child class:
namespace AppBundle\Entity;
use Ais\PrestasiBundle\Entity\Prestasi as BasePrestasi;
class CustomPrestasi extends BasePrestasi
{
// Add custom fields/methods
}
Event Listeners:
Hook into bundle events (e.g., prestasi.pre_save) via Symfony’s event dispatcher:
$dispatcher->addListener('prestasi.pre_save', function ($event) {
$prestasi = $event->getPrestasi();
// Modify $prestasi before save
});
Override Templates: Override bundle templates by copying files from:
vendor/ais/prestasibundle/Resources/views/
to:
app/Resources/AisPrestasiBundle/views/
Add New Routes:
Extend routes.yml in your bundle or create a custom route file:
# app/config/routing.yml
app_prestasi_custom:
resource: "@AppBundle/Resources/config/routing/prestasi.yml"
prefix: /api
How can I help you explore Laravel packages today?