Installation:
composer require creads/api2symfony-bundle 1.0.*@dev
Register the bundle in AppKernel.php under dev/test environments only.
First Use Case: Generate a controller from a RAML file:
php app/console api2symfony:generate:raml path/to/api.raml Acme\DemoBundle
Output will be cached in app/cache/dev/api2symfony/.
Where to Look First:
app/cache/dev/api2symfony/ (generated controllers).RAML-to-Controller Generation:
app/cache/dev/api2symfony/ with a versioned directory structure.php app/console api2symfony:generate:raml api/raml/posts.raml App\Controller\Api
Outputs to:
app/cache/dev/api2symfony/App/Controller/Api/1_0_1_alpha/PostsController.php
Integration with Symfony Workflow:
dev/test environments (avoids runtime overhead).php bin/console cache:clear) to regenerate.version field in spec) dictates the output directory. Update RAML to trigger regeneration.Extending Functionality:
src/ (Symfony’s autoloader priority).RAML Structure:
#%RAML 0.8
title: YourAPI
version: 1.0.0 # Critical for cache paths
/{id} for resource-specific routes (auto-generates getPost(), putPost(), etc.).Symfony Integration:
@Route or use routing.yml to expose endpoints.Testing:
Environment Restrictions:
dev/test. Accidentally enabling it in prod will break routing (controllers won’t exist in src/).AppKernel.php.Cache Overwriting:
version field in RAML to force regeneration.rm -rf app/cache/dev/api2symfony/
Limited Format Support:
Generated Code Quality:
Namespace Collisions:
Acme\DemoBundl) will fail.composer.json or src/.Command Errors:
APP_DEBUG=1) for detailed command output.Missing Controllers:
mkdir -p app/cache/dev/api2symfony/
chmod -R 775 app/cache/dev/
Routing Issues:
@Route annotations. Add them manually or use Symfony’s routing.yml:
api_posts:
resource: "@Api2SymfonyBundle/Resources/config/routing.yml"
prefix: /api
Custom Templates:
vendor/creads/api2symfony-bundle/Resources/views/ to app/Resources/Api2SymfonyBundle/views/.Post-Generation Hooks:
kernel.request event to modify generated controllers dynamically (e.g., inject services):
// src/EventListener/ApiControllerListener.php
public function onKernelRequest(GetResponseEvent $event) {
if ($event->getRequest()->attributes->has('_controller') &&
strpos($event->getRequest()->attributes->get('_controller'), 'Api2Symfony') !== false) {
// Modify controller logic here
}
}
RAML Preprocessing:
# app/config.yml
api2symfony:
preprocessors:
- App\Preprocessor\AddAuthHeaders
config.yml options. All behavior is driven by the api2symfony:generate:raml command.version in RAML must match the cache directory structure. Use semantic versioning (e.g., 1.0.0-alpha).How can I help you explore Laravel packages today?