2017 © Pedro Peláez
 

library laravel-service-utils

Utils for internal Laravel services.

image

diegoalvarezb/laravel-service-utils

Utils for internal Laravel services.

  • Sunday, September 3, 2017
  • by diegoalvarezb
  • Repository
  • 1 Watchers
  • 1 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

laravel-service-utils

This tool adds some utilities for internal services in Laravel., (*1)

Using this package, you could extend all your services (classes with the application business logic) from Diegoalvarezb\ServiceUtils\AbstractService and use some funcionalities: - Service response interface - Log management, (*2)

Requirements

  • PHP >= 5.6
  • Laravel >= 5.0

Installation and configuration

Package installation with composer:, (*3)

composer require diegoalvarezb/laravel-service-utils

And add the service provider in your config/app.php file:, (*4)

Diegoalvarezb\FrontMessages\ServiceUtilsServiceProvider::class

And this command will add the service-utils config file to the laravel config folder:, (*5)

php artisan vendor:publish --tag=service-utils

Service response interface

Use the next command to return the result of a method:, (*6)

return $this->generateResponse($data = [], $errorCode = 'NO_ERROR', $message = '');

The first param contains an array with all data. The second one must be the error code (this one must exists in the service-utils config file). The third one an additional message (if you don't send this param, the corresponding in the config file will be selected)., (*7)

This method will return a ServiceResponse object, wich has the next methods: - hasErrors() - isCritical() - getMessage() - getData() - getHttpCode(), (*8)

Service log management

Use the next command to write info the log file:, (*9)

$this->logException($exception, $type = 'error', $customMessage = '');

The first param contains the exception. The second one must be the log type. The third one an additional message., (*10)

The list of log types: - error - emergency - alert - critical - warning - notice - info, (*11)

The structure of the log: [datetime] local.LOG_TYPE: Path\To\Class | method() | (Exception) | message, (*12)

Example config file: service-utils.php

<?php

use Symfony\Component\HttpFoundation\Response;

return [

    /*
     * Error code list for service response interface.
     */
    'service_codes' => [

        'NOT_ERROR' => [
            'is_error' => false,
            'message' => 'Ok.',
            'http_code' => Response::HTTP_OK,
            'is_critial' => false,
        ],

        'GENERAL_ERROR' => [
            'is_error' => true,
            'message' => 'General error.',
            'http_code' => Response::HTTP_INTERNAL_SERVER_ERROR,
            'is_critial' => false,
        ],

        'NEW_ERROR' => [
            'is_error' => true,
            'message' => 'Text example of a new error.',
            'http_code' => Response::HTTP_INTERNAL_SERVER_ERROR,
            'is_critial' => true,
        ],

    ],

];

License

MIT, (*13)

The Versions

03/09 2017

dev-master

9999999-dev https://github.com/diegoalvarezb/laravel-service-utils

Utils for internal Laravel services.

  Sources   Download

MIT

The Requires

 

by Diego Alvarez

laravel services php utils

03/09 2017

v1.0.1

1.0.1.0 https://github.com/diegoalvarezb/laravel-service-utils

Utils for internal Laravel services.

  Sources   Download

MIT

The Requires

 

by Diego Alvarez

laravel services php utils

03/09 2017

v1.0.0

1.0.0.0 https://github.com/diegoalvarezb/laravel-service-utils

Utils for internal Laravel services.

  Sources   Download

MIT

The Requires

 

by Diego Alvarez

laravel services php utils