PHP code example of bildvitta / iss-sdk

1. Go to this page and download the library: Download bildvitta/iss-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bildvitta / iss-sdk example snippets


return [
    'base_uri' => env('MS_HUB_BASE_URI', 'https://api-dev-hub.nave.dev'),

    'front_uri' => env('MS_HUB_FRONT_URI', 'https://develop.hub.nave.dev'),

    'prefix' => env('MS_HUB_API_PREFIX', '/api'),

    'model_user' => '\App\Entities\User',

    'model_company' => '\BildVitta\Hub\Entities\HubCompany::class',

    'programatic_access' => [
        'client_id' => env('HUB_PROGRAMMATIC_CLIENT'),
        'client_secret' => env('HUB_PROGRAMMATIC_SECRET')
    ],

    'oauth' => [
        'client_id' => env('HUB_CLIENT_ID', ''),
        'client_secret' => env('HUB_CLIENT_SECRET', ''),
        'redirect' => env('HUB_REDIRECT_URI', ''),
        'scopes' => env('HUB_SCOPE', 'profile'),

        'authorize_uri' => '/auth/authorize',
        'token_uri' => '/oauth/token',
        'userinfo_uri' => '/users/me'
    ]
];

// config/permission.php

return [
    'models' = [
        'permission' => \BildVitta\Hub\Entities\HubPermission::class,
        'role' => \BildVitta\Hub\Entities\HubRole::class,
    ]
];

// \App\Models\User

use BildVitta\Hub\Traits\User\HasCompanyLinks;

class User extends Authenticatable
{
    use HasCompanyLinks;
    ...
}

$response = Hub::setToken('jwt')->auth()->permissions();

$response->body(); // string;
$response->json(); // array|mixed;
$response->collect(); // Illuminate\Support\Collection;
$response->status(); // int;
$response->ok(); // bool;
$response->successful(); // bool;
$response->failed(); // bool;
$response->serverError(); // bool;
$response->clientError(); // bool;
$response->header('content-type'); // string;
$response->headers(); // array;

$token = 'jwt';

$hub = app('hub', [$token]); // instance 2
$hub = app('hub')->setToken($token); // instance 1
$hub = new \BildVitta\Hub\Hub($token); // instance 3
$hub = (new \BildVitta\Hub\Hub())->setToken($token); // instance 4
$hub = BildVitta\Hub\Facades\Hub::setToken($token); // instance 1


Route::middleware('hub.auth')->get('/users/me', function () {
    return auth()->user()->toArray();
});

try {
    Hub::auth()->check('jwt');
} catch (RequestException $requestException) {
    throw new Exception('invalid token');
}

try {
    $permissions = Hub::setToken('jwt')->auth()->permissions()['results']; // Implements `ArrayAccess`
    
    foreach ($permissions as $permission) {
        #TODO
    }
} catch (RequestException $requestException) {
    #TODO
}

use BildVitta\Hub\Scopes\PermissionScope;

$query = RealEstateDevelopment::query();
$query->withGlobalScope('permission', new PermissionScope('real_estate_developments.show'));

$count = $query->count();
$query->pagination();

return (new RealEstateDevelopmentResource('index', $query->get()))->count($count);

use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('notifications.{uuid}', function ($user, $uuid) {
    return (string) $user->uuid === (string) $uuid;
});

Broadcast::routes([
    'middleware' => ['hub.check'],
    'prefix' => 'api',
]);
bash
php artisan hub:install