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

Platformsh Client Php Bundle Laravel Package

danielpanzella/platformsh-client-php-bundle

Symfony bundle that registers the Platform.sh PHP API client as a service. Configure API token and token type in YAML, then fetch the PlatformClient from the container or inject it via Symfony 3.3+ autowiring.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle Add the package via Composer:

    composer require danielpanzella/platformsh-client-php-bundle
    

    Enable the bundle in config/bundles.php:

    return [
        // ...
        DanielPanzella\PlatformshClientBundle\PlatformshClientBundle::class => ['all' => true],
    ];
    
  2. Configure API Credentials Add your Platform.sh API token to config/packages/platform_client.yaml:

    platform_client:
        api_token: "%env(PLATFORM_API_TOKEN)%"  # Use env vars for security
        api_token_type: "project"              # or "user" if applicable
    
  3. First Use Case: Fetch Project Info Inject the client in a service/controller:

    use Platformsh\Client\PlatformClient;
    
    class MyService {
        public function __construct(PlatformClient $platformClient) {
            $this->platformClient = $platformClient;
        }
    
        public function getProjectDetails() {
            $project = $this->platformClient->getProject();
            return $project->getName(); // e.g., "my-project"
        }
    }
    

Implementation Patterns

Common Workflows

  1. Environment Management List environments and their URLs:

    $environments = $this->platformClient->getEnvironments();
    foreach ($environments as $env) {
        echo $env->getId() . ": " . $env->getUrl() . "\n";
    }
    
  2. Branch/Environment Sync Trigger a build for a specific branch:

    $branch = $this->platformClient->getBranch('main');
    $branch->triggerBuild();
    
  3. Service Communication Get service details (e.g., database credentials):

    $services = $this->platformClient->getServices();
    $dbService = $services->getService('database');
    $credentials = $dbService->getCredentials();
    

Integration Tips

  • Dependency Injection: Prefer constructor injection for testability.
  • Environment Awareness: Use PLATFORM_ENVIRONMENT to conditionally interact with the API (e.g., skip in local dev).
  • Caching: Cache API responses (e.g., project/environment lists) if they rarely change:
    $cacheKey = 'platformsh_project_' . $projectId;
    $project = $this->cache->get($cacheKey) ?: $this->platformClient->getProject($projectId);
    $this->cache->set($cacheKey, $project, 3600); // Cache for 1 hour
    

Gotchas and Tips

Pitfalls

  1. Token Permissions

    • The API token must have project-level access (not just user-level) for most operations.
    • Debug 403 errors by checking token scope in Platform.sh UI under Access Management.
  2. Deprecated Methods

    • The bundle is outdated (last release: 2017). Some PlatformClient methods may not exist in newer platformsh-client-php versions.
    • Workaround: Check the official client docs and adapt calls (e.g., getProject()getProjectById()).
  3. Symfony Version Mismatch

    • The bundle assumes Symfony 3.x. For Symfony 5/6:
      • Use autowire: true in services.yaml for the PlatformClient.
      • Override the bundle’s configuration if needed (e.g., move tokens to services.yaml).
  4. Rate Limiting

    • Platform.sh API has rate limits. Handle Platformsh\Client\Exception\RateLimitExceededException gracefully.

Debugging

  • Enable API Debugging:
    platform_client:
        debug: true  # Logs API requests/responses to `var/log/platformsh.log`
    
  • Validate Responses:
    try {
        $project = $this->platformClient->getProject();
    } catch (\Platformsh\Client\Exception\ApiException $e) {
        // Log $e->getResponse()->getBody()
    }
    

Extension Points

  1. Custom API Clients Extend the bundle to support multiple projects/clients:

    # config/packages/platform_client.yaml
    platform_client:
        clients:
            project1:
                api_token: "%env(PLATFORM_PROJECT1_TOKEN)%"
                api_token_type: "project"
            project2:
                api_token: "%env(PLATFORM_PROJECT2_TOKEN)%"
    

    Then inject Platformsh\Client\PlatformClientInterface and resolve specific clients via the container.

  2. Event Listeners Listen for environment events (e.g., build completion):

    // src/EventListener/PlatformshListener.php
    class PlatformshListener {
        public function onKernelRequest(GetResponseEvent $event) {
            if ($event->isMasterRequest()) {
                $this->platformClient->getWebhook()->listen('build.finished');
            }
        }
    }
    
  3. Testing Mock the PlatformClient in tests:

    $mockClient = $this->createMock(PlatformClient::class);
    $mockClient->method('getProject')->willReturn(new Project('my-project'));
    $this->container->set(PlatformClient::class, $mockClient);
    
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony