Download the PHP package hampel/binarylane-api-laravel without Composer

On this page you can find all versions of the php package hampel/binarylane-api-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package binarylane-api-laravel

BinaryLane API for Laravel

Tests Latest Version on Packagist Total Downloads Open Issues License

By Simon Hampel

Laravel integration for hampel/binarylane-api — a service provider, a manager for named accounts, a facade, and a queued job that waits for BinaryLane's actions to finish.

Three things it adds that an application would otherwise write for itself:

The request building, status mapping and exception hierarchy are the core package's, untouched: a 401 and a 404 stay different exceptions rather than both becoming an unsuccessful response.

Requirements

PHP 8.3 or later, and Laravel 12 or 13.

Laravel Zero works too, with the HTTP component installed (php <app> app:install http). Laravel binds Illuminate\Http\Client\Factory as a singleton in FoundationServiceProvider, which a Laravel Zero application does not register; unbound, Http::fake() silently fails to intercept and the request reaches the real API. This package binds one when nothing else has, so the behaviour is the same on both.

AwaitAction needs illuminate/queue and illuminate/bus, which are not installed with this package. A Laravel application has both already. In Laravel Zero, php <app> app:install queue adds them; without them the job class cannot be loaded, and everything else works.

Installation

In a Laravel application the provider and the BinaryLane alias are discovered automatically. Publish the config file if you want to edit it:

Laravel Zero does not run package discovery, so there the provider has to be listed by hand, in config/app.php:

The global BinaryLane alias is not registered either. Import the facade class — use Hampel\BinaryLane\Api\Laravel\Facades\BinaryLane; — or inject BinaryLaneManager.

vendor:publish --tag=binarylane-config works in Laravel Zero once the provider is listed, though list does not show it: Laravel Zero hides the command rather than removing it. Before the provider is listed it answers that there is nothing to publish.

Configuration

An account needs a token and nothing else — there is one BinaryLane, so there is no URL to configure.

A BinaryLane token can do everything its account can do. There is one kind of token: no scopes, no expiry, no read-only variant. A token configured for a dashboard that only lists servers can also cancel them. Keep it out of anything that does not need it.

The shipped config/binarylane.php defines one account called main. Add more by naming them:

An account with no token is refused when its client is built, rather than allowed to reach the API and come back 401 — which would read as a revoked token rather than as an unset environment variable. An empty string counts as no token. It raises Hampel\BinaryLane\Api\Laravel\Exception\InvalidConfiguration, which extends the core package's BinaryLaneException.

An application config file named binarylane.php replaces these settings key by key. Laravel merges a package's configuration shallowly, and the application's file wins for every top-level key it defines. So an application that already keeps its own settings in config/binarylane.php — a timeout meaning something else, say — silently changes this package's settings of the same name, with no error from either. Publish this file and edit it, or name your own settings file something else.

Page size and base URI describe the API, not an account

Both are shared by every account's client and validated when the first client is built. A per_page of 0 is refused, although the API accepts it: it asks for a total and no items, which as a default would make every list come back empty. base_uri exists for a recorded fixture served locally and for an outbound proxy that terminates the connection.

Transport

Applied to every request, alongside any Http::globalRequestMiddleware() the application has configured and the transport settings from Http::globalOptions() — a proxy, a CA bundle or client certificate, the protocol version, curl options. Global options that would change the request itself are not applied: headers, auth, query and the body options would overwrite what the core package built, including its Authorization header. These timeouts bound one request, not the work it starts — how long to wait for an action is AwaitAction's timeout.

Usage

The facade reaches the default account directly:

Name an account to reach another:

It is client() and not account(). BinaryLane::account() is the core package's account endpoint — GET /v2/account — and the manager forwards unknown calls to the default client, so a method on both would mean different things depending on which class you thought you were calling.

Everything past that point is the core package — see its documentation for the endpoints, entities, pagination, server creation and the complete-or-error pattern of question-shaped actions.

Inject the manager where a facade is not wanted:

Waiting for actions

A server action returns a receipt, not a result. Powering a server on, resizing it, rebuilding it and creating it all answer with an action that has not finished yet. The core package's actions()->await() polls until it does, which blocks — right in a console command, wrong in a web request, where a server build would hold the request open for minutes.

