Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sdk Symfony Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    
  2. 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.

  3. First Use Case: Autowire Astroway in a controller or service:

    use Astroway\Astroway;
    
    final class ChartController {
        public function __construct(private readonly Astroway $astroway) {}
    }
    

Implementation Patterns

Core Workflow

  1. Dependency Injection (DI):

    • The bundle registers Astroway\Astroway as a public service, enabling autowiring in controllers, services, or command classes.
    • Example:
      #[Route('/predict', name: 'predict')]
      public function predict(Request $request, Astroway $astroway) {
          $result = $astroway->predict()->run($request->request->all());
          return $this->json($result);
      }
      
  2. Configuration-Driven Initialization:

    • All SDK behavior (e.g., base_url, timeout) is controlled via astroway.yaml.
    • Override defaults per environment (e.g., staging vs. production) by extending the config:
      # config/packages/astroway_prod.yaml
      astroway:
          timeout: 60.0
      
  3. Service Decoration (Future-Proofing):

    • Tag services for decoration (planned in 0.1.0-alpha.2+):
      services:
          App\Service\CustomAstrowayDecorator:
              tags: ['astroway.namespace']
      
    • Decorate the Astroway service to extend functionality (e.g., logging, caching).
  4. Environment-Specific Config:

    • Use Symfony’s %kernel.environment% to switch configs:
      astroway:
          base_url: '%env(ASTROWAY_BASE_URL_%kernel.environment%)%'
      
    • Define in .env:
      ASTROWAY_BASE_URL_dev=https://dev.astroway.info/v1
      ASTROWAY_BASE_URL_prod=https://api.astroway.info/v1
      
  5. Integration with Symfony Components:

    • HttpClient: Use the SDK’s HTTP client alongside Symfony’s HttpClient for unified request handling.
    • Messenger: Queue Astroway API calls as async messages:
      $message = new AstrowayPredictMessage($data);
      $this->messageBus->dispatch($message);
      

Gotchas and Tips

Pitfalls

  1. Missing api_key:

    • The bundle requires api_key in astroway.yaml. Omitting it throws a ConfigurationException.
    • Fix: Always validate .env.local contains ASTROWAY_API_KEY.
  2. Symfony Version Mismatch:

    • The bundle targets Symfony 6.4+. Using older versions may break DI registration.
    • Fix: Pin Symfony to ^6.4 or ^7.0 in composer.json.
  3. Circular Dependencies:

    • If Astroway is injected into a service that’s also a dependency of Astroway (e.g., custom decorators), Symfony’s compiler may fail.
    • Fix: Use lazy-loading or split logic into separate services.
  4. API Rate Limits:

    • The SDK’s timeout config doesn’t handle rate limits. Monitor responses for 429 errors.
    • Tip: Implement a retry decorator (e.g., using Symfony\Contracts\HttpClient\RetryStrategy).

Debugging

  1. Service Not Autowired:

    • Verify the bundle is loaded (check config/bundles.php).
    • Debug: Run php bin/console debug:container Astroway\Astroway to confirm the service exists.
  2. Configuration Overrides:

    • Use php bin/console debug:config astroway to inspect merged config.
    • Tip: Clear cache (php bin/console cache:clear) after config changes.
  3. HTTP Errors:

    • Enable Symfony’s HttpClient debug mode:
      framework:
          http_client:
              debug: true
      
    • Log SDK responses for debugging:
      $astroway->getClient()->setOptions(['debug' => true]);
      

Extension Points

  1. Custom Decorators:

    • Extend 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;
                  }
              };
          }
      }
      
    • Tag it for future compiler-pass integration (post 0.1.0-alpha.2).
  2. Profiler Integration (Planned):

    • Subscribe to the AstrowayDataCollector (available in 0.1.0-beta.1) to log API calls in the Symfony Profiler toolbar:
      $collector = new AstrowayDataCollector($astroway);
      $collector->collect($request);
      
  3. Console Commands (Planned):

    • Use astroway:health (post 0.1.0-rc.1) to validate API connectivity:
      php bin/console astroway:health
      

Configuration Quirks

  1. Default Values:

    • base_url, timeout, and auth_scheme use sensible defaults but can be overridden.
    • Example override:
      astroway:
          auth_scheme: bearer  # Defaults to 'header'
      
  2. Environment Variables:

    • Use %env(ASTROWAY_*)% for dynamic values (e.g., base_url per environment).
    • Tip: Validate .env files with symfony/flex or a custom validator.
  3. Namespace Conflicts:

    • If Astroway\Astroway conflicts with another service, rename it in services.yaml:
      services:
          Astroway\Astroway:
              alias: app.astroway
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme