astroway/sdk-symfony
Official Symfony bundle for astroway/sdk. Provides DI registration and an autowireable Astroway service with standard Symfony configuration via astroway.yaml (API key, base URL, timeout, auth scheme). Works with Symfony Flex or manual bundle registration.
Install the package:
composer require astroway/sdk-symfony
The bundle auto-registers via Symfony Flex. If using manual bundle registration, add to config/bundles.php:
Astroway\Symfony\AstrowayBundle::class => ['all' => true],
Configure via astroway.yaml:
Create config/packages/astroway.yaml:
astroway:
api_key: '%env(ASTROWAY_API_KEY)%'
base_url: 'https://api.astroway.info/v1' # Optional
timeout: 30.0 # Optional (seconds)
auth_scheme: header # Optional (header|bearer)
Set ASTROWAY_API_KEY in .env.local.
First Use Case:
Autowire Astroway in a controller or service:
use Astroway\Astroway;
final class ChartController {
public function __construct(private readonly Astroway $astroway) {}
}
Dependency Injection (DI):
Astroway\Astroway as a public service, enabling autowiring in controllers, services, or command classes.#[Route('/predict', name: 'predict')]
public function predict(Request $request, Astroway $astroway) {
$result = $astroway->predict()->run($request->request->all());
return $this->json($result);
}
Configuration-Driven Initialization:
base_url, timeout) is controlled via astroway.yaml.# config/packages/astroway_prod.yaml
astroway:
timeout: 60.0
Service Decoration (Future-Proofing):
0.1.0-alpha.2+):
services:
App\Service\CustomAstrowayDecorator:
tags: ['astroway.namespace']
Astroway service to extend functionality (e.g., logging, caching).Environment-Specific Config:
%kernel.environment% to switch configs:
astroway:
base_url: '%env(ASTROWAY_BASE_URL_%kernel.environment%)%'
.env:
ASTROWAY_BASE_URL_dev=https://dev.astroway.info/v1
ASTROWAY_BASE_URL_prod=https://api.astroway.info/v1
Integration with Symfony Components:
HttpClient for unified request handling.$message = new AstrowayPredictMessage($data);
$this->messageBus->dispatch($message);
Missing api_key:
api_key in astroway.yaml. Omitting it throws a ConfigurationException..env.local contains ASTROWAY_API_KEY.Symfony Version Mismatch:
^6.4 or ^7.0 in composer.json.Circular Dependencies:
Astroway is injected into a service that’s also a dependency of Astroway (e.g., custom decorators), Symfony’s compiler may fail.API Rate Limits:
timeout config doesn’t handle rate limits. Monitor responses for 429 errors.Symfony\Contracts\HttpClient\RetryStrategy).Service Not Autowired:
config/bundles.php).php bin/console debug:container Astroway\Astroway to confirm the service exists.Configuration Overrides:
php bin/console debug:config astroway to inspect merged config.php bin/console cache:clear) after config changes.HTTP Errors:
HttpClient debug mode:
framework:
http_client:
debug: true
$astroway->getClient()->setOptions(['debug' => true]);
Custom Decorators:
Astroway by creating a decorator service:
class CachedAstrowayDecorator implements AstrowayDecoratorInterface {
public function decorate(Astroway $astroway): Astroway {
return new class($astroway) extends Astroway {
public function predict(array $data): array {
$cacheKey = md5(serialize($data));
if ($cached = $this->cache->get($cacheKey)) {
return $cached;
}
$result = parent::predict($data);
$this->cache->set($cacheKey, $result, 3600);
return $result;
}
};
}
}
0.1.0-alpha.2).Profiler Integration (Planned):
AstrowayDataCollector (available in 0.1.0-beta.1) to log API calls in the Symfony Profiler toolbar:
$collector = new AstrowayDataCollector($astroway);
$collector->collect($request);
Console Commands (Planned):
astroway:health (post 0.1.0-rc.1) to validate API connectivity:
php bin/console astroway:health
Default Values:
base_url, timeout, and auth_scheme use sensible defaults but can be overridden.astroway:
auth_scheme: bearer # Defaults to 'header'
Environment Variables:
%env(ASTROWAY_*)% for dynamic values (e.g., base_url per environment)..env files with symfony/flex or a custom validator.Namespace Conflicts:
Astroway\Astroway conflicts with another service, rename it in services.yaml:
services:
Astroway\Astroway:
alias: app.astroway
How can I help you explore Laravel packages today?