Download the PHP package phpslides/status without Composer

On this page you can find all versions of the php package phpslides/status. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package status

HTTP PhpSlides\Status

Installation

After creating your PhpSlides project, navigate to the project directory and install PhpSlides-Status package using this command below:

Or download the zip file directly from the released version, ectract the file and add it to a folder 📂 in your PhpSlides project.

Download phpslides\status zip

EXPLANATION

Using Status() class function

Create a Status instance for API response. Which is used in PhpSlides API Controller Class

You can pass a string value to the Status() function parameter which is by default ResponseType::JSON using the Response namespace PhpSlides\Enums\ResponseType

In returning value in JSON format. The parameter includes this enum value type:

If the parameters contain any value apart from the enum ResponseType value it'll return default value an array form, which isn't recommended.

Some Functions & Methods

success() method

Returning a default success message, using the success() method.

The success() method takes 2 parameters, $data to render and $status which is the status code.

The first parameter can be either Array or String and the second parameter is an Integer from StatusCode static class. It returns ResponseType::<type> which is passed as a parameter in the Status() function.

error() method

Returning an error Api message using the error() method It also takes 2 parameters, the first is either an Array or String and the second which is interger for setting http_response_code, it has default value of StatusCode::INTERNAL_SERVER_ERROR which is 500

It also returns ResponseType::<type>

Full code for success() & error() methods

If no parameter is specified in the Status(), by default it's returning ResponseType::JSON for returning response in JSON format

Namespace and Status Interface

namespace

\PhpSlides\Status()

\PhpSlides\StatusCode

\PhpSlides\StatusText

\PhpSlides\Http\Response

\PhpSlides\Enums\ResponseType

\PhpSlides\Interface\StatusInterface

\PhpSlides\Interface\ResponseInterface

\PhpSlides\Status\Exception\ApiException()

\PhpSlides\Status\Exception\ExceptionInterface

Status() Interface Methods

__construct(string $response = ResponseType::JSON)

public function getStatus (): int;

public function getStatusText (): string;

public function getMessage (): mixed;

public function get (): string|array;

public function getJson (): string;

public function set (mixed $data, int $status = StatusCode::NO_CONTENT, string $statusText = StatusText::NO_CONTENT ): void;

public function setStatus (int $status): void;

public function setStatusText (string $statusText): void;

public function setMessage (mixed $message): void;

public function error (array|string $data, int $status = StatusCode::INTERNAL_SERVER_ERROR): string|array;

public function success (array|string $data, int $status = StatusCode::OK): string|array;

Response{} Interface Method

public static function json(array $data = [], int $status = StatusCode::OK): string;

public static function html(array $data = [], int $status = StatusCode::OK): string;

public static function csv(array $data = [], int $status = StatusCode::OK): string;

public static function xml(array $data = [], int $status = StatusCode::OK): string;

public static function array(array $data = [], int $status = StatusCode::UNSUPPORTED_MEDIA_TYPE): array;

enum ResponseType{} Interface

const JSON = 'JSON';

const HTML = 'HTML';

const CSV = 'CSV';

const XML = 'XML';

DOCUMENTATION

Status Class Methods

The Status class provides several methods to manage and format API responses in different formats such as JSON, HTML, CSV, or XML. Here's a quick guide on how to use them.

__construct(string $response = ResponseType::JSON)

The constructor initializes a new Status instance. You can specify the response format by passing a ResponseType enum value. If no value is passed, it defaults to ResponseType::JSON.

getStatus(): int

This method retrieves the current HTTP status code.

getStatusText(): string

Retrieves the status text corresponding to the HTTP status code.

getMessage(): mixed

Gets the message set for the response. This could be an array, string, or any data type depending on the response.

get(): string|array

Retrieves the response data in its raw form, either as a string or an array.

getJson(): string

Converts the response data to a JSON string. This method is useful when you need to explicitly get the response in JSON format.

set(mixed $data, int $status = StatusCode::NO_CONTENT, string $statusText = StatusText::NO_CONTENT): void

Sets the response data, status code, and status text. This method is used to manually define the response properties.

setStatus(int $status): void

Sets the HTTP status code.

setStatusText(string $statusText): void

Sets the status text corresponding to the HTTP status code.

setMessage(mixed $message): void

Sets the message for the response. This message can be an array, string, or any other data type.

error(array|string $data, int $status = StatusCode::INTERNAL_SERVER_ERROR): string|array

Creates an error response. You can pass the error message and an optional status code. By default, it sets the status code to 500 (Internal Server Error).

success(array|string $data, int $status = StatusCode::OK): string|array

Creates a success response. You can pass the response data and an optional status code. By default, it sets the status code to 200 (OK).

Response Class Methods

The Response class provides static methods to directly return responses in different formats. These methods are especially useful when you want to quickly output data without creating a Status instance.

json(array $data = [], int $status = StatusCode::OK): string

Returns the data in JSON format with the specified HTTP status code.

html(array $data = [], int $status = StatusCode::OK): string

Returns the data formatted as HTML.

csv(array $data = [], int $status = StatusCode::OK): string

Returns the data formatted as CSV.

xml(array $data = [], int $status = StatusCode::OK): string

Returns the data formatted as XML.

array(array $data = [], int $status = StatusCode::UNSUPPORTED_MEDIA_TYPE): array

Returns the data as a PHP array. This is a fallback option if none of the other formats is specified.

enum ResponseType

The ResponseType enum provides predefined constants for the supported response formats. These include:

Use these constants when specifying the response type in the Status class.


All versions of status with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phpslides/status contains the following files

Loading the files please wait ....