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

On this page you can find all versions of the php package hampel/xenforo-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 xenforo-api-laravel

XenForo API for Laravel

Tests Latest Version on Packagist Total Downloads Open Issues License

By Simon Hampel

Laravel integration for hampel/xenforo-api — a service provider, a manager for named forums, and a facade.

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

It supplies the transport and nothing else. The core package's request building, status mapping and exception hierarchy are untouched, which is the point: 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 is supported too, with two extra steps covered under Installation. It needs the HTTP component, which an application opts into with php <app> app:install http (that command runs composer require illuminate/http and nothing else).

Installation

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

Laravel Zero

Laravel Zero switches package discovery off, so register the provider yourself in config/app.php:

The XenForo alias comes from the same discovery, so it is not registered either — import Hampel\XenForo\Api\Laravel\Facades\XenForo by its class name. To edit the config, copy vendor/hampel/xenforo-api-laravel/config/xenforo.php into the application's config/.

Registering the provider also closes a gap in Http::fake(). Laravel binds Illuminate\Http\Client\Factory as a singleton in FoundationServiceProvider, which a Laravel Zero application does not register, and the HTTP component installs the classes without binding anything. Unbound, the container builds a fresh factory on every resolution, so the one this package holds is not the one Http::fake() configures, and the fake would miss: the request would go to the real forum. The provider binds a singleton when nothing else has. Without the provider nothing is bound at all, and resolving a client fails with a BindingResolutionException rather than reaching the network.

Configuration

A forum needs a URL. Everything else is optional.

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

Either the board URL or the /api URL is accepted; both are normalised.

Credentials

XenForo accepts three quite different credentials on the same endpoints, and which one you hold changes what you may ask for:

configuration credential what it does
key ApiKey a guest or user key. The key itself decides which user the request acts as.
key + user SuperUserKey a super-user key acting as that user_id. XenForo answers 403 user_id_not_allowed if the key is not a super-user key.
bearer BearerToken an OAuth2 access token. Takes precedence over key.
none Guest XenForo treats a missing key as a guest, so unauthenticated endpoints answer normally and everything else answers 400 no_api_key_in_request.

Two combinations are refused when the client is built, because both otherwise fail somewhere far less obvious:

Both raise Hampel\XenForo\Api\Laravel\Exception\InvalidConfiguration, which extends the core package's XenForoException, so an application already catching that catches misconfiguration too.

bypassPermissions is deliberately not configurable. It belongs to a super-user key and to no other credential, and it is per-call by nature:

Transport

Applied to every request, alongside any Http::globalRequestMiddleware() the application has configured. Http::globalOptions() applies too, but only its transport options: timeouts, TLS verification and client certificates, proxy, protocol version and curl settings. Global headers, query and body options are ignored, because the request is built by the core package and they would overwrite its API key, its query string or its body.

Redirects are not followed — Guzzle's PSR-18 entry point does not follow them, so a 3xx is handed back whole. That is what the two attachment thumbnail endpoints need, since the 301 they answer with is their documented output.

Usage

The facade reaches the default forum directly:

Name a forum to reach another:

Everything past that point is the core package — see its documentation for the endpoints, the entities, pagination, uploads, OAuth2 and how to call an endpoint an add-on added that neither package has heard of.

Inject the manager where a facade is not wanted:

Forums that are not in configuration

When the forum list lives somewhere other than config/xenforo.php — a database table, per-tenant settings, a file read on demand to keep API keys out of the config repository — build a client from an array instead:

The array takes the same keys as an entry under xenforo.forums, and gets the same validation and choice of credential. The client sends through the same transport, so Http::fake() and Http::preventStrayRequests() reach it. Each call builds a new client and nothing is memoised, so keep the one you get.

The transport is bound under the container key xenforo.http_client, with PSR-17 factories beside it, for constructing a Hampel\XenForo\Api\Client directly:

Returning an entity

Entities implement \JsonSerializable and serialise to the forum's own payload, so handing one to a JSON response gives you what the API answered rather than the entity's internals:

Fields the credential is not allowed to see are absent from that payload rather than null, which is the distinction XenForo itself draws — a permission failure and a genuinely empty field are not the same thing, and ApiResponse::has() is how to tell them apart. Add-on fields the specification does not describe survive too.

Errors

The core package's exceptions arrive untouched. Telling them apart is the reason to use it rather than Http:: directly — a client that reports every unsuccessful status the same way cannot tell a rejected credential from a user who is not a member:

Testing

Fake the forum 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 not JSON still arrives as MalformedResponseException.

Three things worth knowing:

Replace the transport entirely by rebinding xenforo.http_client to any PSR-18 client. That is how an application with its own outbound HTTP policy, such as a proxy-aware or SSRF-guarded client that everything must go through, makes this package use it:

The binding can go in any service provider. This package only binds the key if nothing has yet, so the override holds whether its provider registers before or after this one, including in Laravel Zero, where the order is the providers list.

Proxy and CA settings don't need a replacement: set them with Http::globalOptions(), which reaches this package's requests and keeps them visible to Http::fake().

Binding Psr\Http\Client\ClientInterface does not affect this package. That key is shared by every package that binds it, so with two of them installed the last one registered would serve both. The package neither binds that key nor falls back to it. An application that wants all of its API traffic through its own client rebinds each package's own key.

What is not visible

Laravel raises ResponseReceived and ConnectionFailed from a layer above the handler stack, and this package sends through the stack directly, so neither fires — anything listening for them, including Telescope's HTTP client watcher, will not show this traffic. The core package logs every request through PSR-3 instead, which reaches the application log.

RequestSending does fire, because Laravel raises it from inside the stack. A listener that pairs it with either of the other two will see requests announced and never concluded.

Http::assertSent() cannot inspect uploaded files either: Illuminate\Http\Client\Request::hasFile() reads data the framework records when it builds a multipart body itself. Assert on the request's Content-Type and body instead.

What this package will not do

Grow retries or backoff. TooManyRequestsException is typed so an application can retry; which requests are safe to retry is the application's knowledge, not this package's.

License

MIT. See LICENSE.md.


All versions of xenforo-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/xenforo-api Version ^1.1
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.0|^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/xenforo-api-laravel contains the following files

Loading the files please wait ...