ReqEase-php

Introduction

ReqEase for PHP is a library that simplifies the process of generating responses that ReqEase can easily interpret and present to your frontend applications. In this section, we'll provide an overview of ReqEase for PHP, including installation, basic usage, code examples, and references for its methods.

Installation

You can easily install ReqEase for PHP using Composer, a popular PHP dependency manager. Simply require the package in your project like this:

composer require hichemtab-tech/reqease-php

Usage

Once installed, you can start using ReqEase for PHP to create responses. Here's an example of how to create and send a message response:

use HichemtabTech\ReqeasePhp\ReqEase;
use HichemtabTech\ReqeasePhp\Responses\Components\ButtonsBuilder;
use HichemtabTech\ReqeasePhp\Responses\Message\MessageContent;
use HichemtabTech\ReqeasePhp\Responses\Message\MessageResponseType;

$response = ReqEase::createMessageResponse()
    ->setContent(
        new MessageContent(
            'Hello BOSS!',
            'Hello BOSS! How are you doing today?'
        )
    )
    ->setButtons(
        ButtonsBuilder::addCancelButton("Cancel")
        ->addRedirectButton('https://google.com')
    )
    ->setType(MessageResponseType::MODAL_BIG)
    ->setHttpCode(200)
    ->setColor('green')
    ->build();

$response->send();

In this example, we create a message response with a custom message and buttons, specifying its type, HTTP code, and color. Finally, we use the send() method to send the response.

Classes and Methods

ReqEase for PHP provides a set of classes and methods to simplify the creation of responses. Here's an overview of these classes and methods:

MessageResponseBuilder

  • Properties:

    • $content: The content of the message response.

    • $type: The type of the message response, which can be one of the following:

      • MessageResponseType::MODAL_BIG

      • MessageResponseType::MODAL_MEDIUM

      • MessageResponseType::MSG_IN_TOAST

      • MessageResponseType::MSG_IN_FORM

  • Methods:

    • setButtons(ButtonsBuilder|array $buttonsBuilder): Sets the buttons for the message response.

FieldsErrorResponseBuilder

  • Properties:

    • $fieldsErrors: An array to store field errors.

  • Methods:

    • setFieldsErrors(FieldsErrorsBuilder|array $fieldsErrorsBuilder): Sets the field errors for the response.

ButtonsBuilder

This class allows you to create buttons for responses. It provides various methods to add different types of buttons, such as close, cancel, confirm, redirect, refresh, retry, call a function, and custom buttons. You can use these methods to build an array of buttons for your response.

Here are the available methods:

  • addCloseButton(string $text = null, string $color = null)

  • addCancelButton(string $text = null, string $color = null)

  • addConfirmButton(string $text = null, string $color = null)

  • addRedirectButton(string $url, string $text = null, string $color = null)

  • addRefreshButton(string $text = null, string $color = null)

  • addRetryButton(string $text = null, string $color = null)

  • addCallFunctionButton(string $functionName, string $text = null, string $color = null)

  • addCustomButton(string $actionType, array $buttonData)

You can use these methods to create and customize buttons for your responses.

FieldsErrorsBuilder

This class is used to build an array of field errors for the FieldsErrorResponseBuilder. It provides methods to add field errors, including the field name and an error message. These errors can be associated with specific form fields in your response.

  • addFieldError(string $field, string $message): Adds a field error with the specified field name and error message.

  • build(): Builds and returns the array of field errors.

These classes and methods make it easy to create and customize responses in ReqEase for PHP. You can use them to generate responses that meet the specific needs of your application.

Last updated