PHPackages                             sevaske/discourse - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. sevaske/discourse

ActiveLibrary[Framework](/categories/framework)

sevaske/discourse
=================

Discourse laravel package

1.5.0(7mo ago)0241MITPHPPHP ^7.4||^8.0CI passing

Since Sep 19Pushed 7mo agoCompare

[ Source](https://github.com/sevaske/discourse)[ Packagist](https://packagist.org/packages/sevaske/discourse)[ GitHub Sponsors](https://github.com/sevaske)[ RSS](/packages/sevaske-discourse/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (6)Versions (8)Used By (1)

[![Packagist](https://camo.githubusercontent.com/f40a09d420cea0e2ecfedbdef23711528be4522e400df525080488cee8629f1c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73657661736b652f646973636f757273652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sevaske/discourse)[![PHPUnit](https://github.com/sevaske/discourse/actions/workflows/tests.yml/badge.svg)](https://github.com/sevaske/discourse/actions/workflows/tests.yml)[![PHPStan](https://github.com/sevaske/discourse/actions/workflows/phpstan.yml/badge.svg)](https://github.com/sevaske/discourse/actions/workflows/phpstan.yml)

Discourse PHP SDK (Unofficial)
==============================

[](#discourse-php-sdk-unofficial)

This is an **unofficial SDK** for interacting with the [Discourse API](https://docs.discourse.org/) &amp; [Discourse Connect (SSO)](https://meta.discourse.org/t/setup-discourseconnect-official-single-sign-on-for-discourse-sso/13045) in PHP.
It provides a clean, PSR-compliant abstraction on top of the Discourse API, so you can interact with your forum programmatically in a structured way.

Requirements
------------

[](#requirements)

- PHP ^7.4 || ^8.0
- PSR-18 HTTP Client (`psr/http-client`)
- PSR-17 HTTP Factories (`psr/http-factory`, `psr/http-message`)
- A PSR-compliant HTTP implementation such as:
    - [Guzzle](https://github.com/guzzle/guzzle)
    - [Symfony HttpClient](https://symfony.com/doc/current/http_client.html)
    - [HTTPlug](https://github.com/php-http/httplug)

Notes
-----

[](#notes)

- This library is **not an official Discourse SDK**.
- It’s intended to provide a strongly typed, PSR-compliant abstraction that can be used in Laravel, Symfony, or plain PHP projects.

Installation
------------

[](#installation)

Install via Composer:

```
composer require sevaske/discourse
```

Usage
-----

[](#usage)

### API

[](#api)

```
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use Sevaske\Discourse\Services\Api;

$discourseUrl = 'https://meta.discourse.com'; // your forum url
$discourseApiKey = 'your-api-key';
$discourseApiUsername = 'your-username';

$httpFactory = new HttpFactory();
$client = new Client([
    'base_uri' => $discourseUrl,
    'headers' => [
        'Api-Key' => $discourseApiKey,
        'Api-Username' => $discourseApiUsername,
    ],
]);

$api = new Api($client, $httpFactory, $httpFactory);

// for examole, invites
$response = $api->invites()->create('some@email.com');
$response->getHttpStatusCode(); // 200
$response->link || $response['link']; // meta.discourse.com/invites/qwerty

// make custom request
$response = $api->request('GET', '/categories.json', [
    'include_subcategories' => true,
]);
```

#### API References

[](#api-references)

###### Badges

[](#badges)

```
$api->badges()->list();
$api->badges()->create(string $name, int $badgeTypeId);
$api->badges()->update(int $id, string $name, int $badgeTypeId);
$api->badges()->delete(int $id);
```

###### Categories

[](#categories)

```
$api->categories()->list(?bool $includeSubcategories = null);
$api->categories()->get(int $id);
$api->categories()->create(string $name, array $extra = []);
$api->categories()->update(int $id, string $name, array $extra = []);
```

###### Groups

[](#groups)

```
$api->groups()->list();
$api->groups()->get(int|string $nameOrId, bool $byId = true);
$api->groups()->create(string $name, array $extra = []);
$api->groups()->update(int $id, string $name, array $extra = []);
$api->groups()->delete(int $id);

$api->groups()->getMembers(int $groupId);
$api->groups()->addMembers(int $groupId, array $usernames);
$api->groups()->removeMembers(int $groupId, array $usernames);
```

###### Invites

[](#invites)

```
$api->invites()->create(
    string $email,
    bool $skipEmail = false,
    ?string $customMessage = null,
    ?int $maxRedemptionsAllowed = 1,
    ?int $topicId = null,
    ?string $groupIds = null,
    ?string $groupNames = null,
    ?string $expiresAt = null
);
```

##### Notifications

[](#notifications)

```
$api->notifications()->list();
$api->notifications()->read(?int $id); // null to read all
```

##### Posts

[](#posts)

```
$api->posts()->latest(?int $before = null);
$api->posts()->get(int $id);
$api->posts()->create(array $data);
$api->posts()->update(int $id, string $raw, ?string $editReason = null);
$api->posts()->delete(int $id);

$api->posts()->lock(int $id);
$api->posts()->unlock(int $id);

$api->posts()->replies(int $id);
$api->posts()->action(int $postId, int $postActionTypeId, ?bool $flagTopic = null);
```

##### Users

[](#users)

```
$api->users()->list(
    ?string $flag = null,   // "active", "new", "staff", "suspended", "blocked", "suspect"
    ?string $order = null,
    ?bool $asc = null,
    ?int $page = null,
    ?bool $showEmails = null,
    ?bool $stats = null,
    ?string $email = null,
    ?string $ip = null
);

$api->users()->getById(int $id);
$api->users()->getByUsername(string $username);
$api->users()->getByExternalId(string $externalId);

$api->users()->create(string $name, string $email, string $password, string $username, array $extra = []);
$api->users()->update(string $username, string $name, array $extra);
$api->users()->delete(int $id, ?bool $deletePosts = null, ?bool $blockEmail = null, ?bool $blockUrls = null, ?bool $blockIp = null);

$api->users()->activate(int $id);
$api->users()->deactivate(int $id);
$api->users()->logout(int $id);

$api->users()->changePassword(string $token, string $username, string $password);
$api->users()->sendPasswordResetEmail(string $login);

$api->users()->badges(string $username);
```

##### Site

[](#site)

```
$api->site()->info();
$api->site()->basicInfo();
```

#### Extending with Macros

[](#extending-with-macros)

This SDK uses a **`Macroable` trait** (inspired by Laravel), which allows you to add new methods to the `Api` class at runtime.

### Example: Simple Macro

[](#example-simple-macro)

```
use Sevaske\Discourse\Services\Api;

Api::macro('ping', function () {
    return 'pong';
});

$api = new Api($client, $httpFactory, $httpFactory);
$api->ping(); // "pong"
```

### Connect (SSO)

[](#connect-sso)

Discourse sends a signed payload to your endpoint with `sso` and `sig`. Build and sign the response payload and redirect back to discourse.

##### Notice

[](#notice)

You should **always validate the signature** before using the payload.

```
use Sevaske\Discourse\Exceptions\InvalidRequestSignature;
use Sevaske\Discourse\Services\Signer;
use Sevaske\Discourse\Services\Connect\RequestPayload;
use Sevaske\Discourse\Services\Connect\ResponsePayload;

$signer = new Signer('your-discourse-secret');

$sso = $_GET['sso'] ?? '';
$sig = $_GET['sig'] ?? '';

if (! $signer->validate($sig, $sso)) {
    throw new InvalidRequestSignature;
}

$request = new RequestPayload($sso);
$response = (new ResponsePayload($signer))->build(
    $request->nonce(),
    'my-user-id',
    'myemail@mywebsite.com',
    [ // optional params
        'name' => 'Naruto Uzumaki',
    ]
);

$redirectUrl = $request->buildReturnUrl($response);
```

Running Tests
-------------

[](#running-tests)

This library uses **PHPUnit** for testing.
You can run tests via Composer:

```
composer test
```

Also, you can run **stan**

```
composer stan
```

License
-------

[](#license)

MIT License

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance63

Regular maintenance activity

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

7

Last Release

235d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/94643c38672a39a9b675ab6d43f5c1d3c0789300cc052f742a960e0a7d70847e?d=identicon)[sevaske](/maintainers/sevaske)

---

Top Contributors

[![sevaske](https://avatars.githubusercontent.com/u/42838184?v=4)](https://github.com/sevaske "sevaske (26 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sevaske-discourse/health.svg)

```
[![Health](https://phpackages.com/badges/sevaske-discourse/health.svg)](https://phpackages.com/packages/sevaske-discourse)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

81733.7k](/packages/flow-php-flow)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6939.5M343](/packages/drupal-core-recommended)[cakephp/authentication

Authentication plugin for CakePHP

1153.6M67](/packages/cakephp-authentication)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
