Installation Add the package via Composer:
composer require avris/suml-symfony
Register the bundle in config/bundles.php (Symfony 4+):
return [
// ...
Avris\SUML\SUMLBundle::class => ['all' => true],
];
Configuration
Publish the default config (if needed) and adjust config/packages/avris_suml.yaml:
avris_suml:
api_key: '%env(SUML_API_KEY)%'
base_uri: 'https://api.suml.ai'
debug: '%kernel.debug%'
First Use Case: Fetching a SUML Model
Inject the SUMLClient service and call a basic method:
use Avris\SUML\Client\SUMLClient;
class MyController extends AbstractController
{
public function __construct(private SUMLClient $sumlClient) {}
public function index()
{
$model = $this->sumlClient->getModel('user');
return $this->json($model);
}
}
Model Management
getModel($name) to retrieve SUML models (e.g., user, product).createModel($name, $attributes).updateModel($id, $attributes) with the model ID and updated data.Querying Data
filterBy($field, $value) before fetching:
$this->sumlClient->getModels('user')->filterBy('role', 'admin')->all();
limit($limit) and offset($offset) for large datasets.Webhook Integration
/suml/webhook):
$this->sumlClient->handleWebhook($request);
validateWebhook($payload).Event Listeners
suml.model.created) in EventSubscriber:
public static function getSubscribedEvents()
{
return [
SUMLEvents::MODEL_CREATED => 'onModelCreated',
];
}
ModelType for CRUD operations.ApiResource to expose SUML models as API endpoints.#[ORM\Entity]
class User
{
#[ORM\Id]
private ?string $sumlId;
// ...
}
API Key Management
api_key in config violates security best practices. Always use environment variables (%env(SUML_API_KEY)%).Rate Limiting
$this->sumlClient->getModel('user', ['cache' => true]);
$this->sumlClient->setRetryPolicy(new ExponentialBackoffPolicy());
Webhook Idempotency
idempotency_keys in payloads to avoid duplicate processing:
$this->sumlClient->handleWebhook($request, ['idempotency_key' => $request->get('idempotency_key')]);
Model Schema Changes
$model = $this->sumlClient->getModel('user');
if (!$this->sumlClient->validateSchema($model, 'user')) {
throw new \RuntimeException('Schema mismatch');
}
debug: true in config to log API requests/responses.SUMLClient in tests:
$this->mock(SUMLClient::class)
->shouldReceive('getModel')
->andReturn(['id' => 1, 'name' => 'Test']);
404 for missing models). Handle them explicitly:
try {
$model = $this->sumlClient->getModel('nonexistent');
} catch (HttpException $e) {
if ($e->getStatusCode() === 404) {
// Handle missing model
}
}
Custom HTTP Client Override the default Guzzle client by binding your own:
# config/packages/avris_suml.yaml
avris_suml:
http_client: 'your_custom_client_id'
Register the client in services.yaml:
services:
your_custom_client_id:
class: 'GuzzleHttp\Client'
calls:
- ['setBaseUri', ['%env(SUML_BASE_URI)%']]
Event Customization Extend SUML events to trigger custom logic:
$dispatcher->addListener(SUMLEvents::MODEL_UPDATED, function ($event) {
// Send notification or log changes
});
Model Transformers Convert SUML responses to custom DTOs using a transformer:
$transformer = new SUMLModelTransformer();
$userDto = $transformer->transform($this->sumlClient->getModel('user'));
How can I help you explore Laravel packages today?