Download the PHP package logcomex/php-utils without Composer

On this page you can find all versions of the php package logcomex/php-utils. 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 php-utils

php-utils

PHP Utilities for Laravel/Lumen

Installation

Utilities Packages

Contracts

Have all the contracts (interfaces) used by the php-utils classes and other that you can use in your project.

Exceptions

Have all the exceptions used by the php-utils classes. And others that you can use in your project to segregate your errors types .

ApiException

You can use for all exceptions in 400 range http code

Visibility Function Return Type
public getHttpCode int
public getToken string
public __toString string
public toArray array
public toJson string

BadImplementationException

This exception means that a situation has been overlooked or incorrectly done by the developer.

Visibility Function Return Type
public getHttpCode int
public getToken string
public __toString string
public toArray array
public toJson string

SecurityException

This exception serves to point out some security problem in your application.

Visibility Function Return Type
public getHttpCode int
public getToken string
public __toString string
public toArray array
public toJson string

UnavailableServiceException

This exception serves to point out that your or other application is unavailable.

Visibility Function Return Type
public getHttpCode int
public getToken string
public getService string
public __toString string
public toArray array
public toJson string

Functionalities

They're a pack of traits that can be useful in your code

PropertiesExporterFunctionality

You can use this functionality to export an array with you class properties

PropertiesAttacherFunctionality

You can use this functionality to attach in your class properties the values passed in the parameter.

Note: To uses this functionality, you need use the PropertiesExporterFunctionality in the class.

Exception Reason
BadImplementationException When you don't use PropertiesExporterFunctionality

ValuesExporterToArrayFunctionality

You can use this functionality to easily get all the properties of class in an array.

Note: To uses this functionality, you need to do two things:

  1. The class must implement Illuminate\Contracts\Support\Arrayable.
  2. The class must use PropertiesExporterFunctionality.
Exception Reason
BadImplementationException When yout don't implement the the Arrayable contract
BadImplementationException When you don't use PropertiesExporterFunctionality

ValuesExporterToJsonFunctionality

You can use this functionality to easily get all the properties of class in a Json.

Note: To uses this functionality, you need to do two things:

  1. The class must implement Illuminate\Contracts\Support\Jsonable.
  2. The class must use PropertiesExporterFunctionality.
Exception Reason
BadImplementationException When yout don't implement the the Jsonable contract
BadImplementationException When you don't use PropertiesExporterFunctionality

Helpers

They're a pack of Helpers classes and traits.

EnumHelper

It's a trait that provide some utilities to your Enumerators classes.

Visibility Function Return Type Purpose
public all array Get all the constants of your Enumerator

Loggers

The idea of this package is provide all the Loggers classes.

LogcomexLogger

Using this class you can easily provide a log template, that is very important to integrate with Datadog.

Middlewares

They're a pack of Middleware classes.

AuthenticateMiddleware

It is a class that provides authentication verification. You'll need a AuthProvider configured in your application to use this Middleware.

RequestLogMiddleware

It is a class that provides a log for each request in your api. You can choose what you gonna print in the log, such as: request-header, request-server, request-payload, response-header, response-content, response-time, and trace-id.

The .env configuration:

Env Variable Type Description
REQUEST_LOGGER_ENABLE_REQUEST_HEADER boolean Print in the log, the request header information
REQUEST_LOGGER_ENABLE_REQUEST_SERVER boolean Print in the log, the request server information
REQUEST_LOGGER_ENABLE_REQUEST_PAYLOAD boolean Print in the log, the request payload information
REQUEST_LOGGER_ENABLE_RESPONSE_HEADER boolean Print in the log, the response header information
REQUEST_LOGGER_ENABLE_RESPONSE_CONTENT boolean Print in the log, the response content information
REQUEST_LOGGER_ENABLE_RESPONSE_TIME boolean Print in the log, the response execution time information
REQUEST_LOGGER_ALLOWED_DATA_REQUEST_SERVER string If has data in this variable, the middleware gonna print just the infos requested in this setting

ResponseTimeLogMiddleware

It is a class that registers the response time of each request in your api. You can choose what request will be measured through calling the middleware by route.

First of all, you have to define the framework start time globally before requiring anything in your bootstrap:

Configuration:

Your app config has to contain the key 'api-name', which will be used by this middleware for identifying what API the response time belongs to.

Usage:

It is IMPORTANT that you call this middleware as the first one, so the response time calc can be the most accurate as possible.

TracerMiddleware

It is a class that provides tracer functionality for your api. So your log can use this value and the HttpHelper. You must create a tracer config file in config folder. We recommend uses this middleware as global, and the first one in middlewares chain.

AccreditedApiKeysMiddleware

It is a class that provides a first level of security for your api. The best analogy is that middleware is your "API guest list".

You need to register a configuration file called accreditedApiKeys, with all the api-keys that can request your api.

Therefore, if the request does not contain the x-infra-key header or a allowed value, the API denies the request with the security exception.

It is recommended to use as a global middleware, and if you need to avoid this middleware for some routes, just insert into the public route group.

Providers

The idea of this package is provide some providers. For a better understanding: Lumen Providers

LogcomexLoggerProvider

You have to use this provider when you're using the Logger Facade.


// bootstrap/app.php

$app->register(Logcomex\MicroservicesCore\Providers\LogcomexLoggerProvider::class);

## Singletons  

> They're a pack of Singleton classes.

#### TracerSingleton

> It is a class that provides the tracer value.

## Unit Tests Coverage

Master <br>
[![codecov](https://codecov.io/gh/comexio/php-utils/branch/master/graph/badge.svg)](https://codecov.io/gh/comexio/php-utils)

## TODO

 - [ ] HttpHelper Doc
 - [ ] TokenHelper Doc
 - [ ] Handlers Package Doc
     - [ ] ExceptionHandler Doc
 - [ ] Logs Package Doc
     - [ ] RequestLog Doc
 - [ ] Middlewares Package Doc
     - [ ] AllowedHostsMiddleware Doc
     - [ ] CorsMiddleware Doc

## Contributing  

- Open an issue first to discuss potential changes/additions.
- Open a pull request, you need two approvals and tests need to pass Travis CI.

All versions of php-utils with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
ext-json Version *
guzzlehttp/guzzle Version ^6.3.3
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 logcomex/php-utils contains the following files

Loading the files please wait ....