nextstage-brasil/ns-helpers

This package is abandoned and no longer maintained. The author suggests using the nsutil package instead.

Methods and classes for various utilities

1.0.1 2024-10-07 14:00 UTC

README

NsHelpers is a collection of PHP utilities for handling files, directories, dates, JSON, HTTP, and more. This repository contains various classes and functions that facilitate the development of PHP applications.

Project Structure

  • src/Helpers/
    • Validate.php: Validation functions.
    • JsonParser.php: JSON manipulation.
    • File.php: File handling utilities.
    • DirectoryManipulation.php: Directory handling utilities.
    • Date.php: Date handling utilities.
    • Compatibility.php: PHP code compatibility checks.
    • Format.php: Formatting utilities.
    • Packer.php: JavaScript script compression.
  • src/Http/
    • Ssl.php: SSL certificate handling.
    • Response.php: HTTP response handling.
    • Http.php: HTTP request handling.
  • src/Integrations/
    • Cep.php: Integration with CEP API.
  • src/Functions/
    • functions.php: Helper functions.
  • tests/
    • FileTest.php: Unit tests for the File class.

Installation

To install NsHelpers, use Composer: composer require nextstage-brasil/ns-helpers

Usage

HTTP Requests

The Http class provides methods to make HTTP requests. Below are some examples of how to use it.

Making a GET Request

<?php
use NsHelpers\Http\Http;
$response = Http::call('https://api.example.com/data', [], 'GET');
echo $response->getBody(); // Outputs the response body as a string

Making a POST Request

<?php
use NsHelpers\Http\Http;
$params = ['key1' => 'value1', 'key2' => 'value2'];
$headers = ['Content-Type: application/json'];
$response = Http::call('https://api.example.com/data', $params, 'POST', $headers);
echo $response->getBody('array'); // Outputs the response body as an array

Making a GET Request with SSL

<?php
use NsHelpers\Http\Http;
$response = Http::call('https://secure.example.com/data', [], 'GET', [], true);
echo $response->getHttpCode(); // Outputs the HTTP status code