PHP code example of kusanagi / katana-sdk-php7

1. Go to this page and download the library: Download kusanagi/katana-sdk-php7 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/ */

    

kusanagi / katana-sdk-php7 example snippets




ice = new \Katana\Sdk\Service();

$service->action('action_name', function (\Katana\Sdk\Action $action) {
    $action->log('Start action');

    return $action;
});

$service->run();



leware = new \Katana\Sdk\Middleware();

$middleware->request(function (\Katana\Sdk\Request $request) {
    $request->log('Start Request');

    return $request;
});

$middleware->response(function (\Katana\Sdk\Response $request) {
    $request->log('Start Response');

    return $request;
});

$middleware->run();



leware = new \Katana\Sdk\Middleware();

$middleware->request(function (\Katana\Sdk\Request $request) {
    $request->setServiceName('service');
    $request->setServiceVersion('1.0.0');
    $request->setActionName('action');

    return $request;
});



leware = new \Katana\Sdk\Middleware();

$middleware->response(function (\Katana\Sdk\Response $response) {
    $httpResponse = $response->getHttpResponse();
    $httpResponse->setBody(
        json_encode(
            $response->getTransport()->getData()
        )
    );
    $httpResponse->setStatus(200, 'OK');

    return $response;
});



ice = new \Katana\Sdk\Service();

$service->action('read', function (\Katana\Sdk\Action $action) {
    $entity = $repository->get($action->getParam('id')->getValue());
    $action->setEntity($entity);

    return $action;
});

$service->action('delete', function (\Katana\Sdk\Action $action) {
    $entity = $repository->delete($action->getParam('id')->getValue());

    return $action;
});

$service->action('create', function (\Katana\Sdk\Action $action) {
    $repository->create(array_map(function (\Katana\Sdk\Param $param) {
        return $param->getValue();
    }, $action->getParams()));

    return $action;
});

$service->action('update', function (\Katana\Sdk\Action $action) {
    $repository->update(array_map(function (\Katana\Sdk\Param $param) {
        return $param->getValue();
    }, $action->getParams()));

    return $action;
});

$service->run();