2017 © Pedro Peláez
 

library laravel-service-generators

Provide command line generation of service layer files.

image

maltex/laravel-service-generators

Provide command line generation of service layer files.

  • Thursday, December 15, 2016
  • by wskyjames
  • Repository
  • 2 Watchers
  • 2 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel 5 Service Generator

A command line tool for generating service layer files for your application. Inspired by Jeffrey Way's L5 generator packages., (*1)

Intro

The generator provided in this package is aimed to reduce time spent on boilerplate code when using a service layer within laravel. Although it allows for use without, the main aim is to be used in conjunction with a repository., (*2)

Set Up

1. Install

Install the package using composer, (*3)

composer require maltex/laravel-service-generators

2. Add Service Provider

Make the package available to your application by adding the service provider. This is not required for production code so register it by adding the following to your app/Providers/AppServiceProvider.php:, (*4)

public function register()
{
    if ($this->app->environment() == 'local') {
        $this->app->register('Maltex\Generators\GeneratorsServiceProvider');
    }
}

Examples

Let's say you're working with a Client model. You've created your front end screen, your routes and a controller end-point. Now we need to manage the business logic., (*5)

php artisan make:service AddClientService --repo=Client --func=addClient, (*6)

You will see that a Services folder is now available in your application with the AddClientService.php file., (*7)


use Maltex\Generators\Contracts\ServiceContract; use App\Repositories\CLientRepository; class AddClientService implements ServiceContract { /** * @var App\Repositories\ClientRepository */ protected $repository; /** * Inject the repository * * @return void */ public function __construct(App\Repositories\ClientRepository $repository) { $this->repository = repository; } /** * @inheritdoc */ public function execute($data) { // TODO Add business logic $this->repository->addClient($data) } }

This service should then be injected into your controller function., (*8)

// ClientController.php
public function create(
    Request $request,
    AddClientService $service
)
{
    if($service->execute($request)) {
        // success response
    }
}

To Do

  • Add config details for repository dir and service dir
  • Add generators for a repository service (tie into Dingo or Lara5 Repo)
  • Offer the option to generate test file for the service

The Versions

15/12 2016

dev-master

9999999-dev

Provide command line generation of service layer files.

  Sources   Download

MIT

The Requires

 

by James Bennett

laravel services generators