1. Go to this page and download the library: Download aaron-lin/app-php 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/ */
aaron-lin / app-php example snippets
use Lin\AppPhp\Server\App;
use Lin\AppPhp\Server\RestfulApp;
use Lin\AppPhp\Authorization\AuthorizationInterface;
// 實作 AuthorizationInterface
class Authorization implements AuthorizationInterface
{
public function Authorize($Token, $RequestScopes = []): bool
{
$AvailableScopes = ['user.read', 'user.create'];
$AccessScopes = array_intersect($RequestScopes, $AvailableScopes);
if (count($RequestScopes) > 0 && count($AccessScopes) === 0) {
return false;
}
return true;
}
}
class User extends RestfulApp
{
public function OnGet()
{
// 檢查權限: 呼叫 App::AuthorizeRequest
if (!$this->AuthorizeRequest(['user.read'])) {
return App::UnauthorizedResponse();
}
// 回應
return App::NoContentResponse();
}
}
// 處理請求
$App = new User();
$App->WithAuthorization(new Authorization())->HandleRequest(App::CreateServerRequest());
$App->SendResponse();
exit;
use Lin\AppPhp\Server\App;
use Lin\AppPhp\Server\RestfulApp;
use Lin\AppPhp\Authorization\AuthorizationInterface;
// 實作 AuthorizationInterface
class Authorization extends OAuthAuthorization
{
public function IsTokenRevoked($JTI)
{
// 檢查 token 是否被撤銷
return false;
}
}
class User extends RestfulApp
{
public function OnGet()
{
// 檢查權限: 呼叫 App::AuthorizeRequest
if (!$this->AuthorizeRequest(['user.read'])) {
return App::UnauthorizedResponse();
}
// 回應
return App::NoContentResponse();
}
}
// 處理請求
$PublicKeyPath = '/var/www/pubkeys/oauth_pub';
$App = new User();
$App->WithAuthorization(new Authorization($PublicKeyPath))->HandleRequest(App::CreateServerRequest());
$App->SendResponse();
exit;
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.