-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,44 @@ | ||
# jsconnect-php | ||
Vanilla Forums jsConnect for PHP, rebuilt for Composer | ||
# Vanilla Forums jsConnect for Composer | ||
|
||
Rebuild of the official [jsConnect PHP library](https://github.com/vanilla/jsConnectPHP) for Vanilla Forums. PSR compliant and easily installable through Composer. | ||
|
||
## Installation | ||
Add the composer dependency: | ||
```bash | ||
composer require hansadema/jsconnect | ||
``` | ||
|
||
## Usage | ||
The example below shows a standard use case for a logged in user. | ||
|
||
```php | ||
<?php | ||
|
||
require_once '../vendor/autoload.php'; | ||
|
||
// Setup a Jsconnect instance | ||
$jsConnect = new \HansAdema\JsConnect\JsConnect('YOUR CLIENT ID', 'YOUR CLIENT SECRET'); | ||
|
||
// Build a user object | ||
$user = new \HansAdema\JsConnect\User([ | ||
'id' => 1234, | ||
'name' => 'Example User', | ||
'email' => '[email protected]', | ||
'photoUrl' => 'http://example.com/user.jpg', | ||
'roles' => ['member', 'administrator'], | ||
]); | ||
|
||
// Try to build the response | ||
$response = $jsConnect->buildResponse($user, $_GET); | ||
|
||
// Return the JSONP result | ||
echo $_GET['callback'].'('.json_encode($response).')'; | ||
``` | ||
|
||
If the user is not logged in, the user object can be left empty. If there is an error, you can return an error with the response data: | ||
```php | ||
$response = [ | ||
'error' => 'invalid_client', | ||
'message' => 'Your Custom Error Message', | ||
]; | ||
``` |