PHPackages                             gokulsrinivas/sangria - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. gokulsrinivas/sangria

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

gokulsrinivas/sangria
=====================

A collection of useful libraries to make life easier.

1.0.1(9y ago)31.5kPHPPHP &gt;=5.3.0

Since Apr 5Pushed 9y ago1 watchersCompare

[ Source](https://github.com/GokulSrinivas/Sangria)[ Packagist](https://packagist.org/packages/gokulsrinivas/sangria)[ RSS](/packages/gokulsrinivas-sangria/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Sangria [![Build Status](https://camo.githubusercontent.com/bfdb90ddafcc81c9c16e08cfc399d941b30b9fd4dc2251a58721f0bcff670251/68747470733a2f2f7472617669732d63692e6f72672f476f6b756c5372696e697661732f53616e677269612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/GokulSrinivas/Sangria) [![license](https://camo.githubusercontent.com/9b91295a3ffb69bf4c93d3e01f83f07bc285fc774b60d29c1607c0988c717622/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d7265642e7376673f7374796c653d666c6174)](https://github.com/GokulSrinivas/Sangria/blob/master/LICENSE.md)
==============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#sangria--)

A Set of lightweight PHP libraries to make your life easier.

**FAQ:** Why the name Sangria?

**Ans:** Because I like [this](https://www.youtube.com/watch?v=KoQrH6EMnas) song and I like to drink/eat [fruits](https://en.wikipedia.org/wiki/Sangria).

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

[](#installation)

- Add `"gokulsrinivas/sangria":"dev-master"` to `"require"` in your `composer.json`.
- Do a `composer install`
- If you're not using this in a framework like laravel, be sure to `include "vendor/autoload.php"` in your file. `vendor` is the folder that is created after the composer install.
- `use Sangria\JSONResponse` / `IMAPAuth` / `LDAPAuth` / `HelperFunctions`
- See usage below.
- Write cleaner code.
- Feel Awesome.
- Build cool stuff.
- Happy coding!

Usage
-----

[](#usage)

### `Sangria\JSONResponse`

[](#sangriajsonresponse)

---

This class is helpful to API Developers who need to return JSON representations of strings, objects, collections etc.

This class follows the following JSON structure.

```
{
  "status_code": 200,
  "message": "OK"
}
```

- Include the class with `use Sangria\JSONResponse;`
- Definition `JSONResponse::response($status_code=400,$message=NULL,$strict_mode=false)`
- The `$status_code` can be HTTP status codes or your own custom status codes.
- If the `$status_code` is a HTTP status code and the message is `NULL`, a default [reason phrase](https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html) is added. (If `$strict_mode` is `false` (default) )
- If the `$strict_mode` is set to `true`, the data given as `$message` is encoded. So, `NULL` is encoded as `null`.
- The `$status_code` defaults to 400.
- `Sangria\JSONResponse` can be safely used in Laravel as all eloquent models and collections can be passed as `$message`.

**Sample Code**

```
