PHPackages                             trano/tranoutilsbundle - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. trano/tranoutilsbundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

trano/tranoutilsbundle
======================

Trano Utils Bundle

1.0.23(2mo ago)0551↓100%MITPHPPHP ^7.2|^8

Since Feb 21Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/ranaivomahaleo/TranoUtilsBundle)[ Packagist](https://packagist.org/packages/trano/tranoutilsbundle)[ RSS](/packages/trano-tranoutilsbundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (26)Used By (0)

TranoUtilsBundle
================

[](#tranoutilsbundle)

The TranoUtilsBundle contains utilities for the following purposes:

- Extended Response with configurable headers using .env file variables
- Json responses setter for REST API with configurable CORS headers using .env file variables
- Simple syntax http query service
- Environment variable reader

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

[](#installation)

Install with composer using

```
composer require trano/tranoutilsbundle

```

Extended Response with configurable headers
-------------------------------------------

[](#extended-response-with-configurable-headers)

The Response headers can be set using the following instruction:

```
use Trano\UtilsBundle\Util\ExtendedResponse;

$extendedreponse = new ExtendedResponse();
$response = new Response('test');
$responseWithHeaders = $extendedreponse->encapsulateHeaders($response);
```

The headers values can be set using the following environment variables:

```
HEADER_STRICT_TRANSPORT_SECURITY=""
HEADER_CACHE_CONTROL=""
HEADER_PRAGMA=""
HEADER_REFERRER_POLICY=""
HEADER_X_CONTENT_TYPE_OPTIONS=""
HEADER_CONTENT_SECURITY_POLICY=""
HEADER_X_FRAME_OPTIONS=""
HEADER_X_XXS_PROTECTION=""
```

By default, the following secured header () values are send back to the client when the corresponding environment variable is not set:

```
Strict-Transport-Security: max-age=31536000
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
Content-Security-Policy: default-src 'self'
X-Frame-Options: deny
X-XXS-Protection: 1; mode=block

```

The map between environment variables and the security headers are

Environment variableHeaderDefault valueHEADER\_STRICT\_TRANSPORT\_SECURITYStrict-Transport-Securitymax-age=31536000HEADER\_CACHE\_CONTROLCache-Controlno-cache, no-store, must-revalidateHEADER\_PRAGMAPragmano-cacheHEADER\_REFERRER\_POLICYReferrer-Policyno-referrerHEADER\_X\_CONTENT\_TYPE\_OPTIONSX-Content-Type-OptionsnosniffHEADER\_CONTENT\_SECURITY\_POLICYContent-Security-Policydefault-src 'self'HEADER\_X\_FRAME\_OPTIONSX-Frame-OptionsdenyHEADER\_X\_XXS\_PROTECTIONX-XXS-Protection1; mode=blockJsonResponse with configurable CORS headers and security headers
----------------------------------------------------------------

[](#jsonresponse-with-configurable-cors-headers-and-security-headers)

### JsonResponse with default security headers

[](#jsonresponse-with-default-security-headers)

Use the following code to return a JsonResponse, code 200, with the default security headers:

```
use Trano\UtilsBundle\Util\ApiJsonResponse;

$apijsonreponse = new ApiJsonResponse();
return $apijsonreponse->_200Ok('this is an ok results');
```

The result of the above instructions is (notice the adition of the `status`, `message` and `results` keys)

```
{
  "status": 200,
  "message": "",
  "results": "this is an ok results"
}
```

By default, the following secured header values () are send back to the client:

```
Strict-Transport-Security: max-age=31536000
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
Content-Security-Policy: default-src 'self'
X-Frame-Options: deny
X-XXS-Protection: 1; mode=block

```

The above headers can be updated using the following environment variables

```
HEADER_STRICT_TRANSPORT_SECURITY=""
HEADER_CACHE_CONTROL=""
HEADER_PRAGMA=""
HEADER_REFERRER_POLICY=""
HEADER_X_CONTENT_TYPE_OPTIONS=""
HEADER_CONTENT_SECURITY_POLICY=""
HEADER_X_FRAME_OPTIONS=""
HEADER_X_XXS_PROTECTION=""
```

To update the CORS headers (`Access-Control.*`), use the following environment variables.

```
ALLOWED_ORIGIN="*"
ALLOWED_METHODS="GET,POST"
ALLOWED_HEADERS="Authorization, Content-Type"
```

The map between environment variables and the headers are

Environment variableHeaderALLOWED\_ORIGINAccess-Control-Allow-OriginALLOWED\_METHODSAccess-Control-Allow-MethodsALLOWED\_HEADERSAccess-Control-Allow-Headers### Custom JsonResponse

[](#custom-jsonresponse)

By default, `ApiJsonResponse` returns a json with `status`, `message` and `results` keys. To change this behaviour with a custom json data structure, set

```
JSON_RESPONSE_TYPE=custom
```

Thus, the following php code

```
use Trano\UtilsBundle\Util\ApiJsonResponse;

$apijsonreponse = new ApiJsonResponse();
return $apijsonreponse->_200Ok(["data" => 'this is an ok custom results']);
```

returns

```
{
  "data": "this is an ok custom results"
}
```

Usage of simple Http request
----------------------------

[](#usage-of-simple-http-request)

The `$httprequest` service is an instance of `Trano\UtilsBundle\Util\HttpRequest`

### GET query with basic Auth

[](#get-query-with-basic-auth)

To return an associative array response using GET, use the following instruction. The get instruction should be at the end.

```
    $http_array_response = $this->httprequest
            ->addHeader('Accept', '*/*')
            ->addHeader('Content-Type', 'application/json')
            ->setBasicAuth('username', 'password')
            ->get('https://www.example.com/getservice');
```

### POST query with array data and basic Auth

[](#post-query-with-array-data-and-basic-auth)

To return an associative array response using POST, use the instructions below.

The $data variable is sent by default using `application/x-www-form-urlencoded` type. If `https://www.example.com/postservice` is a Symfony controller route, `$data['data1']` variable would be get using `$request->request->get('data1');` instruction.

The post instruction should be at the end. ``

```
    $data = [
        'data1' => 'data1',
        'data2' => 'data2',
    ];
    $http_array_response = $this->httprequest
        ->setBasicAuth('username', 'password')
        ->setBodyArray($data)
        ->post('https://www.example.com/postservice');
```

Notice that due to the functionalities of the symfony http request, both GET and POST simple queries are synchronous (those queries wait for the response).

Usage of Environment variable reader
------------------------------------

[](#usage-of-environment-variable-reader)

Let us consider that we have the following environment variable file .env

```
DATABASE_URL='mysql://aaa:bbb...'

```

To read this environment variable, use the $env service, an instance of `Trano\UtilsBundle\Util\Env`as follows

```
$database_url = $this->env->getEnv('DATABASE_URL');
```

Example with a Symfony controller
---------------------------------

[](#example-with-a-symfony-controller)

Let us consider the environment variable at .env file

```
ALLOWED_ORIGIN="*"
ALLOWED_METHODS="GET,POST,PUT,DELETE"
ALLOWED_HEADERS="Authorization, Content-Type"

```

Important: If the ALLOWED\_\* are not set in .env file, the corresponsing Access-Control-Allow-\* headers will not be set.

To use the environment reader (`Trano\UtilsBundle\Util\Env`) and the Json response (`Trano\UtilsBundle\Util\ApiJsonResponse`) in a controller, use the following script

```
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Trano\UtilsBundle\Util\ApiJsonResponse;
use Trano\UtilsBundle\Util\Env;

class HomeController extends AbstractController
{
    /**
     * @var ApiJsonResponse
     */
    private $apijsonresponse;

    /**
     * @var Env
     */
    private $env;

    /**
     * ControllerTrait constructor.
     * @param ApiJsonResponse $apijsonresponse
     * @param Env $env
     */
    public function __construct(ApiJsonResponse $apijsonresponse, Env $env)
    {
        $this->apijsonresponse = $apijsonresponse;
        $this->env = $env;
    }

    /**
     * @Route("/", methods={"GET"})
     */
    public function index(Request $request)
    {
        // Computes DATABASE_URL from .env file
        // If DATABASE_URL does not exists in .env file, it returns '' string.
        $database_url = $this->env->getEnv('DATABASE_URL');

        // Return Json response with the http status 200.
        return $this->apijsonresponse->_200Ok('this is an ok results');
    } // index
}
```

The route / above reads DATABASE\_URL variable environment and returns the following json data.

```
{
    "status": 200,
    "message": "",
    "results": "this is an ok results"
}

```

License
-------

[](#license)

This bundle is under the MIT license. See the complete license [in the bundle](LICENSE).

About us
--------

[](#about-us)

TranoUtilsBundle is an initiative of [atety](https://www.atety.com).

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance90

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~91 days

Recently: every ~355 days

Total

25

Last Release

79d ago

PHP version history (3 changes)1.0.0PHP ^7.1

1.0.12PHP ^7.2|^8.0

1.0.19PHP ^7.2|^8

### Community

Maintainers

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

---

Top Contributors

[![ranaivomahaleo](https://avatars.githubusercontent.com/u/2079339?v=4)](https://github.com/ranaivomahaleo "ranaivomahaleo (1 commits)")

---

Tags

corscors-requestenvironment-variableshttpstatusjsonapiphpsymfonysymfony-bundle

### Embed Badge

![Health badge](/badges/trano-tranoutilsbundle/health.svg)

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

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[pentatrion/vite-bundle

Vite integration for your Symfony app

2725.3M13](/packages/pentatrion-vite-bundle)[symfony/asset-mapper

Maps directories of assets &amp; makes them available in a public directory with versioned filenames.

1656.9M131](/packages/symfony-asset-mapper)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)[symfony/ai-agent

PHP library for building agentic applications.

30536.7k44](/packages/symfony-ai-agent)[shyim/danger-php

Port of danger to PHP

8544.9k](/packages/shyim-danger-php)

PHPackages © 2026

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