1. Go to this page and download the library: Download juklicek/restful 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/ */
namespace ResourcesModule;
use Drahak\Restful\IResource;
use Drahak\Restful\Application\UI\ResourcePresenter;
/**
* SamplePresenter resource
* @package ResourcesModule
* @author Drahomír Hanák
*/
class SamplePresenter extends ResourcePresenter
{
protected $typeMap = array(
'json' => IResource::JSON,
'xml' => IResource::XML
);
/**
* @GET sample[.<type xml|json>]
*/
public function actionContent($type = 'json')
{
$this->resource->title = 'REST API';
$this->resource->subtitle = '';
$this->sendResource($this->typeMap[$type]);
}
/**
* @GET sample/detail
*/
public function actionDetail()
{
$this->resource->message = 'Hello world';
}
}
use Drahak\Restful\Application\Routes\ResourceRoute;
$anyRouteList[] = new ResourceRoute('sample[.<type xml|json>]', 'Resources:Sample:content', ResourceRoute::GET);
/**
* SamplePresenter resource
* @package Restful\Api
* @author Drahomír Hanák
*/
class SamplePresenter extends BasePresenter
{
public function validateCreate()
{
$this->input->field('password')
->addRule(IValidator::MIN_LENGTH, NULL, 3)
->addRule(IValidator::PATTERN, 'Please add at least one number to password', '/.*[0-9].*/');
}
public function actionCreate()
{
// some save data insertion
}
}
namespace Restful\Api;
use Drahak\Restful\Application\UI\ResourcePresenter;
/**
* Base API ErrorPresenter
* @package Restful\Api
* @author Drahomír Hanák
*/
class ErrorPresenter extends ResourcePresenter
{
/**
* Provide error to client
* @param \Exception $exception
*/
public function actionDefault($exception)
{
$this->sendErrorResource($exception);
}
}
use Drahak\Restful\Application\UI\SecuredResourcePresenter
/**
* My secured resource presenter
* @author Drahomír Hanák
*/
class ArticlesPresenter extends SecuredResourcePresenter
{
// all my resources are protected and reachable only for logged user's
// you can also add some Authorizator to check user rights
}
namespace ResourcesModule;
use Drahak\Restful\Security\Process\SecuredAuthentication;
/**
* CRUD resource presenter
* @package ResourcesModule
* @author Drahomír Hanák
*/
class CrudPresenter extends BasePresenter
{
/** @var SecuredAuthentication */
private $securedAuthentication;
/**
* Inject secured authentication process
* @param SecuredAuthentication $auth
*/
public function injectSecuredAuthentication(SecuredAuthentication $auth)
{
$this->securedAuthentication = $auth;
}
protected function startup()
{
parent::startup();
$this->authentication->setAuthProcess($this->securedAuthentication);
}
// your secured resource action
}
namespace Restful\Api;
use Drahak\Restful\IResource;
use Drahak\Restful\Security\Process\AuthenticationProcess;
use Drahak\Restful\Security\Process\OAuth2Authentication;
/**
* CRUD resource presenter
* @package Restful\Api
* @author Drahomír Hanák
*/
class CrudPresenter extends BasePresenter
{
/** @var AuthenticationProcess */
private $authenticationProcess;
/**
* Inject authentication process
* @param OAuth2Authentication $auth
*/
public function injectSecuredAuthentication(OAuth2Authentication $auth)
{
$this->authenticationProcess = $auth;
}
/**
* Check presenter
yaml
php:
zlib.output_compression: yes
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.