AwaitAction is that wait on the queue:

Check for null. Every server action may answer with a bodiless 202 and no action to wait on. The job takes an action or an id and nothing else, and an id below 1 is refused when it is constructed — in the request that dispatched it, rather than later in a worker's log.

A server build names its actions rather than returning one:

The constructor takes the action or its id, then optionally the account name, a timeout and a polling interval:

argument default meaning
account the default account which configured account the action belongs to
timeout 3600 seconds from dispatch to give up, time in the queue included
interval 10 seconds between polls; at most 900 on Amazon SQS

How it ends is an event

when the action the job fires and
completed ActionCompleted succeeds
errored ActionFailed succeeds — an errored action stays errored, so there is nothing to retry
is waiting on a question or an unpaid invoice ActionBlocked succeeds — neither resolves by waiting
was still running at the deadline ActionTimedOut succeeds — nothing was cancelled

All four live in Hampel\BinaryLane\Api\Laravel\Events, and each carries the account name and the action as last seen; ActionTimedOut also carries waited, in seconds. Listen for the ones you care about:

The events share no parent class, deliberately. Laravel matches a listener by class and by interface, never by parent class, so a listener on a common base would hear nothing.

When it cannot find out, it retries or fails

A poll that failed in a way the next one may not repeat is retried until the deadline — a 5xx, a 429, a transport failure, a malformed response, or an answer about some other action. A 429's Retry-After is honoured when it is longer than the interval. Past the deadline, the job fails.

Anything else fails the job at once, because asking again will not change it: a token that is not valid, an action id that does not exist on the account, an account name no longer in the configuration. A failed job is reported and lands in failed_jobs like any other.

A failed, blocked or timed-out action is also logged at warning, with the account, the action id, its type and the resource it acts on. The events are the structured report; the log line is there so an application that listens for none of them still hears about the outcomes that need a person. A completed action is not logged.

Four things it needs from the queue

It is tagged binarylane and binarylane:action:<id> for Horizon.

Errors

The core package's exceptions arrive untouched:

UnknownAccount, InvalidConfiguration and QueueRequired extend the core package's BinaryLaneException, so an application already catching that catches these too.

Testing

Fake the API with the vocabulary the rest of your suite already uses:

The package's real code path runs; only the socket is replaced. So a faked 404 still arrives as NotFoundException, and a faked 200 whose body is HTML still arrives as MalformedResponseException.

To test your own handling of AwaitAction, call handle() on a job with fake queue interactions, which records releases and failures rather than ignoring them:

Replace the transport entirely by binding binarylane.http_client — how an application with its own outbound HTTP policy makes this package use it:

The package binds that key only if nothing has already, so the override works from any service provider, whether it registers before or after this package's — including AppServiceProvider in a Laravel Zero config/app.php, where it is listed first.

This package does not use a Psr\Http\Client\ClientInterface binding, yours or another package's, and does not bind that key itself. It is one key shared by every package that uses it, so an application with several API integrations installed would otherwise get whichever registered last. To send several packages through one client, bind each package's own key to it.

What Laravel's HTTP events see

RequestSending fires; ResponseReceived and ConnectionFailed do not. Laravel raises the first from inside the handler stack this package sends through, and the other two from a layer above it. So Telescope's HTTP client watcher, which listens for ResponseReceived, will not show this traffic. The core package logs every request at debug through PSR-3, which reaches the application log, and logs nothing above debug: a failure arrives as an exception, and logging it is the catcher's decision. The token is never logged.

Versioning

hampel/binarylane-api is 0.x, so its public API can change in a minor release; this package constrains it at ^0.5 and expects to bump.

License

MIT. See LICENSE.md.


All versions of binarylane-api-laravel with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
guzzlehttp/guzzle Version ^7.8|^8.0
guzzlehttp/psr7 Version ^2.0|^3.0
hampel/binarylane-api Version ^0.3
illuminate/contracts Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1|^2.0
psr/log Version ^1.1|^2.0|^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hampel/binarylane-api-laravel contains the following files

Loading the files please wait ...