PHP code example of mezon / service

1. Go to this page and download the library: Download mezon/service 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/ */

    

mezon / service example snippets


class TodoService extends \Mezon\Service\ServiceBase implements \Mezon\Service\ServiceBaseLogicInterface
{

    /**
     * First endpoint
     */
    public function actionPing()
    {
        return ('I am alive!');
    }
}

\Mezon\Service\Service::start(TodoService::class);

public function actionLongEndpoint()
{
    return ('long endpoint');
}

/**
 * Logic implementation
 *
 * @author Dodonov A.A.
 */
class TodoLogic extends \Mezon\Service\ServiceBaseLogic
{

    /**
     * First endpoint
     */
    public function actionPing()
    {
        return ('I am alive!');
    }
}

/**
 * Service class
 *
 * @author Dodonov A.A.
 */
class TodoService extends \Mezon\Service\ServiceBase
{
}

\Mezon\Service\Service::start(TodoService::class, TodoLogic::class);

\Mezon\Service\Service::start(\Mezon\Service\ServiceBase::class, TodoLogic::class);

\Mezon\Service\Service::start(\Mezon\Service\ServiceBase::class, [
    TodoSystemLogic::class,
    TodoReadLogic::class,
    TodoWriteLogic::class
]);

class CommentLogic extends \Mezon\Service\ServiceBaseLogic
{

    /**
     * Our endpoint
     */
    public function userHeadComment(string $route, array $params)
    {
        return [
            // some data here
        ];
    }
}

[
    'userName' => 'name of the user',
    'articleId' => 'id of the article',
    'headCommentId' => 'comment's id'
]



return [
    [
    	"route" => "/user/[s:userName]/profile/articles/[i:articleId]/comments/[i:headCommentId]",
		"callback" => "userHeadComment",
		"method" => "GET",
		"call_type" => "public_call"
    ]
];

// this is first step
// but we have some more )
class TodoSecurityProvider extends \Mezon\Service\ServiceAuthenticationSecurityProvider{
    
}

/**
 * Logic implementation
 */
class TodoLogic extends \Mezon\Service\ServiceBaseLogic
{

    /**
     * First endpoint
     */
    public function ping(): string
    {
        return 'I am alive!';
    }

    /**
     * Second route
     */
    public function whoAmI(): string
    {
        return 'I\'am Batman!';
    }
}

/**
 * Service class
 */
class TodoService extends \Mezon\Service\ServiceBase
{
}

/**
 * Security provider
 */
class TodoSecurityProvider extends \Mezon\Service\ServiceAuthenticationSecurityProvider{}

\Mezon\Service\Service::start(TodoService::class, TodoLogic::class, null, TodoSecurityProvider::class);