PHPackages                             phpslides/status - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. phpslides/status

ActiveLibrary[API Development](/categories/api)

phpslides/status
================

PhpSlides HTTP Status Response in handling PhpSlides API

v0.0.3(1y ago)313MITPHPPHP &gt;=8.2

Since Jul 1Pushed 1y agoCompare

[ Source](https://github.com/PhpSlides/status)[ Packagist](https://packagist.org/packages/phpslides/status)[ Docs](https://github.com/phpslides/status)[ Fund](https://www.buymeacoffee.com/dconco)[ Fund](https://ko-fi.com/dconco)[ RSS](/packages/phpslides-status/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (5)Used By (0)

HTTP PhpSlides\\Status
======================

[](#http-phpslidesstatus)

 [![](./images/status.jpeg)](./images/status.jpeg)

Installation
------------

[](#installation)

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

```
composer require phpslides/status
```

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](https://github.com/phpslides/status/releases/tag/v0.0.3)

Quick Start
-----------

[](#quick-start)

### Using Status() class function

[](#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:

```
use PhpSlides\Enums\ResponseType;

ResponseType::JSON;
ResponseType::HTML;
ResponseType::CSV;
ResponseType::XML;

new Status(ResponseType::JSON);
```

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 &amp; Methods

[](#some-functions--methods)

#### success() method

[](#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::` which is passed as a parameter in the `Status()` function.

```
use PhpSlides\StatusCode;

$user = [
    "name": "John Doe",
    "email": "john@doe.com"
];
return (new Status())->success($user, StatusCode::OK);
```

#### error() method

[](#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::`

```
return (new Status(ResponseType::JSON))->error('User not Found', StatusCode::NOT_FOUND);
```

#### Full code for success() &amp; error() methods

[](#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-and-status-interface)

### namespace

[](#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

[](#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

[](#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

[](#enum-responsetype-interface)

`const JSON = 'JSON';`

`const HTML = 'HTML';`

`const CSV = 'CSV';`

`const XML = 'XML';`

DOCUMENTATION
-------------

[](#documentation)

### Status Class Methods

[](#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)`

[](#__constructstring-response--responsetypejson)

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`.

```
$status = new Status(); // Defaults to JSON
$status = new Status(ResponseType::HTML); // Initializes with HTML response type
```

#### `getStatus(): int`

[](#getstatus-int)

This method retrieves the current HTTP status code.

```
$httpStatus = $status->getStatus(); // Returns the current HTTP status code
```

#### `getStatusText(): string`

[](#getstatustext-string)

Retrieves the status text corresponding to the HTTP status code.

```
$statusText = $status->getStatusText(); // Returns status text, e.g., "OK" for 200
```

#### `getMessage(): mixed`

[](#getmessage-mixed)

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

```
$message = $status->getMessage(); // Returns the message set in the response
```

#### `get(): string|array`

[](#get-stringarray)

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

```
$response = $status->get(); // Returns the raw response data
```

#### `getJson(): string`

[](#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.

```
$jsonResponse = $status->getJson(); // Returns the response as a JSON string
```

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

[](#setmixed-data-int-status--statuscodeno_content-string-statustext--statustextno_content-void)

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

```
$status->set(['key' => 'value'], StatusCode::OK, StatusText::OK); // Sets custom response data
```

#### `setStatus(int $status): void`

[](#setstatusint-status-void)

Sets the HTTP status code.

```
$status->setStatus(StatusCode::OK); // Manually set the status code
```

#### `setStatusText(string $statusText): void`

[](#setstatustextstring-statustext-void)

Sets the status text corresponding to the HTTP status code.

```
$status->setStatusText(StatusText::OK); // Manually set the status text
```

#### `setMessage(mixed $message): void`

[](#setmessagemixed-message-void)

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

```
$status->setMessage('Success message'); // Manually set the response message
```

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

[](#errorarraystring-data-int-status--statuscodeinternal_server_error-stringarray)

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).

```
$errorResponse = $status->error('An error occurred', StatusCode::BAD_REQUEST); // Returns error response in JSON
```

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

[](#successarraystring-data-int-status--statuscodeok-stringarray)

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).

```
$successResponse = $status->success(['message' => 'Operation successful']); // Returns success response in JSON
```

### Response Class Methods

[](#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`

[](#jsonarray-data---int-status--statuscodeok-string)

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

```
$response = Response::json(['key' => 'value'], StatusCode::CREATED); // Outputs JSON response
```

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

[](#htmlarray-data---int-status--statuscodeok-string)

Returns the data formatted as HTML.

```
$response = Response::html(['key' => 'value'], StatusCode::OK); // Outputs HTML response
```

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

[](#csvarray-data---int-status--statuscodeok-string)

Returns the data formatted as CSV.

```
$response = Response::csv(['key' => 'value'], StatusCode::OK); // Outputs CSV response
```

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

[](#xmlarray-data---int-status--statuscodeok-string)

Returns the data formatted as XML.

```
$response = Response::xml(['key' => 'value'], StatusCode::OK); // Outputs XML response
```

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

[](#arrayarray-data---int-status--statuscodeunsupported_media_type-array)

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

```
$response = Response::array(['key' => 'value']); // Outputs data as an array
```

### enum ResponseType

[](#enum-responsetype)

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

- `ResponseType::JSON` - For JSON format
- `ResponseType::HTML` - For HTML format
- `ResponseType::CSV` - For CSV format
- `ResponseType::XML` - For XML format

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

```
$status = new Status(ResponseType::XML); // Initializes the Status class with XML response type
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~26 days

Total

3

Last Release

633d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/aff7e7d7d6268a283ff2f4968de6430a826972a58b9d719cdea57b98aaf5fdb2?d=identicon)[dconco](/maintainers/dconco)

---

Top Contributors

[![dconco](https://avatars.githubusercontent.com/u/118613296?v=4)](https://github.com/dconco "dconco (18 commits)")

---

Tags

apihttp-statusphpslidesphpslides-statusstatusapistatusslidesphpslidesphpslides-status

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpslides-status/health.svg)

```
[![Health](https://phpackages.com/badges/phpslides-status/health.svg)](https://phpackages.com/packages/phpslides-status)
```

###  Alternatives

[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22779.0k](/packages/m165437-laravel-blueprint-docs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
